{% extends "group_admin/base.html" %}
{% block title %}Privacy Policy{% endblock %}

{% block content %}
<div class="row justify-content-center">
  <div class="col-lg-9">

    <h2 class="mb-1"><i class="bi bi-file-earmark-lock2 me-2"></i>Server Privacy Policy</h2>
    <p class="text-muted mb-4">
      Write your Minecraft server's privacy policy here. Players will be shown this page when
      the <strong>MCConsent</strong> plugin asks them to consent before playing.
    </p>

    {# ── Public URL banner ────────────────────────────────────── #}
    {% if public_url %}
    <div class="alert alert-info d-flex align-items-center gap-2 mb-4">
      <i class="bi bi-link-45deg fs-5 flex-shrink-0"></i>
      <div>
        <strong>Public URL</strong> — paste this into your <code>consent-plugin/config.yml</code>
        as the <code>policy-url</code> value:<br>
        <code id="publicUrl">{{ public_url }}</code>
        <button class="btn btn-sm btn-outline-light ms-2" onclick="navigator.clipboard.writeText('{{ public_url }}')">
          <i class="bi bi-clipboard"></i> Copy
        </button>
      </div>
    </div>
    {% else %}
    <div class="alert alert-secondary mb-4">
      <i class="bi bi-info-circle me-2"></i>
      Save the policy once to generate a secret public URL.
    </div>
    {% endif %}

    {# ── Last updated ─────────────────────────────────────────── #}
    {% if policy and policy.updated_at %}
    <p class="text-muted small">Last updated: {{ policy.updated_at.strftime('%Y-%m-%d %H:%M UTC') }}</p>
    {% endif %}

    {# ── Editor form ──────────────────────────────────────────── #}
    <form method="post">
      <input type="hidden" name="_csrf_token" value="{{ csrf_token() }}">

      <div class="mb-3">
        <label for="policy_url" class="form-label fw-semibold">
          Additional / External Policy URL <span class="text-muted fw-normal">(optional)</span>
        </label>
        <input type="url" class="form-control font-monospace"
               id="policy_url" name="policy_url" maxlength="500"
               placeholder="https://your-website.example.com/privacy"
               value="{{ (policy.policy_url or '') if policy else '' }}">
        <div class="form-text">
          If you host a full policy on your own website you can link it here. It will be
          displayed as a button on the public policy page.
        </div>
      </div>

      <div class="mb-3">
        <label for="policy_text" class="form-label fw-semibold">Policy Text</label>
        <textarea class="form-control font-monospace" id="policy_text" name="policy_text"
                  rows="24" placeholder="Enter your privacy policy here…"
                  style="resize: vertical;">{{ (policy.policy_text or '') if policy else '' }}</textarea>
        <div class="form-text">
          Plain text or basic Markdown is accepted. HTML is <strong>not</strong> rendered.
        </div>
      </div>

      <div class="d-flex gap-2">
        <button type="submit" class="btn btn-warning">
          <i class="bi bi-floppy me-1"></i>Save Policy
        </button>
        {% if policy %}
        <a href="{{ public_url }}" target="_blank" class="btn btn-outline-light">
          <i class="bi bi-box-arrow-up-right me-1"></i>Preview public page
        </a>
        {% endif %}
      </div>
    </form>

  </div>
</div>
{% endblock %}
