<?php
/** @var array $courses */
/** @var string $csrfToken */
$bp = defined('BASE_PATH') ? BASE_PATH : '/gmind';
?>
<style>
.course-card {
    background: #fff;
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 16px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    border-left: 4px solid #16a085;
}
.course-card h4 { margin: 0 0 5px; color: #0d3b3b; font-size: 1rem; }
.course-card .meta { font-size: 0.82rem; color: #666; margin-bottom: 15px; }
.form-row { display: flex; gap: 15px; flex-wrap: wrap; align-items: flex-end; }
.form-group { flex: 1; min-width: 150px; }
.form-group label { display: block; font-size: 0.78rem; font-weight: 600; color: #0d3b3b; margin-bottom: 4px; }
.form-group input { width: 100%; padding: 8px 10px; border: 1px solid #ddd; border-radius: 6px; font-size: 0.86rem; }
.btn-save { background: linear-gradient(135deg,#16a085,#117a65); color: #fff; border: none; padding: 10px 20px; border-radius: 8px; font-weight: 600; cursor: pointer; font-size: 0.86rem; }
.global-fee { font-size: 0.72rem; color: #999; margin-top: 3px; }
</style>

<div class="container-fluid py-4">
    <div style="margin-bottom: 20px;">
        <h1 style="margin:0;font-size:1.3rem;color:#0d3b3b;">📚 My Courses & Settings</h1>
        <p style="margin:4px 0 0;font-size:0.84rem;color:#666;">
            Set your branch-specific course fee and exactly 3 subjects per course. 
            These will override global defaults and apply <strong>only to your branch</strong>.
        </p>
    </div>

    <?php if (empty($courses)): ?>
        <div class="course-card" style="text-align:center;padding:40px;">
            <i class="fas fa-book fa-3x mb-3" style="color:#ccc;"></i>
            <p style="color:#999;">No courses available.</p>
        </div>
    <?php else: ?>
        <?php foreach ($courses as $c): ?>
            <div class="course-card">
                <h4><?= htmlspecialchars($c['name'] ?? '', ENT_QUOTES, 'UTF-8') ?></h4>
                <div class="meta">
                    Duration: <?= htmlspecialchars($c['duration'] ?? '—', ENT_QUOTES, 'UTF-8') ?> · 
                    Global Fee: ₹<?= number_format((float)($c['fee'] ?? 0)) ?>
                </div>

                <form method="POST" action="<?= $bp ?>/branch/courses/update">
                    <input type="hidden" name="csrf_token" value="<?= htmlspecialchars($csrfToken, ENT_QUOTES, 'UTF-8') ?>">
                    <input type="hidden" name="course_id" value="<?= (int)$c['id'] ?>">
                    
                    <div class="form-row">
                        <div class="form-group">
                            <label>💰 Your Course Fee (₹)</label>
                            <input type="number" name="course_fee" value="<?= htmlspecialchars($c['branch_fee'] ?? '', ENT_QUOTES, 'UTF-8') ?>" min="0" step="0.01" placeholder="e.g., 5000">
                            <div class="global-fee">Default: ₹<?= number_format((float)($c['fee'] ?? 0)) ?></div>
                        </div>
                        
                        <div class="form-group">
                            <label>📘 Subject 1</label>
                            <input type="text" name="subject_1" value="<?= htmlspecialchars($c['branch_subject_1'] ?? '', ENT_QUOTES, 'UTF-8') ?>" placeholder="e.g., Theory">
                        </div>
                        
                        <div class="form-group">
                            <label>📗 Subject 2</label>
                            <input type="text" name="subject_2" value="<?= htmlspecialchars($c['branch_subject_2'] ?? '', ENT_QUOTES, 'UTF-8') ?>" placeholder="e.g., Practical">
                        </div>
                        
                        <div class="form-group">
                            <label>📙 Subject 3</label>
                            <input type="text" name="subject_3" value="<?= htmlspecialchars($c['branch_subject_3'] ?? '', ENT_QUOTES, 'UTF-8') ?>" placeholder="e.g., Lab">
                        </div>

                        <div class="form-group" style="flex:0;">
                            <button type="submit" class="btn-save">
                                <i class="fas fa-save"></i> Save
                            </button>
                        </div>
                    </div>
                </form>
            </div>
        <?php endforeach; ?>
    <?php endif; ?>
</div>
