import { createSlice, PayloadAction } from "@reduxjs/toolkit";

const loadingSlice = createSlice({
  name: "loading",
  initialState: {
    isLoading: false,
    isSmallLoading: false,
    message: "Loading ...",
  },
  reducers: {
    startLoading: (state, action: PayloadAction<any>) => {
      console.log("Setting animation enabled state to: ", action.payload);
      return {
        ...state,
        isLoading: true,
        message: action.payload?.message ?? "Loading ...",
      };
    },
    stopLoading: (state) => {
      state.isLoading = false;
    },
    startSmallLoading: (state) => {
      state.isSmallLoading = true;
    },
    stopSmallLoading: (state) => {
      state.isSmallLoading = false;
    },
  },
});

export const {
  startLoading,
  stopLoading,
  startSmallLoading,
  stopSmallLoading,
} = loadingSlice.actions;
export default loadingSlice.reducer;
