"use strict";(self.webpackChunkdotcms_ui=self.webpackChunkdotcms_ui||[]).push([[3284],{93284:(E,u,i)=>{i.r(u),i.d(u,{dot_date_time:()=>m});var _=i(15861),e=i(55956),l=i(26184),a=i(47628),d=i(50394);const r="-date",m=class{constructor(t){(0,e.r)(this,t),this.dotValueChange=(0,e.c)(this,"dotValueChange",7),this.dotStatusChange=(0,e.c)(this,"dotStatusChange",7),this._step={date:null,time:null},this._status={date:null,time:null},this.value="",this.name="",this.label="",this.hint="",this.required=!1,this.requiredMessage="This field is required",this.validationMessage="The field doesn't comply with the specified format",this.disabled=!1,this.min="",this.max="",this.step="1,1",this.dateLabel="Date",this.timeLabel="Time",this.classNames=void 0,this.errorMessageElement=void 0}reset(){var t=this;return(0,_.Z)(function*(){t._status.date=null,t._status.time=null,t.el.querySelectorAll("dot-input-calendar").forEach(s=>{s.reset()}),t.dotValueChange.emit({name:t.name,value:""})})()}componentWillLoad(){this.validateProps()}valueWatch(){this.value=(0,a.c)(this,"value","dateTime"),this._value=(0,a.d)(this.value)}minWatch(){this.min=(0,a.c)(this,"min","dateTime"),this._minDateTime=(0,a.d)(this.min)}maxWatch(){this.max=(0,a.c)(this,"max","dateTime"),this._maxDateTime=(0,a.d)(this.max)}stepWatch(){this.step=(0,a.c)(this,"step")||"1,1",[this._step.date,this._step.time]=this.step.split(",")}emitValueChange(t){const h=t.detail;t.stopImmediatePropagation(),this.formatValue(h),this.isValueComplete()&&(this.value=this.getValue(),this.dotValueChange.emit({name:this.name,value:this.value}))}emitStatusChange(t){const h=t.detail;let s;t.stopImmediatePropagation(),this.setStatus(h),this.setErrorMessageElement(h),this.isStatusComplete()&&(s=this.statusHandler(),this.classNames=(0,l.a)(s,s.dotValid,this.required),this.dotStatusChange.emit({name:this.name,status:s}))}componentDidLoad(){this.setDotAttributes()}render(){return(0,e.h)(e.H,{class:Object.assign({},this.classNames)},(0,e.h)("dot-label",{label:this.label,required:this.required,name:this.name},(0,e.h)("div",{class:"dot-date-time__body","aria-describedby":(0,l.h)(this.hint),tabIndex:this.hint?0:null},(0,e.h)("label",null,this.dateLabel,(0,e.h)("dot-input-calendar",{disabled:this.disabled,type:"date",name:this.name+r,value:this._value.date,required:this.required,min:this._minDateTime.date,max:this._maxDateTime.date,step:this._step.date})),(0,e.h)("label",null,this.timeLabel,(0,e.h)("dot-input-calendar",{disabled:this.disabled,type:"time",name:this.name+"-time",value:this._value.time,required:this.required,min:this._minDateTime.time,max:this._maxDateTime.time,step:this._step.time})))),(0,l.c)(this.hint),this.errorMessageElement)}setDotAttributes(){const t=this.el.querySelector('input[type="date"]'),h=this.el.querySelector('input[type="time"]'),s=["dottype","dotstep","dotmin","dotmax","dotvalue"];setTimeout(()=>{let n=Array.from(this.el.attributes);n.forEach(({name:g,value:v})=>{const o=g.replace(d.D,"");this[o]&&(this[o]=v)}),n=(0,d.g)(Array.from(this.el.attributes),s),(0,d.s)(t,n),(0,d.s)(h,n)},0)}validateProps(){this.minWatch(),this.maxWatch(),this.stepWatch(),this.valueWatch()}statusHandler(){return{dotTouched:this._status.date.dotTouched||this._status.time.dotTouched,dotValid:this._status.date.dotValid&&this._status.time.dotValid,dotPristine:this._status.date.dotPristine&&this._status.time.dotPristine}}formatValue(t){t.name.indexOf(r)>=0?this._value.date=t.value:this._value.time=t.value}getValue(){return this._value.date&&this._value.time?`${this._value.date} ${this._value.time}`:""}setStatus(t){t.name.indexOf(r)>=0?this._status.date=t.status:this._status.time=t.status}isValueComplete(){return!!this._value.time&&!!this._value.date}isStatusComplete(){return this._status.date&&this._status.time}isValid(){return!this.isStatusComplete()||!!this.isStatusInRange()}isStatusInRange(){return this._status.time.isValidRange&&this._status.date.isValidRange}setErrorMessageElement(t){this.errorMessageElement=this.isStatusComplete()?(0,l.b)(!this.statusHandler().dotValid&&!this.statusHandler().dotPristine,this.getErrorMessage()):(0,l.b)(!t.status.dotPristine,this.getErrorMessage())}getErrorMessage(){return this.getValue()?this.isValid()?"":this.validationMessage:this.requiredMessage}get el(){return(0,e.g)(this)}static get watchers(){return{value:["valueWatch"],min:["minWatch"],max:["maxWatch"],step:["stepWatch"]}}};m.style=".dot-date-time__body{display:flex}.dot-date-time__body label{align-items:center;display:flex;flex-grow:1;margin-right:1rem}.dot-date-time__body label:last-child{margin-right:0}.dot-date-time__body label dot-input-calendar{flex-grow:1;margin-left:0.5rem}"}}]);