{extends file="layout.tpl"}

{block name="content"}
<div class="container-fluid">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <div>
            <h4 class="mb-1">Edycja profilu</h4>
            <p class="text-muted mb-0">Zaktualizuj swoje dane</p>
        </div>
        <a href="{$baseUrl}/profile" class="btn btn-outline-secondary">
            <i class="bi bi-arrow-left me-1"></i>Powrót
        </a>
    </div>

    {if $error|default:false}
    <div class="alert alert-danger"><i class="bi bi-exclamation-circle me-2"></i>{$error}</div>
    {/if}

    <div class="row g-4">
        <!-- Avatar -->
        <div class="col-lg-4">
            <div class="card">
                <div class="card-header">
                    <h5 class="card-title mb-0"><i class="bi bi-image me-2"></i>Avatar</h5>
                </div>
                <div class="card-body text-center">
                    <div class="mb-3">
                        {if $profile.avatar}
                        <img src="/uploads/avatars/{$profile.avatar}" class="rounded-circle" style="width: 150px; height: 150px; object-fit: cover;">
                        {else}
                        <div class="rounded-circle bg-primary bg-opacity-10 d-inline-flex align-items-center justify-content-center" style="width: 150px; height: 150px;">
                            <i class="bi bi-person text-primary" style="font-size: 5rem;"></i>
                        </div>
                        {/if}
                    </div>
                    
                    <form method="post" action="{$baseUrl}/profile/avatar/upload" enctype="multipart/form-data" class="mb-2">
                        <input type="hidden" name="csrf_token" value="{$csrfToken}">
                        <div class="input-group">
                            <input type="file" name="avatar" class="form-control form-control-sm" accept="image/*" required>
                            <button type="submit" class="btn btn-sm btn-primary">Wyślij</button>
                        </div>
                        <small class="text-muted">Max 2MB, JPG/PNG/GIF/WEBP</small>
                    </form>
                    
                    {if $profile.avatar}
                    <form method="post" action="{$baseUrl}/profile/avatar/remove">
                        <input type="hidden" name="csrf_token" value="{$csrfToken}">
                        <button type="submit" class="btn btn-sm btn-outline-danger" onclick="return confirm('Usunąć avatar?')">
                            <i class="bi bi-trash me-1"></i>Usuń avatar
                        </button>
                    </form>
                    {/if}
                </div>
            </div>

            <!-- Zmiana hasła -->
            <div class="card mt-4">
                <div class="card-header">
                    <h5 class="card-title mb-0"><i class="bi bi-key me-2"></i>Zmiana hasła</h5>
                </div>
                <div class="card-body">
                    <a href="{$baseUrl}/change-password" class="btn btn-outline-primary w-100">
                        <i class="bi bi-key me-1"></i>Zmień hasło
                    </a>
                </div>
            </div>
        </div>

        <!-- Formularz profilu -->
        <div class="col-lg-8">
            <form method="post">
                <input type="hidden" name="csrf_token" value="{$csrfToken}">

                <div class="card">
                    <div class="card-header">
                        <h5 class="card-title mb-0"><i class="bi bi-person me-2"></i>Dane podstawowe</h5>
                    </div>
                    <div class="card-body">
                        <div class="row g-3">
                            <div class="col-md-6">
                                <label class="form-label">Imię i nazwisko</label>
                                <input type="text" name="full_name" class="form-control" value="{$profile.full_name|default:''}">
                            </div>
                            <div class="col-md-6">
                                <label class="form-label">Firma</label>
                                <input type="text" name="company" class="form-control" value="{$profile.company|default:''}">
                            </div>
                            <div class="col-md-6">
                                <label class="form-label">Email</label>
                                <input type="email" name="email" class="form-control" value="{$profile.email|default:''}">
                            </div>
                            <div class="col-md-6">
                                <label class="form-label">Telefon</label>
                                <input type="text" name="phone" class="form-control" value="{$profile.phone|default:''}">
                            </div>
                            <div class="col-12">
                                <label class="form-label">Adres</label>
                                <textarea name="address" class="form-control" rows="2">{$profile.address|default:''}</textarea>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="card mt-4">
                    <div class="card-header">
                        <h5 class="card-title mb-0"><i class="bi bi-gear me-2"></i>Preferencje</h5>
                    </div>
                    <div class="card-body">
                        <div class="row g-3">
                            <div class="col-md-4">
                                <label class="form-label">Strefa czasowa</label>
                                <select name="timezone" class="form-select">
                                    {foreach $timezones as $tz => $label}
                                    <option value="{$tz}" {if $profile.timezone == $tz}selected{/if}>{$label}</option>
                                    {/foreach}
                                </select>
                            </div>
                            <div class="col-md-4">
                                <label class="form-label">Język</label>
                                <select name="language" class="form-select">
                                    <option value="pl" {if $profile.language == 'pl'}selected{/if}>Polski</option>
                                    <option value="en" {if $profile.language == 'en'}selected{/if}>English</option>
                                </select>
                            </div>
                            <div class="col-md-4">
                                <label class="form-label">Motyw</label>
                                <select name="theme" class="form-select">
                                    <option value="dark" {if $profile.theme == 'dark'}selected{/if}>Ciemny</option>
                                    <option value="light" {if $profile.theme == 'light'}selected{/if}>Jasny</option>
                                </select>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="card mt-4">
                    <div class="card-header">
                        <h5 class="card-title mb-0"><i class="bi bi-bell me-2"></i>Powiadomienia</h5>
                    </div>
                    <div class="card-body">
                        <div class="form-check mb-2">
                            <input type="checkbox" name="notifications_email" class="form-check-input" id="notifEmail" value="1"
                                   {if $profile.notifications_email}checked{/if}>
                            <label class="form-check-label" for="notifEmail">Powiadomienia email</label>
                        </div>
                        <div class="form-check">
                            <input type="checkbox" name="notifications_browser" class="form-check-input" id="notifBrowser" value="1"
                                   {if $profile.notifications_browser}checked{/if}>
                            <label class="form-check-label" for="notifBrowser">Powiadomienia w przeglądarce</label>
                        </div>
                    </div>
                </div>

                <div class="mt-4">
                    <button type="submit" class="btn btn-primary">
                        <i class="bi bi-check-lg me-1"></i>Zapisz zmiany
                    </button>
                    <a href="{$baseUrl}/profile" class="btn btn-outline-secondary ms-2">Anuluj</a>
                </div>
            </form>
        </div>
    </div>
</div>
{/block}
