import { createSlice } from "@reduxjs/toolkit";
import getItem from "../../utils/getItem";

export const theSlice = createSlice({
  name: 'category-settings',
  initialState: {
    list: [],
    loaded: false,
  },
  reducers: {
    // section parts
    loadCategorySettings: (state, action) => {
      const data = action.payload;
      state.list = data;
      state.loaded = true;
    },
    updateCategorySetting: (state, action) => {
      const {id, data} = action.payload
      let item = getItem(id, state.list);
      Object.assign(item, data);
    },
  }
});

export const {
  loadCategorySettings,
  updateCategorySetting,
} = theSlice.actions;
export default theSlice.reducer;