// 导入 ProjectConfig 类型
import type { ProjectConfig } from '/#/config';

// 导入 Vue 的 computed 函数
import { computed } from 'vue';

// 导入 useAppStore 函数
import { useAppStore } from '/@/store/modules/app';
// 导入 ContentEnum 和 ThemeEnum 枚举
import { ContentEnum, ThemeEnum } from '/@/enums/appEnum';

// 定义 RootSetting 类型，从 ProjectConfig 中排除一些属性
type RootSetting = Omit<
  ProjectConfig,
  'locale' | 'headerSetting' | 'menuSetting' | 'multiTabsSetting'
>;

// 导出 useRootSetting 函数
export function useRootSetting() {
  // 获取 appStore 实例
  const appStore = useAppStore();

  // 获取页面加载状态
  const getPageLoading = computed(() => appStore.getPageLoading);

  // 获取是否开启 KeepAlive
  const getOpenKeepAlive = computed(() => appStore.getProjectConfig.openKeepAlive);

  // 获取设置按钮位置
  const getSettingButtonPosition = computed(() => appStore.getProjectConfig.settingButtonPosition);

  // 获取是否允许嵌入 iframe 页面
  const getCanEmbedIFramePage = computed(() => appStore.getProjectConfig.canEmbedIFramePage);

  // 获取权限模式
  const getPermissionMode = computed(() => appStore.getProjectConfig.permissionMode);

  // 获取是否显示 Logo
  const getShowLogo = computed(() => appStore.getProjectConfig.showLogo);

  // 获取内容模式
  const getContentMode = computed(() => appStore.getProjectConfig.contentMode);

  // 获取是否使用返回顶部功能
  const getUseOpenBackTop = computed(() => appStore.getProjectConfig.useOpenBackTop);

  // 获取是否显示设置按钮
  const getShowSettingButton = computed(() => appStore.getProjectConfig.showSettingButton);

  // 获取是否使用错误处理
  const getUseErrorHandle = computed(() => appStore.getProjectConfig.useErrorHandle);

  // 获取是否显示页脚
  const getShowFooter = computed(() => appStore.getProjectConfig.showFooter);

  // 获取是否显示面包屑
  const getShowBreadCrumb = computed(() => appStore.getProjectConfig.showBreadCrumb);

  // 获取主题颜色
  const getThemeColor = computed(() => appStore.getProjectConfig.themeColor);

  // 获取是否显示面包屑图标
  const getShowBreadCrumbIcon = computed(() => appStore.getProjectConfig.showBreadCrumbIcon);

  // 获取是否使用全屏内容
  const getFullContent = computed(() => appStore.getProjectConfig.fullContent);

  // 获取是否使用弱色模式
  const getColorWeak = computed(() => appStore.getProjectConfig.colorWeak);

  // 获取是否使用灰度模式
  const getGrayMode = computed(() => appStore.getProjectConfig.grayMode);

  // 获取锁屏时间
  const getLockTime = computed(() => appStore.getProjectConfig.lockTime);

  // 获取是否显示深色模式切换按钮
  const getShowDarkModeToggle = computed(() => appStore.getProjectConfig.showDarkModeToggle);

  // 获取深色模式状态
  const getDarkMode = computed(() => appStore.getDarkMode);

  // 获取布局内容模式
  const getLayoutContentMode = computed(() =>
    appStore.getProjectConfig.contentMode === ContentEnum.FULL
      ? ContentEnum.FULL
      : ContentEnum.FIXED
  );

  // 设置根设置
  function setRootSetting(setting: Partial<RootSetting>) {
    appStore.setProjectConfig(setting);
  }

  // 设置深色模式
  function setDarkMode(mode: ThemeEnum) {
    appStore.setDarkMode(mode);
  }

  // 返回所有计算属性和方法
  return {
    setRootSetting,

    getSettingButtonPosition,
    getFullContent,
    getColorWeak,
    getGrayMode,
    getLayoutContentMode,
    getPageLoading,
    getOpenKeepAlive,
    getCanEmbedIFramePage,
    getPermissionMode,
    getShowLogo,
    getUseErrorHandle,
    getShowBreadCrumb,
    getShowBreadCrumbIcon,
    getUseOpenBackTop,
    getShowSettingButton,
    getShowFooter,
    getContentMode,
    getLockTime,
    getThemeColor,
    getDarkMode,
    setDarkMode,
    getShowDarkModeToggle,
  };
}