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

<?= $this->section('content') ?>
    <div class="space-y-6">
        <section class="page-header">
            <div>
                <p class="page-kicker">Profil trainer</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 trainer</h3>
                    <p class="section-copy">Profil operational si campurile folosite in dashboard si in liste.</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">Nume complet</label>
                        <input type="text" name="full_name" class="form-input" value="<?= esc((string) $values['full_name']) ?>">
                        <?php if (! empty($errors['full_name'])) : ?><p class="field-error"><?= esc($errors['full_name']) ?></p><?php endif; ?>
                    </div>
                    <div>
                        <label class="mb-2 block text-sm font-medium text-slate-700">Rol afisat</label>
                        <select name="display_role" class="form-select">
                            <?php foreach ($roleOptions as $roleOption) : ?>
                                <option value="<?= esc($roleOption) ?>" <?= (string) $values['display_role'] === $roleOption ? 'selected' : '' ?>><?= esc($roleOption) ?></option>
                            <?php endforeach; ?>
                        </select>
                        <?php if (! empty($errors['display_role'])) : ?><p class="field-error"><?= esc($errors['display_role']) ?></p><?php endif; ?>
                    </div>
                    <div>
                        <label class="mb-2 block text-sm font-medium text-slate-700">Username</label>
                        <input type="text" name="username" class="form-input" value="<?= esc((string) $values['username']) ?>">
                        <?php if (! empty($errors['username'])) : ?><p class="field-error"><?= esc($errors['username']) ?></p><?php endif; ?>
                    </div>
                    <div>
                        <label class="mb-2 block text-sm font-medium text-slate-700">Email</label>
                        <input type="email" name="email" class="form-input" value="<?= esc((string) $values['email']) ?>">
                        <?php if (! empty($errors['email'])) : ?><p class="field-error"><?= esc($errors['email']) ?></p><?php endif; ?>
                    </div>
                    <div>
                        <label class="mb-2 block text-sm font-medium text-slate-700">Telefon</label>
                        <input type="text" name="phone" class="form-input" value="<?= esc((string) $values['phone']) ?>">
                        <?php if (! empty($errors['phone'])) : ?><p class="field-error"><?= esc($errors['phone']) ?></p><?php endif; ?>
                    </div>
                    <div>
                        <label class="mb-2 block text-sm font-medium text-slate-700">Avatar path</label>
                        <input type="text" name="avatar_path" class="form-input" value="<?= esc((string) $values['avatar_path']) ?>" placeholder="uploads/coaches/avatar.jpg">
                        <?php if (! empty($errors['avatar_path'])) : ?><p class="field-error"><?= esc($errors['avatar_path']) ?></p><?php endif; ?>
                    </div>
                    <div>
                        <label class="mb-2 block text-sm font-medium text-slate-700">Status</label>
                        <select name="is_active" class="form-select">
                            <option value="1" <?= (string) $values['is_active'] === '1' ? 'selected' : '' ?>>Activ</option>
                            <option value="0" <?= (string) $values['is_active'] === '0' ? 'selected' : '' ?>>Inactiv</option>
                        </select>
                        <?php if (! empty($errors['is_active'])) : ?><p class="field-error"><?= esc($errors['is_active']) ?></p><?php endif; ?>
                    </div>
                    <div>
                        <label class="mb-2 block text-sm font-medium text-slate-700">Parola <?= $coach === null ? '' : '(optional)' ?></label>
                        <input type="password" name="password" class="form-input" value="">
                        <?php if (! empty($errors['password'])) : ?><p class="field-error"><?= esc($errors['password']) ?></p><?php endif; ?>
                    </div>
                    <div>
                        <label class="mb-2 block text-sm font-medium text-slate-700">Confirmare parola</label>
                        <input type="password" name="password_confirmation" class="form-input" value="">
                        <?php if (! empty($errors['password_confirmation'])) : ?><p class="field-error"><?= esc($errors['password_confirmation']) ?></p><?php endif; ?>
                    </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">Disponibilitate saptamanala</h3>
                    <p class="section-copy">Configureaza zilele si intervalele in care trainerul este disponibil pentru sesiuni.</p>
                </div>
                <div class="space-y-3">
                    <?php foreach ($values['availability'] as $day => $slot) : ?>
                        <div class="grid gap-4 rounded-2xl border border-slate-200 bg-slate-50 px-4 py-4 md:grid-cols-[1.2fr_160px_160px]">
                            <label class="flex items-center gap-3">
                                <input type="checkbox" name="availability[<?= esc((string) $day) ?>][enabled]" value="1" class="form-checkbox" <?= ! empty($slot['enabled']) ? 'checked' : '' ?>>
                                <span class="text-sm font-medium text-slate-700"><?= esc(day_of_week_label((int) $day)) ?></span>
                            </label>
                            <input type="time" name="availability[<?= esc((string) $day) ?>][start]" class="form-input" value="<?= esc((string) $slot['start']) ?>">
                            <input type="time" name="availability[<?= esc((string) $day) ?>][end]" class="form-input" value="<?= esc((string) $slot['end']) ?>">
                        </div>
                    <?php endforeach; ?>
                </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() ?>
