import * as i0 from '@angular/core';
import { inject, Injectable, importProvidersFrom } from '@angular/core';
import { PreviewService, hookRoute, ViewContext, hookTab, HookProviderTypes, hookActionBar } from '@c8y/ngx-components';
import { ContextDashboardModule, NewDashboardGuard, ContextDashboardComponent, newDashboardTab } from '@c8y/ngx-components/context-dashboard';
import { AddDeviceDashboardFactory, DeviceDashboardActionBarFactory } from '@c8y/ngx-components/context-dashboard/device/add';
import { DeviceDashboardGuard } from '@c8y/ngx-components/context-dashboard/device/view';
import { firstValueFrom, first } from 'rxjs';

class AddDMDeviceDashboardFactory extends AddDeviceDashboardFactory {
    constructor() {
        super(...arguments);
        this.previewFeatureService = inject(PreviewService);
    }
    async get(activatedRoute) {
        const previewEnabled = await firstValueFrom(this.previewFeatureService.getState$(DM_DASHBOARD_MANAGER_PREVIEW_KEY));
        return previewEnabled ? super.get(activatedRoute) : [];
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AddDMDeviceDashboardFactory, deps: null, target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AddDMDeviceDashboardFactory, providedIn: 'root' }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AddDMDeviceDashboardFactory, decorators: [{
            type: Injectable,
            args: [{
                    providedIn: 'root'
                }]
        }] });

const DM_DASHBOARD_MANAGER_PREVIEW_KEY = 'ui.dm-dashboard-manager';
function canActivateDashboardManager() {
    const previewFeatureService = inject(PreviewService);
    return previewFeatureService.getState$(DM_DASHBOARD_MANAGER_PREVIEW_KEY).pipe(first());
}
const addDeviceContextDashboardFeatureProvider = [
    importProvidersFrom(ContextDashboardModule),
    hookRoute([
        // new dashboard route should be defined last
        {
            path: newDashboardTab.path,
            component: ContextDashboardComponent,
            canActivate: [canActivateDashboardManager, NewDashboardGuard],
            canDeactivate: [(component) => component.canDeactivate()],
            context: ViewContext.Device,
            rootContext: ViewContext.Dashboard
        }
    ]),
    hookTab(AddDMDeviceDashboardFactory, { providerType: HookProviderTypes.ExistingProvider }),
    hookActionBar(DeviceDashboardActionBarFactory)
];
const viewDeviceContextDashboardFeatureProvider = [
    importProvidersFrom(ContextDashboardModule),
    hookRoute([
        {
            path: 'dashboard/:dashboardId',
            component: ContextDashboardComponent,
            canActivate: [canActivateDashboardManager, DeviceDashboardGuard],
            canDeactivate: [(component) => component.canDeactivate()],
            context: ViewContext.Device,
            rootContext: ViewContext.Dashboard
        }
    ])
];

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

export { DM_DASHBOARD_MANAGER_PREVIEW_KEY, addDeviceContextDashboardFeatureProvider, canActivateDashboardManager, viewDeviceContextDashboardFeatureProvider };
//# sourceMappingURL=c8y-ngx-components-context-dashboard-devicemanagement.mjs.map
