import { FILTERS_LIST } from '../../constants';

import { slice } from '../slices';

const nameSpace = slice.name;

export const nameSelector = (state$) => state$[nameSpace].name;
export const periodSelector = (state$) => state$[nameSpace].period;
export const periodCustomStartDateSelector = (state$) => state$[nameSpace].periodCustomStartDate;
export const periodCustomEndDateSelector = (state$) => state$[nameSpace].periodCustomEndDate;
export const scheduleTypeSelector = (state$) => state$[nameSpace].scheduleType;
export const scheduleDaySelector = (state$) => state$[nameSpace].scheduleDay;
export const scheduleTimeSelector = (state$) => state$[nameSpace].scheduleTime;
export const recipientsSelector = (state$) => state$[nameSpace].recipients;
export const dimensionsListSelector = (state$) => state$[nameSpace].dimensionsList;
export const checkedMetricsSelector = (state$) => state$[nameSpace].checkedMetrics;
export const checkedDimensionsSelector = (state$) => state$[nameSpace].checkedDimensions;
export const isReadOnlySelector = (state$) => state$[nameSpace].isReadOnly;
export const isDownloadingSelector = (state$) => state$[nameSpace].isDownloading;
export const isLoadingSelector = (state$) => state$[nameSpace].isLoading;
export const searchTextSelector = (state$) => state$[nameSpace].searchText;
export const pageSelector = (state$) => state$[nameSpace].page;
export const pageSizeSelector = (state$) => state$[nameSpace].pageSize;
export const sortBySelector = (state$) => state$[nameSpace].sortBy;
export const sortOrderSelector = (state$) => state$[nameSpace].sortOrder;
export const recordsSelector = (state$) => state$[nameSpace].records;
export const recordsTotalSelector = (state$) => state$[nameSpace].recordsTotal;
export const downloadReportTryRequestCounterSelector = (state$) => state$[nameSpace].downloadReportTryRequestCounter;

export const filtersSelector = (state$) => {
  const state = state$[nameSpace];

  return FILTERS_LIST.reduce(
    (acc, cur) => ({
      ...acc,
      [`${cur.name}_FILTER_VALUES`]: state[`${cur.name}_FILTER_VALUES`],
      [`${cur.name}_FILTER_OPTIONS`]: state[`${cur.name}_FILTER_OPTIONS`],
      [`${cur.name}_FILTER_ACTION`]: state[`${cur.name}_FILTER_ACTION`],
    }),
    {},
  );
};
