import * as i0 from '@angular/core';
import { InjectionToken, ViewChild, Optional, Inject, Component, NgModule } from '@angular/core';
import { gettext } from '@c8y/ngx-components/gettext';
import * as i1 from '@c8y/ngx-components';
import { CoreModule, hookNavigator, hookRoute, ViewContext } from '@c8y/ngx-components';
import * as i2 from '@c8y/ngx-components/context-dashboard';
import { ContextDashboardModule, ContextDashboardComponent } from '@c8y/ngx-components/context-dashboard';

/**
 * A hook to define the default widgets of the home dashboard in the cockpit app.
 */
const COCKPIT_HOME_DASHBOARD_CONFIG = new InjectionToken('CockpitHomeDashboardConfig');
/**
 * An array of widgets that is per default placed on the home dashboard of the cockpit app.
 */
const DEFAULT_COCKPIT_HOME_WIDGETS = [
    {
        name: 'cockpit.welcome.widget',
        title: gettext('Welcome to Cockpit'),
        _x: 0,
        _y: 0,
        _height: 5,
        _width: 24,
        classes: { 'panel-title-hidden': true }
    },
    {
        name: 'Asset Alarms',
        title: gettext('Active, critical alarms'),
        config: {
            widgetId: 'Asset Alarms',
            displayMode: 'config',
            aggregation: null,
            isAutoRefreshEnabled: true,
            refreshInterval: 30_000,
            refreshOption: 'live',
            dateTimeContext: {
                dateFrom: new Date(0).toISOString(),
                dateTo: new Date().toISOString(),
                interval: 'custom'
            }
        },
        _x: 0,
        _y: 5,
        _height: 4,
        _width: 12
    },
    {
        name: 'Recent Alarms',
        title: gettext('Recent alarms'),
        config: {
            widgetId: 'Recent Alarms',
            displayMode: 'config',
            aggregation: null,
            isAutoRefreshEnabled: true,
            refreshInterval: 30_000,
            refreshOption: 'live',
            dateTimeContext: {
                dateFrom: new Date(0).toISOString(),
                dateTo: new Date().toISOString(),
                interval: 'custom'
            }
        },
        _x: 0,
        _y: 9,
        _height: 4,
        _width: 12
    },
    {
        name: 'Map',
        title: gettext('Map'),
        config: {
            displayMode: 'dashboard'
        },
        _x: 12,
        _y: 5,
        _height: 8,
        _width: 12
    }
];

