<?php
/**
 * Frontend — Batch Schedule Listing Page
 */
$bp = defined('BASE_PATH') ? BASE_PATH : '/gmind';
include __DIR__ . '/../layouts/header.php';
?>

<!-- Page Banner -->
<section class="page-banner" style="background: linear-gradient(135deg, #1a1a5e 0%, #4A6CF7 100%); padding: 60px 0 40px; text-align:center; color:#fff;">
    <div class="container">
        <h1 style="margin:0 0 8px; font-size:32px; font-weight:700;">Upcoming Batches</h1>
        <p style="margin:0; opacity:0.85; font-size:16px;">Enroll now and start your journey with Gmind Institute</p>
    </div>
</section>

<!-- Batch Listing -->
<section style="padding:50px 0;">
    <div class="container">

        <!-- Course Filter -->
        <?php if (!empty($courses)): ?>
        <div style="margin-bottom:30px; display:flex; align-items:center; gap:12px; flex-wrap:wrap;">
            <span style="font-weight:600; color:#333;">Filter by Course:</span>
            <a href="<?= $bp ?>/batch-schedule" style="padding:6px 16px; border-radius:20px; font-size:13px; text-decoration:none; <?= $courseFilter === 0 ? 'background:#4A6CF7; color:#fff;' : 'background:#f0f0f0; color:#666;' ?>">All</a>
            <?php foreach ($courses as $c): ?>
            <a href="<?= $bp ?>/batch-schedule?course=<?= (int) $c['id'] ?>" style="padding:6px 16px; border-radius:20px; font-size:13px; text-decoration:none; <?= $courseFilter === (int)$c['id'] ? 'background:#4A6CF7; color:#fff;' : 'background:#f0f0f0; color:#666;' ?>"><?= htmlspecialchars($c['name'], ENT_QUOTES, 'UTF-8') ?></a>
            <?php endforeach; ?>
        </div>
        <?php endif; ?>

        <?php if (empty($batches)): ?>
        <div style="text-align:center; padding:60px 20px; color:#999;">
            <svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 0 24 24" fill="none" stroke="#ccc" stroke-width="1.5" style="margin-bottom:10px;">
                <rect x="3" y="4" width="18" height="18" rx="2" ry="2"/><line x1="16" y1="2" x2="16" y2="6"/><line x1="8" y1="2" x2="8" y2="6"/><line x1="3" y1="10" x2="21" y2="10"/>
            </svg>
            <p style="font-size:18px; margin:0;">No upcoming batches at the moment.</p>
            <p style="font-size:14px; margin:6px 0 0;">Please check back soon or <a href="<?= $bp ?>/contact" style="color:#4A6CF7;">contact us</a> for details.</p>
        </div>
        <?php else: ?>

        <div style="display:grid; gap:20px;">
            <?php foreach ($batches as $b): ?>
            <div style="background:#fff; border-radius:14px; box-shadow:0 2px 12px rgba(0,0,0,0.06); overflow:hidden; display:flex; flex-wrap:wrap; border-left:4px solid <?= $b['is_featured'] ? '#4A6CF7' : '#ddd' ?>;">

                <!-- Left: Date Badge -->
                <div style="background:linear-gradient(135deg,#4A6CF7,#6C3FE8); color:#fff; padding:20px; min-width:110px; display:flex; flex-direction:column; align-items:center; justify-content:center; text-align:center;">
                    <span style="font-size:13px; text-transform:uppercase; font-weight:600; opacity:0.85;"><?= date('M', strtotime($b['start_date'])) ?></span>
                    <span style="font-size:36px; font-weight:700; line-height:1;"><?= date('d', strtotime($b['start_date'])) ?></span>
                    <span style="font-size:12px; opacity:0.8;"><?= date('Y', strtotime($b['start_date'])) ?></span>
                </div>

                <!-- Right: Details -->
                <div style="flex:1; min-width:280px; padding:20px 24px;">
                    <div style="display:flex; align-items:flex-start; justify-content:space-between; gap:12px; flex-wrap:wrap; margin-bottom:10px;">
                        <div>
                            <h3 style="margin:0 0 4px; font-size:18px; color:#222; font-weight:700;"><?= htmlspecialchars($b['batch_name'], ENT_QUOTES, 'UTF-8') ?></h3>
                            <?php if (!empty($b['course_name'])): ?>
                            <span style="font-size:13px; color:#4A6CF7; font-weight:500;"><?= htmlspecialchars($b['course_name'], ENT_QUOTES, 'UTF-8') ?></span>
                            <?php endif; ?>
                        </div>
                        <?php
                        $sc = ['upcoming'=>['#4A6CF7','Upcoming'],'running'=>['#2ED573','Running'],'completed'=>['#999','Completed'],'cancelled'=>['#FF4757','Cancelled']];
                        $s = $sc[$b['status']] ?? ['#999','N/A'];
                        ?>
                        <span style="display:inline-block; padding:4px 12px; border-radius:20px; font-size:11px; font-weight:600; color:#fff; background:<?= $s[0] ?>;"><?= $s[1] ?></span>
                    </div>

                    <div style="display:flex; gap:20px; flex-wrap:wrap; margin-bottom:12px;">
                        <?php if ($b['timing']): ?>
                        <span style="font-size:13px; color:#666; display:flex; align-items:center; gap:4px;">
                            <svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="#4A6CF7" stroke-width="2"><circle cx="12" cy="12" r="10"/><polyline points="12 6 12 12 16 14"/></svg>
                            <?= htmlspecialchars($b['timing'], ENT_QUOTES, 'UTF-8') ?>
                        </span>
                        <?php endif; ?>
                        <?php if ($b['days']): ?>
                        <span style="font-size:13px; color:#666; display:flex; align-items:center; gap:4px;">
                            <svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="#4A6CF7" stroke-width="2"><rect x="3" y="4" width="18" height="18" rx="2"/><line x1="16" y1="2" x2="16" y2="6"/><line x1="8" y1="2" x2="8" y2="6"/><line x1="3" y1="10" x2="21" y2="10"/></svg>
                            <?= htmlspecialchars($b['days'], ENT_QUOTES, 'UTF-8') ?>
                        </span>
                        <?php endif; ?>
                        <span style="font-size:13px; color:#666; display:flex; align-items:center; gap:4px;">
                            <svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="#4A6CF7" stroke-width="2"><path d="M17 21v-2a4 4 0 00-4-4H5a4 4 0 00-4 4v2"/><circle cx="9" cy="7" r="4"/></svg>
                            <?= (int) $b['seats_available'] ?> / <?= (int) $b['seats_total'] ?> seats
                        </span>
                        <?php if ($b['fee']): ?>
                        <span style="font-size:13px; color:#666; display:flex; align-items:center; gap:4px;">
                            <svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="#4A6CF7" stroke-width="2"><line x1="12" y1="1" x2="12" y2="23"/><path d="M17 5H9.5a3.5 3.5 0 000 7h5a3.5 3.5 0 010 7H6"/></svg>
                            ₹<?= number_format((float) $b['fee']) ?>
                        </span>
                        <?php endif; ?>
                    </div>

                    <?php if ($b['end_date']): ?>
                    <p style="font-size:12px; color:#999; margin:0;">End date: <?= date('M j, Y', strtotime($b['end_date'])) ?></p>
                    <?php endif; ?>

                    <div style="margin-top:12px;">
                        <?php if ((int) $b['seats_available'] > 0): ?>
                        <a href="<?= $bp ?>/admission" style="display:inline-block; padding:8px 20px; background:linear-gradient(135deg,#4A6CF7,#6C3FE8); color:#fff; border-radius:8px; font-size:13px; font-weight:600; text-decoration:none; transition:transform 0.2s;">Enroll Now</a>
                        <?php else: ?>
                        <span style="display:inline-block; padding:8px 20px; background:#ccc; color:#fff; border-radius:8px; font-size:13px; font-weight:600;">Batch Full</span>
                        <?php endif; ?>
                    </div>
                </div>
            </div>
            <?php endforeach; ?>
        </div>
        <?php endif; ?>
    </div>
</section>

<style>
    @media (max-width: 600px) {
        .page-banner h1 { font-size: 24px !important; }
        .page-banner { padding: 40px 0 30px !important; }
    }
</style>

<?php include __DIR__ . '/../layouts/footer.php'; ?>
