"use strict";(self.webpackChunkPlesk=self.webpackChunkPlesk||[]).push([["views/smb/web/move"],{1353:(e,t,s)=>{s.r(t);var a=s(92),n=s(208),i=s(210),r=s.n(i),o=s(209),l=s(88),d=s(923),m=s(674);const u=l.Locale.getSection("components.forms.domain.move"),h="new",c="existing";class p extends n.Component{constructor(...e){super(...e),(0,a.default)(this,"state",{loading:!0,formState:null,isOpen:!0,subdomains:[],aliases:[],targets:[],errors:{},values:{target:null,moveto:c},isNew:!1,moveToNewData:null,moveDatabases:null,task:null}),(0,a.default)(this,"handleClose",(()=>{this.setState({isOpen:!1})})),(0,a.default)(this,"handleSubmit",(({target:e,username:t,password:s,moveDatabases:a})=>{const i={},{domainId:r}=this.props,{isNew:l,moveToNewData:d}=this.state,m=null!==d&&d.withHosting;if(l?(!t&&m&&(i.username={isEmpty:(0,n.jsx)(o.Translate,{content:"usernameIsRequred"})}),!s&&m&&(i.password={isEmpty:(0,n.jsx)(o.Translate,{content:"passwordIsRequred"})})):e||(i.target={isEmpty:(0,n.jsx)(o.Translate,{content:"targetIsRequred"})}),this.setState({errors:i}),Object.keys(i).length)return;const u=l?{moveto:h,domainId:r,username:t,password:s,moveDatabases:a}:{moveto:c,domainId:r,webspaceId:e.id,moveDatabases:a};this.setState({formState:"submit"},(()=>{this.move(u)}))}))}componentDidMount(){this.loadData()}async loadData(){this.setState({loading:!0});const{targets:e,...t}=await l.api.get("/smb/web/move-data",{domainId:this.props.domainId});this.setState({...t,targets:e,loading:!1,values:{...this.state.values,moveto:e.length?c:h},isNew:!e.length})}async move(e){const{status:t,task:s,errors:a}=await l.api.post("/smb/web/move",e);"ok"!==t?this.setState({errors:a,formState:null,loading:!1}):this.setState({task:s})}renderChildrenHint(){const e=this.state.subdomains.join(", "),t=this.state.aliases.join(", ");return e&&t?(0,n.jsx)(o.Translate,{content:"hintSubdomainsAndAliases",params:{subdomains:e,aliases:t}}):e?(0,n.jsx)(o.Translate,{content:"hintSubdomains",params:{subdomains:e}}):t?(0,n.jsx)(o.Translate,{content:"hintAliases",params:{aliases:t}}):void 0}renderNewSubscriptionOption(){const{isNew:e,moveToNewData:{available:t,withHosting:s}}=this.state,a=[];return e&&t&&(s?a.push((0,n.jsx)(o.FormFieldText,{name:"username",label:(0,n.jsx)(o.Translate,{content:"username"}),description:(0,n.jsx)(o.Translate,{content:"usernameHint"}),size:"md",required:!0},"username"),(0,n.jsx)(o.FormFieldPassword,{name:"password",label:(0,n.jsx)(o.Translate,{content:"password"}),size:"md",required:!0},"password")):a.push((0,n.jsxs)(o.Alert,{intent:"info",children:[(0,n.jsx)(o.Icon,{name:"info-circle"})," ",(0,n.jsx)(o.Translate,{content:"noWebHosting"})]}))),{disabled:!t,value:h,label:(0,n.jsx)(o.Translate,{content:"selectNewSubscription"}),indentFields:a}}renderContent(){const{targets:e,moveToNewData:t}=this.state,s=!e.length;return this.state.loading?(0,n.jsx)(o.ContentLoader,{}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(o.Paragraph,{children:this.renderChildrenHint()}),t?(0,n.jsx)(o.FormFieldRadioButtons,{name:"moveto",onChange:e=>this.setState({isNew:e===h}),options:[{disabled:s,value:c,label:(0,n.jsx)(o.Translate,{content:"selectTarget"}),indentFields:[(0,n.jsx)(d.default,{name:"target",data:e,locale:u,disabled:s,placeholder:s?u.lmsg("noAvailableSubscriptions"):null},"target")]},this.renderNewSubscriptionOption()]}):(0,n.jsx)(d.default,{name:"target",label:(0,n.jsx)(o.Translate,{content:"selectTarget"}),data:e,locale:u})]})}renderDatabaseSection(){return(0,n.jsxs)(o.Paragraph,{children:[(0,n.jsx)(o.Paragraph,{children:(0,n.jsx)("br",{})}),(0,n.jsx)(o.Alert,{intent:"info",children:(0,n.jsx)(o.Translate,{content:"hintDatabases"})}),(0,n.jsx)(o.Paragraph,{children:(0,n.jsx)(o.FormFieldCheckbox,{name:"moveDatabases",value:"1",label:(0,n.jsx)(o.Translate,{content:"labelDatabases"})})})]})}render(){const{errors:e,formState:t,loading:s,values:a,moveDatabases:i,task:r}=this.state;return(0,n.jsx)(o.LocaleProvider,{messages:u.messages,children:(0,n.jsxs)(m.default,{title:(0,n.jsx)(o.Translate,{content:"title",params:{name:this.props.domainName}}),isOpen:this.state.isOpen,onClose:this.handleClose,size:"sm",form:{values:a,state:t,vertical:!0,submitButton:{disabled:s},applyButton:!1,hideRequiredLegend:!0,onSubmit:this.handleSubmit,errors:e},dataType:"move-domain",task:r,children:[(0,n.jsx)(o.Paragraph,{children:(0,n.jsx)(o.Translate,{content:this.props.mainDomain?"hintMain":"hint"})}),this.renderContent(),i?this.renderDatabaseSection():null]})})}}p.propTypes={domainId:r().number.isRequired,domainName:r().string.isRequired,mainDomain:r().bool},p.defaultProps={mainDomain:!1},t.default=p},1352:(e,t,s)=>{s.r(t);var a=s(208),n=s(1353);t.default=e=>{(0,a.render)((0,a.jsx)(n.default,{...e}),document.createElement("div"))}}}]);
//# sourceMappingURL=move.js.map?79e530c3bf3c72bec3ac