import { Component, importProvidersFrom } from '@angular/core';
import { FieldArrayType, FormlyModule } from '@ngx-formly/core';
import * as i0 from "@angular/core";
import * as i1 from "@angular/common";
import * as i2 from "../../common/icon.directive";
import * as i3 from "../../i18n/c8y-translate.directive";
import * as i4 from "ngx-bootstrap/popover";
import * as i5 from "ngx-bootstrap/tooltip";
import * as i6 from "@ngx-formly/core";
import * as i7 from "../../i18n/c8y-translate.pipe";
import * as i8 from "../../common/humanize.pipe";
import * as i9 from "./array-type-inject-template.pipe";
export const arrayTypeConfig = () => importProvidersFrom(FormlyModule.forChild({ types: [{ name: 'array', component: ArrayTypeComponent }] }));
export class ArrayTypeComponent extends FieldArrayType {
    add() {
        this.formControl.markAsTouched();
        super.add();
    }
    remove(i) {
        this.formControl.markAsTouched();
        super.remove(i);
    }
    ngOnInit() {
        this.fieldArrayProps =
            typeof this.field?.fieldArray === 'function'
                ? this.field.fieldArray(this.field)
                    ?.props
                : this.field?.fieldArray?.props;
        if (this.props.required && !this.field.fieldGroup.length) {
            this.add();
        }
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: ArrayTypeComponent, deps: null, target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.2.13", type: ArrayTypeComponent, selector: "c8y-array-type", usesInheritance: true, ngImport: i0, template: "<div role=\"group\" [attr.aria-labelledby]=\"id + '-fieldset'\">\n  <div id=\"{{ id + '-fieldset' }}\" class=\"legend form-block\" *ngIf=\"to.label || to.description\">\n    {{ to.label | humanize }}\n    <button\n      class=\"btn-help btn-help--sm m-t-auto m-b-auto\"\n      type=\"button\"\n      [attr.aria-label]=\"'Help' | translate\"\n      [popover]=\"to.description\"\n      placement=\"right\"\n      triggers=\"focus\"\n      *ngIf=\"to.description\"\n    ></button>\n  </div>\n\n  <div\n    class=\"form-control-feedback-message has-error\"\n    role=\"alert\"\n    *ngIf=\"showError && formControl.errors\"\n  >\n    <formly-validation-message [field]=\"field\"></formly-validation-message>\n  </div>\n\n  <div *ngFor=\"let ifield of field.fieldGroup; let i = index\" class=\"input-group-array\">\n    <formly-field [field]=\"ifield | c8yArrayTypeInjectTemplate: customTemplate\"></formly-field>\n    <ng-container\n      *ngIf=\"ifield.type === 'formly-group' || ifield.type === 'array'\"\n      [ngTemplateOutlet]=\"customTemplate\"\n    ></ng-container>\n    <ng-template #customTemplate>\n      <div class=\"input-group-btn delete-row\">\n        <button\n          class=\"btn btn-dot btn-dot--danger flex-item-right\"\n          type=\"button\"\n          [attr.aria-label]=\"'Delete' | translate\"\n          tooltip=\"{{ 'Delete' | translate }}\"\n          [delay]=\"500\"\n          placement=\"right\"\n          [disabled]=\"to.disabled || (field.fieldGroup.length === 1 && to.required)\"\n          (click)=\"remove(i)\"\n        >\n          <i c8yIcon=\"minus-circle\"></i>\n        </button>\n      </div>\n    </ng-template>\n  </div>\n\n  <div class=\"p-t-8\">\n    <button\n      class=\"btn btn-sm btn-default\"\n      type=\"button\"\n      title=\"{{\n        (field.templateOptions?.addText | translate) || 'Add \\{\\{ label \\}\\}'\n          | translate: fieldArrayProps\n      }}\"\n      [disabled]=\"to.disabled\"\n      (click)=\"add()\"\n      [attr.data-cy]=\"field.templateOptions?.addTextDataCy || 'add-array-item'\"\n    >\n      <i c8yIcon=\"plus-circle\" class=\"m-r-4\"></i>\n      <span\n        *ngIf=\"!field.templateOptions?.addText\"\n        ngNonBindable\n        translate\n        [translateParams]=\"fieldArrayProps\"\n      >\n        Add {{ label }}\n      </span>\n      <span *ngIf=\"field.templateOptions?.addText\">\n        {{ field.templateOptions?.addText | translate }}\n      </span>\n    </button>\n  </div>\n</div>\n", dependencies: [{ kind: "directive", type: i1.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { 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.IconDirective, selector: "[c8yIcon]", inputs: ["c8yIcon"] }, { kind: "directive", type: i3.C8yTranslateDirective, selector: "[translate],[ngx-translate]" }, { kind: "directive", type: i4.PopoverDirective, selector: "[popover]", inputs: ["adaptivePosition", "boundariesElement", "popover", "popoverContext", "popoverTitle", "placement", "outsideClick", "triggers", "container", "containerClass", "isOpen", "delay"], outputs: ["onShown", "onHidden"], exportAs: ["bs-popover"] }, { kind: "directive", type: i5.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: "component", type: i6.FormlyField, selector: "formly-field", inputs: ["field"] }, { kind: "component", type: i6.ɵFormlyValidationMessage, selector: "formly-validation-message", inputs: ["field"] }, { kind: "pipe", type: i7.C8yTranslatePipe, name: "translate" }, { kind: "pipe", type: i8.HumanizePipe, name: "humanize" }, { kind: "pipe", type: i9.C8yArrayTypeInjectTemplatePipe, name: "c8yArrayTypeInjectTemplate" }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: ArrayTypeComponent, decorators: [{
            type: Component,
            args: [{ selector: 'c8y-array-type', template: "<div role=\"group\" [attr.aria-labelledby]=\"id + '-fieldset'\">\n  <div id=\"{{ id + '-fieldset' }}\" class=\"legend form-block\" *ngIf=\"to.label || to.description\">\n    {{ to.label | humanize }}\n    <button\n      class=\"btn-help btn-help--sm m-t-auto m-b-auto\"\n      type=\"button\"\n      [attr.aria-label]=\"'Help' | translate\"\n      [popover]=\"to.description\"\n      placement=\"right\"\n      triggers=\"focus\"\n      *ngIf=\"to.description\"\n    ></button>\n  </div>\n\n  <div\n    class=\"form-control-feedback-message has-error\"\n    role=\"alert\"\n    *ngIf=\"showError && formControl.errors\"\n  >\n    <formly-validation-message [field]=\"field\"></formly-validation-message>\n  </div>\n\n  <div *ngFor=\"let ifield of field.fieldGroup; let i = index\" class=\"input-group-array\">\n    <formly-field [field]=\"ifield | c8yArrayTypeInjectTemplate: customTemplate\"></formly-field>\n    <ng-container\n      *ngIf=\"ifield.type === 'formly-group' || ifield.type === 'array'\"\n      [ngTemplateOutlet]=\"customTemplate\"\n    ></ng-container>\n    <ng-template #customTemplate>\n      <div class=\"input-group-btn delete-row\">\n        <button\n          class=\"btn btn-dot btn-dot--danger flex-item-right\"\n          type=\"button\"\n          [attr.aria-label]=\"'Delete' | translate\"\n          tooltip=\"{{ 'Delete' | translate }}\"\n          [delay]=\"500\"\n          placement=\"right\"\n          [disabled]=\"to.disabled || (field.fieldGroup.length === 1 && to.required)\"\n          (click)=\"remove(i)\"\n        >\n          <i c8yIcon=\"minus-circle\"></i>\n        </button>\n      </div>\n    </ng-template>\n  </div>\n\n  <div class=\"p-t-8\">\n    <button\n      class=\"btn btn-sm btn-default\"\n      type=\"button\"\n      title=\"{{\n        (field.templateOptions?.addText | translate) || 'Add \\{\\{ label \\}\\}'\n          | translate: fieldArrayProps\n      }}\"\n      [disabled]=\"to.disabled\"\n      (click)=\"add()\"\n      [attr.data-cy]=\"field.templateOptions?.addTextDataCy || 'add-array-item'\"\n    >\n      <i c8yIcon=\"plus-circle\" class=\"m-r-4\"></i>\n      <span\n        *ngIf=\"!field.templateOptions?.addText\"\n        ngNonBindable\n        translate\n        [translateParams]=\"fieldArrayProps\"\n      >\n        Add {{ label }}\n      </span>\n      <span *ngIf=\"field.templateOptions?.addText\">\n        {{ field.templateOptions?.addText | translate }}\n      </span>\n    </button>\n  </div>\n</div>\n" }]
        }] });
//# sourceMappingURL=data:application/json;base64, 