import React, { useState } from 'react'; import { __, _n, sprintf } from '@wordpress/i18n'; import { Button, Badge } from './ui'; /** * The check list, grouped and collapsible. * * A flat list of twenty-six rows is a list nobody reads to the end. Grouping * them by subject — title, then body, then links, then the technical leftovers * — with a count of what is still open in each header means the writer can * open the one group that concerns them and ignore the rest. Groups that are * entirely passing start collapsed, because "all good" needs one line, not * seven. */ const MARK = { pass: { glyph: '✓', tone: 'var(--ars-good)', bg: 'var(--ars-good-tonal)' }, warn: { glyph: '!', tone: 'var(--ars-warning)', bg: 'var(--ars-warning-tonal)' }, fail: { glyph: '✕', tone: 'var(--ars-serious)', bg: 'var(--ars-serious-tonal)' }, }; function Row({ check, onFix, fixing }) { const [open, setOpen] = useState(false); const mark = MARK[check.status] || MARK.warn; const hasDetail = check.status !== 'pass' && !!check.fix; return (
  • {mark.glyph} {check.label} {check.ai && check.status !== 'pass' && onFix && ( )} {hasDetail && ( )}
    {open && hasDetail && (

    {check.fix}

    )}
  • ); } export default function CheckList({ checks = [], sections = {}, onFix, fixing = null }) { const order = Object.keys(sections).length ? Object.entries(sections) : [['basics', __('Checks', 'ai-rank-suite')]]; // A check whose section the server does not know about would otherwise // vanish silently, which is the worst way for a check to fail. const known = new Set(order.map(([id]) => id)); const orphans = checks.filter((c) => !known.has(c.section)); const [collapsed, setCollapsed] = useState({}); const render = (id, label, rows) => { if (!rows.length) return null; const open = rows.filter((c) => c.status !== 'pass'); const allGood = open.length === 0; // Passing groups start closed; a group with work in it starts open. const isOpen = collapsed[id] === undefined ? !allGood : !collapsed[id]; return (
    {isOpen && ( )}
    ); }; return (
    {order.map(([id, label]) => render(id, label, checks.filter((c) => c.section === id)))} {render('other', __('Other', 'ai-rank-suite'), orphans)}
    ); }