<?= $this->extend('layouts/dashboard') ?>

<?= $this->section('content') ?>
    <div class="space-y-6">
        <section class="page-header">
            <div>
                <p class="page-kicker">Children Master</p>
                <h2 class="section-title text-2xl"><?= esc($pageTitle) ?></h2>
                <p class="section-copy mt-2 max-w-3xl"><?= esc($pageDescription) ?></p>
            </div>
        </section>

        <?php if (! empty($errors['general'])) : ?>
            <div class="rounded-2xl border border-rose-200 bg-rose-50 px-4 py-3 text-sm text-rose-700"><?= esc($errors['general']) ?></div>
        <?php endif; ?>

        <form method="post" action="<?= esc($submitUrl) ?>" class="space-y-6">
            <section class="surface-card p-6">
                <div class="mb-6">
                    <h3 class="section-title">Date copil</h3>
                    <p class="section-copy">Seteaza identitatea copilului si asignarea initiala in academie.</p>
                </div>
                <div class="grid gap-5 md:grid-cols-2 xl:grid-cols-3">
                    <div>
                        <label class="mb-2 block text-sm font-medium text-slate-700">Prenume</label>
                        <input type="text" name="first_name" class="form-input" value="<?= esc((string) $values['first_name']) ?>">
                        <?php if (! empty($errors['first_name'])) : ?><p class="field-error"><?= esc($errors['first_name']) ?></p><?php endif; ?>
                    </div>
                    <div>
                        <label class="mb-2 block text-sm font-medium text-slate-700">Nume</label>
                        <input type="text" name="last_name" class="form-input" value="<?= esc((string) $values['last_name']) ?>">
                        <?php if (! empty($errors['last_name'])) : ?><p class="field-error"><?= esc($errors['last_name']) ?></p><?php endif; ?>
                    </div>
                    <div>
                        <label class="mb-2 block text-sm font-medium text-slate-700">Data nasterii</label>
                        <input type="date" name="birth_date" class="form-input" value="<?= esc((string) $values['birth_date']) ?>">
                        <?php if (! empty($errors['birth_date'])) : ?><p class="field-error"><?= esc($errors['birth_date']) ?></p><?php endif; ?>
                    </div>
                    <div>
                        <label class="mb-2 block text-sm font-medium text-slate-700">Gen</label>
                        <select name="gender" class="form-select">
                            <option value="">Selecteaza</option>
                            <?php foreach ($options['genders'] as $gender) : ?>
                                <option value="<?= esc($gender['value']) ?>" <?= (string) $values['gender'] === $gender['value'] ? 'selected' : '' ?>><?= esc($gender['label']) ?></option>
                            <?php endforeach; ?>
                        </select>
                        <?php if (! empty($errors['gender'])) : ?><p class="field-error"><?= esc($errors['gender']) ?></p><?php endif; ?>
                    </div>
                    <div>
                        <label class="mb-2 block text-sm font-medium text-slate-700">Nivel curent</label>
                        <select name="academy_level_id" class="form-select">
                            <option value="">Selecteaza nivelul</option>
                            <?php foreach ($options['levels'] as $level) : ?>
                                <option value="<?= esc((string) $level['id']) ?>" <?= (string) $values['academy_level_id'] === (string) $level['id'] ? 'selected' : '' ?>><?= esc($level['name']) ?></option>
                            <?php endforeach; ?>
                        </select>
                        <?php if (! empty($errors['academy_level_id'])) : ?><p class="field-error"><?= esc($errors['academy_level_id']) ?></p><?php endif; ?>
                    </div>
                    <div>
                        <label class="mb-2 block text-sm font-medium text-slate-700">Grupa</label>
                        <select name="academy_group_id" class="form-select">
                            <option value="">Selecteaza grupa</option>
                            <?php foreach ($options['groups'] as $group) : ?>
                                <option value="<?= esc((string) $group['id']) ?>" <?= (string) $values['academy_group_id'] === (string) $group['id'] ? 'selected' : '' ?>><?= esc($group['name']) ?></option>
                            <?php endforeach; ?>
                        </select>
                        <?php if (! empty($errors['academy_group_id'])) : ?><p class="field-error"><?= esc($errors['academy_group_id']) ?></p><?php endif; ?>
                    </div>
                    <div>
                        <label class="mb-2 block text-sm font-medium text-slate-700">Trainer principal</label>
                        <select name="primary_coach_id" class="form-select">
                            <option value="">Selecteaza trainerul</option>
                            <?php foreach ($options['coaches'] as $coach) : ?>
                                <option value="<?= esc((string) $coach['id']) ?>" <?= (string) $values['primary_coach_id'] === (string) $coach['id'] ? 'selected' : '' ?>><?= esc($coach['full_name']) ?></option>
                            <?php endforeach; ?>
                        </select>
                        <?php if (! empty($errors['primary_coach_id'])) : ?><p class="field-error"><?= esc($errors['primary_coach_id']) ?></p><?php endif; ?>
                    </div>
                    <div>
                        <label class="mb-2 block text-sm font-medium text-slate-700">Prima zi curs</label>
                        <input type="date" name="first_class_at" class="form-input" value="<?= esc((string) $values['first_class_at']) ?>">
                        <?php if (! empty($errors['first_class_at'])) : ?><p class="field-error"><?= esc($errors['first_class_at']) ?></p><?php endif; ?>
                    </div>
                    <div>
                        <label class="mb-2 block text-sm font-medium text-slate-700">Status</label>
                        <select name="status" class="form-select">
                            <?php foreach ($options['statuses'] as $status) : ?>
                                <option value="<?= esc($status['value']) ?>" <?= (string) $values['status'] === $status['value'] ? 'selected' : '' ?>><?= esc($status['label']) ?></option>
                            <?php endforeach; ?>
                        </select>
                        <?php if (! empty($errors['status'])) : ?><p class="field-error"><?= esc($errors['status']) ?></p><?php endif; ?>
                    </div>
                    <div class="flex items-center gap-3 rounded-2xl border border-slate-200 bg-slate-50 px-4 py-3">
                        <input type="hidden" name="has_siblings" value="0">
                        <input type="checkbox" id="has_siblings" name="has_siblings" value="1" class="form-checkbox" <?= (string) $values['has_siblings'] === '1' ? 'checked' : '' ?>>
                        <label for="has_siblings" class="text-sm font-medium text-slate-700">Are frati / surori in academie</label>
                    </div>
                </div>
                <div class="mt-5">
                    <label class="mb-2 block text-sm font-medium text-slate-700">Observatii</label>
                    <textarea name="notes" rows="4" class="form-input"><?= esc((string) $values['notes']) ?></textarea>
                    <?php if (! empty($errors['notes'])) : ?><p class="field-error"><?= esc($errors['notes']) ?></p><?php endif; ?>
                </div>
            </section>

            <section class="surface-card p-6">
                <div class="mb-6">
                    <h3 class="section-title">Contact parinte / tutore</h3>
                    <p class="section-copy">Aceste date sunt folosite pentru profilul copilului si comunicarea operationala.</p>
                </div>
                <div class="grid gap-5 md:grid-cols-3">
                    <div>
                        <label class="mb-2 block text-sm font-medium text-slate-700">Nume parinte</label>
                        <input type="text" name="guardian_name" class="form-input" value="<?= esc((string) $values['guardian_name']) ?>">
                        <?php if (! empty($errors['guardian_name'])) : ?><p class="field-error"><?= esc($errors['guardian_name']) ?></p><?php endif; ?>
                    </div>
                    <div>
                        <label class="mb-2 block text-sm font-medium text-slate-700">Telefon</label>
                        <input type="text" name="guardian_phone" class="form-input" value="<?= esc((string) $values['guardian_phone']) ?>">
                        <?php if (! empty($errors['guardian_phone'])) : ?><p class="field-error"><?= esc($errors['guardian_phone']) ?></p><?php endif; ?>
                    </div>
                    <div>
                        <label class="mb-2 block text-sm font-medium text-slate-700">Email</label>
                        <input type="email" name="guardian_email" class="form-input" value="<?= esc((string) $values['guardian_email']) ?>">
                        <?php if (! empty($errors['guardian_email'])) : ?><p class="field-error"><?= esc($errors['guardian_email']) ?></p><?php endif; ?>
                    </div>
                </div>
            </section>

            <div class="flex flex-wrap gap-3">
                <button type="submit" class="btn-primary">Salveaza</button>
                <a href="<?= esc($cancelUrl) ?>" class="btn-secondary">Renunta</a>
            </div>
        </form>
    </div>
<?= $this->endSection() ?>
