import { defineStore } from 'pinia'
import storage from 'store'

export const useOem = defineStore('oem', {
    state: () => ({
        siteInfo: {
            iconUrl: '',
            sysLogoUrl: '',
            sysMinLogoUrl: '',
            sysName: '',
            companyName: '',
            companyServiceTel: '',
            companyEmail: '',
            companyAddress: '',
            darkSysLogoUrl:'',
            darkSysMinLogoUrl:'',

            mgr: {
                sysPrimaryColor: '',
                loginPageBGImgUrl: '',
                loginPageCardPosition: 'right',
                sysLogoUrl: '',
                sysMinLogoUrl: '',
                darkSysLogoUrl:'',
                darkSysMinLogoUrl:'',
            },
            mch: {
                sysPrimaryColor: '',
                loginPageBGImgUrl: '',
                loginPageCardPosition: 'right'
            }
        },

        sysConfig: {
            httpMsgIsEncrypt: null, //是否优先使用http加密通信
        }
    }),

    actions: {

        refInfo(infos){ // 刷新信息

            this.siteInfo = Object.assign({}, infos.siteInfo)
            Object.assign(this.sysConfig, infos.sysConfig)

        },

        // 获取 当值不存在是需要在locationstore中获取（比如登录成功 重定向到页面时）
        getSiteInfo(){

            // @ts-ignore : 改变网站信息
            if(!this.siteInfo.sysName){
                // @ts-ignore : 改变网站信息
                this.siteInfo = Object.assign({}, storage.get(window.$SITE_INFO_NAME).siteInfo)
            }

            return this.siteInfo
        }, 

        // 获取 是否加密传输
        getHttpMessageEncryptFlag(){

          if(typeof this.sysConfig.httpMsgIsEncrypt != 'boolean'){
            // @ts-ignore : 改变
            this.sysConfig = Object.assign({}, storage.get(window.$SITE_INFO_NAME).sysConfig)
          }

          return this.sysConfig.httpMsgIsEncrypt
      }


    }

})
