{% extends "admin_base.html" %}
{% block title %}Leadership Quotes | Nexora Admin{% endblock %}
{% block content %}
<div class="admin-head">
  <p class="eyebrow">Leadership</p>
  <h1>CEO / Secretary / Director Quotes</h1>
  <p>Manage leadership messages shown on the homepage with photos. Lower sort order appears first.</p>
</div>

{% if can('leadership_create') %}
<section class="admin-panel">
  <h2><i class="fas fa-plus"></i> Add New Person</h2>
  <form class="admin-form" method="post" enctype="multipart/form-data">
    <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
    <label>Full Name<input name="name" placeholder="e.g. Ahmed Khan" required></label>
    <label>Designation<input name="role" placeholder="Sports CEO / Secretary / Director" required></label>
    <label>Sort Order<input type="number" name="sort_order" value="0" min="0"></label>
    <label>Photo <span class="field-hint">(square best)</span><input type="file" name="image" accept="image/*"></label>
    <label class="full">Quote<textarea name="quote" rows="3" placeholder="Their message or quote..." required></textarea></label>
    <label class="check"><input type="checkbox" name="active" checked> Show on website</label>
    <button class="btn primary" type="submit"><i class="fas fa-plus"></i> Add Person</button>
  </form>
</section>
{% endif %}

<section class="admin-panel">
  <h2><i class="fas fa-quote-left"></i> Current Entries</h2>
  {% if leaders %}
  <div class="admin-card-grid compact-admin-grid">
    {% for leader in leaders %}
    <article class="mini-admin-card compact-manage-card leader-manage-card">
      <div class="leader-admin-summary">
        {% set ld_img = img(leader.image) if leader.image else '' %}
        {% if ld_img %}
        <img class="thumb contain" src="{{ url_for('serve_media', filename=ld_img) }}" alt="{{ leader.name }}">
        {% else %}
        <span class="admin-avatar">{{ leader.name[:1] | upper }}</span>
        {% endif %}
        <div>
          <h3>{{ leader.name }}</h3>
          <p>{{ leader.role }}</p>
          <span class="badge {{ 'paid' if leader.active else 'neutral' }}">{{ 'Visible' if leader.active else 'Hidden' }}</span>
        </div>
      </div>
      <p class="admin-quote-preview">{{ leader.quote }}</p>
      <div class="compact-actions">
        {% if can('leadership_update') %}
        <button class="btn outline small" type="button" data-toggle-edit><i class="fas fa-pen"></i> Edit</button>
        <form method="post" action="{{ url_for('delete_leader', leader_id=leader.id) }}" data-confirm="Delete {{ leader.name }}?">
          <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
          <button class="danger-link small" type="submit"><i class="fas fa-trash"></i> Delete</button>
        </form>
        {% endif %}
      </div>
      <form method="post" action="{{ url_for('update_leader', leader_id=leader.id) }}" enctype="multipart/form-data"
        class="admin-inline-edit" hidden>
        <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
        <label>Name<input name="name" value="{{ leader.name }}" required></label>
        <label>Designation<input name="role" value="{{ leader.role }}" required></label>
        <label>Quote<textarea name="quote" rows="4" required>{{ leader.quote }}</textarea></label>
        <label>Sort Order<input type="number" name="sort_order" value="{{ leader.sort_order }}" min="0"></label>
        <label>Replace Photo<input type="file" name="image" accept="image/*"></label>
        <label class="check"><input type="checkbox" name="active" {% if leader.active %}checked{% endif %}> Show on
          website</label>
        {% if can('leadership_delete') %}
        <button class="btn primary small" type="submit"><i class="fas fa-floppy-disk"></i> Save Changes</button>
        {% endif %}
      </form>
    </article>
    {% endfor %}
  </div>
  {% else %}
  <div class="empty"><i class="fas fa-quote-left"></i>No entries yet. Add a CEO, Secretary, or Director above.
  </div>
  {% endif %}
</section>
{% endblock %}
