<!DOCTYPE html>
<html lang="<%= I18n.default_locale %>">
  <head>
    <title><%= ENV.fetch('OPERUM_BASE_TITLE', 'Operum') %></title>
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <meta name="author" content="Miquel Sabaté Solà">

    <meta name="description" content="<%= I18n.t('meta.description') %>">
    <% if I18n.default_locale == :ca %>
      <meta property="og:locale" content="ca_ES" />
    <% else %>
      <meta property="og:locale" content="en_US" />
    <% end %>
    <meta property="og:url" content="https://github.com/mssola/operum" />
    <meta property="og:title" content="<%= ENV.fetch('OPERUM_BASE_TITLE', 'Operum') %>" />
    <meta property="og:description" content="<%= I18n.t('meta.description') %>" />

    <link rel="alternate" hreflang="<%= I18n.default_locale %>" href="<%= request.base_url %>">

    <%= csrf_meta_tags %>
    <%= csp_meta_tag %>

    <%= stylesheet_link_tag "application", "data-turbo-track": "reload" %>
    <%= javascript_importmap_tags %>

    <!-- favicon -->
    <link rel="icon" href="/favicon.ico" sizes="16x16">
    <link rel="icon" href="/favicon-32x32.png" sizes="32x32" type="image/png">
    <link rel="apple-touch-icon" href="/apple-touch-icon.png">
    <link rel="manifest" href="/manifest.webmanifest">
  </head>

  <body>
    <% if current_user && @searches %>
      <header data-controller="header">
        <nav>
          <a class="<%= 'current' if current_user.last_search_id.nil? %>" href="/"><%= I18n.t('searches.home') %></a>
          <% @searches.each do |s| %>
            <a class="<%= 'current' if current_user.last_search_id == s.id %>" href="<%= search_path(s) %>"><%= s.name %></a>
          <% end %>
          <a id="toggle-hidden-global-menu" href="#" data-action="header#toggle"><i id="header-chevron" class="gg-chevron-down"></i></a>
        </nav>

        <div id="hidden-nav" class="hidden">
          <div class="flex-wrap">
            <span><%= I18n.t('general.create').capitalize %>: </span>
            <%= link_to I18n.t('searches.object'), new_search_path %>
            <%= link_to I18n.t('things.object'), new_thing_path %>
          </div>

          <div class="flex-wrap">
            <span><%= I18n.t('searches.title') %>: </span>
            <% if @search&.id %>
              <%= link_to I18n.t('general.edit'), edit_search_path(@search) %>
              <%= link_to I18n.t('general.delete'), search_path(@search), data: { turbo_confirm: I18n.t('general.sure'), turbo_method: :delete } %>
            <% end %>

            <%= link_to I18n.t('searches.export.action'), new_search_exports_path(current_user.last_search_id ? current_user.last_search_id : '0') %>
          </div>

          <div class="flex-wrap">
            <span><%= I18n.t('general.list').capitalize %>: </span>
            <%= link_to I18n.t('tags.title').downcase, tags_path %>
            <%= link_to I18n.t('searches.shared.title').downcase, shared_searches_path %>
          </div>
        </div>
      </header>
    <% end %>

    <main>
      <% if flash[:notice] %>
        <div class="notice">
          <span><%= flash[:notice] %>.</span>
        </div>
      <% end %>

      <% if flash[:alert] %>
        <div class="notice">
          <span><%= flash[:alert] %>.</span>
        </div>
      <% end %>

      <%= yield %>
    </main>

    <footer>
      <p>
        <%= I18n.t('layout.created-by') %> <a href="http://jo.mssola.com/">Miquel Sabaté Solà</a>
        <br>
        <%= I18n.t('layout.this-page-license') %> <a href="/license">AGPLv3</a> (<a href="https://github.com/mssola/operum"><%= I18n.t('layout.source-code') %></a>)
        <% if current_user %>
          <br>
          <%= link_to I18n.t('sessions.sign-out'), sessions_path, data: { turbo_method: :delete } %>
        <% end %>
      </p>
    </footer>
  </body>
</html>
