<!DOCTYPE html>
<html <% if @theme %>data-bs-theme="<%= @theme %>"<% end %>>
  <head>
    <% unless @theme %>
      <script blocking="render">
        // Combines the approaches from:
        // https://www.freexian.com/blog/debusine-dark-mode/
        // https://www.xjavascript.com/blog/how-do-i-detect-dark-mode-using-javascript/#5-handling-dynamic-theme-changes
        function setTheme() {
          let theme = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
          let [html] = document.getElementsByTagName("html");
          html.setAttribute("data-bs-theme", theme);
        }
        setTheme();
        const darkModeQuery = window.matchMedia('(prefers-color-scheme: dark)');
        darkModeQuery.addEventListener('change', setTheme);
      </script>
    <% end %>
    <meta charset="utf-8">
    <% if @refresh %>
      <meta http-equiv="refresh" content="300"/>
    <% end %>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="<%= Debci.config.distro_name %> Continuous Integration Results">
    <meta name="author" content="The Debian Project">
    <title><%= Debci.config.distro_name %> Continuous Integration<% if defined?(@moretitle) %> - <%= @moretitle %><% end %></title>
    <link rel="icon" type="image/png" href="/debian.png"/>
    <%== stylesheet_tag '/bootstrap/css/bootstrap.css' %>
    <%== stylesheet_tag '/style.css' %>
    <%== stylesheet_tag '/fork-awesome/css/fork-awesome.css' %>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  </head>
  <body>
    <div id='wrap'>

      <nav class="navbar navbar-expand-lg bg-body-tertiary border-bottom">
        <div class="container">
          <a class="navbar-brand d-none d-sm-block" href="/"><%= Debci.config.distro_name %> Continuous Integration</a>
          <a class="navbar-brand d-block d-sm-none" href="/"><%= Debci.config.distro_name %> CI</a>
          <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
          </button>
          <div class="collapse navbar-collapse" id="navbarSupportedContent">
            <ul class="navbar-nav me-auto mb-2 mb-lg-0">
              <li class="nav-item"><a class="nav-link active" href="/">Home</a></li>
              <li class="nav-item"><a class="nav-link active" href="/experiments/">Experiments</a></li>
              <li class="nav-item"><a class="nav-link active" href="/status/">Status</a></li>
              <li class="nav-item"><a class="nav-link active" href="/doc/">Documentation</a></li>
              <li class="nav-item"><a class="nav-link active" href="/api/">API</a></li>
            </ul>
            <ul class="navbar-nav ms-auto">
              <% if defined?(@user) && @user %>
                <li class="nav-item dropdown">
                  <a class="nav-link dropdown-toggle" href="#" data-bs-toggle="dropdown" aria-expanded="false">
                    <%= @user.username %>
                  </a>
                  <ul class="dropdown-menu">
                    <li>
                      <a class="dropdown-item" href="/user/<%= @user.username %>">
                        Self Service panel
                      </a>
                    </li>
                    <li class="divider" style="margin: 0.25rem 0;"></li>
                    <li>
                      <a class="dropdown-item" href="/user/<%= @user.username %>/test">
                        Request Test
                      </a>
                    </li>
                    <li>
                      <a class="dropdown-item" href="/user/<%= @user.username %>/jobs">
                        Job History
                      </a>
                    </li>
                    <li>
                      <a class="dropdown-item" href="/user/<%= @user.username %>/keys">
                        Manage API keys
                      </a>
                    </li>
                    <% if @user.admin %>
                      <li>
                        <a class="dropdown-item" href="/admin/">
                          Admin Interface
                        </a>
                      </li>
                    <% end %>
                    <li>
                      <hr class="divider" style="margin: 0.25rem 0;">
                    </li>
                    <li>
                      <a class="dropdown-item" href="/user/logout">
                        Logout
                      </a>
                    </li>
                  </ul>
                </li>
              <% else %>
                <li class="nav-item"><a class="nav-link active" href="/user/login?original_url=<%= request.path %>">Login</a></li>
              <% end %>
            </ul>
          </div>
        </div>
      </nav>

      <% if notice != "" %>
        <div class="container">
          <%== notice %>
        </div>
      <% end %>

      <div class="main container">
        <%== yield %>
      </div>

      <div id="footer" class="border-top">
        <div class="container">
          <div class='row text-muted credit'>
            <p>
            debci - Copyright © 2014-<%= Time.now.year %> the debci development team. This is free
            software licensed under the GNU General Public License version 3 or
            later. Source code on
            <a href="https://salsa.debian.org/ci-team/debci">git repository</a>.
            Report bugs against
            <a href="https://bugs.debian.org/src:debci">debci on the Debian BTS</a>.
            </p>
          </div>
          <div class='row text-muted'>
            <form action="/user/theme/" method="POST">
              <div class="input-group input-group-sm">
                <span class="input-group-text">Theme: </span>
                <input type="submit" class="btn btn-<%= @theme == "light" && "" || "outline-" %>secondary" name="theme" value="light" />
                <input type="submit" class="btn btn-<%= @theme == "dark" && "" || "outline-" %>secondary" name="theme" value="dark" />
                <input type="submit" class="btn btn-<%= @theme.nil? && "" || "outline-" %>secondary" name="theme" value="auto" />
              </div>
            </form>
          </div>
          <div class='row text-muted'>
            This page was generated on <%= Time.now.utc.to_s %>
          </div>
        </div>
      </div>
    </div>

    <%== javascript_tag "/jquery.js" %>
    <%== javascript_tag "/jquery.flot.js" %>
    <%== javascript_tag "/jquery.flot.time.js" %>
    <%== javascript_tag "/jquery.flot.stack.js" %>
    <%== javascript_tag "/bootstrap/js/bootstrap.bundle.min.js" %>
    <%== javascript_tag "/app.js" %>
  </body>
</html>
