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

const initialState = {
  account: null,
  accountOptions: null,

  menu: [],
  storedInHouseMenuSettings: {},

  selectedAnalytic: '',
  publisherName: '',
  salesforceId: '',

  isLoadingUrl: false,
  lookerReportUrl: '',

  statusOverallFailure: undefined,
  statusShowPopup: false,
  statusPopupMessage: '',
};

export const slice = createSlice({
  name: '@@analyticsGeneral/ANALYTICS',
  initialState,

  reducers: {
    setFieldAction: (state, action) => {
      Object.entries(action.payload).forEach(([key, value]) => {
        state[key] = value;
      });
    },

    getMenuItemsAction: (state) => state,
    getAccountOptionsAction: (state) => state,
    getLookerUrlAction: (state) => state,
    getStatusAction: (state) => state,
  },
});

export const { setFieldAction, getMenuItemsAction, getAccountOptionsAction, getLookerUrlAction, getStatusAction } =
  slice.actions;

export default slice.reducer;
