import { createSlice } from '@reduxjs/toolkit';

const initialState = {
    sortOrder: 'asc',
    viewMode: 'tile',
    isModalVisible: false,
    selectedPatient: null,
    currentPage: 1,
    pageSize: 10,
};

const patientsSlice = createSlice({
    name: 'patientsUI',
    initialState,
    reducers: {
        setSortOrder(state, action) {
            state.sortOrder = action.payload;
        },
        setViewMode(state, action) {
            state.viewMode = action.payload;
        },
        openModal(state) {
            state.isModalVisible = true;
        },
        closeModal(state) {
            state.isModalVisible = false;
        },
        selectPatient(state, action) {
            state.selectedPatient = action.payload;
        },
        setCurrentPage(state, action) {
            state.currentPage = action.payload;
        },
        setPageSize(state, action) {
            state.pageSize = action.payload;
        },
    },
});

export const {
    setSortOrder,
    setViewMode,
    openModal,
    closeModal,
    selectPatient,
    setCurrentPage,
    setPageSize,
} = patientsSlice.actions;

export default patientsSlice.reducer;