<?php
require_once dirname(__DIR__) . '/config/config.php';
require_once dirname(__DIR__) . '/includes/db.php';
require_once dirname(__DIR__) . '/includes/functions.php';
require_once dirname(__DIR__) . '/includes/auth.php';
require_once dirname(__DIR__) . '/includes/diagnostics.php';
require_once dirname(__DIR__) . '/includes/layout.php';
requirePermission('diagnostics_view');

$results = getDiagnosticsResults();
$statusLabels = ['ok' => '정상', 'warning' => '주의', 'error' => '오류', 'unknown' => '확인 필요'];

renderHeader('진단센터', 'diagnostics');
?>
<div class="admin-dashboard diagnostics-page">
    <div class="page-title-section">
        <h1 class="page-main-title">진단센터</h1>
        <p class="page-subtitle">서버, DB, 스캔 경로, storage 권한, PWA 파일, 보관함 상태를 빠르게 점검합니다.</p>
    </div>

    <div class="diagnostic-grid">
        <?php foreach ($results as $result): ?>
            <?php $status = $result['status'] ?? 'unknown'; ?>
            <article class="diagnostic-card status-<?php echo h($status); ?>">
                <div class="diagnostic-card-head">
                    <strong><?php echo h($result['title']); ?></strong>
                    <span class="diagnostic-badge"><?php echo h($statusLabels[$status] ?? '확인 필요'); ?></span>
                </div>
                <p><?php echo h($result['message']); ?></p>
                <?php if (!empty($result['detail'])): ?><small><?php echo h($result['detail']); ?></small><?php endif; ?>
            </article>
        <?php endforeach; ?>
    </div>
</div>
<?php renderFooter(); ?>
