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

const initialState = {
  keywordType: '',
  keywordList: [],
  keywordListLoading: false,
  keywordSearchPrefix: '',

  labelType: '',
  labelList: [],
  labelListLoading: false,
  labelSearchPrefix: '',

  feedDescriptionType: '',
  feedDescriptionList: [],
  feedDescriptionListLoading: false,
  feedDescriptionSearchPrefix: '',

  accountType: '',
  accountList: [],
  accountListLoading: false,
  accountSearchPrefix: '',

  hubsType: '',
  hubsList: [],
  hubsListLoading: false,
  hubsSearchPrefix: '',

  accountGetOwners: '',
};

export const slice = createSlice({
  name: '@@editorialSearchFilterSuggester/EDITORIAL_SEARCH_FILTER_SUGGESTER',
  initialState,
  reducers: {
    keywordTypeAction: (state, action) => {
      state.keywordType = action.payload || initialState.keywordType;
    },
    keywordListAction: (state, action) => {
      state.keywordList = action.payload || initialState.keywordList;
    },
    keywordListLoadingAction: (state, action) => {
      state.keywordListLoading = action.payload || initialState.keywordListLoading;
    },
    keywordSearchPrefixAction: (state, action) => {
      state.keywordSearchPrefix = action.payload || initialState.keywordSearchPrefix;
    },
    labelTypeAction: (state, action) => {
      state.labelType = action.payload || initialState.labelType;
    },
    labelListAction: (state, action) => {
      state.labelList = action.payload || initialState.labelList;
    },
    labelListLoadingAction: (state, action) => {
      state.labelListLoading = action.payload || initialState.labelListLoading;
    },
    labelSearchPrefixAction: (state, action) => {
      state.labelSearchPrefix = action.payload || initialState.labelSearchPrefix;
    },
    feedDescriptionTypeAction: (state, action) => {
      state.feedDescriptionType = action.payload || initialState.feedDescriptionType;
    },
    feedDescriptionListAction: (state, action) => {
      state.feedDescriptionList = action.payload || initialState.feedDescriptionList;
    },
    feedDescriptionListLoadingAction: (state, action) => {
      state.feedDescriptionListLoading = action.payload || initialState.feedDescriptionListLoading;
    },
    feedDescriptionSearchPrefixAction: (state, action) => {
      state.feedDescriptionSearchPrefix = action.payload || initialState.feedDescriptionSearchPrefix;
    },
    accountTypeAction: (state, action) => {
      state.accountType = action.payload || initialState.accountType;
    },
    accountListAction: (state, action) => {
      state.accountList = action.payload || initialState.accountList;
    },
    accountListLoadingAction: (state, action) => {
      state.accountListLoading = action.payload || initialState.accountListLoading;
    },
    accountSearchPrefixAction: (state, action) => {
      state.accountSearchPrefix = action.payload || initialState.accountSearchPrefix;
    },
    accountGetOwnersAction: (state, action) => {
      state.accountGetOwners = action.payload || initialState.accountGetOwners;
    },
    hubsTypeAction: (state, action) => {
      state.hubsType = action.payload || initialState.hubsType;
    },
    hubsListAction: (state, action) => {
      state.hubsList = action.payload || initialState.hubsList;
    },
    hubsListLoadingAction: (state, action) => {
      state.hubsListLoading = action.payload || initialState.hubsListLoading;
    },
    hubsSearchPrefixAction: (state, action) => {
      state.hubsSearchPrefix = action.payload || initialState.hubsSearchPrefix;
    },
    clearAction: (state) => {
      Object.keys(initialState).forEach((key) => {
        state[key] = initialState[key];
      });
    },
  },
});

export const {
  keywordTypeAction,
  keywordListAction,
  keywordListLoadingAction,
  keywordSearchPrefixAction,
  labelTypeAction,
  labelListAction,
  labelListLoadingAction,
  labelSearchPrefixAction,
  feedDescriptionTypeAction,
  feedDescriptionListAction,
  feedDescriptionListLoadingAction,
  feedDescriptionSearchPrefixAction,
  accountTypeAction,
  accountListAction,
  accountListLoadingAction,
  accountSearchPrefixAction,
  accountGetOwnersAction,
  hubsTypeAction,
  hubsListAction,
  hubsListLoadingAction,
  hubsSearchPrefixAction,
  clearAction,
} = slice.actions;
