import Panel from "../../Module/Panel";
import { _decorator, Button, Label, Node } from "cc";
import { changeScene } from "db://assets/Module/UIFast";
import { HomeScene } from "db://assets/Scripts/Scenes/HomeScene";
import GameMgr from "db://assets/Scripts/GameMgr";
import { MainGame } from "db://assets/Scripts/Scenes/MainGame";

const {ccclass, property} = _decorator;

@ccclass('NoBoxPanel')
export default class NoBoxPanel extends Panel {

    static bundle: string = "";
    static skin = "NoBoxPanel";
    static group = "NoBoxPanel";

    @property(Node)
    close: Node = null!;

    @property(Node)
    cancel: Node = null!;

    @property(Node)
    ok: Node = null!;

    @property(Label)
    score: Label = null!;

    @property(Label)
    total: Label = null!;

    async start() {
        this.ok.on(Button.EventType.CLICK, this.onOk, this);
        this.close.on(Button.EventType.CLICK, this.onClose, this);
        this.cancel.on(Button.EventType.CLICK, this.onClose, this);

        const {totalScore, score,} = this.data;

        this.score.string = score.toString();
        this.total.string = `累计游园币：${totalScore}`;
    }

    /**
     * 再来一局
     */
    onOk = async () => {
        this.btnEnable(this.ok, false);
        const success = await GameMgr.ins.start();
        this.btnEnable(this.ok, true);
        if (!success) {
            changeScene(HomeScene);
            this.hidePanel();
            return;
        }
        changeScene(MainGame);
        this.hidePanel();
    }

    /**
     * 返回首页
     */
    onClose = () => {
        changeScene(HomeScene);
        this.hidePanel();
    }

}
