import { sliceNames } from '@/src/constants/redux/redux';
import { createSlice, PayloadAction } from '@reduxjs/toolkit';



interface ModalState {
    isOpen: boolean;
    view: React.ReactNode | null;
    customSize?: {
        width: string;
    };
}

const initialState: ModalState = {
    isOpen: false,
    view: null,
    customSize: { width: '70%' },
};

const modalSlice = createSlice({
    name: sliceNames.modal,
    initialState,
    reducers: {
        openModal: (state, action: PayloadAction<{ view: React.ReactNode; customSize?: { width: string } }>) => {
            state.isOpen = true;
            state.view = action.payload.view;
            state.customSize = action.payload.customSize || state.customSize;
        },
        closeModal: (state) => {
            state.isOpen = false;
            state.view = null;
            state.customSize = { width: '70%' };
        },
    },
});

export const { openModal, closeModal } = modalSlice.actions;
export default modalSlice.reducer;
