import Events from './Events';

/** Event bus that logs all emitted events (except pointer move) when debug mode is enabled. */
export default class LoggedEvents extends Events
{
    private enableDebug = false;

    constructor()
    {
        super();

        window.enableDebugEvents = () =>
        {
            this.enableDebug = true;
        };
        window.disableDebugEvents = () =>
        {
            this.enableDebug = false;
        };
    }

    public override emit(event: string | symbol, ...args: unknown[]): boolean
    {
        if (event !== 'globalpointermove' && this.enableDebug)
        {
            // eslint-disable-next-line no-console
            console.log(`%c ${String(event)} %s`, 'background: #8095AA; color: white; padding: 2px;', args);
        }

        return super.emit(event, ...args);
    }

    public override dispose(): void
    {
        super.dispose();
        window.enableDebugEvents = undefined;
        window.disableDebugEvents = undefined;
    }
}
