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