import * as i0 from '@angular/core';
import { Injectable, Component, NgModule } from '@angular/core';
import * as i1$1 from 'ngx-bootstrap/modal';
import { CdkStep } from '@angular/cdk/stepper';
import { FormGroup } from '@angular/forms';
import { gettext } from '@c8y/ngx-components/gettext';
import * as i3 from '@c8y/ngx-components';
import { ModalComponent, IconDirective, LoadingComponent, C8yStepper, C8yStepperButtons, OperationResultComponent, C8yTranslatePipe, CoreModule, CommonModule } from '@c8y/ngx-components';
import * as i4 from '@ngx-formly/core';
import { FormlyModule } from '@ngx-formly/core';
import { uniq, cloneDeep } from 'lodash-es';
import { Subject, of, forkJoin, throwError, BehaviorSubject, defer, from } from 'rxjs';
import { catchError, switchMap, map, takeUntil, mergeMap, shareReplay } from 'rxjs/operators';
import * as i1 from '@c8y/client';
import * as i2 from '@ngx-translate/core';
import { NgIf, NgFor, NgClass, AsyncPipe } from '@angular/common';
import { hookDeviceRegistration } from '@c8y/ngx-components/register-device';

const PRODUCT_EXPERIENCE_LORIOT_REGISTRATION = {
    EVENT: 'deviceRegistration',
    COMPONENT: 'loriot-registration',
    RESULT: { SUCCESS: 'registrationSuccess', FAILURE: 'registrationFailure' }
};

var LoriotErrorName;
(function (LoriotErrorName) {
    LoriotErrorName["NoDeviceProtocolsError"] = "NoDeviceProtocolsError";
    LoriotErrorName["NoConnectivitySettingsError"] = "NoConnectivitySettingsError";
    LoriotErrorName["ConnectivitySettingsError"] = "ConnectivitySettingsError";
    LoriotErrorName["RegistrationError"] = "RegistrationError";
    LoriotErrorName["DeviceProtocolsFetchError"] = "DeviceProtocolsFetchError";
    LoriotErrorName["ApplicationError"] = "ApplicationError";
})(LoriotErrorName || (LoriotErrorName = {}));
class LoriotProviderService {
    constructor(client, inventoryService, translateService, appState) {
        this.client = client;
        this.inventoryService = inventoryService;
        this.translateService = translateService;
        this.appState = appState;
        this.baseUrl = '/service/loriot/';
        this.registrationUrl = `${this.baseUrl}newDeviceRequest`;
        this.header = { 'Content-Type': 'application/json' };
        this.applicationsUrl = `${this.baseUrl}applications`;
    }
    async getConnections() {
        const options = {
            method: 'GET',
            headers: this.header
        };
        const res = await this.client.fetch(`${this.baseUrl}lns-connection`, options);
        const data = await res.json();
        if (res.status === 200) {
            if (data.length === 0) {
                await this.throwNoConnectivitySettingsError();
            }
        }
        else {
            await this.throwConnectivitySettingsError(data);
        }
        return { res, data };
    }
    async createDevice(device) {
        const options = {
            method: 'POST',
            headers: this.header,
            body: JSON.stringify(device)
        };
        const res = await this.client.fetch(this.registrationUrl, options);
        const data = await res.json();
        if (res.status !== 201) {
            this.throwRegistrationError(data);
        }
        return { res, data };
    }
    async getAvailableProtocols(filter = { withTotalPages: true }) {
        const query = {
            __filter: {
                __and: [
                    { __has: 'c8y_IsDeviceType' },
                    {
                        type: { __in: ['c8y_LoraDeviceType', 'c8y_LpwanDeviceType'] }
                    }
                ]
            },
            __orderby: [{ name: 1 }]
        };
        const deviceProtocolsList = await this.inventoryService.listQuery(query, filter);
        const { res, data } = deviceProtocolsList;
        if (res.status === 200) {
            if (data.length === 0) {
                this.throwNoDeviceProtocolsError();
            }
        }
        else {
            this.throwDeviceProtocolsFetchError();
        }
        return deviceProtocolsList;
    }
    async getApplications(connectionName) {
        const options = {
            method: 'GET',
            headers: this.header,
            params: {
                loriotConnectionName: connectionName
            }
        };
        const res = await this.client.fetch(this.applicationsUrl, options);
        const data = await res.json();
        /* Every connection will have atleast 1 application,
        so having check for this enpoint returning empty result is not needed*/
        if (res.status !== 200) {
            this.throwApplicationError(data);
        }
        return { res, data };
    }
    async throwNoConnectivitySettingsError() {
        const error = new Error();
        error.name = LoriotErrorName.NoConnectivitySettingsError;
        const hasAdminRight = await this.appState.isApplicationAvailable('administration');
        if (hasAdminRight) {
            error.message = this.translateService.instant(gettext(`Connectivity settings are not configured. Configure them in the Administration application under <a href="{{ link }}">Settings</a>.`), {
                link: '/apps/administration/index.html#/connectivitySettings/multiple_lns_connectors_loriot'
            });
        }
        else {
            error.message = gettext('Connectivity settings are not configured. Contact the administrator.');
        }
        throw error;
    }
    throwConnectivitySettingsError(data) {
        const error = new Error();
        error.name = LoriotErrorName.ConnectivitySettingsError;
        error.message = data.message;
        throw error;
    }
    throwRegistrationError(data) {
        const error = new Error();
        error.name = LoriotErrorName.RegistrationError;
        error.message = data.message;
        throw error;
    }
    throwDeviceProtocolsFetchError() {
        const error = new Error();
        error.name = LoriotErrorName.DeviceProtocolsFetchError;
        error.message = gettext('Could not load device protocols.');
        throw error;
    }
    throwNoDeviceProtocolsError() {
        const error = new Error();
        error.name = LoriotErrorName.NoDeviceProtocolsError;
        error.message = this.translateService.instant(gettext(`No device protocols configured. Create a LoRa device protocol in <a href="{{ link }}">Device protocols</a>.`), {
            link: '/apps/devicemanagement/#/deviceprotocols'
        });
        throw error;
    }
    throwApplicationError(data) {
        const error = new Error();
        error.name = LoriotErrorName.ApplicationError;
        error.message = data.message;
        throw error;
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: LoriotProviderService, deps: [{ token: i1.FetchClient }, { token: i1.InventoryService }, { token: i2.TranslateService }, { token: i3.AppStateService }], target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: LoriotProviderService, providedIn: 'root' }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: LoriotProviderService, decorators: [{
            type: Injectable,
            args: [{
                    providedIn: 'root'
                }]
        }], ctorParameters: () => [{ type: i1.FetchClient }, { type: i1.InventoryService }, { type: i2.TranslateService }, { type: i3.AppStateService }] });

