{% extends "base.html" %}

{% block title %}Twoje dane - Moje konto - Norda Biznes Partner{% endblock %}

{% block extra_css %}
<style>
    .konto-layout {
        display: grid;
        grid-template-columns: 240px 1fr;
        gap: var(--spacing-xl);
        max-width: 1000px;
        margin: 0 auto;
    }

    .konto-sidebar {
        background: var(--surface);
        border-radius: var(--radius-lg);
        padding: var(--spacing-lg);
        box-shadow: var(--shadow);
        height: fit-content;
        position: sticky;
        top: 100px;
    }

    .konto-sidebar-header {
        display: flex;
        align-items: center;
        gap: var(--spacing-md);
        padding-bottom: var(--spacing-md);
        margin-bottom: var(--spacing-md);
        border-bottom: 1px solid var(--border);
    }

    .konto-avatar {
        width: 48px;
        height: 48px;
        border-radius: 50%;
        background: linear-gradient(135deg, var(--primary), #1e40af);
        color: white;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 20px;
        font-weight: 600;
    }

    .konto-sidebar-name {
        font-weight: 600;
        color: var(--text-primary);
        font-size: var(--font-size-sm);
    }

    .konto-sidebar-email {
        font-size: 11px;
        color: var(--text-secondary);
        word-break: break-all;
    }

    .konto-nav {
        display: flex;
        flex-direction: column;
        gap: var(--spacing-xs);
    }

    .konto-nav a {
        display: flex;
        align-items: center;
        gap: var(--spacing-sm);
        padding: var(--spacing-sm) var(--spacing-md);
        border-radius: var(--radius);
        text-decoration: none;
        color: var(--text-secondary);
        font-size: var(--font-size-sm);
        transition: all 0.2s;
    }

    .konto-nav a:hover {
        background: var(--background);
        color: var(--text-primary);
    }

    .konto-nav a.active {
        background: var(--primary);
        color: white;
    }

    .konto-nav a svg {
        width: 18px;
        height: 18px;
        flex-shrink: 0;
    }

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

    .konto-header {
        margin-bottom: var(--spacing-xl);
        padding-bottom: var(--spacing-lg);
        border-bottom: 1px solid var(--border);
    }

    .konto-header h1 {
        font-size: var(--font-size-2xl);
        color: var(--text-primary);
        margin-bottom: var(--spacing-xs);
    }

    .konto-header p {
        color: var(--text-secondary);
    }

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

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

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

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

    .form-input:disabled {
        background: var(--background);
        color: var(--text-secondary);
        cursor: not-allowed;
    }

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

    .form-row {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: var(--spacing-md);
    }

    .info-box {
        background: #f0f9ff;
        border: 1px solid #bae6fd;
        border-radius: var(--radius);
        padding: var(--spacing-md);
        margin-bottom: var(--spacing-lg);
        font-size: var(--font-size-sm);
        color: #0369a1;
    }

    .info-box a {
        color: #0369a1;
        font-weight: 500;
    }

    .form-actions {
        display: flex;
        gap: var(--spacing-md);
        padding-top: var(--spacing-lg);
        border-top: 1px solid var(--border);
    }

    .badge-row {
        display: flex;
        gap: var(--spacing-sm);
        margin-top: var(--spacing-sm);
    }

    .profile-badge {
        display: inline-flex;
        align-items: center;
        gap: var(--spacing-xs);
        padding: 4px 10px;
        border-radius: var(--radius-full);
        font-size: var(--font-size-xs);
        font-weight: 500;
    }

    .badge-verified {
        background: #dcfce7;
        color: #166534;
    }

    .badge-member {
        background: #dbeafe;
        color: #1e40af;
    }

    @media (max-width: 768px) {
        .konto-layout {
            grid-template-columns: 1fr;
        }

        .konto-sidebar {
            position: static;
        }

        .konto-nav {
            flex-direction: row;
            flex-wrap: wrap;
        }

        .form-row {
            grid-template-columns: 1fr;
        }

        .form-actions {
            flex-direction: column;
        }
    }
</style>
{% endblock %}

{% block content %}
<div class="konto-layout">
    <aside class="konto-sidebar">
        <div class="konto-sidebar-header">
            <div class="konto-avatar">
                {{ (current_user.name or current_user.email)[0].upper() }}
            </div>
            <div>
                <div class="konto-sidebar-name">{{ current_user.name or 'Użytkownik' }}</div>
                <div class="konto-sidebar-email">{{ current_user.email }}</div>
            </div>
        </div>
        <nav class="konto-nav">
            <a href="{{ url_for('konto_dane') }}" class="active">
                <svg fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24">
                    <path d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"/>
                </svg>
                Twoje dane
            </a>
            <a href="{{ url_for('konto_prywatnosc') }}">
                <svg fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24">
                    <path d="M12 15v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2zm10-10V7a4 4 0 00-8 0v4h8z"/>
                </svg>
                Prywatność
            </a>
            <a href="{{ url_for('konto_bezpieczenstwo') }}">
                <svg fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24">
                    <path d="M9 12l2 2 4-4m5.618-4.016A11.955 11.955 0 0112 2.944a11.955 11.955 0 01-8.618 3.04A12.02 12.02 0 003 9c0 5.591 3.824 10.29 9 11.622 5.176-1.332 9-6.03 9-11.622 0-1.042-.133-2.052-.382-3.016z"/>
                </svg>
                Bezpieczeństwo
            </a>
            <a href="{{ url_for('konto_blokady') }}">
                <svg fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24">
                    <path d="M18.364 18.364A9 9 0 005.636 5.636m12.728 12.728A9 9 0 015.636 5.636m12.728 12.728L5.636 5.636"/>
                </svg>
                Blokady
            </a>
        </nav>
    </aside>

    <main class="konto-content">
        <div class="konto-header">
            <h1>Twoje dane</h1>
            <p>Zarządzaj swoimi danymi osobowymi</p>
            <div class="badge-row">
                {% if current_user.is_verified %}
                <span class="profile-badge badge-verified">
                    <svg width="12" height="12" fill="currentColor" viewBox="0 0 20 20">
                        <path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z" clip-rule="evenodd"/>
                    </svg>
                    Zweryfikowany
                </span>
                {% endif %}
                {% if current_user.is_norda_member %}
                <span class="profile-badge badge-member">
                    <svg width="12" height="12" fill="currentColor" viewBox="0 0 20 20">
                        <path d="M9.049 2.927c.3-.921 1.603-.921 1.902 0l1.07 3.292a1 1 0 00.95.69h3.462c.969 0 1.371 1.24.588 1.81l-2.8 2.034a1 1 0 00-.364 1.118l1.07 3.292c.3.921-.755 1.688-1.54 1.118l-2.8-2.034a1 1 0 00-1.175 0l-2.8 2.034c-.784.57-1.838-.197-1.539-1.118l1.07-3.292a1 1 0 00-.364-1.118L2.98 8.72c-.783-.57-.38-1.81.588-1.81h3.461a1 1 0 00.951-.69l1.07-3.292z"/>
                    </svg>
                    Członek NORDA
                </span>
                {% endif %}
            </div>
        </div>

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

            <div class="form-group">
                <label for="name" class="form-label">Imię i nazwisko</label>
                <input type="text" id="name" name="name" class="form-input"
                       value="{{ current_user.name or '' }}"
                       placeholder="Jan Kowalski"
                       maxlength="255">
                <p class="form-help">Twoje imię i nazwisko widoczne dla innych użytkowników</p>
            </div>

            <div class="form-group">
                <label for="phone" class="form-label">Numer telefonu</label>
                <input type="tel" id="phone" name="phone" class="form-input"
                       value="{{ current_user.phone or '' }}"
                       placeholder="+48 123 456 789"
                       maxlength="50">
                <p class="form-help">Opcjonalnie - ułatwi kontakt z innymi członkami. Możesz ukryć telefon w ustawieniach prywatności.</p>
            </div>

            <div class="form-group">
                <label for="email" class="form-label">Adres email</label>
                <input type="email" id="email" class="form-input"
                       value="{{ current_user.email }}"
                       disabled>
                <p class="form-help">Adres email nie może być zmieniony</p>
            </div>

            {% if current_user.company %}
            <div class="info-box">
                <strong>Powiązana firma:</strong> {{ current_user.company.name }}<br>
                <a href="{{ url_for('company_detail_by_slug', slug=current_user.company.slug) }}">Zobacz profil firmy →</a>
            </div>
            {% endif %}

            <div class="form-actions">
                <button type="submit" class="btn btn-primary">
                    Zapisz zmiany
                </button>
                <a href="{{ url_for('index') }}" class="btn btn-outline">
                    Anuluj
                </a>
            </div>
        </form>
    </main>
</div>
{% endblock %}
