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