import { Component, Input, Output, EventEmitter } from '@angular/core';
import { set, unset, toInteger } from 'lodash';
import { gettext } from '@c8y/ngx-components';
import { ControlContainer, NgModelGroup } from '@angular/forms';
import * as i0 from "@angular/core";
import * as i1 from "@c8y/ngx-components";
import * as i2 from "@angular/common";
import * as i3 from "@angular/forms";
import * as i4 from "ngx-bootstrap/collapse";
export class OpcuaDeviceProtocolDataReportingComponent {
    constructor() {
        this.onSubscriptionChange = new EventEmitter();
        this.subscription = {
            type: 'None'
        };
        this.subscriptionParameters = {
            samplingRate: undefined,
            deadbandType: 'None',
            deadbandValue: undefined,
            ranges: '',
            queueSize: undefined,
            dataChangeTrigger: 'Status',
            discardOldest: true
        };
        this.cyclicReadParameters = {
            rate: undefined
        };
        this.types = [
            { value: 'None', label: gettext('None') },
            { value: 'CyclicRead', label: gettext('Cyclic read') },
            { value: 'Subscription', label: gettext('Subscription') }
        ];
        this.filters = [
            { value: 'None', label: gettext('None') },
            { value: 'Absolute', label: gettext('Absolute') },
            { value: 'Percent', label: gettext('Percent') }
        ];
        this.triggers = [
            { value: 'Status', label: gettext('Status') },
            { value: 'StatusValue', label: gettext('Status/Value') },
            { value: 'StatusValueTimestamp', label: gettext('Status/Value/Timestamp') }
        ];
        this.discard = [
            { value: true, label: gettext('oldest`data`') },
            { value: false, label: gettext('newest`data`') }
        ];
        this.requireCyclic = false;
        this.requireSubscription = false;
        this.subscriptionTypeName = 'subscriptionType';
        this.parseReadingInterval = $event => toInteger($event.target.value);
    }
    set model(_model) {
        if (_model.subscriptionType) {
            this.subscription = _model.subscriptionType;
            if (this.subscription.type === 'CyclicRead') {
                this.cyclicReadParameters = _model.subscriptionType.cyclicReadParameters;
                this.requireCyclic = true;
                this.requireSubscription = false;
            }
            if (this.subscription.type === 'Subscription') {
                this.subscriptionParameters = _model.subscriptionType.subscriptionParameters;
                this.requireCyclic = false;
                this.requireSubscription = true;
            }
            if (this.subscription.type === 'None') {
                this.requireCyclic = false;
                this.requireSubscription = false;
            }
        }
        this._model = _model;
        this.subscriptionTypeName = 'subscriptionType' + _model.id;
    }
    updateModel() {
        setTimeout(() => {
            unset(this.subscription, 'subscriptionParameters');
            unset(this.subscription, 'cyclicReadParameters');
            if (this.subscription.type === 'CyclicRead') {
                this.requireCyclic = true;
                this.requireSubscription = false;
                set(this.subscription, 'cyclicReadParameters', this.cyclicReadParameters);
            }
            else if (this.subscription.type === 'Subscription') {
                this.requireCyclic = false;
                this.requireSubscription = true;
                set(this.subscription, 'subscriptionParameters', this.subscriptionParameters);
            }
            else if (this.subscription.type === 'None') {
                this.requireCyclic = false;
                this.requireSubscription = false;
            }
            this.onSubscriptionChange.emit(this.subscription);
        });
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: OpcuaDeviceProtocolDataReportingComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.2.13", type: OpcuaDeviceProtocolDataReportingComponent, selector: "opcua-device-protocol-data-reporting", inputs: { model: "model", groupName: "groupName" }, outputs: { onSubscriptionChange: "onSubscriptionChange" }, ngImport: i0, template: "<c8y-form-group>\n  <label translate>Mechanism</label>\n  <label\n    title=\"{{ mechanism.label | translate }}\"\n    class=\"c8y-radio radio-inline\"\n    *ngFor=\"let mechanism of types\"\n  >\n    <input\n      type=\"radio\"\n      name=\"{{subscriptionTypeName}}\"\n      [value]=\"mechanism.value\"\n      [(ngModel)]=\"subscription.type\"\n      (change)=\"updateModel()\"\n      required\n      [attr.data-cy]=\"mechanism.value\"\n    />\n    <span></span>\n    <span>{{ mechanism.label | translate }}</span>\n  </label>\n</c8y-form-group>\n\n<div class=\"row collapse\" [collapse]=\"subscription.type != 'CyclicRead'\" [isAnimated]=\"true\">\n  <div class=\"col-sm-6 col-md-4 col-lg-3\">\n    <c8y-form-group>\n      <label translate>Reading interval</label>\n      <div class=\"input-group\">\n        <input\n          class=\"form-control\"\n          type=\"number\"\n          name=\"rate\"\n          [(ngModel)]=\"cyclicReadParameters.rate\"\n          placeholder=\"{{ 'e.g.' | translate }} 50\"\n          [required]=\"requireCyclic\"\n          min=\"50\"\n          [attr.data-cy]=\"'cyclicReadRate'\"\n        />\n        <span class=\"input-group-addon units\" title=\"{{ 'Milliseconds' | translate }}\">\n          {{ 'msec' | translate }}\n        </span>\n      </div>\n    </c8y-form-group>\n  </div>\n</div>\n\n<div class=\"row collapse\" [collapse]=\"subscription.type != 'Subscription'\" [isAnimated]=\"true\">\n  <div class=\"col-sm-6 col-lg-4\">\n    <c8y-form-group>\n      <label translate>Sampling interval</label>\n      <div class=\"input-group\">\n        <input\n          class=\"form-control\"\n          type=\"number\"\n          name=\"samplingRate\"\n          [(ngModel)]=\"subscriptionParameters.samplingRate\"\n          placeholder=\"{{ 'e.g.' | translate }} 500\"\n          [required]=\"requireSubscription\"\n          min=\"0\"\n          [attr.data-cy]=\"'subscriptionSamplingRate'\"\n        />\n        <span class=\"input-group-addon units\" title=\"{{ 'Milliseconds' | translate }}\" translate>\n          msec\n        </span>\n      </div>\n    </c8y-form-group>\n  </div>\n  <div class=\"col-sm-6 col-lg-4\">\n    <c8y-form-group>\n      <label translate>Queue size</label>\n      <div class=\"input-group\">\n        <input\n          class=\"form-control\"\n          type=\"number\"\n          name=\"queueSize\"\n          [(ngModel)]=\"subscriptionParameters.queueSize\"\n          placeholder=\"{{ 'e.g.' | translate }} 10\"\n          min=\"1\"\n          [attr.data-cy]=\"'subscriptionQueueSize'\"\n        />\n        <span class=\"input-group-addon\">\n          <strong translate>Discard</strong>&nbsp;\n          <label\n            *ngFor=\"let discardOption of discard\"\n            title=\"{{ discardOption.label | translate }}\"\n            class=\"c8y-radio radio-inline\"\n          >\n            <input\n              type=\"radio\"\n              name=\"discard{{ _model.id }}\"\n              [value]=\"discardOption.value\"\n              [(ngModel)]=\"subscriptionParameters.discardOldest\"\n              [required]=\"requireSubscription\"\n              [attr.data-cy]=\"discardOption.label\"\n              [attr.data-name]=\"'discard' + _model.id\"\n            />\n            <span></span>\n            <span>{{ discardOption.label | translate }}</span>\n          </label>\n        </span>\n      </div>\n    </c8y-form-group>\n  </div>\n  <div class=\"clearfix\"></div>\n  <div class=\"col-sm-6 col-lg-4\">\n    <c8y-form-group>\n      <label translate>Data change trigger</label>\n      <label\n        *ngFor=\"let trigger of triggers\"\n        title=\"{{ trigger.label | translate }}\"\n        class=\"c8y-radio radio-inline\"\n      >\n        <input\n          type=\"radio\"\n          name=\"dataChangeTrigger{{ _model.id }}\"\n          [value]=\"trigger.value\"\n          [(ngModel)]=\"subscriptionParameters.dataChangeTrigger\"\n          [required]=\"requireSubscription\"\n          [attr.data-cy]=\"trigger.label\"\n          [attr.data-name]=\"'dataChangeTrigger' + _model.id\"\n        />\n        <span></span>\n        <span>{{ trigger.label | translate }}</span>\n      </label>\n    </c8y-form-group>\n  </div>\n  <div class=\"col-sm-6 col-lg-4\">\n    <c8y-form-group>\n      <label translate>Deadband filter</label>\n      <label\n        *ngFor=\"let deadbandFilter of filters\"\n        title=\"{{ deadbandFilter.label | translate }}\"\n        class=\"c8y-radio radio-inline\"\n      >\n        <input\n          type=\"radio\"\n          name=\"deadbandType{{ _model.id }}\"\n          [value]=\"deadbandFilter.value\"\n          [(ngModel)]=\"subscriptionParameters.deadbandType\"\n          [required]=\"requireSubscription\"\n          [attr.data-cy]=\"deadbandFilter.label\"\n          [attr.data-name]=\"'deadbandType' + _model.id\"\n        />\n        <span></span>\n        <span>{{ deadbandFilter.label | translate }}</span>\n      </label>\n    </c8y-form-group>\n    <div [collapse]=\"subscriptionParameters.deadbandType == 'None'\" [isAnimated]=\"true\">\n      <c8y-form-group>\n        <label translate>Deadband value</label>\n        <input\n          class=\"form-control\"\n          type=\"number\"\n          name=\"deadbandValue\"\n          [(ngModel)]=\"subscriptionParameters.deadbandValue\"\n          placeholder=\"{{ 'e.g.' | translate }} 10\"\n          [required]=\"subscriptionParameters.deadbandType != 'None'\"\n          min=\"0\"\n          [attr.data-cy]=\"'deadbandValue'\"\n        />\n      </c8y-form-group>\n    </div>\n  </div>\n</div>\n", dependencies: [{ kind: "directive", type: i1.C8yTranslateDirective, selector: "[translate],[ngx-translate]" }, { kind: "directive", type: i2.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i1.MinValidationDirective, selector: "[min]", inputs: ["min"] }, { kind: "directive", type: i3.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: i3.NumberValueAccessor, selector: "input[type=number][formControlName],input[type=number][formControl],input[type=number][ngModel]" }, { kind: "directive", type: i3.RadioControlValueAccessor, selector: "input[type=radio][formControlName],input[type=radio][formControl],input[type=radio][ngModel]", inputs: ["name", "formControlName", "value"] }, { kind: "directive", type: i3.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i3.RequiredValidator, selector: ":not([type=checkbox])[required][formControlName],:not([type=checkbox])[required][formControl],:not([type=checkbox])[required][ngModel]", inputs: ["required"] }, { kind: "directive", type: i3.MinValidator, selector: "input[type=number][min][formControlName],input[type=number][min][formControl],input[type=number][min][ngModel]", inputs: ["min"] }, { kind: "directive", type: i3.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }, { kind: "component", type: i1.FormGroupComponent, selector: "c8y-form-group", inputs: ["hasError", "hasWarning", "hasSuccess", "novalidation", "status"] }, { kind: "directive", type: i1.RequiredInputPlaceholderDirective, selector: "input[required], input[formControlName]" }, { kind: "directive", type: i4.CollapseDirective, selector: "[collapse]", inputs: ["display", "isAnimated", "collapse"], outputs: ["collapsed", "collapses", "expanded", "expands"], exportAs: ["bs-collapse"] }, { kind: "pipe", type: i1.C8yTranslatePipe, name: "translate" }], viewProviders: [{ provide: ControlContainer, useExisting: NgModelGroup }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: OpcuaDeviceProtocolDataReportingComponent, decorators: [{
            type: Component,
            args: [{ selector: 'opcua-device-protocol-data-reporting', viewProviders: [{ provide: ControlContainer, useExisting: NgModelGroup }], template: "<c8y-form-group>\n  <label translate>Mechanism</label>\n  <label\n    title=\"{{ mechanism.label | translate }}\"\n    class=\"c8y-radio radio-inline\"\n    *ngFor=\"let mechanism of types\"\n  >\n    <input\n      type=\"radio\"\n      name=\"{{subscriptionTypeName}}\"\n      [value]=\"mechanism.value\"\n      [(ngModel)]=\"subscription.type\"\n      (change)=\"updateModel()\"\n      required\n      [attr.data-cy]=\"mechanism.value\"\n    />\n    <span></span>\n    <span>{{ mechanism.label | translate }}</span>\n  </label>\n</c8y-form-group>\n\n<div class=\"row collapse\" [collapse]=\"subscription.type != 'CyclicRead'\" [isAnimated]=\"true\">\n  <div class=\"col-sm-6 col-md-4 col-lg-3\">\n    <c8y-form-group>\n      <label translate>Reading interval</label>\n      <div class=\"input-group\">\n        <input\n          class=\"form-control\"\n          type=\"number\"\n          name=\"rate\"\n          [(ngModel)]=\"cyclicReadParameters.rate\"\n          placeholder=\"{{ 'e.g.' | translate }} 50\"\n          [required]=\"requireCyclic\"\n          min=\"50\"\n          [attr.data-cy]=\"'cyclicReadRate'\"\n        />\n        <span class=\"input-group-addon units\" title=\"{{ 'Milliseconds' | translate }}\">\n          {{ 'msec' | translate }}\n        </span>\n      </div>\n    </c8y-form-group>\n  </div>\n</div>\n\n<div class=\"row collapse\" [collapse]=\"subscription.type != 'Subscription'\" [isAnimated]=\"true\">\n  <div class=\"col-sm-6 col-lg-4\">\n    <c8y-form-group>\n      <label translate>Sampling interval</label>\n      <div class=\"input-group\">\n        <input\n          class=\"form-control\"\n          type=\"number\"\n          name=\"samplingRate\"\n          [(ngModel)]=\"subscriptionParameters.samplingRate\"\n          placeholder=\"{{ 'e.g.' | translate }} 500\"\n          [required]=\"requireSubscription\"\n          min=\"0\"\n          [attr.data-cy]=\"'subscriptionSamplingRate'\"\n        />\n        <span class=\"input-group-addon units\" title=\"{{ 'Milliseconds' | translate }}\" translate>\n          msec\n        </span>\n      </div>\n    </c8y-form-group>\n  </div>\n  <div class=\"col-sm-6 col-lg-4\">\n    <c8y-form-group>\n      <label translate>Queue size</label>\n      <div class=\"input-group\">\n        <input\n          class=\"form-control\"\n          type=\"number\"\n          name=\"queueSize\"\n          [(ngModel)]=\"subscriptionParameters.queueSize\"\n          placeholder=\"{{ 'e.g.' | translate }} 10\"\n          min=\"1\"\n          [attr.data-cy]=\"'subscriptionQueueSize'\"\n        />\n        <span class=\"input-group-addon\">\n          <strong translate>Discard</strong>&nbsp;\n          <label\n            *ngFor=\"let discardOption of discard\"\n            title=\"{{ discardOption.label | translate }}\"\n            class=\"c8y-radio radio-inline\"\n          >\n            <input\n              type=\"radio\"\n              name=\"discard{{ _model.id }}\"\n              [value]=\"discardOption.value\"\n              [(ngModel)]=\"subscriptionParameters.discardOldest\"\n              [required]=\"requireSubscription\"\n              [attr.data-cy]=\"discardOption.label\"\n              [attr.data-name]=\"'discard' + _model.id\"\n            />\n            <span></span>\n            <span>{{ discardOption.label | translate }}</span>\n          </label>\n        </span>\n      </div>\n    </c8y-form-group>\n  </div>\n  <div class=\"clearfix\"></div>\n  <div class=\"col-sm-6 col-lg-4\">\n    <c8y-form-group>\n      <label translate>Data change trigger</label>\n      <label\n        *ngFor=\"let trigger of triggers\"\n        title=\"{{ trigger.label | translate }}\"\n        class=\"c8y-radio radio-inline\"\n      >\n        <input\n          type=\"radio\"\n          name=\"dataChangeTrigger{{ _model.id }}\"\n          [value]=\"trigger.value\"\n          [(ngModel)]=\"subscriptionParameters.dataChangeTrigger\"\n          [required]=\"requireSubscription\"\n          [attr.data-cy]=\"trigger.label\"\n          [attr.data-name]=\"'dataChangeTrigger' + _model.id\"\n        />\n        <span></span>\n        <span>{{ trigger.label | translate }}</span>\n      </label>\n    </c8y-form-group>\n  </div>\n  <div class=\"col-sm-6 col-lg-4\">\n    <c8y-form-group>\n      <label translate>Deadband filter</label>\n      <label\n        *ngFor=\"let deadbandFilter of filters\"\n        title=\"{{ deadbandFilter.label | translate }}\"\n        class=\"c8y-radio radio-inline\"\n      >\n        <input\n          type=\"radio\"\n          name=\"deadbandType{{ _model.id }}\"\n          [value]=\"deadbandFilter.value\"\n          [(ngModel)]=\"subscriptionParameters.deadbandType\"\n          [required]=\"requireSubscription\"\n          [attr.data-cy]=\"deadbandFilter.label\"\n          [attr.data-name]=\"'deadbandType' + _model.id\"\n        />\n        <span></span>\n        <span>{{ deadbandFilter.label | translate }}</span>\n      </label>\n    </c8y-form-group>\n    <div [collapse]=\"subscriptionParameters.deadbandType == 'None'\" [isAnimated]=\"true\">\n      <c8y-form-group>\n        <label translate>Deadband value</label>\n        <input\n          class=\"form-control\"\n          type=\"number\"\n          name=\"deadbandValue\"\n          [(ngModel)]=\"subscriptionParameters.deadbandValue\"\n          placeholder=\"{{ 'e.g.' | translate }} 10\"\n          [required]=\"subscriptionParameters.deadbandType != 'None'\"\n          min=\"0\"\n          [attr.data-cy]=\"'deadbandValue'\"\n        />\n      </c8y-form-group>\n    </div>\n  </div>\n</div>\n" }]
        }], propDecorators: { model: [{
                type: Input
            }], groupName: [{
                type: Input
            }], onSubscriptionChange: [{
                type: Output
            }] } });
//# sourceMappingURL=data:application/json;base64, 