"use strict";(self.webpackChunkunifiNetworkUi=self.webpackChunkunifiNetworkUi||[]).push([[30656],{30656:(e,t,n)=>{n.r(t),n.d(t,{default:()=>x});var i=n(469733),o=n(296540),s=n(822336),r=n(589727),a=n(71479),l=n(998837),c=n(742920),m=n(648092),h=n(9247),u=n(137007),d=n(6510);const p=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))};var C=n(663516),E=n(257420),g=n(959533);const f=class{constructor(e){this.onChannelMessage=e=>{this.terminal&&this.terminal.write(e)},this.onChannelClose=()=>{const{formatMessage:e,onClose:t,device:{mac:n}}=this.props;this.terminal&&(this.terminal.write("\r\n"),this.writeToTerminalConnectionStatus(e({id:E.ih.TERMINAL_CONNECTION_DROPPED})),this.releaseConnection(n),t&&t())},this.close=()=>{const{device:{mac:e},formatMessage:t}=this.props;this.eventBus.emit(g.J.CANCEL_CONNECTION,e),this.writeToTerminalConnectionStatus(t({id:"COMMON_DISCONNECTED"})),this.terminal&&(this.releaseConnection(e),this.terminal.dispose())},this.props=e,this.eventBus=new u.EventEmitter}writeToTerminalConnectionStatus(e){const{device:t,formatMessage:n}=this.props;this.terminal.write(`[${E.AB.FONT}${n({id:"COMMON_DEVICE"})} ${(0,d.Q)(t)}: ${e}[m\r\n`)}open(e){this.terminal=new h.B({cols:E.XF.COLS,rows:E.XF.ROWS,cursorBlink:!1,fontSize:E.XF.FONT,theme:{background:E.AB.BACKGROUND,foreground:E.AB.FOREGROUND,selection:E.AB.SELECTION,cursor:E.AB.FOREGROUND}}),this.closed=!1,e&&this.updateTheme(e),this.initTerminal();const{formatMessage:t}=this.props;return(0,C.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:E.ih.TERMINAL_CONNECTED}))})).catch(e=>(this.writeToTerminalConnectionStatus(t({id:E.ih.TERMINAL_CONNECTION_ERROR})),Promise.reject(new Error("ConnectionError"))))}updateTheme(e){this.terminal.setOption("theme",e)}setupTerminalCommunication(e){this.eventBus.on(g.w.MESSAGE_RECEIVED,this.onChannelMessage),this.eventBus.on(g.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,C.eh)(e))}initTerminal(){const{element:e,formatMessage:t}=this.props;this.terminal.open(e),this.writeToTerminalConnectionStatus(t({id:E.ih.TERMINAL_CONNECTING}))}getTerminalSelection(){if(this.terminal.hasSelection())return this.terminal.getSelection();this.terminal.selectAll();const e=this.terminal.getSelection();return this.terminal.clearSelection(),e}copyContent(){const e=this.getTerminalSelection();p(e)}};var T=n(294303),N=n(675359),S=n(126457),w=n(699784),A=n(187483),O=n(705426),v=n(989512);const b=(0,a.A)("div")`
  width: 100%;
  height: ${13*E.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;
  }
`,R=({createTerminal:e})=>{const t=(0,o.useRef)(),[n,i]=(0,o.useState)(!1);return(0,o.useEffect)(()=>{t.current&&!n&&(i(!0),e(t.current))},[n]),o.createElement(b,{ref:t})},M=(0,a.A)(r.A)`
  color: ${({theme:{themeName:e}})=>s.Ay[`desktop-color-neutral-08-${e}`]};
  cursor: pointer;
`,x=({device:e})=>{const{formatMessage:t}=(0,w.tz)(),n=(0,i.useSelector)(A.bI),s=(0,i.useSelector)(A.ub),r=(0,i.useSelector)(m.a),{motifPalette:{uiShell:a,ui05:h,activeInteractive02:u}}=(0,l.u)(),d=(0,i.useDispatch)(),[p,C]=(0,o.useState)(!1),[E,g]=(0,o.useState)(),b=(0,o.useMemo)(()=>({background:a,foreground:h,cursor:u}),[a,h,u]),x=()=>{E&&E.close()},I=(0,o.useCallback)(()=>{E&&(E.copyContent(),d((0,N.ox)({icon:c.C.success,message:"COMMON_COPIED_TO_CLIPBOARD"})))},[E,d]);return(0,o.useEffect)(()=>{E&&E.updateTheme(b)},[E,b]),o.createElement(O.A,{flushContent:!0,noSlide:!0,onRequestClose:()=>{x(),d((0,S.AS)())},headerClassName:"custom-header-padding",title:o.createElement(T.A,{alignItems:"center",width:"100%",justifyContent:"space-between",position:"relative",bottom:"2px"},o.createElement(v.A,{device:e}),o.createElement(M,{onClick:I})),footer:()=>null,size:"medium"},o.createElement(R,{createTerminal:i=>{if(!i||E||p)return;C(!0);const o=new f({formatMessage:t,device:e,element:i,dispatch:d,isWebrtc:n,webSocketPool:r,onClose:x,isHybridApp:s});g(o),o.open(b).catch(x)}}))}},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%"},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)))}}]);