{% extends "admin_base.html" %}
{% block title %}Edit Registration | Nexora Admin{% endblock %}
{% block content %}
<div class="admin-head">
  <p class="eyebrow">Edit Registration</p>
  <h1>{{ row.full_name }}</h1>
  <p>Manage player details, payment status, ticket serial, and QR token from here.</p>
</div>

<section class="admin-panel">
  <form class="admin-form registration-edit-form" method="post" enctype="multipart/form-data">
    <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
    <div class="form-grid">
      <label>Full Name<input name="full_name" value="{{ row.full_name }}" required></label>
      <label>Email<input type="email" name="email" value="{{ row.email }}" required></label>
      <label>Mobile Number<input name="phone" value="{{ row.phone }}" required></label>
      <label>CNIC<input name="cnic" value="{{ row.cnic }}" required></label>
      <label>Institution Type
        <select name="institution_type" required>
          {% for item in ['University', 'College', 'School', 'Academy', 'Open'] %}
          <option value="{{ item }}" {% if (row.institution_type or 'University') == item %}selected{% endif %}>{{ item }}</option>
          {% endfor %}
        </select>
      </label>
      <label>Institution Name<input name="university" value="{{ row.university }}" required></label>
      <label>Roll No / Student ID<input name="roll_no" value="{{ row.roll_no or '' }}"></label>
      <label>Game
        <select name="game_id" required>
          {% for game in games %}
          <option value="{{ game.id }}" {% if row.game_id == game.id %}selected{% endif %}>{{ game.title }} — {{ game.platform }}</option>
          {% endfor %}
        </select>
      </label>
      <label>Entry Type
        <select name="entry_type" required>
          <option value="individual" {% if row.entry_type == 'individual' %}selected{% endif %}>Individual</option>
          <option value="group" {% if row.entry_type == 'group' %}selected{% endif %}>Group / Team</option>
        </select>
      </label>
      <label>Payment Method<input name="payment_method" value="{{ row.payment_method }}"></label>
      <label>Payment Status
        <select name="payment_status">
          <option value="under_verification" {% if row.payment_status == 'under_verification' %}selected{% endif %}>Under Verification</option>
          <option value="unpaid" {% if row.payment_status == 'unpaid' %}selected{% endif %}>Unpaid / Pending</option>
          <option value="paid" {% if row.payment_status == 'paid' %}selected{% endif %}>Paid / Approved</option>
          <option value="partial" {% if row.payment_status == 'partial' %}selected{% endif %}>Partial Payment</option>
          <option value="refunded" {% if row.payment_status == 'refunded' %}selected{% endif %}>Refunded</option>
        </select>
      </label>
      <label>Amount Paid<input name="amount_paid" value="{{ row.amount_paid or '' }}" placeholder="e.g. Rs. 1,500"></label>
      <label>Transaction / Reference ID<input name="transaction_reference" value="{{ row.transaction_reference or '' }}" placeholder="Bank / wallet reference"></label>
      <label>Ticket Serial<input name="ticket_serial" value="{{ row.ticket_serial }}" readonly><span class="field-hint">System-generated unique serial</span></label>
      <label>Team Name<input name="team_name" value="{{ row.team_name or '' }}"></label>
      <label>Leader Name<input name="leader_name" value="{{ row.leader_name or '' }}"></label>
      <label class="full">Team Members
        <textarea name="members" rows="6" placeholder="Member 1: Name | email@example.com | 03xx">{{ row.members or '' }}</textarea>
      </label>
      <label class="full">Replace Payment Screenshot
        <input type="file" name="proof_image" accept="image/*">
        {% if row.proof_image %}<span class="field-hint">Current file: {{ row.proof_image }}</span>{% endif %}
      </label>
      <label class="check full">
        <input type="checkbox" name="regenerate_token" value="1">
        Regenerate QR token
      </label>
    </div>

    <div class="form-actions">
      <button class="btn primary" type="submit"><i class="fas fa-floppy-disk"></i> Save Registration</button>
      <a class="btn outline" href="{{ url_for('registration_view', reg_id=row.id) }}"><i class="fas fa-eye"></i> View</a>
      <a class="btn outline" href="{{ url_for('admin_registrations') }}"><i class="fas fa-arrow-left"></i> Back</a>
    </div>
  </form>
</section>
{% endblock %}
