import{M as x}from"./Modal-B49aPHst.js";import{u as B}from"./TemplateDiffModal-wTVlkLcb.js";import{d as $,ae as M,o as l,c as a,F as m,a as n,n as k,f as c,t as u,b as f,k as N,l as P,r as C,i as v,af as V,h as _,x as E,a7 as F}from"./index-CXwCk-SR.js";import{_ as L}from"./_plugin-vue_export-helper-DlAUqK2U.js";const R={class:"sab__display",title:"Which version this session renders for templates that differ from OAP."},z=["disabled","title"],D={key:0,class:"sab__count"},I={key:0,class:"sab__body"},W={class:"sab__lede"},j={class:"sab__list"},q={key:1,class:"sab__body"},G={class:"sab__lede"},H={key:0,class:"sab__err"},J={key:0,class:"sab__list"},K=["disabled"],Q=$({__name:"SyncAllButton",props:{kind:{}},setup(A){const p=A,y=B({kind:p.kind}),O=M(),b=v(()=>O.mode==="local"?"local":"remote");function h(t){b.value!==t&&V(t)}const r=v(()=>{const t=y.status.value;return t?t.badges.filter(e=>e.kind===p.kind&&(e.status==="diverged"||e.status==="bundled-fallback")).map(e=>e.name).sort():[]}),i=_(!1),d=_(!1),s=_(null),g=v(()=>y.readOnly.value||r.value.length===0),S=v(()=>y.readOnly.value?"OAP unreachable — page is read-only":r.value.length===0?"Everything already matches OAP — nothing to push":`Push ${r.value.length} changed template(s) to OAP`);function w(){g.value||(s.value=null,i.value=!0)}async function T(){if(!d.value){d.value=!0;try{const t=await E.templateSync.syncAll(p.kind);await F(),s.value={synced:t.synced.length,failed:t.failed},t.failed.length===0&&setTimeout(()=>{i.value=!1,s.value=null},1400)}catch(t){s.value={synced:0,failed:[{name:"—",error:t instanceof Error?t.message:String(t)}]}}finally{d.value=!1}}}return(t,e)=>(l(),a(m,null,[n("span",R,[e[4]||(e[4]=n("span",{class:"sab__display-label"},"Showing",-1)),n("button",{class:k(["sab__seg",{on:b.value==="local"}]),type:"button",onClick:e[0]||(e[0]=o=>h("local"))},"Local",2),n("button",{class:k(["sab__seg",{on:b.value==="remote"}]),type:"button",onClick:e[1]||(e[1]=o=>h("remote"))},"Remote",2)]),n("button",{class:"sw-btn",type:"button",disabled:g.value,title:S.value,onClick:w},[e[5]||(e[5]=c(" Sync all to OAP",-1)),r.value.length?(l(),a("span",D,u(r.value.length),1)):f("",!0)],8,z),N(x,{open:i.value,title:"Sync all to OAP",onClose:e[3]||(e[3]=o=>i.value=!1)},{footer:P(()=>[n("button",{class:"sw-btn ghost",type:"button",onClick:e[2]||(e[2]=o=>i.value=!1)},u(s.value?"Close":"Cancel"),1),s.value?f("",!0):(l(),a("button",{key:0,class:"sw-btn primary",type:"button",disabled:d.value||r.value.length===0,onClick:T},u(d.value?"Pushing…":`Push ${r.value.length} to OAP`),9,K))]),default:P(()=>[s.value?(l(),a("div",q,[n("p",G,[e[8]||(e[8]=c(" Pushed ",-1)),n("b",null,u(s.value.synced),1),e[9]||(e[9]=c(" template(s). ",-1)),s.value.failed.length?(l(),a("span",H,u(s.value.failed.length)+" failed.",1)):f("",!0)]),s.value.failed.length?(l(),a("ul",J,[(l(!0),a(m,null,C(s.value.failed,o=>(l(),a("li",{key:o.name,class:"mono sab__err"},u(o.name)+": "+u(o.error),1))),128))])):f("",!0)])):(l(),a("div",I,[n("p",W,[e[6]||(e[6]=c(" Push the bundled copy of these ",-1)),n("b",null,u(r.value.length),1),e[7]||(e[7]=c(" template(s) to OAP, overwriting what OAP currently stores. Already-synced templates are not touched. This affects every operator using this OAP. ",-1))]),n("ul",j,[(l(!0),a(m,null,C(r.value,o=>(l(),a("li",{key:o,class:"mono"},u(o),1))),128))])]))]),_:1},8,["open"])],64))}}),ee=L(Q,[["__scopeId","data-v-3386dbb3"]]);export{ee as S};
