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

const popupSlice = createSlice({
  name: "popup",
  initialState: {
    isOpen: false,
    isOpenCompatibilityModal: false,
    isSuccess: true,
    title: "Notification",
    message: "",
    buttonText: "Close",
    hasRightButton: false,
    rightButtonText: "Confirm",
    rightButtonAction: "",
  },
  reducers: {
    openPopup: (state, action: PayloadAction<any>) => {
      return {
        ...state,
        isOpen: true,
        isSuccess: action.payload?.isSuccess ?? true,
        title: action.payload?.title ?? "Notification",
        message: action.payload?.message,
        buttonText: action.payload?.buttonText ?? "Close",
        hasRightButton: action.payload?.hasRightButton ?? false,
        rightButtonText: action.payload?.rightButtonText ?? "Confirm",
        rightButtonAction: action.payload?.rightButtonAction ?? "",
      };
    },
    closePopup: (state) => {
      state.isOpen = false;
    },
    openCompatibilityModal: (state) => {
      state.isOpenCompatibilityModal = true;
    },
    closeCompatibilityModal: (state) => {
      state.isOpenCompatibilityModal = false;
    },
  },
});

export const {
  openPopup,
  closePopup,
  openCompatibilityModal,
  closeCompatibilityModal,
} = popupSlice.actions;
export default popupSlice.reducer;
