<%- include("../../../src/web/views/partials/layout-top", { title }) %>
<section class="card">
  <%- include("../../../src/web/views/partials/page-header", {
    eyebrow: "Knowledge",
    pageTitle: "OKF Knowledge",
    description: "Browse curated community facts, help answers, and role-aware support knowledge."
  }) %>
  <form method="get" action="/plugins/okf" class="log-controls">
    <label>
      <span>Search</span>
      <input name="q" value="<%= filters.q %>" placeholder="Search questions, facts, or topics" />
    </label>
    <label>
      <span>Category</span>
      <select name="category">
        <option value="">All categories</option>
        <% categories.forEach((category) => { %>
        <option value="<%= category %>" <%= filters.category === category ? "selected" : "" %>><%= category %></option>
        <% }) %>
      </select>
    </label>
    <label>
      <span>Tag</span>
      <select name="tag">
        <option value="">All tags</option>
        <% tags.forEach((tag) => { %>
        <option value="<%= tag %>" <%= filters.tag === tag ? "selected" : "" %>><%= tag %></option>
        <% }) %>
      </select>
    </label>
    <button class="button subtle" type="submit">Search</button>
    <a class="button subtle" href="/plugins/okf">Reset</a>
  </form>
</section>

<section class="card">
  <div class="section-header">
    <div>
      <h2>Knowledge entries</h2>
      <p class="hint"><%= entries.length %> visible entr<%= entries.length === 1 ? "y" : "ies" %>.</p>
    </div>
    <% if (okfAccess.canEdit) { %>
    <a class="button subtle" href="/plugins/okf/admin">Manage OKF</a>
    <% } %>
  </div>
  <% if (!entries.length) { %>
  <div class="empty-state">No OKF entries match this filter.</div>
  <% } else { %>
  <div class="table-wrap">
    <table class="table">
      <thead>
        <tr>
          <th>Entry</th>
          <th>Category</th>
          <th>Tags</th>
          <th>Updated</th>
        </tr>
      </thead>
      <tbody>
        <% entries.forEach((entry) => { %>
        <tr>
          <td>
            <a href="<%= entry.href || `/plugins/okf/${encodeURIComponent(entry.slug)}` %>"><strong><%= entry.title %></strong></a>
            <% if (entry.source_kind === "community_file") { %>
            <span class="badge">Community file</span>
            <% } %>
            <p class="hint"><%= entry.summary || "No summary provided." %></p>
          </td>
          <td><%= entry.category || "General" %></td>
          <td>
            <% (entry.tags || []).forEach((tag) => { %>
            <span class="badge"><%= tag %></span>
            <% }) %>
          </td>
          <td><%= new Date(entry.updated_at).toLocaleString() %></td>
        </tr>
        <% }) %>
      </tbody>
    </table>
  </div>
  <% } %>
</section>
<%- include("../../../src/web/views/partials/layout-bottom") %>
