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