import{slicedToArray as e}from"../../_virtual/_rollupPluginBabelHelpers.js";import o,{useState as t,useRef as i,useCallback as n,useEffect as l,useLayoutEffect as a}from"react";import"prop-types";import s from"classnames";import r from"../Heading/Heading.js";import u from"../Clickable/Clickable.js";import d from"../EditableInput/EditableInput.js";import c from"../../hooks/usePrevious/index.js";import{InputType as p}from"../EditableInput/EditableInputConstants.js";import"./EditableHeading.scss.js";var m=function(m){var g=m.id,h=m.className,E=m.inputClassName,v=m.dataTestId,f=m.value,C=m.editing,b=m.disabled,y=m.onFinishEditing,T=m.onCancelEditing,x=m.onIgnoreBlurEvent,z=m.errorClassTimeout,I=m.style,L=m.customColor,F=m.onStartEditing,H=m.contentRenderer,M=m.tooltip,O=m.highlightTerm,A=m.insetFocus,j=m.autoFocus,w=t(C&&!b),B=e(w,2),P=B[0],S=B[1],k=t(!1),N=e(k,2),D=N[0],K=N[1],V=t(f||""),R=e(V,2),_=R[0],G=R[1],X=c(f),q=i(null),J=n((function(e){b||P||(S(!0),F&&F(e))}),[P,b,S,F]),Q=n((function(e,o){S(!1),G(e),null==y||y(e,o)}),[y,S,G]),U=n((function(e){S(!1),null==T||T(e)}),[T,S]),W=n((function(e){null==x||x(e)}),[x]),Y=n((function(){K(!1)}),[K]),Z=n((function(){K(!0)}),[K]),$=n((function(){Y()}),[Y]);l((function(){C||f===X||f===_||G(f)}),[C,f,X,_,G]),l((function(){S(C)}),[C]),a((function(){C||_||!f||G(f)}),[C,f,X,_,G]),l((function(){var e;return D&&(e=setTimeout(Y,z)),function(){return e&&clearTimeout(e)}}),[D,K,Y,z]);var ee,oe,te,ie=!b&&P;return o.createElement("div",{ref:q,style:I,className:s("editable-heading--wrapper",h,{"inset-focus":A}),"aria-label":"".concat(f," ").concat(M||""),id:g,"data-testid":v},o.createElement(u,{role:ie?"button":"input",onClick:J,disabled:b},ie?(oe=m.inputType||(m.ellipsisMaxLines>1?p.TEXT_AREA:void 0),te={value:_,className:s("editable-heading-input","element-type-".concat(m.type),"size-".concat(m.size),E),isValidValue:m.isValidValue,onChange:m.onChange,onKeyDown:m.onKeyDown,onClick:m.onClick,customColor:L,onTabHandler:m.onTabHandler,onArrowKeyDown:m.onArrowKeyDown,autoComplete:m.autoComplete,maxLength:m.maxLength,placeholder:m.placeholder,shouldFocusOnMount:m.shouldFocusOnMount,selectOnMount:m.selectOnMount,inputType:oe,ignoreBlurClass:m.ignoreBlurClass,autoSize:m.autoSize,textareaSubmitOnEnter:m.textareaSubmitOnEnter,onFinishEditing:Q,onCancelEditing:U,onIgnoreBlurEvent:W,onError:Z,onSuccess:$,ariaLabel:m.inputAriaLabel,autoFocus:j},o.createElement(d,te)):(ee={value:m.displayPlaceholderInTextMode?_||m.placeholder||"":_,type:m.type,customColor:L,suggestEditOnHover:m.suggestEditOnHover&&!b,tooltipPosition:m.tooltipPosition,ellipsisMaxLines:m.ellipsisMaxLines,nonEllipsisTooltip:m.tooltip,size:m.size,highlightTerm:O},H?H(ee):o.createElement(r,ee))))};m.types=r.types,m.sizes=r.sizes,m.defaultProps={className:"",id:"",placeholder:void 0,type:r.types.h1,errorClass:"error",errorClassTimeout:2e3,displayPlaceholderInTextMode:!0,suggestEditOnHover:!0,autoSize:!0,size:r.sizes.LARGE,inputAriaLabel:void 0,highlightTerm:null,customColor:void 0,ignoreBlurClass:void 0,onFinishEditing:void 0,onCancelEditing:void 0,onIgnoreBlurEvent:void 0,style:void 0,dataTestId:"",inputClassName:"",insetFocus:!1,maxLength:void 0};var g=m;export{g as default};
