<?php
/**
 * Franchise Plans List — Gmind Institute ERP
 * Lists all franchise plans with CRUD actions
 */
$bp = defined('BASE_PATH') ? BASE_PATH : '/gmind';
?>
<div class="admin-page-header" style="display:flex;justify-content:space-between;align-items:center;margin-bottom:24px;">
    <h1 style="margin:0;font-size:22px;font-weight:700;">Franchise Plans</h1>
    <a href="<?= $bp ?>/admin/franchise-plans/create" class="admin-btn admin-btn-primary">+ Create Plan</a>
</div>

<div class="admin-table-wrapper">
    <table class="admin-table">
        <thead>
            <tr>
                <th>Name</th>
                <th>Slug</th>
                <th>Price (₹)</th>
                <th>Duration (Months)</th>
                <th>Max Students</th>
                <th>Max Exams/Month</th>
                <th>Active</th>
                <th>Sort Order</th>
                <th>Actions</th>
            </tr>
        </thead>
        <tbody>
            <?php if (!empty($plans)): ?>
                <?php foreach ($plans as $plan): ?>
                <tr>
                    <td><?= htmlspecialchars($plan['name'], ENT_QUOTES, 'UTF-8') ?></td>
                    <td><code style="background:#f5f5f5;padding:2px 6px;border-radius:3px;font-size:12px;"><?= htmlspecialchars($plan['slug'], ENT_QUOTES, 'UTF-8') ?></code></td>
                    <td>₹<?= number_format((float)($plan['price'] ?? 0), 2) ?></td>
                    <td><?= (int)($plan['duration_months'] ?? 0) ?></td>
                    <td><?= (int)($plan['max_students'] ?? 0) ?></td>
                    <td><?= (int)($plan['max_exams_per_month'] ?? 0) ?></td>
                    <td>
                        <?php if (!empty($plan['is_active'])): ?>
                            <span class="admin-badge admin-badge-success">Yes</span>
                        <?php else: ?>
                            <span class="admin-badge admin-badge-danger">No</span>
                        <?php endif; ?>
                    </td>
                    <td><?= (int)($plan['sort_order'] ?? 0) ?></td>
                    <td>
                        <a href="<?= $bp ?>/admin/franchise-plans/edit/<?= (int)$plan['id'] ?>" class="admin-btn admin-btn-sm admin-btn-secondary" title="Edit">Edit</a>
                        <form method="POST" action="<?= $bp ?>/admin/franchise-plans/delete/<?= (int)$plan['id'] ?>" style="display:inline;" onsubmit="return confirm('Are you sure you want to delete this plan?');">
                            <input type="hidden" name="csrf_token" value="<?= htmlspecialchars($csrfToken, ENT_QUOTES, 'UTF-8') ?>">
                            <button type="submit" class="admin-btn admin-btn-sm admin-btn-danger" title="Delete">Delete</button>
                        </form>
                    </td>
                </tr>
                <?php endforeach; ?>
            <?php else: ?>
                <tr><td colspan="9" style="text-align:center;color:#999;">No franchise plans found. Create your first plan.</td></tr>
            <?php endif; ?>
        </tbody>
    </table>
</div>
