'use client';
import type { ReactElement } from 'react';
import type { GameView } from '@/game/engine';
import type { PlanClaim } from '@/game/battle-promises';
import {
BATTLE_CLAIM_MAX_DEPTH,
BATTLE_CLAIM_MAX_NODES,
BATTLE_CLAIM_MAX_TERMS,
battleClaimExpressionError,
battleClaimExpressionSize,
} from '@/game/battle-claim-expression';
import { BattleClaimFields } from './battle-promises';
import { Button } from './ui/button';
const newClaim = (): PlanClaim => ({ kind: 'dial', compare: 'eq', value: 0 });
/** Controlled structure editor. Invalid leaf input stays available for repair. */
export function BattleClaimExpressionFields({ value, game, disabled, onChange }: {
value: PlanClaim;
game: GameView;
disabled: boolean;
onChange: (claim: PlanClaim) => void;
}) {
const size = battleClaimExpressionSize(value);
const commit = (next: PlanClaim) => {
if (!disabled && !battleClaimExpressionError(next)) onChange(next);
};
const render = (
node: PlanClaim,
path: string,
replace: (next: PlanClaim) => PlanClaim,
remove?: () => PlanClaim,
): ReactElement => {
const group = node.kind === 'and' || node.kind === 'or';
const allowed = (next: PlanClaim) => !disabled && !battleClaimExpressionError(replace(next));
const change = (next: PlanClaim) => commit(replace(next));
const wrap = (kind: 'and' | 'or'): PlanClaim => ({ kind, terms: [node, newClaim()] });
return
;
};
return ;
}