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

<?= $this->section('content') ?>
<section class="qb-page-hero">
    <div class="flex flex-col gap-4 lg:flex-row lg:items-end lg:justify-between">
        <div class="qb-page-hero-copy">
            <span class="qb-label">Inventário técnico</span>
            <h1 class="mt-5 text-white">Turbinas</h1>
            <p class="mt-4 text-sm leading-7 text-slate-300">Inventário industrial das turbinas por parque eólico, pronto para manutenção e auditoria.</p>
        </div>
        <div class="flex flex-wrap gap-3">
            <span class="qb-chip qb-chip--soft"><?= count($turbines) ?> ativos</span>
            <a href="<?= site_url('turbines/new') ?>" class="qb-button-primary">Nova turbina</a>
        </div>
    </div>
</section>

<section class="qb-table-shell">
    <div class="overflow-x-auto">
        <table class="min-w-full text-sm">
            <thead>
                <tr>
                    <th class="px-4 py-4 text-left">Código</th>
                    <th class="px-4 py-4 text-left">Nome</th>
                    <th class="px-4 py-4 text-left">Site</th>
                    <th class="px-4 py-4 text-left">Modelo</th>
                    <th class="px-4 py-4 text-left">Potência</th>
                    <th class="px-4 py-4 text-left">Estado</th>
                    <th class="px-4 py-4 text-left">Ações</th>
                </tr>
            </thead>
            <tbody class="divide-y divide-white/5">
                <?php foreach ($turbines as $turbine): ?>
                    <tr>
                        <td class="px-4 py-4 font-semibold text-white"><span class="qb-code"><?= esc($turbine['turbine_code']) ?></span></td>
                        <td class="px-4 py-4"><?= esc($turbine['name'] ?: '-') ?></td>
                        <td class="px-4 py-4"><?= esc($turbine['site_name'] ?? '-') ?></td>
                        <td class="px-4 py-4"><?= esc($turbine['model'] ?: '-') ?></td>
                        <td class="px-4 py-4"><?= esc($turbine['rated_power_kw'] ?: '-') ?></td>
                        <td class="px-4 py-4"><span class="qb-status-pill qb-status-pill--soft"><?= esc($turbine['status']) ?></span></td>
                        <td class="px-4 py-4">
                            <div class="qb-table-actions">
                                <a href="<?= site_url('turbines/' . $turbine['id'] . '/edit') ?>" class="qb-button-secondary text-xs">Editar</a>
                                <form action="<?= site_url('turbines/' . $turbine['id'] . '/delete') ?>" method="post" onsubmit="return confirm('Remover esta turbina?');">
                                    <?= csrf_field() ?>
                                    <button type="submit" class="qb-button-danger text-xs">Remover</button>
                                </form>
                            </div>
                        </td>
                    </tr>
                <?php endforeach; ?>
                <?php if ($turbines === []): ?>
                    <tr>
                        <td colspan="7" class="px-4 py-6">
                            <div class="qb-empty-state">Ainda não existem turbinas registadas neste workspace.</div>
                        </td>
                    </tr>
                <?php endif; ?>
            </tbody>
        </table>
    </div>
</section>
<?= $this->endSection() ?>
