import { useCallback, type ChangeEvent } from "react"; import { Input } from "@arronqzy/ui"; import type { ClockNodeConfig } from "@arronqzy/blueprint-dsl"; import { useI18n } from "@arronqzy/i18n/react"; import type { BlueprintGraphNode } from "../graph/document"; import { resolveNodeClockConfig } from "../graph/document"; import { ConfigFieldLabel, ConfigSectionTitle } from "./ConfigHintIcon"; export type ClockNodeConfigPanelProps = { node: BlueprintGraphNode; onUpdateNode: ( nodeId: string, patch: Partial> ) => void; }; function patchClockConfig( node: BlueprintGraphNode, patch: Partial ) { return { clockConfig: { ...resolveNodeClockConfig(node), ...patch }, configSource: "clock" as const, }; } export function ClockNodeConfigPanel({ node, onUpdateNode, }: ClockNodeConfigPanelProps) { const { t } = useI18n(); const clockConfig = resolveNodeClockConfig(node); const handleIntervalChange = useCallback( (e: ChangeEvent) => { const raw = Number(e.target.value); const intervalSeconds = Number.isFinite(raw) && raw > 0 ? Math.floor(raw) : 0; onUpdateNode(node.id, patchClockConfig(node, { intervalSeconds })); }, [node, onUpdateNode] ); const handleOutputCountChange = useCallback( (e: ChangeEvent) => { const raw = Number(e.target.value); const outputCount = Number.isFinite(raw) && raw > 0 ? Math.floor(raw) : 1; onUpdateNode(node.id, patchClockConfig(node, { outputCount })); }, [node, onUpdateNode] ); const handleFormatChange = useCallback( (e: ChangeEvent) => { onUpdateNode( node.id, patchClockConfig(node, { timeFormat: e.target.value }) ); }, [node, onUpdateNode] ); const handleEmitImmediatelyChange = useCallback( (e: ChangeEvent) => { onUpdateNode( node.id, patchClockConfig(node, { emitImmediately: e.target.checked }) ); }, [node, onUpdateNode] ); return (
); }