import Config from "../Config";
import Gamecfg from "../common/gameCfg";
import { gameMethod } from "../common/gameMethod";
import { FightTypeMap, Lang, TaskKind } from "../data/const/TypeConst";
import Load from "./Load";

export class I18n {
	static getI18nText(key: string, ...args) {
		let i18n = Gamecfg.languageClientText.getItem(key);
		let str: string = key;
		if (!i18n || !i18n[Config.lang]) {
			if (CC_PREVIEW) console.warn(`多语言languageText: ${key},${Config.lang}不存在`);
		} else str = i18n[Config.lang];
		return I18n.format(str, args);
	}

	static getI18nLang(key: string, ...args) {
		let i18n = Gamecfg.languageLang.getItem(key);
		let str: string = key;
		if (!i18n || !i18n[Config.lang]) {
			if (CC_PREVIEW) console.warn(`多语言languageLang: ${key},${Config.lang}不存在`);
		} else str = i18n[Config.lang];
		return I18n.format(str, args);
	}

	static format(str: string, args: any[]) {
		let result = str;
		args.forEach((element, index) => {
			result = result.replace(`{${index}}`, element);
		});
		return result;
	}

	static readonly temp = [{}, {}, {}, {}, {}, {}, {}, {}, {}, {}];
	static getI18nLangArr(key: string) {
		let i18n = Gamecfg.languageLang.getItem(key);
		let arr: any = this.temp;
		if (!i18n || !i18n[Config.lang]) {
			if (CC_PREVIEW) console.warn(`多语言languageLangArr: ${key},${Config.lang}不存在`);
			return arr;
		} else {
			try {
				arr = JSON.parse(i18n[Config.lang]);
			} catch (e: any) {
				if (CC_PREVIEW) console.error(e);
			}
		}
		return arr;
	}

	/**
	 * 如果是zh-cn，则从原路径读取
	 */
	static LoadI18nTexture(node: cc.Node, url: string, callback: Function = null) {
		let u = url;
		if (Config.lang != Lang.lang_zh_cn) u = `${Config.lang}/${url}`;
		Load.loadTexture(node, u, (isSucc) => {
			if (!isSucc) {
				console.warn(`${Config.lang}: ${node.name}节点上的资源${url}加载失败`);
			}
			if (callback) callback(isSucc);
		});
	}

	static getEpsTypeName(type: number) {
		return I18n.getI18nText(`common_eptype_${type}`);
	}

	static getMoneyDesc(money: number | string) {
		return I18n.getI18nText("money_desc", money);
	}

	static getTaskDescKey(id: number | string) {
		return `task_desc_name_${id}`;
	}

	static getTaskDesc(id: number | string, ...args) {
		return I18n.getI18nLang(I18n.getTaskDescKey(id), ...args);
	}

	static getUserEpDesc(key: string | number, ...args) {
		return I18n.getI18nLang(`user_ep_desc_${key}`, ...args);
	}

	static getFazhenInfoName(id: string | number) {
		return I18n.getI18nLang(`equip_info_name_${id}`);
	}

	static getFazhenSkillDesc(id: string | number, ...args) {
		return I18n.getI18nLang(`fazhen_skill_desc_${id}`, ...args);
	}

	static getFazhenSkillName(id: string | number, ...args) {
		return I18n.getI18nLang(`fazhen_skill_name_${id}`);
	}

	static getFazhenInfoDesc(id: string | number) {
		return I18n.getI18nLang(`fazhen_info_desc_${id}`);
	}

	static getFushiEpDesc(key: string | number) {
		return I18n.getI18nLang(`fushi_ep_desc_${key}`);
	}

	static getFushiItemName(id: string | number) {
		return I18n.getI18nLang(`fushi_item_name_${id}`);
	}

	static getFushiEpName(key: string | number) {
		return I18n.getI18nLang(`fushi_ep_name_${key}`);
	}

	static getFushiTaskdescContent(kind: string | number, ...args) {
		return I18n.getI18nLang(`fushi_taskdesc_content_${kind}`, ...args);
	}

	static getFushiTaskdescName(kind: string | number, ...args) {
		return I18n.getI18nLang(`fushi_taskdesc_name_${kind}`, ...args);
	}

	static getGuideInfoParam(id: string | number): any[] {
		return I18n.getI18nLangArr(`guide_info_pram_${id}`);
	}

	static getPveInfoName(id: string | number) {
		return I18n.getI18nLang(`pve_info_name_${id}`);
	}

	static getJinxiuByTzDesc(tzid: number | string) {
		return I18n.getI18nLang(`jinxiu_info_desc_${tzid}`);
	}

	static getJinxiuByTzName(tzid: number | string) {
		return I18n.getI18nLang(`jinxiu_info_tzName${tzid}`);
	}

