{% extends "admin/base.html" %}

{% block title %}Competitions Management{% endblock %}

{% block extra_styles %}
<style>
    .section {
        margin-bottom: 48px;
    }
    .section-title {
        font-family: var(--font-display);
        font-size: 28px;
        color: var(--white);
        margin-bottom: 24px;
    }
    .add-form {
        background: #1a1a1a;
        border: 1px solid #333;
        border-radius: 16px;
        padding: 24px;
        margin-bottom: 32px;
    }
    .form-row {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 16px;
        margin-bottom: 16px;
    }
    .form-group {
        margin-bottom: 16px;
    }
    .form-label {
        display: block;
        color: var(--gray-300);
        margin-bottom: 6px;
        font-family: var(--font-body);
        font-size: 14px;
    }
    .form-input, .form-select, .form-textarea {
        width: 100%;
        padding: 10px 12px;
        background: #0d0d0d;
        border: 1px solid #333;
        border-radius: 8px;
        color: #fff;
        font-size: 14px;
    }
    .form-textarea {
        min-height: 100px;
        resize: vertical;
    }
    .form-input:focus, .form-select:focus, .form-textarea:focus {
        outline: none;
        border-color: var(--blue);
    }
    .competitions-list {
        display: flex;
        flex-direction: column;
        gap: 20px;
    }
    .comp-card {
        background: #1a1a1a;
        border: 1px solid #333;
        border-radius: 16px;
        padding: 24px;
    }
    .comp-header {
        display: flex;
        justify-content: space-between;
        align-items: start;
        margin-bottom: 16px;
    }
    .comp-title {
        font-family: var(--font-display);
        font-size: 22px;
        color: var(--white);
        margin-bottom: 4px;
    }
    .comp-meta {
        color: var(--gray-400);
        font-family: var(--font-body);
        font-size: 14px;
    }
    .comp-description {
        color: var(--gray-300);
        font-family: var(--font-body);
        margin-bottom: 12px;
        line-height: 1.6;
    }
    .comp-awards {
        color: var(--gray-400);
        font-family: var(--font-body);
        font-size: 14px;
    }
    .btn {
        padding: 10px 20px;
        border-radius: 8px;
        border: none;
        font-family: var(--font-body);
        font-size: 14px;
        cursor: pointer;
        transition: all 0.2s ease;
    }
    .btn-primary {
        background: var(--blue);
        color: var(--white);
    }
    .btn-primary:hover {
        background: var(--blue-light);
        transform: translateY(-2px);
    }
    .btn-danger {
        background: rgba(239, 68, 68, 0.2);
        color: #ef4444;
    }
    .btn-danger:hover {
        background: rgba(239, 68, 68, 0.3);
    }
    .info-text {
        color: var(--gray-400);
        font-family: var(--font-body);
        font-size: 13px;
        margin-top: 4px;
    }
</style>
{% endblock %}

{% block content %}
<h1 class="admin-header">Competitions Management</h1>

<div class="section">
    <h2 class="section-title">Add New Competition</h2>
    <div class="add-form">
        <form method="POST" action="{{ url_for('add_competition') }}" enctype="multipart/form-data">
            <div class="form-row">
                <div class="form-group">
                    <label class="form-label">Season</label>
                    <input type="text" name="season" class="form-input" placeholder="e.g., Into The Deep" list="seasons" required>
                    <datalist id="seasons">
                        {% for season in seasons %}
                        <option value="{{ season }}">
                        {% endfor %}
                    </datalist>
                </div>
                <div class="form-group">
                    <label class="form-label">Event Name</label>
                    <input type="text" name="event_name" class="form-input" required>
                </div>
            </div>
            <div class="form-group">
                <label class="form-label">Date</label>
                <input type="text" name="date" class="form-input" placeholder="e.g., 06/19/2025 or 11/11/23 - 01/06/24" required>
            </div>
            <div class="form-group">
                <label class="form-label">Description</label>
                <textarea name="description" class="form-textarea" required></textarea>
            </div>
            <div class="form-group">
                <label class="form-label">Awards (optional)</label>
                <textarea name="awards" class="form-textarea" placeholder="One award per line"></textarea>
                <p class="info-text">Enter each award on a new line</p>
            </div>
            <div class="form-group">
                <label class="form-label">Competition Image (optional)</label>
                <input type="file" name="image" class="form-input" accept="image/*">
            </div>
            <button type="submit" class="btn btn-primary">Add Competition</button>
        </form>
    </div>
</div>

<div class="section">
    <h2 class="section-title">Existing Competitions</h2>
    <div class="competitions-list">
        {% for comp in competitions %}
        <div class="comp-card">
            <div class="comp-header">
                <div>
                    <h3 class="comp-title">{{ comp.event_name }}</h3>
                    <p class="comp-meta">{{ comp.season }} · {{ comp.date }}</p>
                </div>
                <form method="POST" action="{{ url_for('delete_competition') }}">
                    <input type="hidden" name="id" value="{{ comp.id }}">
                    <button type="submit" class="btn btn-danger" onclick="return confirm('Are you sure?')">Delete</button>
                </form>
            </div>
            <p class="comp-description">{{ comp.description }}</p>
            {% if comp.awards %}
            <p class="comp-awards">🏆 {{ comp.awards|replace('|', ' · ') }}</p>
            {% endif %}
        </div>
        {% endfor %}
    </div>
</div>
{% endblock %}
