{% extends "base.html" %}

{% block title %}{% if announcement %}Edytuj ogloszenie{% else %}Nowe ogloszenie{% endif %} - Norda Biznes Hub{% endblock %}

{% block extra_css %}
<style>
    .admin-header {
        margin-bottom: var(--spacing-xl);
    }

    .admin-header h1 {
        font-size: var(--font-size-3xl);
        color: var(--text-primary);
    }

    .form-section {
        background: var(--surface);
        padding: var(--spacing-xl);
        border-radius: var(--radius-lg);
        box-shadow: var(--shadow);
        max-width: 800px;
    }

    .form-group {
        margin-bottom: var(--spacing-lg);
    }

    .form-group label {
        display: block;
        margin-bottom: var(--spacing-xs);
        font-weight: 500;
        color: var(--text-primary);
    }

    .form-group input[type="text"],
    .form-group input[type="datetime-local"],
    .form-group select,
    .form-group textarea {
        width: 100%;
        padding: var(--spacing-sm) var(--spacing-md);
        border: 1px solid var(--border);
        border-radius: var(--radius-md);
        font-size: var(--font-size-base);
    }

    .form-group textarea {
        min-height: 200px;
        resize: vertical;
    }

    .form-row {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
        gap: var(--spacing-lg);
    }

    .checkbox-group {
        display: flex;
        gap: var(--spacing-lg);
        flex-wrap: wrap;
    }

    .checkbox-item {
        display: flex;
        align-items: center;
        gap: var(--spacing-xs);
    }

    .checkbox-item input[type="checkbox"] {
        width: 18px;
        height: 18px;
    }

    .form-hint {
        font-size: var(--font-size-sm);
        color: var(--text-secondary);
        margin-top: var(--spacing-xs);
    }

    .btn-group {
        display: flex;
        gap: var(--spacing-md);
        margin-top: var(--spacing-xl);
    }
</style>
{% endblock %}

{% block content %}
<div class="container">
    <div class="admin-header">
        <h1>{% if announcement %}Edytuj ogloszenie{% else %}Nowe ogloszenie{% endif %}</h1>
    </div>

    <div class="form-section">
        <form method="POST">
            <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">

            <div class="form-group">
                <label for="title">Tytul *</label>
                <input type="text" id="title" name="title" required
                       value="{{ announcement.title if announcement else '' }}"
                       placeholder="np. Informacja o skladkach za styczen 2026">
            </div>

            <div class="form-group">
                <label for="content">Tresc *</label>
                <textarea id="content" name="content" required
                          placeholder="Tresc ogloszenia...">{{ announcement.content if announcement else '' }}</textarea>
                <p class="form-hint">Mozesz uzyc podstawowego formatowania HTML.</p>
            </div>

            <div class="form-row">
                <div class="form-group">
                    <label for="type">Typ ogloszenia</label>
                    <select id="type" name="type">
                        <option value="general" {% if announcement and announcement.announcement_type == 'general' %}selected{% endif %}>Ogolne</option>
                        <option value="fees" {% if announcement and announcement.announcement_type == 'fees' %}selected{% endif %}>Skladki</option>
                        <option value="event" {% if announcement and announcement.announcement_type == 'event' %}selected{% endif %}>Wydarzenie</option>
                        <option value="important" {% if announcement and announcement.announcement_type == 'important' %}selected{% endif %}>Wazne</option>
                        <option value="urgent" {% if announcement and announcement.announcement_type == 'urgent' %}selected{% endif %}>Pilne</option>
                    </select>
                </div>
            </div>

            <div class="form-row">
                <div class="form-group">
                    <label for="publish_date">Data publikacji</label>
                    <input type="datetime-local" id="publish_date" name="publish_date"
                           value="{{ announcement.publish_date.strftime('%Y-%m-%dT%H:%M') if announcement and announcement.publish_date else '' }}">
                    <p class="form-hint">Pozostaw puste aby opublikowac natychmiast.</p>
                </div>

                <div class="form-group">
                    <label for="expire_date">Data wygasniecia</label>
                    <input type="datetime-local" id="expire_date" name="expire_date"
                           value="{{ announcement.expire_date.strftime('%Y-%m-%dT%H:%M') if announcement and announcement.expire_date else '' }}">
                    <p class="form-hint">Pozostaw puste aby nie wygasalo.</p>
                </div>
            </div>

            <div class="form-group">
                <label>Opcje</label>
                <div class="checkbox-group">
                    <label class="checkbox-item">
                        <input type="checkbox" name="is_published"
                               {% if announcement and announcement.is_published %}checked{% endif %}>
                        <span>Opublikowane</span>
                    </label>
                    <label class="checkbox-item">
                        <input type="checkbox" name="is_pinned"
                               {% if announcement and announcement.is_pinned %}checked{% endif %}>
                        <span>Przypiete (na gorze)</span>
                    </label>
                </div>
            </div>

            <div class="btn-group">
                <a href="{{ url_for('admin_announcements') }}" class="btn btn-secondary">Anuluj</a>
                <button type="submit" class="btn btn-primary">
                    {% if announcement %}Zapisz zmiany{% else %}Utworz ogloszenie{% endif %}
                </button>
            </div>
        </form>
    </div>
</div>
{% endblock %}
