<?= $this->extend('layouts/main') ?>
<?= $this->section('content') ?>

<div class="d-flex justify-content-between align-items-center mb-3">
    <h4 class="mb-0">
        <i class="bi bi-clock-history text-primary me-2"></i>
        Edit Jam Pelajaran
    </h4>
    <a href="/asc-import" class="btn btn-sm btn-outline-secondary">
        <i class="bi bi-arrow-left me-1"></i>Kembali ke Daftar Import
    </a>
</div>

<div class="card">
    <div class="card-header">
        <strong><?= esc($import['name']) ?></strong><br>
        <small class="text-muted">Tahun Ajaran <?= esc($import['academic_year']) ?> — Semester <?= esc($import['semester']) ?></small>
    </div>
    <div class="card-body">
        
        <?php if (empty($periods)): ?>
            <div class="alert alert-warning">
                <i class="bi bi-exclamation-triangle me-2"></i>
                Belum ada data periode/jam pelajaran untuk import ini.
            </div>
        <?php else: ?>

        <div class="alert alert-info">
            <i class="bi bi-info-circle me-2"></i>
            Ubah jam mulai dan jam selesai untuk setiap periode pelajaran. 
            Perubahan akan langsung berdampak pada semua jadwal di import ini.
        </div>

        <form method="post" action="/asc-import/update-periods/<?= $import['id'] ?>">
            <?= csrf_field() ?>
            
            <div class="table-responsive">
                <table class="table table-bordered table-hover">
                    <thead class="table-dark">
                        <tr>
                            <th style="width:60px">No</th>
                            <th style="width:100px">Jam ke-</th>
                            <th style="width:180px">Jam Mulai</th>
                            <th style="width:180px">Jam Selesai</th>
                            <th>Nama Periode</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php foreach ($periods as $index => $period): ?>
                        <tr>
                            <td class="text-center"><?= $index + 1 ?></td>
                            <td class="text-center fw-bold"><?= $period['period_number'] ?></td>
                            <td>
                                <input type="time" 
                                       name="periods[<?= $period['id'] ?>][start_time]" 
                                       value="<?= esc($period['start_time']) ?>"
                                       class="form-control form-control-sm"
                                       required>
                            </td>
                            <td>
                                <input type="time" 
                                       name="periods[<?= $period['id'] ?>][end_time]" 
                                       value="<?= esc($period['end_time']) ?>"
                                       class="form-control form-control-sm"
                                       required>
                            </td>
                            <td>
                                <input type="text" 
                                       name="periods[<?= $period['id'] ?>][name]" 
                                       value="<?= esc($period['name']) ?>"
                                       class="form-control form-control-sm"
                                       placeholder="Nama periode (opsional)">
                            </td>
                        </tr>
                        <?php endforeach; ?>
                    </tbody>
                </table>
            </div>

            <div class="mt-3 d-flex justify-content-end gap-2">
                <button type="submit" class="btn btn-primary">
                    <i class="bi bi-save me-1"></i>Simpan Perubahan
                </button>
                <a href="/asc-import/edit-periods/<?= $import['id'] ?>" class="btn btn-secondary">
                    <i class="bi bi-arrow-repeat me-1"></i>Reset
                </a>
            </div>
        </form>
        
        <?php endif; ?>
    </div>
</div>

<?= $this->endSection() ?>