import{x as M,a as R,b as N,c as f}from"./xterm-dpUsuiNl.js?v=1773287522785";import{u as I}from"./useSocket-DTHwGZgK.js?v=1773287522785";import{x as $}from"./xterm-addon-canvas-DELv9KNm.js?v=1773287522785";import{k as P,R as U,r as h,w as Z,o as j,b as q,$ as G,Z as H,n as J}from"./vue-core-DJjvd5ZC.js?v=1773287522785";import{b1 as K,c as Q}from"./index-BTglIPU2.js?v=1773287522785";const V=P({__name:"index",props:{data:{},url:{}},emits:["success"],setup(b,{expose:g,emit:C}){const{t:l}=U(),p=b,{data:E}=p,O=C,{ws:a,status:A,send:d,open:x,close:w}=I(p.url,{get verifyData(){return{...E}},onMessage:(n,o)=>{const t=o.data;if(t.indexOf("Authentication timeout.")>-1)u.value=!0;else if(t=="\\r\\nlogout\\r\\n"||t=="logout\\r\\n"||t=="\r\nlogout\r\n"||t=="logout\r\n"||t.search(/logout[\r\n]+$/)>-1){e.write("\r"+l("Component.Terminal.index_1")+"\r"),y(),w();return}}});let e,r;const u=h(!1),i=h(null),z=()=>{e=new M.Terminal({cursorBlink:!0,fontSize:14,fontFamily:"Monaco, Menlo, Consolas, 'Courier New', monospace",theme:{background:"#333",foreground:"#ececec"}}),r=new R.FitAddon,D(),L(),v(),T()};let s=null;const D=()=>{const n=a.value;n&&(e.loadAddon(r),e.loadAddon(new $.CanvasAddon),e.loadAddon(new N.WebLinksAddon),s=new f.AttachAddon(n),e.loadAddon(s),setTimeout(()=>{r.fit()},100))};Z([a,A],([n,o])=>{if(o==="CLOSED"&&n){e.write("\r\n"+l("Component.Terminal.index_2")+"\r\n"),setTimeout(()=>{x()},500);return}o==="OPEN"&&n&&(s&&s.dispose(),s=new f.AttachAddon(n),e.loadAddon(s),setTimeout(()=>{r.fit();const{cols:t,rows:F}=e;d({cols:t,rows:F,resize:1}),O("success")},100))},{immediate:!1});const L=()=>{i.value&&e.open(i.value)};let m=!1;const S=()=>{m=!0},y=()=>{m=!1},v=()=>{e.focus(),e.onData(n=>{const o=a.value;n==="\r"&&u.value&&(u.value=!1,e.write("\r\n"),k()),o===void 0&&n==="\r"&&!m&&(S(),e.write("\r\n"+l("Component.Terminal.index_2")+"\r\n"),k())})},k=()=>{x(),v();const n=a.value;n&&e.loadAddon(new f.AttachAddon(n))},T=()=>{J(()=>{if(r.fit(),A.value!=="CLOSED"){const{cols:n,rows:o}=e;d({cols:n,rows:o,resize:1})}})};let _=!0;const c=new ResizeObserver(()=>{K(()=>{if(_){_=!1;return}T()},200)()}),B=()=>{const n=i.value;n&&c.observe(n)};return g({send:d}),j(async()=>{z(),B()}),q(()=>{c==null||c.disconnect(),w(),e==null||e.dispose()}),(n,o)=>(G(),H("div",{ref_key:"terminalRef",ref:i,class:"w-full h-full"},null,512))}}),oe=Q(V,[["__scopeId","data-v-bbac929c"]]);export{oe as S};
