import { Component, EventEmitter, Input, Output } from '@angular/core';
import { ControlContainer, NgForm } from '@angular/forms';
import { pull } from 'lodash-es';
import { relations } from './dynamic-accesss-mapping-relations.model';
import * as i0 from "@angular/core";
import * as i1 from "@angular/forms";
import * as i2 from "@c8y/ngx-components";
import * as i3 from "@angular/common";
import * as i4 from "ngx-bootstrap/tooltip";
export class ChildPredicatesComponent {
    constructor(controlContainer) {
        this.controlContainer = controlContainer;
        this.onRemoveAllChildPredicates = new EventEmitter();
        this.relations = relations;
    }
    removeChildPredicate(childPredicate) {
        pull(this.childPredicates, childPredicate);
        if (this.childPredicates.length === 0) {
            this.onRemoveAllChildPredicates.emit();
        }
        this.controlContainer.control.markAsDirty();
    }
    addChildPredicate() {
        this.childPredicates.push({
            operator: 'EQ',
            parameterPath: '',
            value: ''
        });
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: ChildPredicatesComponent, deps: [{ token: i1.ControlContainer }], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.2.13", type: ChildPredicatesComponent, selector: "c8y-sso-child-predicates", inputs: { childPredicates: "childPredicates", accessMappingIndex: "accessMappingIndex" }, outputs: { onRemoveAllChildPredicates: "onRemoveAllChildPredicates" }, ngImport: i0, template: "<fieldset class=\"c8y-fieldset p-16\">\n  <legend>{{ 'When' | translate }}</legend>\n  <div class=\"tight-grid hidden-sm hidden-xs\">\n    <div class=\"col-md-4\">\n      <label translate>Key</label>\n    </div>\n    <div class=\"col-md-2\">\n      <label translate>Operator`logical`</label>\n    </div>\n    <div class=\"col-md-4\">\n      <label translate>Value</label>\n    </div>\n  </div>\n  <div\n    class=\"tight-grid\"\n    *ngFor=\"let childPredicate of childPredicates; last as isLast; index as idx\"\n  >\n    <div class=\"col-md-4\">\n      <c8y-form-group>\n        <label\n          [for]=\"'parameterPath' + accessMappingIndex + idx\"\n          class=\"visible-sm visible-xs\"\n          translate\n        >\n          Key\n        </label>\n        <input\n          [name]=\"'parameterPath' + accessMappingIndex + idx\"\n          [id]=\"'parameterPath' + accessMappingIndex + idx\"\n          type=\"text\"\n          class=\"form-control\"\n          [(ngModel)]=\"childPredicate.parameterPath\"\n          placeholder=\"{{ 'Key' | translate }}\"\n          required\n        />\n      </c8y-form-group>\n    </div>\n    <div class=\"col-md-2\">\n      <c8y-form-group>\n        <label\n          [for]=\"'operator' + accessMappingIndex + idx\"\n          class=\"visible-sm visible-xs\"\n          translate\n        >\n          Operator`logical`\n        </label>\n        <div class=\"c8y-select-wrapper\">\n          <select\n            class=\"form-control\"\n            [name]=\"'operator' + accessMappingIndex + idx\"\n            [id]=\"'operator' + accessMappingIndex + idx\"\n            [(ngModel)]=\"childPredicate.operator\"\n            required\n          >\n            <option\n              *ngFor=\"let relation of relations\"\n              [ngValue]=\"relation.value\"\n            >\n              {{ relation.label | translate }}\n            </option>\n          </select>\n          <span></span>\n        </div>\n      </c8y-form-group>\n    </div>\n    <div class=\"col-md-4\">\n      <c8y-form-group>\n        <label\n          [for]=\"'value' + accessMappingIndex + idx\"\n          class=\"visible-sm visible-xs\"\n          translate\n        >\n          Value\n        </label>\n        <input\n          [id]=\"'value' + accessMappingIndex + idx\"\n          [name]=\"'value' + accessMappingIndex + idx\"\n          type=\"text\"\n          class=\"form-control\"\n          [(ngModel)]=\"childPredicate.value\"\n          placeholder=\"{{ 'Value' | translate }}\"\n          required\n        />\n      </c8y-form-group>\n    </div>\n    <div class=\"col-md-1\">\n      <c8y-form-group>\n        <button\n          class=\"btn btn-dot btn-dot--danger hidden-xs hidden-sm\"\n          name=\"removeButton\"\n          (click)=\"removeChildPredicate(childPredicate)\"\n          tooltip=\"{{ 'Remove' | translate }}\"\n          [attr.aria-label]=\"'Remove' | translate\"\n          [delay]=\"300\"\n          type=\"button\"\n        >\n          <i c8yIcon=\"minus-circle\"></i>\n        </button>\n        <button\n          name=\"removeButton\"\n          class=\"btn btn-danger btn-block btn-sm visible-xs visible-sm\"\n          (click)=\"removeChildPredicate(childPredicate)\"\n          title=\"{{ 'Remove' | translate }}\"\n          type=\"button\"\n        >\n          <i c8yIcon=\"minus-circle\"></i>\n          <span translate>Remove</span>\n        </button>\n      </c8y-form-group>\n    </div>\n    <div class=\"col-md-1\">\n      <c8y-form-group *ngIf=\"isLast\">\n        <button\n          title=\"{{ 'and' | translate }}\"\n          class=\"btn btn-default btn-block btn-sm\"\n          (click)=\"addChildPredicate()\"\n          type=\"button\"\n          translate\n        >\n          and\n        </button>\n      </c8y-form-group>\n    </div>\n  </div>\n</fieldset>\n", dependencies: [{ kind: "directive", type: i2.IconDirective, selector: "[c8yIcon]", inputs: ["c8yIcon"] }, { kind: "directive", type: i2.C8yTranslateDirective, selector: "[translate],[ngx-translate]" }, { kind: "directive", type: i3.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i3.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i1.NgSelectOption, selector: "option", inputs: ["ngValue", "value"] }, { kind: "directive", type: i1.ɵNgSelectMultipleOption, selector: "option", inputs: ["ngValue", "value"] }, { 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.SelectControlValueAccessor, selector: "select:not([multiple])[formControlName],select:not([multiple])[formControl],select:not([multiple])[ngModel]", inputs: ["compareWith"] }, { kind: "directive", type: i1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i1.RequiredValidator, selector: ":not([type=checkbox])[required][formControlName],:not([type=checkbox])[required][formControl],:not([type=checkbox])[required][ngModel]", inputs: ["required"] }, { kind: "directive", type: i1.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }, { kind: "component", type: i2.FormGroupComponent, selector: "c8y-form-group", inputs: ["hasError", "hasWarning", "hasSuccess", "novalidation", "status"] }, { kind: "directive", type: i2.RequiredInputPlaceholderDirective, selector: "input[required], input[formControlName]" }, { kind: "directive", type: i4.TooltipDirective, selector: "[tooltip], [tooltipHtml]", inputs: ["adaptivePosition", "tooltip", "placement", "triggers", "container", "containerClass", "boundariesElement", "isOpen", "isDisabled", "delay", "tooltipHtml", "tooltipPlacement", "tooltipIsOpen", "tooltipEnable", "tooltipAppendToBody", "tooltipAnimation", "tooltipClass", "tooltipContext", "tooltipPopupDelay", "tooltipFadeDuration", "tooltipTrigger"], outputs: ["tooltipChange", "onShown", "onHidden", "tooltipStateChanged"], exportAs: ["bs-tooltip"] }, { kind: "pipe", type: i2.C8yTranslatePipe, name: "translate" }], viewProviders: [{ provide: ControlContainer, useExisting: NgForm }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: ChildPredicatesComponent, decorators: [{
            type: Component,
            args: [{ selector: 'c8y-sso-child-predicates', viewProviders: [{ provide: ControlContainer, useExisting: NgForm }], template: "<fieldset class=\"c8y-fieldset p-16\">\n  <legend>{{ 'When' | translate }}</legend>\n  <div class=\"tight-grid hidden-sm hidden-xs\">\n    <div class=\"col-md-4\">\n      <label translate>Key</label>\n    </div>\n    <div class=\"col-md-2\">\n      <label translate>Operator`logical`</label>\n    </div>\n    <div class=\"col-md-4\">\n      <label translate>Value</label>\n    </div>\n  </div>\n  <div\n    class=\"tight-grid\"\n    *ngFor=\"let childPredicate of childPredicates; last as isLast; index as idx\"\n  >\n    <div class=\"col-md-4\">\n      <c8y-form-group>\n        <label\n          [for]=\"'parameterPath' + accessMappingIndex + idx\"\n          class=\"visible-sm visible-xs\"\n          translate\n        >\n          Key\n        </label>\n        <input\n          [name]=\"'parameterPath' + accessMappingIndex + idx\"\n          [id]=\"'parameterPath' + accessMappingIndex + idx\"\n          type=\"text\"\n          class=\"form-control\"\n          [(ngModel)]=\"childPredicate.parameterPath\"\n          placeholder=\"{{ 'Key' | translate }}\"\n          required\n        />\n      </c8y-form-group>\n    </div>\n    <div class=\"col-md-2\">\n      <c8y-form-group>\n        <label\n          [for]=\"'operator' + accessMappingIndex + idx\"\n          class=\"visible-sm visible-xs\"\n          translate\n        >\n          Operator`logical`\n        </label>\n        <div class=\"c8y-select-wrapper\">\n          <select\n            class=\"form-control\"\n            [name]=\"'operator' + accessMappingIndex + idx\"\n            [id]=\"'operator' + accessMappingIndex + idx\"\n            [(ngModel)]=\"childPredicate.operator\"\n            required\n          >\n            <option\n              *ngFor=\"let relation of relations\"\n              [ngValue]=\"relation.value\"\n            >\n              {{ relation.label | translate }}\n            </option>\n          </select>\n          <span></span>\n        </div>\n      </c8y-form-group>\n    </div>\n    <div class=\"col-md-4\">\n      <c8y-form-group>\n        <label\n          [for]=\"'value' + accessMappingIndex + idx\"\n          class=\"visible-sm visible-xs\"\n          translate\n        >\n          Value\n        </label>\n        <input\n          [id]=\"'value' + accessMappingIndex + idx\"\n          [name]=\"'value' + accessMappingIndex + idx\"\n          type=\"text\"\n          class=\"form-control\"\n          [(ngModel)]=\"childPredicate.value\"\n          placeholder=\"{{ 'Value' | translate }}\"\n          required\n        />\n      </c8y-form-group>\n    </div>\n    <div class=\"col-md-1\">\n      <c8y-form-group>\n        <button\n          class=\"btn btn-dot btn-dot--danger hidden-xs hidden-sm\"\n          name=\"removeButton\"\n          (click)=\"removeChildPredicate(childPredicate)\"\n          tooltip=\"{{ 'Remove' | translate }}\"\n          [attr.aria-label]=\"'Remove' | translate\"\n          [delay]=\"300\"\n          type=\"button\"\n        >\n          <i c8yIcon=\"minus-circle\"></i>\n        </button>\n        <button\n          name=\"removeButton\"\n          class=\"btn btn-danger btn-block btn-sm visible-xs visible-sm\"\n          (click)=\"removeChildPredicate(childPredicate)\"\n          title=\"{{ 'Remove' | translate }}\"\n          type=\"button\"\n        >\n          <i c8yIcon=\"minus-circle\"></i>\n          <span translate>Remove</span>\n        </button>\n      </c8y-form-group>\n    </div>\n    <div class=\"col-md-1\">\n      <c8y-form-group *ngIf=\"isLast\">\n        <button\n          title=\"{{ 'and' | translate }}\"\n          class=\"btn btn-default btn-block btn-sm\"\n          (click)=\"addChildPredicate()\"\n          type=\"button\"\n          translate\n        >\n          and\n        </button>\n      </c8y-form-group>\n    </div>\n  </div>\n</fieldset>\n" }]
        }], ctorParameters: () => [{ type: i1.ControlContainer }], propDecorators: { childPredicates: [{
                type: Input
            }], accessMappingIndex: [{
                type: Input
            }], onRemoveAllChildPredicates: [{
                type: Output
            }] } });
//# sourceMappingURL=data:application/json;base64, 