import {useMemo, useState} from 'react'; import type {NPFamily} from './contract.ts'; import {allocate, buildTree, familyCounts, quotaLeaves, quotaValue, unlock} from './quota.ts'; import type {QuotaNode, QuotaResult, QuotaTargets} from './quota.ts'; import './quota.css'; export function QuotaTree({families, targets, onChange}: {families: NPFamily[]; targets: QuotaTargets; onChange: (targets: QuotaTargets) => void}) { const tree = useMemo(() => buildTree(families), [families]); const [expanded, setExpanded] = useState([]), [error, setError] = useState(''); const leaves = quotaLeaves(tree), total = quotaValue(tree, targets.versions); const supported = leaves.filter(v => v.supported).reduce((n, v) => n + quotaValue(v, targets.versions), 0); function apply(result: QuotaResult) { setError(result.error || ''); if (!result.error) onChange({total: quotaValue(tree, result.versions), versions: result.versions, locked: result.locked}); } function family(node: QuotaNode) { // 母题卡片(配置屏 1-2):绿条=能出题的版本占比 const c = familyCounts(node); return
单机身 {c.single} · 多机身 {c.multi} 个版本
能出题 {c.supported} / {c.total} {!!node.paused?.length &&
暂停 {node.paused.length} 版
    {node.paused.map(p =>
  • {p.id}:{p.reason || '目录里没写原因'}
  • )}
}
; } function row(node: QuotaNode, depth: number) { const versions = quotaLeaves(node), open = expanded.includes(node.id), isLocked = targets.locked.includes(node.id); return
{node.children.length ? : } {depth === 0 && } apply(allocate(tree, targets.versions, targets.locked, node.id, e.target.valueAsNumber))} /> {depth === 0 && } {node.version ? node.supported ? '能出' : '还不能出' : `能出 ${versions.filter(v => v.supported).length} / ${versions.length} 个版本`}
{depth === 0 && !node.version && family(node)} {open && node.children.map(c => row(c, depth + 1))}
; } return
{targets.locked.includes('total') && }能出题的版本共 {supported} 道 · 还出不了的 {total - supported} 道(这些版本生成器或证明器还不支持)
{error &&

{error}

}{tree.children.map(c => row(c, 0))}
; }