<h2 class="page-title">Nuevo Día Feriado</h2>
<p class="text-muted">Ingrese los datos del día festivo en el formulario.</p>
<div class="row">
    <div class="col-md-12">
        <div class="card shadow mb-4">
            <div class="card-header">
                <strong class="card-title">Formulario</strong>
            </div>
            <div class="card-body">
                <form action="<?= BASE_ACTION ?>holidays" method="POST">
                    <div class="form-group">
                        <label for="description">Descripción</label>
                        <input type="text" name="description" class="form-control" id="description" required>
                    </div>

                    <div class="form-group">
                        <label for="holiday_day">Día</label>
                        <input type="number" name="holiday_day" class="form-control" id="holiday_day" required min="1" max="31">
                    </div>

                    <div class="form-group">
                        <label for="holiday_month">Mes</label>
                        <select name="holiday_month" id="holiday_month" class="form-control" required>
                            <option value="">-- Mes --</option>
                            <?php
                            $months = [
                                1 => 'Enero', 2 => 'Febrero', 3 => 'Marzo',
                                4 => 'Abril', 5 => 'Mayo', 6 => 'Junio',
                                7 => 'Julio', 8 => 'Agosto', 9 => 'Septiembre',
                                10 => 'Octubre', 11 => 'Noviembre', 12 => 'Diciembre'
                            ];
                            foreach ($months as $num => $name): ?>
                                <option value="<?= $num ?>"><?= $name ?></option>
                            <?php endforeach; ?>
                        </select>
                    </div>

                    <div class="form-group">
                        <label for="year">Año (opcional)</label>
                        <input type="number" name="year" class="form-control" id="year" min="2020" max="<?= date('Y') + 10 ?>">
                        <small class="form-text text-muted">Complete este campo solo si es un feriado específico de un año.</small>
                    </div>

                    <div class="d-flex justify-content-start">
                        <a href="<?= BASE_HREF ?>holidays" class="btn btn-secondary mr-2">Cancelar</a>
                        <button type="submit" class="btn btn-primary">Guardar</button>
                    </div>
                </form>

            </div>
        </div>
    </div>
</div>

<script>
    document.addEventListener("DOMContentLoaded", function() {
        document.querySelectorAll("input[required], select[required], textarea[required]").forEach(function (input) {
            let label = document.querySelector(`label[for="${input.id}"]`);
            if (label && !label.innerHTML.includes("*")) {
                label.innerHTML += ' <span class="text-danger">*</span>';
            }
        });
    });
</script>

<script>
    document.getElementById('description').addEventListener('input', function (event) {
        event.target.value = event.target.value.toUpperCase();
    });
</script>