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