<?= $this->extend('layouts/admin') ?>

<?= $this->section('content') ?>

<div class="animate-up">
    <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 30px;">
        <div>
            <h1>Registers</h1>
            <p style="color: var(--text-muted);">Access and manage your custom data ledgers and spreadsheets.</p>
        </div>
        <a href="<?= base_url('admin/register_new') ?>" class="btn btn-primary" style="padding: 12px 25px; border-radius: 12px; box-shadow: 0 10px 20px rgba(229, 45, 39, 0.2);">
            <i class="bi bi-plus-lg"></i> New Register
        </a>
    </div>

    <div class="template-grid" style="display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 30px;">
        <?php if (empty($sheets)): ?>
            <div style="grid-column: 1 / -1; text-align: center; padding: 100px; background: #fff; border-radius: 24px; border: 2px dashed var(--border);">
                <i class="bi bi-grid-3x3" style="font-size: 3rem; color: var(--text-admin-muted); opacity: 0.3; display: block; margin-bottom: 20px;"></i>
                <h3>No registers found</h3>
                <p style="color: var(--text-muted); margin-bottom: 30px;">Start by creating your first data register using a template.</p>
                <a href="<?= base_url('admin/register_new') ?>" class="btn btn-primary">Create First Register</a>
            </div>
        <?php else: ?>
            <?php foreach ($sheets as $sheet): ?>
                <div class="template-card" onclick="location.href='<?= base_url('admin/project_sheet/' . $sheet['id']) ?>'" style="display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: 20px; overflow: hidden; cursor: pointer; transition: all 0.3s; background: #fff;">
                    <div style="height: 120px; background: linear-gradient(135deg, <?= empty($sheet['updated_at']) ? '#94a3b8' : 'var(--primary)' ?> 0%, <?= empty($sheet['updated_at']) ? '#64748b' : 'var(--primary-dark)' ?> 100%); display: flex; align-items: center; justify-content: center; color: #fff; font-size: 3rem;">
                        <i class="bi bi-table"></i>
                    </div>
                    <div style="padding: 25px;">
                        <h4 style="margin-bottom: 5px;"><?= $sheet['project_name'] ?></h4>
                        <p style="color: var(--text-muted); font-size: 0.85rem; margin-bottom: 15px;">Project Ledger</p>
                        <div style="display: flex; justify-content: space-between; align-items: center; font-size: 0.75rem; color: var(--text-admin-muted); border-top: 1px solid var(--border); padding-top: 15px;">
                            <span><i class="bi bi-clock"></i> <?= empty($sheet['updated_at']) ? 'Not initialized' : 'Updated ' . date('M d, Y', strtotime($sheet['updated_at'])) ?></span>
                            <span style="color: var(--primary); font-weight: 700;">OPEN <i class="bi bi-arrow-right"></i></span>
                        </div>
                    </div>
                </div>
            <?php endforeach; ?>
        <?php endif; ?>
    </div>
</div>

<?= $this->endSection() ?>
