# This file was generated by `tree-sitter playground`, with modifications:
#
# * favicon has been changed to the ðŸŒ² emoji
# * title element has been changed to "TSPM Â· Playground"
# * the language select has been made visible and is templated with the
#   grammars built by TSPM
#
# The remaining contents must be considered:
#
# Copyright (c) 2018-2021 Max Brunsfeld
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

{ grammars }:
let
  grammarSelect = grammar:
    let
      slug = "${grammar.language}/${grammar.owner}";
      display = "${grammar.language} Â· ${grammar.owner}";
      selected =
        if grammar.language == "elixir" then " selected=\"selected\"" else "";
    in ''<option value="${slug}"${selected}>${display}</option>'';
  grammarSelects =
    builtins.concatStringsSep " " (builtins.map grammarSelect grammars);
in ''
  <html>
    <head>
      <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
      <meta charset="utf-8" />
      <title>TSPM Â· Playground</title>
      <link
        rel="stylesheet"
        href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.45.0/codemirror.min.css"
      />
      <link
        rel="stylesheet"
        href="https://cdnjs.cloudflare.com/ajax/libs/clusterize.js/0.18.0/clusterize.min.css"
      />
      <link
        rel="shortcut icon"
        href="data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20100%20100%22%3E%3Ctext%20y%3D%22.9em%22%20font-size%3D%2290%22%3E%F0%9F%8C%B2%3C%2Ftext%3E%3C%2Fsvg%3E"
        type="image/svg+xml"
      />
    </head>

    <body>
      <div id="playground-container" style="visibility: visible">
        <header>
          <div class="header-item">
            <bold></bold>
          </div>

          <div class="header-item">
            <label for="logging-checkbox">log</label>
            <input id="logging-checkbox" type="checkbox" />
          </div>

          <div class="header-item">
            <label for="query-checkbox">query</label>
            <input id="query-checkbox" type="checkbox" checked="checked" />
          </div>

          <div class="header-item">
            <label for="update-time">parse time: </label>
            <span id="update-time"></span>
          </div>

          <select id="language-select">${grammarSelects}</select>
        </header>

        <main>
          <div id="input-pane">
            <div id="code-container">
              <textarea id="code-input" style="display: none"></textarea>
            </div>
            <div id="query-container" style="">
              <textarea id="query-input" style="display: none">(ERROR) @error</textarea>
            </div>
          </div>

          <div id="output-container-scroll">
            <pre
              id="output-container"
              class="highlight"
              tabindex="0"
              style="counter-increment: clusterize-counter 0"
            ><div></div></pre>
          </div>
        </main>
      </div>

      <script
        src="https://code.jquery.com/jquery-3.3.1.min.js"
        crossorigin="anonymous"
      ></script>

      <script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.45.0/codemirror.min.js"></script>
      <script src="https://cdnjs.cloudflare.com/ajax/libs/clusterize.js/0.18.0/clusterize.min.js"></script>

      <script>
        LANGUAGE_BASE_URL = "";
      </script>
      <script src="tree-sitter.js"></script>
      <script src="playground.js"></script>

      <style>
        body {
          margin: 0;
          padding: 0;
        }

        #playground-container {
          width: 100%;
          height: 100%;
          display: flex;
          flex-direction: column;
        }

        header {
          box-sizing: border-box;
          display: flex;
          padding: 20px;
          height: 60px;
          border-bottom: 1px solid #aaa;
        }

        main {
          flex: 1;
          position: relative;
        }

        #input-pane {
          position: absolute;
          top: 0;
          left: 0;
          bottom: 0;
          right: 50%;
          display: flex;
          flex-direction: column;
        }

        #code-container,
        #query-container {
          flex: 1;
          position: relative;
          overflow: hidden;
          border-right: 1px solid #aaa;
          border-bottom: 1px solid #aaa;
        }

        #output-container-scroll {
          position: absolute;
          top: 0;
          left: 50%;
          bottom: 0;
          right: 0;
        }

        .header-item {
          margin-right: 30px;
        }

        #playground-container .CodeMirror {
          position: absolute;
          top: 0;
          bottom: 0;
          left: 0;
          right: 0;
          height: 100%;
        }

        #output-container-scroll {
          flex: 1;
          padding: 0;
          overflow: auto;
        }

        #output-container {
          padding: 0 10px;
          margin: 0;
        }

        #logging-checkbox {
          vertical-align: middle;
        }

        .CodeMirror div.CodeMirror-cursor {
          border-left: 3px solid red;
        }

        a {
          text-decoration: none;
          color: #040404;
          padding: 2px;
        }

        a:hover {
          text-decoration: underline;
        }

        a.highlighted {
          background-color: #d9d9d9;
          color: red;
          border-radius: 3px;
          text-decoration: underline;
        }

        .query-error {
          text-decoration: underline red dashed;
          -webkit-text-decoration: underline red dashed;
        }
      </style>
    </body>
  </html>
''
