{% extends 'aapayout/base.html' %}
{% load i18n %}

{% block details %}
<div class="container-fluid">
    <div class="row mb-4">
        <div class="col-12">
            <h2>{% translate "Edit Participant" %}: {{ participant.character.character_name }}</h2>
        </div>
    </div>

    <div class="row">
        <div class="col-md-8">
            <div class="card">
                <div class="card-header">
                    <h5>{% translate "Participant Information" %}</h5>
                </div>
                <div class="card-body">
                    <form method="post">
                        {% csrf_token %}

                        {% if form.non_field_errors %}
                        <div class="alert alert-danger">
                            {{ form.non_field_errors }}
                        </div>
                        {% endif %}

                        <div class="mb-3">
                            <label class="form-label">{% translate "Character" %}</label>
                            <input type="text" class="form-control" value="{{ participant.character.character_name }}" disabled>
                            <small class="form-text text-muted">{% translate "Character cannot be changed" %}</small>
                        </div>

                        <div class="mb-3">
                            <label for="{{ form.role.id_for_label }}" class="form-label">
                                {{ form.role.label }} <span class="text-danger">*</span>
                            </label>
                            {{ form.role }}
                            {% if form.role.errors %}
                                <div class="text-danger">{{ form.role.errors }}</div>
                            {% endif %}
                        </div>

                        <div class="mb-3">
                            <label for="{{ form.joined_at.id_for_label }}" class="form-label">
                                {{ form.joined_at.label }} <span class="text-danger">*</span>
                            </label>
                            {{ form.joined_at }}
                            {% if form.joined_at.errors %}
                                <div class="text-danger">{{ form.joined_at.errors }}</div>
                            {% endif %}
                        </div>

                        <div class="mb-3">
                            <label for="{{ form.left_at.id_for_label }}" class="form-label">
                                {{ form.left_at.label }}
                            </label>
                            {{ form.left_at }}
                            {% if form.left_at.errors %}
                                <div class="text-danger">{{ form.left_at.errors }}</div>
                            {% endif %}
                            <small class="form-text text-muted">{% translate "Leave empty if participant is still active" %}</small>
                        </div>

                        <div class="mb-3">
                            <label for="{{ form.notes.id_for_label }}" class="form-label">
                                {{ form.notes.label }}
                            </label>
                            {{ form.notes }}
                            {% if form.notes.errors %}
                                <div class="text-danger">{{ form.notes.errors }}</div>
                            {% endif %}
                        </div>

                        <div class="d-flex justify-content-between">
                            <a href="{% url 'aapayout:fleet_detail' participant.fleet.pk %}" class="btn btn-secondary">
                                <i class="fas fa-arrow-left"></i> {% translate "Cancel" %}
                            </a>
                            <button type="submit" class="btn btn-primary">
                                <i class="fas fa-save"></i> {% translate "Save Changes" %}
                            </button>
                        </div>
                    </form>
                </div>
            </div>
        </div>

        <div class="col-md-4">
            <div class="card border-info">
                <div class="card-header bg-info text-white">
                    <h5>{% translate "Participant Info" %}</h5>
                </div>
                <div class="card-body">
                    <dl class="row small">
                        <dt class="col-sm-5">{% translate "Fleet" %}:</dt>
                        <dd class="col-sm-7">
                            <a href="{% url 'aapayout:fleet_detail' participant.fleet.pk %}">
                                {{ participant.fleet.name }}
                            </a>
                        </dd>

                        <dt class="col-sm-5">{% translate "Status" %}:</dt>
                        <dd class="col-sm-7">
                            {% if participant.is_active %}
                                <span class="badge bg-success">{% translate "Active" %}</span>
                            {% else %}
                                <span class="badge bg-secondary">{% translate "Left" %}</span>
                            {% endif %}
                        </dd>

                        <dt class="col-sm-5">{% translate "Added" %}:</dt>
                        <dd class="col-sm-7">{{ participant.created_at|date:"Y-m-d H:i" }}</dd>
                    </dl>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}
