import { defineStore } from "pinia";
import { getAssetsImages } from '@/framework/utils/index'
export const Layout = () => import('@/framework/layout/index.vue');//顶部菜单布局
export const Layout1 = () => import('@/framework/layout1/index.vue');//顶部一级菜单、左侧二级菜单局部

declare var window: any
/**
 * 菜单配色
 * navrbarBackgroundColor(顶部导航栏背景颜色)
 * menuFontTextColor(默认菜单名称颜色)
 * activeMenuFontTextColor(活动菜单名称颜色)#2467e8
 * 
 * */

const layoutColorBlue={navrbarBackgroundColor:'#428bca',menuFontTextColor:'#ffffff',activeMenuFontTextColor:'#ffffff',activeMenuBackgroundColor:'#5FA8E7',
  userBackgroundColor:'#3399CC',userChooseColor:'#5FA8E7',systemChooseColor:'#5FA8E7',}
const layoutColorDarkBlue={navrbarBackgroundColor:'#071635',menuFontTextColor:'#ffffff',activeMenuFontTextColor:'#4D7FE0',activeMenuBackgroundColor:'',
  userBackgroundColor:'#10234A',userChooseColor:'rgba(36,103,232,0.2)',systemChooseColor:'#0D2758'}
//菜单布局处理
const layoutHandle = (realSetting:object,currentLayout:string) => {
  if('layout'===currentLayout){
    realSetting.currentLayout = Layout
  }
}
//菜单配色处理
const layoutColorHandle = (realSetting:object,currentLayoutColor:string) => {
  if('DarkBlue'===currentLayoutColor){
    realSetting.currentLayoutColor.value = layoutColorDarkBlue
  }
}


/**获取自定义配置 */
const getCustConfig = (realSetting:object) => {
  if(!publicData.extConfigName) return;
  let extConfig=window[publicData.extConfigName]
  if(!extConfig||typeof extConfig !== "object") return;
  for (let key in realSetting) {
    if(extConfig[key]!==undefined){
      if('currentLayout'===key){
        layoutHandle(realSetting,extConfig[key])
      }else if('currentLayoutColor'===key){
        layoutColorHandle(realSetting,extConfig[key])
      }else
        realSetting[key].value =extConfig[key]
    }
  }
}
/**获取默认配置 */
const getDefaultConfig = (realSetting:object) => {
  if (window.frameBaseConfig) {
    if(window.frameBaseConfig.tokenKey!==undefined){
      realSetting.tokenKey.value =window.frameBaseConfig.tokenKey
    }
    if(window.frameBaseConfig.loginResultKey!==undefined){
      realSetting.loginResultKey.value =window.frameBaseConfig.loginResultKey
    }
    if(window.frameBaseConfig.currentLayout!==undefined){
      if('layout'===window.frameBaseConfig.currentLayout){
        realSetting.currentLayout = Layout
      }
    }
    if(window.frameBaseConfig.currentLayoutColor!==undefined){
      if('DarkBlue'===window.frameBaseConfig.currentLayoutColor){
        realSetting.currentLayoutColor.value = layoutColorDarkBlue
      }
    }

    if(window.frameBaseConfig.backendServices!==undefined){
      realSetting.backendServices.value =window.frameBaseConfig.backendServices
    }
    if(window.frameBaseConfig.logoutRemoveToken!==undefined){
      realSetting.logoutRemoveToken.value =window.frameBaseConfig.logoutRemoveToken
    }
    if(window.frameBaseConfig.loginAddress!==undefined){
      realSetting.loginAddress.value =window.frameBaseConfig.loginAddress
    }
    if(window.frameBaseConfig.skipLoginAddressTime!==undefined){
      realSetting.skipLoginAddressTime.value =window.frameBaseConfig.skipLoginAddressTime
    }
    if(window.frameBaseConfig.loginType!==undefined){
      realSetting.loginType.value =window.frameBaseConfig.loginType
    }
    if(window.frameBaseConfig.navrbarBackgroundColor!==undefined){
      realSetting.navrbarBackgroundColor.value =window.frameBaseConfig.navrbarBackgroundColor
    }
    if(window.frameBaseConfig.menuFontTextColor!==undefined){
      realSetting.menuFontTextColor.value =window.frameBaseConfig.menuFontTextColor
    }
    if(window.frameBaseConfig.activeMenuFontTextColor!==undefined){
      realSetting.activeMenuFontTextColor.value =window.frameBaseConfig.activeMenuFontTextColor
    }
    if(window.frameBaseConfig.showLogo!==undefined){
      realSetting.showLogo.value =window.frameBaseConfig.showLogo
    }
    if(window.frameBaseConfig.logoAddress!==undefined){
      realSetting.logoAddress.value =window.frameBaseConfig.logoAddress
    }
    if(window.frameBaseConfig.headAddress!==undefined){
      realSetting.headAddress.value =window.frameBaseConfig.headAddress
    }
    if(window.frameBaseConfig.showSubSystemTags!==undefined){
      realSetting.showSubSystemTags.value =window.frameBaseConfig.showSubSystemTags
    }
    if(window.frameBaseConfig.showPersonalCenter!==undefined){
      realSetting.showPersonalCenter.value =window.frameBaseConfig.showPersonalCenter
    }
    if(window.frameBaseConfig.showDownloadCenter!==undefined){
      realSetting.showDownloadCenter.value =window.frameBaseConfig.showDownloadCenter
    }
    if(window.frameBaseConfig.showMessageNotify!==undefined){
      realSetting.showMessageNotify.value =window.frameBaseConfig.showMessageNotify
    }
    if(window.frameBaseConfig.tagsView!==undefined){
      realSetting.tagsView.value =window.frameBaseConfig.tagsView
    }
    if(window.frameBaseConfig.fixedHeader!==undefined){
      realSetting.fixedHeader.value =window.frameBaseConfig.fixedHeader
    }
    if(window.frameBaseConfig.fixedTags!==undefined){
      realSetting.fixedTags.value =window.frameBaseConfig.fixedTags
    }
    if(window.frameBaseConfig.maxTags!==undefined){
      realSetting.maxTags.value =window.frameBaseConfig.maxTags
    }
    if(window.frameBaseConfig.extModuleSendToken!==undefined){
      realSetting.extModuleSendToken.value =window.frameBaseConfig.extModuleSendToken
    }
    if(window.frameBaseConfig.websiteInfo!==undefined){
      realSetting.websiteInfo.value =window.frameBaseConfig.websiteInfo
    }
  }
}

