import { V2NIMConst, NIM } from '../dist/nim.js'
let appConfig = {
  // 用户的appkey
  // 用于在web demo中注册账号异步请求demo 服务器中使用
  test: {
    appkey: 'fe416640c8e8a72734219e1847ad2547',
    postUrl: 'https://apptest.netease.im'
  },
  online: {
    appkey: '885dea390870814acf3ba8558c717572',//885dea390870814acf3ba8558c717572     //45c6af3c98409b18a84451215d0bdd6e
    postUrl: 'https://app.netease.im'
  }
}

const imLogin = async ()=>{
	let storage_token='';
	let storage_accid='';
	if (process.env.UNI_PLATFORM == "h5") {
		if (window.location.href.indexOf('dev') > -1) {
			storage_accid=uni.getStorageSync('AUTH_YX_ACCID_App');
			storage_token=uni.setStorageSync('AUTH_YX_TOKEN_App');	
		} else {
			storage_accid=uni.getStorageSync('DEV_AUTH_YX_ACCID_App');
			storage_token=uni.getStorageSync('DEV_AUTH_YX_TOKEN_App');
		}
	} else if(process.env.UNI_PLATFORM == "mp-weixin") {
		const {
			envVersion
		} = uni.getAccountInfoSync().miniProgram;
		if (envVersion == "release") {
			storage_accid=uni.getStorageSync('AUTH_YX_ACCID_App');
			storage_token=uni.setStorageSync('AUTH_YX_TOKEN_App');	
		} else {
			storage_accid=uni.getStorageSync('DEV_AUTH_YX_ACCID_App');
			storage_token=uni.getStorageSync('DEV_AUTH_YX_TOKEN_App');
		}
	}else{
		if (BASE_URL.indexOf('dev') == -1) {
			storage_accid=uni.getStorageSync('DEV_AUTH_YX_ACCID_App');
			storage_token=uni.getStorageSync('DEV_AUTH_YX_TOKEN_App');
			
		} else {
			storage_accid=uni.getStorageSync('AUTH_YX_ACCID_App');
			storage_token=uni.setStorageSync('AUTH_YX_TOKEN_App');	
		}
	}
	const account =storage_accid;
	const token = storage_token;
	const appkey = appConfig.online.appkey
	const params1 = {
	  appkey: appkey,
	  debugLevel: 'log',
	  apiVersion: 'v2'
	}
	
	console.log('NIM', NIM)
	const nim = NIM.getInstance(params1)
	console.log('V2NIMConst', V2NIMConst.V2NIMTeamUpdateInfoMode.V2NIM_TEAM_UPDATE_INFO_MODE_MANAGER)
	console.log('V2NIMConst', V2NIMConst.V2NIMConversationType.V2NIM_CONVERSATION_TYPE_P2P)
	
	try {
	  console.log('正在 login...')
	
	  await nim.V2NIMLoginService.login(account, token, {
	    retryCount: 3,
	    timeout: 60000,
	    forceMode: false,
	    authType: 0
	  })
	
	  console.log('login 成功')
	
	
   }catch(error){
	console.log('login 失败', error)
}

}
export default imLogin