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

<?= $this->section('content') ?>
<section class="card stack-md">
    <div class="section-head">
        <div>
            <h3>Plantillas de inspección</h3>
            <p>Catálogo de formatos (SIM1, SIM6, SIM9, SIM11…) con sus preguntas y frecuencias.</p>
        </div>
        <a class="btn btn-primary" href="<?= site_url('inspection-templates/create') ?>">Nueva plantilla</a>
    </div>

    <?php if ($templates === []): ?>
        <p class="muted">Aún no hay plantillas.</p>
    <?php else: ?>
        <div class="table-wrap">
            <table>
                <thead>
                    <tr><th>Código</th><th>Nombre</th><th>FORM.SE</th><th>Modo</th><th>Rev.</th><th>Activo</th><th></th></tr>
                </thead>
                <tbody>
                <?php foreach ($templates as $t): ?>
                    <tr>
                        <td><strong><?= esc($t['code']) ?></strong></td>
                        <td><?= esc($t['name']) ?></td>
                        <td><?= esc($t['form_code'] ?? '') ?></td>
                        <td><?= esc($t['layout_mode']) ?></td>
                        <td><?= esc((string) $t['revision']) ?></td>
                        <td><?= $t['activo'] ? 'Sí' : 'No' ?></td>
                        <td><a href="<?= site_url('inspection-templates/' . $t['id'] . '/edit') ?>">Editar</a></td>
                    </tr>
                <?php endforeach; ?>
                </tbody>
            </table>
        </div>
    <?php endif; ?>
</section>
<?= $this->endSection() ?>
