import { Component, forwardRef, Input } from '@angular/core';
import { FormBuilder, FormControl, NG_VALIDATORS, NG_VALUE_ACCESSOR, Validators } from '@angular/forms';
import { take } from 'rxjs/operators';
import { AlarmEventAttributesFormService } from './alarm-event-attributes-form.service';
import * as i0 from "@angular/core";
import * as i1 from "@angular/forms";
import * as i2 from "./alarm-event-attributes-form.service";
import * as i3 from "@angular/common";
import * as i4 from "@c8y/ngx-components";
export class AlarmEventAttributesFormComponent {
    constructor(formBuilder, alarmEventAttributesFormService) {
        this.formBuilder = formBuilder;
        this.alarmEventAttributesFormService = alarmEventAttributesFormService;
        this.omitProperties = {};
        this.selectedItems = [];
    }
    ngOnInit() {
        this.formGroup = this.formBuilder.group({
            filters: this.formBuilder.group({
                type: [
                    '',
                    [
                        Validators.required,
                        this.alarmEventAttributesFormService.duplicateTypeValidator(this.selectedItems)
                    ]
                ]
            }),
            timelineType: ''
        });
        if (!this.omitProperties.label) {
            this.formGroup.addControl('label', new FormControl('', Validators.required));
        }
    }
    validate(_control) {
        return this.formGroup?.valid ? null : { formInvalid: {} };
    }
    writeValue(obj) {
        this.formGroup.patchValue(obj);
    }
    registerOnChange(fn) {
        this.formGroup.valueChanges.subscribe(fn);
    }
    registerOnTouched(fn) {
        this.formGroup.valueChanges.pipe(take(1)).subscribe(fn);
    }
    setDisabledState(isDisabled) {
        isDisabled ? this.formGroup.disable() : this.formGroup.enable();
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.9", ngImport: i0, type: AlarmEventAttributesFormComponent, deps: [{ token: i1.FormBuilder }, { token: i2.AlarmEventAttributesFormService }], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.2.9", type: AlarmEventAttributesFormComponent, selector: "c8y-alarm-event-attributes-form", inputs: { timelineType: "timelineType", omitProperties: "omitProperties", selectedItems: "selectedItems" }, providers: [
            {
                provide: NG_VALUE_ACCESSOR,
                useExisting: forwardRef(() => AlarmEventAttributesFormComponent),
                multi: true
            },
            {
                provide: NG_VALIDATORS,
                useExisting: forwardRef(() => AlarmEventAttributesFormComponent),
                multi: true
            }
        ], ngImport: i0, template: "<div [formGroup]=\"formGroup\">\n  <c8y-form-group *ngIf=\"formGroup.controls.label\">\n    <label class=\"m-0\">{{ 'Label' | translate }}</label>\n    <input\n      class=\"form-control flex-grow\"\n      name=\"label\"\n      formControlName=\"label\"\n      [placeholder]=\"\n        'e.g. {{ example }}'\n          | translate\n            : {\n                example: timelineType === 'ALARM' ? 'Alarm unavailable' : 'Location update'\n              }\n      \"\n    />\n  </c8y-form-group>\n\n  <div formGroupName=\"filters\">\n    <c8y-form-group>\n      <label class=\"m-0\">{{ 'Type' | translate }}</label>\n      <input\n        class=\"form-control flex-grow\"\n        name=\"type\"\n        formControlName=\"type\"\n        [placeholder]=\"\n          'e.g. {{ example }}'\n            | translate\n              : {\n                  example:\n                    timelineType === 'ALARM' ? 'c8y_UnavailabilityAlarm' : 'c8y_LocationUpdate'\n                }\n        \"\n      />\n      <c8y-messages>\n        <c8y-message\n          name=\"duplicateType\"\n          [text]=\"'Type already used.' | translate\"\n        ></c8y-message>\n      </c8y-messages>\n    </c8y-form-group>\n  </div>\n</div>\n", dependencies: [{ kind: "directive", type: i3.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i1.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: i1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i1.NgControlStatusGroup, selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],form:not([ngNoForm]),[ngForm]" }, { kind: "component", type: i4.FormGroupComponent, selector: "c8y-form-group", inputs: ["hasError", "hasWarning", "hasSuccess", "novalidation", "status"] }, { kind: "directive", type: i4.MessageDirective, selector: "c8y-message", inputs: ["name", "text"] }, { kind: "component", type: i4.MessagesComponent, selector: "c8y-messages", inputs: ["show", "defaults", "helpMessage"] }, { kind: "directive", type: i4.RequiredInputPlaceholderDirective, selector: "input[required], input[formControlName]" }, { kind: "directive", type: i1.FormGroupDirective, selector: "[formGroup]", inputs: ["formGroup"], outputs: ["ngSubmit"], exportAs: ["ngForm"] }, { kind: "directive", type: i1.FormControlName, selector: "[formControlName]", inputs: ["formControlName", "disabled", "ngModel"], outputs: ["ngModelChange"] }, { kind: "directive", type: i1.FormGroupName, selector: "[formGroupName]", inputs: ["formGroupName"] }, { kind: "pipe", type: i4.C8yTranslatePipe, name: "translate" }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.9", ngImport: i0, type: AlarmEventAttributesFormComponent, decorators: [{
            type: Component,
            args: [{ selector: 'c8y-alarm-event-attributes-form', providers: [
                        {
                            provide: NG_VALUE_ACCESSOR,
                            useExisting: forwardRef(() => AlarmEventAttributesFormComponent),
                            multi: true
                        },
                        {
                            provide: NG_VALIDATORS,
                            useExisting: forwardRef(() => AlarmEventAttributesFormComponent),
                            multi: true
                        }
                    ], template: "<div [formGroup]=\"formGroup\">\n  <c8y-form-group *ngIf=\"formGroup.controls.label\">\n    <label class=\"m-0\">{{ 'Label' | translate }}</label>\n    <input\n      class=\"form-control flex-grow\"\n      name=\"label\"\n      formControlName=\"label\"\n      [placeholder]=\"\n        'e.g. {{ example }}'\n          | translate\n            : {\n                example: timelineType === 'ALARM' ? 'Alarm unavailable' : 'Location update'\n              }\n      \"\n    />\n  </c8y-form-group>\n\n  <div formGroupName=\"filters\">\n    <c8y-form-group>\n      <label class=\"m-0\">{{ 'Type' | translate }}</label>\n      <input\n        class=\"form-control flex-grow\"\n        name=\"type\"\n        formControlName=\"type\"\n        [placeholder]=\"\n          'e.g. {{ example }}'\n            | translate\n              : {\n                  example:\n                    timelineType === 'ALARM' ? 'c8y_UnavailabilityAlarm' : 'c8y_LocationUpdate'\n                }\n        \"\n      />\n      <c8y-messages>\n        <c8y-message\n          name=\"duplicateType\"\n          [text]=\"'Type already used.' | translate\"\n        ></c8y-message>\n      </c8y-messages>\n    </c8y-form-group>\n  </div>\n</div>\n" }]
        }], ctorParameters: () => [{ type: i1.FormBuilder }, { type: i2.AlarmEventAttributesFormService }], propDecorators: { timelineType: [{
                type: Input
            }], omitProperties: [{
                type: Input
            }], selectedItems: [{
                type: Input
            }] } });
//# sourceMappingURL=data:application/json;base64, 