@telsho/react-google-flight-datepicker 1.1.3 → 1.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,2 +1,1394 @@
1
- "use strict";var Mt=Object.create;var Ge=Object.defineProperty,zt=Object.defineProperties,Lt=Object.getOwnPropertyDescriptor,Et=Object.getOwnPropertyDescriptors,St=Object.getOwnPropertyNames,Be=Object.getOwnPropertySymbols,Pt=Object.getPrototypeOf,je=Object.prototype.hasOwnProperty,ct=Object.prototype.propertyIsEnumerable;var ot=(e,t,o)=>t in e?Ge(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,v=(e,t)=>{for(var o in t||(t={}))je.call(t,o)&&ot(e,o,t[o]);if(Be)for(var o of Be(t))ct.call(t,o)&&ot(e,o,t[o]);return e},w=(e,t)=>zt(e,Et(t));var He=(e,t)=>{var o={};for(var a in e)je.call(e,a)&&t.indexOf(a)<0&&(o[a]=e[a]);if(e!=null&&Be)for(var a of Be(e))t.indexOf(a)<0&&ct.call(e,a)&&(o[a]=e[a]);return o};var Kt=(e,t)=>{for(var o in t)Ge(e,o,{get:t[o],enumerable:!0})},at=(e,t,o,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of St(t))!je.call(e,i)&&i!==o&&Ge(e,i,{get:()=>t[i],enumerable:!(a=Lt(t,i))||a.enumerable});return e};var F=(e,t,o)=>(o=e!=null?Mt(Pt(e)):{},at(t||!e||!e.__esModule?Ge(o,"default",{value:e,enumerable:!0}):o,e)),$t=e=>at(Ge({},"__esModule",{value:!0}),e);var lo={};Kt(lo,{RangeDatePicker:()=>Ot,SingleDatePicker:()=>Ut});module.exports=$t(lo);var b=require("react"),M=F(require("dayjs")),Zt=F(require("classnames")),Rt=F(require("dayjs/plugin/localeData"));var gt=F(require("dayjs"));function Fe(e,t,o){let a=[],i=new Date(e,t,1),d=new Date(e,t+1,0).getDate(),A=1,g=i.getDay()===0?1:7-i.getDay()+1;for(o==="sunday"&&(g=7-i.getDay());A<=d;)a.push({start:A,days:g-A+1}),A=g+1,g+=7,g=A===1&&g===8?1:g,g>d&&(g=d);return{totalWeek:a,totalDay:d}}function Qe(e,t){let o=[...Array(7)].map((a,i)=>(0,gt.default)().day(i).format(t==="dd"?"dd":t==="ddd"?"ddd":"dddd"));if(e==="sunday"){let a=o.pop();a&&o.unshift(a)}return o}function it(e,t){let o;return function(...i){let r=()=>{o=null,e.apply(this,i)};o&&clearTimeout(o),o=setTimeout(r,t)}}var k=require("react"),Ze=F(require("dayjs"));var pe=require("react/jsx-runtime"),lt=(0,k.createContext)(null),rt=(0,k.createContext)(null),nt=(0,k.createContext)(null),dt=(0,k.createContext)(null),_t=(0,k.createContext)(null),T=()=>{let e=(0,k.useContext)(lt);if(!e)throw new Error("useDateState must be used within DatePickerProvider");return e},N=()=>{let e=(0,k.useContext)(rt);if(!e)throw new Error("useDatePickerConfig must be used within DatePickerProvider");return e},xe=()=>{let e=(0,k.useContext)(nt);if(!e)throw new Error("useUIState must be used within DatePickerProvider");return e},Y=()=>{let e=(0,k.useContext)(dt);if(!e)throw new Error("useDisplayCustomization must be used within DatePickerProvider");return e};var qt=async e=>{if(e==="en")return!0;try{return await import(`dayjs/locale/${e}.js`),!0}catch(t){return console.error(`Failed to load locale ${e}:`,t),!1}},It=({children:e,dateState:t,config:o,uiState:a,display:i,locale:r="en"})=>{let[d,A]=(0,k.useState)({currentLocale:"en",isLocaleReady:r==="en"});return(0,k.useEffect)(()=>{r!=="en"?(A(g=>w(v({},g),{isLocaleReady:!1})),qt(r).then(g=>{g?(Ze.default.locale(r),A({currentLocale:r,isLocaleReady:!0})):(Ze.default.locale("en"),A({currentLocale:"en",isLocaleReady:!0}))})):(Ze.default.locale("en"),A({currentLocale:"en",isLocaleReady:!0}))},[r]),d.isLocaleReady?(0,pe.jsx)(_t.Provider,{value:d,children:(0,pe.jsx)(lt.Provider,{value:t,children:(0,pe.jsx)(rt.Provider,{value:o,children:(0,pe.jsx)(nt.Provider,{value:a,children:(0,pe.jsx)(dt.Provider,{value:i,children:e})})})})}):null};var mo=require("react");var Me=require("react/jsx-runtime"),eo=e=>(0,Me.jsx)("svg",w(v({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},e),{children:(0,Me.jsx)("path",{d:"M9 11H7v2h2v-2zm4 0h-2v2h2v-2zm4 0h-2v2h2v-2zm2-7h-1V2h-2v2H8V2H6v2H5c-1.11 0-1.99.9-1.99 2L3 20a2 2 0 002 2h14c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2zm0 16H5V9h14v11z"})})),Re=eo;var me=require("react"),st=F(require("classnames")),ke=F(require("dayjs"));var Xo=require("react");var ze=require("react/jsx-runtime"),to=e=>(0,ze.jsx)("svg",w(v({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},e),{children:(0,ze.jsx)("path",{d:"M15.41 16.59L10.83 12l4.58-4.59L14 6l-6 6 6 6 1.41-1.41z"})})),Oe=to;var Ho=require("react");var Le=require("react/jsx-runtime"),oo=e=>(0,Le.jsx)("svg",w(v({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},e),{children:(0,Le.jsx)("path",{d:"M8.59 16.59L13.17 12 8.59 7.41 10 6l6 6-6 6-1.41-1.41z"})})),Ue=oo;var L=require("react/jsx-runtime"),Ee=({type:e,showIcon:t=!1,tabIndex:o=0,nonFocusable:a=!1})=>{let[i,r]=(0,me.useState)(null),[d,A]=(0,me.useState)(!1),[g,s]=(0,me.useState)(!1),{fromDate:n,toDate:m,inputFocus:D,handleClickDateInput:Q,handleChangeDate:f}=T(),{isSingle:B,minDate:X,maxDate:h,dateFormat:c}=N(),{startDatePlaceholder:y,endDatePlaceholder:C}=Y(),G=e==="from"?n:m,P=e==="from"?y:C;(0,me.useEffect)(()=>{if(G){let U=G.clone().locale(ke.default.locale()).format("ddd, DD MMM");c&&(U=G.format(c)),r(U);let O=X?(0,ke.default)(X):null,Z=h?(0,ke.default)(h):null;O!=null&&O.add(1,"day").isAfter(G,"date")||e==="to"&&n&&G.isBefore(n.add(1,"day"),"date")?A(!0):A(!1),Z!=null&&Z.subtract(1,"day").isBefore(G,"date")?s(!0):s(!1)}else r(null)},[G,n,X,h,c,e]);let z=V=>{V.stopPropagation(),G&&f(G.subtract(1,"day"),e)},oe=V=>{V.stopPropagation(),G&&f(G.add(1,"day"),e)},p=()=>{Q(e)};return(0,L.jsxs)("div",{className:(0,st.default)("date",{"is-focus":D===e&&!B,"is-single":B}),role:"button",tabIndex:a?-1:o,onClick:p,id:`${e}-date-input-button`,children:[t&&(0,L.jsx)(Re,{className:"icon-calendar",viewBox:"0 0 24 24"}),(0,L.jsx)("div",{className:"selected-date",children:i!=null?i:(0,L.jsx)("div",{className:"date-placeholder",children:P})}),i&&(0,L.jsxs)("div",{className:"change-date-group",children:[(0,L.jsx)("button",{type:"button",className:"btn-outline change-date-button",onClick:z,tabIndex:a?-1:0,disabled:d,children:(0,L.jsx)(Oe,{viewBox:"0 0 24 24",className:"icon-arrow"})}),(0,L.jsx)("button",{type:"button",className:"btn-outline change-date-button",onClick:oe,tabIndex:a?-1:0,disabled:g,children:(0,L.jsx)(Ue,{viewBox:"0 0 24 24",className:"icon-arrow"})})]})]})};var ie=require("react/jsx-runtime"),Je=({showIcon:e=!1,nonFocusable:t=!1})=>{let{isSingle:o}=N(),{dateInputSeperator:a}=Y();return(0,ie.jsxs)("div",{className:"date-picker-input",children:[e&&(0,ie.jsx)(Re,{className:"icon-calendar mobile",viewBox:"0 0 24 24"}),(0,ie.jsxs)("div",{className:"date-picker-date-group",children:[(0,ie.jsx)(Ee,{type:"from",tabIndex:t?-1:0,showIcon:!0,nonFocusable:t}),!o&&a&&(0,ie.jsx)("div",{className:"date-input-separator",children:a}),!o&&(0,ie.jsx)(Ee,{type:"to",tabIndex:t?-1:0,showIcon:!1,nonFocusable:t})]})]})};var At=require("react-dom");var ve=require("react"),Ct=()=>{let[e,t]=(0,ve.useState)(!1);return(0,ve.useEffect)(()=>{t(!0)},[]),e};var bt=require("react/jsx-runtime"),co=({children:e=null,isMobile:t=!1})=>Ct()?t?(0,At.createPortal)((0,bt.jsx)("div",{children:e}),document.body):e:null,ut=co;var Ae=require("react"),Ft=F(require("classnames"));var So=require("react");var Se=require("react/jsx-runtime"),ao=e=>(0,Se.jsx)("svg",w(v({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 492 492"},e),{children:(0,Se.jsx)("path",{d:"M464.3 207.4l.8.2H136l103.5-103.7c5-5.1 7.8-12 7.8-19.2 0-7.2-2.7-14-7.8-19l-16.1-16.2c-5-5-11.8-7.8-19-7.8-7.2 0-14 2.8-19 7.8L7.8 227C2.8 232 0 238.8 0 246c0 7.3 2.8 14 7.8 19.2l177.5 177.4c5 5 11.8 7.8 19 7.8 7.2 0 14-2.8 19-7.8l16-16.1a26.6 26.6 0 000-37.7L134.8 284.4h330a27.9 27.9 0 0027.3-27.6V234a27.3 27.3 0 00-27.7-26.6z"})})),pt=ao;var te=F(require("react")),E=F(require("dayjs")),Dt=require("react-window"),ht=F(require("react-virtualized-auto-sizer"));var yt=require("react"),Gt=F(require("classnames")),Xt=F(require("dayjs"));var xt=require("react"),mt=F(require("classnames")),ft=F(require("dayjs"));var ee=require("react"),Pe=F(require("classnames"));var Ce=require("react/jsx-runtime"),Ke=(0,ee.forwardRef)(({dateIndex:e,dateValue:t,isEndDay:o,selected:a,hovered:i,disabled:r,totalDay:d,highlight:A,handleHoverDay:g,subText:s},n)=>{let m=(0,ee.useRef)(null),{onSelectDate:D,onHoverDate:Q}=T(),f=c=>{c.stopPropagation(),c.preventDefault(),!r&&D(t)},B=()=>{r||(Q(t),g(t))},X=(0,ee.useCallback)(()=>{if(!n||typeof n=="function")return;let c=n.current;c&&m.current&&(c.style.left=`${m.current.offsetLeft-c.offsetWidth+135}px`,c.style.top=`${m.current.offsetTop-c.offsetHeight-15}px`,c.style.visibility="visible")},[n]),h=(0,ee.useCallback)(()=>{if(!n||typeof n=="function")return;let c=n.current;c&&(c.style.visibility="hidden")},[n]);return(0,ee.useEffect)(()=>{let c=m.current;return c&&(c.addEventListener("mouseover",X),c.addEventListener("mouseleave",h)),()=>{c&&(c.removeEventListener("mouseover",X),c.removeEventListener("mouseleave",h))}},[X,h]),(0,Ce.jsxs)("div",{className:(0,Pe.default)("day",{selected:a,hovered:i,disabled:r,highlight:A,end:o,"has-subtext":!!s}),onClick:f,onMouseEnter:B,role:"button",tabIndex:-1,"data-day-index":e,"data-date-value":t.valueOf(),ref:m,children:[i&&!(o&&e===d)&&!(e===1&&a&&!o)&&(0,Ce.jsx)("div",{className:(0,Pe.default)("background-day",{"first-day":e===1,"last-day":e===d})}),(0,Ce.jsxs)("div",{className:"day-content",children:[(0,Ce.jsx)("div",{className:"text-day",children:e}),s&&(0,Ce.jsx)("div",{className:"sub-text",style:{position:"relative",zIndex:3,color:a&&!i?"#fff":"#666"},children:s})]})]})});Ke.displayName="Day";var $e=require("react/jsx-runtime"),_e=(0,xt.forwardRef)(({isFirst:e,week:t,month:o,year:a,totalDay:i,weekIndex:r,handleHoverDay:d},A)=>{let{fromDate:g,toDate:s,hoverDate:n}=T(),{minDate:m,maxDate:D,isSingle:Q,highlightToday:f}=N(),{subTextDict:B}=Y(),X=()=>Array.from({length:t.days},(h,c)=>{var U;let y=c+t.start,C=(0,ft.default)(`${a}-${o+1}-${y}`),G=m&&C.isBefore(m,"date")||D&&C.isAfter(D,"date"),P=g&&C.isSame(g,"date")||s&&C.isSame(s,"date"),z=!1,oe=f&&C.isSame(new Date,"date");g&&!g.isSame(s,"date")&&!Q&&(s&&!g.isAfter(C,"date")&&!s.isBefore(C,"date")&&(z=!0),!s&&!C.isBefore(g,"date")&&!(n&&n.isBefore(C,"date"))&&g.isBefore(n,"date")&&(z=!0));let p=s&&C.isSame(s,"date")||!s&&n&&C.isSame(n,"date"),V=B?(U=B[C.format("YYYY-MM-DD")])!=null?U:"\xA0":"";return(0,$e.jsx)(Ke,{dateIndex:y,dateValue:C,selected:P,hovered:z,highlight:oe,disabled:G,isEndDay:p,totalDay:i,handleHoverDay:d,subText:V,ref:A},c)});return(0,$e.jsx)("div",{className:(0,mt.default)("week",{first:e}),children:X()})});_e.displayName="Week";var le=require("react/jsx-runtime"),Xe=(0,yt.forwardRef)(({month:e,year:t,hidden:o=!1,isAnimating:a=!1,handleHoverDay:i,className:r},d)=>{let{startWeekDay:A,weekDayFormat:g,monthFormat:s,singleCalendar:n}=N(),m=()=>{let{totalWeek:f,totalDay:B}=Fe(t,e,A);return f.map(X=>{let h=`${t}-${e}-${X.start}`;return(0,le.jsx)(_e,{week:X,month:e,year:t,isFirst:X===f[0],totalDay:B,weekIndex:f.indexOf(X),handleHoverDay:i,ref:d},h)})},D=()=>Qe(A,g).map(B=>(0,le.jsx)("div",{className:"weekday",children:B},`weekday-${B.toLowerCase()}`)),Q=()=>{let f=(0,Xt.default)(`${t}-${e+1}-1`);return s?f.format(s):f.format("MMMM - YYYY")};return(0,le.jsxs)("div",{className:(0,Gt.default)("month-calendar",{isAnimating:a,hidden:o,single:n},r),"data-month-index":e+1,children:[(0,le.jsx)("div",{className:"month-name",children:Q()}),(0,le.jsx)("div",{className:"weekdays",children:D()}),(0,le.jsx)("div",{className:"week-container",children:m()})]})});Xe.displayName="MonthCalendar";var S=require("react/jsx-runtime"),Bt=()=>{let[e,t]=(0,te.useState)(2400),o=(0,te.useRef)(null),{fromDate:a}=T(),{startWeekDay:i,minDate:r,maxDate:d,weekDayFormat:A}=N(),{complsOpen:g}=xe(),{tooltip:s,subTextDict:n}=Y(),m=r?(0,E.default)(r).year():1900,D=r?(0,E.default)(r).month():0;(0,te.useEffect)(()=>{if(d){let c=r?(0,E.default)(r):(0,E.default)("1900-01-01");t((0,E.default)(d).diff(c,"month")+1)}},[d,r]),(0,te.useEffect)(()=>{if(o.current&&g){let c=a?(0,E.default)(a):(0,E.default)(),y=c.diff((0,E.default)("1900-01-01"),"month");r&&(y=c.diff((0,E.default)(r),"month")),o.current.scrollToItem(y+1,"smart")}},[g,a,r]);let Q=c=>{let y=c+D,C=m+Math.floor(y/12),G=y%12;return{year:C,month:G}},f=te.default.memo(({index:c,style:y})=>{let{year:C,month:G}=Q(c);return(0,S.jsx)("div",{style:y,children:(0,S.jsx)(Xe,{month:G,year:C,hidden:!1,isAnimating:!1,handleHoverDay:()=>{}})})});f.displayName="CalendarRow";let B=c=>{let{year:y,month:C}=Q(c),{totalWeek:G}=Fe(y,C,i||"monday");return G.length*48+34},X=()=>(0,S.jsx)(ht.default,{children:({height:c,width:y})=>(0,S.jsx)(Dt.VariableSizeList,{ref:o,width:y,height:c-36,itemCount:e,itemSize:B,children:f})});return(0,S.jsx)("div",{className:"calendar-wrapper",children:(0,S.jsxs)("div",{className:"calendar-content",children:[(0,S.jsx)("div",{className:"weekdays mobile",children:Qe(i||"monday",A).map((y,C)=>(0,S.jsx)("div",{className:"weekday",children:y},C))}),X()]})})};var u=require("react"),fe=F(require("classnames")),De=F(require("dayjs"));var j=require("react/jsx-runtime"),go=()=>{let[e,t]=(0,u.useState)(!1);return(0,u.useEffect)(()=>{t(!0)},[]),e},Ht=({dateChanged:e=null})=>{let t=go(),o=(0,u.useRef)(null),a=(0,u.useRef)(null),[i,r]=(0,u.useState)(0),[d,A]=(0,u.useState)([]),[g,s]=(0,u.useState)(null),[n,m]=(0,u.useState)(!1),[D,Q]=(0,u.useState)(!1),[f,B]=(0,u.useState)(0),[X,h]=(0,u.useState)(null),[c,y]=(0,u.useState)(!1),{fromDate:C}=T(),{minDate:G,maxDate:P,singleCalendar:z}=N(),{complsOpen:oe}=xe(),{tooltip:p}=Y(),V=(0,u.useCallback)(I=>[I.subtract(1,"month"),I,I.add(1,"month"),I.add(2,"month")],[]);(0,u.useEffect)(()=>{if(!t||!o.current)return;let I=()=>{let J=o.current.offsetWidth,R=window.getComputedStyle(o.current),$=z?J+parseInt(R.marginLeft)-8:J/2;B($)};I();let x=new ResizeObserver(I);return x.observe(o.current),()=>x.disconnect()},[t,z]),(0,u.useEffect)(()=>{s(C!=null?C:(0,De.default)())},[oe,C]),(0,u.useEffect)(()=>{if(!g)return;let I=G?(0,De.default)(G):null,x=P?(0,De.default)(P):null;m(!!(I&&g.isBefore(I.add(1,"month"),"month"))),Q(!!(x&&g.isAfter(x.subtract(2,"month"),"month"))),A(V(g))},[g,G,P,V]),(0,u.useEffect)(()=>{if(!e||!g)return;let I=e.diff(g,"month");I<-1&&Z(),I>1&&O()},[e,g]);let U=(0,u.useCallback)(I=>()=>{if(I==="next"&&D||I==="prev"&&n||c)return;y(!0),r(I==="next"?-f:f);let x=setTimeout(()=>{s(J=>{let R=I==="next"?J.add(1,"month"):J.subtract(1,"month");return A(V(R)),R}),r(0),y(!1)},200);return()=>clearTimeout(x)},[D,n,c,f,V]),[O,Z]=(0,u.useMemo)(()=>[U("next"),U("prev")],[U]),ce=(0,u.useCallback)(()=>{if(!t||!o.current)return;let x=o.current.querySelector(".day.selected, .month-calendar:not(.hidden) .day:not(.disabled)");x==null||x.focus()},[t]),ne=(0,u.useCallback)(I=>{var Ie,ue;let x=I.target,J=x.getAttribute("data-day-index");if(!J)return;I.preventDefault();let R=x.closest(".calendar-wrapper"),$=parseInt((Ie=x.dataset.dateValue)!=null?Ie:"0"),de=(0,De.default)($),Ye=de.endOf("month").date(),_=parseInt(J);switch(I.key){case"ArrowLeft":_--;break;case"ArrowUp":_-=7;break;case"ArrowRight":_++;break;case"ArrowDown":_+=7;break;case" ":x.click();return;default:return}if(_>0&&_<=Ye)(ue=R==null?void 0:R.querySelector(`[data-day-index="${_}"]`))==null||ue.focus();else{let q=de.add(_-parseInt(J),"day"),ae=q.diff(g,"month");ae>1&&!D&&O(),ae<0&&!n&&Z(),setTimeout(()=>{var se;(se=R==null?void 0:R.querySelector(`[data-month-index="${q.month()+1}"] [data-day-index="${q.date()}"]`))==null||se.focus()},200)}},[g,D,n,O,Z]),Te=(0,u.useMemo)(()=>{var x;if(!p||!t)return null;let I=typeof p=="function"?p((x=X==null?void 0:X.toDate())!=null?x:new Date):p;return(0,j.jsx)("div",{id:"day-tooltip",className:"tooltip-text",ref:a,children:I})},[p,X,t]),K=(0,u.useMemo)(()=>d.map((I,x)=>{let J=x===1||x===2,R=c&&i<0&&x===3,$=c&&i>0&&x===0;return(0,j.jsx)(Xe,{hidden:!J&&!R&&!$,isAnimating:R||$,month:I.month(),year:I.year(),handleHoverDay:h,ref:a,className:(0,fe.default)({"slide-next":R,"slide-prev":$})},`${I.year()}-${I.month()}`)}),[d,c,i]);return(0,j.jsxs)("div",{className:"relative",children:[Te,(0,j.jsxs)("div",{className:(0,fe.default)("calendar-wrapper",{single:z}),ref:o,onKeyDown:ne,role:"grid","aria-label":"Calendar",children:[(0,j.jsx)("div",{className:(0,fe.default)("calendar-content",{isAnimating:c}),style:{transform:`translateX(${i}px)`},children:K}),(0,j.jsxs)("div",{className:"calendar-flippers",children:[(0,j.jsx)("button",{className:(0,fe.default)("flipper-button",{disabled:n}),onClick:Z,onKeyDown:I=>I.key===" "&&Z(),disabled:n,"aria-label":"Previous month",children:(0,j.jsx)(Oe,{viewBox:"0 0 24 24"})}),(0,j.jsx)("button",{className:(0,fe.default)("flipper-button",{disabled:D}),onClick:O,onKeyDown:I=>I.key===" "&&O(),disabled:D,"aria-label":"Next month",onBlur:ce,children:(0,j.jsx)(Ue,{viewBox:"0 0 24 24"})})]})]})]})};var W=require("react/jsx-runtime"),Qt=({containerRef:e})=>{let[t,o]=(0,Ae.useState)(!1),[a,i]=(0,Ae.useState)(null),r=(0,Ae.useRef)(null),d=e||r,{handleChangeDate:A,handleReset:g}=T(),{singleCalendar:s,expandDirection:n}=N(),{complsOpen:m,isMobile:D,toggleDialog:Q}=xe(),{hideDialogHeader:f,hideDialogFooter:B}=Y(),X=(h,c)=>{i(h),A(h,c)};return(0,Ae.useEffect)(()=>{m&&!t&&o(!0),m&&setTimeout(()=>{var c;let h=(c=d.current)==null?void 0:c.querySelector("#start-date-input-button");h&&h.focus()},50)},[m,d,t]),(0,W.jsxs)("div",{className:(0,Ft.default)("dialog-date-picker",{open:m,hide:!m&&t,single:s&&!D,"expand-left":n==="left","expand-right":n==="right"}),ref:d,children:[!f&&(0,W.jsxs)("div",{className:"dialog-header",children:[(0,W.jsx)("button",{type:"button",className:"btn-outline back-button",onClick:Q,children:(0,W.jsx)(pt,{viewBox:"0 0 492 492"})}),(0,W.jsx)(Je,{showIcon:!0,nonFocusable:!m}),(0,W.jsx)("button",{type:"button",className:"btn-outline reset-button",onClick:g,children:"Reset"})]}),(0,W.jsx)("div",{className:"dialog-content",children:D?(0,W.jsx)(Bt,{}):(0,W.jsx)(Ht,{dateChanged:a})}),!B&&(0,W.jsxs)("div",{className:"dialog-footer",children:[(0,W.jsx)("button",{type:"button",className:"submit-button",onClick:Q,tabIndex:0,children:"Done"}),(0,W.jsx)("button",{type:"button",className:"btn-outline reset-button mobile",onClick:g,children:"Reset"})]})]})};var re=require("react/jsx-runtime");M.default.extend(Rt.default);var io=({startDate:e=null,endDate:t=null,className:o="",disabled:a=!1,startDatePlaceholder:i,endDatePlaceholder:r,onChange:d,onFocus:A=()=>{},startWeekDay:g="monday",minDate:s=null,maxDate:n=null,weekDayFormat:m="dd",dateFormat:D="",monthFormat:Q="",highlightToday:f=!1,dateInputSeperator:B=null,hideDialogHeader:X=!1,hideDialogFooter:h=!1,hideDialogAfterSelectEndDate:c=!1,isOpen:y=!1,onCloseCalendar:C,tooltip:G="",subTextDict:P=null,expandDirection:z="right",locale:oe="en",isSingle:p=!1,singleCalendar:V=!1})=>{let[U,O]=(0,b.useState)(y),[Z,ce]=(0,b.useState)(p?"from":null),[ne,Te]=(0,b.useState)(e?(0,M.default)(e):void 0),[K,I]=(0,b.useState)(t?(0,M.default)(t):void 0),[x,J]=(0,b.useState)(),[R,$]=(0,b.useState)(!1),[de,Ye]=(0,b.useState)(!1),Ie=(()=>{let[l,H]=(0,b.useState)(!1);return(0,b.useEffect)(()=>{H(!0)},[]),l})(),ue=(0,b.useRef)(null),q=(0,b.useRef)(null),ae=(0,b.useRef)(null),se=(0,b.useCallback)(()=>{Ie&&$(window.innerWidth<768)},[Ie]),tt=it(()=>{let l=q.current?q.current.toDate():null,H=!p&&ae.current?ae.current.toDate():null;p?d(l,null):d(l,H)},20),ye=(l,H=!1)=>{Te(l||void 0),q.current=l||null,H&&tt()},be=(l,H=!1)=>{p||(I(l||void 0),ae.current=l||null,H&&tt())};(0,b.useLayoutEffect)(()=>{if(Ie)return se(),window.addEventListener("resize",se),()=>window.removeEventListener("resize",se)},[Ie,se]),(0,b.useEffect)(()=>{Ye(!0);let l=H=>{ue.current&&H.target instanceof Node&&!ue.current.contains(H.target)&&window.innerWidth>=768&&O(!1)};return document.addEventListener("click",l),()=>document.removeEventListener("click",l)},[]),(0,b.useEffect)(()=>{let l=e?(0,M.default)(e):null;q.current=l,ye(l,!1)},[e]),(0,b.useEffect)(()=>{if(!p){let l=t?(0,M.default)(t):null;ae.current=l,be(l,!1)}},[t,p]),(0,b.useEffect)(()=>{var l,H;if(!U&&de){let ge=((l=q.current)==null?void 0:l.toDate())||null,he=((H=ae.current)==null?void 0:H.toDate())||null;p?C(ge,null):C(ge,he)}},[U,de,p,C]),(0,b.useEffect)(()=>{O(y)},[y]),(0,b.useEffect)(()=>{de&&A(Z==="from"?"Start Date":Z==="to"?"End Date":"")},[Z,de,A]);let kt=()=>{O(!U)},Jt=l=>{a||!p&&l==="to"&&!ne||(U||O(!0),ce(l))},vt=(0,b.useCallback)(l=>{let H=s?(0,M.default)(s):null,ge=n?(0,M.default)(n):null;H&&H.isAfter(l,"date")||ge&&ge.isBefore(l,"date")||(p?(ye(l,!0),c&&setTimeout(()=>O(!1),50)):Z==="from"||ne&&l.isBefore(ne,"date")?(ye(l,!0),K&&l.isAfter(K,"date")&&be(null,!0),ce("to")):(be(l,!0),ce(null),c&&setTimeout(()=>O(!1),50)))},[s,n,p,c,Z,ne,K]),wt=l=>{J(l)},Nt=()=>{J(void 0),ye(null,!0),p||be(null,!0),ce("from")},Wt=(0,b.useCallback)((l,H)=>{let ge=s?(0,M.default)(s):null,he=n?(0,M.default)(n):null;ge&&ge.isAfter(l,"date")||he&&he.isBefore(l,"date")||(H==="from"||p?(ce("from"),ye(l,!0),!p&&K&&l.isAfter(K,"date")&&be(null,!0)):(ce("to"),be(l,!0)))},[s,n,p,K,Z]),Vt={fromDate:ne,toDate:K,hoverDate:x,inputFocus:Z,onSelectDate:vt,onHoverDate:wt,handleChangeDate:Wt,handleReset:Nt,handleClickDateInput:Jt},Tt={isSingle:p,startWeekDay:g,minDate:s?(0,M.default)(s).toDate():null,maxDate:n?(0,M.default)(n).toDate():null,weekDayFormat:m,dateFormat:D,monthFormat:Q,highlightToday:f,singleCalendar:V,expandDirection:z,locale:oe},Yt={complsOpen:U,isMobile:R,disabled:a,toggleDialog:kt},jt={startDatePlaceholder:i,endDatePlaceholder:r,dateInputSeperator:B,hideDialogHeader:X,hideDialogFooter:h,hideDialogAfterSelectEndDate:c,tooltip:G,subTextDict:P};return(0,re.jsx)("div",{className:"react-google-flight-datepicker",children:(0,re.jsx)("div",{className:(0,Zt.default)("date-picker",o,{disabled:a}),ref:ue,children:(0,re.jsxs)(It,{dateState:Vt,config:Tt,uiState:Yt,display:jt,locale:oe,children:[(0,re.jsx)(Je,{}),(0,re.jsx)(ut,{children:(0,re.jsx)(Qt,{})})]})})})},we=io;var Ne=require("react"),Ve=require("react/jsx-runtime"),We=({children:e})=>{let[t,o]=(0,Ne.useState)(!1);return(0,Ne.useEffect)(()=>{o(!0)},[]),t?(0,Ve.jsx)(Ve.Fragment,{children:e}):null};var qe=require("react/jsx-runtime"),Ot=r=>{var d=r,{onChange:e=()=>{},onCloseCalendar:t=()=>{},startDatePlaceholder:o="Start date",endDatePlaceholder:a="End date"}=d,i=He(d,["onChange","onCloseCalendar","startDatePlaceholder","endDatePlaceholder"]);return(0,qe.jsx)(We,{children:(0,qe.jsx)(we,w(v({},i),{isSingle:!1,startDate:i.startDate,endDate:i.endDate,startDatePlaceholder:o,endDatePlaceholder:a,onChange:e,onCloseCalendar:t}))})};var et=require("react/jsx-runtime"),Ut=i=>{var r=i,{onChange:e=()=>{},onCloseCalendar:t=()=>{},startDatePlaceholder:o="Date"}=r,a=He(r,["onChange","onCloseCalendar","startDatePlaceholder"]);return(0,et.jsx)(We,{children:(0,et.jsx)(we,w(v({},a),{endDate:null,isSingle:!0,startDate:a.startDate,startDatePlaceholder:o,onChange:d=>e(d),onCloseCalendar:d=>t(d)}))})};
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/lib/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ RangeDatePicker: () => RangeDatePicker,
34
+ SingleDatePicker: () => SingleDatePicker
35
+ });
36
+ module.exports = __toCommonJS(index_exports);
37
+
38
+ // src/lib/components/DatePicker/BaseDatePicker.tsx
39
+ var import_react10 = require("react");
40
+ var import_dayjs8 = __toESM(require("dayjs"));
41
+ var import_classnames7 = __toESM(require("classnames"));
42
+ var import_localeData = __toESM(require("dayjs/plugin/localeData"));
43
+
44
+ // src/lib/helpers/index.ts
45
+ var import_dayjs = __toESM(require("dayjs"));
46
+ function getMonthInfo(year, month, startDay) {
47
+ const weeks = [];
48
+ const firstDate = new Date(year, month, 1);
49
+ const lastDate = new Date(year, month + 1, 0);
50
+ const numDays = lastDate.getDate();
51
+ let start = 1;
52
+ let end = firstDate.getDay() === 0 ? 1 : 7 - firstDate.getDay() + 1;
53
+ if (startDay === "sunday") {
54
+ end = 7 - firstDate.getDay();
55
+ }
56
+ while (start <= numDays) {
57
+ weeks.push({ start, days: end - start + 1 });
58
+ start = end + 1;
59
+ end += 7;
60
+ end = start === 1 && end === 8 ? 1 : end;
61
+ if (end > numDays) {
62
+ end = numDays;
63
+ }
64
+ }
65
+ return { totalWeek: weeks, totalDay: numDays };
66
+ }
67
+ function getWeekDay(startWeekDay, weekDayFormat) {
68
+ const days = [...Array(7)].map(
69
+ (_, i) => (0, import_dayjs.default)().day(i).format(weekDayFormat === "dd" ? "dd" : weekDayFormat === "ddd" ? "ddd" : "dddd")
70
+ );
71
+ if (startWeekDay === "sunday") {
72
+ const last = days.pop();
73
+ if (last) {
74
+ days.unshift(last);
75
+ }
76
+ }
77
+ return days;
78
+ }
79
+ function debounce(func, wait) {
80
+ let timeout;
81
+ return function executedFunction(...args) {
82
+ const later = () => {
83
+ timeout = null;
84
+ func.apply(this, args);
85
+ };
86
+ if (timeout) {
87
+ clearTimeout(timeout);
88
+ }
89
+ timeout = setTimeout(later, wait);
90
+ };
91
+ }
92
+
93
+ // src/lib/components/DatePicker/DatePickerProvider.tsx
94
+ var import_react = require("react");
95
+ var import_dayjs2 = __toESM(require("dayjs"));
96
+ var import_jsx_runtime = require("react/jsx-runtime");
97
+ var DateStateContext = (0, import_react.createContext)(null);
98
+ var DatePickerConfigContext = (0, import_react.createContext)(null);
99
+ var UIStateContext = (0, import_react.createContext)(null);
100
+ var DisplayContext = (0, import_react.createContext)(null);
101
+ var LocaleContext = (0, import_react.createContext)(null);
102
+ var useDateState = () => {
103
+ const context = (0, import_react.useContext)(DateStateContext);
104
+ if (!context) throw new Error("useDateState must be used within DatePickerProvider");
105
+ return context;
106
+ };
107
+ var useDatePickerConfig = () => {
108
+ const context = (0, import_react.useContext)(DatePickerConfigContext);
109
+ if (!context) throw new Error("useDatePickerConfig must be used within DatePickerProvider");
110
+ return context;
111
+ };
112
+ var useUIState = () => {
113
+ const context = (0, import_react.useContext)(UIStateContext);
114
+ if (!context) throw new Error("useUIState must be used within DatePickerProvider");
115
+ return context;
116
+ };
117
+ var useDisplayCustomization = () => {
118
+ const context = (0, import_react.useContext)(DisplayContext);
119
+ if (!context) throw new Error("useDisplayCustomization must be used within DatePickerProvider");
120
+ return context;
121
+ };
122
+ var loadLocale = async (locale) => {
123
+ if (locale === "en") return true;
124
+ try {
125
+ await import(`dayjs/locale/${locale}.js`);
126
+ return true;
127
+ } catch (error) {
128
+ console.error(`Failed to load locale ${locale}:`, error);
129
+ return false;
130
+ }
131
+ };
132
+ var DatePickerProvider = ({
133
+ children,
134
+ dateState,
135
+ config,
136
+ uiState,
137
+ display,
138
+ locale = "en"
139
+ }) => {
140
+ const [localeState, setLocaleState] = (0, import_react.useState)({
141
+ currentLocale: "en",
142
+ isLocaleReady: locale === "en"
143
+ });
144
+ (0, import_react.useEffect)(() => {
145
+ if (locale !== "en") {
146
+ setLocaleState((prev) => ({ ...prev, isLocaleReady: false }));
147
+ loadLocale(locale).then((success) => {
148
+ if (success) {
149
+ import_dayjs2.default.locale(locale);
150
+ setLocaleState({
151
+ currentLocale: locale,
152
+ isLocaleReady: true
153
+ });
154
+ } else {
155
+ import_dayjs2.default.locale("en");
156
+ setLocaleState({
157
+ currentLocale: "en",
158
+ isLocaleReady: true
159
+ });
160
+ }
161
+ });
162
+ } else {
163
+ import_dayjs2.default.locale("en");
164
+ setLocaleState({
165
+ currentLocale: "en",
166
+ isLocaleReady: true
167
+ });
168
+ }
169
+ }, [locale]);
170
+ if (!localeState.isLocaleReady) {
171
+ return null;
172
+ }
173
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LocaleContext.Provider, { value: localeState, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DateStateContext.Provider, { value: dateState, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DatePickerConfigContext.Provider, { value: config, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(UIStateContext.Provider, { value: uiState, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DisplayContext.Provider, { value: display, children }) }) }) }) });
174
+ };
175
+
176
+ // src/lib/assets/svg/calendar.svg
177
+ var React2 = __toESM(require("react"));
178
+ var import_jsx_runtime2 = require("react/jsx-runtime");
179
+ var SvgCalendar = (props) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", ...props, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M9 11H7v2h2v-2zm4 0h-2v2h2v-2zm4 0h-2v2h2v-2zm2-7h-1V2h-2v2H8V2H6v2H5c-1.11 0-1.99.9-1.99 2L3 20a2 2 0 002 2h14c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2zm0 16H5V9h14v11z" }) });
180
+ var calendar_default = SvgCalendar;
181
+
182
+ // src/lib/components/DatePicker/DateInput.tsx
183
+ var import_react2 = require("react");
184
+ var import_classnames = __toESM(require("classnames"));
185
+ var import_dayjs3 = __toESM(require("dayjs"));
186
+
187
+ // src/lib/assets/svg/prev.svg
188
+ var React3 = __toESM(require("react"));
189
+ var import_jsx_runtime3 = require("react/jsx-runtime");
190
+ var SvgPrev = (props) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", ...props, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M15.41 16.59L10.83 12l4.58-4.59L14 6l-6 6 6 6 1.41-1.41z" }) });
191
+ var prev_default = SvgPrev;
192
+
193
+ // src/lib/assets/svg/next.svg
194
+ var React4 = __toESM(require("react"));
195
+ var import_jsx_runtime4 = require("react/jsx-runtime");
196
+ var SvgNext = (props) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", ...props, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("path", { d: "M8.59 16.59L13.17 12 8.59 7.41 10 6l6 6-6 6-1.41-1.41z" }) });
197
+ var next_default = SvgNext;
198
+
199
+ // src/lib/components/DatePicker/DateInput.tsx
200
+ var import_jsx_runtime5 = require("react/jsx-runtime");
201
+ var DateInput = ({
202
+ type,
203
+ showIcon = false,
204
+ tabIndex = 0,
205
+ nonFocusable = false
206
+ }) => {
207
+ const [formattedDate, setFormattedDate] = (0, import_react2.useState)(null);
208
+ const [disablePrev, setDisablePrev] = (0, import_react2.useState)(false);
209
+ const [disableNext, setDisableNext] = (0, import_react2.useState)(false);
210
+ const {
211
+ fromDate,
212
+ toDate,
213
+ inputFocus,
214
+ handleClickDateInput,
215
+ handleChangeDate
216
+ } = useDateState();
217
+ const {
218
+ isSingle,
219
+ minDate,
220
+ maxDate,
221
+ dateFormat
222
+ } = useDatePickerConfig();
223
+ const {
224
+ startDatePlaceholder,
225
+ endDatePlaceholder
226
+ } = useDisplayCustomization();
227
+ const value = type === "from" ? fromDate : toDate;
228
+ const placeholder = type === "from" ? startDatePlaceholder : endDatePlaceholder;
229
+ (0, import_react2.useEffect)(() => {
230
+ if (value) {
231
+ let formattedValue = value.clone().locale(import_dayjs3.default.locale());
232
+ let text = formattedValue.format("ddd, DD MMM");
233
+ if (dateFormat) {
234
+ text = value.format(dateFormat);
235
+ }
236
+ setFormattedDate(text);
237
+ const minDateDayjs = minDate ? (0, import_dayjs3.default)(minDate) : null;
238
+ const maxDateDayjs = maxDate ? (0, import_dayjs3.default)(maxDate) : null;
239
+ if (minDateDayjs?.add(1, "day").isAfter(value, "date") || type === "to" && fromDate && value.isBefore(fromDate.add(1, "day"), "date")) {
240
+ setDisablePrev(true);
241
+ } else {
242
+ setDisablePrev(false);
243
+ }
244
+ if (maxDateDayjs?.subtract(1, "day").isBefore(value, "date")) {
245
+ setDisableNext(true);
246
+ } else {
247
+ setDisableNext(false);
248
+ }
249
+ } else {
250
+ setFormattedDate(null);
251
+ }
252
+ }, [value, fromDate, minDate, maxDate, dateFormat, type]);
253
+ const prevDate = (e) => {
254
+ e.stopPropagation();
255
+ if (value) {
256
+ handleChangeDate(value.subtract(1, "day"), type);
257
+ }
258
+ };
259
+ const nextDate = (e) => {
260
+ e.stopPropagation();
261
+ if (value) {
262
+ handleChangeDate(value.add(1, "day"), type);
263
+ }
264
+ };
265
+ const handleClick = () => {
266
+ handleClickDateInput(type);
267
+ };
268
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
269
+ "div",
270
+ {
271
+ className: (0, import_classnames.default)("date", {
272
+ "is-focus": inputFocus === type && !isSingle,
273
+ "is-single": isSingle
274
+ }),
275
+ role: "button",
276
+ tabIndex: nonFocusable ? -1 : tabIndex,
277
+ onClick: handleClick,
278
+ id: `${type}-date-input-button`,
279
+ children: [
280
+ showIcon && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(calendar_default, { className: "icon-calendar", viewBox: "0 0 24 24" }),
281
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "selected-date", children: formattedDate ?? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "date-placeholder", children: placeholder }) }),
282
+ formattedDate && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "change-date-group", children: [
283
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
284
+ "button",
285
+ {
286
+ type: "button",
287
+ className: "btn-outline change-date-button",
288
+ onClick: prevDate,
289
+ tabIndex: nonFocusable ? -1 : 0,
290
+ disabled: disablePrev,
291
+ children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(prev_default, { viewBox: "0 0 24 24", className: "icon-arrow" })
292
+ }
293
+ ),
294
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
295
+ "button",
296
+ {
297
+ type: "button",
298
+ className: "btn-outline change-date-button",
299
+ onClick: nextDate,
300
+ tabIndex: nonFocusable ? -1 : 0,
301
+ disabled: disableNext,
302
+ children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(next_default, { viewBox: "0 0 24 24", className: "icon-arrow" })
303
+ }
304
+ )
305
+ ] })
306
+ ]
307
+ }
308
+ );
309
+ };
310
+
311
+ // src/lib/components/DatePicker/DateInputGroup.tsx
312
+ var import_jsx_runtime6 = require("react/jsx-runtime");
313
+ var DateInputGroup = ({
314
+ showIcon = false,
315
+ nonFocusable = false
316
+ }) => {
317
+ const { isSingle } = useDatePickerConfig();
318
+ const { dateInputSeperator } = useDisplayCustomization();
319
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "date-picker-input", children: [
320
+ showIcon && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(calendar_default, { className: "icon-calendar mobile", viewBox: "0 0 24 24" }),
321
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "date-picker-date-group", children: [
322
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
323
+ DateInput,
324
+ {
325
+ type: "from",
326
+ tabIndex: nonFocusable ? -1 : 0,
327
+ showIcon: true,
328
+ nonFocusable
329
+ }
330
+ ),
331
+ !isSingle && dateInputSeperator && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "date-input-separator", children: dateInputSeperator }),
332
+ !isSingle && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
333
+ DateInput,
334
+ {
335
+ type: "to",
336
+ tabIndex: nonFocusable ? -1 : 0,
337
+ showIcon: false,
338
+ nonFocusable
339
+ }
340
+ )
341
+ ] })
342
+ ] });
343
+ };
344
+
345
+ // src/lib/components/DatePicker/DialogWrapper.tsx
346
+ var import_react_dom = require("react-dom");
347
+
348
+ // src/lib/hooks/useClientSide.ts
349
+ var import_react3 = require("react");
350
+ var useClientSide = () => {
351
+ const [isClient, setIsClient] = (0, import_react3.useState)(false);
352
+ (0, import_react3.useEffect)(() => {
353
+ if (typeof window !== "undefined" && typeof document !== "undefined") {
354
+ setIsClient(true);
355
+ } else {
356
+ console.warn("Client-side context not available");
357
+ }
358
+ }, []);
359
+ return isClient;
360
+ };
361
+
362
+ // src/lib/components/DatePicker/DialogWrapper.tsx
363
+ var import_jsx_runtime7 = require("react/jsx-runtime");
364
+ var DialogWrapper = ({
365
+ children = null,
366
+ isMobile = false
367
+ }) => {
368
+ const isClient = useClientSide();
369
+ if (!isClient) return null;
370
+ return isMobile ? (0, import_react_dom.createPortal)(/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { children }), document.body) : children;
371
+ };
372
+ var DialogWrapper_default = DialogWrapper;
373
+
374
+ // src/lib/components/DatePicker/Dialog.tsx
375
+ var import_react9 = require("react");
376
+ var import_classnames6 = __toESM(require("classnames"));
377
+
378
+ // src/lib/assets/svg/back.svg
379
+ var React6 = __toESM(require("react"));
380
+ var import_jsx_runtime8 = require("react/jsx-runtime");
381
+ var SvgBack = (props) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 492 492", ...props, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("path", { d: "M464.3 207.4l.8.2H136l103.5-103.7c5-5.1 7.8-12 7.8-19.2 0-7.2-2.7-14-7.8-19l-16.1-16.2c-5-5-11.8-7.8-19-7.8-7.2 0-14 2.8-19 7.8L7.8 227C2.8 232 0 238.8 0 246c0 7.3 2.8 14 7.8 19.2l177.5 177.4c5 5 11.8 7.8 19 7.8 7.2 0 14-2.8 19-7.8l16-16.1a26.6 26.6 0 000-37.7L134.8 284.4h330a27.9 27.9 0 0027.3-27.6V234a27.3 27.3 0 00-27.7-26.6z" }) });
382
+ var back_default = SvgBack;
383
+
384
+ // src/lib/components/DatePicker/DialogContentMobile.tsx
385
+ var import_react7 = __toESM(require("react"));
386
+ var import_dayjs6 = __toESM(require("dayjs"));
387
+ var import_react_window = require("react-window");
388
+ var import_react_virtualized_auto_sizer = __toESM(require("react-virtualized-auto-sizer"));
389
+
390
+ // src/lib/components/DatePicker/MonthCalendar.tsx
391
+ var import_react6 = require("react");
392
+ var import_classnames4 = __toESM(require("classnames"));
393
+ var import_dayjs5 = __toESM(require("dayjs"));
394
+
395
+ // src/lib/components/DatePicker/Week.tsx
396
+ var import_react5 = require("react");
397
+ var import_classnames3 = __toESM(require("classnames"));
398
+ var import_dayjs4 = __toESM(require("dayjs"));
399
+
400
+ // src/lib/components/DatePicker/Day.tsx
401
+ var import_react4 = require("react");
402
+ var import_classnames2 = __toESM(require("classnames"));
403
+ var import_jsx_runtime9 = require("react/jsx-runtime");
404
+ var Day = (0, import_react4.forwardRef)(({
405
+ dateIndex,
406
+ dateValue,
407
+ isEndDay,
408
+ selected,
409
+ hovered,
410
+ disabled,
411
+ totalDay,
412
+ highlight,
413
+ handleHoverDay,
414
+ subText
415
+ }, ref) => {
416
+ const dayRef = (0, import_react4.useRef)(null);
417
+ const { onSelectDate, onHoverDate } = useDateState();
418
+ const selectDate = (e) => {
419
+ e.stopPropagation();
420
+ e.preventDefault();
421
+ if (disabled) return;
422
+ onSelectDate(dateValue);
423
+ };
424
+ const handleHoverDate = () => {
425
+ if (disabled) return;
426
+ onHoverDate(dateValue);
427
+ handleHoverDay(dateValue);
428
+ };
429
+ const handleTooltipPosition = (0, import_react4.useCallback)(() => {
430
+ if (!ref || typeof ref === "function") return;
431
+ const element = ref.current;
432
+ if (element && dayRef.current) {
433
+ element.style.left = `${dayRef.current.offsetLeft - element.offsetWidth + 135}px`;
434
+ element.style.top = `${dayRef.current.offsetTop - element.offsetHeight - 15}px`;
435
+ element.style.visibility = "visible";
436
+ }
437
+ }, [ref]);
438
+ const handleTooltipHidden = (0, import_react4.useCallback)(() => {
439
+ if (!ref || typeof ref === "function") return;
440
+ const element = ref.current;
441
+ if (element) {
442
+ element.style.visibility = "hidden";
443
+ }
444
+ }, [ref]);
445
+ (0, import_react4.useEffect)(() => {
446
+ const currentRef = dayRef.current;
447
+ if (currentRef) {
448
+ currentRef.addEventListener("mouseover", handleTooltipPosition);
449
+ currentRef.addEventListener("mouseleave", handleTooltipHidden);
450
+ }
451
+ return () => {
452
+ if (currentRef) {
453
+ currentRef.removeEventListener("mouseover", handleTooltipPosition);
454
+ currentRef.removeEventListener("mouseleave", handleTooltipHidden);
455
+ }
456
+ };
457
+ }, [handleTooltipPosition, handleTooltipHidden]);
458
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
459
+ "div",
460
+ {
461
+ className: (0, import_classnames2.default)("day", {
462
+ selected,
463
+ hovered,
464
+ disabled,
465
+ highlight,
466
+ end: isEndDay,
467
+ "has-subtext": !!subText
468
+ }),
469
+ onClick: selectDate,
470
+ onMouseEnter: handleHoverDate,
471
+ role: "button",
472
+ tabIndex: -1,
473
+ "data-day-index": dateIndex,
474
+ "data-date-value": dateValue.valueOf(),
475
+ ref: dayRef,
476
+ children: [
477
+ hovered && !(isEndDay && dateIndex === totalDay) && !(dateIndex === 1 && selected && !isEndDay) && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
478
+ "div",
479
+ {
480
+ className: (0, import_classnames2.default)("background-day", {
481
+ "first-day": dateIndex === 1,
482
+ "last-day": dateIndex === totalDay
483
+ })
484
+ }
485
+ ),
486
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: "day-content", children: [
487
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: "text-day", children: dateIndex }),
488
+ subText && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
489
+ "div",
490
+ {
491
+ className: "sub-text",
492
+ style: {
493
+ position: "relative",
494
+ zIndex: 3,
495
+ color: selected && !hovered ? "#fff" : "#666"
496
+ },
497
+ children: subText
498
+ }
499
+ )
500
+ ] })
501
+ ]
502
+ }
503
+ );
504
+ });
505
+ Day.displayName = "Day";
506
+
507
+ // src/lib/components/DatePicker/Week.tsx
508
+ var import_jsx_runtime10 = require("react/jsx-runtime");
509
+ var Week = (0, import_react5.forwardRef)(({
510
+ isFirst,
511
+ week,
512
+ month,
513
+ year,
514
+ totalDay,
515
+ weekIndex,
516
+ handleHoverDay
517
+ }, ref) => {
518
+ const {
519
+ fromDate,
520
+ toDate,
521
+ hoverDate
522
+ } = useDateState();
523
+ const {
524
+ minDate,
525
+ maxDate,
526
+ isSingle,
527
+ highlightToday
528
+ } = useDatePickerConfig();
529
+ const { subTextDict } = useDisplayCustomization();
530
+ const generateDay = () => {
531
+ return Array.from({ length: week.days }, (_, index) => {
532
+ const dateIndex = index + week.start;
533
+ const dateValue = (0, import_dayjs4.default)(`${year}-${month + 1}-${dateIndex}`);
534
+ const disabled = minDate && dateValue.isBefore(minDate, "date") || maxDate && dateValue.isAfter(maxDate, "date");
535
+ const selected = fromDate && dateValue.isSame(fromDate, "date") || toDate && dateValue.isSame(toDate, "date");
536
+ let hovered = false;
537
+ const highlight = highlightToday && dateValue.isSame(/* @__PURE__ */ new Date(), "date");
538
+ if (fromDate && !fromDate.isSame(toDate, "date") && !isSingle) {
539
+ if (toDate && !fromDate.isAfter(dateValue, "date") && !toDate.isBefore(dateValue, "date")) {
540
+ hovered = true;
541
+ }
542
+ if (!toDate && !dateValue.isBefore(fromDate, "date") && !(hoverDate && hoverDate.isBefore(dateValue, "date")) && fromDate.isBefore(hoverDate, "date")) {
543
+ hovered = true;
544
+ }
545
+ }
546
+ const isEndDate = toDate && dateValue.isSame(toDate, "date") || !toDate && hoverDate && dateValue.isSame(hoverDate, "date");
547
+ const subText = !subTextDict ? "" : subTextDict[dateValue.format("YYYY-MM-DD")] ?? "\xA0";
548
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
549
+ Day,
550
+ {
551
+ dateIndex,
552
+ dateValue,
553
+ selected,
554
+ hovered,
555
+ highlight,
556
+ disabled,
557
+ isEndDay: isEndDate,
558
+ totalDay,
559
+ handleHoverDay,
560
+ subText,
561
+ ref
562
+ },
563
+ index
564
+ );
565
+ });
566
+ };
567
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: (0, import_classnames3.default)("week", { first: isFirst }), children: generateDay() });
568
+ });
569
+ Week.displayName = "Week";
570
+
571
+ // src/lib/components/DatePicker/MonthCalendar.tsx
572
+ var import_jsx_runtime11 = require("react/jsx-runtime");
573
+ var MonthCalendar = (0, import_react6.forwardRef)(({
574
+ month,
575
+ year,
576
+ hidden = false,
577
+ isAnimating = false,
578
+ handleHoverDay,
579
+ className
580
+ }, ref) => {
581
+ const {
582
+ startWeekDay,
583
+ weekDayFormat,
584
+ monthFormat,
585
+ singleCalendar
586
+ } = useDatePickerConfig();
587
+ const generateWeek = () => {
588
+ const { totalWeek, totalDay } = getMonthInfo(year, month, startWeekDay);
589
+ return totalWeek.map((week) => {
590
+ const weekKey = `${year}-${month}-${week.start}`;
591
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
592
+ Week,
593
+ {
594
+ week,
595
+ month,
596
+ year,
597
+ isFirst: week === totalWeek[0],
598
+ totalDay,
599
+ weekIndex: totalWeek.indexOf(week),
600
+ handleHoverDay,
601
+ ref
602
+ },
603
+ weekKey
604
+ );
605
+ });
606
+ };
607
+ const generateWeekDay = () => {
608
+ const arrWeekDay = getWeekDay(startWeekDay, weekDayFormat);
609
+ return arrWeekDay.map((day) => {
610
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { className: "weekday", children: day }, `weekday-${day.toLowerCase()}`);
611
+ });
612
+ };
613
+ const getMonthDisplay = () => {
614
+ const date = (0, import_dayjs5.default)(`${year}-${month + 1}-1`);
615
+ return monthFormat ? date.format(monthFormat) : date.format("MMMM - YYYY");
616
+ };
617
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(
618
+ "div",
619
+ {
620
+ className: (0, import_classnames4.default)("month-calendar", {
621
+ isAnimating,
622
+ hidden,
623
+ single: singleCalendar
624
+ }, className),
625
+ "data-month-index": month + 1,
626
+ children: [
627
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { className: "month-name", children: getMonthDisplay() }),
628
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { className: "weekdays", children: generateWeekDay() }),
629
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { className: "week-container", children: generateWeek() })
630
+ ]
631
+ }
632
+ );
633
+ });
634
+ MonthCalendar.displayName = "MonthCalendar";
635
+
636
+ // src/lib/components/DatePicker/DialogContentMobile.tsx
637
+ var import_jsx_runtime12 = require("react/jsx-runtime");
638
+ var DialogContentMobile = () => {
639
+ const [rowCount, setRowCount] = (0, import_react7.useState)(2400);
640
+ const listRef = (0, import_react7.useRef)(null);
641
+ const {
642
+ fromDate
643
+ } = useDateState();
644
+ const {
645
+ startWeekDay,
646
+ minDate,
647
+ maxDate,
648
+ weekDayFormat
649
+ } = useDatePickerConfig();
650
+ const {
651
+ complsOpen
652
+ } = useUIState();
653
+ const {
654
+ tooltip,
655
+ subTextDict
656
+ } = useDisplayCustomization();
657
+ const minYear = minDate ? (0, import_dayjs6.default)(minDate).year() : 1900;
658
+ const minMonth = minDate ? (0, import_dayjs6.default)(minDate).month() : 0;
659
+ (0, import_react7.useEffect)(() => {
660
+ if (maxDate) {
661
+ const _minDate = minDate ? (0, import_dayjs6.default)(minDate) : (0, import_dayjs6.default)("1900-01-01");
662
+ setRowCount((0, import_dayjs6.default)(maxDate).diff(_minDate, "month") + 1);
663
+ }
664
+ }, [maxDate, minDate]);
665
+ (0, import_react7.useEffect)(() => {
666
+ if (listRef.current && complsOpen) {
667
+ const date = fromDate ? (0, import_dayjs6.default)(fromDate) : (0, import_dayjs6.default)();
668
+ let monthDiff = date.diff((0, import_dayjs6.default)("1900-01-01"), "month");
669
+ if (minDate) {
670
+ monthDiff = date.diff((0, import_dayjs6.default)(minDate), "month");
671
+ }
672
+ listRef.current.scrollToItem(monthDiff + 1, "smart");
673
+ }
674
+ }, [complsOpen, fromDate, minDate]);
675
+ const getMonthYearFromIndex = (index) => {
676
+ const _index = index + minMonth;
677
+ const year = minYear + Math.floor(_index / 12);
678
+ const month = _index % 12;
679
+ return { year, month };
680
+ };
681
+ const Row = import_react7.default.memo(({ index, style }) => {
682
+ const { year, month } = getMonthYearFromIndex(index);
683
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { style, children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
684
+ MonthCalendar,
685
+ {
686
+ month,
687
+ year,
688
+ hidden: false,
689
+ isAnimating: false,
690
+ handleHoverDay: () => {
691
+ }
692
+ }
693
+ ) });
694
+ });
695
+ Row.displayName = "CalendarRow";
696
+ const getItemSize = (index) => {
697
+ const { year, month } = getMonthYearFromIndex(index);
698
+ const { totalWeek } = getMonthInfo(year, month, startWeekDay || "monday");
699
+ return totalWeek.length * 48 + 34;
700
+ };
701
+ const renderMonthCalendars = () => {
702
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_react_virtualized_auto_sizer.default, { children: ({ height, width }) => /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
703
+ import_react_window.VariableSizeList,
704
+ {
705
+ ref: listRef,
706
+ width,
707
+ height: height - 36,
708
+ itemCount: rowCount,
709
+ itemSize: getItemSize,
710
+ children: Row
711
+ }
712
+ ) });
713
+ };
714
+ const generateWeekDay = () => {
715
+ const arrWeekDay = getWeekDay(startWeekDay || "monday", weekDayFormat);
716
+ return arrWeekDay.map((day, index) => /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: "weekday", children: day }, index));
717
+ };
718
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: "calendar-wrapper", children: /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { className: "calendar-content", children: [
719
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: "weekdays mobile", children: generateWeekDay() }),
720
+ renderMonthCalendars()
721
+ ] }) });
722
+ };
723
+
724
+ // src/lib/components/DatePicker/DialogContentDesktop.tsx
725
+ var import_react8 = require("react");
726
+ var import_classnames5 = __toESM(require("classnames"));
727
+ var import_dayjs7 = __toESM(require("dayjs"));
728
+ var import_jsx_runtime13 = require("react/jsx-runtime");
729
+ var useClientSide2 = () => {
730
+ const [isClient, setIsClient] = (0, import_react8.useState)(false);
731
+ (0, import_react8.useEffect)(() => {
732
+ setIsClient(true);
733
+ }, []);
734
+ return isClient;
735
+ };
736
+ var DialogContentDesktop = ({
737
+ dateChanged = null
738
+ }) => {
739
+ const isClient = useClientSide2();
740
+ const containerRef = (0, import_react8.useRef)(null);
741
+ const tooltipRef = (0, import_react8.useRef)(null);
742
+ const [translateAmount, setTranslateAmount] = (0, import_react8.useState)(0);
743
+ const [monthArray, setMonthArray] = (0, import_react8.useState)([]);
744
+ const [focusDate, setFocusDate] = (0, import_react8.useState)(null);
745
+ const [disablePrev, setDisablePrev] = (0, import_react8.useState)(false);
746
+ const [disableNext, setDisableNext] = (0, import_react8.useState)(false);
747
+ const [wrapperWidth, setWrapperWidth] = (0, import_react8.useState)(0);
748
+ const [dayValue, setDayValue] = (0, import_react8.useState)(null);
749
+ const [isAnimating, setIsAnimating] = (0, import_react8.useState)(false);
750
+ const { fromDate } = useDateState();
751
+ const { minDate, maxDate, singleCalendar } = useDatePickerConfig();
752
+ const { complsOpen } = useUIState();
753
+ const { tooltip } = useDisplayCustomization();
754
+ const getArrayMonth = (0, import_react8.useCallback)((date) => [
755
+ date.subtract(1, "month"),
756
+ date,
757
+ date.add(1, "month"),
758
+ date.add(2, "month")
759
+ ], []);
760
+ (0, import_react8.useEffect)(() => {
761
+ if (!isClient || !containerRef.current) return;
762
+ const updateDimensions = () => {
763
+ const width = containerRef.current.offsetWidth;
764
+ const style = window.getComputedStyle(containerRef.current);
765
+ const translateValue = singleCalendar ? width + parseInt(style.marginLeft) - 8 : width / 2;
766
+ setWrapperWidth(translateValue);
767
+ };
768
+ updateDimensions();
769
+ const resizeObserver = new ResizeObserver(updateDimensions);
770
+ resizeObserver.observe(containerRef.current);
771
+ return () => resizeObserver.disconnect();
772
+ }, [isClient, singleCalendar]);
773
+ (0, import_react8.useEffect)(() => {
774
+ setFocusDate(fromDate ?? (0, import_dayjs7.default)());
775
+ }, [complsOpen, fromDate]);
776
+ (0, import_react8.useEffect)(() => {
777
+ if (!focusDate) return;
778
+ const minDayjs = minDate ? (0, import_dayjs7.default)(minDate) : null;
779
+ const maxDayjs = maxDate ? (0, import_dayjs7.default)(maxDate) : null;
780
+ setDisablePrev(
781
+ Boolean(
782
+ minDayjs && focusDate.isBefore(minDayjs.add(1, "month"), "month")
783
+ )
784
+ );
785
+ setDisableNext(
786
+ Boolean(
787
+ maxDayjs && focusDate.isAfter(maxDayjs.subtract(2, "month"), "month")
788
+ )
789
+ );
790
+ setMonthArray(getArrayMonth(focusDate));
791
+ }, [focusDate, minDate, maxDate, getArrayMonth]);
792
+ (0, import_react8.useEffect)(() => {
793
+ if (!dateChanged || !focusDate) return;
794
+ const monthDiff = dateChanged.diff(focusDate, "month");
795
+ if (monthDiff < -1) decreaseCurrentMonth();
796
+ if (monthDiff > 1) increaseCurrentMonth();
797
+ }, [dateChanged, focusDate]);
798
+ const handleMonthChange = (0, import_react8.useCallback)((direction) => () => {
799
+ if (direction === "next" && disableNext || direction === "prev" && disablePrev || isAnimating) return;
800
+ setIsAnimating(true);
801
+ setTranslateAmount(direction === "next" ? -wrapperWidth : wrapperWidth);
802
+ const timer = setTimeout(() => {
803
+ setFocusDate((prev) => {
804
+ const newDate = direction === "next" ? prev.add(1, "month") : prev.subtract(1, "month");
805
+ setMonthArray(getArrayMonth(newDate));
806
+ return newDate;
807
+ });
808
+ setTranslateAmount(0);
809
+ setIsAnimating(false);
810
+ }, 200);
811
+ return () => clearTimeout(timer);
812
+ }, [disableNext, disablePrev, isAnimating, wrapperWidth, getArrayMonth]);
813
+ const [increaseCurrentMonth, decreaseCurrentMonth] = (0, import_react8.useMemo)(
814
+ () => [handleMonthChange("next"), handleMonthChange("prev")],
815
+ [handleMonthChange]
816
+ );
817
+ const focusOnCalendar = (0, import_react8.useCallback)(() => {
818
+ if (!isClient || !containerRef.current) return;
819
+ const selector = ".day.selected, .month-calendar:not(.hidden) .day:not(.disabled)";
820
+ const focusTarget = containerRef.current.querySelector(selector);
821
+ focusTarget?.focus();
822
+ }, [isClient]);
823
+ const handleKeyDown = (0, import_react8.useCallback)((e) => {
824
+ const target = e.target;
825
+ const dayIndex = target.getAttribute("data-day-index");
826
+ if (!dayIndex) return;
827
+ e.preventDefault();
828
+ const calendarContainer = target.closest(".calendar-wrapper");
829
+ const dateValue = parseInt(target.dataset.dateValue ?? "0");
830
+ const date = (0, import_dayjs7.default)(dateValue);
831
+ const lastDate = date.endOf("month").date();
832
+ let newIndex = parseInt(dayIndex);
833
+ switch (e.key) {
834
+ case "ArrowLeft":
835
+ newIndex--;
836
+ break;
837
+ case "ArrowUp":
838
+ newIndex -= 7;
839
+ break;
840
+ case "ArrowRight":
841
+ newIndex++;
842
+ break;
843
+ case "ArrowDown":
844
+ newIndex += 7;
845
+ break;
846
+ case " ":
847
+ target.click();
848
+ return;
849
+ default:
850
+ return;
851
+ }
852
+ if (newIndex > 0 && newIndex <= lastDate) {
853
+ calendarContainer?.querySelector(`[data-day-index="${newIndex}"]`)?.focus();
854
+ } else {
855
+ const newDate = date.add(newIndex - parseInt(dayIndex), "day");
856
+ const monthDiff = newDate.diff(focusDate, "month");
857
+ if (monthDiff > 1 && !disableNext) increaseCurrentMonth();
858
+ if (monthDiff < 0 && !disablePrev) decreaseCurrentMonth();
859
+ setTimeout(() => {
860
+ calendarContainer?.querySelector(
861
+ `[data-month-index="${newDate.month() + 1}"] [data-day-index="${newDate.date()}"]`
862
+ )?.focus();
863
+ }, 200);
864
+ }
865
+ }, [focusDate, disableNext, disablePrev, increaseCurrentMonth, decreaseCurrentMonth]);
866
+ const renderTooltip = (0, import_react8.useMemo)(() => {
867
+ if (!tooltip || !isClient) return null;
868
+ const content = typeof tooltip === "function" ? tooltip(dayValue?.toDate() ?? /* @__PURE__ */ new Date()) : tooltip;
869
+ return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { id: "day-tooltip", className: "tooltip-text", ref: tooltipRef, children: content });
870
+ }, [tooltip, dayValue, isClient]);
871
+ const calendarMonths = (0, import_react8.useMemo)(
872
+ () => monthArray.map((date, index) => {
873
+ const isVisible = index === 1 || index === 2;
874
+ const isSlidingNext = isAnimating && translateAmount < 0 && index === 3;
875
+ const isSlidingPrev = isAnimating && translateAmount > 0 && index === 0;
876
+ return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
877
+ MonthCalendar,
878
+ {
879
+ hidden: !isVisible && !isSlidingNext && !isSlidingPrev,
880
+ isAnimating: isSlidingNext || isSlidingPrev,
881
+ month: date.month(),
882
+ year: date.year(),
883
+ handleHoverDay: setDayValue,
884
+ ref: tooltipRef,
885
+ className: (0, import_classnames5.default)({ "slide-next": isSlidingNext, "slide-prev": isSlidingPrev })
886
+ },
887
+ `${date.year()}-${date.month()}`
888
+ );
889
+ }),
890
+ [monthArray, isAnimating, translateAmount]
891
+ );
892
+ return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { className: "relative", children: [
893
+ renderTooltip,
894
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(
895
+ "div",
896
+ {
897
+ className: (0, import_classnames5.default)("calendar-wrapper", { single: singleCalendar }),
898
+ ref: containerRef,
899
+ onKeyDown: handleKeyDown,
900
+ role: "grid",
901
+ "aria-label": "Calendar",
902
+ children: [
903
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
904
+ "div",
905
+ {
906
+ className: (0, import_classnames5.default)("calendar-content", { isAnimating }),
907
+ style: { transform: `translateX(${translateAmount}px)` },
908
+ children: calendarMonths
909
+ }
910
+ ),
911
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { className: "calendar-flippers", children: [
912
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
913
+ "button",
914
+ {
915
+ className: (0, import_classnames5.default)("flipper-button", { disabled: disablePrev }),
916
+ onClick: decreaseCurrentMonth,
917
+ onKeyDown: (e) => e.key === " " && decreaseCurrentMonth(),
918
+ disabled: disablePrev,
919
+ "aria-label": "Previous month",
920
+ children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(prev_default, { viewBox: "0 0 24 24" })
921
+ }
922
+ ),
923
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
924
+ "button",
925
+ {
926
+ className: (0, import_classnames5.default)("flipper-button", { disabled: disableNext }),
927
+ onClick: increaseCurrentMonth,
928
+ onKeyDown: (e) => e.key === " " && increaseCurrentMonth(),
929
+ disabled: disableNext,
930
+ "aria-label": "Next month",
931
+ onBlur: focusOnCalendar,
932
+ children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(next_default, { viewBox: "0 0 24 24" })
933
+ }
934
+ )
935
+ ] })
936
+ ]
937
+ }
938
+ )
939
+ ] });
940
+ };
941
+
942
+ // src/lib/components/DatePicker/Dialog.tsx
943
+ var import_jsx_runtime14 = require("react/jsx-runtime");
944
+ var Dialog = ({
945
+ containerRef: externalRef
946
+ }) => {
947
+ const [hideAnimation, setHideAnimation] = (0, import_react9.useState)(false);
948
+ const [dateChanged, setDateChanged] = (0, import_react9.useState)(null);
949
+ const defaultRef = (0, import_react9.useRef)(null);
950
+ const containerRef = externalRef || defaultRef;
951
+ const {
952
+ handleChangeDate,
953
+ handleReset
954
+ } = useDateState();
955
+ const {
956
+ singleCalendar,
957
+ expandDirection
958
+ } = useDatePickerConfig();
959
+ const {
960
+ complsOpen,
961
+ isMobile,
962
+ toggleDialog
963
+ } = useUIState();
964
+ const {
965
+ hideDialogHeader,
966
+ hideDialogFooter
967
+ } = useDisplayCustomization();
968
+ const onChangeDate = (date, type) => {
969
+ setDateChanged(date);
970
+ handleChangeDate(date, type);
971
+ };
972
+ (0, import_react9.useEffect)(() => {
973
+ if (complsOpen && !hideAnimation) {
974
+ setHideAnimation(true);
975
+ }
976
+ if (complsOpen) {
977
+ setTimeout(() => {
978
+ const startDateInput = containerRef.current?.querySelector(
979
+ "#start-date-input-button"
980
+ );
981
+ if (startDateInput) {
982
+ startDateInput.focus();
983
+ }
984
+ }, 50);
985
+ }
986
+ }, [complsOpen, containerRef, hideAnimation]);
987
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(
988
+ "div",
989
+ {
990
+ className: (0, import_classnames6.default)("dialog-date-picker", {
991
+ "open": complsOpen,
992
+ "hide": !complsOpen && hideAnimation,
993
+ "single": singleCalendar && !isMobile,
994
+ "expand-left": expandDirection === "left",
995
+ "expand-right": expandDirection === "right"
996
+ }),
997
+ ref: containerRef,
998
+ children: [
999
+ !hideDialogHeader && /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("div", { className: "dialog-header", children: [
1000
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
1001
+ "button",
1002
+ {
1003
+ type: "button",
1004
+ className: "btn-outline back-button",
1005
+ onClick: toggleDialog,
1006
+ children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(back_default, { viewBox: "0 0 492 492" })
1007
+ }
1008
+ ),
1009
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
1010
+ DateInputGroup,
1011
+ {
1012
+ showIcon: true,
1013
+ nonFocusable: !complsOpen
1014
+ }
1015
+ ),
1016
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
1017
+ "button",
1018
+ {
1019
+ type: "button",
1020
+ className: "btn-outline reset-button",
1021
+ onClick: handleReset,
1022
+ children: "Reset"
1023
+ }
1024
+ )
1025
+ ] }),
1026
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { className: "dialog-content", children: isMobile ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(DialogContentMobile, {}) : /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
1027
+ DialogContentDesktop,
1028
+ {
1029
+ dateChanged
1030
+ }
1031
+ ) }),
1032
+ !hideDialogFooter && /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("div", { className: "dialog-footer", children: [
1033
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
1034
+ "button",
1035
+ {
1036
+ type: "button",
1037
+ className: "submit-button",
1038
+ onClick: toggleDialog,
1039
+ tabIndex: 0,
1040
+ children: "Done"
1041
+ }
1042
+ ),
1043
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
1044
+ "button",
1045
+ {
1046
+ type: "button",
1047
+ className: "btn-outline reset-button mobile",
1048
+ onClick: handleReset,
1049
+ children: "Reset"
1050
+ }
1051
+ )
1052
+ ] })
1053
+ ]
1054
+ }
1055
+ );
1056
+ };
1057
+
1058
+ // src/lib/components/DatePicker/BaseDatePicker.tsx
1059
+ var import_jsx_runtime15 = require("react/jsx-runtime");
1060
+ import_dayjs8.default.extend(import_localeData.default);
1061
+ var BaseDatePicker = ({
1062
+ startDate = null,
1063
+ endDate = null,
1064
+ className = "",
1065
+ disabled = false,
1066
+ startDatePlaceholder,
1067
+ endDatePlaceholder,
1068
+ onChange,
1069
+ onFocus = () => {
1070
+ },
1071
+ startWeekDay = "monday",
1072
+ minDate = null,
1073
+ maxDate = null,
1074
+ weekDayFormat = "dd",
1075
+ dateFormat = "",
1076
+ monthFormat = "",
1077
+ highlightToday = false,
1078
+ dateInputSeperator = null,
1079
+ hideDialogHeader = false,
1080
+ hideDialogFooter = false,
1081
+ hideDialogAfterSelectEndDate = false,
1082
+ isOpen = false,
1083
+ onCloseCalendar,
1084
+ tooltip = "",
1085
+ subTextDict = null,
1086
+ expandDirection = "right",
1087
+ locale = "en",
1088
+ isSingle = false,
1089
+ singleCalendar = false
1090
+ }) => {
1091
+ const [complsOpen, setComplsOpen] = (0, import_react10.useState)(isOpen);
1092
+ const [inputFocus, setInputFocus] = (0, import_react10.useState)(
1093
+ isSingle ? "from" : null
1094
+ );
1095
+ const [fromDate, setFromDate] = (0, import_react10.useState)(
1096
+ startDate ? (0, import_dayjs8.default)(startDate) : void 0
1097
+ );
1098
+ const [toDate, setToDate] = (0, import_react10.useState)(
1099
+ endDate ? (0, import_dayjs8.default)(endDate) : void 0
1100
+ );
1101
+ const [hoverDate, setHoverDate] = (0, import_react10.useState)();
1102
+ const [isMobile, setIsMobile] = (0, import_react10.useState)(false);
1103
+ const [isFirstTime, setIsFirstTime] = (0, import_react10.useState)(false);
1104
+ const isClient = useClientSide();
1105
+ const containerRef = (0, import_react10.useRef)(null);
1106
+ const fromDateRef = (0, import_react10.useRef)(null);
1107
+ const toDateRef = (0, import_react10.useRef)(null);
1108
+ const handleResize = (0, import_react10.useCallback)(() => {
1109
+ if (!isClient) return;
1110
+ setIsMobile(window.innerWidth < 768);
1111
+ }, [isClient]);
1112
+ const notifyChange = () => {
1113
+ const _startDate = fromDateRef.current ? fromDateRef.current.toDate() : null;
1114
+ const _endDate = !isSingle && toDateRef.current ? toDateRef.current.toDate() : null;
1115
+ if (isSingle) {
1116
+ onChange(_startDate, null);
1117
+ } else {
1118
+ onChange(_startDate, _endDate);
1119
+ }
1120
+ };
1121
+ const debounceNotifyChange = debounce(notifyChange, 20);
1122
+ const updateFromDate = (dateValue, shouldNotifyChange = false) => {
1123
+ setFromDate(dateValue || void 0);
1124
+ fromDateRef.current = dateValue || null;
1125
+ if (shouldNotifyChange) {
1126
+ debounceNotifyChange();
1127
+ }
1128
+ };
1129
+ const updateToDate = (dateValue, shouldNotifyChange = false) => {
1130
+ if (!isSingle) {
1131
+ setToDate(dateValue || void 0);
1132
+ toDateRef.current = dateValue || null;
1133
+ if (shouldNotifyChange) {
1134
+ debounceNotifyChange();
1135
+ }
1136
+ }
1137
+ };
1138
+ (0, import_react10.useLayoutEffect)(() => {
1139
+ if (!isClient) return;
1140
+ handleResize();
1141
+ window.addEventListener("resize", handleResize);
1142
+ return () => window.removeEventListener("resize", handleResize);
1143
+ }, [isClient, handleResize]);
1144
+ (0, import_react10.useEffect)(() => {
1145
+ if (!isClient) return;
1146
+ setIsFirstTime(true);
1147
+ const handleDocumentClick = (e) => {
1148
+ if (containerRef.current && e.target instanceof Node && !containerRef.current.contains(e.target) && window.innerWidth >= 768) {
1149
+ setComplsOpen(false);
1150
+ }
1151
+ };
1152
+ document.addEventListener("click", handleDocumentClick);
1153
+ return () => document.removeEventListener("click", handleDocumentClick);
1154
+ }, [isClient]);
1155
+ (0, import_react10.useEffect)(() => {
1156
+ const _startDateJs = startDate ? (0, import_dayjs8.default)(startDate) : null;
1157
+ fromDateRef.current = _startDateJs;
1158
+ updateFromDate(_startDateJs, false);
1159
+ }, [startDate]);
1160
+ (0, import_react10.useEffect)(() => {
1161
+ if (!isSingle) {
1162
+ const _endDateJs = endDate ? (0, import_dayjs8.default)(endDate) : null;
1163
+ toDateRef.current = _endDateJs;
1164
+ updateToDate(_endDateJs, false);
1165
+ }
1166
+ }, [endDate, isSingle]);
1167
+ (0, import_react10.useEffect)(() => {
1168
+ if (!complsOpen && isFirstTime) {
1169
+ const _startDate = fromDateRef.current?.toDate() || null;
1170
+ const _endDate = toDateRef.current?.toDate() || null;
1171
+ if (isSingle) {
1172
+ onCloseCalendar(_startDate, null);
1173
+ } else {
1174
+ onCloseCalendar(_startDate, _endDate);
1175
+ }
1176
+ }
1177
+ }, [complsOpen, isFirstTime, isSingle, onCloseCalendar]);
1178
+ (0, import_react10.useEffect)(() => {
1179
+ setComplsOpen(isOpen);
1180
+ }, [isOpen]);
1181
+ (0, import_react10.useEffect)(() => {
1182
+ if (isFirstTime) {
1183
+ const input = inputFocus === "from" ? "Start Date" : inputFocus === "to" ? "End Date" : "";
1184
+ onFocus(input);
1185
+ }
1186
+ }, [inputFocus, isFirstTime, onFocus]);
1187
+ const toggleDialog = () => {
1188
+ setComplsOpen(!complsOpen);
1189
+ };
1190
+ const handleClickDateInput = (focusInput) => {
1191
+ if (disabled || !isSingle && focusInput === "to" && !fromDate) {
1192
+ return;
1193
+ }
1194
+ if (!complsOpen) {
1195
+ setComplsOpen(true);
1196
+ }
1197
+ setInputFocus(focusInput);
1198
+ };
1199
+ const onSelectDate = (0, import_react10.useCallback)(
1200
+ (date) => {
1201
+ const minDayjs = minDate ? (0, import_dayjs8.default)(minDate) : null;
1202
+ const maxDayjs = maxDate ? (0, import_dayjs8.default)(maxDate) : null;
1203
+ if (minDayjs && minDayjs.isAfter(date, "date") || maxDayjs && maxDayjs.isBefore(date, "date")) {
1204
+ return;
1205
+ }
1206
+ if (isSingle) {
1207
+ updateFromDate(date, true);
1208
+ if (hideDialogAfterSelectEndDate) {
1209
+ setTimeout(() => setComplsOpen(false), 50);
1210
+ }
1211
+ } else if (inputFocus === "from" || fromDate && date.isBefore(fromDate, "date")) {
1212
+ updateFromDate(date, true);
1213
+ if (toDate && date.isAfter(toDate, "date")) {
1214
+ updateToDate(null, true);
1215
+ }
1216
+ setInputFocus("to");
1217
+ } else {
1218
+ updateToDate(date, true);
1219
+ setInputFocus(null);
1220
+ if (hideDialogAfterSelectEndDate) {
1221
+ setTimeout(() => setComplsOpen(false), 50);
1222
+ }
1223
+ }
1224
+ },
1225
+ [
1226
+ minDate,
1227
+ maxDate,
1228
+ isSingle,
1229
+ hideDialogAfterSelectEndDate,
1230
+ inputFocus,
1231
+ fromDate,
1232
+ toDate
1233
+ ]
1234
+ );
1235
+ const onHoverDate = (date) => {
1236
+ setHoverDate(date);
1237
+ };
1238
+ const handleReset = () => {
1239
+ setHoverDate(void 0);
1240
+ updateFromDate(null, true);
1241
+ if (!isSingle) {
1242
+ updateToDate(null, true);
1243
+ }
1244
+ setInputFocus("from");
1245
+ };
1246
+ const handleChangeDate = (0, import_react10.useCallback)(
1247
+ (date, type) => {
1248
+ const minDayjs = minDate ? (0, import_dayjs8.default)(minDate) : null;
1249
+ const maxDayjs = maxDate ? (0, import_dayjs8.default)(maxDate) : null;
1250
+ if (minDayjs && minDayjs.isAfter(date, "date") || maxDayjs && maxDayjs.isBefore(date, "date")) {
1251
+ return;
1252
+ }
1253
+ if (type === "from" || isSingle) {
1254
+ setInputFocus("from");
1255
+ updateFromDate(date, true);
1256
+ if (!isSingle && toDate && date.isAfter(toDate, "date")) {
1257
+ updateToDate(null, true);
1258
+ }
1259
+ } else {
1260
+ setInputFocus("to");
1261
+ updateToDate(date, true);
1262
+ }
1263
+ },
1264
+ [minDate, maxDate, isSingle, toDate, inputFocus]
1265
+ );
1266
+ const dateState = {
1267
+ fromDate,
1268
+ toDate,
1269
+ hoverDate,
1270
+ inputFocus,
1271
+ onSelectDate,
1272
+ onHoverDate,
1273
+ handleChangeDate,
1274
+ handleReset,
1275
+ handleClickDateInput
1276
+ };
1277
+ const config = {
1278
+ isSingle,
1279
+ startWeekDay,
1280
+ minDate: minDate ? (0, import_dayjs8.default)(minDate).toDate() : null,
1281
+ maxDate: maxDate ? (0, import_dayjs8.default)(maxDate).toDate() : null,
1282
+ weekDayFormat,
1283
+ dateFormat,
1284
+ monthFormat,
1285
+ highlightToday,
1286
+ singleCalendar,
1287
+ expandDirection,
1288
+ locale
1289
+ };
1290
+ const uiState = {
1291
+ complsOpen,
1292
+ isMobile,
1293
+ disabled,
1294
+ toggleDialog
1295
+ };
1296
+ const display = {
1297
+ startDatePlaceholder,
1298
+ endDatePlaceholder,
1299
+ dateInputSeperator,
1300
+ hideDialogHeader,
1301
+ hideDialogFooter,
1302
+ hideDialogAfterSelectEndDate,
1303
+ tooltip,
1304
+ subTextDict
1305
+ };
1306
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("div", { className: "react-google-flight-datepicker", children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
1307
+ "div",
1308
+ {
1309
+ className: (0, import_classnames7.default)("date-picker", className, {
1310
+ disabled
1311
+ }),
1312
+ ref: containerRef,
1313
+ children: /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(
1314
+ DatePickerProvider,
1315
+ {
1316
+ dateState,
1317
+ config,
1318
+ uiState,
1319
+ display,
1320
+ locale,
1321
+ children: [
1322
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(DateInputGroup, {}),
1323
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(DialogWrapper_default, { children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(Dialog, {}) })
1324
+ ]
1325
+ }
1326
+ )
1327
+ }
1328
+ ) });
1329
+ };
1330
+ var BaseDatePicker_default = BaseDatePicker;
1331
+
1332
+ // src/lib/components/DatePicker/ClientOnly.tsx
1333
+ var import_react11 = require("react");
1334
+ var import_jsx_runtime16 = require("react/jsx-runtime");
1335
+ var ClientOnly = ({ children }) => {
1336
+ const [hasMounted, setHasMounted] = (0, import_react11.useState)(false);
1337
+ (0, import_react11.useEffect)(() => {
1338
+ setHasMounted(true);
1339
+ }, []);
1340
+ if (!hasMounted) return null;
1341
+ return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_jsx_runtime16.Fragment, { children });
1342
+ };
1343
+
1344
+ // src/lib/components/DatePicker/RangeDatePicker.tsx
1345
+ var import_jsx_runtime17 = require("react/jsx-runtime");
1346
+ var RangeDatePicker = ({
1347
+ onChange = () => {
1348
+ },
1349
+ onCloseCalendar = () => {
1350
+ },
1351
+ startDatePlaceholder = "Start date",
1352
+ endDatePlaceholder = "End date",
1353
+ ...props
1354
+ }) => /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(ClientOnly, { children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
1355
+ BaseDatePicker_default,
1356
+ {
1357
+ ...props,
1358
+ isSingle: false,
1359
+ startDate: props.startDate,
1360
+ endDate: props.endDate,
1361
+ startDatePlaceholder,
1362
+ endDatePlaceholder,
1363
+ onChange,
1364
+ onCloseCalendar
1365
+ }
1366
+ ) });
1367
+
1368
+ // src/lib/components/DatePicker/SingleDatePicker.tsx
1369
+ var import_jsx_runtime18 = require("react/jsx-runtime");
1370
+ var SingleDatePicker = ({
1371
+ onChange = () => {
1372
+ },
1373
+ onCloseCalendar = () => {
1374
+ },
1375
+ startDatePlaceholder = "Date",
1376
+ ...props
1377
+ }) => /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(ClientOnly, { children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
1378
+ BaseDatePicker_default,
1379
+ {
1380
+ ...props,
1381
+ endDate: null,
1382
+ isSingle: true,
1383
+ startDate: props.startDate,
1384
+ startDatePlaceholder,
1385
+ onChange: (date) => onChange(date),
1386
+ onCloseCalendar: (date) => onCloseCalendar(date)
1387
+ }
1388
+ ) });
1389
+ // Annotate the CommonJS export names for ESM import in node:
1390
+ 0 && (module.exports = {
1391
+ RangeDatePicker,
1392
+ SingleDatePicker
1393
+ });
2
1394
  //# sourceMappingURL=index.js.map