<?php
/**
 * Admin — Video Testimonial Form (Create/Edit)
 */
$bp = defined('BASE_PATH') ? BASE_PATH : '/gmind';
$video = $video ?? null;
$isEdit = $video !== null;
?>
<div class="admin-section">
    <div style="margin-bottom:20px;">
        <a href="<?= $bp ?>/admin/video-testimonials" style="color:#4A6CF7; text-decoration:none; font-size:13px; display:inline-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="currentColor" stroke-width="2"><polyline points="15 18 9 12 15 6"/></svg>
            Back to Video Testimonials
        </a>
    </div>

    <form method="POST" action="<?= $isEdit ? $bp . '/admin/video-testimonials/' . (int)$video['id'] : $bp . '/admin/video-testimonials' ?>" enctype="multipart/form-data" style="max-width:700px;">
        <input type="hidden" name="csrf_token" value="<?= htmlspecialchars($csrfToken ?? '', ENT_QUOTES, 'UTF-8') ?>">

        <div style="margin-bottom:16px;">
            <label style="display:block; font-weight:600; margin-bottom:6px; font-size:14px;">Student Name *</label>
            <input type="text" name="student_name" value="<?= htmlspecialchars($video['student_name'] ?? '', ENT_QUOTES, 'UTF-8') ?>" required
                style="width:100%; padding:10px 14px; border:1px solid #ddd; border-radius:8px; font-size:14px; outline:none;">
        </div>

        <div style="margin-bottom:16px;">
            <label style="display:block; font-weight:600; margin-bottom:6px; font-size:14px;">Course Name</label>
            <input type="text" name="course_name" value="<?= htmlspecialchars($video['course_name'] ?? '', ENT_QUOTES, 'UTF-8') ?>" placeholder="e.g., CCC, O-Level, ADCA"
                style="width:100%; padding:10px 14px; border:1px solid #ddd; border-radius:8px; font-size:14px; outline:none;">
        </div>

        <div style="margin-bottom:16px;">
            <label style="display:block; font-weight:600; margin-bottom:6px; font-size:14px;">Video URL *</label>
            <input type="url" name="video_url" value="<?= htmlspecialchars($video['video_url'] ?? '', ENT_QUOTES, 'UTF-8') ?>" required
                placeholder="https://www.youtube.com/watch?v=..." 
                style="width:100%; padding:10px 14px; border:1px solid #ddd; border-radius:8px; font-size:14px; outline:none;">
            <p style="font-size:12px; color:#888; margin:4px 0 0;">Paste YouTube link — thumbnail auto-generates from video</p>
        </div>

        <?php
        // Show preview if editing
        if ($isEdit && !empty($video['video_url'])):
            $embedUrl = \App\Models\VideoTestimonial::getEmbedUrl($video['video_url']);
        ?>
        <div style="margin-bottom:16px;">
            <label style="display:block; font-weight:600; margin-bottom:6px; font-size:14px;">Video Preview</label>
            <iframe src="<?= htmlspecialchars($embedUrl, ENT_QUOTES, 'UTF-8') ?>" style="width:100%; height:280px; border:none; border-radius:8px;" allowfullscreen></iframe>
        </div>
        <?php endif; ?>

        <div style="margin-bottom:16px;">
            <label style="display:block; font-weight:600; margin-bottom:6px; font-size:14px;">Custom Thumbnail (optional)</label>
            <input type="file" name="thumbnail" accept="image/jpeg,image/png,image/webp"
                style="width:100%; padding:10px; border:1px solid #ddd; border-radius:8px; font-size:14px;">
            <p style="font-size:12px; color:#888; margin:4px 0 0;">Leave empty to auto-use YouTube thumbnail</p>
        </div>

        <div style="margin-bottom:16px;">
            <label style="display:block; font-weight:600; margin-bottom:6px; font-size:14px;">Short Text</label>
            <textarea name="short_text" rows="2" maxlength="300" placeholder="A brief quote or description..."
                style="width:100%; padding:10px 14px; border:1px solid #ddd; border-radius:8px; font-size:14px; outline:none; resize:vertical;"><?= htmlspecialchars($video['short_text'] ?? '', ENT_QUOTES, 'UTF-8') ?></textarea>
        </div>

        <div style="display:flex; gap:16px; margin-bottom:16px; flex-wrap:wrap;">
            <div style="flex:1; min-width:120px;">
                <label style="display:block; font-weight:600; margin-bottom:6px; font-size:14px;">Sort Order</label>
                <input type="number" name="sort_order" value="<?= (int)($video['sort_order'] ?? 0) ?>" min="0"
                    style="width:100%; padding:10px 14px; border:1px solid #ddd; border-radius:8px; font-size:14px; outline:none;">
            </div>
            <div style="flex:1; min-width:120px;">
                <label style="display:block; font-weight:600; margin-bottom:6px; font-size:14px;">Status</label>
                <select name="status" style="width:100%; padding:10px 14px; border:1px solid #ddd; border-radius:8px; font-size:14px; outline:none;">
                    <option value="1" <?= ($video['status'] ?? 1) ? 'selected' : '' ?>>Active</option>
                    <option value="0" <?= !($video['status'] ?? 1) ? 'selected' : '' ?>>Inactive</option>
                </select>
            </div>
        </div>

        <div style="display:flex; gap:12px; margin-top:20px;">
            <button type="submit" class="admin-btn" style="background:#4A6CF7; color:#fff; padding:10px 24px; border-radius:8px; font-size:14px; font-weight:600; border:none; cursor:pointer;">
                <?= $isEdit ? 'Update Video Testimonial' : 'Add Video Testimonial' ?>
            </button>
            <a href="<?= $bp ?>/admin/video-testimonials" style="padding:10px 24px; border:1px solid #ddd; border-radius:8px; font-size:14px; color:#666; text-decoration:none;">Cancel</a>
        </div>
    </form>
</div>
