{"version":3,"file":"RadioField.cjs","sources":["../../../../src/components/forms/RadioField.tsx"],"sourcesContent":["import React from \"react\";\n\ninterface RadioOption {\n  id: string | number;\n  title?: string;\n  name?: string;\n}\n\ninterface RadioFieldProps {\n  options?: RadioOption[];\n  name: string;\n  label: string;\n  required?: boolean;\n  defaultValue?: string | number;\n  setSelectedValue?: (value: string) => void;\n  setNameIDValueIndex?: (\n    name: string,\n    id: string,\n    value: string,\n    index: number\n  ) => void;\n  note?: string;\n}\n\n/**\n *\n * @component\n * @example\n * ```tsx\n * import { RadioField } from \"@instincthub/react-ui\";\n *\n * <RadioField\n *   options={[\n *     { id: 1, title: \"Option 1\" },\n *     { id: 2, title: \"Option 2\" },\n *     { id: 3, title: \"Option 3\" },\n *   ]}\n *   names=\"radioField\"\n *   labels=\"Radio Field\"\n *   requireds={true}\n *   defaultValues={1}\n *   setSelectedValue={(value) => {\n *     console.log(value);\n *   }}\n * />\n * ```\n * Props interface for the RadioField component\n * @property {RadioOption[]} options - Array of options for the radio field\n * @property {string} names - Name of the input field\n * @property {string} labels - Label for the radio field\n * @property {boolean} requireds - Whether the field is required\n * @property {string | number} defaultValues - Default value for the radio field\n * @property {(name: string, id: string, value: string, index: number) => void} setNameIDValueIndex - Callback for setting name, id, value, and index\n * @property {(value: string) => void} setSelectedValue - Callback for setting the selected value\n */\n\nconst RadioField: React.FC<RadioFieldProps> = (props) => {\n  const handleOptionChange = (event: React.ChangeEvent<HTMLInputElement>) => {\n    if (props.setSelectedValue) {\n      props.setSelectedValue(event.target.value);\n    }\n    if (props.setNameIDValueIndex) {\n      props.setNameIDValueIndex(\n        props.name,\n        String(event.target.dataset.id),\n        event.target.value,\n        Number(event.target.dataset.index)\n      );\n    }\n  };\n\n  if (!props.options || props.options.length === 0) {\n    return null;\n  }\n\n  return (\n    <div className={props.name}>\n      <h5 className=\"mt-3\">{props.label}</h5>\n\n      <div className=\"ihub-field\">\n        <div className=\"ihub-radio-wrapper\">\n          {props.options.map((option, index) => {\n            return (\n              <div className=\"ihub-radio-parent\" key={index}>\n                <label className=\"ihub-radio\">\n                  <input\n                    type=\"radio\"\n                    name={props.name}\n                    id={props.name + index}\n                    data-id={option.id}\n                    data-index={index}\n                    value={option.id}\n                    required={index === 0 ? props.required : false}\n                    onChange={handleOptionChange}\n                    defaultChecked={props.defaultValue === option.id}\n                  />\n                  <span className=\"ihub-label-title\">\n                    {option.title ? option.title : option.name}\n                  </span>\n                </label>\n              </div>\n            );\n          })}\n        </div>\n      </div>\n      {props.note && <p className=\"ihub-input-notes\">{props.note}</p>}\n    </div>\n  );\n};\n\nexport default RadioField;\n"],"names":["props","handleOptionChange","event","setSelectedValue","target","value","setNameIDValueIndex","name","String","dataset","id","Number","index","options","length","_jsxs","className","children","_jsx","jsx","label","map","option","jsxs","type","required","onChange","defaultChecked","defaultValue","title","note"],"mappings":"uHAwD8C,SAACA,GAC7C,IAAMC,EAAqB,SAACC,GACtBF,EAAMG,kBACRH,EAAMG,iBAAiBD,EAAME,OAAOC,OAElCL,EAAMM,qBACRN,EAAMM,oBACJN,EAAMO,KACNC,OAAON,EAAME,OAAOK,QAAQC,IAC5BR,EAAME,OAAOC,MACbM,OAAOT,EAAME,OAAOK,QAAQG,SAKlC,OAAKZ,EAAMa,SAAoC,IAAzBb,EAAMa,QAAQC,OAKlCC,EAAAA,KAAK,MAAA,CAAAC,UAAWhB,EAAMO,KAAIU,SAAA,CACxBC,EAAIC,IAAA,KAAA,CAAAH,UAAU,OAAMC,SAAEjB,EAAMoB,QAE5BF,EAAAC,IAAA,MAAA,CAAKH,UAAU,aACbC,SAAAC,EAAAC,IAAA,MAAA,CAAKH,UAAU,8BACZhB,EAAMa,QAAQQ,IAAI,SAACC,EAAQV,GAC1B,OACEM,EAAAA,WAAKF,UAAU,oBACbC,SAAAF,EAAAQ,KAAA,QAAA,CAAOP,UAAU,uBACfE,EACEC,IAAA,QAAA,CAAAK,KAAK,QACLjB,KAAMP,EAAMO,KACZG,GAAIV,EAAMO,KAAOK,YACRU,EAAOZ,GAAE,aACNE,EACZP,MAAOiB,EAAOZ,GACde,SAAoB,IAAVb,GAAcZ,EAAMyB,SAC9BC,SAAUzB,EACV0B,eAAgB3B,EAAM4B,eAAiBN,EAAOZ,KAEhDQ,EAAMC,IAAA,OAAA,CAAAH,UAAU,mBAAkBC,SAC/BK,EAAOO,MAAQP,EAAOO,MAAQP,EAAOf,WAdJK,SAsB/CZ,EAAM8B,MAAQZ,EAAAA,IAAA,IAAA,CAAGF,UAAU,4BAAoBhB,EAAM8B,UAjCjD,IAoCX"}