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

//로그인 정보
const loginUser = createSlice({
    name: 'createSlice',
    initialState: {},
    reducers: {
        setLoginUser(stats, action) {
            for (let key in action.payload) {
                stats[key] = action.payload[key];
            }
        }
    }
})
//로그인 정보 변경
const { setLoginUser } = loginUser.actions;


//특정 로그인 유저의 대상자(시니어)목록 정보
const seniorList = createSlice({
    name: 'createSlice',
    initialState: {value: []},
    reducers: {
        setSeniorList(stats, action) {
          //console.log("seniorList createSlice stats.value : ", stats.value, ", action.payload.value : ", action.payload.value);
          stats.value = action.payload.value;
        }
    }
})
//특정 로그인 유저의 대상자(시니어)목록 정보 변경
const { setSeniorList } = seniorList.actions;


//특정 로그인 유저가 지정한 조회 할 대상자(시니어) Index
const currentSeniorIndex = createSlice({
    name: 'createSlice',
    initialState: {value: 0},
    reducers: {
        setCurrentSeniorIndex(stats, action) {
            /* for (let key in action.payload) {
                stats[key] = action.payload[key];
            } */
            //console.log("stats : ", stats.value, ", action.payload : ", action.payload.value);
            stats.value = action.payload.value;
        }
    }
})
//특정 로그인 유저가 지정한 조회 할 대상자(시니어) Index 변경
const { setCurrentSeniorIndex } = currentSeniorIndex.actions;

export default configureStore({
    reducer: {
        loginUser: loginUser.reducer,
        seniorList: seniorList.reducer,
        currentSeniorIndex: currentSeniorIndex.reducer,
    }
})

export { setLoginUser, setSeniorList, setCurrentSeniorIndex };