import { LanguageManager } from "./LanguageManager";

export class ScenceLanguageSourceSet {
	private static _CommonSource: cc.Node;
	private static _source: cc.Node = null;
	private static _content: cc.Node = null;
	private static _allSlotLanguageSourceDic: Map<number, cc.Node> = new Map<number, cc.Node>();
	//=======================================================================================
	/**
	 * 一般場景
	 * @param parent 只能設目前場景
	 * @param source 使用語系集合
	 */
	public static SetNormalScence(parent: cc.Node, source: cc.Prefab[]) {
		this._content = parent.getChildByName("LanguageContent");
		if (!this._content) {
			this._content = parent.ExAddChild(new cc.Node("LanguageContent"));
		}
		if (source != null) {
			this._content.ExAddChild(new cc.Node("CommonLanguageContent"));
			this._source = this._content.ExAddChild(source[LanguageManager.SourceIndex]);
			//(勿拿掉為了避美術不小心 關掉眼睛)
			this._source.active = true;
			for (let child of this._source.children) {
				//(勿拿掉為了避美術不小心 關掉眼睛)
				child.active = true;
				for (let childchild of child.children) {
					//(勿拿掉為了避美術不小心 打開眼睛)
					childchild.active = false;
				}
			}
		}
	}
	public static SetNormalScence_v2(parent: cc.Node, source: cc.Prefab) {
		this._content = parent.getChildByName("LanguageContent");
		if (!this._content) {
			this._content = parent.ExAddChild(new cc.Node("LanguageContent"));
		}
		if (source != null) {
			this._content.ExAddChild(new cc.Node("CommonLanguageContent"));
			this._source = this._content.ExAddChild(source);
			//(勿拿掉為了避美術不小心 關掉眼睛)
			this._source.active = true;
			for (let child of this._source.children) {
				//(勿拿掉為了避美術不小心 關掉眼睛)
				child.active = true;
				for (let childchild of child.children) {
					//(勿拿掉為了避美術不小心 打開眼睛)
					childchild.active = false;
				}
			}
		}
	}
	//=======================================================================================
	/**
	 * 遊戲場景
	 * @param parent 只能目前場景
	 * @param sourceCommonLanguage 通用語系包(上下UI)
	 * @param sourceSlotLanguage 機台介面語系
	 */
	public static SetGameScence(parent: cc.Node, sourceCommonLanguage: cc.Prefab[], sourceSlotLanguage: cc.Node) {
		this._content = parent;
		if (sourceCommonLanguage != null && sourceCommonLanguage.length > 0) {
			this._CommonSource = this._content.ExAddChild(sourceCommonLanguage[LanguageManager.SourceIndex]);
			for (let commonLang of this._CommonSource.children) {
				//(勿拿掉為了避美術不小心 關掉眼睛)
				commonLang.active = true;
				for (let commonLangChild of commonLang.children) {
					//(勿拿掉為了避美術不小心 打開眼睛)
					commonLangChild.active = false;
				}
			}
			//(勿拿掉為了避美術不小心 關掉眼睛)
			this._CommonSource.active = true;
		}
		else {
			this._content.ExAddChild(new cc.Node("CommonLanguageContent"));
		}
		if (sourceSlotLanguage != null) {
			this._source = sourceSlotLanguage;
			this._source.setParent(this._content);
			//(勿拿掉為了避美術不小心 關掉眼睛)
			this._source.active = true;
			for (let slotLanguage of this._source.children) {
				//(勿拿掉為了避美術不小心 關掉眼睛)
				slotLanguage.active = true;
				for (let rollerSlotChild of slotLanguage.children) {
					//(勿拿掉為了避美術不小心 打開眼睛)
					rollerSlotChild.active = false;
				}
				this._allSlotLanguageSourceDic.set(+slotLanguage.name, slotLanguage);
			}
		}
	}
	public static CommonLanguageContent(type: number): cc.Node {
		return this._content.children[0].children[type];
	}

	public static SlotLanguageContent(): cc.Node {
		if (this && this._content && this._content.children[1]) {
			return this._content.children[1];
		} else {
			return null;
		}
	}

	public static GetSlotLanguage(index: number): cc.Node {
		return this._allSlotLanguageSourceDic.get(index);
	}
	//=======================================================================================
}