	static getYixiangInfoDesc(id: string | number) {
		return I18n.getI18nLang(`yixiang_info_desc_${id}`);
	}

	static getYixiangInfoName(id: string | number) {
		return I18n.getI18nLang(`yixiang_info_name_${id}`);
	}

	static getYixiangInfoSource(id: string | number) {
		return I18n.getI18nLang(`yixiang_info_source_${id}`);
	}

	static getLiudaoInfoName(id: string | number) {
		return I18n.getI18nLang(`liudao_info_name_${id}`);
	}

	static getLonggongJiaofuName(id: string | number) {
		return I18n.getI18nLang(`longgong_jiaofu_name_${id}`);
	}

	static getDongtianPvdtName(id: number | string) {
		return I18n.getI18nLang(`dongtian_pvdt_name_${id}`);
	}

	static getEquipPifugetDesc(id: number | string) {
		return I18n.getI18nLang(`equip_pifu_getDesc_${id}`);
	}

	static getDongtianCarName(id: string | number) {
		return I18n.getI18nLang(`dongtian_car_name_${id}`);
	}

	static getDongtianXlLvName(type: number | string, id: number | string) {
		return I18n.getI18nLang(`dongtian_xlLv_name_${type}_${id}`);
	}

	static getPveJingyingName(id: string | number) {
		return I18n.getI18nLang(`pve_jingying_name_${id}`);
	}

	static getPvwTypeName(id: string | number) {
		return I18n.getI18nLang(`pvw_type_name_${id}`);
	}

	static getPvwMonsterName(id: string | number) {
		return I18n.getI18nLang(`pvw_monster_name_${id}`);
	}

	static getReddotInfoName(id: string | number) {
		return I18n.getI18nLang(`reddot_info_name_${id}`);
	}

	static getShengqiInfoName(id: string | number) {
		return I18n.getI18nLang(`shengqi_info_name_${id}`);
	}

	static getShengqiInfoDesc(id: string | number) {
		return I18n.getI18nLang(`shengqi_info_desc_${id}`);
	}

	static getShengqiInfoSkillDesc(id: string | number) {
		return I18n.getI18nLang(`shengqi_info_skillDesc_${id}`);
	}

	static getShengqiInfoChipName(id: string | number) {
		return I18n.getI18nLang(`shengqi_info_chipName_${id}`);
	}

	static getShengqiInfoChipDesc(id: string | number) {
		return I18n.getI18nLang(`shengqi_info_chipDesc_${id}`);
	}

	static getShopCoinName(id: string | number) {
		return I18n.getI18nLang(`shop_coin_name_${id}`);
	}

	static getShopDiamondName(id: string | number) {
		return I18n.getI18nLang(`shop_diamond_name_${id}`);
	}

	static getShopKind11Title(id: string | number) {
		return I18n.getI18nLang(`shop_kind11_title_${id}`);
	}

	static getSubscribeInfoContent(id: string | number) {
		return I18n.getI18nLang(`subscribe_info_content_${id}`);
	}

	static getXianlvInfoName(id: number | string) {
		return I18n.getI18nLang(`xianlv_info_name_${id}`);
	}

	static getMonClubBossName(id: number | string) {
		return I18n.getI18nLang(`mon_clubBoss_name_${id}`);
	}

	static getHelpInfoDesc(id: number | string) {
		return I18n.getI18nLang(`help_info_desc_${id}`);
	}

	static getXianlvSkill_DescDesc(id: string | number) {
		return I18n.getI18nLang(`xianlv_skill_desc_desc_${id}`);
	}

	static getXianlvSkillName(id: string | number) {
		return I18n.getI18nLang(`xianlv_skill_name_${id}`);
	}

	static getXiantuInfoName(id: string | number) {
		let kaiqiCfg = Gamecfg.kaiqiInfo.getItem(id.toString());
		return I18n.getI18nLang(kaiqiCfg.name);
	}

	static getXiantuInfoDesc(id: string | number) {
		let kaiqiCfg = Gamecfg.kaiqiInfo.getItem(id.toString());
		return I18n.getI18nLang(kaiqiCfg.desc);
	}

	static getZhaocaiPinzhirwdTitle(pinzhi: string | number) {
		return I18n.getI18nLang(`zhaocai_pinzhi_rwdTitle_${pinzhi}`);
	}

	static getClubMijiName(type: number | string, id: number | string) {
		return I18n.getI18nLang(`club_miji_name_${type}_${id}`);
	}

	// 宗门旗帜描述
	static getClubFlagDesc(id: number | string, ...args) {
		return I18n.getI18nLang(`club_flag_desc_${id}`, args);
	}

	static getFazhenJibanName(id: string | number) {
		return I18n.getI18nLang(`fazhen_jiban_name_${id}`);
	}

	static getBaoshiInfoName(id: number | string) {
		return I18n.getI18nLang(`baoshi_info_name_${id}`);
	}

