<?= $this->extend('layout/admin') ?>
<?= $this->section('title') ?>Manage Suffixes<?= $this->endSection() ?>

<?= $this->section('content') ?>
<div class="page-header">
    <h1 style="font-size: 1.5rem; font-weight: 700;">Global Suffix Management</h1>
</div>

<div class="grid" style="grid-template-columns: 2fr 1fr; gap: 2rem;">
    <!-- Suffixes Table -->
    <div class="card">
        <h3 style="font-size: 1.125rem; font-weight: 600; margin-bottom: 1.5rem;">Active TLDs</h3>
        <div class="table-wrapper" style="box-shadow: none; border: 1px solid var(--border-color);">
            <table>
                <thead>
                    <tr>
                        <th>Suffix</th>
                        <th>Network Status</th>
                        <th>Action</th>
                    </tr>
                </thead>
                <tbody>
                    <?php if(empty($suffixes)): ?>
                        <tr><td colspan="3" style="text-align: center; color: var(--text-muted); padding: 2rem;">No suffixes registered. Site is crippled!</td></tr>
                    <?php else: ?>
                        <?php foreach($suffixes as $s): ?>
                        <tr>
                            <td style="font-weight: 700; color: var(--primary);"><?= esc($s->suffix) ?></td>
                            <td>
                                <span class="status-badge status-<?= $s->is_active ? 'active' : 'suspended' ?>">
                                    <?= $s->is_active ? 'Routing' : 'Offline' ?>
                                </span>
                            </td>
                            <td>
                                <a href="<?= base_url('admin/suffixes/delete/' . $s->id) ?>" class="btn btn-outline" style="border-color: var(--error); color: var(--error); padding: 0.25rem 0.5rem; font-size: 0.75rem;" onclick="return confirm('Deleting a suffix may break connected subdomains permanently. Are you sure?')">Delete</a>
                            </td>
                        </tr>
                        <?php endforeach; ?>
                    <?php endif; ?>
                </tbody>
            </table>
        </div>
    </div>

    <!-- Add Suffix -->
    <div class="card" style="border-top: 4px solid var(--primary); height: fit-content;">
        <h3 style="font-size: 1.125rem; font-weight: 600; margin-bottom: 0.5rem;">Inject New Suffix</h3>
        <p style="color: var(--text-muted); font-size: 0.875rem; margin-bottom: 1.5rem;">New suffixes must already be registered natively in your Cloudflare Zones to route properly.</p>
        
        <form action="<?= base_url('admin/suffixes/add') ?>" method="POST">
            <div class="form-group">
                <label class="form-label">TLD Suffix</label>
                <input type="text" name="suffix" class="form-control" placeholder=".cloud.bd" required>
            </div>
            
            <button type="submit" class="btn btn-primary" style="width: 100%; justify-content: center;">Approve and Deploy</button>
        </form>
    </div>
</div>
<?= $this->endSection() ?>
