UNPKG

@payfit/unity-components

Version:

40 lines (39 loc) • 1.28 kB
import { useState as e } from "react"; //#region src/modules/ai-kit/components/ai-structured-input/hooks/use-ai-structured-input-navigation.ts function t(t) { let { steps: n, initialStepId: r } = t, i = n[0]; if (!i) throw Error("useAIStructuredInputNavigation requires at least one step."); if (r !== void 0 && !n.some((e) => e.id === r)) throw Error(`Initial step ID "${r}" must match a configured step ID.`); let [a, o] = e(() => r ?? i.id), s = n.findIndex((e) => e.id === a); if (s < 0) throw Error(`Active step ID "${a}" is missing. Existing steps cannot be removed while the hook is active.`); let c = n[s]; if (!c) throw Error("Could not resolve the active structured-input step."); let l = (e) => { n.some((t) => t.id === e) && o(e); }, u = (e) => { let t = n.find((t) => t.id === e); t && o(t.id); }, d = () => { let e = n[s + 1]; e && o(e.id); }, f = () => { let e = n[s - 1]; e && o(e.id); }, p = (e) => { e !== a || !c.autoAdvanceOnAnswer || d(); }, m = s === 0, h = s === n.length - 1; return { activeStepId: a, onActiveStepChange: u, goToStep: l, advance: d, goBack: f, onAnswer: p, isFirstStep: m, isLastStep: h, canAdvance: !h, canGoBack: !m }; } //#endregion export { t as useAIStructuredInputNavigation };