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