import { _decorator, Button, Component, Label, Node } from 'cc';
import { InGamePanel } from './InGamePanel';
import { ManagerType } from '../../Managers/global/data-flow/TopLevelManager';
const { ccclass, property } = _decorator;

@ccclass('LevelCompletePanel')
export class LevelCompletePanel extends InGamePanel
{
    @property({type: Label})
    private m_TurnsLabel: Label;

    @property({type: Label})
    private m_MatchesLabel: Label;

    @property({type: Label})
    private m_CurrentLvl: Label;

    @property({type: Label})
    private m_NextLvl: Label;

    @property({type: Button})
    private restartBtn: Button;

    @property({type: Button})
    private nextBtn: Button;

    protected onEnable(): void 
    {
        super.onEnable();

        this.restartBtn.node.on(Button.EventType.CLICK, () => 
        {
            this.fn_OnRestart();
        });
        
        this.nextBtn.node.on(Button.EventType.CLICK, () =>
        {
            this.fn_ArchiveCard();
            this.uiManager.fn_OnNextLevelClicked();
        });

        this.quitBtn.node.on(Button.EventType.CLICK, () =>
        {
            this.uiManager.fn_UpdateLevelsPage();
        });
    }

    protected onDisable(): void 
    {
        super.onDisable();

        this.restartBtn.node.off(Button.EventType.CLICK);
        this.nextBtn.node.off(Button.EventType.CLICK);
        this.quitBtn.node.off(Button.EventType.CLICK);
    }

    public fn_InitLevelData(matches: number, turns: number, currentLvl: number, nextLvl: number)
    {
        this.m_MatchesLabel.string = matches.toString();
        this.m_TurnsLabel.string = turns.toString();
        this.m_CurrentLvl.string = currentLvl.toString();
        this.m_NextLvl.string = nextLvl.toString();
    }
}

