"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const P=/^\d{4}-[01]\d-[0-3]\d$/;function w(s){if(!s.match(P)&&s)throw new Error("Invalid Date Format, only YYYY-MM-DD date format is allowed.")}function m(s){return!!(typeof s=="string"&&s.match(P)&&!isNaN(new Date(s).getTime()))}function o(s){if(!s)return"";const e=s.toISOString();return e.slice(0,e.indexOf("T"))}function l(s){return w(s),Number(s.slice(0,4))}function f(s){return w(s),Number(s.slice(s.indexOf("-")+1,s.lastIndexOf("-")))}function S(s){return w(s),Number(s.slice(s.lastIndexOf("-")+1))}function D(s){return s<10?`0${s}`:s.toString()}function d(s){s&&w(s);const e=new Date(s||new Date);return new Date(new Date(e.getTime()-e.getTimezoneOffset()*6e4).toISOString())}var I=Object.defineProperty,C=(s,e,t)=>e in s?I(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,N=(s,e,t)=>C(s,e+"",t);class z{constructor(){N(this,"_listeners",new Map)}on(e,t){t&&this._listeners.set(e,t)}off(e){this._listeners.delete(e)}emit(e,t){const i=this._listeners.get(e);i&&i(t)}dispose(){this._listeners=new Map}}var j=Object.defineProperty,V=(s,e,t)=>e in s?j(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,_=(s,e,t)=>V(s,typeof e!="symbol"?e+"":e,t);class R extends z{constructor(e){super(),_(this,"_state","loading"),_(this,"_locale"),_(this,"_selectedDate"),_(this,"_renderedDate"),_(this,"_days"),_(this,"_monthOffsetIndex",[0,0]),_(this,"_weekOffset"),_(this,"_dayRenderType"),_(this,"_datePickerMaxRow"),_(this,"_datePickerAutoRow"),_(this,"_delayTimeout"),_(this,"_twoSide"),_(this,"_normalized"),_(this,"_monthStep"),_(this,"_dateFormatter"),_(this,"_open",!1),_(this,"_mode"),_(this,"_isLoading",!1),this._bindAll(R.prototype);const t=o(d(e.date)),i=e.twoSide??!1,r=e.normalized??!!i,n=(e==null?void 0:e.dateFormatter)??(a=>a);this._locale=e.locale,this._dateFormatter=n,this._open=e.open??!1,this._mode=e.mode??"day",this._weekOffset=e.weekOffset||0,this._dayRenderType=e.dayRenderType||"space",this._datePickerMaxRow=e.datePickerMaxRow||6,this._datePickerAutoRow=e.datePickerAutoRow??!1,this._delayTimeout=e.delayTimeout??150,this._twoSide=i,this._normalized=r,this._monthStep=i&&r?2:1,this._selectedDate=e.date?t:"",this._renderedDate=this._calculateRenderedDate(t,r,i,n),this._days=this._calculateDays(),this.on("calculateDays",this._onCalculateDays),this.on("changeOpen",this._onChangeOpen),this.on("changeMode",this._onChangeView),this.on("changeState",this._onChangeState),this._state="rendered"}_bindAll(e){Object.getOwnPropertyNames(e).forEach(t=>{if(t!=="constructor"&&t!="_bindAll"){const i=this[t];typeof i=="function"&&(this[t]=i.bind(this))}})}getMode(){return this._mode}isLoading(){return this._isLoading}isOpen(){return this._open}getPickerState(){return this._state}onChangeDate(e){this.on("changeDate",e)}_triggerUpdate(e){if(this._selectedDate){const t=d(this._selectedDate);t.setMilliseconds(d().getMilliseconds()),this.emit(e,o(t))}else this.emit(e,o(d()))}_onCalculateDays(){this._days=this._calculateDays()}_onChangeOpen(){this._triggerUpdate("changeDate")}_onChangeView(){this._triggerUpdate("changeDate")}_onChangeState(e){this._state=e,this._isLoading=e==="loading",this._days=this._calculateDays(),this._triggerUpdate("changeDate")}_forceLoadingStart(){this._delayTimeout>0&&this.emit("changeState","loading")}_forceLoadingEnd(){this._delayTimeout>0&&setTimeout(()=>{this.emit("changeState","rendered")},this._delayTimeout)}_getPastMonth(e){let t=e;return e===1?t=12:t-=1,t}_get2PastMonth(e){return this._getPastMonth(this._getPastMonth(e))}_calculateRenderedDate(e,t,i,r,n=!1){var L,u,y,p;if(!t||!i)return e;const a=d(n?e:this._renderedDate||e),h=((u=(L=this._days)==null?void 0:L.find(g=>g.date===e))==null?void 0:u.state)==="prev",c=this._renderedDate?((p=(y=this.getDays("next"))==null?void 0:y.find(g=>g.date===e))==null?void 0:p.state)==="next":!1,M=f(r(o(a))),E=this._getLocale(l(r(o(a)))).months[this._getPastMonth(M)].numberOfDays;if(c)return e;if(h){const g=this._getLocale(l(r(o(a)))).months[this._get2PastMonth(M)].numberOfDays;a.setDate(a.getDate()-1-E-g)}else M%2===0&&a.setDate(a.getDate()-1-E);return o(a)}_getSelectedDate(){return this._dateFormatter(this._selectedDate)}_getRenderedDate(){return this._dateFormatter(this._renderedDate)}_calculateMonthOfDate(e){return f(e)}_nextMonthDate(){const e=d(this._renderedDate);return e.setMonth(e.getMonth()+1),this._dateFormatter(o(e))}_calculateDays(e,t=0){const i=e||this._renderedDate,r=S(this._dateFormatter(i)),n=S(i)-r,a=d(i);a.setDate(n+1);const h=d(o(a)),c=a.getDay(),M=l(this._dateFormatter(i)),E=this._calculateMonthOfDate(this._dateFormatter(i)),L=this._getLocale(M).months[E].numberOfDays;let u=Array(L).fill("").map((y,p)=>{const g=`${a.getFullYear()}-${D(a.getMonth()+1)}-${D(a.getDate())}`;return a.setDate(a.getDate()+1),{day:p+1,state:"current",date:g}});if(this._dayRenderType==="space")this._monthOffsetIndex[t]=c;else if(this._dayRenderType==="fill"){this._monthOffsetIndex[0]=-this._weekOffset,this._monthOffsetIndex[1]=-this._weekOffset;const y=(c+this._weekOffset)%7+this._calculateAutoRowStartLength(u.length),p=d(o(h));p.setMonth(p.getMonth()-1);const g=this._dateFormatter(o(p)),U=this._getLocale(l(g)).months[f(g)].numberOfDays;h.setDate(h.getDate()-y),u=[...Array(y).fill("").map(($,x)=>{const k=`${h.getFullYear()}-${D(h.getMonth()+1)}-${D(h.getDate())}`;return h.setDate(h.getDate()+1),{day:U-y+x+1,state:"prev",date:k}}),...u];const A=this._calculateAutoRowEndLength(u.length),Y=Array(A).fill("").map(($,x)=>{const k=`${a.getFullYear()}-${D(a.getMonth()+1)}-${D(a.getDate())}`;return a.setDate(a.getDate()+1),{day:x+1,state:"next",date:k}});u.push(...Y)}else throw new Error("can't calculate days.");return u}_calculateAutoRowEndLength(e){let t=Math.ceil(e/7);const i=this._datePickerAutoRow&&t({monthNumber:Number(e),...t}))}getYearsList(e,t){if(t<=e)throw new Error("maximum year most be greater than minimum year");return Array(t-e+1).fill("").map((i,r)=>e+r)}getDate(){if(!this._selectedDate)return"";const e=this._getSelectedDate();return`${l(e)}-${D(f(e))}-${D(S(e))}`}getSelectedDateOriginal(){return this._selectedDate}getRenderedDateOriginal(){return this._renderedDate}getRenderedMonth(){return f(this._getRenderedDate())}getRenderedMonthName(){return this._getLocale(this._getYear()).months[this._calculateMonthOfDate(this._getRenderedDate())].name}getRenderedYear(){return l(this._getRenderedDate())}getRenderedNextMonth(){return f(this._nextMonthDate())}getRenderedNextMonthName(){return this._getLocale(l(this._nextMonthDate())).months[this._calculateMonthOfDate(this._nextMonthDate())].name}getRenderedNextDateYear(){return l(this._nextMonthDate())}getDayMonthOffset(e=0){return(this._monthOffsetIndex[e]+this._weekOffset)%7}changeMonth(e,t=!0){const i=this._dateFormatter(o(d(this._renderedDate))),r=e-f(i),n=d(this._renderedDate);n.setMonth(n.getMonth()+r),this._renderedDate=this._calculateRenderedDate(o(n),this._normalized,this._twoSide,this._dateFormatter,!0),t&&(this._mode="day"),this._forceUpdate()}changeYear(e,t=!0){const i=l(this._dateFormatter(this._renderedDate))-e,r=d(this._renderedDate);r.setFullYear(l(this._renderedDate)-i),this._renderedDate=o(r),t&&(this._mode="day"),this._forceUpdate()}handleShowNextMonth(){const e=d(this._renderedDate);e.setMonth(e.getMonth()+this._monthStep),this._updateDate(o(e))}handleShowPrevMonth(){const e=d(this._renderedDate);e.setMonth(e.getMonth()-this._monthStep),this._updateDate(o(e))}handleShowNextYear(){const e=d(this._renderedDate);e.setFullYear(e.getFullYear()+1),this._updateDate(o(e))}handleShowPrevYear(){const e=d(this._renderedDate);e.setFullYear(e.getFullYear()-1),this._updateDate(o(e))}goToToday(){this._open=!0,this._forceLoadingStart();const e=o(d());this._renderedDate=e,this._selectedDate=e,this._forceLoadingEnd(),this._triggerUpdate("calculateDays"),this._triggerUpdate("changeDate")}setOpen(e){this._open!==e&&(this._open=e,this.emit("changeOpen",""))}setMode(e){e!==this._mode&&(this._mode=e,this.emit("changeMode",""))}setDate(e){w(e),this._selectedDate=e,this._forceUpdate()}}class O extends R{constructor(e){super(e),super._bindAll(O.prototype)}changeDay(e,t){if(m(e)){let i=t==="current";if(this._twoSide&&this._dayRenderType==="fill"&&this._normalized){const n=this._days.find(h=>h.date===e),a=this.getDays("next").find(h=>h.date===e);i=(n==null?void 0:n.state)==="current"||(n==null?void 0:n.state)==="next"||(a==null?void 0:a.state)==="current"||(a==null?void 0:a.state)==="prev"}this._dayRenderType==="fill"&&!i&&this._forceLoadingStart(),this._selectedDate=e;let r=e;this._normalized&&(r=this._calculateRenderedDate(e,this._normalized,this._twoSide,this._dateFormatter)),this._renderedDate=r,this._days=this._calculateDays(r),this.emit("changeDate",o(d(r))),!i&&this._dayRenderType==="fill"&&this._updateChangeDay(e)}}isSelectedDay(e){return this._selectedDate===e}_updateChangeDay(e){this._isLoading=!1,this._selectedDate=e,this._triggerUpdate("calculateDays")}}var H=Object.defineProperty,Z=(s,e,t)=>e in s?H(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,F=(s,e,t)=>Z(s,typeof e!="symbol"?e+"":e,t);class T extends R{constructor(e){super(e),F(this,"_selectedEndDate"),F(this,"_hoveredDate"),super._bindAll(T.prototype),this._selectedEndDate=e.endDate?o(d(e.endDate)):""}changeDay(e,t){if(m(e)){let i=t==="current";if(this._twoSide&&this._dayRenderType==="fill"&&this._normalized){const a=this._days.find(c=>c.date===e),h=this.getDays("next").find(c=>c.date===e);i=(a==null?void 0:a.state)==="current"||(a==null?void 0:a.state)==="next"||(h==null?void 0:h.state)==="current"||(h==null?void 0:h.state)==="prev"}this._dayRenderType==="fill"&&!i&&this._forceLoadingStart();const r=this._state;this._selectedDate&&this._selectedEndDate&&(this._selectedEndDate=void 0,this._hoveredDate=void 0),r==="rendered"||d(this._selectedDate).getTime()>d(e).getTime()?(this._selectedDate=e,this._state="selecting"):r==="selecting"&&(this._selectedEndDate=e,this._state="rendered");let n=e;this._normalized&&(n=this._calculateRenderedDate(e,this._normalized,this._twoSide,this._dateFormatter)),this._renderedDate=n,this._days=this._calculateDays(n),this.emit("changeDate",o(d(n))),!i&&this._dayRenderType==="fill"&&(this._selectedDate&&!this._selectedEndDate&&(this._selectedEndDate=e),this._updateChangeDay(e))}}isSelectedDay(e){return this._selectedDate===e||this._selectedEndDate===e}getSelectedEndDate(){return this._selectedEndDate&&this._dateFormatter(this._selectedEndDate)}getSelectedEndDateUnformatted(){return this._selectedEndDate}_updateChangeDay(e){this._isLoading=!1,this._selectedDate?this._selectedDate&&(this._selectedEndDate=e,this._state="rendered"):(this._selectedDate=e,this._state="selecting"),this._triggerUpdate("calculateDays")}getEndDate(){if(!this._selectedEndDate)return"";const e=this._dateFormatter(this._selectedEndDate);return`${l(e)}-${D(f(e))}-${D(S(e))}`}goToToday(){this._open=!0,this._forceLoadingStart();const e=o(d());this._renderedDate=e,this._selectedDate=e,this._selectedEndDate="",this._hoveredDate="",this._forceLoadingEnd(),this._triggerUpdate("calculateDays"),this._triggerUpdate("changeDate")}onCellHover(e){this._state==="selecting"&&(this._hoveredDate=e,this._selectedDate&&(this._selectedEndDate&&(this._hoveredDate=void 0,this._state="rendered"),this._triggerUpdate("changeDate")))}isDateInRange(e,t=!1,i=!0){const r=d(this._selectedDate).getTime(),n=d(this._hoveredDate||this._selectedEndDate||this._selectedDate).getTime(),a=d(e).getTime(),h=t?a>=r:a>r,c=i?a<=n:ae in s?q(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,v=(s,e,t)=>B(s,typeof e!="symbol"?e+"":e,t);class b extends R{constructor(e){super(e),v(this,"_selectedEndDate"),v(this,"_hoveredDate"),v(this,"_selectedDatesLookup"),super._bindAll(b.prototype),this._selectedEndDate=e.endDate?o(d(e.endDate)):"",this._selectedDatesLookup=e.selectedDate??this._calculateSelectedDaysLookup()}_calculateSelectedDaysLookup(){if(this._selectedDate||this._selectedEndDate){const e=new Map;return this._getDatesInRange(this._selectedDate,this._selectedEndDate||this._selectedDate).forEach(t=>{e.set(t,1)}),e}return new Map}_getDatesInRange(e,t,i=!0,r=!0){const n=[],a=d(e),h=d(t);for(i&&n.push(o(d(e)));a{i.set(r,1)}),this._selectedDatesLookup=new Map([...this._selectedDatesLookup,...i])}}deSelectInRange(e,t){if(m(e)){this._rangeSelection(e,t);const i=new Map;this._getDatesInRange(this._selectedDate,this._selectedEndDate||this._selectedDate).forEach(n=>{i.set(n,1)});const r=new Map([...this._selectedDatesLookup]);for(const[n]of i)r.has(n)&&r.delete(n);this._selectedDatesLookup=r}}isSelectedDay(e){return this._selectedDatesLookup.has(e)}_rangeSelection(e,t){let i=t==="current";if(this._twoSide&&this._dayRenderType==="fill"&&this._normalized){const a=this._days.find(c=>c.date===e),h=this.getDays("next").find(c=>c.date===e);i=(a==null?void 0:a.state)==="current"||(a==null?void 0:a.state)==="next"||(h==null?void 0:h.state)==="current"||(h==null?void 0:h.state)==="prev"}this._dayRenderType==="fill"&&!i&&this._forceLoadingStart();const r=this._state;(this._selectedDate||this._selectedEndDate)&&(this._selectedEndDate=void 0,this._hoveredDate=void 0),r==="rendered"||d(this._selectedDate).getTime()>d(e).getTime()?(this._selectedDate=e,this._state="selecting"):r==="selecting"&&(this._selectedEndDate=e,this._state="rendered");let n=e;this._normalized&&(n=this._calculateRenderedDate(e,this._normalized,this._twoSide,this._dateFormatter)),this._renderedDate=n,this._days=this._calculateDays(n),this.emit("changeDate",o(d(n))),!i&&this._dayRenderType==="fill"&&(this._selectedDate&&!this._selectedEndDate&&(this._selectedEndDate=e),this._updateChangeDay(e))}_updateChangeDay(e){this._isLoading=!1,this._selectedDate?this._selectedDate&&(this._selectedEndDate=e,this._state="rendered"):(this._selectedDate=e,this._state="selecting"),this._triggerUpdate("calculateDays")}getEndDate(){if(!this._selectedEndDate)return"";const e=this._dateFormatter(this._selectedEndDate);return`${l(e)}-${D(f(e))}-${D(S(e))}`}goToToday(){this._open=!0,this._forceLoadingStart();const e=o(d());this._renderedDate=e,this._selectedDate=e,this._selectedEndDate="",this._hoveredDate="",this._forceLoadingEnd(),this._triggerUpdate("calculateDays"),this._triggerUpdate("changeDate")}onCellHover(e){this._state==="selecting"&&(this._hoveredDate=e,this._selectedDate&&(this._selectedEndDate&&(this._hoveredDate=void 0,this._state="rendered"),this._triggerUpdate("changeDate")))}isDateInRange(e,t=!1,i=!0){const r=d(this._selectedDate).getTime(),n=d(this._hoveredDate||this._selectedEndDate||this._selectedDate).getTime(),a=d(e).getTime(),h=t?a>=r:a>r,c=i?a<=n:a