export const useSettingsStore = defineStore("setting", () => {
  //令牌key
  const tokenKey=ref('abacus_emp_token')
  //登录信息key
  const loginResultKey=ref('abacus_login_result' )
  //菜单布局类型
  let currentLayout = Layout1
  //菜单配色类型 layoutColorDarkBlue
  const currentLayoutColor=ref(layoutColorBlue)
  //后台服务配置{"acas":"example"}
  const backendServices=ref({})
  //退出登录是否清理登录令牌
  const logoutRemoveToken = ref<boolean>(false);
  //应用登录地址
  const loginAddress = ref<string>('/abacus/index.html');
  //跳转登录页面延迟时间
  const skipLoginAddressTime = ref<number>(3000);
  //登录类型相关配置,acas员工登录默认放第一个
  const loginType = ref([{"id":"employee","name":"员工","prefixUrl":"/acas/user"}]);
  //顶部导航栏背景颜色
  const navrbarBackgroundColor = ref<String>('#071635');
  //默认菜单名称颜色
  const menuFontTextColor=ref<String>('#ffffff');
  //活动菜单名称颜色
  const activeMenuFontTextColor=ref<String>('#4D7FE0');
  //是否显示顶部导航栏左侧logo
  const showLogo = ref<boolean>(true);
  //左侧logo地址
  const logoAddress= ref<String>('');
  //头像地址
  const headAddress= ref<String>(getAssetsImages('head.jpg'));
  //是否显示顶部导航栏左侧子系统选择功能
  const showSubSystemTags = ref<boolean>(true);
  //是否显示个人中心
  const showPersonalCenter = ref<boolean>(true);
  //是否显示下载中心
  const showDownloadCenter = ref<boolean>(true); 
  //是否显示顶部导航栏右侧消息通知
  const showMessageNotify = ref<boolean>(false); 
  //是否显示多标签导航
  const tagsView = ref<boolean>(true);
  //是否固定头部
  const fixedHeader = ref<boolean>(true);
  //是否固定tags
  const fixedTags = ref<boolean>(true);
  //最大标签数量,默认8，配置0代表不限制
  const maxTags = ref<Number>(8);
  //外部模块发送Token
  const extModuleSendToken = ref<boolean>(false);
  //网站相关信息配置
  const websiteInfo=ref({
    //是否显示
    show:false,
    //排列规则,不配置:左;center:居中;end:靠右
    //justify:"center",
    //党政机关事业单位网站标识
    //conacUrl:{"url":"","size":"30"},
    //其他信息，版本信息、导航与链接等等
    //otherInfo:[{"name":"xxx公司","url":""},{"name":"示例名称","url":"完整链接地址，不配置，则不跳转"},],
  })
  
  const realSetting={tokenKey,loginResultKey,currentLayout, backendServices, logoutRemoveToken, loginAddress, skipLoginAddressTime, loginType, navrbarBackgroundColor, menuFontTextColor, activeMenuFontTextColor, showLogo, logoAddress, headAddress, showSubSystemTags,showPersonalCenter,showDownloadCenter, showMessageNotify,tagsView,fixedHeader,fixedTags,maxTags,extModuleSendToken,currentLayoutColor,websiteInfo}
  getDefaultConfig(realSetting)
  getCustConfig(realSetting)
  return realSetting

});
