<?php
/**
 * Admin — Batch Schedules Listing
 */
$bp = defined('BASE_PATH') ? BASE_PATH : '/gmind';
?>
<div class="admin-section">
    <div style="display:flex; justify-content:space-between; align-items:center; margin-bottom:20px; flex-wrap:wrap; gap:12px;">
        <h2 style="margin:0; font-size:20px;">Batch Schedules</h2>
        <a href="<?= $bp ?>/admin/batch-schedules/create" class="admin-btn" style="background:#4A6CF7; color:#fff; text-decoration:none; padding:8px 18px; border-radius:8px; font-size:13px; display:inline-flex; align-items:center; gap:6px;">
            <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="12" y1="5" x2="12" y2="19"/><line x1="5" y1="12" x2="19" y2="12"/></svg>
            Add Batch
        </a>
    </div>

    <?php if (empty($batches)): ?>
    <div style="text-align:center; padding:50px 20px; color:#999;">
        <p style="font-size:16px;">No batch schedules yet.</p>
    </div>
    <?php else: ?>
    <div class="admin-table-wrap" style="overflow-x:auto;">
        <table class="admin-table">
            <thead>
                <tr>
                    <th>Batch Name</th>
                    <th>Course</th>
                    <th>Start Date</th>
                    <th>Timing</th>
                    <th>Days</th>
                    <th>Seats</th>
                    <th>Fee</th>
                    <th>Status</th>
                    <th>Featured</th>
                    <th>Countdown</th>
                    <th>Actions</th>
                </tr>
            </thead>
            <tbody>
                <?php foreach ($batches as $b): ?>
                <tr>
                    <td style="font-weight:600;"><?= htmlspecialchars($b['batch_name'], ENT_QUOTES, 'UTF-8') ?></td>
                    <td style="color:#888; font-size:13px;"><?= htmlspecialchars($b['course_name'] ?? '—', ENT_QUOTES, 'UTF-8') ?></td>
                    <td style="font-size:13px;"><?= date('M j, Y', strtotime($b['start_date'])) ?></td>
                    <td style="font-size:13px;"><?= htmlspecialchars($b['timing'] ?? '—', ENT_QUOTES, 'UTF-8') ?></td>
                    <td style="font-size:13px;"><?= htmlspecialchars($b['days'] ?? '—', ENT_QUOTES, 'UTF-8') ?></td>
                    <td style="font-size:13px;">
                        <span style="color:#2ED573; font-weight:600;"><?= (int) $b['seats_available'] ?></span>/<?= (int) $b['seats_total'] ?>
                    </td>
                    <td style="font-size:13px;"><?= $b['fee'] ? '₹' . number_format((float)$b['fee']) : '—' ?></td>
                    <td>
                        <?php
                        $sc = ['upcoming'=>'#4A6CF7','running'=>'#2ED573','completed'=>'#999','cancelled'=>'#FF4757'];
                        $scl = $sc[$b['status']] ?? '#999';
                        ?>
                        <span style="display:inline-block; padding:3px 10px; border-radius:20px; font-size:11px; font-weight:600; color:#fff; background:<?= $scl ?>;"><?= ucfirst($b['status']) ?></span>
                    </td>
                    <td><?= $b['is_featured'] ? '⭐' : '—' ?></td>
                    <td><?= $b['show_countdown'] ? '🕐' : '—' ?></td>
                    <td>
                        <div style="display:flex; gap:6px; flex-wrap:wrap;">
                            <a href="<?= $bp ?>/admin/batch-schedules/<?= (int) $b['id'] ?>/edit" class="admin-btn admin-btn-sm" style="background:#4A6CF7; color:#fff; text-decoration:none; padding:4px 10px; border-radius:6px; font-size:11px;">Edit</a>
                            <form method="POST" action="<?= $bp ?>/admin/batch-schedules/<?= (int) $b['id'] ?>/delete" style="display:inline;" onsubmit="return confirm('Delete this batch?');">
                                <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" style="padding:4px 10px; border-radius:6px; font-size:11px; border:none; cursor:pointer;">Delete</button>
                            </form>
                        </div>
                    </td>
                </tr>
                <?php endforeach; ?>
            </tbody>
        </table>
    </div>
    <?php endif; ?>
</div>
