import { WIDGET_DISPLAY_STATE_ERROR, WIDGET_DISPLAY_STATE_NO_DATA } from '@/modules/analytics/common/constants';

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

const nameSpace = slice.name;

export const hubSelector = (state$) => state$[nameSpace].hub;
export const hubOptionsSelector = (state$) => state$[nameSpace].hubOptions;
export const watchSelector = (state$) => state$[nameSpace].watch;
export const watchOptionsSelector = (state$) => state$[nameSpace].watchOptions;
export const watchChannelSelector = (state$) => state$[nameSpace].watchChannel;
export const watchChannelOptionsSelector = (state$) => state$[nameSpace].watchChannelOptions;
export const originSelector = (state$) => state$[nameSpace].origin;
export const calendarSelector = (state$) => state$[nameSpace].calendar;
export const calendarCustomSelector = (state$) => state$[nameSpace].calendarCustom;
export const includeArchivedSelector = (state$) => state$[nameSpace].includeArchived;
export const activeTabIdSelector = (state$) => state$[nameSpace].activeTabId;
export const totalSelector = (state$) => state$[nameSpace].total;
export const topSearchesSelector = (state$) => state$[nameSpace].topSearches;
export const tableItemsSelector = (state$) => state$[nameSpace].tableItems;
export const searchSelector = (state$) => state$[nameSpace].search;
export const searchOptionsSelector = (state$) => state$[nameSpace].searchOptions;
export const sortBySelector = (state$) => state$[nameSpace].sortBy;
export const sortOrderSelector = (state$) => state$[nameSpace].sortOrder;
export const metricsSelector = (state$) => state$[nameSpace].metrics;
export const metricViewsSelector = (state$) => state$[nameSpace].metricViews;
export const metricAttentionSpanSelector = (state$) => state$[nameSpace].metricAttentionSpan;
export const metricSearchesSelector = (state$) => state$[nameSpace].metricSearches;
export const selectedItemIdSelector = (state$) => state$[nameSpace].selectedItemId;
export const activeMetricSelector = (state$) => state$[nameSpace].activeMetric;
export const itemMetricsSelector = (state$) => state$[nameSpace].itemMetrics;
export const displayStateMainMetricsSelector = (state$) => state$[nameSpace].displayStateMainMetrics;
export const displayStateTopSearchesSelector = (state$) => state$[nameSpace].displayStateTopSearches;
export const displayStateTopVideosSelector = (state$) => state$[nameSpace].displayStateTopVideos;
export const isExportCsvLoadingSelector = (state$) => state$[nameSpace].isExportCsvLoading;
export const isExportPdfLoadingSelector = (state$) => state$[nameSpace].isExportPdfLoading;

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

  return [state.displayStateMainMetrics, state.displayStateTopSearches, state.displayStateTopVideos].every(
    (o) => o === WIDGET_DISPLAY_STATE_NO_DATA,
  );
};

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

  return [state.displayStateMainMetrics, state.displayStateTopSearches, state.displayStateTopVideos].every(
    (o) => o === WIDGET_DISPLAY_STATE_ERROR,
  );
};