class LoriotDeviceRegistrationComponent {
    constructor(bsModalRef, loriotService, gainsightService) {
        this.bsModalRef = bsModalRef;
        this.loriotService = loriotService;
        this.gainsightService = gainsightService;
        this.PAGING = {
            withTotalPages: true,
            pageSize: 10
        };
        this.form = new FormGroup({});
        this.model = {};
        this.protocols$ = this.getProtocols$();
        this.connections$ = this.getConnections$();
        this.unsubscribe$ = new Subject();
        this.load$ = this.connections$.pipe(catchError((error) => of(error)), switchMap(connections => {
            if (connections instanceof Error &&
                connections.name === LoriotErrorName.NoConnectivitySettingsError) {
                return of([connections]);
            }
            return forkJoin([
                of(connections),
                this.protocols$.pipe(catchError((error) => of(error)))
            ]);
        }), map(results => {
            return results.filter(result => {
                return result instanceof Error;
            });
        }), switchMap(errors => {
            return errors.length === 0 ? of([]) : throwError(errors);
        }));
        this.fields = [
            {
                key: 'title',
                type: 'string',
                templateOptions: {
                    placeholder: gettext('LORIOT LoRa'),
                    label: gettext('Title'),
                    required: true
                }
            },
            {
                key: 'deveui',
                type: 'string',
                templateOptions: {
                    placeholder: 'FEDCBA9876543210',
                    label: gettext('Device EUI'),
                    required: true,
                    pattern: '^([A-F0-9]{16})$'
                },
                validation: {
                    messages: {
                        pattern: gettext('Must be a valid 16 digit uppercase hexadecimal number.')
                    }
                }
            },
            {
                key: 'appeui',
                type: 'string',
                templateOptions: {
                    placeholder: 'FEDCBA9876543210',
                    label: gettext('Application EUI'),
                    required: true,
                    pattern: '^([a-fA-F0-9]{16})$'
                },
                validation: {
                    messages: {
                        pattern: gettext('Must be a valid 16 digit hexadecimal number.')
                    }
                }
            },
            {
                key: 'appkey',
                type: 'string',
                templateOptions: {
                    placeholder: 'FEDCBA9876543210FEDCBA9876543210',
                    label: gettext('Application key'),
                    required: true,
                    pattern: '^([a-fA-F0-9]{32})$'
                },
                validation: {
                    messages: {
                        pattern: gettext('Must be a valid 32 digit hexadecimal number.')
                    }
                }
            },
            {
                key: 'connection',
                type: 'typeahead',
                templateOptions: {
                    label: gettext('Connection'),
                    required: true,
                    c8yForOptions: this.connections$,
                    displayProperty: 'name',
                    valueProperties: ['name']
                }
            },
            {
                key: 'application',
                type: 'typeahead',
                templateOptions: {
                    label: gettext('Application name'),
                    required: true,
                    placeholder: gettext('LORIOT application'),
                    displayProperty: 'name',
                    valueProperties: ['hexId']
                },
                hooks: {
                    onInit: field => {
                        const connectionControl = field.form.get('connection');
                        connectionControl.valueChanges
                            .pipe(takeUntil(this.unsubscribe$), mergeMap(({ name }) => this.getApplications$(name)))
                            .subscribe(apps => {
                            field.templateOptions.c8yForOptions = of(apps);
                            field.formControl.setValue(null);
                        }, error => {
                            field.form.get('application').setErrors({ application: true });
                            field.validators.application.message = error.message;
                        });
                    }
                },
                validators: {
                    application: {
                        expression: (control) => {
                            return control.status === 'VALID';
                        },
                        message: () => ''
                    }
                }
            },
            {
                key: 'deviceType',
                type: 'typeahead',
                templateOptions: {
                    label: gettext('Device protocol'),
                    required: true,
                    c8yForOptions: this.protocols$,
                    displayProperty: 'name',
                    valueProperties: ['id', 'name']
                }
            }
        ];
        this.registrationStepLabels = {
            next: gettext('Register')
        };
        this.finalStepLabels = {
            back: gettext('Close')
        };
        this.state = 'loadPending';
        this.errors$ = new BehaviorSubject([]);
        this.errorMessages$ = this.errors$.pipe(map(errors => errors.map(error => error.message)), map(messages => uniq(messages)));
        this.load$.subscribe(() => {
            this.state = 'loadSuccess';
        }, errors => {
            this.state = 'loadError';
            this.errors$.next(errors);
        });
    }
    async create(event) {
        this.state = 'registrationPending';
        const loriotDevice = this.getLoriotDeviceToSend();
        try {
            await this.loriotService.createDevice(loriotDevice);
            this.state = 'registrationSuccess';
            this.gainsightService.triggerEvent(PRODUCT_EXPERIENCE_LORIOT_REGISTRATION.EVENT, {
                result: PRODUCT_EXPERIENCE_LORIOT_REGISTRATION.RESULT.SUCCESS,
                component: PRODUCT_EXPERIENCE_LORIOT_REGISTRATION.COMPONENT
            });
        }
        catch (error) {
            this.state = 'registrationError';
            this.gainsightService.triggerEvent(PRODUCT_EXPERIENCE_LORIOT_REGISTRATION.EVENT, {
                result: PRODUCT_EXPERIENCE_LORIOT_REGISTRATION.RESULT.FAILURE,
                component: PRODUCT_EXPERIENCE_LORIOT_REGISTRATION.COMPONENT
            });
            this.errors$.next([error]);
        }
        event.stepper.next();
    }
    getLoriotDeviceToSend() {
        const loriotDevice = cloneDeep(this.model);
        loriotDevice.lnsConnectionName = this.model.connection.name;
        delete loriotDevice.connection;
        loriotDevice.appid = this.model.application.hexId;
        delete loriotDevice.application;
        return loriotDevice;
    }
    getProtocols$() {
        return defer(() => from(this.loriotService.getAvailableProtocols())).pipe(shareReplay(1));
    }
    getConnections$() {
        return defer(() => from(this.loriotService.getConnections())).pipe(shareReplay(1));
    }
    getApplications$(name) {
        return defer(() => from(this.loriotService.getApplications(name))).pipe(shareReplay(1));
    }
    ngOnDestroy() {
        this.unsubscribe$.next();
        this.unsubscribe$.complete();
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: LoriotDeviceRegistrationComponent, deps: [{ token: i1$1.BsModalRef }, { token: LoriotProviderService }, { token: i3.GainsightService }], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "20.3.19", type: LoriotDeviceRegistrationComponent, isStandalone: true, selector: "c8y-loriot-registration", ngImport: i0, template: "<c8y-modal\n  [title]=\"'LORIOT registration' | translate\"\n  [headerClasses]=\"'dialog-header'\"\n  [customFooter]=\"true\"\n>\n  <ng-container c8y-modal-title>\n    <span [c8yIcon]=\"'c8y-device-connect'\"></span>\n  </ng-container>\n  <ng-container *ngIf=\"state === 'loadPending'; else registrationForm\">\n    <div class=\"p-16 text-center\">\n      <c8y-loading></c8y-loading>\n    </div>\n  </ng-container>\n\n  <ng-template #registrationForm>\n    <c8y-stepper\n      [hideStepProgress]=\"true\"\n      linear\n      c8y-modal-body\n      *ngIf=\"(errorMessages$ | async).length === 0; else errorMessagesPresent\"\n    >\n      <cdk-step [stepControl]=\"form\">\n        <div class=\"p-b-16\">\n          <p class=\"modal-subtitle sticky-top\">\n            {{ 'Register a single LORIOT device' | translate }}\n          </p>\n          <formly-form\n            class=\"d-block p-l-24 p-r-24 p-t-16\"\n            [form]=\"form\"\n            [fields]=\"fields\"\n            [model]=\"model\"\n          ></formly-form>\n        </div>\n        <c8y-stepper-buttons\n          class=\"modal-footer d-block sticky-bottom separator-top bg-component\"\n          [labels]=\"registrationStepLabels\"\n          (onNext)=\"create($event)\"\n          (onCancel)=\"bsModalRef.hide()\"\n          [showButtons]=\"{ cancel: true, next: true }\"\n          [pending]=\"state === 'registrationPending'\"\n          [disabled]=\"!form.valid\"\n        ></c8y-stepper-buttons>\n      </cdk-step>\n      <cdk-step state=\"final\">\n        <div\n          class=\"p-16 text-center\"\n          *ngIf=\"state === 'registrationPending'\"\n        >\n          <c8y-loading></c8y-loading>\n        </div>\n        <div class=\"m-24\">\n          <c8y-operation-result\n            class=\"lead m-b-0\"\n            type=\"success\"\n            *ngIf=\"state === 'registrationSuccess'\"\n            text=\"{{ 'Device registered' | translate }}\"\n            [size]=\"84\"\n            [vertical]=\"true\"\n          ></c8y-operation-result>\n        </div>\n\n        <c8y-stepper-buttons\n          class=\"sticky-bottom d-block p-t-16 p-b-16 separator-top bg-component\"\n          (onCustom)=\"bsModalRef.hide()\"\n          [showButtons]=\"{ custom: true }\"\n          [labels]=\"finalStepLabels\"\n        ></c8y-stepper-buttons>\n      </cdk-step>\n    </c8y-stepper>\n  </ng-template>\n\n  <ng-template #errorMessagesPresent>\n    <div class=\"m-24\">\n      <c8y-operation-result\n        class=\"lead\"\n        type=\"error\"\n        *ngIf=\"state === 'registrationError'\"\n        text=\"{{ 'Failed to register' | translate }}\"\n        [size]=\"84\"\n        [vertical]=\"true\"\n      ></c8y-operation-result>\n      <div\n        class=\"m-b-8\"\n        *ngFor=\"let msg of errorMessages$ | async\"\n        data-cy=\"loriot-device-registration.component--registration-error\"\n        [ngClass]=\"{\n          'text-center': state === 'registrationError',\n          'alert alert-danger': state === 'loadError'\n        }\"\n      >\n        <span [innerHTML]=\"msg | translate\"></span>\n      </div>\n    </div>\n\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-template>\n</c8y-modal>\n", dependencies: [{ kind: "component", type: ModalComponent, selector: "c8y-modal", inputs: ["disabled", "close", "dismiss", "title", "body", "customFooter", "headerClasses", "labels"], outputs: ["onDismiss", "onClose"] }, { kind: "directive", type: IconDirective, selector: "[c8yIcon]", inputs: ["c8yIcon"] }, { kind: "directive", type: NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: LoadingComponent, selector: "c8y-loading", inputs: ["layout", "progress", "message"] }, { kind: "component", type: C8yStepper, selector: "c8y-stepper", inputs: ["disableDefaultIcons", "disableProgressButtons", "customClasses", "hideStepProgress", "useStepLabelsAsTitlesOnly"], outputs: ["onStepChange"] }, { kind: "component", type: CdkStep, selector: "cdk-step", inputs: ["stepControl", "label", "errorMessage", "aria-label", "aria-labelledby", "state", "editable", "optional", "completed", "hasError"], outputs: ["interacted"], exportAs: ["cdkStep"] }, { kind: "ngmodule", type: FormlyModule }, { kind: "component", type: i4.FormlyForm, selector: "formly-form", inputs: ["form", "model", "fields", "options"], outputs: ["modelChange"] }, { kind: "component", type: C8yStepperButtons, selector: "c8y-stepper-buttons", inputs: ["labels", "pending", "disabled", "showButtons"], outputs: ["onCancel", "onNext", "onBack", "onCustom"] }, { kind: "component", type: OperationResultComponent, selector: "c8y-operation-result", inputs: ["text", "vertical", "size", "type"] }, { kind: "directive", type: NgFor, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "pipe", type: C8yTranslatePipe, name: "translate" }, { kind: "pipe", type: AsyncPipe, name: "async" }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: LoriotDeviceRegistrationComponent, decorators: [{
            type: Component,
            args: [{ selector: 'c8y-loriot-registration', imports: [
                        ModalComponent,
                        IconDirective,
                        NgIf,
                        LoadingComponent,
                        C8yStepper,
                        CdkStep,
                        FormlyModule,
                        C8yStepperButtons,
                        OperationResultComponent,
                        NgFor,
                        NgClass,
                        C8yTranslatePipe,
                        AsyncPipe
                    ], template: "<c8y-modal\n  [title]=\"'LORIOT registration' | translate\"\n  [headerClasses]=\"'dialog-header'\"\n  [customFooter]=\"true\"\n>\n  <ng-container c8y-modal-title>\n    <span [c8yIcon]=\"'c8y-device-connect'\"></span>\n  </ng-container>\n  <ng-container *ngIf=\"state === 'loadPending'; else registrationForm\">\n    <div class=\"p-16 text-center\">\n      <c8y-loading></c8y-loading>\n    </div>\n  </ng-container>\n\n  <ng-template #registrationForm>\n    <c8y-stepper\n      [hideStepProgress]=\"true\"\n      linear\n      c8y-modal-body\n      *ngIf=\"(errorMessages$ | async).length === 0; else errorMessagesPresent\"\n    >\n      <cdk-step [stepControl]=\"form\">\n        <div class=\"p-b-16\">\n          <p class=\"modal-subtitle sticky-top\">\n            {{ 'Register a single LORIOT device' | translate }}\n          </p>\n          <formly-form\n            class=\"d-block p-l-24 p-r-24 p-t-16\"\n            [form]=\"form\"\n            [fields]=\"fields\"\n            [model]=\"model\"\n          ></formly-form>\n        </div>\n        <c8y-stepper-buttons\n          class=\"modal-footer d-block sticky-bottom separator-top bg-component\"\n          [labels]=\"registrationStepLabels\"\n          (onNext)=\"create($event)\"\n          (onCancel)=\"bsModalRef.hide()\"\n          [showButtons]=\"{ cancel: true, next: true }\"\n          [pending]=\"state === 'registrationPending'\"\n          [disabled]=\"!form.valid\"\n        ></c8y-stepper-buttons>\n      </cdk-step>\n      <cdk-step state=\"final\">\n        <div\n          class=\"p-16 text-center\"\n          *ngIf=\"state === 'registrationPending'\"\n        >\n          <c8y-loading></c8y-loading>\n        </div>\n        <div class=\"m-24\">\n          <c8y-operation-result\n            class=\"lead m-b-0\"\n            type=\"success\"\n            *ngIf=\"state === 'registrationSuccess'\"\n            text=\"{{ 'Device registered' | translate }}\"\n            [size]=\"84\"\n            [vertical]=\"true\"\n          ></c8y-operation-result>\n        </div>\n\n        <c8y-stepper-buttons\n          class=\"sticky-bottom d-block p-t-16 p-b-16 separator-top bg-component\"\n          (onCustom)=\"bsModalRef.hide()\"\n          [showButtons]=\"{ custom: true }\"\n          [labels]=\"finalStepLabels\"\n        ></c8y-stepper-buttons>\n      </cdk-step>\n    </c8y-stepper>\n  </ng-template>\n\n  <ng-template #errorMessagesPresent>\n    <div class=\"m-24\">\n      <c8y-operation-result\n        class=\"lead\"\n        type=\"error\"\n        *ngIf=\"state === 'registrationError'\"\n        text=\"{{ 'Failed to register' | translate }}\"\n        [size]=\"84\"\n        [vertical]=\"true\"\n      ></c8y-operation-result>\n      <div\n        class=\"m-b-8\"\n        *ngFor=\"let msg of errorMessages$ | async\"\n        data-cy=\"loriot-device-registration.component--registration-error\"\n        [ngClass]=\"{\n          'text-center': state === 'registrationError',\n          'alert alert-danger': state === 'loadError'\n        }\"\n      >\n        <span [innerHTML]=\"msg | translate\"></span>\n      </div>\n    </div>\n\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-template>\n</c8y-modal>\n" }]
        }], ctorParameters: () => [{ type: i1$1.BsModalRef }, { type: LoriotProviderService }, { type: i3.GainsightService }] });

class LoriotDeviceRegistrationButtonComponent {
    constructor(modalService) {
        this.modalService = modalService;
    }
    open() {
        this.modalService.show(LoriotDeviceRegistrationComponent, {
            class: 'modal-sm',
            ariaDescribedby: 'modal-body',
            ariaLabelledBy: 'modal-title',
            ignoreBackdropClick: true
        });
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: LoriotDeviceRegistrationButtonComponent, deps: [{ token: i1$1.BsModalService }], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "20.3.19", type: LoriotDeviceRegistrationButtonComponent, isStandalone: true, selector: "c8y-loriot-registration", ngImport: i0, template: "<button (click)=\"open()\"><i c8yIcon=\"c8y-device-connect\"></i> {{ 'LORIOT LoRa' | translate }} </button>", dependencies: [{ kind: "directive", type: IconDirective, selector: "[c8yIcon]", inputs: ["c8yIcon"] }, { kind: "pipe", type: C8yTranslatePipe, name: "translate" }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: LoriotDeviceRegistrationButtonComponent, decorators: [{
            type: Component,
            args: [{ selector: 'c8y-loriot-registration', imports: [IconDirective, C8yTranslatePipe], template: "<button (click)=\"open()\"><i c8yIcon=\"c8y-device-connect\"></i> {{ 'LORIOT LoRa' | translate }} </button>" }]
        }], ctorParameters: () => [{ type: i1$1.BsModalService }] });

class LoriotDeviceRegistrationFactory {
    constructor(tenantService) {
        this.tenantService = tenantService;
    }
    get() {
        const items = [];
        if (this.tenantService.isMicroserviceSubscribedInCurrentTenant('loriot')) {
            items.push({
                template: LoriotDeviceRegistrationButtonComponent,
                priority: 97,
                category: 'single'
            });
        }
        return items;
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: LoriotDeviceRegistrationFactory, deps: [{ token: i3.TenantUiService }], target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: LoriotDeviceRegistrationFactory, providedIn: 'root' }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: LoriotDeviceRegistrationFactory, decorators: [{
            type: Injectable,
            args: [{
                    providedIn: 'root'
                }]
        }], ctorParameters: () => [{ type: i3.TenantUiService }] });

class LoriotDeviceRegistrationModule {
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: LoriotDeviceRegistrationModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
    static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.3.19", ngImport: i0, type: LoriotDeviceRegistrationModule, imports: [CoreModule,
            CommonModule,
            LoriotDeviceRegistrationButtonComponent,
            LoriotDeviceRegistrationComponent] }); }
    static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: LoriotDeviceRegistrationModule, providers: [hookDeviceRegistration(LoriotDeviceRegistrationFactory), LoriotProviderService], imports: [CoreModule,
            CommonModule,
            LoriotDeviceRegistrationComponent] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: LoriotDeviceRegistrationModule, decorators: [{
            type: NgModule,
            args: [{
                    imports: [
                        CoreModule,
                        CommonModule,
                        LoriotDeviceRegistrationButtonComponent,
                        LoriotDeviceRegistrationComponent
                    ],
                    providers: [hookDeviceRegistration(LoriotDeviceRegistrationFactory), LoriotProviderService]
                }]
        }] });

/**
 * Generated bundle index. Do not edit.
 */

export { LoriotDeviceRegistrationButtonComponent, LoriotDeviceRegistrationComponent, LoriotDeviceRegistrationFactory, LoriotDeviceRegistrationModule };
//# sourceMappingURL=c8y-ngx-components-loriot-device-registration.mjs.map
