import{I as A}from"./iconify-56cbf3ff.js";import{d as B,r as d,u as T,a3 as U,t as e,W as _,q as g,K as m,a7 as h,o as S,e as V,f as c,h as r,w as i,j as l,s as b,g as y,n as D,a6 as k,af as E,a0 as M}from"./index-a0da86f0.js";import{_ as $}from"./_plugin-vue_export-helper-c27b6911.js";const z={class:"installed-apps-page"},P={class:"page-header"},q={class:"header-content"},G={class:"page-title"},K={class:"page-description"},L={class:"apps-section"},R=B({__name:"InstalledApps",setup(W){const v=d([]),p=d(!1),x=d(!1),u=d(null),n=T(),w=U(),I=[{title:e("App Name"),key:"name",width:200},{title:e("Version"),key:"version",width:100,render:a=>a.version||"1.0.0"},{title:e("Git Branch"),key:"git_branch",width:120,render:a=>a.git_branch||"main"},{title:e("Actions"),key:"actions",width:280,render:a=>_("div",{class:"action-buttons"},[_(g,{size:"small",type:"default",loading:u.value===a.name,disabled:a.name==="jingrow",onClick:()=>N(a)},{default:()=>e("Export Package")}),_(g,{size:"small",type:"error",style:"margin-left: 8px;",disabled:!a.uninstallable,onClick:()=>j(a)},{default:()=>a.uninstallable?e("Uninstall"):e("System App")})])}],f=async()=>{var a,o;try{p.value=!0;const t=await m.get("/jingrow/installed-apps",{headers:h()});t.data.success?v.value=t.data.data.apps||[]:n.error(t.data.error||e("Failed to load apps"))}catch(t){console.error("Load apps error:",t),n.error(((o=(a=t.response)==null?void 0:a.data)==null?void 0:o.error)||e("Failed to load apps"))}finally{p.value=!1}},C=()=>{f()},N=async a=>{var o,t;if(a.name==="jingrow"){n.warning(e("System App")+" "+e("cannot be exported"));return}try{u.value=a.name;const s=await m.post(`/jingrow/export-app-package/${a.name}`,{},{headers:h()});if(s.data.success){if(n.success(e("App package exported successfully: {0}").replace("{0}",s.data.filename||a.name)),s.data.filename){const F=`/files/${s.data.filename}`;window.open(F,"_blank")}}else n.error(s.data.error||e("Failed to export app package"))}catch(s){console.error("Export app error:",s),n.error(((t=(o=s.response)==null?void 0:o.data)==null?void 0:t.error)||e("Failed to export app package"))}finally{u.value=null}},j=async a=>{if(!a.uninstallable){n.warning(e("System App")+" "+e("cannot be uninstalled"));return}w.warning({title:e("Uninstall App"),content:e("Are you sure you want to uninstall '{0}'? This action cannot be undone.").replace("{0}",a.name),positiveText:e("Uninstall"),negativeText:e("Cancel"),onPositiveClick:async()=>{var o,t;try{x.value=!0;const s=await m.post(`/jingrow/uninstall/${a.name}`,{},{headers:h()});s.data.success?(n.success(e("App '{0}' uninstalled successfully").replace("{0}",a.name)),await f()):n.error(s.data.error||e("Failed to uninstall app"))}catch(s){console.error("Uninstall app error:",s),n.error(((t=(o=s.response)==null?void 0:o.data)==null?void 0:t.error)||e("Failed to uninstall app"))}finally{x.value=!1}}})};return S(()=>{f()}),(a,o)=>(D(),V("div",z,[c("div",P,[c("div",q,[c("h1",G,[r(l(k),null,{default:i(()=>[r(l(A),{icon:"tabler:apps"})]),_:1}),b(" "+y(l(e)("Installed Apps")),1)]),c("p",K,y(l(e)("Manage your locally installed applications")),1)])]),c("div",L,[r(l(M),{class:"apps-card"},{"header-extra":i(()=>[r(l(g),{onClick:C,loading:p.value},{icon:i(()=>[r(l(k),null,{default:i(()=>[r(l(A),{icon:"tabler:refresh"})]),_:1})]),default:i(()=>[b(" "+y(l(e)("Refresh")),1)]),_:1},8,["loading"])]),default:i(()=>[r(l(E),{columns:I,data:v.value,loading:p.value,pagination:!1},null,8,["data","loading"])]),_:1})])]))}});const Q=$(R,[["__scopeId","data-v-fb9ef3d0"]]);export{Q as default};
