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

import {initialState} from './index.js';

/**
 * 获取store中的切割出指定片段
 * @param state
 */
const selectDomain = (state) => state?.main || initialState;

/**
 * 主页标签
 */
export const selectTabs = createSelector(
  [selectDomain],
  main => main.tabs
);

/**
 * 当前路由
 */
export const selectPathname = createSelector(
  [selectDomain],
  main => main.pathname
);

/**
 * 用户列表
 */
export const selectUsers = createSelector(
  [selectDomain],
  main => main.users
);

/**
 * 角色列表
 */
export const selectRoles = createSelector(
  [selectDomain],
  main => main.roles
);

/**
 * 主题域
 */
export const selectDomains = createSelector(
  [selectDomain],
  main => main.domains
);

/**
 * 主题域下的模型
 */
export const selectModals = createSelector(
  [selectDomain],
  main => main.modals
);

/**
 * 数据源列表
 */
export const selectDBSource = createSelector(
  [selectDomain],
  main => main.sourceList
);

/**
 * 数据库信息
 */
export const selectDBList = createSelector(
  [selectDomain],
  main => main.dbList
);

/**
 * 数据库表信息
 */
export const selectTableList = createSelector(
  [selectDomain],
  main => main.tableList
);

/**
 * 数据库表字段信息
 */
export const selectTableColumns = createSelector(
  [selectDomain],
  main => main.tableColumns
);

/**
 * 节点信息
 */
export const selectNodes = createSelector(
  [selectDomain],
  main => main.nodes
);

/**
 * 节点连接线
 */
export const selectEdges = createSelector(
  [selectDomain],
  main => main.edges
);

/**
 * 指标列表
 */
export const selectIndexLibs = createSelector(
  [selectDomain],
  main => main.indexLib
);

/**
 * 业务限定列表
 */
export const selectConditions = createSelector(
  [selectDomain],
  main => main.conditions
);

/**
 * 指标数据集列表
 */
export const selectDataSet = createSelector(
  [selectDomain],
  main => main.dataset
);

/**
 * 维度列表
 */
export const selectDimensions = createSelector(
  [selectDomain],
  main => main.dimensions
);


/**
 * 维度列表
 */
export const selectRoleAuth = createSelector(
  [selectDomain],
  main => main.roleAuth
);

/**
 * 维度列表
 */
export const selectPeriods = createSelector(
  [selectDomain],
  main => main.periods
);