import { Component } from '@angular/core';
import { C8yJSONSchema, gettext } from '@c8y/ngx-components';
import { ExtensibleDeviceRegistrationService } from './extensible-device-registration.service';
import { BsModalRef } from 'ngx-bootstrap/modal';
import * as i0 from "@angular/core";
import * as i1 from "ngx-bootstrap/modal";
import * as i2 from "@c8y/ngx-components";
import * as i3 from "./extensible-device-registration.service";
import * as i4 from "@angular/common";
import * as i5 from "./extensible-device-registration-stepper.component";
export class ExtensibleDeviceRegistrationModalComponent {
    constructor(bsModalRef, jsonschema, registrationService) {
        this.bsModalRef = bsModalRef;
        this.jsonschema = jsonschema;
        this.registrationService = registrationService;
        this.labels = [];
    }
    async ngOnInit() {
        const { title, pages } = await this.registrationService
            .getSchema(this.contextPath)
            .catch(error => {
            this.loadingErrorMessage =
                error?.message || gettext('Cannot fetch a form definition from the microservice.');
            return {
                title: gettext('Error')
            };
        });
        this.title = title;
        this.pages = pages?.map((step) => {
            this.labels.push(step.title);
            return [this.jsonschema.toFieldConfig(step)];
        });
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: ExtensibleDeviceRegistrationModalComponent, deps: [{ token: i1.BsModalRef }, { token: i2.C8yJSONSchema }, { token: i3.ExtensibleDeviceRegistrationService }], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.2.13", type: ExtensibleDeviceRegistrationModalComponent, selector: "extensible-device-registration-modal", ngImport: i0, template: "<c8y-modal\n  [title]=\"title | translate\"\n  [headerClasses]=\"'dialog-header'\"\n  [customFooter]=\"true\"\n>\n  <ng-container c8y-modal-title>\n    <span class=\"c8y-icon c8y-icon-device-connect\"></span>\n  </ng-container>\n  <ng-container *ngIf=\"pages as steps; else loadingOrError\">\n    <c8y-extensible-device-registration-stepper\n      c8y-modal-body\n      [steps]=\"steps\"\n      [labels]=\"labels\"\n      [contextPath]=\"contextPath\"\n    ></c8y-extensible-device-registration-stepper>\n  </ng-container>\n  <ng-template #loadingOrError>\n    <ng-container *ngIf=\"loadingErrorMessage; else loading\">\n      <c8y-operation-result\n        class=\"lead text-regular\"\n        type=\"error\"\n        text=\"{{ loadingErrorMessage | translate }}\"\n        [size]=\"84\"\n        [vertical]=\"true\"\n        data-cy=\"error\"\n      ></c8y-operation-result>\n      <div class=\"modal-footer\">\n        <button\n          class=\"btn btn-default\"\n          title=\"{{ 'Close' | translate }}\"\n          type=\"button\"\n          (click)=\"bsModalRef.hide()\"\n        >\n          {{ 'Close' | translate }}\n        </button>\n      </div>\n    </ng-container>\n    <ng-template #loading>\n      <div class=\"modal-header modal-header-info text-center\">\n        <c8y-loading\n          class=\"text-center\"\n          layout=\"application\"\n          [message]=\"'Loading the registration form definition\u2026' | translate\"\n        ></c8y-loading>\n      </div>\n    </ng-template>\n  </ng-template>\n</c8y-modal>\n", dependencies: [{ kind: "directive", type: i4.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: i2.LoadingComponent, selector: "c8y-loading", inputs: ["layout", "progress", "message"] }, { kind: "component", type: i2.OperationResultComponent, selector: "c8y-operation-result", inputs: ["text", "vertical", "size", "type"] }, { kind: "component", type: i2.ModalComponent, selector: "c8y-modal", inputs: ["disabled", "close", "dismiss", "title", "body", "customFooter", "headerClasses", "labels"], outputs: ["onDismiss", "onClose"] }, { kind: "component", type: i5.ExtensibleDeviceRegistrationStepperComponent, selector: "c8y-extensible-device-registration-stepper", inputs: ["contextPath", "labels", "steps"] }, { kind: "pipe", type: i2.C8yTranslatePipe, name: "translate" }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: ExtensibleDeviceRegistrationModalComponent, decorators: [{
            type: Component,
            args: [{ selector: 'extensible-device-registration-modal', template: "<c8y-modal\n  [title]=\"title | translate\"\n  [headerClasses]=\"'dialog-header'\"\n  [customFooter]=\"true\"\n>\n  <ng-container c8y-modal-title>\n    <span class=\"c8y-icon c8y-icon-device-connect\"></span>\n  </ng-container>\n  <ng-container *ngIf=\"pages as steps; else loadingOrError\">\n    <c8y-extensible-device-registration-stepper\n      c8y-modal-body\n      [steps]=\"steps\"\n      [labels]=\"labels\"\n      [contextPath]=\"contextPath\"\n    ></c8y-extensible-device-registration-stepper>\n  </ng-container>\n  <ng-template #loadingOrError>\n    <ng-container *ngIf=\"loadingErrorMessage; else loading\">\n      <c8y-operation-result\n        class=\"lead text-regular\"\n        type=\"error\"\n        text=\"{{ loadingErrorMessage | translate }}\"\n        [size]=\"84\"\n        [vertical]=\"true\"\n        data-cy=\"error\"\n      ></c8y-operation-result>\n      <div class=\"modal-footer\">\n        <button\n          class=\"btn btn-default\"\n          title=\"{{ 'Close' | translate }}\"\n          type=\"button\"\n          (click)=\"bsModalRef.hide()\"\n        >\n          {{ 'Close' | translate }}\n        </button>\n      </div>\n    </ng-container>\n    <ng-template #loading>\n      <div class=\"modal-header modal-header-info text-center\">\n        <c8y-loading\n          class=\"text-center\"\n          layout=\"application\"\n          [message]=\"'Loading the registration form definition\u2026' | translate\"\n        ></c8y-loading>\n      </div>\n    </ng-template>\n  </ng-template>\n</c8y-modal>\n" }]
        }], ctorParameters: () => [{ type: i1.BsModalRef }, { type: i2.C8yJSONSchema }, { type: i3.ExtensibleDeviceRegistrationService }] });
//# sourceMappingURL=data:application/json;base64, 