<?php require __DIR__ . '/settings_nav.php';
$groups = ['environment' => t('health.group_environment'),'database' => t('health.group_database'),'storage' => t('health.group_storage'),'continuity' => t('health.group_continuity'),'files' => t('health.group_files'),'security' => t('health.group_security')]; ?>
<?php if ($installed): ?><div class="alert alert-success">✅ <?= h(t('install.complete')) ?></div><?php endif; ?>
<div class="d-flex flex-wrap align-items-end justify-content-between gap-3 mb-3">
    <div>
        <h2 class="mb-1"><?= h(t('health.title')) ?></h2>
        <div class="text-muted"><?= h(t('health.intro')) ?></div>
    </div><a class="btn btn-primary" href="/settings/health">↻ <?= h(t('health.refresh')) ?></a>
</div>
<div class="row g-3 mb-4">
    <div class="col-md-4">
        <div class="card border-success">
            <div class="card-body">
                <div class="subheader"><?= h(t('health.ok')) ?></div>
                <div class="h1 text-success mb-0"><?= (int)$report['summary']['ok'] ?></div>
            </div>
        </div>
    </div>
    <div class="col-md-4">
        <div class="card border-warning">
            <div class="card-body">
                <div class="subheader"><?= h(t('health.warnings')) ?></div>
                <div class="h1 text-warning mb-0"><?= (int)$report['summary']['warning'] ?></div>
            </div>
        </div>
    </div>
    <div class="col-md-4">
        <div class="card border-danger">
            <div class="card-body">
                <div class="subheader"><?= h(t('health.errors')) ?></div>
                <div class="h1 text-danger mb-0"><?= (int)$report['summary']['error'] ?></div>
            </div>
        </div>
    </div>
</div>
<div class="alert alert-info d-flex flex-wrap justify-content-between gap-2">
    <span><?= h(t('health.versions', ['php' => $report['php'],'sqlite' => $report['sqlite']])) ?></span><span><?= h(t('health.generated', ['date' => $report['generated_at']])) ?></span>
</div>
<?php foreach ($groups as $group => $label): $rows = array_values(array_filter($report['checks'], static fn (array$c): bool => $c['group'] === $group));
    if (!$rows) {
        continue;
    } ?><div class="card mb-3">
    <div class="card-header">
        <h3 class="card-title"><?= h($label) ?></h3>
    </div>
    <div class="list-group list-group-flush"><?php foreach ($rows as $row): ?><div class="list-group-item">
            <div class="d-flex gap-3"><span
                    class="fs-2"><?= $row['status'] === 'ok' ? '✅' : ($row['status'] === 'warning' ? '⚠️' : '❌') ?></span>
                <div>
                    <div class="fw-semibold"><?= h($row['title']) ?></div>
                    <div class="text-muted small"><?= h($row['detail']) ?></div>
                </div>
            </div>
        </div><?php endforeach; ?></div>
</div><?php endforeach; ?>
<div class="text-muted small text-end"><?= h(t('health.read_only')) ?></div>
