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

import { CONTEXT_OPEN_IN_VIDEO_EDIT_TAGS } from '../../constants';

const initialState = {
  // States for SelectCreateCategory logic
  selectedCategory: null,
  customCategoriesOptions: null,
  // States for SelectCreateTag logic,
  selectedTag: null,
  tagsOptions: null,
  // presave from props
  openContext: CONTEXT_OPEN_IN_VIDEO_EDIT_TAGS,
};

export const slice = createSlice({
  name: '@@tagEditor',
  initialState,
  reducers: {
    setStateAction: (state, action) => {
      Object.keys(action.payload).forEach((key) => {
        state[key] = action.payload[key];
      });
    },
    clearAction: () => initialState,
    getCustomCategoriesOptionsAction: (state) => state,
    createCustomCategoryAction: (state) => state,
    editCustomCategoryAction: (state) => state,
    getCustomTagsOptionsAction: (state) => state,
    getCustomTagsWithCategoryOptionsAction: (state) => state,
    getSystemTagsOptionsAction: (state) => state,
    createSystemTagAction: (state) => state,
  },
});

export const {
  setStateAction,
  clearAction,
  getCustomCategoriesOptionsAction,
  createCustomCategoryAction,
  editCustomCategoryAction,
  getCustomTagsOptionsAction,
  getCustomTagsWithCategoryOptionsAction,
  getSystemTagsOptionsAction,
  createSystemTagAction,
} = slice.actions;
