<?php
/**
 * Create Batch View — Modern, Responsive
 *
 * Upload to: /gmind/branch/Views/batches/create.php
 */

/** @var array $courses */
/** @var string $csrfToken */

$bp = defined('BASE_PATH') ? BASE_PATH : '/gmind';
$csrf = htmlspecialchars($csrfToken ?? '', ENT_QUOTES, 'UTF-8');
?>
<style>
    .batch-form-card {
        background: #fff;
        border: none;
        border-radius: 12px;
        box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    }
    .batch-form-card .card-header {
        background: linear-gradient(135deg, #16a085, #117a65);
        color: #fff;
        border-radius: 12px 12px 0 0 !important;
        padding: 18px 24px;
        font-weight: 700;
    }
    .batch-form-card .card-body { padding: 28px; }
    .form-label { font-weight: 600; color: #2c1e4a; font-size: 0.9rem; margin-bottom: 6px; }
    .form-control, .form-select { border-radius: 8px; padding: 10px 12px; border: 1px solid #d0d5dd; }
    .form-control:focus, .form-select:focus { border-color: #16a085; box-shadow: 0 0 0 3px rgba(22,160,133,0.1); }
    .required-mark { color: #dc2626; margin-left: 2px; }
    .btn-submit {
        background: linear-gradient(135deg, #16a085, #117a65);
        color: #fff;
        padding: 14px 32px;
        border: none;
        border-radius: 8px;
        font-weight: 700;
        font-size: 1rem;
        cursor: pointer;
        transition: transform 0.15s ease, box-shadow 0.15s ease;
    }
    .btn-submit:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(22,160,133,0.3); color: #fff; }
    .btn-cancel {
        background: #f3f4f6; color: #6b7280; padding: 14px 28px; border-radius: 8px;
        text-decoration: none; font-weight: 600; display: inline-flex; align-items: center; gap: 8px;
    }
    .btn-cancel:hover { background: #e5e7eb; color: #4b5563; text-decoration: none; }
    .info-banner {
        background: linear-gradient(135deg, rgba(22,160,133,0.08), rgba(17,122,101,0.04));
        border-left: 4px solid #16a085;
        padding: 14px 18px;
        border-radius: 8px;
        margin-bottom: 24px;
        display: flex;
        align-items: center;
        gap: 14px;
    }
    .info-banner i { color: #16a085; font-size: 1.4rem; }
    .info-banner-text { font-size: 0.88rem; color: #0d3b3b; }
</style>

<div class="container-fluid py-4">
    <div style="margin-bottom:14px;">
        <a href="<?= $bp ?>/branch/batches" style="color:#16a085;text-decoration:none;font-size:0.88rem;">
            <i class="fas fa-arrow-left"></i> Back to Batches
        </a>
    </div>

    <h2 style="color:#0d3b3b; font-weight:700; margin-bottom:20px;">
        <i class="fas fa-plus-circle"></i> Create New Batch
    </h2>

    <div class="info-banner">
        <i class="fas fa-info-circle"></i>
        <div class="info-banner-text">
            <strong>Tip:</strong> Batches help you organize students by course and time slot. Students can be assigned to a batch during admission.
        </div>
    </div>

    <div class="card batch-form-card" style="max-width:750px;">
        <div class="card-header">
            <i class="fas fa-calendar-plus"></i> Batch Information
        </div>
        <div class="card-body">
            <form method="POST" action="<?= $bp ?>/branch/batches">
                <input type="hidden" name="csrf_token" value="<?= $csrf ?>">

                <div class="row">
                    <div class="col-md-8 mb-3">
                        <label class="form-label">Batch Name <span class="required-mark">*</span></label>
                        <input type="text" name="batch_name" class="form-control" required
                               placeholder="e.g., Morning Batch 2026"
                               value="<?= htmlspecialchars($_POST['batch_name'] ?? '', ENT_QUOTES, 'UTF-8') ?>">
                    </div>
                    <div class="col-md-4 mb-3">
                        <label class="form-label">Status</label>
                        <select name="status" class="form-select">
                            <option value="upcoming" <?= (($_POST['status'] ?? '') === 'upcoming') ? 'selected' : '' ?>>Upcoming</option>
                            <option value="running"  <?= (($_POST['status'] ?? '') === 'running')  ? 'selected' : '' ?>>Running</option>
                            <option value="completed" <?= (($_POST['status'] ?? '') === 'completed') ? 'selected' : '' ?>>Completed</option>
                        </select>
                    </div>
                </div>

                <div class="mb-3">
                    <label class="form-label">Course</label>
                    <select name="course_id" class="form-select">
                        <option value="">— Select Course (Optional) —</option>
                        <?php foreach ($courses as $c): ?>
                            <option value="<?= (int)$c['id'] ?>" <?= ((int)($_POST['course_id'] ?? 0) === (int)$c['id']) ? 'selected' : '' ?>>
                                <?= htmlspecialchars($c['name'], ENT_QUOTES, 'UTF-8') ?>
                                (<?= htmlspecialchars($c['duration'] ?? '', ENT_QUOTES, 'UTF-8') ?>)
                            </option>
                        <?php endforeach; ?>
                    </select>
                    <small class="text-muted">Optional — assign a course to this batch.</small>
                </div>

                <div class="row">
                    <div class="col-md-6 mb-3">
                        <label class="form-label">Start Date</label>
                        <input type="date" name="start_date" class="form-control"
                               value="<?= htmlspecialchars($_POST['start_date'] ?? date('Y-m-d'), ENT_QUOTES, 'UTF-8') ?>">
                    </div>
                    <div class="col-md-6 mb-3">
                        <label class="form-label">End Date</label>
                        <input type="date" name="end_date" class="form-control"
                               value="<?= htmlspecialchars($_POST['end_date'] ?? '', ENT_QUOTES, 'UTF-8') ?>">
                    </div>
                </div>

                <div class="row">
                    <div class="col-md-6 mb-3">
                        <label class="form-label">Start Time</label>
                        <input type="time" name="start_time" class="form-control"
                               value="<?= htmlspecialchars($_POST['start_time'] ?? '09:00', ENT_QUOTES, 'UTF-8') ?>">
                    </div>
                    <div class="col-md-6 mb-3">
                        <label class="form-label">End Time</label>
                        <input type="time" name="end_time" class="form-control"
                               value="<?= htmlspecialchars($_POST['end_time'] ?? '11:00', ENT_QUOTES, 'UTF-8') ?>">
                    </div>
                </div>

                <div class="row">
                    <div class="col-md-6 mb-3">
                        <label class="form-label">Max Students</label>
                        <input type="number" name="max_students" class="form-control" min="1"
                               value="<?= htmlspecialchars($_POST['max_students'] ?? '30', ENT_QUOTES, 'UTF-8') ?>">
                    </div>
                </div>

                <div class="mb-4">
                    <label class="form-label">Description (Optional)</label>
                    <textarea name="description" class="form-control" rows="3"
                              placeholder="Any notes about this batch..."><?= htmlspecialchars($_POST['description'] ?? '', ENT_QUOTES, 'UTF-8') ?></textarea>
                </div>

                <div class="d-flex justify-content-between flex-wrap gap-2">
                    <a href="<?= $bp ?>/branch/batches" class="btn-cancel">
                        <i class="fas fa-times"></i> Cancel
                    </a>
                    <button type="submit" class="btn-submit">
                        <i class="fas fa-check"></i> Create Batch
                    </button>
                </div>
            </form>
        </div>
    </div>
</div>
