<!DOCTYPE html>
<html>
  <head>
    <link rel="stylesheet" href="{{ config.static.url }}css/xterm.css" />
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto%20Mono"/>
    <script src="{{ config.static.url }}js/textual.js"></script>
    <style>
      body {
        background: #000000;
      }

      .dialog-container {
        font-family: "Roboto Mono", menlo, monospace;
        position: absolute;
        width: 100vw;
        height: 100vh;
        display: flex;
        align-items: center;
        justify-content: center;
        z-index: 10;
      }
      .shade {
        font-family: "Roboto Mono", menlo, monospace;
        position: absolute;
        width: 100%;
        height: 100%;
      }
      .intro {
        font-family: "Roboto Mono", menlo, monospace;
        width: 640px;
        height: 240px;
        z-index: 20;
        color: rgba(255, 255, 255, 0.95);
        background-color: #000000;
        display: flex;
        align-items: center;
        text-align: center;
        justify-content: center;
      }

      body.-first-byte .intro-dialog,
      body.-first-byte .intro-dialog .shade {
        font-family: "Roboto Mono", menlo, monospace;
        opacity: 0;
        transition: opacity 0.3s ease-out;
        display: none;
      }

      body .textual-terminal {
        font-family: "Roboto Mono", menlo, monospace;
        opacity: 0;
        transition: opacity 0.3s ease-out;
      }

      body.-first-byte .textual-terminal {
        font-family: "Roboto Mono", menlo, monospace;
        opacity: 1;
        transition: opacity 0.3s ease-out;
      }

      body Button {
        font-family: "Roboto Mono", menlo, monospace;
        background-color: #000000;
        color: rgba(255, 255, 255, 0.95);
        display: block;
      }

      .closed-dialog {
        font-family: "Roboto Mono", menlo, monospace;
        opacity: 0;
        display: none;
      }

      body.-closed .closed-dialog {
        font-family: "Roboto Mono", menlo, monospace;
        opacity: 1;
        display: flex;
      }

      #start {
        font-family: "Roboto Mono", menlo, monospace;
        display: none;
      }

      #start.-delay {
        font-family: "Roboto Mono", menlo, monospace;
        display: flex;
      }

      footer {
        position: fixed;
        bottom: 0;
        width: 100%;
        text-align: center;
        color: rgba(255, 255, 255, 0.5);
        font-size: 12px;
        padding: 10px 0;
        background-color: #000000;
        z-index: 5;
      }
    </style>
    <script>
      function getStartUrl() {
        const url = new URL(window.location.href);
        const params = new URLSearchParams(url.search);
        params.delete("delay");
        return url.pathname + "?" + params.toString();
      }
      async function refresh() {
        const ping_url = document.body.dataset.pingurl;
        if (ping_url) {
          await fetch(ping_url, {
            method: "GET",
            mode: "no-cors",
          });
        }
        window.location.href = getStartUrl();
      }
    </script>
  </head>
  <body data-pingurl="{{ ping_url }}">
    <div class="dialog-container intro-dialog">
      <div class="shade"></div>
      <div class="intro">
        <div>正加载命令行应用实例...<br><br>
        确保使用现代浏览器并启用 JavaScript<br>
      终端模拟器基于 XTerm.js<br>应用程序框架: Textual <br>
      &copy; Wang Zhiyu 2024-2025, 保留此实例的所有权</div>
        <button type="button" onClick="refresh()" id="start">启动新实例</button>
      </div>
    </div>

    <div class="dialog-container closed-dialog">
      <div class="shade"></div>
      <div class="intro">
        <div class="message">实例程序已终止</div>
        <button type="button" onClick="refresh()">重新打开实例</button>
      </div>
    </div>

    <div
      id="terminal"
      class="textual-terminal"
      data-session-websocket-url="{{ app_websocket_url }}"
      data-font-size="{{ font_size }}"
    ></div>
  </body>
</html>
