<!DOCTYPE html>
<html lang="<%= params[:locale] %>">
<head>
  <title><%= content_for?(:title) ? content_for(:title) : site_name %></title>
  <% if content_for?(:description) %><meta name="description" value="<%= content_for(:description) %>"><% end %>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <%= vite_client_tag %>
  <%= vite_javascript_tag 'application' %>
  <% if @caching_request %>
    <%= PageCache::CSRF_META_TAGS %>
  <% else %>
    <%= csrf_meta_tags %>
  <% end %>
  <% if defined?(@bots) %>
    <meta name="robots" content="<%= @bots %>">
  <% end %>
  <% if greasy? %>
    <meta name="clckd" content="bf6242cc3039bff31a7815dff8ee247b" />
    <meta name="lhverifycode" content="32dc01246faccb7f5b3cad5016dd5033" />
  <% else %>
    <meta name="clckd" content="1eb37c8f8f91e75152a85f734fdb0867" />
  <% end %>
  <link rel="canonical" href="<%= canonical_url(@canonical_params) %>">
  <link rel="icon" href="<%= vite_asset_path('images/blacklogo16.png') %>">
  <%= non_blocking_stylesheet_tag('https://fonts.googleapis.com/css?family=Open+Sans&display=swap') unless Rails.env.test? %>
  <% valid_request_for_locale_switch = request.get? && !@routing_error %>
  <% if valid_request_for_locale_switch
    # https://support.google.com/webmasters/answer/189077
    alternate_url_without_locale = current_path_with_params(locale: 'XX').sub(/\A\/XX/, '') %>
    <link rel="alternate" hreflang="x-default" href="<%= current_path_with_params(locale: nil) %>">
    <% available_locales_for_domain.each do |code| %>
      <link rel="alternate" hreflang="<%= code %>" href="/<%= code %><%= alternate_url_without_locale %>">
    <% end
  end %>

  <% if defined?(@link_alternates)
    @link_alternates.each do |la| %>
      <link rel="alternate" type="<%= la[:type] %>" href="<%= la[:url] %>" <% if !la[:title].nil? %> title="<%= la[:title] %>"<% end %>>
    <% end
  end %>

  <link rel="search" href="<%= opensearch_description_path %>" type="application/opensearchdescription+xml" title="<%= t('opensearch.short_name', site_name: site_name, default: t('opensearch.short_name', site_name: site_name, locale: 'en')) %>" hreflang="<%= I18n.locale %>">

  <% if Rails.env.production? %>
    <% gtm_id = if sleazy?
                  'G-ZB1G3ZKC89'
                elsif cn_greasy?
                  'G-49Z8J2WT6B'
                else
                  'G-7NMRNRYW7C'
                end %>
    <!-- Global site tag (gtag.js) - Google Analytics -->
    <script async src="https://www.googletagmanager.com/gtag/js?id=<%= gtm_id %>"></script>
    <script>
      window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('js', new Date());
      gtag('config', '<%= gtm_id %>', {
        'ad_method': '<%= @ad_method&.tracking_key || ("_status_#{response.code}" if response.code != '200') %>',
        'ad_method_variant': '<%= @ad_method&.variant %>',
        'action': '<%= j controller_name %>/<%= j action_name %>'
      });
    </script>
  <% end %>

  <% if @ad_method&.ea? %>
    <script async src="https://media.ethicalads.io/media/client/ethicalads.min.js" onerror="if (typeof gtag !== 'undefined') { gtag('event', 'EthicalAds placement', { 'ea_campaign_type': '(error)' })};switchToEaFallback()"></script>
  <% elsif @ad_method&.ga? %>
    <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-2247465624637408"
            crossorigin="anonymous"></script>
  <% end %>

  <% if content_for(:head_bottom) %><%= yield(:head_bottom) %><% end %>
