import { Component, Input, Output, EventEmitter } from '@angular/core';
import { ControlContainer, NgForm } from '@angular/forms';
import * as i0 from "@angular/core";
import * as i1 from "@angular/forms";
import * as i2 from "@angular/common";
import * as i3 from "@c8y/ngx-components";
import * as i4 from "./child-predicates.component";
export class DynamicAccessMappingComponent {
    constructor(controlContainer) {
        this.controlContainer = controlContainer;
        this.onRemoveAccessMapping = new EventEmitter();
    }
    ngOnChanges() {
        if (this.accessMapping && this.apps && this.groups) {
            this.setSelectedItems();
        }
    }
    onRemoveAllChildPredicates() {
        this.onRemoveAccessMapping.emit(this.accessMapping);
    }
    getIds(selectedItems) {
        return selectedItems.map(item => parseInt(item.id, 10));
    }
    setSelectedItems() {
        if (this.accessMapping) {
            if (this.accessMapping.thenGroups) {
                this.selectedGroups = this.groups.filter(item => this.accessMapping.thenGroups.includes(item.id));
            }
            if (this.accessMapping.thenApplications) {
                this.selectedApps = this.apps.filter(item => this.accessMapping.thenApplications.includes(+item.id));
            }
        }
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.9", ngImport: i0, type: DynamicAccessMappingComponent, deps: [{ token: i1.ControlContainer }], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.2.9", type: DynamicAccessMappingComponent, selector: "c8y-sso-dynamic-access-mapping", inputs: { groups: "groups", apps: "apps", accessMapping: "accessMapping", accessMappingIndex: "accessMappingIndex" }, outputs: { onRemoveAccessMapping: "onRemoveAccessMapping" }, usesOnChanges: true, ngImport: i0, template: "<fieldset class=\"c8y-fieldset p-8\">\n  <div *ngIf=\"accessMapping.when.childPredicates.length != 0\">\n    <c8y-sso-child-predicates\n      [childPredicates]=\"accessMapping.when.childPredicates\"\n      [accessMappingIndex]=\"'am' + accessMappingIndex\"\n      (onRemoveAllChildPredicates)=\"onRemoveAllChildPredicates()\"\n    ></c8y-sso-child-predicates>\n\n    <fieldset class=\"c8y-fieldset p-16\">\n      <legend>\n        {{ 'Provide access to' | translate }}\n      </legend>\n      <div class=\"row\">\n        <div class=\"col-sm-6\">\n          <div\n            title=\"{{ 'Default global roles' | translate }}\"\n            class=\"form-group\"\n          >\n            <label\n              [for]=\"'groups' + accessMappingIndex\"\n              class=\"control-label\"\n            >\n              {{ 'Default global roles' | translate }}\n            </label>\n            <c8y-select-legacy\n              [id]=\"'groups' + accessMappingIndex\"\n              [items]=\"groups\"\n              [selected]=\"selectedGroups\"\n              [disableApplyOnNoSelection]=\"true\"\n              (onChange)=\"controlContainer.control.markAsDirty(); selectedGroups = $event; accessMapping.thenGroups = getIds($event)\"\n            ></c8y-select-legacy>\n          </div>\n        </div>\n        <div class=\"col-sm-6\">\n          <div\n            title=\"{{ 'Default applications' | translate }}\"\n            class=\"form-group\"\n          >\n            <label\n              [for]=\"'apps' + accessMappingIndex\"\n              class=\"control-label\"\n            >\n              {{ 'Default applications' | translate }}\n            </label>\n            <c8y-select-legacy\n              [id]=\"'apps' + accessMappingIndex\"\n              [items]=\"apps\"\n              [selected]=\"selectedApps\"\n              [disableApplyOnNoSelection]=\"true\"\n              (onChange)=\"controlContainer.control.markAsDirty(); selectedApps = $event; accessMapping.thenApplications = getIds($event)\"\n            ></c8y-select-legacy>\n          </div>\n        </div>\n      </div>\n    </fieldset>\n  </div>\n</fieldset>\n", dependencies: [{ kind: "directive", type: i2.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: i3.SelectLegacyComponent, selector: "c8y-select-legacy", inputs: ["placeholder", "selectedLabel", "applyLabel", "items", "selected", "updateItems", "disableApplyOnNoSelection", "addDropdownContainerToBody"], outputs: ["onChange"] }, { kind: "component", type: i4.ChildPredicatesComponent, selector: "c8y-sso-child-predicates", inputs: ["childPredicates", "accessMappingIndex"], outputs: ["onRemoveAllChildPredicates"] }, { kind: "pipe", type: i3.C8yTranslatePipe, name: "translate" }], viewProviders: [{ provide: ControlContainer, useExisting: NgForm }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.9", ngImport: i0, type: DynamicAccessMappingComponent, decorators: [{
            type: Component,
            args: [{ selector: 'c8y-sso-dynamic-access-mapping', viewProviders: [{ provide: ControlContainer, useExisting: NgForm }], template: "<fieldset class=\"c8y-fieldset p-8\">\n  <div *ngIf=\"accessMapping.when.childPredicates.length != 0\">\n    <c8y-sso-child-predicates\n      [childPredicates]=\"accessMapping.when.childPredicates\"\n      [accessMappingIndex]=\"'am' + accessMappingIndex\"\n      (onRemoveAllChildPredicates)=\"onRemoveAllChildPredicates()\"\n    ></c8y-sso-child-predicates>\n\n    <fieldset class=\"c8y-fieldset p-16\">\n      <legend>\n        {{ 'Provide access to' | translate }}\n      </legend>\n      <div class=\"row\">\n        <div class=\"col-sm-6\">\n          <div\n            title=\"{{ 'Default global roles' | translate }}\"\n            class=\"form-group\"\n          >\n            <label\n              [for]=\"'groups' + accessMappingIndex\"\n              class=\"control-label\"\n            >\n              {{ 'Default global roles' | translate }}\n            </label>\n            <c8y-select-legacy\n              [id]=\"'groups' + accessMappingIndex\"\n              [items]=\"groups\"\n              [selected]=\"selectedGroups\"\n              [disableApplyOnNoSelection]=\"true\"\n              (onChange)=\"controlContainer.control.markAsDirty(); selectedGroups = $event; accessMapping.thenGroups = getIds($event)\"\n            ></c8y-select-legacy>\n          </div>\n        </div>\n        <div class=\"col-sm-6\">\n          <div\n            title=\"{{ 'Default applications' | translate }}\"\n            class=\"form-group\"\n          >\n            <label\n              [for]=\"'apps' + accessMappingIndex\"\n              class=\"control-label\"\n            >\n              {{ 'Default applications' | translate }}\n            </label>\n            <c8y-select-legacy\n              [id]=\"'apps' + accessMappingIndex\"\n              [items]=\"apps\"\n              [selected]=\"selectedApps\"\n              [disableApplyOnNoSelection]=\"true\"\n              (onChange)=\"controlContainer.control.markAsDirty(); selectedApps = $event; accessMapping.thenApplications = getIds($event)\"\n            ></c8y-select-legacy>\n          </div>\n        </div>\n      </div>\n    </fieldset>\n  </div>\n</fieldset>\n" }]
        }], ctorParameters: () => [{ type: i1.ControlContainer }], propDecorators: { groups: [{
                type: Input
            }], apps: [{
                type: Input
            }], accessMapping: [{
                type: Input
            }], onRemoveAccessMapping: [{
                type: Output
            }], accessMappingIndex: [{
                type: Input
            }] } });
//# sourceMappingURL=data:application/json;base64, 