import * as i0 from '@angular/core';
import { Injectable } from '@angular/core';
import { gettext } from '@c8y/ngx-components/gettext';
import { hookRoute, ViewContext, hookService } from '@c8y/ngx-components';
import * as i1 from '@c8y/ngx-components/remote-access/data';
import { canActivateRemoteAccess } from '@c8y/ngx-components/remote-access/data';
import * as i2 from 'ngx-bootstrap/modal';

class VNCRemoteAccessProtocolProviderService {
    constructor(remoteAccess, bsModalService) {
        this.remoteAccess = remoteAccess;
        this.bsModalService = bsModalService;
        this.protocolName = 'VNC';
        this.protocolLabel = gettext('VNC');
        this.protocolDescription = gettext('Allows to connect to a VNC service.');
        this.protocolIcon = 'laptop';
    }
    async addEndpoint(deviceId) {
        const modalResult = await this.openVNCEndpointModal({});
        if (!modalResult) {
            return modalResult;
        }
        return this.remoteAccess.addConfiguration(deviceId, modalResult);
    }
    removeEndpoint(deviceId, currentEndpointConfig) {
        return this.remoteAccess.deleteConfiguration(deviceId, currentEndpointConfig.id);
    }
    async editEndpoint(deviceId, currentEndpointConfig) {
        const modalResult = await this.openVNCEndpointModal(currentEndpointConfig);
        if (!modalResult) {
            return modalResult;
        }
        return this.remoteAccess.updateConfiguration(deviceId, modalResult);
    }
    async connectEndpointHref(deviceId, configuration) {
        return `/device/${deviceId}/vnc/${configuration.id}`;
    }
    async getDefaultEndpointConfiguration() {
        return {
            hostname: '127.0.0.1',
            port: 5900
        };
    }
    async openVNCEndpointModal(currentConfiguration) {
        const { RemoteAccessVncEndpointModalComponent } = await import('@c8y/ngx-components/remote-access/vnc/remote-access-vnc-endpoint-modal');
        try {
            const modalRef = this.bsModalService.show(RemoteAccessVncEndpointModalComponent, {
                initialState: { currentValue: currentConfiguration }
            });
            return (await modalRef.content.result);
        }
        catch (e) {
            // modal closed
            return null;
        }
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.18", ngImport: i0, type: VNCRemoteAccessProtocolProviderService, deps: [{ token: i1.RemoteAccessService }, { token: i2.BsModalService }], target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.18", ngImport: i0, type: VNCRemoteAccessProtocolProviderService, providedIn: 'root' }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.18", ngImport: i0, type: VNCRemoteAccessProtocolProviderService, decorators: [{
            type: Injectable,
            args: [{ providedIn: 'root' }]
        }], ctorParameters: () => [{ type: i1.RemoteAccessService }, { type: i2.BsModalService }] });
const remoteAccessVNCProviders = [
    hookRoute({
        loadComponent: () => import('@c8y/ngx-components/remote-access/vnc/vnc-viewer').then(m => m.VncViewerComponent),
        path: 'vnc/:configurationId',
        context: ViewContext.Device,
        tabs: [],
        canActivate: [canActivateRemoteAccess]
    }),
    hookService('remoteAccessProtocolHook', VNCRemoteAccessProtocolProviderService)
];

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

export { VNCRemoteAccessProtocolProviderService, remoteAccessVNCProviders };
//# sourceMappingURL=c8y-ngx-components-remote-access-vnc.mjs.map
