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