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

<?= $this->section('content') ?>
<section class="card stack-md">
    <form method="post" action="<?= site_url('inspections') ?>" class="stack-md">
        <?= csrf_field() ?>

        <div class="grid grid-2">
            <div>
                <label>Plantilla *</label>
                <select name="template_id" required>
                    <option value="">Selecciona…</option>
                    <?php foreach ($templates as $t): ?>
                        <option value="<?= (int) $t['id'] ?>" <?= $preselect_template === (int) $t['id'] ? 'selected' : '' ?>>
                            <?= esc($t['code']) ?> — <?= esc($t['name']) ?>
                        </option>
                    <?php endforeach; ?>
                </select>
            </div>
            <div>
                <label>Cliente *</label>
                <select name="client_id" required>
                    <option value="">Selecciona…</option>
                    <?php foreach ($clients as $c): ?>
                        <option value="<?= (int) $c['id'] ?>" <?= $preselect_client === (int) $c['id'] ? 'selected' : '' ?>>
                            <?= esc($c['nombre']) ?>
                        </option>
                    <?php endforeach; ?>
                </select>
            </div>
        </div>

        <div class="grid grid-2">
            <div>
                <label>Sistema</label>
                <input type="text" name="sistema" placeholder="Ej. Sprinklers piso 3">
            </div>
            <div>
                <label>Equipo</label>
                <input type="text" name="equipo" placeholder="Ej. Bomba jockey, riser, tablero">
            </div>
        </div>
        <div class="grid grid-2">
            <div>
                <label>Atención</label>
                <input type="text" name="atencion" placeholder="Nombre de quien atiende">
            </div>
            <div>
                <label>Servicio</label>
                <input type="text" name="servicio">
            </div>
        </div>
        <div class="grid grid-2">
            <div>
                <label>Contrato</label>
                <input type="text" name="contrato">
            </div>
            <div>
                <label>Fecha</label>
                <input type="date" name="fecha" value="<?= esc(date('Y-m-d')) ?>">
            </div>
        </div>
        <div class="grid grid-2">
            <div>
                <label>Periodicidad</label>
                <select name="periodicidad" required>
                    <option value="mensual">Mensual</option>
                    <option value="semestral">Semestral</option>
                    <option value="anual">Anual</option>
                </select>
            </div>
        </div>

        <div class="actions-row">
            <a class="btn btn-secondary" href="<?= site_url('inspections') ?>">Cancelar</a>
            <button class="btn btn-primary" type="submit">Iniciar inspección</button>
        </div>
    </form>
</section>
<?= $this->endSection() ?>
