import{slicedToArray as o}from"../../_virtual/_rollupPluginBabelHelpers.js";import{jsx as e}from"react/jsx-runtime";import{forwardRef as n,useState as r,useRef as t,useCallback as i,useLayoutEffect as u,useEffect as a}from"react";import s from"classnames";import l from"autosize";import c from"../../hooks/useStyle.js";import m from"../../hooks/useMergeRefs.js";import{isTabEvent as f,isEnterEvent as d,isEscapeEvent as p,isArrowUpEvent as v,isArrowDownEvent as E,isArrowLeftEvent as g,isArrowRightEvent as T}from"../../utils/dom-event-utils.js";import{InputType as b}from"./EditableInputConstants.js";import"./EditableInput.scss.js";var A=n((function(n,A){var h=n.className,C=n.inputType,y=void 0===C?b.INPUT:C,j=n.autoSize,x=void 0!==j&&j,F=n.id,w=n.tabIndex,I=n.autoComplete,_=void 0===I||I,B=n.maxLength,K=n.placeholder,R=void 0===K?"":K,k=n.onClick,D=n.onKeyPress,L=n.shouldFocusOnMount,P=void 0===L||L,S=n.selectOnMount,X=n.value,z=n.customColor,M=n.ignoreBlurClass,N=n.onFinishEditing,O=n.onIgnoreBlurEvent,H=n.onFocus,V=n.onBlur,q=n.isValidValue,U=n.onChange,G=n.onError,J=n.onSuccess,Q=n.onKeyDown,W=n.onTabHandler,Y=n.onCancelEditing,Z=n.textareaSubmitOnEnter,$=void 0!==Z&&Z,oo=n.onArrowKeyDown,eo=n.ariaLabel,no=n.autoFocus,ro=void 0!==no&&no,to=r(X||""),io=o(to,2),uo=io[0],ao=io[1],so=t(null),lo=m({refs:[A,so]}),co=i((function(){so.current&&x&&y===b.TEXT_AREA&&l(so.current)}),[so,x,y]),mo=i((function(){so.current&&requestAnimationFrame((function(){so.current.focus()}))}),[so]),fo=i((function(o){H&&H(o)}),[H]),po=i((function(o){if(n=M,(e=o.relatedTarget)&&n&&e.classList.contains(n))O(uo);else{var e,n,r=o;r.origin="blur",N&&N(uo,r),V&&V(r)}}),[M,uo,N,V,O]),vo=i((function(o){var e=o.target.value;!q||q(e)?(ao(e),U&&U(e),J&&J()):G&&G()}),[q,U,G,J]),Eo=i((function(){so.current&&so.current.select()}),[so]),go=i((function(){so.current&&(so.current.value="",so.current.value=uo)}),[so,uo]),To=i((function(o){return Q?Q(o,uo):W&&f(o)&&y!==b.TEXT_AREA?(o.preventDefault(),W(uo,o)):(N&&d(o)&&(y!==b.TEXT_AREA||$)&&N(uo,o),Y&&p(o)&&Y(o),void(oo&&(v(o)||E(o)||g(o)||T(o))&&oo(uo,o)))}),[Q,y,uo,W,$,N,Y,oo]);u((function(){P&&mo(),co(),S?Eo():go()}),[]),a((function(){ao(X)}),[X]);var bo=c(void 0,{color:z}),Ao=y===b.TEXT_AREA&&x?1:void 0;return e(y,{ref:lo,id:F,style:bo,className:s("editable-input--wrapper",h,{"no-resize":x}),onChange:vo,onKeyDown:To,onBlur:po,onFocus:fo,onClick:k,onKeyPress:D,value:uo,placeholder:R,dir:"auto",tabIndex:w,autoComplete:_?"on":"off",rows:Ao,maxLength:B,"aria-label":eo,autoFocus:ro})}));export{A as default};
