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

const initialState = {
  query: '',
  fromSuggester: false,
  playlistType: '',
  searchSuggester: null,
  suggesterOptions: [],
};

export const slice = createSlice({
  name: '@@editorialSearch/EDITORIAL_SEARCH',
  initialState,
  reducers: {
    queryAction: (state, action) => {
      state.query = action.payload || initialState.query;
    },
    playlistTypeAction: (state, action) => {
      state.playlistType = action.payload || initialState.playlistType;
    },
    searchSuggesterAction: (state, action) => {
      state.searchSuggester = action.payload || initialState.searchSuggester;
    },
    searchFromSuggesterAction: (state, action) => {
      state.fromSuggester = action.payload || initialState.fromSuggester;
    },
    suggesterOptionsAction: (state, action) => {
      state.suggesterOptions = action.payload || initialState.suggesterOptions;
    },
    clearAction: (state) => {
      Object.keys(initialState.createForm).forEach((key) => {
        state.createForm[key] = initialState.createForm[key];
      });
    },
    showUploaderAction: (state) => state,
    searchEventAction: (state) => state,
  },
});

export const {
  queryAction,
  playlistTypeAction,
  searchSuggesterAction,
  searchFromSuggesterAction,
  suggesterOptionsAction,
  clearAction,
  showUploaderAction,
  searchEventAction,
} = slice.actions;
