import { ProjectName } from '@/config'

// #ifdef MP-WEIXIN
const extConfig = wx.getExtConfigSync ? wx.getExtConfigSync() : {}
// #endif
// 常量索引
const envVal = {
	// #ifdef H5
	imgUrl: `${window.location.protocol}//img.${getFirstHost()}.com`,
	// #endif
	// #ifdef MP-WEIXIN
	imgUrl: extConfig.imgHost,
	// #endif
	env: process.env.NODE_ENV,
	// 本地连接地址
	hostUrl: null,
	// 请求接口地址
	formal: null,
	// 项目来源
	source: ProjectName
}

// 项目配置
if (ProjectName == 'mobile') {
	// #ifdef H5
	envVal.formal = process.env.NODE_ENV == 'development' ? 'http://m.huaml.com' : `${window.location.protocol}//${window.location.host}`
	envVal.hostUrl = process.env.NODE_ENV == 'development' ? `http://api.m.huaml.com` : `${window.location.protocol}//api.${window.location.host}`
	// #endif
	// #ifdef MP-WEIXIN
	envVal.formal = process.env.NODE_ENV == 'development' ? extConfig.mHost : extConfig.mHost
	envVal.hostUrl = process.env.NODE_ENV == 'development' ? extConfig.mHost : extConfig.mHost
	// #endif

	// uni.setStorageSync('source', 'mobile')
} else if (ProjectName == 'business') {
	// #ifdef H5
	envVal.formal = process.env.NODE_ENV == 'development' ? 'http://b.huaml.com' : `${window.location.protocol}//${window.location.host}`
	envVal.hostUrl = process.env.NODE_ENV == 'development' ? `http://api.b.huaml.com` : `${window.location.protocol}//api.${window.location.host}`
	// #endif
	// #ifndef H5
	envVal.formal = process.env.NODE_ENV == 'development' ? 'http://b.huaml.com' : `https://b.huaml.com`
	envVal.hostUrl = process.env.NODE_ENV == 'development' ? `http://api.b.huaml.com` : `https://api.b.huaml.com`
	// #endif

	// uni.setStorageSync('source', 'business')
} else {
	// #ifdef H5
	envVal.formal = process.env.NODE_ENV == 'development' ? 'http://w.huaml.com' : `${window.location.protocol}//${window.location.host}`
	envVal.hostUrl = process.env.NODE_ENV == 'development' ? `http://api.w.huaml.com` : `${window.location.protocol}//api.w.${getFirstHost()}.com`
	// #endif
	// #ifndef H5
	envVal.formal = process.env.NODE_ENV == 'development' ? 'http://w.huaml.com' : `https://w.huaml.com`
	envVal.hostUrl = process.env.NODE_ENV == 'development' ? `http://api.w.huaml.com` : `https://api.w.huaml.com`
	// #endif

	// uni.setStorageSync('source', 'www')
}

function getFirstHost() {
	let host = window.location.host
	host = host.split('.')
	host = host.length == 3 ? host[1] : host[0]
	return process.env.NODE_ENV == 'development' ? 'huaml' : host
}

console.log(envVal)

export default envVal
