<aside class="flex flex-col min-h-screen w-[250px] bg-dark text-white px-3 py-4 rounded-r-lg overflow-y-auto lg:block" data-nav-target="nav" style="scrollbar-width: none; -ms-overflow-style: none;">
  <div class="space-y-4">
    <% flash.each do |name, msg| %>
      <% next if name.to_sym == :application_secret %>
      <%
        c =
          case name.to_sym
          when :notice, :success
            'flash-message--success'
          else
            'flash-message--error'
          end
      %>
      <div class="flash-message flash-message--enter <%= c %>" data-controller="flash"><%= msg %></div>
    <% end %>

    <% if current_user %>
      <div class="flex flex-col items-center gap-2 pb-3 border-b border-darkless">
        <%= render 'shared/user_mention', user: current_user %>
        <%= render 'static_pages/streak', user: current_user, show_text: true, turbo_frame: false %>
        <% if current_user.admin_level != 0 %>
          <%= render 'static_pages/admin_level', user: current_user %>
        <% end %>
      </div>
    <% else %>
      <div>
        <%= link_to 'Sign in', signin_path, class: 'block px-4 py-2 rounded-md transition text-white font-semibold bg-primary hover:bg-secondary text-center' %>
      </div>
    <% end %>

    <nav class="space-y-1">
      <div>
        <%= link_to root_path, class: "block px-3 py-2 rounded-md text-sm transition-colors #{current_page?(root_path) ? 'bg-primary text-white font-bold' : 'hover:bg-darkless'}", data: { action: "click->nav#clickLink" } do %>
          Home
        <% end %>
      </div>

      <div>
        <%= link_to leaderboards_path, class: "block px-3 py-2 rounded-md text-sm transition-colors #{current_page?(leaderboards_path) ? 'bg-primary text-white font-bold' : 'hover:bg-darkless'}", data: { action: "click->nav#clickLink" } do %>
          Leaderboards
        <% end %>
      </div>

      <% unless current_user %>
        <div>
          <%= link_to docs_path, class: "block px-3 py-2 rounded-md text-sm transition-colors #{current_page?(docs_path) || request.path.start_with?('/docs') ? 'bg-primary text-white font-bold' : 'hover:bg-darkless'}", data: { action: "click->nav#clickLink" } do %>
            Docs
          <% end %>
        </div>

        <div>
          <%= link_to extensions_path, class: "block px-3 py-2 rounded-md text-sm transition-colors #{current_page?(extensions_path) ? 'bg-primary text-white font-bold' : 'hover:bg-darkless'}", data: { action: "click->nav#clickLink" } do %>
            Extensions
          <% end %>
        </div>

      <% end %>

      <% if current_user %>
        <div>
          <%= link_to my_projects_path, class: "block px-3 py-2 rounded-md text-sm transition-colors #{current_page?(my_projects_path) ? 'bg-primary text-white font-bold' : 'hover:bg-darkless'}", data: { action: "click->nav#clickLink" } do %>
            Projects
          <% end %>
        </div>

        <div>
          <%= link_to docs_path, class: "block px-3 py-2 rounded-md text-sm transition-colors #{current_page?(docs_path) || request.path.start_with?('/docs') ? 'bg-primary text-white font-bold' : 'hover:bg-darkless'}", data: { action: "click->nav#clickLink" } do %>
            Docs
          <% end %>
        </div>

        <div>
          <%= link_to extensions_path, class: "block px-3 py-2 rounded-md text-sm transition-colors #{current_page?(extensions_path) ? 'bg-primary text-white font-bold' : 'hover:bg-darkless'}", data: { action: "click->nav#clickLink" } do %>
            Extensions
          <% end %>
        </div>

        <div>
          <%= link_to my_settings_path, class: "block px-3 py-2 rounded-md text-sm transition-colors #{current_page?(my_settings_path) ? 'bg-primary text-white font-bold' : 'hover:bg-darkless'}", data: { action: "click->nav#clickLink" } do %>
            Settings
          <% end %>
        </div>

        <div>
          <%= link_to oauth_applications_path, class: "block px-3 py-2 rounded-md text-sm transition-colors #{current_page?(oauth_applications_path) || request.path.start_with?('/oauth/applications') ? 'bg-primary text-white font-bold' : 'hover:bg-darkless'}", data: { action: "click->nav#clickLink" } do %>
            My OAuth Apps
          <% end %>
        </div>

        <div>
          <a type="button" onclick="showLogout()" class="w-full text-left block px-3 py-2 rounded-md text-sm transition-colors hover:bg-darkless">Logout</a>
        </div>
      <% end %>

      <% if current_user&.admin_level.present? || Rails.env.development? %>
        <div class="pt-2 mt-2 border-t border-darkless space-y-1">
          <% dev_tool(nil, "div") do %>
            <%= link_to letter_opener_web_path, class: "block px-3 py-2 rounded-md text-sm transition-colors #{current_page?(letter_opener_web_path) ? 'bg-primary text-white font-bold' : 'hover:bg-darkless'}", data: { action: "click->nav#clickLink" } do %>
              Letter Opener
            <% end %>
          <% end %>

          <% dev_tool(nil, "div") do %>
            <%= link_to '/rails/mailers', class: "block px-3 py-2 rounded-md text-sm transition-colors #{current_page?('/rails/mailers') ? 'bg-primary text-white font-bold' : 'hover:bg-darkless'}", data: { action: "click->nav#clickLink" } do %>
              Mailers
            <% end %>
          <% end %>

          <% if current_user&.admin_level == "admin" || current_user&.admin_level == "superadmin" %>
            <% admin_tool(nil, "div") do %>
              <%= link_to admin_timeline_path, class: "block px-3 py-2 rounded-md text-sm transition-colors #{current_page?(admin_timeline_path) ? 'bg-primary text-white font-bold' : 'hover:bg-darkless'}", data: { action: "click->nav#clickLink" } do %>
                Review Timeline
              <% end %>
            <% end %>
          <% elsif current_user&.admin_level == "viewer" %>
            <% viewer_tool(nil, "div") do %>
              <%= link_to admin_timeline_path, class: "block px-3 py-2 rounded-md text-sm transition-colors #{current_page?(admin_timeline_path) ? 'bg-primary text-white font-bold' : 'hover:bg-darkless'}", data: { action: "click->nav#clickLink" } do %>
                Review Timeline
              <% end %>
            <% end %>
          <% end %>

          <% if current_user&.admin_level == "admin" || current_user&.admin_level == "superadmin" %>
            <% admin_tool(nil, "div") do %>
              <%= link_to admin_trust_level_audit_logs_path, class: "block px-3 py-2 rounded-md text-sm transition-colors #{current_page?(admin_trust_level_audit_logs_path) || request.path.start_with?('/admin/trust_level_audit_logs') ? 'bg-primary text-white font-bold' : 'hover:bg-darkless'}", data: { action: "click->nav#clickLink" } do %>
                Trust Level Logs
              <% end %>
            <% end %>
          <% elsif current_user&.admin_level == "viewer" %>
            <% viewer_tool(nil, "div") do %>
              <%= link_to admin_trust_level_audit_logs_path, class: "block px-3 py-2 rounded-md text-sm transition-colors #{current_page?(admin_trust_level_audit_logs_path) || request.path.start_with?('/admin/trust_level_audit_logs') ? 'bg-primary text-white font-bold' : 'hover:bg-darkless'}", data: { action: "click->nav#clickLink" } do %>
                Trust Level Logs
              <% end %>
            <% end %>
          <% end %>

          <% if current_user&.admin_level == "admin" || current_user&.admin_level == "superadmin" %>
            <% admin_tool(nil, "div") do %>
              <%= link_to admin_admin_api_keys_path, class: "block px-3 py-2 rounded-md text-sm transition-colors #{current_page?(admin_admin_api_keys_path) || request.path.start_with?('/admin/admin_api_keys') ? 'bg-primary text-white font-bold' : 'hover:bg-darkless'}", data: { action: "click->nav#clickLink" } do %>
                Admin API Keys
              <% end %>
            <% end %>
          <% elsif current_user&.admin_level == "viewer" %>
            <% viewer_tool(nil, "div") do %>
              <%= link_to admin_admin_api_keys_path, class: "block px-3 py-2 rounded-md text-sm transition-colors #{current_page?(admin_admin_api_keys_path) || request.path.start_with?('/admin/admin_api_keys') ? 'bg-primary text-white font-bold' : 'hover:bg-darkless'}", data: { action: "click->nav#clickLink" } do %>
                Admin API Keys
              <% end %>
            <% end %>
          <% end %>

          <% superadmin_tool(nil, "div") do %>
            <%= link_to admin_admin_users_path, class: "block px-3 py-2 rounded-md text-sm transition-colors #{current_page?(admin_admin_users_path) ? 'bg-primary text-white font-bold' : 'hover:bg-darkless'}", data: { action: "click->nav#clickLink" } do %>
              Admin Management
            <% end %>
          <% end %>

          <% superadmin_tool(nil, "div") do %>
            <%= link_to admin_deletion_requests_path, class: "block px-3 py-2 rounded-md text-sm transition-colors #{current_page?(admin_deletion_requests_path) ? 'bg-primary text-white font-bold' : 'hover:bg-darkless'}", data: { action: "click->nav#clickLink" } do %>
              Account Deletions
              <% pending_count = DeletionRequest.pending.count %>
              <% if pending_count > 0 %>
                <span class="ml-1 px-1.5 py-0.5 text-xs rounded-full bg-primary text-white font-medium"><%= pending_count %></span>
              <% end %>
            <% end %>
          <% end %>

          <% superadmin_tool(nil, "div") do %>
            <%= link_to good_job_path, class: "block px-3 py-2 rounded-md text-sm transition-colors #{current_page?(good_job_path) ? 'bg-primary text-white font-bold' : 'hover:bg-darkless'}", data: { action: "click->nav#clickLink" } do %>
              GoodBoy
            <% end %>
          <% end %>

          <% superadmin_tool(nil, "div") do %>
            <%= link_to admin_oauth_applications_path, class: "block px-3 py-2 rounded-md text-sm transition-colors #{current_page?(admin_oauth_applications_path) || request.path.start_with?('/admin/oauth_applications') ? 'bg-primary text-white font-bold' : 'hover:bg-darkless'}", data: { action: "click->nav#clickLink" } do %>
              All OAuth Apps
            <% end %>
          <% end %>

          <% superadmin_tool(nil, "div") do %>
            <%= link_to flipper_path, class: "block px-3 py-2 rounded-md text-sm transition-colors #{current_page?(flipper_path) ? 'bg-primary text-white font-bold' : 'hover:bg-darkless'}", data: { action: "click->nav#clickLink" } do %>
              Feature Flags
            <% end %>
          <% end %>
        </div>
      <% end %>
    </nav>
  </div>
</aside>
