import{defineProperty as t}from"../../../_virtual/_rollupPluginBabelHelpers.js";import{__rest as e}from"../../../_virtual/_tslib.js";import{camelCase as o}from"es-toolkit";import{getTestId as i,ComponentDefaultTestId as n}from"../../tests/testIds.js";import r from"classnames";import s,{useRef as a,useMemo as l,useCallback as c,useEffect as m}from"react";import{CSSTransition as u}from"react-transition-group";import p from"../Text/Text.js";import{Loader as d}from"@vibe/loader/mockedClassNames";import{Flex as f}from"@vibe/layout/mockedClassNames";import{CloseSmall as v}from"@vibe/icons";import T from"./ToastLink/ToastLink.js";import y from"./ToastButton/ToastButton.js";import{ToastType as h,ToastActionType as j}from"./ToastConstants.js";import{getIcon as g}from"./ToastHelpers.js";import{NOOP as N}from"../../utils/function-utils.js";import{getStyle as E}from"../../helpers/typesciptCssModulesHelper.js";import{withStaticPropsWithoutForwardRef as b}from"../../types/withStaticProps.js";import"../../utils/colors-vars-map.js";import k from"./Toast.module.scss.js";import x from"../IconButton/IconButton.js";import C from"../../hooks/usePrevious/index.js";var B=b((function(h){var j=h.open,b=void 0!==j&&j,B=h.loading,O=void 0!==B&&B,A=h.autoHideDuration,w=void 0===A?null:A,L=h.type,_=void 0===L?"normal":L,S=h.icon,H=h.hideIcon,I=void 0!==H&&H,P=h.action,z=h.actions,D=h.children,M=h.closeable,R=void 0===M||M,U=h.onClose,q=void 0===U?N:U,F=h.className,G=h.id,J=h.closeButtonAriaLabel,K=void 0===J?"Close":J,Q=h["data-testid"],V=a(null),W=a(null),X=C(null==z?void 0:z.length),Y=l((function(){return z?z.filter((function(t){return"link"===t.type})).map((function(t){var o=e(t,["type"]);return s.createElement(T,Object.assign({key:o.href,className:k.actionLink},o))})):null}),[z]),Z=l((function(){return void 0!==X&&(null==z?void 0:z.length)!==X}),[z,X]),$=l((function(){return z?z.filter((function(t){return"button"===t.type})).map((function(o,i){var n=o.content,a=e(o,["type","content"]);return s.createElement(y,Object.assign({key:"alert-button-".concat(i),className:r(k.actionButton,t({},k.withTransition,Z))},a),n)})):null}),[z,Z]),tt=l((function(){return r(k.toast,E(k,o("type-"+_)),F)}),[_,F]),et=c((function(){q&&q()}),[q]),ot=a(),it=c((function(t){q&&null!=t&&(clearTimeout(ot.current),ot.current=setTimeout((function(){et()}),t))}),[et,q]);m((function(){return b&&w>0&&it(w),function(){clearTimeout(ot.current)}}),[b,w,it]);var nt=!I&&g(_,S),rt=c((function(t){var e=t.style.width;t.style.width="auto";var o=getComputedStyle(t).width;t.style.width=e,t.style.width=o}),[]);return m((function(){V.current&&rt(V.current)}),[D,rt]),s.createElement(u,{in:b,nodeRef:W,classNames:{enterActive:k.enterActive,exitActive:k.exitActive},timeout:400,unmountOnExit:!0},s.createElement(p,{ref:W,id:G,"data-testid":Q||i(n.TOAST,G),type:"text2",element:"div",color:"fixedLight",className:tt,role:"alert","aria-live":"polite"},nt&&s.createElement("div",{className:r(k.icon)},nt),s.createElement(f,{align:"center",gap:"large",className:k.content},s.createElement(f,{gap:"medium","data-testid":i(n.TOAST_CONTENT),className:k.textContent},s.createElement("span",null,D),Y),($||P)&&($||P),O&&s.createElement(d,{size:"xs"})),R&&s.createElement(x,{className:r(k.closeButton),onClick:et,size:"small",kind:"tertiary",color:"fixed-light",ariaLabel:K,"data-testid":i(n.TOAST_CLOSE_BUTTON),icon:v,hideTooltip:!0})))}),{types:h,actionTypes:j});export{B as default};
//# sourceMappingURL=Toast.js.map
