import { ChangeDetectionStrategy, ChangeDetectorRef, Component, Injector, Input, TemplateRef, Type } from '@angular/core';
import { FilteringFormRendererContext } from './filtering-form-renderer';
import * as i0 from "@angular/core";
import * as i1 from "@angular/common";
import * as i2 from "@angular/forms";
import * as i3 from "../../common/component-outlet.directive";
import * as i4 from "../../i18n/c8y-translate.pipe";
export class FilteringFormRendererComponent {
    set _spec(spec) {
        this.spec = spec;
    }
    constructor(injector, cd) {
        this.injector = injector;
        this.cd = cd;
        this.defaultRendererFilterText = '';
    }
    ngOnChanges() {
        const { renderer, context } = this.spec;
        if (renderer instanceof TemplateRef) {
            this.rendererType = 'TEMPLATE';
        }
        else if (renderer instanceof Type) {
            this.rendererType = 'COMPONENT';
            this.rendererInjector = Injector.create({
                providers: [{ provide: FilteringFormRendererContext, useValue: this.spec.context }],
                parent: this.injector
            });
        }
        const { filterPredicate } = context.property;
        if (typeof filterPredicate === 'string') {
            this.defaultRendererFilterText = filterPredicate;
        }
        if (filterPredicate === undefined) {
            this.defaultRendererFilterText = '';
        }
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: FilteringFormRendererComponent, deps: [{ token: i0.Injector }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.2.13", type: FilteringFormRendererComponent, selector: "c8y-filtering-form-renderer", inputs: { _spec: ["spec", "_spec"] }, usesOnChanges: true, ngImport: i0, template: "<ng-container *ngIf=\"spec.renderer\">\n  <ng-container\n    *ngIf=\"rendererType === 'TEMPLATE'\"\n    [ngTemplateOutlet]=\"spec.renderer\"\n    [ngTemplateOutletContext]=\"{ $implicit: spec.context }\"\n  ></ng-container>\n\n  <ng-container\n    *ngIf=\"rendererType === 'COMPONENT'\"\n    [c8yComponentOutlet]=\"spec.renderer\"\n    [c8yComponentOutletInjector]=\"rendererInjector\"\n  ></ng-container>\n</ng-container>\n\n<ng-container *ngIf=\"!spec.renderer\">\n  <div class=\"form-group p-t-8\">\n    <label>{{ 'Filter text' | translate }}</label>\n    <input\n      class=\"form-control\"\n      [(ngModel)]=\"defaultRendererFilterText\"\n      (keyup.enter)=\"\n        spec.context.applyFilter({\n          filterPredicate: defaultRendererFilterText\n        })\n      \"\n    />\n  </div>\n\n  <div class=\"data-grid__dropdown__footer d-flex separator-top\">\n    <button\n      title=\"{{ 'Reset' | translate }}\"\n      class=\"btn btn-default btn-sm flex-grow m-r-8\"\n      (click)=\"defaultRendererFilterText = ''; spec.context.resetFilter()\"\n    >\n      {{ 'Reset' | translate }}\n    </button>\n    <button\n      title=\"{{ 'Apply' | translate }}\"\n      class=\"btn btn-primary btn-sm flex-grow\"\n      (click)=\"\n        spec.context.applyFilter({\n          filterPredicate: defaultRendererFilterText\n        })\n      \"\n    >\n      {{ 'Apply' | translate }}\n    </button>\n  </div>\n</ng-container>\n", dependencies: [{ kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i1.NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "directive", type: i2.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { kind: "directive", type: i2.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i2.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }, { kind: "directive", type: i3.C8yComponentOutlet, selector: "[c8yComponentOutlet]", inputs: ["c8yComponentOutlet", "c8yComponentOutletInjector", "c8yComponentOutletEnvironmentInjector"] }, { kind: "pipe", type: i4.C8yTranslatePipe, name: "translate" }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: FilteringFormRendererComponent, decorators: [{
            type: Component,
            args: [{ selector: 'c8y-filtering-form-renderer', changeDetection: ChangeDetectionStrategy.OnPush, template: "<ng-container *ngIf=\"spec.renderer\">\n  <ng-container\n    *ngIf=\"rendererType === 'TEMPLATE'\"\n    [ngTemplateOutlet]=\"spec.renderer\"\n    [ngTemplateOutletContext]=\"{ $implicit: spec.context }\"\n  ></ng-container>\n\n  <ng-container\n    *ngIf=\"rendererType === 'COMPONENT'\"\n    [c8yComponentOutlet]=\"spec.renderer\"\n    [c8yComponentOutletInjector]=\"rendererInjector\"\n  ></ng-container>\n</ng-container>\n\n<ng-container *ngIf=\"!spec.renderer\">\n  <div class=\"form-group p-t-8\">\n    <label>{{ 'Filter text' | translate }}</label>\n    <input\n      class=\"form-control\"\n      [(ngModel)]=\"defaultRendererFilterText\"\n      (keyup.enter)=\"\n        spec.context.applyFilter({\n          filterPredicate: defaultRendererFilterText\n        })\n      \"\n    />\n  </div>\n\n  <div class=\"data-grid__dropdown__footer d-flex separator-top\">\n    <button\n      title=\"{{ 'Reset' | translate }}\"\n      class=\"btn btn-default btn-sm flex-grow m-r-8\"\n      (click)=\"defaultRendererFilterText = ''; spec.context.resetFilter()\"\n    >\n      {{ 'Reset' | translate }}\n    </button>\n    <button\n      title=\"{{ 'Apply' | translate }}\"\n      class=\"btn btn-primary btn-sm flex-grow\"\n      (click)=\"\n        spec.context.applyFilter({\n          filterPredicate: defaultRendererFilterText\n        })\n      \"\n    >\n      {{ 'Apply' | translate }}\n    </button>\n  </div>\n</ng-container>\n" }]
        }], ctorParameters: () => [{ type: i0.Injector }, { type: i0.ChangeDetectorRef }], propDecorators: { _spec: [{
                type: Input,
                args: ['spec']
            }] } });
//# sourceMappingURL=data:application/json;base64, 