</head>
<body>

  <header id="main-header">
    <div class="width-constraint">
      <div id="site-name">
        <%= link_to_unless_current(vite_image_tag('images/blacklogo96.png', alt: '', width: 96, height: 96), root_path) %>
        <div id="site-name-text">
          <h1><%= link_to_unless_current site_name, root_path %></h1>
        </div>
      </div>
      <div id="site-nav">
        <div id="nav-user-info">
          <% if user_signed_in? %>
            <% if current_user.moderator? %>
              <%= render partial: 'layouts/moderator_notices' %>
            <% end %>
            <% if notification_widget_count %>
              <%= link_to notification_widget_count, notifications_path(current_user), class: 'notification-widget' %>
            <% end %>
            <span class="user-profile-link"><%= link_to(current_user.name, current_user) %></span>
            <span class="sign-out-link">[ <%= link_to t('users.sign_out'), destroy_user_session_path, method: :delete %> ]</span>
          <% else %>
            <span class="sign-in-link"><%= link_to(t('layouts.application.sign_in'), new_user_session_path(request.get? ? {return_to: @return_to || request.fullpath} : {}), {rel: 'nofollow'}) %></span>
          <% end %>

          <% locale_selector = capture do %>
            <% form_action = valid_request_for_locale_switch ? current_path_with_params(locale: nil) : root_path({locale: nil}) %>
            <form class="language-selector" action="<%= form_action %>">
              <% user_with_locale = !current_user.nil? && !current_user.locale.nil?
              locale_with_override_param = user_with_locale ? '1' : nil
              switch_url_without_locale = current_path_with_params(locale: 'XX', locale_override: locale_with_override_param).delete_prefix('/XX') if valid_request_for_locale_switch %>
              <select class="language-selector-locale" name="locale" data-translate-url="<%= Rails.configuration.help_translate_url %>">
                <% site_locales(in_locale: request_locale).each do |code, name|
                  if valid_request_for_locale_switch %>
                    <option data-language-url="/<%= code %><%= switch_url_without_locale %>" value="<%= code %>"<% if params[:locale] == code %> selected<% end %>>
                      <%= name %> (<%= code %>)
                    </option>
                  <% else %>
                    <option data-language-url="<%= root_path({locale: code, locale_override: locale_with_override_param}) %>" value="<%= code %>"<% if params[:locale] == code %> selected<% end %>>
                      <%= name %> (<%= code %>)
                    </option>
                  <% end
                end %>
                <option value="help">Help us translate!</option>
              </select><input class="language-selector-submit" type="submit" value="→">
              <% if user_with_locale %>
                <input type="hidden" name="locale_override" value="1">
              <% end %>
            </form>
          <% end %>
          <%= locale_selector %>
        </div>
        <nav>
          <li class="scripts-index-link"><%= link_to(t('layouts.application.script_list'), scripts_path) %></li>
          <% unless cn_greasy? %>
            <li class="forum-link"><%= link_to(t('layouts.application.forum'), discussions_path) %></li>
          <% end %>
          <li class="help-link"><%= link_to(t('layouts.application.help'), help_path) %></li>
          <li class="with-submenu">
            <a href="#" onclick="return false"><%= t('layouts.application.submenu') %></a>
            <nav>
              <li><%= link_to t('layouts.application.advanced_search'), search_path %></li>
              <li><%= link_to t('layouts.application.user_list'), users_path %></li>
              <li><%= link_to t('layouts.application.libraries'), libraries_scripts_path %></li>
              <li><%= link_to t('layouts.application.moderator_log'), moderator_actions_path %></li>
            </nav>
          </li>
        </nav>
      </div>

      <div id="mobile-nav">
        <div class="mobile-nav-opener">☰</div>
        <nav class="collapsed">
          <li class="scripts-index-link"><%= link_to(t('layouts.application.script_list'), scripts_path) %></li>
          <li class="forum-link"><%= link_to(t('layouts.application.forum'), discussions_path) %></li>
          <li class="help-link"><%= link_to(t('layouts.application.help'), help_path) %></li>
          <li><%= link_to t('layouts.application.advanced_search'), search_path %></li>
          <li><%= link_to t('layouts.application.user_list'), users_path %></li>
          <li><%= link_to t('layouts.application.libraries'), libraries_scripts_path %></li>
          <li><%= link_to t('layouts.application.moderator_log'), moderator_actions_path %></li>
          <% if user_signed_in? %>
            <li class="multi-link-nav">
              <% if current_user.moderator? %>
                <%= render partial: 'layouts/moderator_notices' %>
              <% end %>
              <% if notification_widget_count %>
                <%= link_to notification_widget_count, notifications_path(current_user), class: 'notification-widget' %>
              <% end %>
              <span class="user-profile-link"><%= link_to(current_user.name, current_user) %></span>
              <span class="sign-out-link">[ <%= link_to t('users.sign_out'), destroy_user_session_path, method: :delete %> ]</span>
            </li>
          <% else %>
            <li class="multi-link-nav">
              <span class="sign-in-link"><%= link_to(t('layouts.application.sign_in'), new_user_session_path(request.get? ? {return_to: @return_to || request.fullpath} : {}), {rel: 'nofollow'}) %></span>
            </li>
          <% end %>
          <li><%= locale_selector %></li>
        </nav>
      </div>

      <script>
        /* submit is handled by js if enabled */
        document.querySelectorAll(".language-selector-submit").forEach((lss) => { lss.style.display = "none" })
      </script>
    </div>
  </header>

  <div class="width-constraint">
    <% if @announcement %>
      <div class="announcement">
        <%= @announcement.content.is_a?(String) ? @announcement.content : instance_exec(&@announcement.content) %>
        <% if @announcement.dismissable %>
          <%= form_with(url: dismiss_announcement_path(key: @announcement.key), data: { turbo: true, turbo_method: :POST }, id: 'announcement-dismiss') do |f| %>
            <%= f.submit '✖' %>
          <% end %>
        <% end %>
      </div>
    <% end %>
    <% if notice %>
      <p class="notice"><%= flash[:html_safe] ? notice.html_safe : notice %></p>
    <% end %>
    <% if alert %>
      <p class="alert"><%= flash[:html_safe] ? alert.html_safe : alert %></p>
    <% end %>

    <%= content_for?(:content) ? yield(:content) : yield %>
  </div>

  <% unless general_ads_setting&.no_ads? %>
    <script>
      (function (d) {
      window.rum = {key: '29razx6j'};
      var script = d.createElement('script');
      script.src = 'https://cdn.perfops.net/rom3/rom3.min.js';
      script.type = 'text/javascript';
      script.defer = true;
      script.async = true;
      d.getElementsByTagName('head')[0].appendChild(script);
      })(document);
    </script>
  <% end %>
</body>
</html>
