{"version":3,"sources":["../../../components/form/hook-checkbox.tsx"],"sourcesContent":["\"use client\";\nimport React from 'react';\nimport _get from 'lodash-es/get';\nimport { Controller, FieldValues, RegisterOptions, Path, useFormContext } from 'react-hook-form';\nimport { cn } from '../../utils/ui';\nimport { FormError } from './error';\nimport { FormCheckbox } from './checkbox';\nimport type { FormCheckboxProps } from './checkbox';\n\ntype HookFormCheckboxProps<T extends FieldValues> = Omit<FormCheckboxProps, 'name' | 'checked' | 'onCheckedChange'> & {\n  name: Path<T>;\n  rules?: RegisterOptions<T, Path<T>>;\n  error?: string;\n};\n\nexport function HookFormCheckbox<T extends FieldValues>({\n  id,\n  name,\n  label,\n  rules,\n  error,\n  disabled,\n  classNames,\n  ...rest\n}: HookFormCheckboxProps<T>) {\n  const methods = useFormContext<T>();\n  if (!methods) return null;\n\n  const {\n    control,\n    formState: { errors },\n  } = methods;\n\n  const fieldError = _get(errors, name);\n  const errorMessage = error ?? (fieldError?.message as string);\n  const showError = !!fieldError && !disabled;\n\n  return (\n    <div className={cn('$hook-form-checkbox', classNames?.wrapper)}>\n      <Controller\n        name={name}\n        control={control}\n        rules={rules}\n        render={({ field: { value, onChange } }) => (\n          <FormCheckbox\n            id={id}\n            name={name}\n            label={label}\n            disabled={disabled}\n            checked={value}\n            onCheckedChange={onChange}\n            classNames={{\n              ...classNames,\n              label: cn(classNames?.label, {\n                'text-danger': showError,\n              }),\n              checkbox: cn(classNames?.checkbox, {\n                'ring-danger text-danger': showError,\n              }),\n            }}\n            {...rest}\n          />\n        )}\n      />\n      {showError && <FormError field={name} className=\"mt-1\" message={errorMessage} />}\n    </div>\n  );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AACA,OAAO,WAAW;AAClB,OAAO,UAAU;AACjB,SAAS,YAAgD,sBAAsB;AAYxE,SAAS,iBAAwC,IAS3B;AAT2B,eACtD;AAAA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAtBF,IAewD,IAQnD,iBARmD,IAQnD;AAAA,IAPH;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA;AAGA,QAAM,UAAU,eAAkB;AAClC,MAAI,CAAC,QAAS,QAAO;AAErB,QAAM;AAAA,IACJ;AAAA,IACA,WAAW,EAAE,OAAO;AAAA,EACtB,IAAI;AAEJ,QAAM,aAAa,KAAK,QAAQ,IAAI;AACpC,QAAM,eAAe,wBAAU,yCAAY;AAC3C,QAAM,YAAY,CAAC,CAAC,cAAc,CAAC;AAEnC,SACE,oCAAC,SAAI,WAAW,GAAG,uBAAuB,yCAAY,OAAO,KAC3D;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA;AAAA,MACA;AAAA,MACA,QAAQ,CAAC,EAAE,OAAO,EAAE,OAAO,SAAS,EAAE,MACpC;AAAA,QAAC;AAAA;AAAA,UACC;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA,SAAS;AAAA,UACT,iBAAiB;AAAA,UACjB,YAAY,iCACP,aADO;AAAA,YAEV,OAAO,GAAG,yCAAY,OAAO;AAAA,cAC3B,eAAe;AAAA,YACjB,CAAC;AAAA,YACD,UAAU,GAAG,yCAAY,UAAU;AAAA,cACjC,2BAA2B;AAAA,YAC7B,CAAC;AAAA,UACH;AAAA,WACI;AAAA,MACN;AAAA;AAAA,EAEJ,GACC,aAAa,oCAAC,aAAU,OAAO,MAAM,WAAU,QAAO,SAAS,cAAc,CAChF;AAEJ;","names":[]}