import { _decorator, Label, Node, tween, UIOpacity } from 'cc';
import { BaseView } from '../../../framework/layer/BaseView';
import { StringUtil } from '../../../framework/util/StringUtil';
import { Framework } from '../../../framework/Framework';
import { TipsOpereteEnum } from '../../common/InterfaceAddEnum';
const { ccclass, property } = _decorator;

@ccclass('CommonTips')
export class CommonTips extends BaseView {
	@property({ type: Label, tooltip: "标题" })
	titleTx: Label = null;

	@property({ type: Label, tooltip: "提示内容" })
	contentTx: Label = null;

	@property({ type: Node, tooltip: "取消按钮" })
	cancelBtn: Node = null;
	@property({ type: Label, tooltip: "取消按钮文字" })
	cancelBtnTx: Label = null;

	@property({ type: Node, tooltip: "确定按钮" })
	confirmBtn: Node = null;
	@property({ type: Label, tooltip: "确定按钮文字" })
	confirmBtnTx: Label = null;

	@property({ type: Node, tooltip: "关闭按钮" })
	closeBtn: Node = null;
	@property({ type: Label, tooltip: "关闭按钮文字" })
	closeBtnTx: Label = null;

	private _callback = null;
	protected onLoad() {
		super.onLoad();
		this.titleTx.string = StringUtil.getLanguageData('提示');
		this.cancelBtnTx.string = StringUtil.getLanguageData('取消');
		this.confirmBtnTx.string = StringUtil.getLanguageData('确定');
		this.closeBtnTx.string = StringUtil.getLanguageData('关闭');
		this.closeBtn.active = false;
		this.cancelBtn.active = false;
		this.confirmBtn.active = false;
	}

	protected onDestroy() {

	}

	//UI开打时会调用,如果有初始化代码应该放到此函数
	onOpen(args) {
		this._callback = args.callback;
		this.contentTx.string = args.content;
		if (args.openType==TipsOpereteEnum.yes) {
			this.closeBtn.active = true;
		} else if (args.openType==TipsOpereteEnum.yes_no) {
			this.cancelBtn.active = true;
			this.confirmBtn.active = true;
		}
	}

	//UI关闭时会调用,该函数在onDestroy前调用
	onClose() {

	}

	//框架管理UI层级时会调用,可根据UI情况修改
	onShow() {
		super.onShow();
	}

	//框架管理UI层级时会调用,可根据UI情况修改
	onHide() {
		super.onHide();
	}

	//UI事件处理
	private onTouchButton(event: Event) {
		let target: any = event.target;
		if (target.name == 'close_btn') {
			Framework.layer.close(this);
		} else if (target.name == 'confirm_btn') {
			Framework.layer.close(this);
			if (this._callback) {
				this._callback();
			}
			Framework.layer.close(this);
		} else if (target.name == 'cancel_btn') {
			Framework.layer.close(this);
		}
	}
}