/** @jsxRuntime automatic */ /** @jsxImportSource @alchemy.run/sigil */ import { useMemo, useState } from "@alchemy.run/sigil/react"; import type { JSX } from "react"; import { Screen, type ScreenController } from "../../../Interaction.ts"; import type { Plan } from "../../../Plan.ts"; import { PromptFrame, ChoiceGroup, useKeyGlyphs, useTerminalInput } from "../ui/index.ts"; import type { PlanTreeData } from "./PlanTree.ts"; import { Plan as PlanComponent, PlanTree } from "./PlanView.tsx"; export interface PlanDecisionChoice { readonly value: Value; readonly label: string; } function PlanDecision(props: { readonly plan: Plan | PlanTreeData; readonly label?: string; readonly message: string; readonly choices: ReadonlyArray>; readonly initialValue: Value; readonly controller: ScreenController; }): JSX.Element { const { plan, label = "Plan", message, choices, initialValue, controller } = props; const tree = useMemo(() => new PlanTree(plan, { mode: "review", label }), [plan, label]); const [selected, setSelected] = useState(initialValue); const keys = useKeyGlyphs(); useTerminalInput((_input, key) => { if (key.enter) controller.submit(selected); else if (key.escape) controller.cancel(); }); return ( } /> ); } export const planDecisionScreen = (options: { readonly plan: Plan | PlanTreeData; readonly label?: string; readonly message: string; readonly choices: ReadonlyArray>; readonly initialValue: Value; }) => Screen.make("plan decision", (controller) => ( ));