"use strict";(self.webpackChunkPlesk=self.webpackChunkPlesk||[]).push([["app/login/recovery-password"],{2199:(e,t,s)=>{s.r(t),s.d(t,{default:()=>d});var n=s(94),i=s(246),r=s(245),o=s(247),a=s.n(o),l=s(90);class c extends r.Component{constructor(e){if(super(e),(0,n.default)(this,"state",{recoveryLink:"",recoveryEmail:"",isActionInProgress:!1,isDialogOpen:!1,sendButtonState:"active"}),(0,n.default)(this,"recoveryLinkContainer",(0,r.createRef)()),(0,n.default)(this,"setLinkSelection",(()=>{setTimeout((()=>{try{const e=document.createRange();e.selectNode(this.recoveryLinkContainer.current);const t=window.getSelection();t.removeAllRanges(),t.addRange(e)}catch{}}),200)})),(0,n.default)(this,"handleAction",(()=>{if(this.state.isActionInProgress)return;if(this.state.recoveryLink)return this.setState({isDialogOpen:!0}),void this.setLinkSelection();this.setState({isActionInProgress:!0});const{userType:e,userId:t}=this.props;l.api.post((0,l.prepareUrl)(`${this.endpoint}/generate-secret`),{userType:e,userId:t}).then((e=>{"success"===e.status?(this.setState({recoveryLink:e.link,recoveryEmail:e.email,isActionInProgress:!1,isDialogOpen:!0}),this.setLinkSelection()):location.reload()}))})),(0,n.default)(this,"handleSend",(()=>{if("active"!==this.state.sendButtonState)return;this.setState({sendButtonState:"loading"});const{messages:e}=this.props,{userType:t,userId:s}=this.props;l.api.post((0,l.prepareUrl)(`${this.endpoint}/send-secret`),{userType:t,userId:s,secret:this.state.recoveryLink}).then((t=>{"success"===t.status?(this.setState({isDialogOpen:!1}),(0,l.clearStatusMessages)(),(0,l.addStatusMessage)("info",e.linkSendedMessage),this.setState({sendButtonState:"active",recoveryLink:null})):location.reload()}))})),(0,n.default)(this,"handleClose",(()=>{this.setState({isDialogOpen:!1,recoveryLink:null})})),2===this.props.userType)this.endpoint="/admin/reseller";else if(4===this.props.userType)this.endpoint="/admin/customer";else if(8===this.props.userType)this.endpoint="/smb/user";else{if(32!==this.props.userType)throw new Error("Unexpected user type.");this.endpoint="/smb/email-address"}}render(){return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(i.Action,{onClick:this.handleAction,progress:this.state.isActionInProgress,children:(0,r.jsx)(i.Translate,{content:"action"})}),(0,r.jsxs)(i.Dialog,{isOpen:this.state.isDialogOpen,buttons:[this.state.recoveryEmail?(0,r.jsx)(i.Button,{intent:"primary",onClick:this.handleSend,state:this.state.sendButtonState,children:(0,r.jsx)(i.Translate,{content:"sendButton"})},"sendButton"):null],title:(0,r.jsx)(i.Translate,{content:"title"}),cancelTitle:(0,r.jsx)(i.Translate,{content:"closeButton"}),onClose:this.handleClose,children:[this.state.recoveryEmail?(0,r.jsx)(i.Paragraph,{children:(0,r.jsx)(i.Translate,{content:"text",params:{email:(0,r.jsx)(i.Text,{bold:!0,children:this.state.recoveryEmail})}})}):null,(0,r.jsx)(i.Alert,{children:(0,r.jsx)("span",{ref:this.recoveryLinkContainer,children:this.state.recoveryLink})})]})]})}}c.propTypes={messages:a().object.isRequired,userType:a().number.isRequired,userId:a().number.isRequired};const d=c},2198:(e,t,s)=>{s.r(t),s.d(t,{default:()=>a});var n=s(246),i=s(245),r=s(90),o=s(2199);const a=({renderTo:e,...t})=>{const s=r.Locale.getSection("components.login.recovery-password").messages;(0,i.render)((0,i.jsx)(n.LocaleProvider,{messages:s,children:(0,i.jsx)(o.default,{messages:s,...t})}),document.getElementById(e))}}}]);
//# sourceMappingURL=recovery-password.js.map?6bcf4989267e91905060