{#- Reviews band with the approved rating card (REV-061). Guest top 3 by counted aged upvotes. -#}
{% from "parts/badges.j2" import pilot_name, school_name, licences %}
<section class="ob-sec ob-revs">
  <div class="ob-hrow"><h2 class="ob-h">Reviews</h2><p class="ob-hs">Most helpful</p></div>
  {#- Option A: the card no longer repeats the hero's score, the review total or the certificate count. -#}
  {% if ato.rating.count %}
  <div class="ob-ratebanner">
    <div class="ob-card ob-ratewide is-noscore{% if not rating_shown %} is-wait{% endif %}">
      {% if rating_shown %}
      <div class="ob-ratechips">
        <span class="ob-ratechip"><b>{{ written_count }}</b> {{ 'Written review' if written_count == 1 else 'Written reviews' }}</span>
        <span class="ob-ratechip"><b>{{ rated_hi if rated_hi is not none else '–' }}</b> Rated 4.0+</span>
      </div>
      <div class="ob-ratewide-bars">
        {% for b in star_bars %}
        <div class="ob-bar"><span>{{ b.k }}</span><i><s style="transform:scaleX({{ b.frac }})"></s></i><b>{{ b.c }}</b></div>
        {% endfor %}
      </div>
      {% else %}
      <p class="ob-wait">{% if ato.rating.count >= min_reviews %}Stars and the 5-to-1 breakdown appear once {{ min_reviews }} reviewers have held their accounts for 7 days.{% else %}Stars and the 5-to-1 breakdown appear at {{ min_reviews }} reviews.{% endif %} Until then, read what members wrote.</p>
      {% endif %}
    </div>
    {% if cat_rows %}{% include "parts/rating_categories.j2" %}{% endif %}
  </div>
  {% endif %}
  <div class="ob-list-r">
  {% if top %}
  {% for group in (review_sections if review_sections is defined else [{'title': none, 'reviews': top}]) %}
  {% if group.title %}<section class="ob-old-reviews"><h3 class="ob-h">{{ group.title }}</h3>{% endif %}
  {% for r in group.reviews %}
    <article class="ob-review{% if r.author.anonymous %} is-anon{% endif %}" data-id="{{ r.id }}">
      <div class="ob-rtop{% if r.author.anonymous %} is-anon{% endif %}">{% if not r.author.anonymous %}<span class="ob-av">{{ r.author.name[:2]|upper }}</span>{% endif %}
        <div class="ob-who"><h3>{{ pilot_name(r.author) }}</h3>{{ licences(r.author) }}</div><time>{{ r.when_label }}</time></div>
      <div class="ob-rscore">{{ svg.score_line(r.stars, r.stars is not none) }}{% if r.edited %}<span class="ob-edtag">Edited{% if r.get('edited_at') %} {{ (nice_month if r.author.anonymous else nice_date)(r.get('edited_at')) }}{% endif %}</span>{% endif %}</div>
      {% if r.get('duplicate') %}<p class="ob-rtext">This older review is retained as history and is excluded from the school's rating.</p>{% endif %}
      {% if r.title %}<h4>{{ r.title }}</h4>{% endif %}
      {% if r.text %}<p class="ob-rtext">{{ r.text }}</p>{% else %}<p class="ob-rtext is-none">Stars only, no written review.</p>{% endif %}
      {% if r.extras %}<p class="ob-rextra">{% for x in r.extras %}{% if not loop.first %}<span class="ob-rx-sep" aria-hidden="true"> · </span>{% endif %}<span class="ob-rx-{{ x.key }}"><span class="ob-vh">{{ x.label }}: </span>{{ x.text }}</span>{% endfor %}</p>{% endif %}
      {% if r.get('privacy_redacted') %}<p class="ob-edtag">Private details removed by moderation.</p>{% endif %}
      {% set reps = r.official_replies if verified else r.official_replies|rejectattr('own')|list %}
      {% if reps %}
      <div class="ob-thread">
        <button type="button" class="ob-ttg" aria-expanded="false"><span class="a">{{ 'View 1 reply' if reps|length == 1 else 'View %d replies'|format(reps|length) }}</span><span class="b">Hide replies</span><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M9 6l6 6-6 6"/></svg></button>
        <div class="ob-tbody" hidden><div class="ob-replies">
        {% for p in reps %}
          <div class="ob-reply is-{{ 'own' if p.own else 'other' }}"><strong>{{ school_name(p.school, paid if p.own else p.paid) }}</strong><small>{{ 'This ATO' if p.own else 'Another verified ATO' }} · {{ nice_date(p.when) }}</small><p>{{ p.text }}</p>{% if p.get('privacy_redacted') %}<small>Private details removed by moderation.</small>{% endif %}</div>
        {% endfor %}
        </div></div>
      </div>
      {% endif %}
    </article>
  {% endfor %}
  {% if group.title %}</section>{% endif %}
  {% endfor %}
  {% else %}
    <p class="ob-empty">No reviews yet. Sign up to review.</p>
  {% endif %}
  </div>
  {% if more > 0 %}
  <div class="ob-gate"><div class="ob-skel" aria-hidden="true"><i></i><i></i><i></i><i></i></div><div class="ob-gate-c"><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 018 0v3"/></svg><h3>Sign in to see the rest</h3><p>{{ more }} more {{ 'review' if more == 1 else 'reviews' }}, and voting after you sign in. Free account.</p><a class="ob-pill primary" href="{{ signin_href }}">Sign in free</a></div></div>
  {% endif %}
  {% include "parts/review_fields.j2" %}
</section>
