{% extends "base.html" %}

{% block title %}Wyslane wiadomosci - Norda Biznes Partner{% endblock %}

{% block extra_css %}
<style>
    .messages-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: var(--spacing-xl);
    }

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

    .messages-tabs {
        display: flex;
        gap: var(--spacing-md);
        margin-bottom: var(--spacing-lg);
    }

    .tab-link {
        padding: var(--spacing-sm) var(--spacing-lg);
        border-radius: var(--radius);
        text-decoration: none;
        color: var(--text-secondary);
        font-weight: 500;
        transition: var(--transition);
    }

    .tab-link:hover {
        background: var(--background);
        color: var(--text-primary);
    }

    .tab-link.active {
        background: var(--primary);
        color: white;
    }

    .messages-list {
        background: var(--surface);
        border-radius: var(--radius-lg);
        box-shadow: var(--shadow);
        overflow: hidden;
    }

    .message-item {
        display: flex;
        align-items: center;
        padding: var(--spacing-md) var(--spacing-lg);
        border-bottom: 1px solid var(--border);
        text-decoration: none;
        color: inherit;
        transition: var(--transition);
    }

    .message-item:last-child {
        border-bottom: none;
    }

    .message-item:hover {
        background: var(--background);
    }

    .message-avatar {
        width: 40px;
        height: 40px;
        border-radius: 50%;
        background: var(--secondary);
        color: white;
        display: flex;
        align-items: center;
        justify-content: center;
        font-weight: 600;
        margin-right: var(--spacing-md);
        flex-shrink: 0;
    }

    .message-content {
        flex: 1;
        min-width: 0;
    }

    .message-subject {
        font-size: var(--font-size-base);
        color: var(--text-primary);
        margin-bottom: var(--spacing-xs);
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .message-preview {
        font-size: var(--font-size-sm);
        color: var(--text-secondary);
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .message-meta {
        text-align: right;
        flex-shrink: 0;
        margin-left: var(--spacing-md);
    }

    .message-date {
        font-size: var(--font-size-sm);
        color: var(--text-secondary);
    }

    .message-to {
        font-size: var(--font-size-sm);
        color: var(--text-primary);
        font-weight: 500;
    }

    .empty-state {
        text-align: center;
        padding: var(--spacing-2xl);
        color: var(--text-secondary);
    }

    .read-status {
        font-size: var(--font-size-xs);
        color: var(--success);
    }

    .pagination {
        display: flex;
        justify-content: center;
        gap: var(--spacing-sm);
        margin-top: var(--spacing-xl);
    }

    .pagination a {
        padding: var(--spacing-sm) var(--spacing-md);
        border-radius: var(--radius);
        text-decoration: none;
        color: var(--text-secondary);
        background: var(--surface);
        border: 1px solid var(--border);
    }

    .pagination a:hover {
        background: var(--background);
    }

    .pagination a.active {
        background: var(--primary);
        color: white;
        border-color: var(--primary);
    }
</style>
{% endblock %}

{% block content %}
<div class="messages-header">
    <h1>Wyslane wiadomosci</h1>
    <a href="{{ url_for('messages_new') }}" class="btn btn-primary">Nowa wiadomosc</a>
</div>

<div class="messages-tabs">
    <a href="{{ url_for('messages_inbox') }}" class="tab-link">Odebrane</a>
    <a href="{{ url_for('messages_sent') }}" class="tab-link active">Wyslane</a>
</div>

<div class="messages-list">
    {% if messages %}
        {% for msg in messages %}
        <a href="{{ url_for('messages_view', message_id=msg.id) }}" class="message-item">
            <div class="message-avatar">
                {{ (msg.recipient.name or msg.recipient.email)[0].upper() }}
            </div>
            <div class="message-content">
                <div class="message-subject">{{ msg.subject or '(brak tematu)' }}</div>
                <div class="message-preview">{{ msg.content[:80] }}{% if msg.content|length > 80 %}...{% endif %}</div>
            </div>
            <div class="message-meta">
                <div class="message-to">Do: {{ msg.recipient.name or msg.recipient.email.split('@')[0] }}</div>
                <div class="message-date">{{ msg.created_at.strftime('%d.%m.%Y %H:%M') }}</div>
                {% if msg.is_read %}
                <div class="read-status">Przeczytana</div>
                {% endif %}
            </div>
        </a>
        {% endfor %}
    {% else %}
        <div class="empty-state">
            <p>Brak wyslanych wiadomosci</p>
        </div>
    {% endif %}
</div>

{% if total_pages > 1 %}
<div class="pagination">
    {% for p in range(1, total_pages + 1) %}
    <a href="{{ url_for('messages_sent', page=p) }}" class="{% if p == page %}active{% endif %}">{{ p }}</a>
    {% endfor %}
</div>
{% endif %}
{% endblock %}
