import{slicedToArray as e,defineProperty as t}from"../../_virtual/_rollupPluginBabelHelpers.js";import{jsx as n,jsxs as a,Fragment as i}from"react/jsx-runtime";import{forwardRef as r,useState as o,useCallback as s}from"react";import d from"classnames";import c from"moment";import"react-dates/initialize";import"react-dates/lib/css/_datepicker.css";import{DayPickerRangeController as u,DayPickerSingleDateController as m}from"react-dates";import l from"./DatePickerHeader/DatePickerHeader.js";import f from"./DateNavigationItem/DateNavigationItem.js";import D from"./YearPicker/YearPicker.js";import{WEEK_FIRST_DAY as v,DAY_SIZE as h}from"./constants.js";import{FocusInput as k,Direction as p}from"./types.js";import{getTestId as y}from"../../tests/testIds.js";import{ComponentDefaultTestId as g}from"../../tests/constants.js";import{NOOP as b}from"../../utils/function-utils.js";import P from"./DatePicker.module.scss.js";var j=r((function(r,j){var O,E=r.id,N=r.className,C=r.firstDayOfWeek,I=void 0===C?v:C,M=r.daySize,R=void 0===M?h:M,S=r.range,K=void 0!==S&&S,T=r.shouldBlockDay,W=r.shouldBlockYear,Y=r.numberOfMonths,A=void 0===Y?1:Y,B=r.hideNavigationKeys,x=void 0!==B&&B,_=r.date,z=r.endDate,H=r.onPickDate,w=r.enableOutsideDays,F=void 0!==w&&w,V=r.showWeekNumber,L=void 0!==V&&V,q=r.shouldBlockRange,G=r["data-testid"],J=r.kind,Q=void 0===J?"primary":J,U=o(k.startDate),X=e(U,2),Z=X[0],$=X[1],ee=o(!1),te=e(ee,2),ne=te[0],ae=te[1],ie=o(null),re=e(ie,2),oe=re[0],se=re[1],de=s((function(e){var t=e.month;return n(l,{"data-testid":G||y(g.DATEPICKER_HEADER,E),currentDate:t||c(),isMonthYearSelection:ne,onToggleMonthYearPicker:function(){return ae((function(e){return!e}))},hideNavigationKeys:x})}),[G,ne,x,E]),ce=s((function(e){var t=0===I?e.clone().add(1,"d").isoWeek():e.isoWeek();return a(i,{children:[n("span",Object.assign({className:P.calendarDayWeekNumber},{children:t}))," ",e.format("D")]})}),[I]),ue=s((function(e){se(e),ae(!1)}),[]),me=s((function(){return n(D,{"data-testid":G||y(g.DATEPICKER_YEAR_SELECTION,E),selectedDate:_,isYearBlocked:W,changeCurrentDate:ue})}),[G,W,ue,_,E]),le=s((function(e){H(Z===k.startDate?Object.assign(Object.assign({},e),{endDate:null}):e)}),[Z,H]),fe=s((function(e){$(e||k.startDate)}),[]),De=!x&&!ne;return a("div",Object.assign({"data-testid":G||y(g.DATEPICKER,E),ref:j,id:E,className:d(P.datepickerContainer,N,(O={},t(O,P.withWeekNumber,L),t(O,P.rangePickerMode,K),t(O,P.noRange,_===z),t(O,P.monthYearSelection,ne),t(O,P.kindSecondary,"secondary"===Q),O))},{children:[K?n(u,{renderDayContents:L?ce:void 0,firstDayOfWeek:I,hideKeyboardShortcutsPanel:!0,startDate:_,endDate:z,onDatesChange:le,focusedInput:Z,minimumNights:0,onFocusChange:fe,navPrev:De?n(f,{kind:p.prev}):n("div",{}),navNext:De?n(f,{kind:p.next}):n("div",{}),daySize:R,isOutsideRange:q,isDayBlocked:T,renderMonthElement:de,enableOutsideDays:F||L,numberOfMonths:A,initialVisibleMonth:function(){return oe||_||c()}},"".concat(null==oe?void 0:""+oe)):n(m,{renderDayContents:L?ce:void 0,firstDayOfWeek:I,hideKeyboardShortcutsPanel:!0,onFocusChange:b,numberOfMonths:A,date:_,onDateChange:function(e){return H(e)},navPrev:De?n(f,{kind:p.prev}):n("div",{}),navNext:De?n(f,{kind:p.next}):n("div",{}),focused:!0,renderMonthElement:de,enableOutsideDays:F||L,daySize:R,isDayBlocked:T,initialVisibleMonth:function(){return oe||_||c()}},"".concat(null==oe?void 0:""+oe)),ne&&me()]}))}));Object.assign(j,{defaultTestId:g.DATEPICKER});var O=j;export{O as default};
