import{n as e}from"./rolldown-runtime-DkW27tQK.js";import{G as t,J as n,K as r,W as i}from"./lit-runtime-BEtFSUCp.js";import{M as a,N as o,T as s,w as c}from"./control-ui-core-DGVkFhVB.js";import{Ht as l,Nt as u,qt as d}from"./control-ui-core-Br5DB0Zj.js";function f(e,t){let n=e?.currentVersion?.trim(),r=n?d(`updates.target.version`,{version:n}):null,i=c(t,e);if(r&&i){let n=t?.target?.kind===`git`||e?.commitsBehind!==void 0;return d(n?`updates.confirm.versionsBehind`:`updates.confirm.versions`,{available:i,installed:r})}return r??i??void 0}function p(e){return d(e?`updates.dialog.installing`:`updates.dialog.restarting`)}async function m(e){if(_)return;_=!0;let i=document.createElement(`div`);document.body.append(i),document.body.classList.add(g);let a=e.viaNativeApp?{confirmLabel:d(`updates.confirm.macAction`),message:d(`updates.confirm.macMessage`),title:d(`chat.sidebar.updateMacAndGateway`)}:{confirmLabel:d(`updates.confirm.action`),message:d(`updates.confirm.message`),title:d(`chat.sidebar.updateGateway`)},s=f(e.updateAvailable,e.updateSchedule);await new Promise(c=>{let l={kind:`confirm`},u=!1,f,m,v=!1,y=()=>{u||(u=!0,f?.(),m!==void 0&&globalThis.clearTimeout(m),r(t,i),i.remove(),document.body.classList.remove(g),_=!1,c())},b=()=>{if(u)return;let e=l,o=e.kind===`working`,c=e.kind===`failed`,f=e.kind===`failed`?e.message:e.kind===`working`?p(e.connected):`${a.message} ${d(`updates.confirm.impact`)}`;r(n`
          <openclaw-modal-dialog label=${a.title} description=${f} @modal-cancel=${y}>
            <div class="exec-approval-card">
              <div class="exec-approval-header">
                <div>
                  <div class="exec-approval-title">${a.title}</div>
                  <div class="exec-approval-sub" style="white-space: pre-line">${f}</div>
                </div>
              </div>
              ${s&&!c?n`<div class="exec-approval-command mono">${s}</div>`:t}
              <div class="exec-approval-actions">
                ${c?n`<button type="button" class="btn" autofocus @click=${y}>
                      ${d(`common.close`)}
                    </button>`:n`
                      <button
                        type="button"
                        class="btn danger ${o?`btn--busy`:``}"
                        ?disabled=${o}
                        @click=${x}
                      >
                        ${o?n`<span class="btn__spinner" aria-hidden="true"></span>${d(`chat.updating`)}`:a.confirmLabel}
                      </button>
                      <button type="button" class="btn" autofocus @click=${y}>
                        ${d(o?`common.close`:`common.cancel`)}
                      </button>
                    `}
              </div>
            </div>
          </openclaw-modal-dialog>
        `,i)};function x(){if(l.kind!==`confirm`)return;if(e.viaNativeApp&&o()){y();return}let t=e.watchUpdateProgress;if(!t){e.startGatewayUpdate(),y();return}l={kind:`working`,connected:!0},b(),e.startGatewayUpdate();let n=!0;f=t(e=>{let t=n;if(n=!1,!(u||l.kind===`confirm`)){if(e.failure&&!t){l={kind:`failed`,message:e.failure},b();return}if(e.busy)v=!0;else if(v){y();return}l={kind:`working`,connected:e.connected},b()}}),m=globalThis.setTimeout(()=>{u||v||l.kind!==`working`||(l={kind:`failed`,message:d(`updates.dialog.notStarted`)},b())},h)}b()})}var h,g,_;function v(){return(v=e((()=>{i(),l(),u(),a(),s(),h=4e3,g=`update-dialog-open`,_=!1})))()}v();export{m as confirmAndStartUpdateRuntime};
//# sourceMappingURL=update-confirmation.runtime-C9N1iuPs.js.map