(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const s of document.querySelectorAll('link[rel="modulepreload"]'))o(s);new MutationObserver(s=>{for(const n of s)if(n.type==="childList")for(const a of n.addedNodes)a.tagName==="LINK"&&a.rel==="modulepreload"&&o(a)}).observe(document,{childList:!0,subtree:!0});function i(s){const n={};return s.integrity&&(n.integrity=s.integrity),s.referrerPolicy&&(n.referrerPolicy=s.referrerPolicy),s.crossOrigin==="use-credentials"?n.credentials="include":s.crossOrigin==="anonymous"?n.credentials="omit":n.credentials="same-origin",n}function o(s){if(s.ep)return;s.ep=!0;const n=i(s);fetch(s.href,n)}})();const r={corner:"bottom-right",toastWidth:320,spacing:16,marginX:16,marginY:96},d=new Map,l=[];let m=null;async function w(){try{const e=await window.edenAPI.shellCommand("view/window-size",{});return m=e,e}catch(e){return console.error("Failed to get window size:",e),{width:1280,height:800}}}function v(){return(m||{height:800}).height-r.marginY*2}function y(){let e=0,t=0;for(const i of d.values())e+=i.element.offsetHeight||100,t++;return t>1&&(e+=(t-1)*r.spacing),e}function h(e=120){const t=y(),i=v();return t+(d.size>0?r.spacing:0)+e<=i}function b(){const e=document.getElementById("toast-container");if(d.size===0||!e)return{x:0,y:0,width:0,height:0};const t=m||{width:1280,height:800},i=e.scrollHeight,o=r.toastWidth,s=i;let n,a;switch(r.corner){case"top-left":n=r.marginX,a=r.marginY;break;case"top-right":n=t.width-o-r.marginX,a=r.marginY;break;case"bottom-left":n=r.marginX,a=t.height-s-r.marginY;break;case"bottom-right":default:n=t.width-o-r.marginX,a=t.height-s-r.marginY;break}return{x:n,y:a,width:o,height:s}}async function u(){const e=b();try{await window.edenAPI.shellCommand("view/update-view-bounds",{appId:"com.eden.toaster",bounds:e})}catch(t){console.error("Failed to update overlay bounds:",t)}}function f(e){const t=document.createElement("div");return t.textContent=e,t.innerHTML}function T(){if(l.length===0||!h())return;const e=l.shift();p(e)}function c(e){const t=d.get(e);t&&(t.timeoutId!==null&&clearTimeout(t.timeoutId),t.element.remove(),d.delete(e),g(),u(),T())}function P(){l.length=0;for(const e of d.values())e.timeoutId!==null&&clearTimeout(e.timeoutId),e.element.remove();d.clear(),g(),u()}function g(){const e=document.getElementById("toast-container");if(!e)return;let t=document.getElementById("dismiss-all-btn");const i=d.size+l.length;i>1?(t||(t=document.createElement("button"),t.id="dismiss-all-btn",t.className="dismiss-all-btn eden-btn eden-btn-ghost",t.textContent="Dismiss All",t.addEventListener("click",P),e.prepend(t)),t.textContent=`Dismiss All (${i})`):t&&t.remove()}function I(e){const t=d.get(e);!t||t.isHoverPaused||(t.isHoverPaused=!0,t.isPaused||E(t))}function H(e){const t=d.get(e);!t||!t.isHoverPaused||(t.isHoverPaused=!1,t.isPaused&&L(t))}function E(e){if(e.isPaused)return;e.timeoutId!==null&&(clearTimeout(e.timeoutId),e.timeoutId=null);const t=Date.now()-e.startTime;e.remainingTime=Math.max(0,e.remainingTime-t),e.isPaused=!0;const i=e.element.querySelector(".eden-progress-bar");i&&(i.style.animationPlayState="paused")}function L(e){if(!e.isPaused)return;e.isPaused=!1,e.startTime=Date.now();const t=e.element.querySelector(".eden-progress-bar");t&&(t.style.animationPlayState="running"),e.remainingTime>0?e.timeoutId=window.setTimeout(()=>{c(e.id)},e.remainingTime):c(e.id)}function z(e){const t=document.createElement("div"),i=e.type||"info",o=!e.timeout||e.timeout<=0;t.className=`toast eden-card-glass toast-${i}${o?" toast-persistent":""}`,t.dataset.id=e.id;const s=o?"":`
    <div class="toast-progress-container">
      <div class="eden-progress">
        <div class="eden-progress-bar" style="animation-duration: ${e.timeout}ms;"></div>
      </div>
    </div>
  `;t.innerHTML=`
    <div class="toast-inner">
      <div class="toast-content">
        <div class="toast-title">${f(e.title)}</div>
        <div class="toast-message">${f(e.message)}</div>
      </div>
      <button class="toast-dismiss" aria-label="Dismiss">×</button>
    </div>
    ${s}
  `;const n=t.querySelector(".toast-dismiss");return n==null||n.addEventListener("click",a=>{a.stopPropagation(),c(e.id)}),o||(t.addEventListener("mouseenter",()=>{I(e.id)}),t.addEventListener("mouseleave",()=>{H(e.id)})),t}function p(e){const t=document.getElementById("toast-container");if(!t)return;const i=z(e);t.appendChild(i);const o=!e.timeout||e.timeout<=0;let s=null;o||(s=window.setTimeout(()=>{c(e.id)},e.timeout));const n={...e,element:i,timeoutId:s,remainingTime:e.timeout??0,isPaused:!1,isHoverPaused:!1,startTime:Date.now()};d.set(e.id,n),g(),u()}function A(e){const{notification:t}=e;h()?p(t):(l.push(t),g(),console.log(`Toast queued: ${t.id} (${l.length} pending)`))}async function x(){console.log("Eden Toaster initializing..."),await w(),window.edenAPI.subscribe("notification/added",A),window.edenAPI.subscribe("view/global-bounds-changed",e=>{m=e.windowSize,u()}),await u(),console.log("Eden Toaster ready!")}x();
