{"version":3,"file":"useRadioInput.mjs","names":[],"sources":["../../../../../../../react-form/src/hooks/useRadioInput.tsx"],"sourcesContent":["\"use client\";\n\nimport { createContext, useContext } from \"react\";\r\n\r\ntype Value = string | number | boolean;\r\n\r\nexport type RadioGroupContextOptions = {\r\n  value: Value;\r\n  changeValue: (value: Value) => void;\r\n};\r\n\r\nexport const RadioGroupContext = createContext<RadioGroupContextOptions>({\r\n  value: \"\",\r\n  changeValue: () => {},\r\n});\r\n\r\nexport type RadioInputHookOutput = {\r\n  isSelected: boolean;\r\n  changeValue: () => void;\r\n};\r\n\r\nexport function useRadioInput(value: Value): RadioInputHookOutput {\r\n  const context = useContext(RadioGroupContext);\r\n\r\n  if (!context) {\r\n    throw new Error(\"useRadioInput must be used within a RadioGroupContext\");\r\n  }\r\n\r\n  const { value: groupValue, changeValue } = context;\r\n\r\n  return {\r\n    isSelected: groupValue === value,\r\n    changeValue: () => changeValue(value),\r\n  };\r\n}\r\n"],"mappings":";;;;;AAWA,MAAa,oBAAoB,cAAwC;CACvE,OAAO;CACP,mBAAmB,CAAC;AACtB,CAAC;AAOD,SAAgB,cAAc,OAAoC;CAChE,MAAM,UAAU,WAAW,iBAAiB;CAE5C,IAAI,CAAC,SACH,MAAM,IAAI,MAAM,uDAAuD;CAGzE,MAAM,EAAE,OAAO,YAAY,gBAAgB;CAE3C,OAAO;EACL,YAAY,eAAe;EAC3B,mBAAmB,YAAY,KAAK;CACtC;AACF"}