<?php require_once __DIR__ . '/../layout.php'; ?>

<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 2rem;">
    <div>
        <h3 style="margin: 0 0 0.5rem; color: white;">Privileges Directory</h3>
        <p style="color: var(--text-muted); margin: 0;">Configure permission tokens/slugs checked by the Auth middleware.</p>
    </div>
    <a href="/superadmin/privilegeCreate" class="btn-gold">
        <i class="ph ph-plus" style="font-weight: bold;"></i> Add Privilege
    </a>
</div>

<div class="card responsive-table-container" style="padding: 0; overflow-x: auto; border: none; margin-bottom: 2rem; border-radius: 12px;">
    <table class="data-table" style="width: 100%; border-collapse: collapse;">
        <thead>
            <tr>
                <th style="width: 10%;">ID</th>
                <th style="width: 45%;">Name</th>
                <th style="width: 35%;">Slug (Token Key)</th>
                <th style="width: 10%; text-align: center;">Actions</th>
            </tr>
        </thead>
        <tbody>
            <?php if (empty($records)): ?>
                <tr>
                    <td colspan="4" style="text-align: center; color: var(--text-muted); padding: 2rem;">No privileges defined yet.</td>
                </tr>
            <?php else: ?>
                <?php foreach ($records as $rec): ?>
                    <tr>
                        <td style="color: var(--text-muted);"><?php echo htmlspecialchars($rec['id']); ?></td>
                        <td><strong style="color: white;"><?php echo htmlspecialchars($rec['name']); ?></strong></td>
                        <td><code style="background: rgba(245, 158, 11, 0.1); color: #fbbf24; padding: 0.2rem 0.5rem; border-radius: 4px; font-size: 0.85rem; font-family: monospace; border: 1px solid rgba(245, 158, 11, 0.2);"><?php echo htmlspecialchars($rec['slug']); ?></code></td>
                        <td style="text-align: center; white-space: nowrap;">
                            <a href="/superadmin/privilegeEdit/<?php echo $rec['id']; ?>" class="action-icon edit" title="Edit">
                                <i class="ph ph-pencil-simple"></i>
                            </a>
                            <a href="/superadmin/privilegeDelete/<?php echo $rec['id']; ?>" class="action-icon delete" title="Delete" onclick="return confirm('Are you sure you want to delete this privilege? This will remove all associated user privilege mappings.');">
                                <i class="ph ph-trash"></i>
                            </a>
                        </td>
                    </tr>
                <?php endforeach; ?>
            <?php endif; ?>
        </tbody>
    </table>
</div>

</div> <!-- main-content -->
</div> <!-- dashboard-layout -->
</body>
</html>
