import{i as e}from"./rolldown-runtime-B1FJdls4.js";import{m as t}from"./vendor-dnd-C1cICjTT.js";import{s as n}from"./vendor-markdown-Db1-9wH7.js";import{t as r}from"./sessionStore-DocB1wnw.js";var i=e(t(),1),a=n();function o(){let e=r(e=>e.serverUpdateAvailable),t=r(e=>e.serverRestarting),n=r(e=>e.wsStatus),[o,s]=(0,i.useState)(!1),[c,l]=(0,i.useState)(null),[u,d]=(0,i.useState)(``),f=(0,i.useRef)(!1);(0,i.useEffect)(()=>{(t||o)&&(f.current=!0)},[t,o]),(0,i.useEffect)(()=>{n===`connected`&&f.current&&(f.current=!1,s(!1),l(null),r.getState().setServerUpdateAvailable(!1),r.getState().setServerRestarting(!1))},[n]);let p=o||t||n===`disconnected`&&f.current;(0,i.useEffect)(()=>{if(!p)return;let e=setInterval(()=>{d(e=>e.length>=3?``:e+`.`)},400);return()=>clearInterval(e)},[p]);let m=(0,i.useCallback)(async()=>{s(!0),l(null);try{let e=await fetch(`/api/server/restart`,{method:`POST`});if(!e.ok){let t=await e.json().catch(()=>({error:`Unknown error`}));throw Error(t.error||`HTTP ${e.status}`)}}catch(e){l(e.message),s(!1)}},[]),h=(0,i.useCallback)(()=>{f.current=!1,r.getState().setServerUpdateAvailable(!1),r.getState().setServerRestarting(!1),s(!1)},[]);return!e&&!p?null:(0,a.jsx)(`div`,{className:[`flex items-center justify-center gap-3 px-4 py-2 text-xs font-mono shrink-0 transition-[color,background-color,border-color,box-shadow,opacity,transform] duration-300`,p?`bg-blue-900/30 border-b border-blue-500/30 text-blue-300`:`bg-amber-900/20 border-b border-amber-500/30 text-amber-300`].join(` `),children:p?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(`span`,{className:`animate-spin text-sm`,children:`⟳`}),(0,a.jsxs)(`span`,{children:[`Server restarting`,u]}),(0,a.jsx)(`span`,{className:`text-blue-400/60 text-[10px]`,children:`auto-reconnecting • terminals preserved`})]}):c?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(`span`,{className:`text-red-400`,children:`✗`}),(0,a.jsxs)(`span`,{className:`text-red-300`,children:[`Restart failed: `,c]}),(0,a.jsx)(`button`,{type:`button`,onClick:m,className:`px-2 py-0.5 rounded border border-red-500/40 bg-red-900/30 text-red-300 hover:bg-red-900/50 transition-colors`,children:`Retry`}),(0,a.jsx)(`button`,{type:`button`,onClick:h,className:`text-terminal-muted hover:text-terminal-text transition-colors ml-1`,title:`Dismiss`,children:`✕`})]}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(`span`,{className:`text-amber-400 text-sm`,children:`⚡`}),(0,a.jsx)(`span`,{children:`Server update available`}),(0,a.jsx)(`button`,{type:`button`,onClick:m,className:`px-3 py-1 rounded-md border border-amber-500/40 bg-amber-900/30 text-amber-200 hover:bg-amber-500/30 hover:text-white transition-[color,background-color,border-color,box-shadow,opacity,transform] font-semibold`,children:`Restart Now`}),(0,a.jsx)(`button`,{type:`button`,onClick:h,className:`text-terminal-muted hover:text-terminal-text transition-colors ml-1`,title:`Dismiss`,children:`✕`})]})})}export{o as UpdateBanner};