import { autoinject, Container, transient, ViewResources } from "aurelia-framework";
import { VanillaFrameworkOverrides, IFrameworkOverrides, AgPromise } from "ag-grid-community";

@autoinject()
@transient()
export class AureliaFrameworkFactory implements IFrameworkOverrides {
    private _container: Container;
    private _viewResources: ViewResources;
    private _baseFrameworkFactory: IFrameworkOverrides = new VanillaFrameworkOverrides();    // todo - inject this

    public setContainer(container: Container): void {
        this._container = container;
    }

    public setViewResources(viewResources: ViewResources): void {
        this._viewResources = viewResources;
    }

    setTimeout(action: any, timeout?: any): void {
        this._baseFrameworkFactory.setTimeout(action, timeout);
    }

    setInterval(action: any, interval?: any): AgPromise<number> {
        return this._baseFrameworkFactory.setInterval(action, interval);
    }

    addEventListener(element: HTMLElement, type: string, listener: EventListener | EventListenerObject, options?: boolean | AddEventListenerOptions): void {
        this._baseFrameworkFactory.addEventListener(element, type, listener, options);
    }

    dispatchEvent(eventType: string, listener: () => {}, global: boolean): void {
        this._baseFrameworkFactory.dispatchEvent(eventType, listener, global);
    }

    frameworkComponent(name: string) {
        this._baseFrameworkFactory.frameworkComponent(name);
    }

    isFrameworkComponent(comp: any): boolean {
        return this._baseFrameworkFactory.isFrameworkComponent(comp);
    }
}
