"use strict";const e=require("react/jsx-runtime"),l=require("react"),j=require("../global.module.cjs"),T=require("../tools/icons.cjs"),a=require("../tools/tools.cjs"),q=require("../lite.cjs"),Y=new Date,I=function(R){const{as:_="div",bottomContent:C,className:N,disabled:o,dropOldClass:S,events:m,forceRows:h,initialMonth:F,initialYear:L,locale:d,onDateClick:u,onMonthChange:x,readOnly:p,selectedDate:v,style:f,topContent:w,variables:M,weekDays:g,weekStartsOn:y,...W}=R,[i,$]=l.useState(L??Y.getFullYear()),[c,P]=l.useState(F??Y.getMonth()),[n,D]=l.useState(null),[A,O]=l.useState(a.generateCalendar(i,c,m,h,y,g,v,d)),B=l.useMemo(()=>{const s=a.classx(!S&&"card card-body px-0 py-2",N),r=a.stylex((t,b)=>({tKey:a.convertBsKeyToVar(b)}),M,f);return{className:s,style:r}},[N,S,f,M]),k=l.useCallback(s=>{if(o)return;D(null);const r=new Date(i,c+s);$(r.getFullYear()),P(r.getMonth()),!p&&(x==null||x(r.getFullYear(),r.getMonth()))},[c,i,o,x,p]),K=l.useCallback(s=>{if(o)return;const r={...s,active:!0};D(n&&n.date.toISOString()===r.date.toISOString()?null:r),O(t=>a.updateCalendarActiveState(r,t)),!p&&(u==null||u(r))},[n,o,u,p]);return l.useEffect(()=>{O(a.generateCalendar(i,c,m,h,y,g,v,d))},[c,i,m,h,d,v,g,y]),e.jsxs(_,{...W,...B,children:[w&&w,e.jsxs("div",{className:"list-group border-0 row-gap-1 px-3",children:[e.jsxs("div",{className:"row align-items-center position-relative text-center mb-2",children:[e.jsx("div",{className:"col px-1",onClick:()=>k(-1),children:e.jsx("div",{className:a.classxWithOptions(null,"user-select-none list-group-item list-group-item-action border-0 px-0 py-1 rounded text-secondary",o?"disabled":j.treeStyles.brlCursorPointer),children:e.jsx(T.BiChevronLeft,{})})}),e.jsx("div",{className:"col px-1"}),e.jsx("div",{className:"col px-1"}),e.jsx("div",{className:"col px-1"}),e.jsx("div",{className:"col px-1"}),e.jsx("div",{className:"col px-1"}),e.jsx("div",{className:"col px-1",onClick:()=>k(1),children:e.jsx("div",{className:a.classxWithOptions(null,"user-select-none list-group-item list-group-item-action border-0 px-0 py-1 rounded text-secondary",o?"disabled":j.treeStyles.brlCursorPointer),children:e.jsx(T.BiChevronRight,{})})}),e.jsx("div",{className:"position-absolute top-50 start-50 translate-middle w-auto text-nowrap",children:q.format(new Date(i,c),"MMMM yyyy",{locale:d})})]}),A.rows.map((s,r)=>e.jsx("div",{className:"row text-center",children:s.map((t,b)=>r===0?e.jsx("div",{className:"col px-1",children:e.jsx("div",{className:"list-group-item border-0 px-0 py-1 rounded text-body-secondary",children:t.value})},`${t.value}${b}`):e.jsx("div",{className:"col px-1",onClick:()=>K(t),children:e.jsxs("div",{className:a.classxWithOptions(null,"list-group-item list-group-item-action px-0 py-1 rounded",o?"disabled":j.treeStyles.brlCursorPointer,!t.isCurrentMonth&&!t.active&&"text-body-tertiary",t.active&&"active",t.isToday?"border-secondary-subtle":t.events&&t.events.length>0?t.active?"border-primary":"border-danger-subtle":"border-0"),children:[q.format(t.date,"d",{locale:d}),t.active&&t.events&&t.events.length>0&&e.jsx("span",{className:"text-danger",children:"•"})]})},t.date.toISOString()))},r))]}),e.jsx("div",{className:"px-2",children:n&&n.events&&n.events.length>0&&e.jsx("ul",{className:a.classxWithOptions(null,"list-group list-group-flush border-top-0 mt-3 overflow-y-auto",n.events.length>1&&"list-group-numbered"),style:{maxHeight:120},children:n.events.map((s,r)=>e.jsxs("li",{className:"list-group-item d-flex justify-content-between align-items-start border-bottom-0",children:[e.jsxs("div",{className:"ms-2 me-auto",children:[e.jsx("div",{className:"fw-bold",children:s.title}),s.description&&e.jsx("div",{children:s.description}),s.endTime&&e.jsx("div",{className:"small text-body-secondary mt-2",children:new Date(s.endTime).toLocaleTimeString()})]}),s.allDay?e.jsx("span",{className:"small text-primary-emphasis text-center",children:"All Day"}):e.jsx(e.Fragment,{children:s.startTime&&e.jsx("span",{className:"small text-body-secondary",children:new Date(s.startTime).toLocaleTimeString()})})]},`${s.id??r}-${n.date.toISOString()}`))})}),C&&C]})};I.displayName="BRL.Calendar";exports.Calendar=I;
//# sourceMappingURL=calendar.cjs.map
