import * as i0 from '@angular/core';
import { Injectable, Component, NgModule } from '@angular/core';
import * as i1$1 from 'ngx-bootstrap/modal';
import { FormGroup } from '@angular/forms';
import * as i4 from '@c8y/ngx-components';
import { gettext, CoreModule, CommonModule } from '@c8y/ngx-components';
import * as i2 from '@ngx-translate/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 i5 from '@angular/common';
import * as i6 from '@angular/cdk/stepper';
import * as i7 from '@ngx-formly/core';
import { hookDeviceRegistration } from '@c8y/ngx-components/register-device';

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

var SigfoxErrorName;
(function (SigfoxErrorName) {
    SigfoxErrorName["NoDeviceProtocolsError"] = "NoDeviceProtocolsError";
    SigfoxErrorName["NoConnectivitySettingsError"] = "NoConnectivitySettingsError";
    SigfoxErrorName["ConnectivitySettingsError"] = "ConnectivitySettingsError";
    SigfoxErrorName["ContractError"] = "ContractError";
    SigfoxErrorName["NoContractsError"] = "NoContractsError";
    SigfoxErrorName["RegistrationError"] = "RegistrationError";
    SigfoxErrorName["DeviceProtocolsFetchError"] = "DeviceProtocolsFetchError";
})(SigfoxErrorName || (SigfoxErrorName = {}));
class SigfoxProviderService {
    constructor(client, inventoryService, tenantOptions, translateService, appState) {
        this.client = client;
        this.inventoryService = inventoryService;
        this.tenantOptions = tenantOptions;
        this.translateService = translateService;
        this.appState = appState;
        this.baseUrl = '/service/sigfox-agent/';
        this.registrationUrl = `${this.baseUrl}newDeviceRequest`;
        this.contractsUrl = `${this.baseUrl}contract`;
        this.header = { 'Content-Type': 'application/json' };
    }
    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 };
    }
    /**
     * Gets contracts from Sigfox platform.
     * @param connectionName The name of connection for which contracts will be retrieved
     * @returns The result list with contract, or throws an error with exception.
     */
    async getContracts(connectionName) {
        const options = {
            method: 'GET',
            headers: this.header,
            params: {
                sigfoxConnectionName: connectionName
            }
        };
        const res = await this.client.fetch(this.contractsUrl, options);
        const data = await res.json();
        if (res.status === 200) {
            if (data.length === 0) {
                this.throwNoContractsError();
            }
        }
        else {
            this.throwContractError(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_SigfoxDeviceType', '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 hasConnectivitySettings() {
        const option = {
            category: 'sigfox-agent',
            key: 'provider.token'
        };
        try {
            await this.tenantOptions.detail(option);
            return true;
        }
        catch (e) {
            await this.throwNoConnectivitySettingsError();
        }
    }
    async throwNoConnectivitySettingsError() {
        const error = new Error();
        error.name = SigfoxErrorName.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_sigfox'
            });
        }
        else {
            error.message = gettext('Connectivity settings are not configured. Contact the administrator.');
        }
        throw error;
    }
    throwConnectivitySettingsError(data) {
        const error = new Error();
        error.name = SigfoxErrorName.ConnectivitySettingsError;
        error.message = data.message;
        throw error;
    }
    throwRegistrationError(data) {
        const error = new Error();
        error.name = SigfoxErrorName.RegistrationError;
        error.message = data.message;
        throw error;
    }
    throwDeviceProtocolsFetchError() {
        const error = new Error();
        error.name = SigfoxErrorName.DeviceProtocolsFetchError;
        error.message = gettext('Could not load device protocols.');
        throw error;
    }
    throwNoDeviceProtocolsError() {
        const error = new Error();
        error.name = SigfoxErrorName.NoDeviceProtocolsError;
        error.message = this.translateService.instant(gettext(`No device protocols configured. Create a Sigfox device protocol in <a href="{{ link }}">Device protocols</a>.`), {
            link: '/apps/devicemanagement/#/deviceprotocols'
        });
        throw error;
    }
    throwContractError(data) {
        const error = new Error();
        error.name = SigfoxErrorName.ContractError;
        error.message = data.message;
        throw error;
    }
    throwNoContractsError() {
        const error = new Error();
        error.name = SigfoxErrorName.NoContractsError;
        error.message = gettext('No contracts found. New contracts must be created via the Sigfox platform.');
        throw error;
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: SigfoxProviderService, deps: [{ token: i1.FetchClient }, { token: i1.InventoryService }, { token: i1.TenantOptionsService }, { token: i2.TranslateService }, { token: i4.AppStateService }], target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: SigfoxProviderService, providedIn: 'root' }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: SigfoxProviderService, decorators: [{
            type: Injectable,
            args: [{
                    providedIn: 'root'
                }]
        }], ctorParameters: () => [{ type: i1.FetchClient }, { type: i1.InventoryService }, { type: i1.TenantOptionsService }, { type: i2.TranslateService }, { type: i4.AppStateService }] });

