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