{#- Edit Premium (MT, 20 Nov). An inert kit for paid, gifted and lapsed schools only; free pages never carry it.
    The page itself stays the guest view. The kit is cloned only after the server says this viewer may edit this school
    (`can_edit`: the owner, one of its staff seats, or Super Admin), or in a design preview with ?preview-edit=1.
    Content only: every section keeps its place, order and style. Locked: the SACAA record, the course list, ratings and reviews.
    Nothing here is sent anywhere; saving is the server's job (see the Notion page "Edit Premium — ATO page editing"). -#}
{% macro row(label, name, kind="text", max=None, ph="", hint=None, mono=False, wide=False, attrs="") -%}
{%- if kind == "date" -%}
{#- Our own day picker (shared/page.js .ga-cal), never the browser's: "12 Jan 2027", today or later, up to three years ahead. -#}
<div class="ek-f ga-cal{% if wide %} is-wide{% endif %}" data-cal="date" data-min="now" data-max="+3" data-hint="From today on"><span class="ek-l" aria-hidden="true">{{ label }}</span>
  <input type="hidden" name="{{ name }}" value="">
  <button type="button" class="ga-cal-btn" aria-haspopup="dialog" aria-expanded="false"><span class="ob-vh">{{ label }}, </span><span class="ga-cal-v is-ph" data-ph="{{ ph or 'Pick a day' }}">{{ ph or "Pick a day" }}</span><svg class="ga-cal-i" viewBox="0 0 24 24" aria-hidden="true"><rect x="4" y="5.5" width="16" height="14" rx="3"/><path d="M4 10h16M9 3.5v4M15 3.5v4"/></svg></button>
  {%- if hint %}<span class="ek-h">{{ hint }}</span>{% endif %}</div>
{%- else -%}
<label class="ek-f{% if wide %} is-wide{% endif %}"><span class="ek-l">{{ label }}</span>
  {%- if kind == "area" %}<textarea name="{{ name }}" rows="3"{% if max %} maxlength="{{ max }}"{% endif %} placeholder="{{ ph }}"></textarea>
  {%- elif kind == "rand" %}<span class="ek-rand"><span aria-hidden="true">R</span><input type="text" name="{{ name }}" inputmode="numeric" maxlength="9" placeholder="0" autocomplete="off"></span>
  {%- else %}<input type="{{ kind }}" name="{{ name }}"{% if max %} maxlength="{{ max }}"{% endif %} placeholder="{{ ph }}" autocomplete="off"{% if mono %} class="is-mono"{% endif %} {{ attrs|safe }}>{% endif %}
  {%- if hint %}<span class="ek-h">{{ hint }}</span>{% endif %}</label>
{%- endif %}
{%- endmacro %}
{% macro hour(name, label, value, off=False) -%}
<span class="ek-tsel"><select name="{{ name }}" aria-label="{{ label }}"{% if off %} disabled{% endif %}><option value=""{% if not value %} selected{% endif %}>&ndash;</option>
{%- for h in range(5, 24) %}{% for m in ("00", "30") %}{% set t = "%02d:%s"|format(h, m) %}{% if t <= "23:00" %}<option{% if t == value %} selected{% endif %}>{{ t }}</option>{% endif %}{% endfor %}{% endfor -%}
</select></span>
{%- endmacro %}
<template id="ob-edit-kit" data-slug="{{ edit_kit.slug }}"{% if edit_kit.lapsed %} data-lapsed{% endif %}>
  {% if edit_kit.lapsed %}
  <div class="ek-dock is-lapsed" role="region" aria-label="Your school page">
    <span class="ek-dot" aria-hidden="true"></span>
    <p class="ek-dock-t"><b>Premium has ended</b><span>Your page content is saved and hidden. It comes back the moment you renew.</span></p>
    <a class="ek-btn is-primary" href="/settings/#billing">Renew Premium</a>
  </div>
  {% else %}
  <div class="ek-dock" role="region" aria-label="Edit your school page">
    <span class="ek-dot" aria-hidden="true"></span>
    <p class="ek-dock-t"><b>Editing your page</b><span class="ek-role" data-role-label>Owner</span></p>
    <button type="button" class="ek-btn ek-peek" aria-pressed="false">View as visitor</button>
    <button type="button" class="ek-btn is-primary ek-done">Done</button>
  </div>

  {% for s in edit_kit.sections %}
  <div class="ek-slot" data-ek="{{ s.key }}"{% if s.filled %} data-filled{% endif %}>
    <div class="ek-slot-c">
      <p class="ek-slot-k">{{ s.label }}</p>
      <p class="ek-slot-w">{{ s.what }}</p>
      <p class="ek-slot-n">Only your team can see this until you save.</p>
    </div>
    <button type="button" class="ek-btn is-primary ek-open" data-ek="{{ s.key }}">Add</button>
  </div>
  {% endfor %}
  <button type="button" class="ek-edit ek-open" data-ek="" aria-label="Edit"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M4 20h4L19 9l-4-4L4 16v4Z"/><path d="m13.5 6.5 4 4"/></svg><span>Edit</span></button>
  {% for l in edit_kit.locked %}
  <p class="ek-lock" data-ek-lock="{{ l.key }}"><svg viewBox="0 0 24 24" aria-hidden="true"><rect x="5" y="11" width="14" height="9" rx="2"/><path d="M8 11V8a4 4 0 0 1 8 0v3"/></svg>Locked · {{ l.why }}</p>
  {% endfor %}

  <dialog class="ek-sheet" aria-labelledby="ek-sheet-h">
    <form method="dialog" class="ek-form" novalidate>
      <header class="ek-sh">
        <div><p class="ek-kicker">Edit content</p><h2 id="ek-sheet-h" class="ek-title">Section</h2></div>
        <button type="submit" value="cancel" class="ek-x" aria-label="Close"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M7 7l10 10M17 7 7 17"/></svg></button>
      </header>
      <p class="ek-rule">Content only. The layout, fonts and colours stay the same on every school page.</p>
      <div class="ek-body">
        <fieldset class="ek-set" data-ek="announcement" hidden>
          {{ row("Title", "title", max=120, ph="Night rating course opens in January", wide=True) }}
          {{ row("Text", "text", kind="area", max=1000, ph="A few lines about what is new.", wide=True) }}
          {{ row("Link (optional)", "url", kind="url", max=300, ph="https://", hint="A plain https address.", wide=True) }}
        </fieldset>
        <fieldset class="ek-set" data-ek="about" hidden>
          {{ row("Lead line", "lead", kind="area", max=300, ph="One sentence that sums up how you teach.", wide=True) }}
          {{ row("First paragraph", "p1", kind="area", max=700, wide=True) }}
          {{ row("Second paragraph", "p2", kind="area", max=700, wide=True) }}
          {{ row("Founded", "founded", kind="text", max=4, ph="2011", mono=True, attrs='inputmode="numeric"') }}
          {{ row("Instructors", "instructors", kind="text", max=3, ph="6", mono=True, attrs='inputmode="numeric"') }}
          {{ row("Students trained", "students_trained", kind="text", max=7, ph="420", mono=True, attrs='inputmode="numeric"') }}
          <div class="ek-f is-wide ek-photo"><span class="ek-l">Flight-line photo</span><button type="button" class="ek-btn ek-upload">Choose a photo</button><span class="ek-h">JPEG, PNG or WebP. Go Around checks every photo.</span></div>
          {{ row("Caption", "caption", max=200, wide=True) }}
          {{ row("Describe the photo", "alt", max=200, hint="Read aloud to people who can't see it.", wide=True) }}
        </fieldset>
        <fieldset class="ek-set" data-ek="fees" hidden>
          <div class="ek-rows" data-ek-rows>
            <div class="ek-item">
              <label class="ek-f is-wide"><span class="ek-l">Course</span><span class="ek-sel"><select name="course"><option value="">Choose from your courses</option>{% for c in edit_kit.courses %}<option>{{ c }}</option>{% endfor %}</select></span></label>
              {{ row("Fee", "fee", kind="rand") }}
              {{ row("Places", "seats", max=3, mono=True, ph="6", attrs='inputmode="numeric"') }}
              {{ row("What it includes", "includes", max=300, wide=True) }}
              {{ row("Next intake", "intake", kind="date", wide=True) }}
            </div>
          </div>
          <button type="button" class="ek-add">Add another course</button>
          <p class="ek-h is-block">Real fees in rand only. The course names come from your SACAA list.</p>
        </fieldset>
        <fieldset class="ek-set" data-ek="fleet" hidden>
          <div class="ek-rows" data-ek-rows>
            <div class="ek-item">
              {{ row("Aircraft type", "type", max=120, ph="Cessna 172S", wide=True) }}
              {{ row("How many", "count", max=3, mono=True, ph="4", attrs='inputmode="numeric"') }}
              <label class="ek-f ek-check"><input type="radio" name="featured"><span>Featured</span></label>
            </div>
          </div>
          <button type="button" class="ek-add">Add another type</button>
        </fieldset>
        <fieldset class="ek-set" data-ek="jobs" hidden>
          {{ row("Position", "title", max=120, ph="Grade II instructor", wide=True) }}
          {{ row("Details", "text", kind="area", max=1000, wide=True) }}
        </fieldset>
        <fieldset class="ek-set" data-ek="link" hidden>
          {{ row("Button text", "title", max=40, ph="Book a trial flight", wide=True) }}
          {{ row("Address", "url", kind="url", max=300, ph="https://", hint="Your own booking page. A plain https address.", wide=True) }}
        </fieldset>
        <fieldset class="ek-set" data-ek="contact" hidden>
          {{ row("Phone", "phone", kind="tel", max=20, mono=True, ph="+27 21 000 0000") }}
          {{ row("WhatsApp", "whatsapp", kind="tel", max=20, mono=True, ph="+27 82 000 0000") }}
          {{ row("Email", "email", kind="email", max=120, ph="flying@school.co.za", wide=True) }}
          {{ row("Address", "address", max=300, wide=True) }}
          <div class="ek-f is-wide"><span class="ek-l">Opening hours</span>
            <ul class="ek-hours">
              {% for d in ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"] %}
              <li><span class="ek-day">{{ d }}</span>{{ hour("open-%d"|format(loop.index0), d ~ " opens", "08:00" if loop.index0 < 6 else "", loop.index0 == 6) }}<span class="ek-to" aria-hidden="true"></span>{{ hour("close-%d"|format(loop.index0), d ~ " closes", "17:00" if loop.index0 < 5 else ("13:00" if loop.index0 == 5 else ""), loop.index0 == 6) }}<label class="ek-closed"><input type="checkbox" name="closed-{{ loop.index0 }}"{% if loop.index0 == 6 %} checked{% endif %}><span>Closed</span></label></li>
              {% endfor %}
            </ul>
          </div>
        </fieldset>
      </div>
      <footer class="ek-foot">
        <p class="ek-live">Goes live as soon as you save. Go Around checks every change.</p>
        <div class="ek-acts">
          <button type="submit" value="hide" class="ek-btn ek-hide" hidden>Hide section</button>
          <button type="submit" value="cancel" class="ek-btn">Cancel</button>
          <button type="submit" value="save" class="ek-btn is-primary">Save and publish</button>
        </div>
      </footer>
    </form>
  </dialog>
  <p class="ek-toast" role="status" aria-live="polite" hidden></p>
  {% endif %}
</template>