	static getChenghaoInfoName(id: string | number) {
		return I18n.getI18nLang(`chenghao_info_name_${id}`);
	}

	static getChenghaoInfoDesc(id: string | number) {
		return I18n.getI18nLang(`chenghao_info_desc_${id}`);
	}

	static getEquipPifuName(id: number | string) {
		return I18n.getI18nLang(`equip_pifu_name_${id}`);
	}

	static getEquipPifuDesc(id: number | string) {
		return I18n.getI18nLang(`equip_pifu_desc_${id}`);
	}

	static getBaoshiItemName(id: string | number) {
		return I18n.getI18nLang(`baoshi_item_name_${id}`);
	}

	static getBaoshiItemDesc(id: string | number) {
		return I18n.getI18nLang(`baoshi_item_desc_${id}`);
	}

	static getJumpInfoName(id: string | number) {
		return I18n.getI18nLang(`jump_info_name_${id}`);
	}

	static getShopFushizName(id: string | number) {
		return I18n.getI18nLang(`shop_fushiz_name_${id}`);
	}

	static getReddotInfoDesc(id: string | number) {
		return I18n.getI18nLang(`reddot_info_desc_${id}`);
	}

	static getFushiJitanName(id: string | number, saveid: string | number) {
		return I18n.getI18nLang(`fushi_jitan_name_${id}_${saveid}`);
	}

	static getFushiItemDesc(id: number | string) {
		return I18n.getI18nLang(`fushi_item_desc_${id}`);
	}

	static getJingguaiInfoName(id: number | string) {
		return I18n.getI18nLang(`jingguai_info_name_${id}`);
	}

	static getJingguaiInfoDesc(id: number | string) {
		return I18n.getI18nLang(`jingguai_info_desc_${id}`);
	}

	static getJingguaiPinzhiName(id: number | string) {
		return I18n.getI18nLang(`jingguai_pinzhi_name_${id}`);
	}

	static getLiantiJingluoName(id: number | string) {
		return I18n.getI18nLang(`lianti_jingluo_name_${id}`);
	}

	static getLiantiTipoDesc(id: number | string) {
		return I18n.getI18nLang(`lianti_tipo_desc_${id}`);
	}

	static getShopJintiaoName(id: number | string) {
		return I18n.getI18nLang(`shop_jintiao_name_${id}`);
	}

	static getMonXiongshouName(id: number | string) {
		return I18n.getI18nLang(`mon_xiongshou_name_${id}`);
	}

	static getXiongshouMFDesc(id: number | string) {
		return I18n.getI18nLang(`xiongshou_MF_desc_${id}`);
	}

	static getXiongshouNLName(id: number | string) {
		return I18n.getI18nLang(`xiongshou_NL_name_${id}`);
	}

	static getXiongshouNLDes(id: number | string) {
		return I18n.getI18nLang(`xiongshou_NL_des_${id}`);
	}

	static getDiZiPuGongDesc(key: number | string) {
		return I18n.getI18nLang(`${key}`);
	}

	//==========================================================================遮天==========================================================================

	static getItemMoneyName(id: number | string) {
		// 道具名字
		return I18n.getI18nLang(`item_money_name_${id}`);
	}

	static getItemMoneyDesc(id: number | string) {
		// 道具描述
		return I18n.getI18nLang(`item_money_desc_${id}`);
	}

	static getZhenFaInfoName(id: string | number) {
		return I18n.getI18nLang(`zhenfa_info_name_${id}`);
	}

	static getShouLingName(id: string | number) {
		return I18n.getI18nLang(`shouling_name_${id}`);
	}

	static getShoulingSkillDesc(key: string | number) {
		return I18n.getI18nLang(`${key}`);
	}

	static getShoulingTuJianName(key: string | number) {
		return I18n.getI18nLang(`shouling_jiban_name_${key}`);
	}

	static getDiziBaseName(id: string) {
		let diziBase = Gamecfg.huobanBase.getItem(id);
		return I18n.getI18nLang(diziBase?.name);
	}

	static getDaoyouBaseDesc(id: string) {
		return I18n.getI18nLang(`daoyou_base_desc_${id}`);
	}

	static getDaoYouSkillTypeName(id: string, ...args) {
		return I18n.getI18nLang(`daoyou_skillType_skillName_${id}`, ...args);
	}

	static getJingjieStepTitle(id: string | number) {
		return I18n.getI18nLang(`jingjie_step_title_${id}`);
	}

	static getJingjieStepMiniTitle(id: string | number) {
		let title = I18n.getI18nLang(`jingjie_step_title_${id}`);
		let splitTitle: string[] = title.split("·");
		return splitTitle[splitTitle.length - 1];
	}

