import { TABLE_REDUX_FIELD_NAME } from '../../constants';
import { SORT_ASC, SORT_DESC } from '@/modules/@common/constants/sort';

import type { DataRecordsType } from '../../types';

import { slice } from '../slices';
import createTableSelector from '@/modules/@common/Table/redux/selectors';

import type { RootState } from '@/modules/@common/store/store';

type OrderType = typeof SORT_ASC | typeof SORT_DESC;

const nameSpace = slice.name;
// table
export const tableSelectors = createTableSelector(TABLE_REDUX_FIELD_NAME, nameSpace);

export const dataSelector = (state: RootState) => tableSelectors.dataSelector(state) as DataRecordsType;
export const pageSelector = (state: RootState) => tableSelectors.pageSelector(state) as number;
export const pageSizeSelector = (state: RootState) => tableSelectors.pageSizeSelector(state) as number;
export const totalCountSelector = (state: RootState) => tableSelectors.totalCountSelector(state) as number;
export const sortBySelector = (state: RootState) => tableSelectors.sortBySelector(state) as string;
export const sortOrderSelector = (state: RootState) => tableSelectors.sortOrderSelector(state) as OrderType;
export const isLoadingSelector = (state: RootState) => tableSelectors.isLoadingSelector(state) as boolean;
export const selectedSelector = (state: RootState) => tableSelectors.selectedSelector(state) as number[];

export const adFormatSelector = (state: RootState) => state[nameSpace].adFormat;
export const periodSelector = (state: RootState) => state[nameSpace].period;

export const customDateFromSelector = (state: RootState) => state[nameSpace].customDateFrom;
export const customDateToSelector = (state: RootState) => state[nameSpace].customDateTo;

export const devicesSelector = (state: RootState) => state[nameSpace].devices;

export const demandSourcesSelector = (state: RootState) => state[nameSpace].demandSources;
export const demandSourcesOptionsSelector = (state: RootState) => state[nameSpace].demandSourcesOptions;

export const playersSelector = (state: RootState) => state[nameSpace].players;
export const playersOptionsSelector = (state: RootState) => state[nameSpace].playersOptions;

export const domainsSelector = (state: RootState) => state[nameSpace].domains;
export const domainsOptionsSelector = (state: RootState) => state[nameSpace].domainsOptions;

export const countriesFullListSelector = (state: RootState) => state[nameSpace].countriesFullList;
export const countriesSelector = (state: RootState) => state[nameSpace].countries;
export const countriesOptionsSelector = (state: RootState) => state[nameSpace].countriesOptions;
