// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

import pg from "./pg";


const { ccclass, property } = cc._decorator;

@ccclass
export default class TipsJigsaw extends cc.Component {
    // LIFE-CYCLE CALLBACKS:
    private sureCall = null;
    private canCall = null;

    onLoad() {
        pg.view.touchOn(cc.find("continue", this.node), this.onContinue, this);
        pg.view.touchOn(cc.find("leave", this.node), this.onLeave, this);
        pg.view.touchOn(cc.find("btn_zcdt", this.node), this.onContinue, this);
        pg.view.touchOn(cc.find("btn_bl", this.node), this.onLeave, this);
        pg.event.on("show_tips", (data) => {
            this.sureCall = data.sureCall;
            this.canCall = data.canCall;
            cc.find("desc", this.node).getComponent(cc.Label).string = data.text;
            this.updataBtn(data.type);
            this.node.active = true;
            this.node.zIndex = 100;
        })
    }


    start() {
    }
    private updataBtn(type) {
        cc.find("btn_zcdt", this.node).active = type == "again";
        cc.find("btn_bl", this.node).active = type == "again";
        cc.find("leave", this.node).active = type == "leave";
        cc.find("continue", this.node).active = type == "leave";
    }
    private onContinue() {
        this.sureCall && this.sureCall();
        this.hide();
    }
    private onLeave() {
        this.canCall && this.canCall();
        this.hide();
    }
    private hide() {
        this.node.active = false;
        this.sureCall = null;
        this.canCall = null;
    }
    // update (dt) {}
}
