{"version":3,"file":"calendarReducer.cjs","sources":["../../../../../src/components/datepicker/internal/calendarReducer.ts"],"sourcesContent":["import type { Reducer } from \"react\";\n\nexport type CalendarAction =\n    | {\n          type: \"SET_SELECTED_DATE\";\n          newDate: Date;\n      }\n    | {\n          type: \"SET_OFFSET\";\n          newOffset: number;\n      }\n    | {\n          type: \"ADD_OFFSET\";\n          addedOffset: number;\n      };\n\nexport type CalendarState = {\n    selectedDate: Date;\n    offset: number;\n    shownDate: Date;\n};\n\nexport const calendarReducer: Reducer<CalendarState, CalendarAction> = (\n    currentState,\n    action,\n) => {\n    let shownDate: Date;\n\n    switch (action.type) {\n        case \"SET_OFFSET\":\n            shownDate = new Date(currentState.selectedDate);\n            shownDate.setMonth(\n                currentState.selectedDate.getMonth() + action.newOffset,\n            );\n\n            return {\n                ...currentState,\n                offset: action.newOffset,\n                shownDate,\n            };\n\n        case \"ADD_OFFSET\":\n            shownDate = new Date(currentState.selectedDate);\n            shownDate.setMonth(\n                currentState.selectedDate.getMonth() +\n                    currentState.offset +\n                    action.addedOffset,\n            );\n\n            return {\n                ...currentState,\n                offset: currentState.offset + action.addedOffset,\n                shownDate,\n            };\n\n        case \"SET_SELECTED_DATE\":\n            return calendarInitializer(action.newDate);\n\n        default:\n            return currentState;\n    }\n};\n\nexport const calendarInitializer = (initialDate: Date): CalendarState => ({\n    selectedDate: initialDate,\n    offset: 0,\n    shownDate: initialDate,\n});\n"],"names":["calendarInitializer","initialDate","selectedDate","offset","shownDate","currentState","action","type","Date","setMonth","getMonth","newOffset","addedOffset","newDate"],"mappings":"gFAsBO,MAyCMA,EAAuBC,IAAAA,CAChCC,aAAcD,EACdE,OAAQ,EACRC,UAAWH,0DA5CwD,CACnEI,EACAC,KAEA,IAAIF,EAEJ,OAAQE,EAAOC,MACX,IAAK,aACD,OAAAH,EAAY,IAAII,KAAKH,EAAaH,cAClCE,EAAUK,SACNJ,EAAaH,aAAaQ,WAAaJ,EAAOK,WAG3C,IACAN,EACHF,OAAQG,EAAOK,UACfP,UAAAA,GAGR,IAAK,aACD,OAAAA,EAAY,IAAII,KAAKH,EAAaH,cAClCE,EAAUK,SACNJ,EAAaH,aAAaQ,WACtBL,EAAaF,OACbG,EAAOM,aAGR,IACAP,EACHF,OAAQE,EAAaF,OAASG,EAAOM,YACrCR,UAAAA,GAGR,IAAK,oBACD,OAAOJ,EAAoBM,EAAOO,SAEtC,QACI,OAAOR"}