<!doctype html>
<html
  lang="en"
  class='color-scheme-<%= @user&.prefers_color_scheme || 'system' %>'
>
<head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
  <link rel="apple-touch-icon" sizes="57x57" href="/apple-touch-icon.png" />
  <link rel="apple-touch-icon" sizes="114x114" href="/apple-touch-icon.png" />
  <link rel="apple-touch-icon" sizes="72x72" href="/apple-touch-icon-144.png" />
  <link rel="apple-touch-icon" sizes="144x144" href="/apple-touch-icon-144.png" />
  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <meta name="referrer" content="always" />
  <meta name="theme-color" content="#AC130D" />
  <% if @meta_tags %>
    <% @meta_tags.each do |k,v| %>
      <meta name="<%= k %>" content="<%= v %>" />
    <% end %>
  <% end %>
  <link rel="shortcut icon" href="/favicon.ico" />
  <% if @short_url %>
    <link rev="canonical" rel="self alternate shorter shorturl shortlink"
      href="<%= @short_url %>" />
  <% end %>
  <title><%= @title.present? ? "#{@title} | " : "" %><%=
    Rails.application.name %></title>
  <%= stylesheet_link_tag "application", :media => "all" %>
  <% if @user %>
    <%= javascript_include_tag "application" %>
  <% end %>
  <%= csrf_meta_tags %>
  <% if @rss_link %>
    <link rel="alternate" type="application/rss+xml"
      title="<%= @rss_link[:title] %>" href="<%= @rss_link[:href] %>" />
  <% end %>
  <% if @comments_rss_link %>
    <link rel="alternate" type="application/rss+xml"
      title="<%= @comments_rss_link[:title] %>"
      href="<%= @comments_rss_link[:href] %>" />
  <% end %>
</head>
<body data-username='<%= @user.try(:username) %>'>
  <header id="nav">
    <a id="logo" style="<%= @traffic_style %>" href="/" title="<%= Rails.application.name %> (Current traffic: <%= @traffic_intensity.to_i %>%)"></a>

    <div class="navholder">
      <nav class="links">
        <%= link_to_different_page 'Active', active_path %>
        <%= link_to_different_page 'Recent', recent_path %>
        <%= link_to_different_page 'Comments', comments_path %>

        <% if @user && @user.can_submit_stories? %>
          <%= link_to_different_page 'Submit', new_story_path %>
        <% end %>

        <%= link_to_different_page 'Search', search_path %>


        <% if @user %>
          <% if @user.inbox_count > 0 %>
            <%= link_to raw("Inbox&nbsp;<span class='inbox_unread'>#{@user.inbox_count}</span>"), inbox_path, class: 'inbox corner' %>
          <% else %>
            <%= link_to "Inbox", inbox_path, class: 'inbox corner' %>
          <% end %>

          <%= link_to_different_page 'Threads', threads_path %>
          <%= link_to_different_page 'Saved', saved_path %>
          <%= link_to_different_page raw("#{@user.username}&nbsp;<span class='karma'>(#{@user.karma})</span>"), settings_path %>
        <% else %>
          <%= link_to_different_page 'Login', login_path, class: 'corner' %>
        <% end %>
      </nav>
    </div>

    <nav class="corner">
      <% if @user %>
        <% if @user.inbox_count > 0 %>
          <%= link_to raw("&#9993;&nbsp;<span class='inbox_unread'>#{@user.inbox_count}</span>"), inbox_path, class: 'inbox' %>
        <% else %>
          <%= link_to raw("&#9993;"), inbox_path, class: 'inbox' %>
        <% end %>
      <% else %>
        <%= link_to 'Login', login_path, class: 'corner' %>
      <% end %>
    </nav>
  </header>

  <% if content_for? :subnav %>
    <header id="subnav">
      <%= yield :subnav %>
    </header>
  <% end %>

  <div id="inside">
    <% if @title.present? && @title_h1 %>
      <h1 class="<%= @title_class %>"><%= @title %></h1>
    <% end %>

    <% [ :error, :success, :notice ].each do |f| %>
      <% if flash[f].present? %>
        <div class="flash-<%= f %>"><%= flash[f] %></div>
      <% end %>
    <% end %>

    <%= yield %>
  </div>

  <footer>
    <%= link_to 'About', about_path %>
    <% if !@user && Rails.application.open_signups? %>
      <a href="/invitations/open">Join <%= Rails.application.name %></a>
    <% end %>
    <% if @user && @user.can_see_invitation_requests? &&
          (iqc = InvitationRequest.verified_count) > 0 %>
      <a href="/invitations">Invitation Queue (<%= iqc %>)</a>
    <% end %>
    <%= link_to 'Tags', tags_path %>
    <% if @user && @user.is_moderator? && (hrc = HatRequest.count) > 0 %>
      <%= link_to "#{hrc} Hat Requests", hats_requests_path, class: 'mod' %>
    <% end %>
    <%= link_to 'Filter', filters_path %>
    <%= link_to 'Moderation Log', moderations_path %>
  </footer>
  <span id="iab-pcm-sdk"></span><span id="iab-autofill-sdk"></span>
</body>
</html>
