'use client';
import type { ReactElement } from 'react';
import type { GameView } from '@/game/engine';
import type { TruthFact } from '@/game/truthtrance';
import {
TRUTH_FACT_MAX_DEPTH,
TRUTH_FACT_MAX_NODES,
TRUTH_FACT_MAX_TERMS,
truthFactExpressionError,
truthFactExpressionSize,
} from '@/game/truth-fact-expression';
import { TruthFactFields } from './mixed-shipment-fields';
import { Button } from './ui/button';
const newFact = (): TruthFact => ({ kind: 'hand', name: 'Shield' });
/** Controlled structure editor. Leaf controls retain their existing validators. */
export function TruthFactExpressionFields({ value, game, target, disabled, onChange }: {
value: TruthFact;
game: GameView;
target: string;
disabled: boolean;
onChange: (fact: TruthFact) => void;
}) {
const size = truthFactExpressionSize(value);
const commit = (next: TruthFact) => {
if (!disabled && !truthFactExpressionError(next)) onChange(next);
};
const render = (
node: TruthFact,
path: string,
replace: (next: TruthFact) => TruthFact,
remove?: () => TruthFact,
): ReactElement => {
const group = node.kind === 'and' || node.kind === 'or';
const allowed = (next: TruthFact) => !disabled && !truthFactExpressionError(replace(next));
const change = (next: TruthFact) => commit(replace(next));
const wrap = (kind: 'and' | 'or'): TruthFact => ({ kind, terms: [node, newFact()] });
return
;
};
return ;
}