{"version":3,"file":"index-CJw5YZXp.mjs","sources":["../../node_modules/@radix-ui/react-use-controllable-state/dist/index.mjs"],"sourcesContent":["// src/use-controllable-state.tsx\nimport * as React from \"react\";\nimport { useLayoutEffect } from \"@radix-ui/react-use-layout-effect\";\nvar useInsertionEffect = React[\" useInsertionEffect \".trim().toString()] || useLayoutEffect;\nfunction useControllableState({\n  prop,\n  defaultProp,\n  onChange = () => {\n  },\n  caller\n}) {\n  const [uncontrolledProp, setUncontrolledProp, onChangeRef] = useUncontrolledState({\n    defaultProp,\n    onChange\n  });\n  const isControlled = prop !== void 0;\n  const value = isControlled ? prop : uncontrolledProp;\n  if (true) {\n    const isControlledRef = React.useRef(prop !== void 0);\n    React.useEffect(() => {\n      const wasControlled = isControlledRef.current;\n      if (wasControlled !== isControlled) {\n        const from = wasControlled ? \"controlled\" : \"uncontrolled\";\n        const to = isControlled ? \"controlled\" : \"uncontrolled\";\n        console.warn(\n          `${caller} is changing from ${from} to ${to}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`\n        );\n      }\n      isControlledRef.current = isControlled;\n    }, [isControlled, caller]);\n  }\n  const setValue = React.useCallback(\n    (nextValue) => {\n      if (isControlled) {\n        const value2 = isFunction(nextValue) ? nextValue(prop) : nextValue;\n        if (value2 !== prop) {\n          onChangeRef.current?.(value2);\n        }\n      } else {\n        setUncontrolledProp(nextValue);\n      }\n    },\n    [isControlled, prop, setUncontrolledProp, onChangeRef]\n  );\n  return [value, setValue];\n}\nfunction useUncontrolledState({\n  defaultProp,\n  onChange\n}) {\n  const [value, setValue] = React.useState(defaultProp);\n  const prevValueRef = React.useRef(value);\n  const onChangeRef = React.useRef(onChange);\n  useInsertionEffect(() => {\n    onChangeRef.current = onChange;\n  }, [onChange]);\n  React.useEffect(() => {\n    if (prevValueRef.current !== value) {\n      onChangeRef.current?.(value);\n      prevValueRef.current = value;\n    }\n  }, [value, prevValueRef]);\n  return [value, setValue, onChangeRef];\n}\nfunction isFunction(value) {\n  return typeof value === \"function\";\n}\n\n// src/use-controllable-state-reducer.tsx\nimport * as React2 from \"react\";\nimport { useEffectEvent } from \"@radix-ui/react-use-effect-event\";\nvar SYNC_STATE = Symbol(\"RADIX:SYNC_STATE\");\nfunction useControllableStateReducer(reducer, userArgs, initialArg, init) {\n  const { prop: controlledState, defaultProp, onChange: onChangeProp, caller } = userArgs;\n  const isControlled = controlledState !== void 0;\n  const onChange = useEffectEvent(onChangeProp);\n  if (true) {\n    const isControlledRef = React2.useRef(controlledState !== void 0);\n    React2.useEffect(() => {\n      const wasControlled = isControlledRef.current;\n      if (wasControlled !== isControlled) {\n        const from = wasControlled ? \"controlled\" : \"uncontrolled\";\n        const to = isControlled ? \"controlled\" : \"uncontrolled\";\n        console.warn(\n          `${caller} is changing from ${from} to ${to}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`\n        );\n      }\n      isControlledRef.current = isControlled;\n    }, [isControlled, caller]);\n  }\n  const args = [{ ...initialArg, state: defaultProp }];\n  if (init) {\n    args.push(init);\n  }\n  const [internalState, dispatch] = React2.useReducer(\n    (state2, action) => {\n      if (action.type === SYNC_STATE) {\n        return { ...state2, state: action.state };\n      }\n      const next = reducer(state2, action);\n      if (isControlled && !Object.is(next.state, state2.state)) {\n        onChange(next.state);\n      }\n      return next;\n    },\n    ...args\n  );\n  const uncontrolledState = internalState.state;\n  const prevValueRef = React2.useRef(uncontrolledState);\n  React2.useEffect(() => {\n    if (prevValueRef.current !== uncontrolledState) {\n      prevValueRef.current = uncontrolledState;\n      if (!isControlled) {\n        onChange(uncontrolledState);\n      }\n    }\n  }, [onChange, uncontrolledState, prevValueRef, isControlled]);\n  const state = React2.useMemo(() => {\n    const isControlled2 = controlledState !== void 0;\n    if (isControlled2) {\n      return { ...internalState, state: controlledState };\n    }\n    return internalState;\n  }, [internalState, controlledState]);\n  React2.useEffect(() => {\n    if (isControlled && !Object.is(controlledState, internalState.state)) {\n      dispatch({ type: SYNC_STATE, state: controlledState });\n    }\n  }, [controlledState, internalState.state, isControlled]);\n  return [state, dispatch];\n}\nexport {\n  useControllableState,\n  useControllableStateReducer\n};\n//# sourceMappingURL=index.mjs.map\n"],"names":["useInsertionEffect","React","trim","toString","useLayoutEffect","useControllableState","prop","defaultProp","onChange","caller","uncontrolledProp","setUncontrolledProp","onChangeRef","value","setValue","useState","prevValueRef","useRef","current","useEffect","useUncontrolledState","isControlled","isControlledRef","wasControlled","useCallback","nextValue","isFunction"],"mappings":"iEAIA,IAAMA,EACHC,EAAc,uBAAuBC,OAAOC,aAAeC,EAYvD,SAASC,GAAwBC,KACtCA,EAAAC,YACAA,EAAAC,SACAA,EAAW,OAAMC,OACjBA,IAEA,MAAOC,EAAkBC,EAAqBC,GA4ChD,UAAiCL,YAC/BA,EAAAC,SACAA,IAMA,MAAOK,EAAOC,GAAkBb,EAAAc,SAASR,GACnCS,EAAqBf,EAAAgB,OAAOJ,GAE5BD,EAAoBX,EAAAgB,OAAOT,GAYjC,OAXAR,GAAmB,KACjBY,EAAYM,QAAUV,CAAA,GACrB,CAACA,IAEEP,EAAAkB,WAAU,KACVH,EAAaE,UAAYL,IAC3BD,EAAYM,UAAUL,GACtBG,EAAaE,QAAUL,EACzB,GACC,CAACA,EAAOG,IAEJ,CAACH,EAAOC,EAAUF,EAC3B,CApE+DQ,CAAqB,CAChFb,cACAC,aAEIa,OAAwB,IAATf,EACfO,EAAQQ,EAAef,EAAOI,EAMO,CACzC,MAAMY,EAAwBrB,EAAAgB,YAAgB,IAATX,GAC/BL,EAAAkB,WAAU,KACd,MAAMI,EAAgBD,EAAgBJ,QACtC,GAAIK,IAAkBF,EAAc,CAMpC,CACAC,EAAgBJ,QAAUG,CAAA,GACzB,CAACA,EAAcZ,GACpB,CAGA,MAAMK,EAAiBb,EAAAuB,aACpBC,IACC,GAAIJ,EAAc,CAChB,MAAMR,EAwCd,SAAoBA,GAClB,MAAwB,mBAAVA,CAChB,CA1CsBa,CAAWD,GAAaA,EAAUnB,GAAQmB,EACpDZ,IAAUP,GACZM,EAAYM,UAAUL,QAGxBF,EAAoBc,EACtB,GAEF,CAACJ,EAAcf,EAAMK,EAAqBC,IAG5C,MAAO,CAACC,EAAOC,EACjB","x_google_ignoreList":[0]}