import { Filter } from "@/services/types";
import { createSlice } from "@reduxjs/toolkit/react";
import { format } from "date-fns";

const filterSlice = createSlice({
    name: "filter",
    initialState: {
        filter: {
            start_date: format(new Date(new Date().getFullYear(), new Date().getMonth(), 1), "yyyy-MM-dd"),
            end_date: format(new Date(), "yyyy-MM-dd"),
        } as Filter,
    },
    reducers: {
        setFilter(state, action) {
        state.filter = action.payload;
        },
    },
});
export const { setFilter } = filterSlice.actions;
export default filterSlice.reducer;