import { IDoesFilterPassParams, IFilterComp, IFilterParams } from "ag-grid-community";
import { Container, TaskQueue } from "aurelia-framework";
import { I18N } from "aurelia-i18n";
import { UIInternal } from "../../utils/ui-internal";
import { BaseFilterBase } from "./base-filter-base";

export default abstract class BaseFilter extends BaseFilterBase implements IFilterComp {
    protected filterChangedCallback: Function;
    protected taskQueue: TaskQueue;

    public init(params: IFilterParams): void {
        super.init(params);
        this.taskQueue = Container.instance.get(TaskQueue);
        this.i18n = Container.instance.get(I18N);
        this.filterChangedCallback = params.filterChangedCallback;
        this.setupGui();
    }

    public async setupGui() {
        await super.setupGui(this.config.agGridConfig.showFilterBox, false);
        UIInternal.broadcast("end init filter " + (this.params as IFilterParams).colDef.field);
    }

    protected isDestroyed() {
        return (this.params?.api as any)?.destroyCalled;
    }

    public doesFilterPass(params: IDoesFilterPassParams): boolean {
        return true;
    }

    public abstract getValue(): any;

    public abstract getModelAsString?(model?: any): string;

    public abstract isFilterActive(): boolean;

    public abstract setupContentGuiSideFilter(): string;

    public abstract getModel(): any;

    public abstract setModel(model: any): void;

    public abstract removeFilterValue(filterValue: any): void;
}