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

import { CALENDAR_FILTER_VALUE, TABS } from '../../constants';

const initialState = {
  calendar: CALENDAR_FILTER_VALUE.any,
  calendarCustom: {
    dateStart: null,
    dateEnd: null,
  },
  eventsSearch: '',
  eventsOptions: [],
  event: null,
  sessionsSearch: '',
  sessionsOptions: [],
  sessions: [],
  activeTab: TABS[0],
  users: null,
  totalMinutes: null,
  averageMinutes: null,
  averageMinutesPercent: null,
  desktop: {
    all: null,
    medium: null,
    large: null,
    xLarge: null,
  },
  mobile: {
    all: null,
    medium: null,
    small: null,
    xSmall: null,
  },
  countries: {
    all: null,
    items: [],
  },
  chartData: [],
  countriesFullList: [],
  isExportPdfLoading: false,
};

export const slice = createSlice({
  name: '@@analyticsLiveDashboard/ANALYTICS_LIVE_DASHBOARD',
  initialState,

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

    getCountriesFullListAction: (state) => state,
    getLiveEventsAction: (state) => state,
    getLiveEventByIdAction: (state) => state,
    getLivePerformanceTotalsAction: (state) => state,
    getChartDataAction: (state) => state,
    exportToPDFAction: (state) => state,
    exportToCSVAction: (state) => state,
  },
});

export const {
  setFieldAction,
  getCountriesFullListAction,
  getLiveEventsAction,
  getLiveEventByIdAction,
  getLivePerformanceTotalsAction,
  getChartDataAction,
  exportToPDFAction,
  exportToCSVAction,
} = slice.actions;

export default slice.reducer;
