<?php

declare(strict_types=1);

// System Status (Phase 10 — Support). Redesigned to read as a genuine,
// professional service-status page (the Statuspage.io/GitHub Status
// convention: a full-width overall-status hero banner leads, a
// component-by-component breakdown follows) rather than two half-width
// cards competing for attention. developer/v1/support/status.php still
// reuses SystemHealthService::check() and the exact same per-service
// health computation the Dashboard's own API Health widget performs —
// no new health-check mechanism. The only backend addition is
// `checked_at` (the real server-side moment this check ran), added
// purely to support an honest "Last checked" caption.
//
// The former "Platform Status" side-by-side card is gone: a status
// page's overall verdict is the single most important thing on the
// page, so it now leads full-width, colored via
// .uh-dashboard-kpi-icon--success/--warning (dev.css, mirrors the
// existing --placeholder modifier's exact shape) instead of sitting
// beside Component Status as two equal-weight cards. Component Status
// keeps the exact dot+label+status row language
// (.uh-dashboard-health-row, dev.css) dashboard/index.php's own API
// Health widget already established — this page's whole subject IS a
// status page, so reusing it here (rather than a generic label/value
// table) was already the right call and still is.
//
// No uptime percentage or incident history is shown: neither exists in
// this platform yet (SystemHealthService has no time-series storage) —
// per this app's own "never fabricate a KPI or trend" rule, a section
// honestly says so instead of inventing numbers.
//
// Refresh control polish pass: brought in line with dashboard/index.php's
// own Refresh control — same "live" dot (.uh-dashboard-refresh-status/
// -dot, dev.css, reused verbatim) before the "Last checked" caption, and
// the same .uh-dashboard-refresh-btn class for the icon-spin/press-down
// loading treatment (support-status.js's own setRefreshLoading(), the
// same pattern dashboard.js's version uses). This replaces that button's
// previous guardSubmit() wrapper (components/form.js) — a generic form-
// submit helper used by 25 other pages for real form submits, but this
// was its only "Refresh button" call site, so swapping it here doesn't
// touch anything guardSubmit does elsewhere.

require __DIR__ . '/../includes/bootstrap.php';

$pageTitle = 'System Status';
$activeNav = 'support';
$breadcrumbs = [['label' => 'Support', 'href' => uh_url('support/')], ['label' => 'System Status']];
$pageScript = 'support-status';

ob_start();
?>

<?= uh_subnav(uh_support_nav_items(), 'status') ?>

<div id="uh-status-error" class="alert alert-danger d-none" role="alert">
  <span id="uh-status-error-message">Unable to load system status.</span>
  <button type="button" class="btn btn-sm btn-outline-danger ms-3" id="uh-status-retry">Retry</button>
</div>

<div class="mb-3">
  <?= uh_card(
      '<div class="d-flex align-items-center justify-content-between flex-wrap gap-3">'
      . '<div class="d-flex align-items-center gap-3">'
      . '<span id="uh-status-hero-icon" class="uh-dashboard-kpi-icon uh-dashboard-kpi-icon--lg">' . uh_icon('check', 24) . '</span>'
      . '<div>'
      . '<div id="uh-status-hero-text" class="fs-4 fw-bold">Checking status…</div>'
      . '<span class="uh-dashboard-refresh-status"><span class="uh-dashboard-refresh-dot" aria-hidden="true"></span><span class="text-muted fs-8">Last checked <span id="uh-status-checked-at">—</span></span></span>'
      . '</div>'
      . '</div>'
      . '<button type="button" class="btn btn-outline-light btn-sm uh-dashboard-refresh-btn" id="uh-status-refresh">' . uh_icon('refresh', 14, 'me-1') . '<span id="uh-status-refresh-label">Refresh</span></button>'
      . '</div>'
  ) ?>
</div>

<div class="mb-3">
  <?= uh_card('<div id="uh-status-services-list"></div>', 'Component Status', '', 'analytics') ?>
</div>

<?= uh_card(
    '<p class="text-muted fs-8 mb-0">Historical uptime and incident tracking are not yet available, this page reflects real-time status only, refreshed on load and whenever you click Refresh.</p>',
    'Uptime & Incident History', '', 'clock'
) ?>
<?php
$content = ob_get_clean();
require __DIR__ . '/../layouts/app.php';
