(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[9548],{9116:(e,l,t)=>{(window.__NEXT_P=window.__NEXT_P||[]).push(["/admin/[user_id]/su/console",function(){return t(8158)}])},8158:(e,l,t)=>{"use strict";t.r(l),t.d(l,{__N_SSP:()=>d,default:()=>m});var s=t(4848),n=t(6540),o=t(4787);async function a(e){let{socket:l}=e,{Terminal:s}=t(2975),{FitAddon:n}=t(9195),o=new n,a=document.getElementById("terminalWrapper"),i=document.getElementById("terminal"),r=Math.round(a.clientWidth/12),c=new s({cols:r,rows:6});c.open(i),o.fit(),l.on("console",e=>{c.write(e)});{let e=new n,t=document.getElementById("shell"),o=new s({cols:r,rows:17});o.open(t),e.fit(),l.on("shell",e=>{o.write(e)}),o.onKey((e,t)=>{l.emit("shell",e.key)})}return c}var i=t(911);function r(e){let{socketDomain:l}=e,[t,r]=n.useState(null),[c,d]=n.useState(null),[m,u]=n.useState("");return n.useEffect(()=>{if(console.log("Socket Domain =>",l),!l)return;let e=(0,o.io)(l,{extraHeaders:{"X-Socket-Paradigm":"Console"}});e.on("connect",()=>{r(e),console.log("Socket Connected!")}),setInterval(()=>{e.emit("get-log")},1e3),e.on("console-log",e=>{console.log("Fetched Log",e),u(e.replace((0,i.A)(),"")),setTimeout(()=>{let e=document.getElementById("logHistoryWrapper");e&&(e.scrollTop=e.scrollHeight)},200)})},[]),n.useEffect(()=>{if(t)return a({socket:t}).then(e=>{d(e)}),function(){var e,l;null===(e=document.getElementById("terminal"))||void 0===e||e.childNodes.forEach(e=>{var l;null===(l=e.parentNode)||void 0===l||l.removeChild(e)}),null===(l=document.getElementById("shell"))||void 0===l||l.childNodes.forEach(e=>{var l;null===(l=e.parentNode)||void 0===l||l.removeChild(e)}),null==c||c.dispose()}},[t]),(0,s.jsxs)(n.Fragment,{children:[(0,s.jsxs)("div",{className:"w-full justify-between",children:[(0,s.jsx)("h2",{className:"text-2xl m-0",children:"Console"}),(0,s.jsx)("button",{onClick:e=>{t&&t.emit("log","Logging to the console")},children:"Log console"})]}),(0,s.jsxs)("div",{className:"grid grid-cols-2 gap-6 w-full items-stretch",children:[(0,s.jsx)("section",{className:"paper bg-slate-900",id:"terminalWrapper",children:(0,s.jsx)("div",{className:"flex flex-col w-full gap-10 items-start justify-start terminal",children:(0,s.jsxs)("div",{className:"flex flex-col items-start w-full",children:[(0,s.jsx)("h2",{className:"m-0 text-white text-base",children:"Shell"}),(0,s.jsx)("hr",{className:"opacity-20"}),(0,s.jsx)("div",{id:"shell",className:"relative grow z-50 overflow-hidden w-full h-[340px]"})]})})}),(0,s.jsx)("section",{className:"paper bg-slate-500",id:"terminalWrapper",children:(0,s.jsx)("div",{className:"flex flex-col w-full gap-10 items-start justify-start terminal",children:(0,s.jsxs)("div",{className:"flex flex-col items-start w-full",children:[(0,s.jsx)("h2",{className:"m-0 text-white text-base",children:"Server Log"}),(0,s.jsx)("hr",{className:"opacity-20"}),(0,s.jsx)("div",{id:"terminal",className:"relative grow z-50 overflow-hidden w-full h-[150px]"})]})})})]})]})}t(5044);var c=t(4725),d=!0;function m(e){let{user:l,data:t,socketDomain:n}=e,o=(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("title",{children:"Console | Datasquirel"}),(0,s.jsx)("meta",{name:"description",content:"Databases Console"})]});return(0,s.jsx)(c.A,{head:o,children:(0,s.jsx)(r,{socketDomain:n})})}}},e=>{var l=l=>e(e.s=l);e.O(0,[160,1335,3348,4946,4725,636,6593,8792],()=>l(9116)),_N_E=e.O()}]);