class SigfoxDeviceRegistrationComponent {
    constructor(bsModalRef, sigfoxService, translateService, gainsightService) {
        this.bsModalRef = bsModalRef;
        this.sigfoxService = sigfoxService;
        this.translateService = translateService;
        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 === SigfoxErrorName.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: 'id',
                type: 'string',
                templateOptions: {
                    placeholder: 'FED987',
                    label: gettext('ID'),
                    required: true,
                    pattern: '(0x){0,1}[0-9A-F]+(h){0,1}'
                },
                validation: {
                    messages: {
                        pattern: gettext('Must be a valid hexadecimal number.')
                    }
                }
            },
            {
                key: 'pac',
                type: 'string',
                templateOptions: {
                    placeholder: 'FEDCBA9876543210',
                    label: gettext('PAC'),
                    required: true,
                    pattern: '^([a-fA-F0-9]{16})$'
                },
                validation: {
                    messages: {
                        pattern: gettext('Must be a valid 16 digit hexadecimal number.')
                    }
                }
            },
            {
                key: 'connection',
                type: 'typeahead',
                templateOptions: {
                    label: gettext('Connection'),
                    required: true,
                    c8yForOptions: this.connections$,
                    displayProperty: 'name',
                    valueProperties: ['name']
                }
            },
            {
                key: 'contract',
                type: 'typeahead',
                templateOptions: {
                    label: gettext('Contract'),
                    required: true,
                    placeholder: 'Free contract_25',
                    displayProperty: 'name',
                    valueProperties: ['id'],
                    description: gettext('Only active contracts with free slots are displayed.')
                },
                hooks: {
                    onInit: field => {
                        const connectionControl = field.form.get('connection');
                        connectionControl.valueChanges
                            .pipe(takeUntil(this.unsubscribe$), mergeMap(({ name }) => this.getContracts$(name)))
                            .subscribe(profiles => {
                            field.templateOptions.c8yForOptions = of(profiles);
                            field.formControl.setValue(null);
                        }, error => {
                            field.form.get('contract').setErrors({ contract: true });
                            field.validators.contract.message = error.message;
                        });
                    }
                },
                validators: {
                    contract: {
                        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']
                }
            },
            {
                key: 'productCertificate',
                type: 'string',
                templateOptions: {
                    placeholder: 'P_001F_EDCB_01',
                    label: gettext('Product certificate key'),
                    pattern: 'P_[0-9A-F]{4}_[0-9A-F]{4}_[0-9A-F]{2}',
                    description: gettext('If no product certificate key is specified, the device is considered a prototype.')
                },
                validation: {
                    messages: {
                        pattern: (_error, _field) => this.translateService.instant(gettext('Must be a valid product certificate key, for example, {{ example }}'), { example: 'P_001F_EDCB_01' })
                    }
                }
            }
        ];
        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 sigfoxDevice = this.getSigfoxDeviceToSend();
        try {
            await this.sigfoxService.createDevice(sigfoxDevice);
            this.state = 'registrationSuccess';
            this.gainsightService.triggerEvent(PRODUCT_EXPERIENCE_SIGFOX_REGISTRATION.EVENT, {
                result: PRODUCT_EXPERIENCE_SIGFOX_REGISTRATION.RESULT.SUCCESS,
                component: PRODUCT_EXPERIENCE_SIGFOX_REGISTRATION.COMPONENT
            });
        }
        catch (error) {
            this.gainsightService.triggerEvent(PRODUCT_EXPERIENCE_SIGFOX_REGISTRATION.EVENT, {
                result: PRODUCT_EXPERIENCE_SIGFOX_REGISTRATION.RESULT.FAILURE,
                component: PRODUCT_EXPERIENCE_SIGFOX_REGISTRATION.COMPONENT
            });
            this.state = 'registrationError';
            this.errors$.next([error]);
        }
        event.stepper.next();
    }
    getSigfoxDeviceToSend() {
        const sigfoxDevice = cloneDeep(this.model);
        sigfoxDevice.lnsConnectionName = this.model.connection.name;
        sigfoxDevice.contractId = this.model.contract.id;
        sigfoxDevice.prototype = !sigfoxDevice.productCertificate;
        delete sigfoxDevice.contract;
        delete sigfoxDevice.connection;
        return sigfoxDevice;
    }
    getContracts$(name) {
        return defer(() => from(this.sigfoxService.getContracts(name))).pipe(shareReplay(1));
    }
    getProtocols$() {
        return defer(() => from(this.sigfoxService.getAvailableProtocols())).pipe(shareReplay(1));
    }
    getConnections$() {
        return defer(() => from(this.sigfoxService.getConnections())).pipe(shareReplay(1));
    }
    ngOnDestroy() {
        this.unsubscribe$.next();
        this.unsubscribe$.complete();
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: SigfoxDeviceRegistrationComponent, deps: [{ token: i1$1.BsModalRef }, { token: SigfoxProviderService }, { token: i2.TranslateService }, { token: i4.GainsightService }], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.2.13", type: SigfoxDeviceRegistrationComponent, selector: "c8y-sigfox-device-registration", ngImport: i0, template: "<c8y-modal\n  [title]=\"'Sigfox 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 Sigfox 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=\"sigfox-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: "directive", type: i4.IconDirective, selector: "[c8yIcon]", inputs: ["c8yIcon"] }, { kind: "directive", type: i5.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i5.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i5.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: i4.LoadingComponent, selector: "c8y-loading", inputs: ["layout", "progress", "message"] }, { kind: "component", type: i4.OperationResultComponent, selector: "c8y-operation-result", inputs: ["text", "vertical", "size", "type"] }, { kind: "component", type: i4.ModalComponent, selector: "c8y-modal", inputs: ["disabled", "close", "dismiss", "title", "body", "customFooter", "headerClasses", "labels"], outputs: ["onDismiss", "onClose"] }, { kind: "component", type: i4.C8yStepper, selector: "c8y-stepper", inputs: ["disableDefaultIcons", "disableProgressButtons", "customClasses", "hideStepProgress", "useStepLabelsAsTitlesOnly"], outputs: ["onStepChange"] }, { kind: "component", type: i6.CdkStep, selector: "cdk-step", inputs: ["stepControl", "label", "errorMessage", "aria-label", "aria-labelledby", "state", "editable", "optional", "completed", "hasError"], outputs: ["interacted"], exportAs: ["cdkStep"] }, { kind: "component", type: i4.C8yStepperButtons, selector: "c8y-stepper-buttons", inputs: ["labels", "pending", "disabled", "showButtons"], outputs: ["onCancel", "onNext", "onBack", "onCustom"] }, { kind: "component", type: i7.FormlyForm, selector: "formly-form", inputs: ["form", "model", "fields", "options"], outputs: ["modelChange"] }, { kind: "pipe", type: i4.C8yTranslatePipe, name: "translate" }, { kind: "pipe", type: i5.AsyncPipe, name: "async" }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: SigfoxDeviceRegistrationComponent, decorators: [{
            type: Component,
            args: [{ selector: 'c8y-sigfox-device-registration', template: "<c8y-modal\n  [title]=\"'Sigfox 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 Sigfox 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=\"sigfox-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: SigfoxProviderService }, { type: i2.TranslateService }, { type: i4.GainsightService }] });

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

class SigfoxDeviceRegistrationFactory {
    constructor(tenantService) {
        this.tenantService = tenantService;
    }
    get() {
        const items = [];
        if (this.tenantService.isMicroserviceSubscribedInCurrentTenant('sigfox-agent')) {
            items.push({
                template: SigfoxDeviceRegistrationButtonComponent,
                priority: 98,
                category: 'single'
            });
        }
        return items;
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: SigfoxDeviceRegistrationFactory, deps: [{ token: i4.TenantUiService }], target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: SigfoxDeviceRegistrationFactory, providedIn: 'root' }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: SigfoxDeviceRegistrationFactory, decorators: [{
            type: Injectable,
            args: [{
                    providedIn: 'root'
                }]
        }], ctorParameters: () => [{ type: i4.TenantUiService }] });

class SigfoxDeviceRegistrationModule {
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: SigfoxDeviceRegistrationModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
    static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "18.2.13", ngImport: i0, type: SigfoxDeviceRegistrationModule, declarations: [SigfoxDeviceRegistrationButtonComponent, SigfoxDeviceRegistrationComponent], imports: [CoreModule, CommonModule] }); }
    static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: SigfoxDeviceRegistrationModule, providers: [hookDeviceRegistration(SigfoxDeviceRegistrationFactory), SigfoxProviderService], imports: [CoreModule, CommonModule] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: SigfoxDeviceRegistrationModule, decorators: [{
            type: NgModule,
            args: [{
                    imports: [CoreModule, CommonModule],
                    declarations: [SigfoxDeviceRegistrationButtonComponent, SigfoxDeviceRegistrationComponent],
                    providers: [hookDeviceRegistration(SigfoxDeviceRegistrationFactory), SigfoxProviderService]
                }]
        }] });

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

export { SigfoxDeviceRegistrationButtonComponent, SigfoxDeviceRegistrationComponent, SigfoxDeviceRegistrationFactory, SigfoxDeviceRegistrationModule };
//# sourceMappingURL=c8y-ngx-components-sigfox-device-registration.mjs.map
