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

@ccclass('Bulletin')
export class Bulletin extends BaseView {
	@property({ type: Label, tooltip: "关闭提示" })
	closeTips: Label = null;

	@property({ type: Label, tooltip: "标题" })
	titleTx: Label = null;

	@property({ type: Sprite, tooltip: "公告图" })
	msgImg: Sprite = null;

	@property({ type: RichText, tooltip: "公告内容" })
	msgTx: RichText = null;

	private data:BulletinEnum = null;

	protected onLoad() {
		super.onLoad();
		this.closeTips.string = StringUtil.getLanguageData('点击空白关闭');
		this.titleTx.string = StringUtil.getLanguageData('公告');
		this.closeTips.node.getComponent(UIOpacity).opacity = 0;
	}

	protected onDestroy() {
		
	}

	//UI开打时会调用,如果有初始化代码应该放到此函数
	onOpen(data:BulletinEnum) {
		this.data = data;

		this.msgTx.string = data.content;

		if (this.data.img){
			this.load('package', 'texture/login/bulletin_img/spriteFrame', SpriteFrame, (res: SpriteFrame) => {
				this.msgImg.spriteFrame = res;
			})
		}

		tween(this.closeTips.node.getComponent(UIOpacity))
			.to(1, { opacity: 255 })
			.to(1.2, { opacity: 10 })
			.union()
			.repeatForever()
			.start()
	}

	//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 == 'mask') {
			Framework.layer.close(this);
		}
	}
}