<h2 class="page-title">Editar Día Feriado</h2>
<p class="text-muted">Modifique 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/<?= $holiday->id ?>/update" method="POST">
                    <input type="hidden" name="_method" value="PUT">

                    <div class="form-group">
                        <label for="description">Descripción</label>
                        <input type="text" name="description" class="form-control" id="description" 
                            value="<?= htmlspecialchars($holiday->description) ?>" required>
                    </div>

                    <div class="form-row">
                        <div class="form-group col-md-4">
                            <label for="holiday_day">Día</label>
                            <input type="number" name="holiday_day" class="form-control" id="holiday_day" min="1" max="31"
                                value="<?= htmlspecialchars($holiday->holiday_day) ?>" required>
                        </div>

                        <div class="form-group col-md-4">
                            <label for="holiday_month">Mes</label>
                            <select name="holiday_month" class="form-control" id="holiday_month" required>
                                <?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 ?>" <?= $holiday->holiday_month == $num ? 'selected' : '' ?>>
                                        <?= $name ?>
                                    </option>
                                <?php endforeach; ?>
                            </select>
                        </div>

                        <div class="form-group col-md-4">
                            <label for="year">Año (opcional)</label>
                            <input type="number" name="year" class="form-control" id="year" min="1900" max="2100"
                                value="<?= htmlspecialchars($holiday->specific_year ?? '') ?>">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="d-block">Estado</label>
                        <div class="custom-control custom-radio">
                            <input type="radio" id="activo" name="active" class="custom-control-input" value="1" <?= $holiday->active == 1 ? 'checked' : '' ?>>
                            <label class="custom-control-label" for="activo">Activo</label>
                        </div>
                        <div class="custom-control custom-radio">
                            <input type="radio" id="inactivo" name="active" class="custom-control-input" value="0" <?= $holiday->active == 0 ? 'checked' : '' ?>>
                            <label class="custom-control-label" for="inactivo">Inactivo</label>
                        </div>
                    </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">Actualizar</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>