import{jsx as i,jsxs as v}from"react/jsx-runtime";import"@styled/tokens";import C from"../icons/ico-dismiss.js";import"../primitives/button.js";import"../primitives/checkbox.js";import"../primitives/dropdown-selector.js";import"../primitives/popover.js";import"../primitives/radio.js";import"../primitives/segmented-control.js";import"../primitives/switch.js";import k from"../primitives/text.js";import S from"../primitives/portal.js";import g from"../utils/animate.js";import{ToastContext as j}from"../../hooks/useToast.js";import{toast as h}from"../../recipes/toast.js";import{HStack as y,VStack as H}from"@styled/jsx";import{useState as P,useRef as R,useReducer as $,useCallback as N,useMemo as q}from"react";import{StatusIcon as w}from"./status-icon.js";let B=0;const T=e=>{const{dismissible:c,lifespan:a,message:l="",variant:t="branded"}=e,o=h({variant:t}),s=e.id,n=e.removeToast,[p,m]=P(!0);return a&&setTimeout(()=>{m(!1)},a),i(g,{"aria-live":["error"].includes(t||"")?"assertive":"polite",show:p,type:"slide",onHidden:()=>{s&&n(s)},children:v(y,{className:o.toast,children:[e.icon&&i(w,{className:o.icon,variant:t}),i(k,{fontColor:"text.quaternary",children:l}),c&&i("button",{className:o.dismiss,onClick:()=>m(!1),"aria-label":"dismiss toast",children:i(C,{className:o.icon})})]})})},I=({icon:e=!1,lifespan:c=0,position:a="top-right",children:l})=>{const t=R([]),o=$(r=>r+1,0)[1],s=N(r=>{t.current=t.current.filter(d=>d.id!==r),o()},[]),n=N(r=>{const{icon:d=r.icon||e,lifespan:x=r.lifespan||c,...b}=r,f=++B;return t.current.push({icon:d,lifespan:x,id:f,...b}),o(),f},[]),p=q(()=>({createToast:n,removeToast:s}),[n,s]),m=(a?.startsWith("top")?[...t.current]:[...t.current].reverse()).map(r=>i(T,{...r,removeToast:s},r.id)),u=h({position:a});return v(j.Provider,{value:p,children:[l,i(S,{children:i("div",{className:u.portal,children:i(H,{className:u.container,children:m})})})]})};export{T as Toast,I as ToastProvider};
//# sourceMappingURL=toast-provider.js.map
