import{__rest as t}from"../../_virtual/_tslib.js";import{jsx as s,Fragment as o,jsxs as e}from"react/jsx-runtime";import{useMemo as a,useCallback as i,useRef as n,useEffect as r}from"react";import l from"classnames";import{CSSTransition as c}from"react-transition-group";import m from"../Button/Button.js";import d from"../Avatar/Avatar.js";import u from"../Icon/Icon.js";import p from"./ToastButton/ToastButton.js";import{ToastType as v,ToastPosition as f,ToastActionType as y,ToastIconSize as j}from"./ToastConstants.js";import{getIcon as b}from"./ToastHelpers.js";import{NOOP as O}from"../../utils/function-utils.js";import"./Toast.scss.js";import{ArtWork as g}from"./ToastArtWork/ToastArtWork.js";import h from"../Loader/Loader.js";var T=function(T){var N=T.open,I=void 0!==N&&N,L=T.autoHideDuration,A=void 0===L?null:L,k=T.type,S=void 0===k?v.POSITIVE:k,z=T.position,B=void 0===z?f.BOTTOM_RIGHT:z,R=T.icon,M=T.hideIcon,_=void 0!==M&&M,C=T.action,G=T.actions,E=T.children,x=T.iconSize,H=void 0===x?"LARGE":x,W=T.closeable,w=void 0===W||W,P=T.artWork,V=T.onClose,Y=void 0===V?O:V,D=T.className,F=T.label,U=T.paragraph,X=T.avatarSrc,q=T.closeIcon,J=T.iconClassName,K=T.loader,Q=void 0!==K&&K,Z=a((function(){return G?G.filter((function(t){return t.type===y.BUTTON})).map((function(o,e){var a=o.content,i=t(o,["type","content"]);return s(p,Object.assign({},i,{children:a}),"alert-button-".concat(e))})):null}),[G]),$=a((function(){return l("l3-style-toast","l3-style-toast--position-".concat(B),"l3-style-toast--type-".concat(S),D)}),[S,D,B]),tt=i((function(){Y&&Y()}),[Y]),st=n(),ot=i((function(t){Y&&null!=t&&(clearTimeout(st.current),st.current=setTimeout((function(){tt()}),t))}),[tt,Y]);r((function(){return I&&A>0&&ot(A),function(){clearTimeout(st.current)}}),[I,A,ot]);var et=!_&&b(S,R,j[H]);return s(c,Object.assign({in:I,classNames:"l3-style-toast-animation",timeout:400,unmountOnExit:!0},{children:s("div",Object.assign({className:"l3-style-toast--position"},{children:s(o,{children:e("div",Object.assign({className:$,role:"alert","aria-live":"polite"},{children:[X&&s("div",Object.assign({className:"l3-style-toast-avatar"},{children:s(d,{type:d.types.IMG,size:d.sizes.SMALL,src:X,rectangle:!0,withoutBorder:!0})})),(!P||!X||Q)&&H&&s("div",Object.assign({className:"l3-style-toast-icon-large"},{children:et})),Q&&s("div",Object.assign({className:"l3-loader-toast-loader"},{children:s(h,{size:h.sizes.XS})})),P&&s("div",Object.assign({className:"l3-style-toast-artwork"},{children:s(g,{type:g.types.IMG,src:P,ariaLabel:"label"})})),s("div",Object.assign({className:l("l3-style-toast-content",{"l3-style-toast-content-no-icon":!et})},{children:e(o,{children:[F&&s("div",Object.assign({className:"l3-style-toast-label"},{children:F||E})),U&&s("div",Object.assign({className:"l3-style-toast-paragraph"},{children:U}))]})})),(Z||C)&&s("div",Object.assign({className:"l3-style-toast-action"},{children:Z||C})),w&&s(m,Object.assign({className:"l3-style-toast_close-button",onClick:tt,size:m.sizes.SMALL,kind:m.kinds.TERTIARY,color:m.colors.ON_PRIMARY_COLOR,ariaLabel:"close-toast"},{children:s(u,{iconType:u.type.SVG,clickable:!1,className:J,ignoreFocusStyle:!0,icon:q})}))]}))})}))}))};Object.assign(T,{types:v,actionTypes:y});var N=T;export{N as default};
