import{jsxs as t,jsx as e}from"react/jsx-runtime";import{useMemo as n,useCallback as a}from"react";import r from"moment";import o from"classnames";import{Text as i}from"../../Text/Text.js";import{MonthOptions as m,isSameDay as d,isSameMonth as s,getMaxDate as l,getMinDate as u}from"../utils.js";import c from"./CalendarGrid.scss.js";var f=["Mon","Tue","Wed","Thu","Fri","Sat","Sun"],g=function(g){var v=g.activeStartDate,h=g.setHoveredDate,T=g.minDate,p=g.maxDate,D=g.tileDisabled,y=g.onChange,b=g.view,M=void 0===b?"month":b,w=g.rangeStartDate,N=g.rangeEndDate,S=g.rangeHoveredDate,x=g.selected,C=g.getTileClassName,j=g.className,O=g.testId,E="month"===M,k=r().startOf(E?"day":"month").toDate(),A=n((function(){if(E){var t=r(v).startOf("month"),e=0===t.day()?t.subtract(6,"days"):t.startOf("week").add(1,"days");return new Array(42).fill(void 0).map((function(t,n){return e.clone().add(n,"days").toDate()}))}var n=r(v).startOf("year");return new Array(12).fill(void 0).map((function(t,e){return n.clone().add(e,"months").toDate()}))}),[v,E]),H=a((function(){return null==h?void 0:h(void 0)}),[h]);return t("div",{className:o(c.root,!E&&c.yearView,j),onMouseLeave:H,"data-testid":O,children:[E&&f.map((function(t){return e(i,{size:14,className:c.dow,children:t},t)})),A.map((function(t){var n=E?d:s,a={activeStartDate:v,date:t},r=T&&t.getTime()<(null==T?void 0:T.getTime())||p&&t.getTime()>(null==p?void 0:p.getTime())||!(null==D||!D(a)),i=!!E&&t.getMonth()!==v.getMonth(),f=n(k,t),g=n(t,x)||n(t,w)||n(t,N),b=l(N||S,w),j=u(N||S,w),O=n(j,t),A=n(b,t),H=j&&b&&j.getTime()<t.getTime()&&b.getTime()>t.getTime(),z=O||A||H;return e("button",{className:o(c.button,!E&&c.monthButton,r&&c.disabled,i&&c.neighbourMonth,f&&c.today,g&&c.selected,z&&c.range,O&&c.rangeStart,A&&c.rangeEnd,null==C?void 0:C(a)),disabled:r,onClick:function(){return y(t)},onMouseEnter:h?function(){return h(t)}:void 0,children:e("span",{className:c.buttonContent,children:"month"===M?t.getDate():m[t.getMonth()].fullTitle})},"".concat(v.getTime(),"-").concat(t.getTime()))}))]})};export{g as CalendarGrid};
//# sourceMappingURL=CalendarGrid.js.map
