(function(){try{var g=typeof window!=="undefined"?window:typeof global!=="undefined"?global:typeof self!=="undefined"?self:{};g["__faroBundleId_hub-ui"]="1776264056705-b139a53649"}catch(l){}})();import{r as e,j as w}from"./c2heove9.js";import{T as S}from"./htibg8hi.js";import{e as I,c as M,f as D}from"./m6px07lc.js";import{$ as F}from"./g811ww8h.js";import{E as N,X as P,Y as O,Z as j,i as _}from"./la47cm74.js";function G(b,s){const a=new CustomEvent("show-toast",{detail:{severity:b,message:s}});window.dispatchEvent(a)}const A=250,k=7e3,$=500;function K(){const s=I(F("root"))?.toast,a=e.useRef(null),n=N(),[i,L]=e.useState(null),[g,c]=e.useState(!1),[C,R]=e.useState(100),r=e.useRef(null),m=e.useRef(null),p=e.useRef(0),d=e.useRef(null);e.useEffect(()=>()=>{d.current&&(clearTimeout(d.current),d.current=null),r.current&&(cancelAnimationFrame(r.current),r.current=null),a.current=null},[]);const f=e.useCallback(()=>{r.current&&(cancelAnimationFrame(r.current),r.current=null)},[]),v=e.useCallback(()=>{R(100),p.current=0,m.current=null,d.current=null,f()},[f]),T=e.useCallback(()=>{const t=Date.now(),o=m.current?t-m.current:0;m.current=t,p.current+=o;const E=Math.max(0,Math.round(100-p.current/k*100));R(E),p.current{r.current||(m.current=Date.now(),r.current=requestAnimationFrame(T))},[T]),h=e.useCallback(t=>{v(),g&&i?(c(!1),d.current=setTimeout(()=>{L(t),c(!0),u()},A)):(L(t),c(!0),u())},[g,v,i,u]),l=M(),y=D();e.useEffect(()=>{l.state==="idle"&&s?.message&&s?.severity&&a.current!==s.message&&(a.current=s.message,h({severity:s.severity,message:s.message}))},[l.state,s?.message,s?.severity,h]),e.useEffect(()=>{y.pathname!==l.location?.pathname&&l.state==="loading"&&a.current&&(a.current=null)},[y.pathname,l.location?.pathname,l.state]),e.useEffect(()=>{const t=o=>{if(o.type==="show-toast"&&o instanceof CustomEvent){const E=S.parse(o.detail);h(E)}};return window.addEventListener("show-toast",t),()=>{window.removeEventListener("show-toast",t)}},[h]),e.useEffect(()=>{const t=()=>{document.visibilityState==="hidden"?f():u()};return document.addEventListener("visibilitychange",t),()=>{document.removeEventListener("visibilitychange",t)}},[f,u]);const x={success:n.vars.palette.docker.green[600],error:n.vars.palette.docker.red[600],warning:n.vars.palette.docker.amber[600],info:n.vars.palette.docker.blue[600]};return w.jsx(P,{"data-testid":"docker-toast",open:g,onClose:(t,o)=>{o==="escapeKeyDown"&&c(!1)},slots:{transition:O},slotProps:{transition:{direction:"left",timeout:A,onExited:v}},sx:{width:{xs:`calc(100vw - ${n.spacing(6)})`,md:n.spacing(50)}},anchorOrigin:{vertical:"bottom",horizontal:"right"},children:w.jsxs(j,{severity:i?.severity,sx:{width:"100%"},onMouseEnter:f,onMouseLeave:u,onClose:()=>{c(!1)},children:[i?.message,w.jsx(_,{"aria-label":"Percentage of time left until toast closes",value:C,variant:"determinate",color:"inherit",sx:{position:"absolute",bottom:0,left:0,right:0,height:n.spacing(.5),borderBottomLeftRadius:n.spacing(.5),borderBottomRightRadius:n.spacing(.5),"& .MuiLinearProgress-bar1":{backgroundColor:i?x[i.severity]:x.info}}})]})})}export{K as T,G as s};