{"version":3,"file":"useTextArea.hook.cjs","sources":["../../../../../src/components/forms/text-area/hooks/useTextArea.hook.tsx"],"sourcesContent":["import { type FocusEventHandler, type MouseEventHandler, useCallback, useId, useRef } from 'react'\r\nimport type { TextAreaProps } from '@components/forms/text-area/types/TextArea.props.ts'\r\nimport type { UseTextAreaReturn } from '@components/forms/text-area/hooks/types'\r\n\r\nexport const useTextArea = (\r\n    props: TextAreaProps & {\r\n        onMouseDown?: MouseEventHandler<HTMLTextAreaElement>\r\n        onFocus?: FocusEventHandler<HTMLTextAreaElement>\r\n        onBlur?: FocusEventHandler<HTMLTextAreaElement>\r\n    }\r\n): UseTextAreaReturn => {\r\n    const {\r\n        label,\r\n        error,\r\n        startIcon,\r\n        endAction,\r\n        onMouseDown,\r\n        onFocus,\r\n        onBlur,\r\n        id\r\n    } = props\r\n\r\n    const generatedId = useId()\r\n    const inputId = id ?? (label ? generatedId : undefined)\r\n    const helperId = `${generatedId}-helper`\r\n    const hasError = Boolean(error)\r\n\r\n    const pointerDownRef = useRef(false)\r\n\r\n    const handleMouseDown = useCallback(\r\n        (e: React.MouseEvent<HTMLTextAreaElement>) => {\r\n            pointerDownRef.current = true\r\n            onMouseDown?.(e)\r\n        },\r\n        [onMouseDown],\r\n    )\r\n\r\n    const handleFocus = useCallback(\r\n        (e: React.FocusEvent<HTMLTextAreaElement>) => {\r\n            if (pointerDownRef.current) {\r\n                e.currentTarget.setAttribute('data-mouse-focus', '')\r\n                pointerDownRef.current = false\r\n            }\r\n            onFocus?.(e)\r\n        },\r\n        [onFocus],\r\n    )\r\n\r\n    const handleBlur = useCallback(\r\n        (e: React.FocusEvent<HTMLTextAreaElement>) => {\r\n            pointerDownRef.current = false\r\n            e.currentTarget.removeAttribute('data-mouse-focus')\r\n            onBlur?.(e)\r\n        },\r\n        [onBlur],\r\n    )\r\n\r\n    const hasStartIcon = Boolean(startIcon)\r\n    const hasEndAction = Boolean(endAction)\r\n\r\n    return {\r\n        inputId,\r\n        helperId,\r\n        hasError,\r\n        handleMouseDown,\r\n        handleFocus,\r\n        handleBlur,\r\n        hasStartIcon,\r\n        hasEndAction,\r\n    }\r\n}\r\n"],"names":["useTextArea","props","label","error","startIcon","endAction","onMouseDown","onFocus","onBlur","id","generatedId","useId","inputId","helperId","hasError","pointerDownRef","useRef","handleMouseDown","useCallback","handleFocus","handleBlur"],"mappings":"yGAIaA,EACTC,GAKoB,CACpB,KAAM,CACF,MAAAC,EACA,MAAAC,EACA,UAAAC,EACA,UAAAC,EACA,YAAAC,EACA,QAAAC,EACA,OAAAC,EACA,GAAAC,CAAA,EACAR,EAEES,EAAcC,EAAAA,MAAA,EACdC,EAAUH,IAAOP,EAAQQ,EAAc,QACvCG,EAAW,GAAGH,CAAW,UACzBI,EAAW,EAAQX,EAEnBY,EAAiBC,EAAAA,OAAO,EAAK,EAE7BC,EAAkBC,EAAAA,YACnB,GAA6C,CAC1CH,EAAe,QAAU,GACzBT,IAAc,CAAC,CACnB,EACA,CAACA,CAAW,CAAA,EAGVa,EAAcD,EAAAA,YACf,GAA6C,CACtCH,EAAe,UACf,EAAE,cAAc,aAAa,mBAAoB,EAAE,EACnDA,EAAe,QAAU,IAE7BR,IAAU,CAAC,CACf,EACA,CAACA,CAAO,CAAA,EAGNa,EAAaF,EAAAA,YACd,GAA6C,CAC1CH,EAAe,QAAU,GACzB,EAAE,cAAc,gBAAgB,kBAAkB,EAClDP,IAAS,CAAC,CACd,EACA,CAACA,CAAM,CAAA,EAMX,MAAO,CACH,QAAAI,EACA,SAAAC,EACA,SAAAC,EACA,gBAAAG,EACA,YAAAE,EACA,WAAAC,EACA,aAViB,EAAQhB,EAWzB,aAViB,EAAQC,CAUzB,CAER"}