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,
	// 第一个host
	firstHost: getFirstHost()
}

// #ifdef H5
envVal.formal = process.env.NODE_ENV == 'development' ? 'https://ghs.huaml.com' : `${window.location.protocol}//${window.location.host}`
envVal.hostUrl = process.env.NODE_ENV == 'development' ? `https://api.shop.hzghd.com` : `${window.location.protocol}//api.${window.location.host}`
// #endif

// #ifdef MP-WEIXIN
envVal.formal = process.env.NODE_ENV == 'development' ? extConfig.apiHost : extConfig.apiHost
envVal.hostUrl = process.env.NODE_ENV == 'development' ? extConfig.apiHost : extConfig.apiHost
// #endif

function getFirstHost() {
	let host = ''
	// #ifdef H5
	host = window.location.host
	host = host.split('.')
	host = host.length == 3 ? host[1] : host[0]
	// #endif
	// #ifndef H5
	host = extConfig.apiHost
	// #endif
	return process.env.NODE_ENV == 'development' ? 'huaml' : host
}

export default envVal
