"use strict";(self.webpackChunkunifiNetworkUi=self.webpackChunkunifiNetworkUi||[]).push([[30656],{989512(e,t,n){n.d(t,{A:()=>h});var i=n(296540),o=n(705145),s=n(71479),r=n(6510);const a=(0,s.A)("span")`
  white-space: nowrap;
`;var l=n(294303),c=n(6176);const m=(0,s.A)(c.A)`
  float: left;
`,h=({defaultName:e="",device:{model:t,name:n,mac:s}={},width:c=25,height:h=25,leftOffset:u=0})=>i.createElement(l.A,{alignItems:"center",marginLeft:u,width:"100%",maxWidth:"100%"},i.createElement(l.A,{marginRight:8,flex:`0 0 ${c}px`,width:c,height:h},i.createElement(m,{model:t,width:c,height:h})),i.createElement(o.A,{isTruncated:!0,size:"medium",color:"text-2"},i.createElement(a,null,(0,r.Q)({model:t,name:n,mac:s})||e)))},30656(e,t,n){n.r(t),n.d(t,{default:()=>M});var i=n(296540),o=n(469733),s=n(822336),r=n(589727),a=n(71479),l=n(382389),c=n(742920),m=n(648092),h=n(9247),u=n(137007),d=n(6510);var p=n(663516),C=n(257420),E=n(959533);const g=class{closed;eventBus;props;terminal;constructor(e){this.props=e,this.eventBus=new u.EventEmitter}writeToTerminalConnectionStatus(e){const{device:t,formatMessage:n}=this.props;this.terminal.write(`[${C.AB.FONT}${n({id:"COMMON_DEVICE"})} ${(0,d.Q)(t)}: ${e}[m\r\n`)}open(e){this.terminal=new h.B({cols:C.XF.COLS,rows:C.XF.ROWS,cursorBlink:!1,fontSize:C.XF.FONT,theme:{background:C.AB.BACKGROUND,foreground:C.AB.FOREGROUND,selection:C.AB.SELECTION,cursor:C.AB.FOREGROUND}}),this.closed=!1,e&&this.updateTheme(e),this.initTerminal();const{formatMessage:t}=this.props;return(0,p.fz)(this.props.device.mac,this.eventBus,this.props).then(e=>e.dataChannelDeferred.promise.then(e=>{e.options&&e.options.messages&&e.options.messages.forEach(e=>{this.terminal.write(e)}),this.setupTerminalCommunication(e.channel),this.writeToTerminalConnectionStatus(t({id:C.ih.TERMINAL_CONNECTED}))})).catch(e=>(this.writeToTerminalConnectionStatus(t({id:C.ih.TERMINAL_CONNECTION_ERROR})),Promise.reject(new Error("ConnectionError"))))}updateTheme(e){this.terminal.setOption("theme",e)}onChannelMessage=e=>{this.terminal&&this.terminal.write(e)};onChannelClose=()=>{const{formatMessage:e,onClose:t,device:{mac:n}}=this.props;this.terminal&&(this.terminal.write("\r\n"),this.writeToTerminalConnectionStatus(e({id:C.ih.TERMINAL_CONNECTION_DROPPED})),this.releaseConnection(n),t&&t())};setupTerminalCommunication(e){this.eventBus.on(E.w.MESSAGE_RECEIVED,this.onChannelMessage),this.eventBus.on(E.w.CHANNEL_CLOSED,this.onChannelClose),this.terminal.on("data",t=>{"open"===e.rtcDataChannel.readyState&&e.send(t)})}releaseConnection(e){this.closed||(this.closed=!0,(0,p.eh)(e))}initTerminal(){const{element:e,formatMessage:t}=this.props;this.terminal.open(e),this.writeToTerminalConnectionStatus(t({id:C.ih.TERMINAL_CONNECTING}))}close=()=>{const{device:{mac:e},formatMessage:t}=this.props;this.eventBus.emit(E.J.CANCEL_CONNECTION,e),this.writeToTerminalConnectionStatus(t({id:"COMMON_DISCONNECTED"})),this.terminal&&(this.releaseConnection(e),this.terminal.dispose())};getTerminalSelection(){if(this.terminal.hasSelection())return this.terminal.getSelection();this.terminal.selectAll();const e=this.terminal.getSelection();return this.terminal.clearSelection(),e}copyContent(){!function(e){const t=document.createElement("textarea");t.value=e,t.setAttribute("readonly",""),t.style.position="absolute",t.style.left="-9999px",document.body.appendChild(t);const n=document.getSelection().rangeCount>0&&document.getSelection().getRangeAt(0);t.select(),document.execCommand("copy"),document.body.removeChild(t),n&&(document.getSelection().removeAllRanges(),document.getSelection().addRange(n))}(this.getTerminalSelection())}};var f=n(294303),T=n(675359),N=n(126457),S=n(916537),w=n(187483),A=n(705426),O=n(989512);const v=(0,a.A)("div")`
  width: 100%;
  height: ${13*C.XF.ROWS+48}px;
  background: ${({theme:{motifPalette:{uiShell:e}}})=>e};
  padding: ${({theme:{spacing:e}})=>e["spacing-xxl"]};

  .xterm {
    overflow: hidden;
    position: relative;
  }

  .xterm-viewport {
    position: absolute;
    width: 100%;
    height: 100%;
    overflow: auto;

    ::-webkit-scrollbar-thumb {
      min-height: 3em;
    }
  }

  .xterm-helpers {
    opacity: 0;
    position: absolute;
  }

  .xterm-text-layer,
  .xterm-selection-layer,
  .xterm-link-layer,
  .xterm-cursor-layer {
    position: absolute;
  }
`,b=({createTerminal:e})=>{const t=(0,i.useRef)(),[n,o]=(0,i.useState)(!1);return(0,i.useEffect)(()=>{t.current&&!n&&(o(!0),e(t.current))},[n]),i.createElement(v,{ref:t})},R=(0,a.A)(r.A)`
  color: ${({theme:{themeName:e}})=>s.Ay[`desktop-color-neutral-08-${e}`]};
  cursor: pointer;
`,M=({device:e})=>{const{formatMessage:t}=(0,S.tz)(),n=(0,o.useSelector)(w.bI),s=(0,o.useSelector)(w.ub),r=(0,o.useSelector)(m.a),{motifPalette:{uiShell:a,ui05:h,activeInteractive02:u}}=(0,l.u)(),d=(0,o.useDispatch)(),[p,C]=(0,i.useState)(!1),[E,v]=(0,i.useState)(),M=(0,i.useMemo)(()=>({background:a,foreground:h,cursor:u}),[a,h,u]),x=()=>{E&&E.close()},I=(0,i.useCallback)(()=>{E&&(E.copyContent(),d((0,T.ox)({icon:c.C.success,message:"COMMON_COPIED_TO_CLIPBOARD"})))},[E,d]);return(0,i.useEffect)(()=>{E&&E.updateTheme(M)},[E,M]),i.createElement(A.A,{flushContent:!0,noSlide:!0,onRequestClose:()=>{x(),d((0,N.AS)())},headerClassName:"custom-header-padding",title:i.createElement(f.A,{alignItems:"center",width:"100%",justifyContent:"space-between",position:"relative",bottom:"2px"},i.createElement(O.A,{device:e}),i.createElement(R,{onClick:I})),footer:()=>null,size:"medium"},i.createElement(b,{createTerminal:i=>{if(!i||E||p)return;C(!0);const o=new g({formatMessage:t,device:e,element:i,dispatch:d,isWebrtc:n,webSocketPool:r,onClose:x,isHybridApp:s});v(o),o.open(M).catch(x)}}))}}}]);