"use strict";(self.webpackChunkPlesk=self.webpackChunkPlesk||[]).push([["views/smb/web/move"],{1807:(e,t,s)=>{s.r(t),s.d(t,{default:()=>b});var a=s(100),n=s(216),i=s(218),o=s.n(i),r=s(217),l=s(96),d=s(951),m=s(729);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:o}=this.props,{isNew:l,moveToNewData:d}=this.state,m=null!==d&&d.withHosting;if(l?(!t&&m&&(i.username={isEmpty:(0,n.jsx)(r.Translate,{content:"usernameIsRequred"})}),!s&&m&&(i.password={isEmpty:(0,n.jsx)(r.Translate,{content:"passwordIsRequred"})})):e||(i.target={isEmpty:(0,n.jsx)(r.Translate,{content:"targetIsRequred"})}),this.setState({errors:i}),Object.keys(i).length)return;const u=l?{moveto:h,domainId:o,username:t,password:s,moveDatabases:a}:{moveto:c,domainId:o,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)(r.Translate,{content:"hintSubdomainsAndAliases",params:{subdomains:e,aliases:t}}):e?(0,n.jsx)(r.Translate,{content:"hintSubdomains",params:{subdomains:e}}):t?(0,n.jsx)(r.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)(r.FormFieldText,{name:"username",label:(0,n.jsx)(r.Translate,{content:"username"}),description:(0,n.jsx)(r.Translate,{content:"usernameHint"}),size:"md",required:!0},"username"),(0,n.jsx)(r.FormFieldPassword,{name:"password",label:(0,n.jsx)(r.Translate,{content:"password"}),size:"md",required:!0},"password")):a.push((0,n.jsxs)(r.Alert,{intent:"info",children:[(0,n.jsx)(r.Icon,{name:"info-circle"})," ",(0,n.jsx)(r.Translate,{content:"noWebHosting"})]}))),{disabled:!t,value:h,label:(0,n.jsx)(r.Translate,{content:"selectNewSubscription"}),indentFields:a}}renderContent(){const{targets:e,moveToNewData:t}=this.state,s=!e.length;return this.state.loading?(0,n.jsx)(r.ContentLoader,{}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(r.Paragraph,{children:this.renderChildrenHint()}),t?(0,n.jsx)(r.FormFieldRadioButtons,{name:"moveto",onChange:e=>this.setState({isNew:e===h}),options:[{disabled:s,value:c,label:(0,n.jsx)(r.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)(r.Translate,{content:"selectTarget"}),data:e,locale:u})]})}renderDatabaseSection(){return(0,n.jsxs)(r.Paragraph,{children:[(0,n.jsx)(r.Paragraph,{children:(0,n.jsx)("br",{})}),(0,n.jsx)(r.Alert,{intent:"info",children:(0,n.jsx)(r.Translate,{content:"hintDatabases"})}),(0,n.jsx)(r.Paragraph,{children:(0,n.jsx)(r.FormFieldCheckbox,{name:"moveDatabases",value:"1",label:(0,n.jsx)(r.Translate,{content:"labelDatabases"})})})]})}render(){const{errors:e,formState:t,loading:s,values:a,moveDatabases:i,task:o}=this.state;return(0,n.jsx)(r.LocaleProvider,{messages:u.messages,children:(0,n.jsxs)(m.default,{title:(0,n.jsx)(r.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:o,children:[(0,n.jsx)(r.Paragraph,{children:(0,n.jsx)(r.Translate,{content:this.props.mainDomain?"hintMain":"hint"})}),this.renderContent(),i?this.renderDatabaseSection():null]})})}}p.propTypes={domainId:o().number.isRequired,domainName:o().string.isRequired,mainDomain:o().bool},p.defaultProps={mainDomain:!1};const b=p},1806:(e,t,s)=>{s.r(t),s.d(t,{default:()=>i});var a=s(216),n=s(1807);const i=e=>{(0,a.render)((0,a.jsx)(n.default,{...e}),document.createElement("div"))}}}]);
//# sourceMappingURL=move.js.map?6ae86c6cee099b2f1fe4