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