{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">Konfiguracja systemu</h4>
            <p class="text-muted mb-0">Ustawienia globalne aplikacji</p>
        </div>
    </div>

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

    <form method="post">
        <input type="hidden" name="csrf_token" value="{$csrfToken}">
        
        <div class="row">
            <div class="col-lg-6">
                <!-- Ogólne -->
                <div class="card mb-4">
                    <div class="card-header">
                        <h5 class="card-title mb-0"><i class="bi bi-gear me-2"></i>Ustawienia ogólne</h5>
                    </div>
                    <div class="card-body">
                        <div class="mb-3">
                            <label class="form-label">Nazwa strony</label>
                            <input type="text" name="site_name" class="form-control" value="{$settings.site_name}">
                        </div>
                        <div class="mb-3">
                            <label class="form-label">Opis strony</label>
                            <input type="text" name="site_description" class="form-control" value="{$settings.site_description}">
                        </div>
                        <div class="mb-3">
                            <label class="form-label">Elementów na stronę</label>
                            <input type="number" name="items_per_page" class="form-control" value="{$settings.items_per_page}" min="5" max="100">
                        </div>
                        <div class="mb-3">
                            <label class="form-label">Czas sesji (sekundy)</label>
                            <input type="number" name="session_lifetime" class="form-control" value="{$settings.session_lifetime}" min="300" max="86400">
                            <small class="text-muted">300 = 5 min, 3600 = 1h, 86400 = 24h</small>
                        </div>
                    </div>
                </div>

                <!-- Domyślne limity -->
                <div class="card mb-4">
                    <div class="card-header">
                        <h5 class="card-title mb-0"><i class="bi bi-sliders me-2"></i>Domyślne limity</h5>
                    </div>
                    <div class="card-body">
                        <div class="row">
                            <div class="col-md-6 mb-3">
                                <label class="form-label">Limit urządzeń</label>
                                <input type="number" name="default_device_limit" class="form-control" value="{$settings.default_device_limit}" min="1" max="100">
                                <small class="text-muted">Dla nowych użytkowników</small>
                            </div>
                            <div class="col-md-6 mb-3">
                                <label class="form-label">Limit playlist</label>
                                <input type="number" name="default_playlist_limit" class="form-control" value="{$settings.default_playlist_limit}" min="1" max="1000">
                                <small class="text-muted">Dla nowych użytkowników</small>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- Generator haseł -->
                <div class="card mb-4">
                    <div class="card-header">
                        <h5 class="card-title mb-0"><i class="bi bi-key me-2"></i>Generator haseł</h5>
                    </div>
                    <div class="card-body">
                        <div class="row">
                            <div class="col-md-6 mb-3">
                                <label class="form-label">Długość hasła</label>
                                <input type="number" name="password_length" class="form-control" value="{$settings.password_length|default:12}" min="6" max="32">
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-6">
                                <div class="form-check mb-2">
                                    <input type="checkbox" name="password_lowercase" id="password_lowercase" class="form-check-input" value="1" {if $settings.password_lowercase|default:1}checked{/if}>
                                    <label class="form-check-label" for="password_lowercase">Małe litery (a-z)</label>
                                </div>
                                <div class="form-check mb-2">
                                    <input type="checkbox" name="password_uppercase" id="password_uppercase" class="form-check-input" value="1" {if $settings.password_uppercase|default:1}checked{/if}>
                                    <label class="form-check-label" for="password_uppercase">Wielkie litery (A-Z)</label>
                                </div>
                            </div>
                            <div class="col-md-6">
                                <div class="form-check mb-2">
                                    <input type="checkbox" name="password_numbers" id="password_numbers" class="form-check-input" value="1" {if $settings.password_numbers|default:1}checked{/if}>
                                    <label class="form-check-label" for="password_numbers">Cyfry (0-9)</label>
                                </div>
                                <div class="form-check mb-2">
                                    <input type="checkbox" name="password_symbols" id="password_symbols" class="form-check-input" value="1" {if $settings.password_symbols|default:0}checked{/if}>
                                    <label class="form-check-label" for="password_symbols">Znaki specjalne (!@#$%)</label>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- API -->
                <div class="card mb-4">
                    <div class="card-header">
                        <h5 class="card-title mb-0"><i class="bi bi-hdd-network me-2"></i>API</h5>
                    </div>
                    <div class="card-body">
                        <div class="form-check form-switch mb-3">
                            <input type="checkbox" name="api_enabled" id="api_enabled" class="form-check-input" value="1" {if $settings.api_enabled}checked{/if}>
                            <label class="form-check-label" for="api_enabled">API włączone</label>
                        </div>
                        <div class="mb-3">
                            <label class="form-label">Limit zapytań/minutę</label>
                            <input type="number" name="api_rate_limit" class="form-control" value="{$settings.api_rate_limit}" min="10" max="1000">
                        </div>
                    </div>
                </div>
            </div>

            <div class="col-lg-6">
                <!-- Tryb konserwacji -->
                <div class="card mb-4 {if $settings.maintenance_mode}border-warning{/if}">
                    <div class="card-header {if $settings.maintenance_mode}bg-warning bg-opacity-10{/if}">
                        <h5 class="card-title mb-0">
                            <i class="bi bi-cone-striped me-2"></i>Tryb konserwacji
                            {if $settings.maintenance_mode}
                            <span class="badge bg-warning ms-2">AKTYWNY</span>
                            {/if}
                        </h5>
                    </div>
                    <div class="card-body">
                        <div class="form-check form-switch mb-3">
                            <input type="checkbox" name="maintenance_mode" id="maintenance_mode" class="form-check-input" value="1" {if $settings.maintenance_mode}checked{/if}>
                            <label class="form-check-label" for="maintenance_mode">Włącz tryb konserwacji</label>
                        </div>
                        <div class="mb-3">
                            <label class="form-label">Komunikat</label>
                            <textarea name="maintenance_message" class="form-control" rows="3">{$settings.maintenance_message}</textarea>
                        </div>
                        <div class="alert alert-info mb-0">
                            <i class="bi bi-info-circle me-2"></i>
                            W trybie konserwacji tylko administratorzy mogą się logować.
                        </div>
                    </div>
                </div>

                <!-- Bezpieczeństwo -->
                <div class="card mb-4">
                    <div class="card-header">
                        <h5 class="card-title mb-0"><i class="bi bi-shield-check me-2"></i>Bezpieczeństwo</h5>
                    </div>
                    <div class="card-body">
                        <div class="row">
                            <div class="col-md-6 mb-3">
                                <label class="form-label">Limit prób logowania</label>
                                <input type="number" name="login_attempts_limit" class="form-control" value="{$settings.login_attempts_limit}" min="3" max="20">
                            </div>
                            <div class="col-md-6 mb-3">
                                <label class="form-label">Blokada (sekundy)</label>
                                <input type="number" name="login_lockout_time" class="form-control" value="{$settings.login_lockout_time}" min="60" max="3600">
                            </div>
                        </div>
                        <div class="mb-3">
                            <label class="form-label">Przechowuj logi (dni)</label>
                            <input type="number" name="log_retention_days" class="form-control" value="{$settings.log_retention_days}" min="1" max="365">
                        </div>
                    </div>
                </div>

                <!-- SMTP -->
                <div class="card mb-4">
                    <div class="card-header">
                        <h5 class="card-title mb-0"><i class="bi bi-envelope me-2"></i>Email (SMTP)</h5>
                    </div>
                    <div class="card-body">
                        <div class="form-check form-switch mb-3">
                            <input type="checkbox" name="smtp_enabled" id="smtp_enabled" class="form-check-input" value="1" {if $settings.smtp_enabled}checked{/if}>
                            <label class="form-check-label" for="smtp_enabled">Włącz wysyłanie emaili</label>
                        </div>
                        <div class="row">
                            <div class="col-md-8 mb-3">
                                <label class="form-label">Serwer SMTP</label>
                                <input type="text" name="smtp_host" class="form-control" value="{$settings.smtp_host}" placeholder="smtp.gmail.com">
                            </div>
                            <div class="col-md-4 mb-3">
                                <label class="form-label">Port</label>
                                <input type="number" name="smtp_port" class="form-control" value="{$settings.smtp_port}">
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-6 mb-3">
                                <label class="form-label">Użytkownik</label>
                                <input type="text" name="smtp_user" class="form-control" value="{$settings.smtp_user}">
                            </div>
                            <div class="col-md-6 mb-3">
                                <label class="form-label">Hasło</label>
                                <input type="password" name="smtp_pass" class="form-control" placeholder="••••••••">
                                <small class="text-muted">Zostaw puste aby nie zmieniać</small>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-6 mb-3">
                                <label class="form-label">Email nadawcy</label>
                                <input type="email" name="smtp_from" class="form-control" value="{$settings.smtp_from}">
                            </div>
                            <div class="col-md-6 mb-3">
                                <label class="form-label">Nazwa nadawcy</label>
                                <input type="text" name="smtp_from_name" class="form-control" value="{$settings.smtp_from_name}">
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="card">
            <div class="card-body">
                <button type="submit" class="btn btn-primary btn-lg">
                    <i class="bi bi-check-lg me-2"></i>Zapisz ustawienia
                </button>
            </div>
        </div>
    </form>
</div>
{/block}
