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

{% block title %}Sponsors 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 {
        width: 100%;
        padding: 10px 12px;
        background: #0d0d0d;
        border: 1px solid #333;
        border-radius: 8px;
        color: #fff;
        font-size: 14px;
    }
    .form-input:focus {
        outline: none;
        border-color: #3b82f6;
    }
    .sponsors-grid {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
        gap: 24px;
    }
    .sponsor-card-admin {
        background: #1a1a1a;
        border: 1px solid #333;
        border-radius: 16px;
        padding: 24px;
    }
    .sponsor-logo-admin {
        width: 100%;
        height: 150px;
        object-fit: contain;
        margin-bottom: 16px;
        background: #0d0d0d;
        border-radius: 12px;
        padding: 16px;
    }
    .sponsor-name-admin {
        font-family: var(--font-display);
        font-size: 20px;
        color: var(--white);
        margin-bottom: 8px;
    }
    .sponsor-url-admin {
        color: var(--blue);
        font-family: var(--font-body);
        font-size: 14px;
        margin-bottom: 16px;
        word-break: break-all;
        text-decoration: none;
    }
    .sponsor-url-admin:hover {
        text-decoration: underline;
    }
    .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;
        width: 100%;
    }
    .btn-danger:hover {
        background: rgba(239, 68, 68, 0.3);
    }
</style>
{% endblock %}

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

<div class="section">
    <h2 class="section-title">Add New Sponsor</h2>
    <div class="add-form">
        <form method="POST" action="{{ url_for('add_sponsor') }}" enctype="multipart/form-data">
            <div class="form-row">
                <div class="form-group">
                    <label class="form-label">Sponsor Name</label>
                    <input type="text" name="name" class="form-input" required>
                </div>
                <div class="form-group">
                    <label class="form-label">Website URL</label>
                    <input type="url" name="website_url" class="form-input" placeholder="https://example.com" required>
                </div>
            </div>
            <div class="form-group">
                <label class="form-label">Logo Image</label>
                <input type="file" name="logo" class="form-input" accept="image/*" required>
            </div>
            <button type="submit" class="btn btn-primary">Add Sponsor</button>
        </form>
    </div>
</div>

<div class="section">
    <h2 class="section-title">Existing Sponsors</h2>
    <div class="sponsors-grid">
        {% for sponsor in sponsors %}
        <div class="sponsor-card-admin">
            {% if sponsor.logo_path %}
            <img src="{{ url_for('static', filename=sponsor.logo_path) }}" class="sponsor-logo-admin" alt="{{ sponsor.name }}">
            {% endif %}
            <h3 class="sponsor-name-admin">{{ sponsor.name }}</h3>
            {% if sponsor.website_url %}
            <a href="{{ sponsor.website_url }}" class="sponsor-url-admin" target="_blank">{{ sponsor.website_url }}</a>
            {% endif %}
            <form method="POST" action="{{ url_for('delete_sponsor') }}">
                <input type="hidden" name="id" value="{{ sponsor.id }}">
                <button type="submit" class="btn btn-danger" onclick="return confirm('Are you sure?')">Delete</button>
            </form>
        </div>
        {% endfor %}
    </div>
</div>
{% endblock %}
