import{u as ee,y as R,n as z,o as r,c as p,d as o,g as n,b as a,t as i,e as l,E as Y,p as q,q as P,h as D,r as m,k as c,F as f,j as d,S as G,G as te,w as se,D as A,f as ae,J as le,H as j,i as F,m as U}from"./index-98f795cb.js";import{_ as oe}from"./LayoutHeader-5b605857.js";import{_ as ne}from"./EmptyState-ade36e24.js";import{D as ie}from"./Dropdown-569f15bd.js";const re={class:"flex flex-col h-full"},de={class:"flex-1 overflow-auto p-5 space-y-6"},ue={class:"rounded-lg border p-5 shadow-sm"},ce={class:"flex items-center justify-between mb-4"},pe={class:"text-lg font-semibold text-ink-gray-9"},me={key:0,class:"flex justify-center py-4"},ve={key:1,class:"flex items-center gap-3 py-3"},fe={class:"flex-1"},ge={class:"text-sm font-medium text-ink-gray-9"},ye={class:"text-xs text-ink-gray-5"},_e={key:0,class:"flex items-center justify-center h-64"},be={key:1,class:"grid gap-4 sm:grid-cols-2 lg:grid-cols-3"},he=["onClick"],xe={class:"flex items-start justify-between mb-4"},ke={class:"flex items-center gap-3"},we={class:"w-12 h-12 rounded-lg bg-blue-100 flex items-center justify-center"},$e={class:"text-base font-medium text-ink-gray-9"},Ve={class:"text-sm text-ink-gray-5 mb-4 line-clamp-2"},Ce={class:"grid grid-cols-2 gap-4 text-sm"},De={class:"text-ink-gray-4 text-xs"},Ae={class:"font-medium text-ink-gray-9"},je={class:"font-medium text-ink-gray-9"},Fe={class:"mt-4 pt-4 border-t flex justify-between items-center text-xs text-ink-gray-4"},Ue={class:"space-y-4"},Me={class:"text-sm text-ink-gray-7"},Te={class:"space-y-4"},Ne={class:"text-sm text-ink-gray-7"},Ie={key:1,class:"mt-4"},Ee={class:"block text-sm font-medium text-ink-gray-7 mb-2"},Se={class:"bg-gray-900 text-gray-100 p-4 rounded-lg text-xs font-mono max-h-64 overflow-y-auto"},Be={class:"flex w-full items-center justify-end gap-2"},H=`image:
  distribution: "alpinelinux"

source:
  downloader: alpinelinux-http
  same_as: 3.12
  url: https://mirror.csclub.uwaterloo.ca/alpine/

targets:
  incus:
    vm:
      filesystem: ext4

files:
- path: /etc/hostname
  generator: hostname

- path: /etc/hosts
  generator: hosts

- path: /etc/network/interfaces
  generator: dump
  content: |-
    auto eth0
    iface eth0 inet dhcp

packages:
  manager: apk
  update: true
  cleanup: true
  sets:
  - packages:
    - alpine-base
    action: install

actions:
- trigger: post-packages
  action: |-
    #!/bin/sh
    set -eux
    rm -f /var/cache/apk/*
`,Pe={__name:"Apps",setup(Le){const J=ee(),g=m(!1),_=m(!1),k=m(!1),w=m(!1),$=m(!1),V=m(!1),b=m(null),v=m(null),h=m(""),u=m({name:"",description:"",yaml_content:H}),y=R({url:"admin_panel.api.apps.get_apps",auto:!0}),C=R({url:"admin_panel.api.servers.get_setup_status",auto:!0}),M=z(()=>y.data||[]),x=z(()=>C.data);function K(){y.reload()}function T(e){J.push({name:"AppDetail",params:{appId:e}})}function O(e){return[{label:"View Details",icon:"eye",onClick:()=>T(e.id)},{label:"Delete",icon:"trash-2",onClick:()=>{b.value=e,_.value=!0}}]}async function Q(){if(!u.value.name){console.error("App name is required");return}w.value=!0;try{const e=await U("admin_panel.api.apps.create_app",{app_name:u.value.name,description:u.value.description,yaml_content:u.value.yaml_content});e.success?(console.log(e.message),g.value=!1,u.value={name:"",description:"",yaml_content:H},y.reload()):console.error(e.error||"Failed to create app")}catch(e){console.error(e.message||"Failed to create app")}finally{w.value=!1}}async function W(){if(b.value){$.value=!0;try{const e=await U("admin_panel.api.apps.delete_app",{app_name:b.value.id});e.success?(console.log(e.message),_.value=!1,b.value=null,y.reload()):console.error(e.error||"Failed to delete app")}catch(e){console.error(e.message||"Failed to delete app")}finally{$.value=!1}}}async function X(){V.value=!0,v.value=null;try{const e=await U("admin_panel.api.servers.run_setup",{doas_password:h.value});v.value=e,e.success&&C.reload()}catch(e){v.value={success:!1,logs:[`Error: ${e.message}`]}}finally{V.value=!1}}function Z(){k.value=!1,v.value=null,h.value=""}return(e,s)=>{var N,I,E,S,B;return r(),p("div",re,[o(oe,{title:e.$t("apps.title")},{right:n(()=>[o(l(c),{variant:"subtle",onClick:K,loading:l(y).loading},{prefix:n(()=>[o(l(f),{name:"refresh-cw",class:"h-4 w-4"})]),default:n(()=>[d(" "+i(e.$t("common.refresh")),1)]),_:1},8,["loading"]),o(l(c),{variant:"solid",onClick:s[0]||(s[0]=t=>g.value=!0)},{prefix:n(()=>[o(l(f),{name:"plus",class:"h-4 w-4"})]),default:n(()=>[d(" "+i(e.$t("apps.createApp")||"Create App"),1)]),_:1})]),_:1},8,["title"]),a("div",de,[a("div",ue,[a("div",ce,[a("h3",pe,i(e.$t("servers.setup.title")),1),o(l(c),{variant:"solid",onClick:s[1]||(s[1]=t=>k.value=!0),disabled:(N=x.value)==null?void 0:N.distrobuilder_installed},{prefix:n(()=>[o(l(f),{name:"download",class:"h-4 w-4"})]),default:n(()=>[d(" "+i(e.$t("servers.setup.install")),1)]),_:1},8,["disabled"])]),l(C).loading?(r(),p("div",me,[o(l(G),{class:"h-6 w-6"})])):(r(),p("div",ve,[a("div",{class:Y(["w-10 h-10 rounded-full flex items-center justify-center",(I=x.value)!=null&&I.distrobuilder_installed?"bg-green-100 text-green-600":"bg-red-100 text-red-600"])},[o(l(f),{name:(E=x.value)!=null&&E.distrobuilder_installed?"check-circle":"alert-circle",class:"h-5 w-5"},null,8,["name"])],2),a("div",fe,[a("p",ge,i((S=x.value)!=null&&S.distrobuilder_installed?e.$t("servers.setup.distrobuilderInstalled"):e.$t("servers.setup.distrobuilderNotInstalled")),1),a("p",ye,i(((B=x.value)==null?void 0:B.distrobuilder_version)||e.$t("servers.setup.distrobuilderDesc")),1)])]))]),l(y).loading?(r(),p("div",_e,[o(l(G),{class:"h-8 w-8"})])):M.value.length?(r(),p("div",be,[(r(!0),p(q,null,P(M.value,t=>(r(),p("div",{key:t.id,class:"rounded-lg border p-5 hover:shadow-md transition-shadow cursor-pointer",onClick:L=>T(t.id)},[a("div",xe,[a("div",ke,[a("div",we,[o(l(f),{name:"package",class:"h-6 w-6 text-blue-600"})]),a("div",null,[a("h3",$e,i(t.name),1),o(l(te),{class:"mt-1",variant:t.status==="active"?"success":"warning",label:t.status},null,8,["variant","label"])])]),o(l(ie),{options:O(t),onClick:s[2]||(s[2]=se(()=>{},["stop"]))},{default:n(()=>[o(l(c),{variant:"ghost",size:"sm"},{default:n(()=>[o(l(f),{name:"more-vertical",class:"h-4 w-4"})]),_:1})]),_:1},8,["options"])]),a("p",Ve,i(t.description),1),a("div",Ce,[a("div",null,[a("span",De,i(e.$t("apps.imageVersion")),1),a("p",Ae,i(t.currentVersion||"-"),1)]),a("div",null,[s[13]||(s[13]=a("span",{class:"text-ink-gray-4 text-xs"},"Versions",-1)),a("p",je,i(t.versions_count||0),1)])]),a("div",Fe,[a("span",null,i(t.size||"-"),1),a("span",null,"Updated: "+i(t.lastUpdated||"-"),1)])],8,he))),128))])):(r(),D(ne,{key:2,icon:"package",title:e.$t("apps.noApps"),description:"No app templates found. Create one to get started."},{action:n(()=>[o(l(c),{variant:"solid",onClick:s[3]||(s[3]=t=>g.value=!0)},{default:n(()=>[d(i(e.$t("apps.createApp")||"Create App"),1)]),_:1})]),_:1},8,["title"]))]),o(l(j),{modelValue:g.value,"onUpdate:modelValue":s[8]||(s[8]=t=>g.value=t),options:{title:"Create App Template"}},{"body-content":n(()=>[a("div",Ue,[o(l(A),{modelValue:u.value.name,"onUpdate:modelValue":s[4]||(s[4]=t=>u.value.name=t),label:"App Name",type:"text",placeholder:"my-app",description:"Alphanumeric characters, dashes and underscores only"},null,8,["modelValue"]),o(l(A),{modelValue:u.value.description,"onUpdate:modelValue":s[5]||(s[5]=t=>u.value.description=t),label:"Description",type:"textarea",placeholder:"Description of this app template..."},null,8,["modelValue"]),a("div",null,[s[14]||(s[14]=a("label",{class:"block text-sm font-medium text-ink-gray-7 mb-1"}," YAML Configuration ",-1)),ae(a("textarea",{"onUpdate:modelValue":s[6]||(s[6]=t=>u.value.yaml_content=t),class:"w-full h-64 bg-gray-900 text-gray-100 p-4 rounded-lg text-sm font-mono focus:outline-none focus:ring-2 focus:ring-blue-500",placeholder:"# Distrobuilder YAML configuration..."},null,512),[[le,u.value.yaml_content]])])])]),actions:n(()=>[o(l(c),{variant:"subtle",onClick:s[7]||(s[7]=t=>g.value=!1)},{default:n(()=>[d(i(e.$t("common.cancel")),1)]),_:1}),o(l(c),{variant:"solid",onClick:Q,loading:w.value,disabled:!u.value.name},{default:n(()=>[d(i(e.$t("common.create")),1)]),_:1},8,["loading","disabled"])]),_:1},8,["modelValue"]),o(l(j),{modelValue:_.value,"onUpdate:modelValue":s[10]||(s[10]=t=>_.value=t),options:{title:"Delete App Template"}},{"body-content":n(()=>{var t;return[a("p",Me,[s[15]||(s[15]=d(" Are you sure you want to delete ",-1)),a("strong",null,i((t=b.value)==null?void 0:t.name),1),s[16]||(s[16]=d("? This will only delete the template file, not the built images. ",-1))])]}),actions:n(()=>[o(l(c),{variant:"subtle",onClick:s[9]||(s[9]=t=>_.value=!1)},{default:n(()=>[d(i(e.$t("common.cancel")),1)]),_:1}),o(l(c),{variant:"solid",theme:"red",onClick:W,loading:$.value},{default:n(()=>[...s[17]||(s[17]=[d(" Delete ",-1)])]),_:1},8,["loading"])]),_:1},8,["modelValue"]),o(l(j),{modelValue:k.value,"onUpdate:modelValue":s[12]||(s[12]=t=>k.value=t),options:{title:e.$t("servers.setup.title")}},{"body-content":n(()=>[a("div",Te,[a("p",Ne,i(e.$t("servers.setup.installDescription")),1),v.value?F("",!0):(r(),D(l(A),{key:0,modelValue:h.value,"onUpdate:modelValue":s[11]||(s[11]=t=>h.value=t),label:"Password (doas)",type:"password",placeholder:"Enter your doas password"},null,8,["modelValue"])),s[18]||(s[18]=a("div",{class:"bg-surface-gray-2 rounded-lg p-3"},[a("p",{class:"text-xs text-ink-gray-5"},[d(" For manual install, run in terminal: "),a("code",{class:"bg-surface-gray-3 px-1 rounded text-ink-gray-7"},"doas apk add distrobuilder")])],-1)),v.value?(r(),p("div",Ie,[a("label",Ee,i(e.$t("common.output")),1),a("div",Se,[(r(!0),p(q,null,P(v.value.logs,(t,L)=>(r(),p("div",{key:L,class:Y({"text-green-400":t.includes("Done"),"text-red-400":t.includes("Failed")||t.includes("Error"),"text-yellow-400":t.includes("===")})},i(t),3))),128))])])):F("",!0)])]),actions:n(()=>[a("div",Be,[o(l(c),{variant:"subtle",onClick:Z},{default:n(()=>[d(i(v.value?e.$t("common.close"):e.$t("common.cancel")),1)]),_:1}),v.value?F("",!0):(r(),D(l(c),{key:0,variant:"solid",onClick:X,loading:V.value,disabled:!h.value},{prefix:n(()=>[o(l(f),{name:"download",class:"h-4 w-4"})]),default:n(()=>[d(" "+i(e.$t("servers.setup.install")),1)]),_:1},8,["loading","disabled"]))])]),_:1},8,["modelValue","options"])])}}};export{Pe as default};
//# sourceMappingURL=Apps-91a8c0d8.js.map
