Liferay.Loader.define("change-tracking-web@2.0.73/publications/js/ChangeTrackingBaseScheduleView",["module","exports","require","frontend-js-web","liferay!frontend-js-react-web$react"],(function(t,e,i){var a;window;{Object.defineProperty(e,"__esModule",{value:!0}),e.ChangeTrackingBaseScheduleView=e.default=void 0;var r=i("frontend-js-web"),s=(a=i("liferay!frontend-js-react-web$react"))&&a.__esModule?a:{default:a};class t extends s.default.Component{constructor(t){super(t),this.handleDateChange=this.handleDateChange.bind(this),this.handleTimeChange=this.handleTimeChange.bind(this)}doSchedule(t){this.setState({formError:null});let e=!1;if(this.state.date?this.isValidDate(this.state.date)||(this.setState({dateError:Liferay.Language.get("please-enter-a-valid-date")}),e=!0):(this.setState({dateError:Liferay.Language.get("this-field-is-required")}),e=!0),this.isValidTime(this.state.time)||(this.setState({timeError:Liferay.Language.get("this-field-is-required")}),e=!0),e)return;const i=this.getJSDate(this.state.date,this.state.time);if(Number.isNaN(i.getTime()))return void this.setState({validationError:Liferay.Language.get("please-enter-a-valid-date")});const a=this.getPublishDate(this.state.date,this.state.time);this.isPublishDateInTheFuture(a)?AUI().use("liferay-portlet-url",(()=>{const e=Liferay.PortletURL.createURL(t);e.setParameter("publishTime",a.getTime()),(0,r.fetch)(e.toString(),{method:"GET"}).then((t=>t.json())).then((t=>{t.redirect?(0,r.navigate)(t.redirect):t.validationError?this.setState({validationError:t.validationError}):t.error&&this.setState({formError:t.error})})).catch((t=>{this.setState({formError:t.error})}))})):this.setState({validationError:Liferay.Language.get("the-publish-time-must-be-in-the-future")})}getDateClassName(){const t="input-group-item input-group-item-shrink";return this.state.dateError||this.state.validationError?t+" has-error":t}getDateHelpText(){return this.state.validationError?s.default.createElement("div",{className:"help-block"},s.default.createElement("div",{className:"required",role:"alert"},this.state.validationError)):this.state.dateError?s.default.createElement("div",{className:"help-block"},s.default.createElement("div",{className:"required",role:"alert"},this.state.dateError)):""}getJSDate(t,e){if("string"==typeof t){const i=t.split("-");return 3===i.length?new Date(i[0]+"-"+this.pad(i[1])+"-"+this.pad(i[2])+"T"+e.hours+":"+e.minutes+":00"):new Date(t+"T"+e.hours+":"+e.minutes+":00")}return new Date(t.getFullYear()+"-"+this.pad(t.getMonth()+1)+"-"+this.pad(t.getDate())+"T"+e.hours+":"+e.minutes+":00")}getPublishDate(t,e){let i=this.getJSDate(t,e);i=new Date(Date.UTC(i.getFullYear(),i.getMonth(),i.getDate(),i.getHours(),i.getMinutes()));const a=new Date(i.toLocaleString("en-US",{timeZone:this.timeZone})),r=new Date(i.toLocaleString("en-US",{timeZone:"UTC"})).getTime()-a.getTime();return i.setTime(i.getTime()+r),i}getTimeClassName(){const t="input-group-item";return this.state.timeError||this.state.validationError?t+" has-error":t}getTimeHelpText(){return this.state.timeError?s.default.createElement("div",{className:"help-block"},s.default.createElement("div",{className:"required",role:"alert"},this.state.timeError)):""}handleDateChange(t){const e=this.isValidDate(t);!this.state.validationError||e&&!this.isPublishDateInTheFuture(this.getPublishDate(t,this.state.time))||this.setState({validationError:null}),(this.state.dateError&&!this.state.date||this.state.dateError&&e&&!this.isValidDate(this.state.date))&&this.setState({dateError:null}),this.setState({date:t})}handleTimeChange(t){!this.state.validationError||this.isValidTime(t)&&!this.isPublishDateInTheFuture(this.getPublishDate(this.state.date,t))||this.setState({validationError:null}),this.state.timeError&&this.isValidTime(t)&&!this.isValidTime(this.state.time)&&this.setState({timeError:null}),this.setState({time:t})}isPublishDateInTheFuture(t){return(new Date).getTime()<t.getTime()}isValidDate(t){if(!t)return!1;if("string"!=typeof t)return!0;if(!(t=t.trim()).match(/^[0-9][0-9][0-9][0-9]-[0-1]?[0-9]-[0-3]?[0-9]$/g))return!1;const e=t.split("-");if(3!==e.length)return!1;const i=new Date(e[0]+"-"+this.pad(e[1])+"-"+this.pad(e[2]));return!Number.isNaN(i.getTime())}isValidTime(t){return"--"!==t.hours&&"--"!==t.minutes}pad(t){let e=t;return"string"==typeof t&&(e=parseInt(t,10)),e<10?"0"+e:e.toString()}}e.ChangeTrackingBaseScheduleView=t;var n=t;e.default=n}}));
//# sourceMappingURL=ChangeTrackingBaseScheduleView.js.map