<%- include('../../partials/adminTopbar', {
  pageTitle: 'Edit robots.txt',
  pageSubtitle: 'Crawler rules for search engines',
  topbarActions: `<a href="/robots.txt" target="_blank" rel="noopener noreferrer" class="btn-ghost text-xs">View robots.txt</a><a href="/sitemap.xml" target="_blank" rel="noopener noreferrer" class="btn-ghost text-xs">sitemap.xml</a>`
}) %>

<main class="admin-main flex-1 overflow-y-auto overflow-x-hidden" id="robots-edit">
  <% if (typeof flash !== 'undefined' && flash) { %>
  <div class="admin-flash admin-flash-<%= flashType === 'error' ? 'error' : 'success' %> mb-4"><%= flash %></div>
  <% } %>

  <form action="/admin/robots" method="post" id="robots-form">
    <div class="grid grid-cols-1 xl:grid-cols-3 gap-6">
      <div class="xl:col-span-2 space-y-5">
        <div class="card">
          <label class="form-label" for="robots-content">robots.txt content</label>
          <p class="text-xs mb-3" style="color:rgba(255,255,255,.4);line-height:1.65">
            Plain robots.txt text — changes apply immediately at
            <a href="/robots.txt" target="_blank" rel="noopener noreferrer" style="color:#a78bfa">/robots.txt</a>.
          </p>
          <textarea
            name="content"
            id="robots-content"
            class="form-input"
            rows="24"
            dir="ltr"
            style="font-family:Consolas,monospace;font-size:13px;text-align:left;min-height:480px"
            spellcheck="false"
            required
          ><%= typeof content !== 'undefined' ? content : '' %></textarea>
        </div>
      </div>

      <div class="space-y-5">
        <div class="card">
          <p class="text-sm font-semibold text-white mb-3">Status</p>
          <p class="text-xs" style="color:rgba(255,255,255,.45);line-height:1.7;margin:0">
            <% if (typeof source !== 'undefined' && source === 'custom') { %>
            Custom file is active.
            <% } else { %>
            Using default content (no custom file saved yet).
            <% } %>
          </p>
        </div>

        <div class="card">
          <p class="text-sm font-semibold text-white mb-3">File path</p>
          <p class="text-xs font-mono" style="color:rgba(255,255,255,.45);direction:ltr;text-align:left">
            <%= typeof robotsFile !== 'undefined' && robotsFile.relativePath ? robotsFile.relativePath : 'data/robots.txt' %>
          </p>
        </div>

        <div class="card">
          <p class="text-sm font-semibold text-white mb-3">Help</p>
          <ul class="text-xs space-y-2" style="color:rgba(255,255,255,.45);line-height:1.65;list-style:disc;padding-left:18px">
            <li>The previous version is backed up automatically before saving.</li>
            <li>Keep the <code class="text-[11px]">Sitemap:</code> line to reference sitemap.xml.</li>
            <li>Paths like <code class="text-[11px]">/admin</code> and <code class="text-[11px]">/auth</code> should usually be Disallow.</li>
          </ul>
        </div>

        <div class="card space-y-3">
          <button type="submit" class="btn-primary w-full justify-center">Save</button>
          <a href="/robots.txt" target="_blank" rel="noopener noreferrer" class="btn-ghost w-full justify-center">View robots.txt</a>
          <button
            type="submit"
            form="robots-reset-form"
            class="btn-ghost w-full justify-center"
            onclick="return confirm('Reset to default content?')"
          >Reset to default</button>
        </div>
      </div>
    </div>
  </form>

  <form action="/admin/robots/reset" method="post" id="robots-reset-form" hidden></form>
</main>
