class UI_Trade extends UIBaseComponent {
	private tradeTitle1: eui.Label;
	private tradeId: eui.Label;
	private tradeScroller: eui.Scroller;
	private tradeList: eui.DataGroup;
	private groudOpen: eui.Group;
	private btnOpen: eui.Button;
	private btnClose: eui.Button;
	private sbtnClose: eui.Button;

	private isOpen: boolean = true;//视图状态-默认打开

	public constructor() {
		super();
	}

	/**
	 * 绑定事件
	 */
	protected bindEvents(): void {
		super.bindEvents();

		mouse.setButtonMode(this.btnClose, true);
		mouse.setButtonMode(this.btnOpen, true);

		this.btnClose.addEventListener(egret.TouchEvent.TOUCH_TAP, this.changeViewStatus, this);
		this.btnOpen.addEventListener(egret.TouchEvent.TOUCH_TAP, this.changeViewStatus, this);
		this.sbtnClose.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onSbtnClose, this);
	}

	/**
	 * 创建完成时调用
	 */
	protected onCreate(): void {
		super.onCreate();
		this.render();
		this.onLangChange();
	}

	//切换视图状态
	private changeViewStatus() {
		AudiosMgr.instance.playButtonClick();

		this.isOpen = !this.isOpen;

		this.btnOpen.visible = !this.isOpen;

		this.btnClose.visible = this.isOpen;
		this.groudOpen.visible = this.isOpen;
	}

	private onSbtnClose() {
		AudiosMgr.instance.playButtonClick();

		Trade.instance.closeTradeView();
	}

	public renderTradeList() {
		if (!Trade.instance.tradeList) return;

		(this.tradeList.dataProvider as eui.ArrayCollection).source = Trade.instance.tradeList;
	}

	public emptyTradeView() {
		(this.tradeList.dataProvider as eui.ArrayCollection).source = [];
	}

	/**
	 * 渲染UI时调用
	 */
	protected render(): void {
		(this.tradeScroller.verticalScrollBar.thumb as eui.Image).source = "pc_json.pc_board10";
		this.tradeList.itemRenderer = UI_TradeItem;
		this.tradeList.dataProvider = new eui.ArrayCollection();

		this.renderTradeList();
	}

	/**
	 * 改变语言时调用
	 */
	protected onLangChange(ev?: egret.Event): void {
		let lang = Lang.instance.lang();

		this.tradeTitle1.text = lang.Trade.title;
		this.btnOpen.label = lang.Trade.title;
	}

	public renderGameId(id: string): void {
		this.tradeId.text = `${id}`;
	}

	/**
	 * 界面关闭时调用
	 */
	public onClose(): void {
	}
}