class CockpitDashboardComponent {
    constructor(appState, homeDashboardConfig) {
        this.appState = appState;
        this.homeDashboardConfig = homeDashboardConfig;
        this.defaultWidgets = DEFAULT_COCKPIT_HOME_WIDGETS;
        this.dashboardName = 'home-cockpit1';
        this.pageTitle = gettext('Home');
        const config = {
            ...this.homeDashboardConfig,
            dashboardName: appState.currentApplication.value?.config?.homeDashboardName,
            userSpecific: appState.currentApplication.value?.config?.userSpecificHomeDashboard
        };
        this.applyDashboardConfig(config);
    }
    canDeactivate() {
        return this.contextDashboard.canDeactivate();
    }
    applyDashboardConfig(config) {
        if (!config) {
            return;
        }
        if (config.dashboardName) {
            this.dashboardName = config.dashboardName;
        }
        if (config.defaultWidgets) {
            this.defaultWidgets = config.defaultWidgets;
        }
        if (config.userSpecific && this.appState.currentUser.value) {
            this.dashboardName = `${this.appState.currentUser.value.userName.replace(/\./g, '__')}_${this.dashboardName}`;
        }
        if (config.pageTitle) {
            this.pageTitle = config.pageTitle;
        }
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: CockpitDashboardComponent, deps: [{ token: i1.AppStateService }, { token: COCKPIT_HOME_DASHBOARD_CONFIG, optional: true }], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "20.3.19", type: CockpitDashboardComponent, isStandalone: true, selector: "c8y-cockpit-dashboard", viewQueries: [{ propertyName: "contextDashboard", first: true, predicate: ContextDashboardComponent, descendants: true, static: true }], ngImport: i0, template: "<c8y-title>\n  {{ pageTitle | translate }}\n</c8y-title>\n\n<c8y-context-dashboard\n  [name]=\"dashboardName\"\n  [defaultWidgets]=\"defaultWidgets\"\n  [canDelete]=\"false\"\n  [hideAvailability]=\"true\"\n></c8y-context-dashboard>\n", dependencies: [{ kind: "ngmodule", type: CoreModule }, { kind: "component", type: i1.TitleComponent, selector: "c8y-title", inputs: ["pageTitleUpdate"] }, { kind: "ngmodule", type: ContextDashboardModule }, { kind: "component", type: i2.ContextDashboardComponent, selector: "c8y-context-dashboard", inputs: ["name", "childrenClasses", "context", "setTitle", "defaultWidgets", "canCopy", "canDelete", "isLoading", "breadcrumbSettings", "showContextHelpButton", "translateWidgetTitle", "translateDashboardTitle", "hideAvailability", "disabled"] }, { kind: "pipe", type: i1.C8yTranslatePipe, name: "translate" }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: CockpitDashboardComponent, decorators: [{
            type: Component,
            args: [{ selector: 'c8y-cockpit-dashboard', standalone: true, imports: [CoreModule, ContextDashboardModule], template: "<c8y-title>\n  {{ pageTitle | translate }}\n</c8y-title>\n\n<c8y-context-dashboard\n  [name]=\"dashboardName\"\n  [defaultWidgets]=\"defaultWidgets\"\n  [canDelete]=\"false\"\n  [hideAvailability]=\"true\"\n></c8y-context-dashboard>\n" }]
        }], ctorParameters: () => [{ type: i1.AppStateService }, { type: undefined, decorators: [{
                    type: Optional
                }, {
                    type: Inject,
                    args: [COCKPIT_HOME_DASHBOARD_CONFIG]
                }] }], propDecorators: { contextDashboard: [{
                type: ViewChild,
                args: [ContextDashboardComponent, { static: true }]
            }] } });

class CockpitHomeDashboardModule {
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: CockpitHomeDashboardModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
    static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.3.19", ngImport: i0, type: CockpitHomeDashboardModule }); }
    static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: CockpitHomeDashboardModule, providers: [
            hookNavigator({
                label: gettext('Home'),
                icon: 'home',
                priority: 10000,
                path: '/home',
                routerLinkExact: false
            }),
            hookRoute({
                path: 'home',
                component: CockpitDashboardComponent,
                canDeactivate: [(component) => component.canDeactivate()],
                rootContext: ViewContext.Dashboard
            })
        ] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: CockpitHomeDashboardModule, decorators: [{
            type: NgModule,
            args: [{
                    providers: [
                        hookNavigator({
                            label: gettext('Home'),
                            icon: 'home',
                            priority: 10000,
                            path: '/home',
                            routerLinkExact: false
                        }),
                        hookRoute({
                            path: 'home',
                            component: CockpitDashboardComponent,
                            canDeactivate: [(component) => component.canDeactivate()],
                            rootContext: ViewContext.Dashboard
                        })
                    ]
                }]
        }] });
class CockpitDashboardModule {
    static config(config = {}) {
        return {
            ngModule: CockpitDashboardModule,
            providers: [
                {
                    provide: COCKPIT_HOME_DASHBOARD_CONFIG,
                    useValue: config
                }
            ]
        };
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: CockpitDashboardModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
    static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.3.19", ngImport: i0, type: CockpitDashboardModule, imports: [CockpitHomeDashboardModule] }); }
    static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: CockpitDashboardModule, imports: [CockpitHomeDashboardModule] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: CockpitDashboardModule, decorators: [{
            type: NgModule,
            args: [{
                    imports: [CockpitHomeDashboardModule]
                }]
        }] });

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

export { COCKPIT_HOME_DASHBOARD_CONFIG, CockpitDashboardComponent, CockpitDashboardModule, CockpitHomeDashboardModule, DEFAULT_COCKPIT_HOME_WIDGETS };
//# sourceMappingURL=c8y-ngx-components-context-dashboard-cockpit-home-dashboard.mjs.map
