import { _decorator, Button } from 'cc';
import { UIPanel } from '../base/UIPanel';
import { EventOperations, EventsType } from '../../Managers/global/interface/IPrimary';

const { ccclass, property } = _decorator;

@ccclass('InGamePanel')
export class InGamePanel extends UIPanel
{
    @property({type: Button})
    public quitBtn: Button;

    public fn_OnRestart()
    {
        this.fn_PassEventData(EventOperations.FIRE, EventsType.RESTART);
    }

    private fn_OnReturnToMenu()
    {
        this.fn_ArchiveCard();
        this.fn_ShowStartPanel();
        this.uiManager.fn_DeactivateCurrentActivePanel();
    }

    public fn_ArchiveCard(): void
    {
        this.fn_PassEventData(EventOperations.FIRE, EventsType.ARCHIVE_CARDS);
    }

    public fn_ShowStartPanel()
    {
        this.fn_PassEventData(EventOperations.FIRE, EventsType.RETURN_TO_MENU);
    }

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

        this.fn_PassEventData(EventOperations.ATTACH, EventsType.ARCHIVE_CARDS);
        this.fn_PassEventData(EventOperations.ATTACH, EventsType.RETURN_TO_MENU);
        this.fn_PassEventData(EventOperations.ATTACH, EventsType.RESTART);

        this.quitBtn.node.on(Button.EventType.CLICK, () => this.fn_OnReturnToMenu());
    }
    
    protected onDisable(): void 
    {
        this.fn_PassEventData(EventOperations.DETACH, EventsType.ARCHIVE_CARDS);
        this.fn_PassEventData(EventOperations.DETACH, EventsType.RETURN_TO_MENU);
        this.fn_PassEventData(EventOperations.DETACH, EventsType.RESTART);

        this.quitBtn.node.off(Button.EventType.CLICK, () => this.fn_OnReturnToMenu());
    }
}

