/*
 * @Author: sjl
 * @Date: 2023-05-07 20:15:47
 * @Descripttion:
 */
import type { GlobConfig } from '/#/config';

import { warn } from '/@/utils/log';
import { getAppEnvConfig } from '/@/utils/env';

export const useGlobSetting = (): Readonly<GlobConfig> => {
  const {
    VITE_GLOB_APP_TITLE,
    VITE_GLOB_API_URL,
    VITE_GLOB_APP_SHORT_NAME,
    VITE_GLOB_API_URL_PREFIX,
    VITE_GLOB_UPLOAD_URL,
    VITE_GLOB_CONFIGURATION,
    VITE_GLOB_WEB_SOCKET,
    VITE_GLOB_CONTENT_SECURITY_POLICY,
    VITE_GLOB_ALARM_NOTIFY_POLLING_INTERVAL_TIME,
    VITE_GLOB_ALARM_NOTIFY_DURATION,
    VITE_GLOB_LARGE_DESIGNER,
    VITE_GLOB_BIG_SCREEN,
    VITE_GLOB_LIGONG_ADMIN,
    VITE_GIS_API,
    VITE_GLOB_DEBUGGER_API,
    VITE_GLOB_LIGONG_PAGE,
    VITE_GLOB_BASE_IMG,
    VITE_GLOB_IS_IDC,
    VITE_GLOB_BASE_IMITATE
  } = getAppEnvConfig();

  if (!/[a-zA-Z\_]*/.test(VITE_GLOB_APP_SHORT_NAME)) {
    warn(
      `VITE_GLOB_APP_SHORT_NAME Variables can only be characters/underscores, please modify in the environment variables and re-running.`
    );
  }

  // Take global configuration
  const glob: Readonly<GlobConfig> = {
    title: VITE_GLOB_APP_TITLE,
    apiUrl: VITE_GLOB_API_URL,
    bigScreen: VITE_GLOB_BIG_SCREEN,
    gisApiUrl: VITE_GIS_API,
    debuggerApiUrl: VITE_GLOB_DEBUGGER_API,
    ligongAdmin: VITE_GLOB_LIGONG_ADMIN,
    shortName: VITE_GLOB_APP_SHORT_NAME,
    urlPrefix: VITE_GLOB_API_URL_PREFIX,
    uploadUrl: VITE_GLOB_UPLOAD_URL,
    configurationPrefix: VITE_GLOB_CONFIGURATION,
    vite_glob_ligong_page: VITE_GLOB_LIGONG_PAGE,
    largeDesignerPrefix: VITE_GLOB_LARGE_DESIGNER,
    socketUrl: VITE_GLOB_WEB_SOCKET,
    securityPolicy: VITE_GLOB_CONTENT_SECURITY_POLICY,
    alarmNotifyDuration: VITE_GLOB_ALARM_NOTIFY_DURATION,
    alarmPollingInterval: VITE_GLOB_ALARM_NOTIFY_POLLING_INTERVAL_TIME,
    baseImgUrl: VITE_GLOB_BASE_IMG,
    baseImitate:VITE_GLOB_BASE_IMITATE,
    isIdc: VITE_GLOB_IS_IDC,
  };
  return glob as Readonly<GlobConfig>;
};
