import{slicedToArray as e,defineProperty as t}from"../../_virtual/_rollupPluginBabelHelpers.js";import{jsx as n,jsxs as i,Fragment as a}from"react/jsx-runtime";import{forwardRef as o,useState as r,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 l,DayPickerSingleDateController as m}from"react-dates";import u from"./DatePickerHeader/DatePickerHeader.js";import f from"./DateNavigationItem/DateNavigationItem.js";import p from"./YearPicker/YearPicker.js";import{WEEK_FIRST_DAY as h,DAY_SIZE as v}from"./constants.js";import{FocusInput as y,Direction as D}from"./types.js";import{getTestId as k}from"../../tests/testIds.js";import{ComponentDefaultTestId as g}from"../../tests/constants.js";import{NOOP as b}from"../../utils/function-utils.js";import j from"./DatePicker.module.scss.js";import O from"../Button/Button.js";import C from"../../storybook/stand-alone-documentaion/typography/Typography.js";import{TypographyTypes as E,TypographySizes as P}from"../../storybook/stand-alone-documentaion/typography/TypographyConstants.js";var N=o((function(o,N){var A,B=o.id,M=o.className,T=o.firstDayOfWeek,I=void 0===T?h:T,R=o.daySize,S=void 0===R?v:R,z=o.range,L=void 0!==z&&z,Y=o.shouldBlockDay,K=o.shouldBlockYear,W=o.numberOfMonths,x=void 0===W?1:W,_=o.hideNavigationKeys,F=void 0!==_&&_,H=o.date,w=o.endDate,V=o.onPickDate,q=o.enableOutsideDays,G=void 0!==q&&q,J=o.showWeekNumber,Q=void 0!==J&&J,U=o.shouldBlockRange,X=o["data-testid"],Z=o.kind,$=void 0===Z?"primary":Z,ee=o.onClear,te=o.onApply,ne=o.buttonFooter,ie=void 0===ne||ne,ae=r(y.startDate),oe=e(ae,2),re=oe[0],se=oe[1],de=r(!1),ce=e(de,2),le=ce[0],me=ce[1],ue=r(null),fe=e(ue,2),pe=fe[0],he=fe[1],ve=s((function(e){var t=e.month;return n(u,{"data-testid":X||k(g.DATEPICKER_HEADER,B),currentDate:t||c(),isMonthYearSelection:le,onToggleMonthYearPicker:function(){return me((function(e){return!e}))},hideNavigationKeys:F})}),[X,le,F,B]),ye=s((function(e){var t=0===I?e.clone().add(1,"d").isoWeek():e.isoWeek();return i(a,{children:[n("span",Object.assign({className:j.calendarDayWeekNumber},{children:t}))," ",e.format("D")]})}),[I]),De=s((function(e){he(e),me(!1)}),[]),ke=s((function(){return n(p,{"data-testid":X||k(g.DATEPICKER_YEAR_SELECTION,B),selectedDate:H,isYearBlocked:K,changeCurrentDate:De})}),[X,K,De,H,B]),ge=s((function(e){V(re===y.startDate?Object.assign(Object.assign({},e),{endDate:null}):e)}),[re,V]),be=s((function(e){se(e||y.startDate)}),[]),je=!F&&!le;return i("div",Object.assign({"data-testid":X||k(g.DATEPICKER,B),ref:N,id:B,className:d(j.datepickerContainer,M,(A={},t(A,j.withWeekNumber,Q),t(A,j.rangePickerMode,L),t(A,j.noRange,H===w),t(A,j.monthYearSelection,le),t(A,j.kindSecondary,"secondary"===$),A))},{children:[L?n(l,{renderDayContents:Q?ye:void 0,firstDayOfWeek:I,hideKeyboardShortcutsPanel:!0,startDate:H,endDate:w,onDatesChange:ge,focusedInput:re,minimumNights:0,onFocusChange:be,navPrev:je?n(f,{kind:D.prev}):n("div",{}),navNext:je?n(f,{kind:D.next}):n("div",{}),daySize:S,isOutsideRange:U,isDayBlocked:Y,renderMonthElement:ve,enableOutsideDays:G||Q,numberOfMonths:x,initialVisibleMonth:function(){return pe||H||c()}},"".concat(null==pe?void 0:""+pe)):n(m,{renderDayContents:Q?ye:void 0,firstDayOfWeek:I,hideKeyboardShortcutsPanel:!0,onFocusChange:b,numberOfMonths:x,date:H,onDateChange:function(e){return V(e)},navPrev:je?n(f,{kind:D.prev}):n("div",{}),navNext:je?n(f,{kind:D.next}):n("div",{}),focused:!0,renderMonthElement:ve,enableOutsideDays:G||Q,daySize:S,isDayBlocked:Y,initialVisibleMonth:function(){return pe||H||c()}},"".concat(null==pe?void 0:""+pe)),le&&ke(),i("div",Object.assign({className:d(j.footer,t({},j.showFooter,H&&ie))},{children:[n(O,Object.assign({size:O.sizes.SMALL,kind:O.kinds.TERTIARY,onClick:function(){L&&se(y.startDate),ee()}},{children:n("div",Object.assign({className:j.footerButton},{children:n(C,{value:"Clear",type:E.LABEL,size:P.sm})}))})),n(O,Object.assign({size:O.sizes.SMALL,onClick:te},{children:n("div",Object.assign({className:j.footerButton},{children:n(C,{value:"Apply",type:E.LABEL,size:P.sm})}))}))]}))]}))}));Object.assign(N,{defaultTestId:g.DATEPICKER});var A=N;export{A as default};
