<?php ob_start(); ?>

<?php
admin_content_header(
    __('admin.marketplace.backups_title', [':slug' => $slug ?? '']),
    'archive',
    [['url' => admin_url('marketplace'), 'label' => __('admin.marketplace.back_to_marketplace'), 'class' => 'btn-secondary']]
);
?>

<div class="card">
    <div class="card-body">

        <?php if (empty($backups)): ?>
        <p class="text-muted" style="text-align:center; padding:2rem 0;">
            <?= icon('inbox', 32) ?><br>
            <?= __('admin.marketplace.backups_none') ?>
        </p>
        <?php else: ?>
        <p style="margin-top:0; color:var(--color-text-muted); font-size:.875rem;">
            <?= __('admin.marketplace.backups_hint', [':slug' => e($slug ?? '')]) ?>
        </p>
        <table class="table">
            <thead>
                <tr>
                    <th><?= __('admin.marketplace.backups_file') ?></th>
                    <th><?= __('admin.marketplace.backups_created') ?></th>
                    <th><?= __('admin.marketplace.backups_size') ?></th>
                    <th></th>
                </tr>
            </thead>
            <tbody>
                <?php foreach ($backups as $i => $backup): ?>
                <tr>
                    <td>
                        <code style="font-size:.8rem;"><?= e($backup['filename']) ?></code>
                        <?php if ($i === 0): ?>
                        <span class="mp-badge mp-badge--free" style="margin-left:.5rem; font-size:.7rem;"><?= __('admin.marketplace.backups_latest') ?></span>
                        <?php endif; ?>
                    </td>
                    <td style="white-space:nowrap;">
                        <?= e(date('d.m.Y H:i', strtotime($backup['created_at']))) ?>
                    </td>
                    <td><?= e(number_format($backup['size'] / 1024, 1)) ?> KB</td>
                    <td style="text-align:right;">
                        <form method="POST" action="<?= admin_url('marketplace/rollback') ?>"
                              onsubmit="return confirm('<?= e(__('admin.marketplace.backups_confirm_restore')) ?>')">
                            <?= csrf_field() ?>
                            <input type="hidden" name="slug" value="<?= e($slug ?? '') ?>">
                            <input type="hidden" name="backup_file" value="<?= e($backup['filename']) ?>">
                            <button type="submit" class="btn btn-warning btn-sm">
                                <?= icon('rotate-ccw', 14) ?> <?= __('admin.marketplace.backups_restore') ?>
                            </button>
                        </form>
                    </td>
                </tr>
                <?php endforeach; ?>
            </tbody>
        </table>
        <?php endif; ?>

    </div>
</div>

<?php
$content = ob_get_clean();
echo $content;
