import {createSlice} from '@reduxjs/toolkit'

const initialState = {
    searchText: '',
    currentPage: 1,
    pageSize: 10,
    selectedSet: null,
    isModalVisible: false,
};

const setsSlice = createSlice({
    name: 'setsUI',
    initialState,
    reducers: {
        setSearchText: (state, action) => {
            state.searchText = action.payload;
        },
        setCurrentPage: (state, action) => {
            state.currentPage = action.payload;
        },
        setPageSize: (state, action) => {
            state.pageSize = action.payload;
        },
        openModal: (state) => {
            state.isModalVisible = true;
        },
        closeModal: (state) => {
            state.isModalVisible = false;
            state.selectedSet = null;
        },
        selectSet: (state, action) => {
            state.selectedSet = action.payload;
        }
    }
});

export const {
    selectSet,
    setSearchText,
    setCurrentPage,
    setPageSize,
    openModal,
    closeModal
} = setsSlice.actions;

export default setsSlice.reducer;