import{be as B,D as E,r as f,m as p,_ as h,bg as V,s as D,H as F,a4 as P}from"./ebt3cj6n.js";import{x as z,a as I}from"./vendor/xterm-b1jefe3j.js";import{p as y,f as g,z as M,U as t,W as d,X as c,a3 as A,P as m,Z as v,a8 as _,F as N,q as R,w as q,u as x,ae as L,a0 as C,ai as j,a9 as $,a2 as H}from"./vendor/json-editor-vue-kcahofzr.js";import"./vendor/unocss-mstcul8h.js";import"./vendor/shiki-bpva4tco.js";const S={border:"t base",flex:"~ gap-2","items-center":"",p2:""},U={"text-sm":"",op50:""},W=y({__name:"TerminalView",props:{id:{}},setup(b){const n=b,i=g(),r=B(),o=g();let a;M(async()=>{a=new z.Terminal({convertEol:!0,cols:80,screenReaderMode:!0});const u=new I.FitAddon;a.loadAddon(u),a.open(i.value),u.fit(),E(window,"resize",()=>{u.fit()}),o.value=await f.getTerminalDetail(await p(),n.id),o.value?.buffer&&a.write(o.value.buffer),r.hook("devtools:terminal:data",({id:e,data:l})=>{e===n.id&&a.write(l)})});async function s(){f.runTerminalAction(await p(),n.id,"clear"),a?.clear()}async function k(){f.runTerminalAction(await p(),n.id,"restart")}async function w(){f.runTerminalAction(await p(),n.id,"terminate")}return(u,e)=>{const l=h;return t(),d(N,null,[c("div",{ref_key:"container",ref:i,"h-full":"","w-full":"","of-auto":"","bg-black":""},null,512),c("div",S,[A(l,{title:"Clear",icon:"i-carbon-clean",border:!1,onClick:e[0]||(e[0]=T=>s())}),o.value?.restartable?(t(),m(l,{key:0,title:"Restart",icon:"carbon-renew",border:!1,onClick:e[1]||(e[1]=T=>k())})):v("",!0),o.value?.terminatable?(t(),m(l,{key:1,title:"Terminate",icon:"carbon-delete",border:!1,onClick:e[2]||(e[2]=T=>w())})):v("",!0),c("span",U,_(o.value?.description),1)])],64)}}}),X={key:0,"h-full":"","w-full":"","of-hidden":"",grid:"~ rows-[max-content_1fr_max-content]"},Z={flex:"~",border:"b base","flex-1":"","items-center":"","n-navbar-glass":""},G=["onClick"],J={key:1,p10:""},K={key:1,"h-full":"",flex:"","items-center":"","justify-center":""},O=y({__name:"TerminalPage",setup(b){const n=V(),i=D(),r=R(()=>n.value?.find(a=>a.id===i.value));async function o(a){f.runTerminalAction(await p(),a,"remove")}return q(()=>{!i.value&&n.value?.length&&(i.value=n.value[0].id)}),(a,s)=>{const k=F,w=h,u=W;return x(n)?.length?(t(),d("div",X,[c("div",Z,[(t(!0),d(N,null,L(x(n),e=>(t(),d("button",{key:e.id,border:"r base",flex:"~ gap-2","items-center":"",px3:"",py2:"",class:C(e.id===r.value?.id?"bg-active":""),onClick:l=>i.value=e.id},[e.icon?(t(),m(k,{key:0,icon:e.icon},null,8,["icon"])):v("",!0),c("span",{class:C(e.id===r.value?.id?"":"op50")},_(e.name)+_(e.isTerminated?" (terminated)":""),3),e.isTerminated?(t(),m(w,{key:1,icon:"carbon-close","mx--2":"",border:!1,onClick:j(l=>o(e.id),["stop"])},null,8,["onClick"])):v("",!0)],10,G))),128))]),r.value?(t(),m(u,{id:r.value.id,key:r.value.id},null,8,["id"])):(t(),d("div",J,[s[0]||(s[0]=$(" Terminal ")),c("code",null,_(x(i)),1),s[1]||(s[1]=$(" not found "))]))])):(t(),d("div",K,s[2]||(s[2]=[c("em",{op50:""},"No terminal attached",-1)])))}}}),ae=y({__name:"terminals",setup(b){return(n,i)=>{const r=O,o=P;return t(),m(o,null,{default:H(()=>[A(r)]),_:1})}}});export{ae as default};
