<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Documentation &bull; <%= appName %></title>
  <%- headAssets %>
  <link rel="stylesheet" href="<%= asset('assets/css/docs-module.css') %>">
</head>
<body>

  <%- topNav %>

  <main class="admin-container">

    <% for (const f of flashes) { %>
      <div class="flash-alert <%= f.type %>">
        <span><%= f.message %></span>
      </div>
    <% } %>

    <div class="page-header">
      <div>
        <h1 class="page-title">Documentation</h1>
        <p class="page-subtitle">Structured IT knowledge base, PRDs, technical guides, and change reports</p>
      </div>
      <div class="page-actions">
        <a href="<%= url('doc-categories') %>" class="btn btn-secondary">Category Documentation</a>
        <a href="<%= url('documentation/new') %>" class="btn btn-primary">+ Create Documentation</a>
      </div>
    </div>

    <div
      id="docCatalogRoot"
      data-endpoint="<%= url('api/documentations') %>"
      data-doc-base="<%= url('documentation') %>"
      data-asset-base="<%= url('') %>"
    >
      <div class="doc-filter-panel">
        <div class="filter-bar doc-search-bar">
          <div class="filter-left">
            <div class="search-wrap doc-search-wrap">
              <svg class="search-ico" width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true">
                <circle cx="11" cy="11" r="8"></circle>
                <line x1="21" y1="21" x2="16.65" y2="16.65"></line>
              </svg>
              <input
                type="search"
                id="docSearchInput"
                class="admin-search-input doc-search-input"
                value="<%= filters.search %>"
                placeholder="Search title, content, tags, or author..."
                aria-label="Search documentation"
                autocomplete="off"
              >
            </div>
          </div>

          <div>
            <span class="status-note" id="docResultCount"><%= docs.length %> document<%= docs.length === 1 ? '' : 's' %></span>
          </div>
        </div>

        <div class="doc-cat-tabs" id="docCategoryTabs" role="tablist" aria-label="Filter by documentation category">
          <button type="button" class="doc-tab-pill<%= !filters.category_id ? ' is-active' : '' %>" data-cat-id="" role="tab" aria-selected="<%= !filters.category_id ? 'true' : 'false' %>">All</button>
          <% for (const cat of categories) { %>
            <button type="button" class="doc-tab-pill<%= String(filters.category_id) === String(cat.id) ? ' is-active' : '' %>" data-cat-id="<%= Number(cat.id) %>" title="<%= cat.name %>" role="tab" aria-selected="<%= String(filters.category_id) === String(cat.id) ? 'true' : 'false' %>"><%= cat.code %></button>
          <% } %>
        </div>
      </div>

      <div class="doc-grid<%= docs.length ? '' : ' is-hidden' %>" id="docGrid">
        <% for (const d of docs) { %>
          <a class="doc-card card" href="<%= url('documentation/' + d.slug) %>">
            <div class="doc-card-cover">
              <% if (d.cover_image) { %>
                <img src="<%= url(d.cover_image) %>" alt="<%= d.title %>" loading="lazy">
              <% } else { %>
                <div class="doc-cover-fallback">
                  <span class="doc-cover-code"><%= d.category_code %></span>
                  <span class="doc-cover-sub"><%= d.category_name %></span>
                </div>
              <% } %>
            </div>

            <div class="doc-card-body">
              <div class="doc-card-badges">
                <span class="cat-pill"><%= d.category_code %> (<%= d.category_name %>)</span>
              </div>

              <h2 class="doc-card-title"><%= d.title %></h2>

              <% if (d.excerpt) { %>
                <p class="doc-card-excerpt"><%= d.excerpt %></p>
              <% } %>

              <% if (d.tag_list && d.tag_list.length) { %>
                <div class="doc-card-tags">
                  <% for (const tag of d.tag_list.slice(0, 3)) { %>
                    <span class="doc-tag-chip"><%= tag %></span>
                  <% } %>
                </div>
              <% } %>

              <div class="doc-card-meta">
                <span><%= Number(d.views_count || 0) %> x dilihat</span>
                <span aria-hidden="true">&middot;</span>
                <span><%= d.author_name %></span>
                <span aria-hidden="true">&middot;</span>
                <span><%= d.updated_at_label %></span>
              </div>
            </div>
          </a>
        <% } %>
      </div>

      <div class="empty-state<%= docs.length ? ' is-hidden' : '' %>" id="docEmptyState">
        <p class="doc-empty-title">No documentation found.</p>
        <p class="doc-empty-sub">Create your first IT document or adjust your search and category filter.</p>
        <a href="<%= url('documentation/new') %>" class="btn btn-primary btn-sm">+ Create Documentation</a>
      </div>
    </div>

  </main>

  <%- shellEnd %>
  <script src="<%= asset('assets/js/docs-catalog.js') %>"></script>
</body>
</html>
