{% extends "base.html" %}

{% block title %}Nowa wiadomosc - Norda Biznes Partner{% endblock %}

{% block extra_css %}
<style>
    .compose-container {
        max-width: 700px;
        margin: 0 auto;
    }

    .compose-header {
        margin-bottom: var(--spacing-xl);
    }

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

    .compose-card {
        background: var(--surface);
        border-radius: var(--radius-lg);
        padding: var(--spacing-xl);
        box-shadow: var(--shadow);
    }

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

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

    .form-group input,
    .form-group select,
    .form-group textarea {
        width: 100%;
        padding: var(--spacing-sm) var(--spacing-md);
        border: 1px solid var(--border);
        border-radius: var(--radius);
        font-size: var(--font-size-base);
        transition: var(--transition);
    }

    .form-group input:focus,
    .form-group select:focus,
    .form-group textarea:focus {
        outline: none;
        border-color: var(--primary);
        box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
    }

    .form-actions {
        display: flex;
        gap: var(--spacing-md);
        margin-top: var(--spacing-xl);
    }

    .back-link {
        display: inline-flex;
        align-items: center;
        gap: var(--spacing-xs);
        color: var(--text-secondary);
        text-decoration: none;
        margin-bottom: var(--spacing-lg);
    }

    .back-link:hover {
        color: var(--primary);
    }

    .recipient-info {
        display: flex;
        align-items: center;
        gap: var(--spacing-md);
        padding: var(--spacing-md);
        background: var(--background);
        border-radius: var(--radius);
        margin-bottom: var(--spacing-lg);
    }

    .recipient-avatar {
        width: 48px;
        height: 48px;
        border-radius: 50%;
        background: var(--primary);
        color: white;
        display: flex;
        align-items: center;
        justify-content: center;
        font-weight: 600;
        font-size: var(--font-size-lg);
    }

    .recipient-name {
        font-weight: 500;
    }

    .recipient-email {
        font-size: var(--font-size-sm);
        color: var(--text-secondary);
    }
</style>
{% endblock %}

{% block content %}
<div class="compose-container">
    <a href="{{ url_for('messages_inbox') }}" class="back-link">
        <svg width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24">
            <path d="M19 12H5M12 19l-7-7 7-7"/>
        </svg>
        Powrot do wiadomosci
    </a>

    <div class="compose-header">
        <h1>Nowa wiadomosc</h1>
    </div>

    <div class="compose-card">
        {% if recipient %}
        <div class="recipient-info">
            <div class="recipient-avatar">{{ (recipient.name or recipient.email)[0].upper() }}</div>
            <div>
                <div class="recipient-name">{{ recipient.name or recipient.email.split('@')[0] }}</div>
                {% if recipient.privacy_show_email != False %}
                <div class="recipient-email">{{ recipient.email }}</div>
                {% endif %}
            </div>
        </div>
        {% endif %}

        <form method="POST" action="{{ url_for('messages_send') }}">
            <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">

            {% if recipient %}
            <input type="hidden" name="recipient_id" value="{{ recipient.id }}">
            {% else %}
            <div class="form-group">
                <label for="recipient_id">Do *</label>
                <select id="recipient_id" name="recipient_id" required>
                    <option value="">Wybierz odbiorcę...</option>
                    {% for user in users %}
                    <option value="{{ user.id }}">{{ user.name or user.email.split('@')[0] }}{% if user.privacy_show_email != False %} ({{ user.email }}){% endif %}</option>
                    {% endfor %}
                </select>
            </div>
            {% endif %}

            <div class="form-group">
                <label for="subject">Temat</label>
                <input type="text" id="subject" name="subject" maxlength="255" placeholder="Temat wiadomosci (opcjonalnie)">
            </div>

            <div class="form-group">
                <label for="content">Tresc *</label>
                <textarea id="content" name="content" rows="8" required placeholder="Napisz wiadomosc..."></textarea>
            </div>

            <div class="form-actions">
                <button type="submit" class="btn btn-primary">Wyslij</button>
                <a href="{{ url_for('messages_inbox') }}" class="btn btn-secondary">Anuluj</a>
            </div>
        </form>
    </div>
</div>
{% endblock %}
