{#- Write form, or the "you already reviewed this ATO" card when the viewer has a review. -#}
{% if own_review %}
<div class="ob-form ob-mine" id="write-review">
  <div class="ob-mine-head">
    <h3>You reviewed this ATO</h3>
    <p>{% if own_review.when_label %}Posted {{ own_review.when_label }}.{% endif %} You can edit within 15 minutes if you are on Trial, Pro or Founding. After 15 minutes you can delete this review (the quota is not refunded). You can replace it after 6 months.</p>
  </div>
  {% if not own_review.text %}
  <div class="ob-addtext">
    <p class="ob-hint">This rating is stars only. Only you can see it until you add a written review. Your stars stay locked.</p>
    <button type="button" class="ob-pill ob-sm primary ob-addtext-go">Add written review</button>
    <div class="ob-addtext-form" hidden>
      <label class="ob-field"><span>Written review</span><textarea class="ob-addtext-in" maxlength="1500" rows="5" placeholder="What should someone know?"></textarea></label>
      <p class="ob-wcount"><span class="n">0</span> / 1,500 · adding text does not use a quota</p>
      <div class="ob-actions"><button type="button" class="ob-pill ob-sm ob-addtext-cancel">Cancel</button><button type="button" class="ob-pill primary ob-addtext-post">Save text</button></div>
    </div>
  </div>
  {% endif %}
  <div class="ob-actions ob-mine-act">
    {% if can.edit %}<button type="button" class="ob-pill ob-sm ob-editrev">Edit</button>{% endif %}
    {% if can.delete %}<button type="button" class="ob-pill ob-sm ob-delrev">Delete</button>{% endif %}
  </div>
  <p class="ob-mine-msg" hidden role="status"></p>
</div>
{% else %}
{#- Write form in the locked v6 language. No step bar, no rule tags.
    16 Nov 2026 (MT: "Yes, change it"): Overall and the seven categories sit in ONE aligned grid.
    Label + hint on the left, five stars in one column, the number at the far right in one column.
    Overall = the average of the categories rated (REV-032); it is worked out, never picked. -#}
{% set overall = form_ratings.get('overall') %}
<div class="ob-card ob-form" id="write-review">
  <h3>Write a review</h3>
  <fieldset class="ob-rgrid" data-rgrid>
    <legend class="ob-ratehint" id="wr-hint">Rate any of seven, skip the rest. Tap a star again to clear it.</legend>
    <div class="ob-rg-row is-overall{% if overall %} is-set {{ 'is-hi' if overall >= 4 else 'is-lo' }}{% endif %}" data-overall>
      <div class="ob-rg-lab"><span class="ob-rg-name" id="wr-overall">Overall</span><small class="ob-rg-det">Average of the categories you rate</small></div>
      <div class="ob-rg-stars" role="img" aria-labelledby="wr-overall wr-overall-v">{{ svg.form_stars(overall or 0) }}</div>
      <output class="ob-rg-num" id="wr-overall-v" aria-live="polite">{% if overall %}{{ '%.1f'|format(overall) }}{% else %}–{% endif %}</output>
    </div>
    {% for key, label, detail in categories %}
    {% set val = form_ratings.get(key) %}
    <div class="ob-rg-row{% if val %} is-set {{ 'is-hi' if val >= 4 else 'is-lo' }}{% endif %}" data-cat="{{ key }}" data-v="{{ val or 0 }}">
      <div class="ob-rg-lab"><span class="ob-rg-name" id="wr-{{ key }}">{{ label }}</span><small class="ob-rg-det" id="wr-{{ key }}-d">{{ detail }}</small></div>
      <div class="ob-rg-stars ob-rg-pick" role="radiogroup" aria-labelledby="wr-{{ key }}" aria-describedby="wr-{{ key }}-d">{{ svg.form_pick(val or 0) }}</div>
      <output class="ob-rg-num" aria-hidden="true">{% if val %}{{ '%.1f'|format(val) }}{% else %}–{% endif %}</output>
    </div>
    {% endfor %}
  </fieldset>
  <div class="ob-field ob-ftext">
    <label for="wr-text">Your written review <em>(optional)</em></label>
    <textarea id="wr-text" placeholder="What should others know?" maxlength="1500" rows="4">{{ form_text }}</textarea>
    <p class="ob-wcount"><span data-words>{{ (form_text.split()|length) if form_text else 0 }}</span> / 150 words</p>
  </div>
  <div class="ob-field">
    <label for="wr-value">Value paid <em>(optional)</em></label>
    <input type="number" id="wr-value" name="fvalue" min="0" step="1" inputmode="decimal" placeholder="Amount in rand (ZAR)">
  </div>
  <div class="ob-field">
    <label for="wr-date">Training date <em>(optional)</em></label>
    <input type="month" id="wr-date" name="fdate" aria-label="Training month and year">
  </div>
  <div class="ob-field">
    <label for="wr-course">Course <em>(optional)</em></label>
    <input type="text" id="wr-course" name="fcourse" maxlength="80" placeholder="e.g. PPL, Night rating">
  </div>
  {% if anonymous_on %}
  <p class="ob-as">Posting as <span class="ob-as-n uname">Anonymous</span></p>
  {% else %}
  <p class="ob-as">Posting as <span class="uname">{{ poster_name }}</span></p>
  {% endif %}
  {% if can.anonymous %}
  <div class="ob-anonwrap{% if anonymous_on %} is-anon{% endif %}">
    <label class="ob-anon">
      <span class="ob-anon-ui">
        <span class="ob-anon-track" aria-hidden="true"><i></i></span>
        <input type="checkbox" class="ob-anon-c"{% if anonymous_on %} checked{% endif %}>
        <span class="ob-anon-copy"><em>Post anonymously</em><small>Name and badges stay hidden, forever.</small></span>
      </span>
    </label>
    <label class="ob-agree"><input type="checkbox" class="ob-agree-c"{% if anonymous_on %} checked{% endif %}><span>This review is honest and from my own experience, and follows the review rules. This stays Anonymous forever.</span></label>
  </div>
  {% else %}
  <label class="ob-anon is-locked">
    <span class="ob-anon-ui">
      <span class="ob-anon-track" aria-hidden="true"><i></i></span>
      <input type="checkbox" disabled>
      <span class="ob-anon-copy"><em>Post anonymously</em><small>Pro and Founding only. {{ 'Trial' if can.plan == 'trial' else 'Free' }} members post with their name.</small></span>
    </span>
  </label>
  {% endif %}
  <p class="ob-quota"><b>{{ can.quota_used }} of {{ can.quota }}</b> reviews used this cycle{% if can.cycle_resets %} · resets {{ can.cycle_resets }}{% endif %}</p>
  <div class="ob-actions"><button type="button" class="ob-pill primary ob-post"{% if not overall %} aria-disabled="true"{% endif %} aria-describedby="wr-post-hint">Post review</button></div>
  <p class="ob-post-hint" id="wr-post-hint"{% if overall %} hidden{% endif %}>Rate at least one category to post.</p>
</div>

{% endif %}
