"use strict";function a(b){"@babel/helpers - typeof";return a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},a(b)}Object.defineProperty(exports,"__esModule",{value:!0}),exports["default"]=void 0;var b=k(require("react")),c=require("carbon-components-react"),d=i(require("prop-types")),e=require("./CodeViewer"),f=i(require("classnames")),g=i(require("./ExpandableDisplay")),h=require("react-i18next");function i(a){return a&&a.__esModule?a:{default:a}}function j(a){if("function"!=typeof WeakMap)return null;var b=new WeakMap,c=new WeakMap;return(j=function(a){return a?c:b})(a)}function k(b,c){if(!c&&b&&b.__esModule)return b;if(null===b||"object"!==a(b)&&"function"!=typeof b)return{default:b};var d=j(c);if(d&&d.has(b))return d.get(b);var e={},f=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var g in b)if("default"!=g&&Object.prototype.hasOwnProperty.call(b,g)){var h=f?Object.getOwnPropertyDescriptor(b,g):null;h&&(h.get||h.set)?Object.defineProperty(e,g,h):e[g]=b[g]}return e["default"]=b,d&&d.set(b,e),e}function l(a,b){return r(a)||q(a,b)||n(a,b)||m()}function m(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function n(a,b){if(a){if("string"==typeof a)return p(a,b);var c=Object.prototype.toString.call(a).slice(8,-1);return"Object"===c&&a.constructor&&(c=a.constructor.name),"Map"===c||"Set"===c?Array.from(a):"Arguments"===c||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(c)?p(a,b):void 0}}function p(a,b){(null==b||b>a.length)&&(b=a.length);for(var c=0,d=Array(b);c<b;c++)d[c]=a[c];return d}function q(a,b){var c=null==a?null:"undefined"!=typeof Symbol&&a[Symbol.iterator]||a["@@iterator"];if(null!=c){var d,e,f=[],g=!0,h=!1;try{for(c=c.call(a);!(g=(d=c.next()).done)&&(f.push(d.value),!(b&&f.length===b));g=!0);}catch(a){h=!0,e=a}finally{try{g||null==c["return"]||c["return"]()}finally{if(h)throw e}}return f}}function r(a){if(Array.isArray(a))return a}var s=function(a){var d=a.websocket,i=(0,b.useState)(""),j=l(i,2),k=j[0],m=j[1],n=(0,b.useState)(""),o=l(n,2),p=o[0],q=o[1],r=(0,h.useTranslation)(),s=r.t,t=(0,b.useRef)(d?d.url:"");(0,b.useEffect)(function(){d&&t.current===d.url||(m([]),t.current=d?d.url:"")},[d]),d&&(d.onmessage=function(a){m(k+s("received")+": "+a.data+"\n")});return b["default"].createElement("div",{className:"testToolWebsocket"},b["default"].createElement("div",{className:(0,f["default"])("testToolSection","testToolWebsocketRequest")},b["default"].createElement("div",{className:"labelText"},s("request")),b["default"].createElement("div",null,b["default"].createElement("div",{className:(0,f["default"])("connection-status"),"data-testid":"connection-status"},s("status"),":",!d&&b["default"].createElement("span",null," ",s("connect_failed")),d&&0===d.readyState&&b["default"].createElement("span",null," ",s("waiting_connection")),d&&1===d.readyState&&b["default"].createElement("span",null," ",s("connected")),d&&2===d.readyState&&b["default"].createElement("span",null," ",s("connection_error")),d&&3===d.readyState&&b["default"].createElement("span",null," ",s("connection_closed"))),b["default"].createElement("div",null,b["default"].createElement(c.TextInput,{id:"message-input",className:"message-input",labelText:s("message"),placeholder:s("enter_message"),role:"textbox",value:p,onChange:function updateMessageValue(a){q(a.target.value)},disabled:!d||1!==d.readyState}),b["default"].createElement(c.Button,{id:"send-message",className:"send-message","data-testid":"send",onClick:function sendMessage(){""!==p&&1===d.readyState&&(d.send(p),m(k+s("sent")+": "+p+"\n"),q(""))},disabled:!d||1!==d.readyState},s("send"))))),0<k.length&&b["default"].createElement("div",{className:(0,f["default"])("testToolSection","testToolWebsocketMessages")},b["default"].createElement("div",{className:"labelText"},s("message_log")),b["default"].createElement("div",{id:"message-list",className:(0,f["default"])("message-list","bx--snippet","bx--snippet--multi","bx--snippet--wraptext")},b["default"].createElement(g["default"],{copyableContent:k},b["default"].createElement(e.CodeViewer,{"data-testid":"message-list",highlight:!1},k)))))};s.propTypes={websocket:d["default"].object,api:d["default"].object};var t=s;exports["default"]=t;