'use client';
"use strict";var e=require("tslib"),l=require("react"),a=require("tailwind-merge"),t=require("date-fns"),n=require("date-fns/locale"),r=require("../../../contexts/BaseColorContext.cjs"),o=require("../../../contexts/HoveredValueContext.cjs");require("../../../contexts/RootStylesContext.cjs");var u=require("../../../contexts/SelectedValueContext.cjs"),d=require("../../../hooks/useInternalState.cjs"),s=require("../../../hooks/useSelectOnKeyDown.cjs"),c=require("../../../lib/constants.cjs"),i=require("./dateRangePickerUtils.cjs"),f=require("./Calendar.cjs"),m=require("./DateRangePickerButton.cjs");require("../Dropdown/Dropdown.cjs");var p=require("../Dropdown/DropdownItem.cjs"),D=require("../../util-elements/Modal/Modal.cjs");function w(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var h=w(l);const v=h.default.forwardRef(((w,v)=>{var C,g,q;const{value:S,defaultValue:b,onValueChange:x,enableDropdown:j=!0,options:P,minDate:k=null,maxDate:R=null,placeholder:E="Select",dropdownPlaceholder:y="Select",disabled:M=!1,color:V=c.BaseColors.Blue,enableYearPagination:N=!1,locale:B=n.enUS,enableClear:O=!0,className:K}=w,Y=e.__rest(w,["value","defaultValue","onValueChange","enableDropdown","options","minDate","maxDate","placeholder","dropdownPlaceholder","disabled","color","enableYearPagination","locale","enableClear","className"]),H=t.startOfToday(),I=l.useRef(null),U=l.useRef(null),[_,T]=d(b,S),[z,A]=l.useState(null),[F,G]=l.useState(!1),[J,L]=l.useState(!1),Q=null!=P?P:i.defaultOptions,W=_&&null!==(C=_[2])&&void 0!==C?C:null,X=_?i.parseStartDate(_[0],k,W,Q):null,Z=_?i.parseEndDate(_[1],R,W,Q):null,$=null!==(q=null!==(g=null!=z?z:Z)&&void 0!==g?g:X)&&void 0!==q?q:H,ee=e=>{const l=i.getStartDateByDropdownValue(e,Q),a=i.getEndDateByDropdownValue(e,Q);T([l,a,e]),null==x||x([l,a,e]),A(t.startOfMonth(a)),L(!1)},[le,ae]=s(ee,Q.map((e=>e.value)),J,L,W);return h.default.createElement(r.Provider,{value:V},h.default.createElement("div",Object.assign({ref:v,className:a.twMerge(i.makeDateRangePickerClassName("root"),"relative w-full",K)},Y),h.default.createElement(m,{value:[X,Z,W],options:Q,placeholder:E,disabled:M,calendarRef:I,showCalendar:F,setShowCalendar:G,onCalendarKeyDown:e=>{"Escape"===e.key&&(e.preventDefault(),G(!1))},enableDropdown:j,dropdownRef:U,showDropdown:J,setShowDropdown:L,onDropdownKeyDown:ae,locale:B,dropdownPlaceholder:y,enableClear:O,onClear:()=>{T([null,null,null]),null==x||x([null,null,null])}}),h.default.createElement(D,{className:i.makeDateRangePickerClassName("calendarModal"),showModal:F,setShowModal:G,parentRef:I,width:288,maxHeight:"max-h-fit"},h.default.createElement(f.default,{enableYearPagination:N,anchorDate:$,startDate:X,endDate:Z,minDate:k,maxDate:R,onDateClick:e=>{X?X&&!Z?e<X?(null==x||x([e,Z,null]),T([e,Z,null])):(null==x||x([X,e,null]),T([X,e,null]),G(!1)):X&&Z&&(null==x||x([e,null,null]),T([e,null,null])):(null==x||x([e,Z,null]),T([e,Z,null]))},locale:B,setStartOfCurrMonth:A})),h.default.createElement(D,{className:i.makeDateRangePickerClassName("dropdownModal"),showModal:J,setShowModal:L,parentRef:U},h.default.createElement(u.Provider,{value:{selectedValue:W,handleValueChange:ee}},h.default.createElement(o.Provider,{value:{hoveredValue:le}},Q.map((({value:e,text:l})=>h.default.createElement(p,{key:e,value:e,text:l}))))))))}));v.displayName="DateRangePicker",module.exports=v;
