import { useRef, type ReactNode, type RefObject } from 'react' import { AlertCircle, Check, ChevronDown, Copy, Download, ExternalLink, RefreshCw } from 'lucide-react' import { Button } from '@/components/ui/button' import { ReportError, ReportSkeleton } from '@/components/ui/reporting' import { useSystemInfo } from '../hooks/use-system-info' import { buildDiagnostics, displayValue, environmentGroups, registrationRows, statusLabel, summarizeDiagnostics } from '../diagnostics' import type { DiagnosticCheck, DiagnosticStatus } from '../config' import type { ReportRow } from '../diagnostics' const statusClass: Record = { pass: 'bg-emerald-50 text-emerald-800', warning: 'bg-amber-50 text-amber-900', fail: 'bg-red-50 text-red-800', unknown: 'bg-slate-100 text-slate-700', } function Status({ status }: { status: DiagnosticStatus }) { return {statusLabel[status]} } function Rows({ rows }: { rows: ReportRow[] }) { return
{rows.map(([label, value]) =>
{label}
{displayValue(value)}
)}
} function DetailsSection({ title, description, children, sectionRef, nested = false }: { title: string; description?: string; children: ReactNode; sectionRef?: RefObject; nested?: boolean }) { const Heading = nested ? 'h3' : 'h2' return
{title}{description &&

{description}

}
{children}
} function CheckRow({ check, expanded = false }: { check: DiagnosticCheck; expanded?: boolean }) { return
  • {check.name}

    Current
    {check.current}
    {check.kind === 'requirement' ? 'Required' : 'Guidance'}
    {check.expected}
    {expanded && <>

    {check.detail}

    {check.action &&

    {check.action}

    } {check.helpUrl && Memory configuration guide} }
  • } export function SystemInfoPage() { const { systemInfo: info, loading, error, checkedAt, refresh, copyState, copyToClipboard, downloadReport, downloadError } = useSystemInfo() const issuesRef = useRef(null) const passedRef = useRef(null) const checks = info ? buildDiagnostics(info) : [] const counts = summarizeDiagnostics(checks) const priority: Record = { fail: 0, warning: 1, unknown: 2, pass: 3 } const issues = checks.filter(check => check.status !== 'pass').sort((a, b) => priority[a.status] - priority[b.status]) const passed = checks.filter(check => check.status === 'pass') const focusIssues = () => { issuesRef.current?.scrollIntoView({ block: 'start' }); issuesRef.current?.focus({ preventScroll: true }) } const showPassed = () => { if (passedRef.current) { passedRef.current.open = true; passedRef.current.scrollIntoView({ block: 'start' }); passedRef.current.querySelector('summary')?.focus({ preventScroll: true }) } } return

    System Info

    Compatibility checks, configuration guidance and a report for support.

    {loading ? 'Checking system information…' : checkedAt ? `Last checked ${checkedAt.toLocaleString(undefined, { dateStyle: 'medium', timeStyle: 'short' })} · browser timezone` : ''}

    {copyState === 'success' ? 'System report copied to clipboard.' : copyState === 'copying' ? 'Copying system report.' : ''}
    {copyState === 'error' &&

    The report could not be copied. Your browser may restrict clipboard access. Try Copy report again or use Download report.

    } {downloadError &&

    The download could not be started. Try again or use Copy report.

    } {error && } {!info && loading && } {info && <>
    {counts.fail ? : 0 failed} {counts.warning ? : 0 to review} {counts.unknown ? : 0 unavailable} {counts.pass ? : 0 passed}

    Includes compatibility, memory recommendations, PHP extensions and registration setup. Not a security or background-job health audit.

    Needs attention

    {issues.length ?
      {issues.map(check => )}
    :

    }
      {passed.map(check => )}
    {!passed.length &&

    No checks passed in the current report.

    }

    Environment details

    {environmentGroups(info).map(group => {group.title === 'WordPress environment' &&

    A disabled built-in WP Cron flag may be intentional when your host runs a system scheduler.

    } {group.title === 'Server' &&
    Private server details · excluded from report
    }
    )}
    Advanced registration details !['WordPress form handled by', 'WooCommerce form handled by'].includes(label))} />
    Theme template path · excluded from report
    }
    }