	static getDiziJingjieStepTitle(pinzhi: string, jingjie: string) {
		let diziTuPoCfg = Gamecfg.huobanTupo.getItem(pinzhi, jingjie);
		return I18n.getI18nLang(diziTuPoCfg.jingjie);
	}

	static getDiziJingjieStepMiniTitle(pinzhi: string, jingjie: string) {
		let diziTuPoCfg = Gamecfg.huobanTupo.getItem(pinzhi, jingjie);
		let title = I18n.getI18nLang(diziTuPoCfg.jingjie);
		let splitTitle: string[] = title.split("·");
		return splitTitle[splitTitle.length - 1];
	}

	static getDiziJingjieStepDoubleTitle(pinzhi: string, jingjie: string) {
		let diziTuPoCfg = Gamecfg.huobanTupo.getItem(pinzhi, jingjie);
		let title = I18n.getI18nLang(diziTuPoCfg.jingjie);
		let splitTitle: string[] = title.split("·");
		return [splitTitle[0], splitTitle[splitTitle.length - 1]];
	}

	static getDaDiGuZiName(id: number | string) {
		// 古字名字
		return I18n.getI18nLang(`dadiguzi_info_name_${id}`);
	}

	static getDaDiGuZiBuWeiName(id: number | string) {
		// 古字部位名字
		return I18n.getI18nLang(`dadiguzi_info_buwei_${id}`);
	}

	static getDaDiGuZiTypeName(id: number | string) {
		// 古字类型名字(灵脉)
		return I18n.getI18nLang(`dadiguzi_type_name_${id}`);
	}

	static getDaDiGuZiShuFaName(id: number | string) {
		// 术法名字
		return I18n.getI18nLang(`shufa_name_des${id}`);
	}

	static getDaDiGuZiShuFaTypeName(id: number | string) {
		// 术法类型名字
		return I18n.getI18nLang(`dadiguzi_xfinfo_type_${id}`);
	}

	static getDaDiGuZiSfinfoDesc(id: string) {
		// 术法技能描述
		return I18n.getI18nLang(id);
	}

	static getDaDiGuZiXftjName(id: number | string) {
		// 图鉴名字
		return I18n.getI18nLang(`dadiguzi_xftj_name_${id}`);
	}

	static getDaDiGuZiMingwenName(id: number | string) {
		// 铭文名字
		return I18n.getI18nLang(`dadiguzi_mingwen_name_${id}`);
	}

	static getDaDiGuZiLingmaiDesc(id: number | string, count: number | string) {
		// 灵脉描述
		return I18n.getI18nLang(`dadiguzi_lingmai_desc_${id}_${count}`);
	}

	static getDaoWenTzName(id: number | string) {
		// 道纹套装名字
		return I18n.getI18nLang(`daowen_tz_info_name_${id}`);
	}

	static getDaoWenBwName(id: number | string) {
		// 道纹部位名字
		return I18n.getI18nLang(`daowen_slot_name_${id}`);
	}

	static getDaoWenTzDesc(id: number | string) {
		// 道纹套装描述
		return I18n.getI18nLang(`daowen_skill_des${id}`);
	}

	static getUserEpName(key: string | number) {
		// 属性名字
		return I18n.getI18nLang(`user_ep_name_${key}`);
	}

	static getSkinName(key: string | number) {
		// 皮肤名字
		return I18n.getI18nLang(`skin_skin_name_${key}`);
	}

	static getDiZiTuJianName(id: string | number) {
		// 图鉴名字
		return I18n.getI18nLang(`dizi_tujian_name_${id}`);
	}

	static getDouFaNpcName(id: string | number, name: string) {
		if (id.toString().length < 6)//NPC读语言表
		{
			let npcName = I18n.getI18nLang(`doufa_npc_name_${id}`);
			return npcName;
		}
		return name;
	}

	static getDouLuoNpcName(id: string | number, name: string) {
		if (id.toString().length < 6)//NPC读语言表
		{
			let npcCfg = Gamecfg.douLuoNpc.getItem(id.toString());
			let npcName = I18n.getI18nLang(npcCfg?.name);
			return npcName;
		}
		return name;
	}

	static getDouLuoNpcServer(id: string | number, name: string) {
		if (id.toString().length < 6)//NPC读语言表
		{
			let npcCfg = Gamecfg.douLuoNpc.getItem(id.toString());
			let npcName = I18n.getI18nLang(npcCfg?.sevname);
			return npcName;
		}
		return name;
	}

	static getYaoTianNpcName(id: string | number, name: string) {
		if (id.toString().length < 6)//NPC读语言表
		{
			let npcName = I18n.getI18nLang(name);
			return npcName;
		}
		return name;
	}

	static getJingjieStepTitleByKey(key: string) {
		return I18n.getI18nLang(key);
	}

	static getCnNum(key: string | number) {
		// 中文数字一到十
		return I18n.getI18nLang(`number_${key}`);
	}
}
