import { _decorator, BlockInputEvents, Component, UITransform } from 'cc';
import { PopupType } from '../popup/PopupType';
import { PopupScaler } from '../popup/PopupScaler';
import { PopupManager } from '../../Managers/global/ui/PopupManager';
import { Cards_Constants } from '../../constants/Cards_Constants';
import { UIManager } from '../../Managers/global/ui/UIManager';
import { EventArgs, EventOperations, EventsType } from '../../Managers/global/interface/IPrimary';

const { ccclass, property } = _decorator;

@ccclass('UIPanel')
export class UIPanel extends Component 
{
    @property({type: PopupType})
    protected popupType: PopupType;

    @property({type: PopupScaler})
    protected popupScaler: PopupScaler;
    
    protected uiManager: UIManager;
    protected evtArgs: EventArgs;

    public get fn_GetPopupType(): PopupType
    {
        return this.popupType;
    }

    protected onEnable(): void 
    {
        if (!this.popupScaler)
            this.popupScaler = this.getComponentInChildren(PopupScaler);
        
        this.popupScaler?.PlayScaleIn();
    }
    
    protected start(): void {
    }
    
    public fn_InitUIManager(uiManager: UIManager)
    {
        this.uiManager = uiManager;
    }

    public fn_ShowPanel()
    {
        this.node.active = true;
    }
    
    public fn_HidePanel()
    {
        this.popupScaler?.PlayScaleOut();
        setTimeout(() => {
            this.node.active = false;
        }, Cards_Constants.MILLI_SEC/2);
    }
    
    protected fn_PassEventData(evtOp: EventOperations, evtType: EventsType)
    {
        this.evtArgs = this.evtArgs == null ? new EventArgs() : this.evtArgs;

        this.evtArgs.evtOp = evtOp;
        this.evtArgs.evtType = evtType;
        this.uiManager.fn_PassEventData(this.evtArgs);
    }
}

