{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "use-fillout-flow",
  "title": "Use Fillout Flow",
  "description": "State hook for step navigation, answers, and submission payload creation.",
  "registryDependencies": [
    "@blocks/fillout-flow-schema",
    "@blocks/fillout-flow-submission"
  ],
  "files": [
    {
      "path": "registry/berlin/blocks/fillout-flow/use-fillout-flow.ts",
      "content": "// Generated from packages/ui/src/components/fillout-flow/use-fillout-flow.ts\n\"use client\";\n\nimport * as React from \"react\";\n\nimport { buildFilloutSubmissionPayload } from \"@/registry/berlin/blocks/fillout-flow-submission\";\nimport { isFilloutStepComplete } from \"@/registry/berlin/blocks/fillout-flow-schema\";\nimport type {\n  FilloutAnswerValue,\n  FilloutFlowDefinition,\n  FilloutFlowValues,\n  FilloutUrlParameterInput,\n} from \"@/registry/berlin/blocks/fillout-flow-types\";\n\nexport interface UseFilloutFlowOptions {\n  flow: FilloutFlowDefinition;\n  initialValues?: FilloutFlowValues;\n  urlParameters?: FilloutUrlParameterInput;\n}\n\nexport function useFilloutFlow(options: UseFilloutFlowOptions) {\n  const { flow, initialValues = {}, urlParameters } = options;\n  const [currentStepIndex, setCurrentStepIndex] = React.useState(0);\n  const [values, setValues] = React.useState<FilloutFlowValues>(initialValues);\n\n  const currentStep = flow.steps[currentStepIndex] ?? null;\n  const isFirstStep = currentStepIndex === 0;\n  const isLastStep = currentStepIndex === flow.steps.length - 1;\n  const canContinue = currentStep\n    ? isFilloutStepComplete(currentStep, values)\n    : false;\n\n  function setValue(questionId: string, value: FilloutAnswerValue | undefined) {\n    setValues((current) => {\n      if (value == null) {\n        const { [questionId]: _removed, ...next } = current;\n        return next;\n      }\n\n      return {\n        ...current,\n        [questionId]: value,\n      };\n    });\n  }\n\n  function goBack() {\n    setCurrentStepIndex((index) => Math.max(0, index - 1));\n  }\n\n  function goNext() {\n    setCurrentStepIndex((index) => Math.min(flow.steps.length - 1, index + 1));\n  }\n\n  function goToStep(index: number) {\n    setCurrentStepIndex(Math.max(0, Math.min(flow.steps.length - 1, index)));\n  }\n\n  function reset(nextValues: FilloutFlowValues = initialValues) {\n    setCurrentStepIndex(0);\n    setValues(nextValues);\n  }\n\n  function createSubmissionPayload() {\n    return buildFilloutSubmissionPayload({\n      flow,\n      values,\n      urlParameters,\n    });\n  }\n\n  return {\n    canContinue,\n    createSubmissionPayload,\n    currentStep,\n    currentStepIndex,\n    flow,\n    goBack,\n    goNext,\n    goToStep,\n    isFirstStep,\n    isLastStep,\n    reset,\n    setValue,\n    values,\n  };\n}\n",
      "type": "registry:lib",
      "target": "src/hooks/use-fillout-flow.ts"
    }
  ],
  "type": "registry:lib"
}