"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("primereact/terminalservice"),n=require("primereact/utils");function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var o=r(e);function a(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0){var n=u(t);n[n.length-1].response=e,this.setState({commands:n})}}},{key:"clear",value:function(){this.setState({commands:[],index:0})}},{key:"componentDidMount",value:function(){t.TerminalService.on("response",this.response),t.TerminalService.on("clear",this.clear)}},{key:"componentDidUpdate",value:function(){this.container.scrollTop=this.container.scrollHeight}},{key:"componentWillUnmount",value:function(){t.TerminalService.off("response",this.response),t.TerminalService.off("clear",this.clear)}},{key:"renderWelcomeMessage",value:function(){return this.props.welcomeMessage?o.default.createElement("div",null,this.props.welcomeMessage):null}},{key:"renderCommand",value:function(e,t){var n=e.text,r=e.response;return o.default.createElement("div",{key:"".concat(n).concat(t)},o.default.createElement("span",{className:"p-terminal-prompt"},this.props.prompt," "),o.default.createElement("span",{className:"p-terminal-command"},n),o.default.createElement("div",{className:"p-terminal-response"},r))}},{key:"renderContent",value:function(){var e=this,t=this.state.commands.map((function(t,n){return e.renderCommand(t,n)}));return o.default.createElement("div",{className:"p-terminal-content"},t)}},{key:"renderPromptContainer",value:function(){var e=this;return o.default.createElement("div",{className:"p-terminal-prompt-container"},o.default.createElement("span",{className:"p-terminal-prompt"},this.props.prompt," "),o.default.createElement("input",{ref:function(t){return e.input=t},type:"text",value:this.state.commandText,className:"p-terminal-input",autoComplete:"off",onChange:this.onInputChange,onKeyDown:this.onInputKeyDown}))}},{key:"render",value:function(){var e=this,t=n.classNames("p-terminal p-component",this.props.className),r=this.renderWelcomeMessage(),a=this.renderContent(),i=this.renderPromptContainer();return o.default.createElement("div",{ref:function(t){return e.container=t},id:this.props.id,className:t,style:this.props.style,onClick:this.onClick},r,a,i)}}])&&f(c.prototype,s),l&&f(c,l),Object.defineProperty(c,"prototype",{writable:!1}),h}();x={id:null,style:null,className:null,welcomeMessage:null,prompt:null},(k="defaultProps")in(w=C)?Object.defineProperty(w,k,{value:x,enumerable:!0,configurable:!0,writable:!0}):w[k]=x,exports.Terminal=C;