import{u as M,y as j,n as N,o as m,c as y,d as o,g as n,b as s,e as l,p as B,q as L,h as S,r as f,k as d,F as _,j as u,t as i,S as Y,G as q,w as z,D as w,f as R,J as E,H as A,m as V}from"./index-96d8d3bd.js";import{_ as G}from"./LayoutHeader-a0707290.js";import{_ as H}from"./EmptyState-060c0be5.js";import{D as I}from"./Dropdown-50cd196e.js";const J={class:"flex flex-col h-full"},K={class:"flex-1 overflow-auto p-5"},O={key:0,class:"flex items-center justify-center h-64"},P={key:1,class:"grid gap-4 sm:grid-cols-2 lg:grid-cols-3"},Q=["onClick"],W={class:"flex items-start justify-between mb-4"},X={class:"flex items-center gap-3"},Z={class:"w-12 h-12 rounded-lg bg-blue-100 flex items-center justify-center"},ee={class:"text-base font-medium text-ink-gray-9"},te={class:"text-sm text-ink-gray-5 mb-4 line-clamp-2"},ae={class:"grid grid-cols-2 gap-4 text-sm"},se={class:"text-ink-gray-4 text-xs"},le={class:"font-medium text-ink-gray-9"},oe={class:"font-medium text-ink-gray-9"},ne={class:"mt-4 pt-4 border-t flex justify-between items-center text-xs text-ink-gray-4"},ie={class:"space-y-4"},re={class:"text-sm text-ink-gray-7"},C=`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/*
`,ve={__name:"Apps",setup(ue){const $=M(),p=f(!1),v=f(!1),h=f(!1),k=f(!1),g=f(null),r=f({name:"",description:"",yaml_content:C}),c=j({url:"admin_panel.api.apps.get_apps",auto:!0}),x=N(()=>c.data||[]);function D(){c.reload()}function b(a){$.push({name:"AppDetail",params:{appId:a}})}function T(a){return[{label:"View Details",icon:"eye",onClick:()=>b(a.id)},{label:"Delete",icon:"trash-2",onClick:()=>{g.value=a,v.value=!0}}]}async function F(){if(!r.value.name){console.error("App name is required");return}h.value=!0;try{const a=await V("admin_panel.api.apps.create_app",{app_name:r.value.name,description:r.value.description,yaml_content:r.value.yaml_content});a.success?(console.log(a.message),p.value=!1,r.value={name:"",description:"",yaml_content:C},c.reload()):console.error(a.error||"Failed to create app")}catch(a){console.error(a.message||"Failed to create app")}finally{h.value=!1}}async function U(){if(g.value){k.value=!0;try{const a=await V("admin_panel.api.apps.delete_app",{app_name:g.value.id});a.success?(console.log(a.message),v.value=!1,g.value=null,c.reload()):console.error(a.error||"Failed to delete app")}catch(a){console.error(a.message||"Failed to delete app")}finally{k.value=!1}}}return(a,e)=>(m(),y("div",J,[o(G,{title:a.$t("apps.title")},{right:n(()=>[o(l(d),{variant:"subtle",onClick:D,loading:l(c).loading},{prefix:n(()=>[o(l(_),{name:"refresh-cw",class:"h-4 w-4"})]),default:n(()=>[u(" "+i(a.$t("common.refresh")),1)]),_:1},8,["loading"]),o(l(d),{variant:"solid",onClick:e[0]||(e[0]=t=>p.value=!0)},{prefix:n(()=>[o(l(_),{name:"plus",class:"h-4 w-4"})]),default:n(()=>[u(" "+i(a.$t("apps.createApp")||"Create App"),1)]),_:1})]),_:1},8,["title"]),s("div",K,[l(c).loading?(m(),y("div",O,[o(l(Y),{class:"h-8 w-8"})])):x.value.length?(m(),y("div",P,[(m(!0),y(B,null,L(x.value,t=>(m(),y("div",{key:t.id,class:"rounded-lg border p-5 hover:shadow-md transition-shadow cursor-pointer",onClick:de=>b(t.id)},[s("div",W,[s("div",X,[s("div",Z,[o(l(_),{name:"package",class:"h-6 w-6 text-blue-600"})]),s("div",null,[s("h3",ee,i(t.name),1),o(l(q),{class:"mt-1",variant:t.status==="active"?"success":"warning",label:t.status},null,8,["variant","label"])])]),o(l(I),{options:T(t),onClick:e[1]||(e[1]=z(()=>{},["stop"]))},{default:n(()=>[o(l(d),{variant:"ghost",size:"sm"},{default:n(()=>[o(l(_),{name:"more-vertical",class:"h-4 w-4"})]),_:1})]),_:1},8,["options"])]),s("p",te,i(t.description),1),s("div",ae,[s("div",null,[s("span",se,i(a.$t("apps.imageVersion")),1),s("p",le,i(t.currentVersion||"-"),1)]),s("div",null,[e[10]||(e[10]=s("span",{class:"text-ink-gray-4 text-xs"},"Versions",-1)),s("p",oe,i(t.versions_count||0),1)])]),s("div",ne,[s("span",null,i(t.size||"-"),1),s("span",null,"Updated: "+i(t.lastUpdated||"-"),1)])],8,Q))),128))])):(m(),S(H,{key:2,icon:"package",title:a.$t("apps.noApps"),description:"No app templates found. Create one to get started."},{action:n(()=>[o(l(d),{variant:"solid",onClick:e[2]||(e[2]=t=>p.value=!0)},{default:n(()=>[u(i(a.$t("apps.createApp")||"Create App"),1)]),_:1})]),_:1},8,["title"]))]),o(l(A),{modelValue:p.value,"onUpdate:modelValue":e[7]||(e[7]=t=>p.value=t),options:{title:"Create App Template"}},{"body-content":n(()=>[s("div",ie,[o(l(w),{modelValue:r.value.name,"onUpdate:modelValue":e[3]||(e[3]=t=>r.value.name=t),label:"App Name",type:"text",placeholder:"my-app",description:"Alphanumeric characters, dashes and underscores only"},null,8,["modelValue"]),o(l(w),{modelValue:r.value.description,"onUpdate:modelValue":e[4]||(e[4]=t=>r.value.description=t),label:"Description",type:"textarea",placeholder:"Description of this app template..."},null,8,["modelValue"]),s("div",null,[e[11]||(e[11]=s("label",{class:"block text-sm font-medium text-ink-gray-7 mb-1"}," YAML Configuration ",-1)),R(s("textarea",{"onUpdate:modelValue":e[5]||(e[5]=t=>r.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),[[E,r.value.yaml_content]])])])]),actions:n(()=>[o(l(d),{variant:"subtle",onClick:e[6]||(e[6]=t=>p.value=!1)},{default:n(()=>[u(i(a.$t("common.cancel")),1)]),_:1}),o(l(d),{variant:"solid",onClick:F,loading:h.value,disabled:!r.value.name},{default:n(()=>[u(i(a.$t("common.create")),1)]),_:1},8,["loading","disabled"])]),_:1},8,["modelValue"]),o(l(A),{modelValue:v.value,"onUpdate:modelValue":e[9]||(e[9]=t=>v.value=t),options:{title:"Delete App Template"}},{"body-content":n(()=>{var t;return[s("p",re,[e[12]||(e[12]=u(" Are you sure you want to delete ",-1)),s("strong",null,i((t=g.value)==null?void 0:t.name),1),e[13]||(e[13]=u("? This will only delete the template file, not the built images. ",-1))])]}),actions:n(()=>[o(l(d),{variant:"subtle",onClick:e[8]||(e[8]=t=>v.value=!1)},{default:n(()=>[u(i(a.$t("common.cancel")),1)]),_:1}),o(l(d),{variant:"solid",theme:"red",onClick:U,loading:k.value},{default:n(()=>[...e[14]||(e[14]=[u(" Delete ",-1)])]),_:1},8,["loading"])]),_:1},8,["modelValue"])]))}};export{ve as default};
//# sourceMappingURL=Apps-ef2ad17e.js.map
