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