<% content_for :title, "Sanasto Wiki" %>

<div class="min-h-screen flex flex-col">
  <header class="bg-white border-b border-slate-200">
    <div class="max-w-7xl mx-auto px-4">
      <div class="h-16 flex items-center justify-between">
        <div class="flex items-center gap-2">
          <span class="text-xl font-bold tracking-tight text-indigo-600">Sanasto</span>
          <span class="text-xl font-light text-slate-400">Wiki</span>
        </div>
        <div class="flex items-center gap-3">
          <%= link_to "Download XLSX", download_entries_path(format: :xlsx),
                      class: "text-xs font-bold text-indigo-700 px-3 py-2 rounded-md border border-indigo-200 bg-indigo-50 hover:bg-indigo-100 transition" %>
          <% if admin? %>
            <%= link_to "Admin", admin_root_path, class: "bg-indigo-600 text-white px-4 py-2 rounded-lg text-sm font-semibold hover:bg-indigo-700 transition" %>
          <% else %>
            <%= link_to "Sign In", login_path, class: "bg-indigo-600 text-white px-4 py-2 rounded-lg text-sm font-semibold hover:bg-indigo-700 transition" %>
          <% end %>
        </div>
      </div>
    </div>
  </header>


  <div class="flex-1 flex flex-col">
    <section id="search">
      <div class="max-w-7xl mx-auto px-4 pb-1 space-y-4">
        <%= render "entries/search_form" %>

        <div id="entries_filters" class="hidden">
          <%= render "entries/filters" %>
        </div>
      </div>
    </section>

    <div id="entries_results">
      <%= render "entries/results" %>
    </div>

  </div>
</div>

<script>
  document.addEventListener("click", function (event) {
    const toggle = event.target.closest("[data-toggle-filters]");
    if (!toggle) {
      return;
    }

    const panel = document.getElementById("entries_filters");
    if (!panel) {
      return;
    }

    const isHidden = panel.classList.toggle("hidden");
    toggle.setAttribute("aria-expanded", (!isHidden).toString());
    toggle.textContent = isHidden ? "Show Filters" : "Hide Filters";
  });
</script>
