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

const initialState = {
  location: null,
  addQueries: { key: null, value: null },
  removeQueries: '',
};

export const slice = createSlice({
  name: '@@COMMON/LOCATION',
  initialState,

  reducers: {
    locationLoadedEventAction: (state) => state,
    locationChangedEventAction: (state) => state,
    locationAction: (state, action) => {
      state.location = action.payload || initialState.location;
    },
    addQueriesAction: (state, action) => {
      state.addQueries = action.payload || initialState.addQueries;
    },
    removeQueriesAction: (state, action) => {
      state.removeQueries = action.payload || initialState.removeQueries;
    },
  },
});

export const {
  addQueriesAction,
  locationAction,
  locationChangedEventAction,
  locationLoadedEventAction,
  removeQueriesAction,
} = slice.actions;

export default slice.reducer;
