<?php
$bp = defined('BASE_PATH') ? BASE_PATH : '/gmind';
$student = $student ?? [];
$photoPath = $photoPath ?? '';
$courseName = $courseName ?? '';
$courseDuration = $courseDuration ?? '';
$batchName = $batchName ?? '';
$csrfToken = $csrfToken ?? '';

$photoUrl = $bp . '/images/avatar-default.png';
if (!empty($photoPath)) $photoUrl = $bp . '/' . ltrim($photoPath, '/');
?>
<div class="admin-section">
    <div style="margin-bottom:14px;">
        <a href="<?= $bp ?>/branch/cert-gen/new" style="color:#16a085;text-decoration:none;font-size:0.85rem;">← Edit Form</a>
    </div>

    <div style="background:linear-gradient(135deg,#0d3b3b,#16a085);color:#fff;border-radius:12px;padding:18px;margin-bottom:18px;">
        <h1 style="margin:0;font-size:1.15rem;">👁 Step 2: Preview Student Details</h1>
        <p style="margin:6px 0 0;opacity:0.9;font-size:0.84rem;">Review all details. Click "Edit" to change, or "Submit" / "Create Result" to proceed.</p>
    </div>

    <div style="background:#fff;border-radius:12px;padding:24px;box-shadow:0 2px 8px rgba(0,0,0,0.06);">
        <div style="display:grid;grid-template-columns:150px 1fr;gap:20px;margin-bottom:20px;">
            <div>
                <img src="<?= htmlspecialchars($photoUrl, ENT_QUOTES, 'UTF-8') ?>" alt="Photo" style="width:140px;height:170px;object-fit:cover;border:2px solid #0d3b3b;border-radius:8px;" onerror="this.src='<?= $bp ?>/images/avatar-default.png'">
            </div>
            <div>
                <h2 style="margin:0 0 6px;font-size:1.2rem;color:#0d3b3b;"><?= htmlspecialchars($student['name'] ?? '', ENT_QUOTES, 'UTF-8') ?></h2>
                <p style="margin:0 0 4px;font-size:0.88rem;color:#666;">S/o: <?= htmlspecialchars($student['father_name'] ?? '', ENT_QUOTES, 'UTF-8') ?></p>
                <p style="margin:0 0 4px;font-size:0.88rem;color:#666;">DOB: <?= htmlspecialchars($student['dob'] ?? '', ENT_QUOTES, 'UTF-8') ?></p>
                <p style="margin:0;font-size:0.88rem;color:#666;">📱 <?= htmlspecialchars($student['phone'] ?? '', ENT_QUOTES, 'UTF-8') ?> · ✉️ <?= htmlspecialchars($student['email'] ?? '', ENT_QUOTES, 'UTF-8') ?></p>
            </div>
        </div>

        <table style="width:100%;font-size:0.88rem;border-collapse:collapse;">
            <tr style="border-bottom:1px solid #f0f0f0;"><td style="padding:8px 0;color:#999;width:30%;">Course</td><td style="padding:8px 0;font-weight:600;"><?= htmlspecialchars($courseName, ENT_QUOTES, 'UTF-8') ?> (<?= htmlspecialchars($courseDuration, ENT_QUOTES, 'UTF-8') ?>)</td></tr>
            <tr style="border-bottom:1px solid #f0f0f0;"><td style="padding:8px 0;color:#999;">Batch</td><td style="padding:8px 0;font-weight:600;"><?= htmlspecialchars($batchName ?: '—', ENT_QUOTES, 'UTF-8') ?></td></tr>
            <tr style="border-bottom:1px solid #f0f0f0;"><td style="padding:8px 0;color:#999;">Full Address</td><td style="padding:8px 0;font-weight:600;"><?= htmlspecialchars($student['address'] ?? '—', ENT_QUOTES, 'UTF-8') ?></td></tr>
            <tr style="border-bottom:1px solid #f0f0f0;"><td style="padding:8px 0;color:#999;">City</td><td style="padding:8px 0;font-weight:600;"><?= htmlspecialchars($student['city'] ?? '—', ENT_QUOTES, 'UTF-8') ?></td></tr>
            <tr style="border-bottom:1px solid #f0f0f0;"><td style="padding:8px 0;color:#999;">State</td><td style="padding:8px 0;font-weight:600;"><?= htmlspecialchars($student['state'] ?? '—', ENT_QUOTES, 'UTF-8') ?></td></tr>
            <tr><td style="padding:8px 0;color:#999;">PIN Code</td><td style="padding:8px 0;font-weight:600;"><?= htmlspecialchars($student['pin_code'] ?? '—', ENT_QUOTES, 'UTF-8') ?></td></tr>
        </table>
    </div>

    <!-- Action buttons -->
    <div style="display:flex;gap:12px;justify-content:center;margin-top:24px;flex-wrap:wrap;">
        <a href="<?= $bp ?>/branch/cert-gen/new" style="padding:14px 28px;border:2px solid #f39c12;color:#f39c12;border-radius:8px;text-decoration:none;font-weight:600;font-size:0.9rem;">
            ✎ Edit Form
        </a>
        <form method="POST" action="<?= $bp ?>/branch/cert-gen/store-student" style="display:inline;">
            <input type="hidden" name="csrf_token" value="<?= htmlspecialchars($csrfToken, ENT_QUOTES, 'UTF-8') ?>">
            <button type="submit" style="padding:14px 28px;background:#7f8c8d;color:#fff;border:none;border-radius:8px;font-weight:600;font-size:0.9rem;cursor:pointer;">
                ✓ Submit Form Only
            </button>
        </form>
        <!-- Note: "Create Result" button appears AFTER student is saved (on the student detail page) -->
        <p style="width:100%;text-align:center;font-size:0.78rem;color:#999;margin-top:10px;">
            💡 Click "Submit Form Only" to save the student. Then you'll be redirected to the student page where you can click "Create Result" to generate certificate + marksheet.
        </p>
    </div>
</div>
