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