{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">Kopie zapasowe</h4>
            <p class="text-muted mb-0">Zarządzaj backupami bazy danych</p>
        </div>
        <form method="post" action="{$baseUrl}/admin/tools/backup">
            <input type="hidden" name="csrf_token" value="{$csrfToken}">
            <button type="submit" class="btn btn-primary">
                <i class="bi bi-plus-lg me-1"></i>Utwórz backup
            </button>
        </form>
    </div>

    <div class="card">
        <div class="card-body p-0">
            <div class="table-responsive">
                <table class="table table-hover mb-0">
                    <thead>
                        <tr>
                            <th>Nazwa pliku</th>
                            <th>Rozmiar</th>
                            <th>Data utworzenia</th>
                            <th class="text-end">Akcje</th>
                        </tr>
                    </thead>
                    <tbody>
                        {foreach $backups as $backup}
                        <tr>
                            <td>
                                <i class="bi bi-file-earmark-zip me-2 text-muted"></i>
                                <strong>{$backup.name}</strong>
                            </td>
                            <td>{($backup.size / 1048576)|number_format:2} MB</td>
                            <td>{$backup.created|date_format:"%d.%m.%Y %H:%M:%S"}</td>
                            <td class="text-end">
                                <a href="{$baseUrl}/admin/backups/download?file={$backup.name|escape:'url'}" 
                                   class="btn btn-sm btn-outline-primary" title="Pobierz">
                                    <i class="bi bi-download"></i>
                                </a>
                                <form method="post" action="{$baseUrl}/admin/backups/delete" class="d-inline">
                                    <input type="hidden" name="csrf_token" value="{$csrfToken}">
                                    <input type="hidden" name="file" value="{$backup.name}">
                                    <button type="submit" class="btn btn-sm btn-outline-danger" title="Usuń" 
                                            onclick="return confirm('Usunąć ten backup?')">
                                        <i class="bi bi-trash"></i>
                                    </button>
                                </form>
                            </td>
                        </tr>
                        {foreachelse}
                        <tr>
                            <td colspan="4" class="text-center py-5 text-muted">
                                <i class="bi bi-archive fs-1 d-block mb-3"></i>
                                Brak kopii zapasowych
                            </td>
                        </tr>
                        {/foreach}
                    </tbody>
                </table>
            </div>
        </div>
    </div>

    <div class="alert alert-info mt-4">
        <i class="bi bi-info-circle me-2"></i>
        System automatycznie przechowuje ostatnie 7 backupów. Starsze są usuwane automatycznie.
    </div>
</div>
{/block}
