import * as i0 from '@angular/core';
import { Injectable, EventEmitter, Output, Input, Component, HostListener, NgModule } from '@angular/core';
import * as i2 from '@c8y/ngx-components';
import { DataGridService, alertOnError, DataGridComponent, EmptyStateComponent, ColumnDirective, C8yTranslatePipe, ModalComponent, BaseColumn, getBasicInputArrayFormFieldConfig, Status, BuiltInActionType, TitleComponent, ExpandableRowDirective, CellRendererDefDirective, IconDirective, CoreModule, ModalModule, hookTab, hookRoute, hookNavigator, NavigatorNode } from '@c8y/ngx-components';
import * as i3 from '@c8y/ngx-components/context-dashboard';
import { TypeDashboardInfoComponent, ContextDashboardModule } from '@c8y/ngx-components/context-dashboard';
import { NameDeviceGridColumn, TypeDeviceGridColumn, GroupDeviceGridColumn, RegistrationDateDeviceGridColumn, DeviceGridModule } from '@c8y/ngx-components/device-grid';
import { gettext } from '@c8y/ngx-components/gettext';
import { TooltipModule } from 'ngx-bootstrap/tooltip';
import * as i1 from '@angular/router';
import * as i1$1 from '@c8y/client';
import { QueriesUtil } from '@c8y/client';
import { NgFor } from '@angular/common';
import * as i1$2 from 'ngx-bootstrap/modal';
import * as i3$1 from '@ngx-translate/core';

const DASHBOARD_MANAGER_PRODUCT_EXPERIENCE = {
    EVENTS: {
        DASHBOARD_TEMPLATE: 'dashboardTemplate'
    },
    COMPONENTS: {
        TYPE_DASHBOARDS_LIST: 'type-dashboards-list',
        TYPE_DASHBOARD_TARGET_ASSETS_GRID: 'type-dashboard-target-assets-grid'
    },
    ACTIONS: {
        DELETE_TYPE_DASHBOARD: 'deleteTypeDashboard',
        EDIT_TYPE_DASHBOARD: 'editTypeDashboard',
        OPEN_DASHBOARD_INSTANCE_TO_EDIT: 'openDashboardInstanceToEdit'
    }
};

class DashboardManagerTabsFactory {
    constructor(router) {
        this.router = router;
    }
    get() {
        const tabs = [];
        if (this.router.url.match(/\/dashboard-manager/g)) {
            tabs.push({
                path: 'dashboard-manager/type-dashboards',
                priority: 1000,
                label: gettext('Type dashboards')
            });
        }
        return tabs;
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: DashboardManagerTabsFactory, deps: [{ token: i1.Router }], target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: DashboardManagerTabsFactory }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: DashboardManagerTabsFactory, decorators: [{
            type: Injectable
        }], ctorParameters: () => [{ type: i1.Router }] });

class BasicNameDeviceGridColumn extends NameDeviceGridColumn {
    constructor(initialColumnConfig) {
        super(initialColumnConfig);
        this.name = 'basic-name';
        this.cellRendererComponent = null;
    }
}

class TypeDashboardAssetsGridService extends DataGridService {
    constructor(inventoryService, userPreferencesService) {
        super(userPreferencesService);
        this.inventoryService = inventoryService;
        this.userPreferencesService = userPreferencesService;
    }
    getDefaultColumns(columnsForDevice = true) {
        return columnsForDevice
            ? [
                new BasicNameDeviceGridColumn(),
                new TypeDeviceGridColumn(),
                new GroupDeviceGridColumn(),
                new RegistrationDateDeviceGridColumn()
            ]
            : [
                new BasicNameDeviceGridColumn(),
                new TypeDeviceGridColumn(),
                new RegistrationDateDeviceGridColumn()
            ];
    }
    async getData(columns, pagination, query = {}, text = null) {
        const filters = {
            ...this.getFilters(columns, pagination, query, text),
            withGroups: true
        };
        return this.inventoryService.list(filters);
    }
    async getCount(columns, pagination, query = {}, text = null) {
        const filters = {
            ...this.getFilters(columns, pagination, query, text),
            pageSize: 1,
            currentPage: 1
        };
        return (await this.inventoryService.list(filters)).paging.totalPages;
    }
    async getTotal(query = {}) {
        const filters = {
            query: this.queriesUtil.buildQuery(query),
            pageSize: 1,
            withTotalPages: true
        };
        return (await this.inventoryService.list(filters)).paging.totalPages;
    }
    getFilters(columns, pagination, query, text) {
        return {
            ...{ query: this.getDeviceQueryString(columns, query) },
            ...(text && { text }),
            pageSize: pagination.pageSize,
            currentPage: pagination.currentPage,
            withChildren: false,
            withTotalPages: true
        };
    }
    getDeviceQueryString(columns, query) {
        let fullQuery = this.getQueryObj(columns);
        fullQuery = this.queriesUtil.addAndFilter(fullQuery, query);
        return this.queriesUtil.buildQuery(fullQuery);
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: TypeDashboardAssetsGridService, deps: [{ token: i1$1.InventoryService }, { token: i2.UserPreferencesService }], target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: TypeDashboardAssetsGridService, providedIn: 'root' }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: TypeDashboardAssetsGridService, decorators: [{
            type: Injectable,
            args: [{
                    providedIn: 'root'
                }]
        }], ctorParameters: () => [{ type: i1$1.InventoryService }, { type: i2.UserPreferencesService }] });

class TypeDashboardTargetAssetsGridComponent {
    constructor(router, assetsGridService, contextDashboardService, gainsightService) {
        this.router = router;
        this.assetsGridService = assetsGridService;
        this.contextDashboardService = contextDashboardService;
        this.gainsightService = gainsightService;
        this.labels = { cancel: gettext('Cancel') };
        this.actionControls = [
            {
                type: 'navigateToInstance',
                text: gettext('Open instance`dashboard`'),
                callback: item => this.navigateToDevice(item),
                icon: 'file-create'
            }
        ];
        this.loadMoreItemsLabel = gettext('Load more assets');
        this.loadingItemsLabel = gettext('Loading assets…');
        this.pagination = {
            pageSize: 25,
            currentPage: 1
        };
        this.onNavigateToAsset = new EventEmitter();
        this.serverSideDataCallback = this.onDataSourceModifier.bind(this);
    }
    ngOnInit() {
        this.isDeviceDashboard = this.contextDashboardService.isDeviceDashboard(this.dashboard);
        this.columns = this.assetsGridService.getDefaultColumns(this.isDeviceDashboard);
    }
    async onDataSourceModifier(dataSourceModifier) {
        const baseQuery = { type: this.dashboard.c8y_Dashboard.deviceTypeValue };
        const { res, data, paging } = await alertOnError(this.assetsGridService.getData(dataSourceModifier.columns, dataSourceModifier.pagination, baseQuery, dataSourceModifier.searchText));
        const filteredSize = await alertOnError(this.assetsGridService.getCount(dataSourceModifier.columns, dataSourceModifier.pagination, baseQuery, dataSourceModifier.searchText));
        const size = await alertOnError(this.assetsGridService.getTotal(baseQuery));
        const serverSideDataResult = {
            res,
            data,
            paging,
            filteredSize,
            size
        };
        return serverSideDataResult;
    }
    trackByName(_index, column) {
        return column.name;
    }
    navigateToDevice(val) {
        const parentSubPath = this.isDeviceDashboard ? 'device' : 'group';
        this.onNavigateToAsset.emit();
        this.router.navigate([`/${parentSubPath}/${val.id}/dashboard/${this.dashboard.id}`]);
        this.gainsightService.triggerEvent(DASHBOARD_MANAGER_PRODUCT_EXPERIENCE.EVENTS.DASHBOARD_TEMPLATE, {
            component: DASHBOARD_MANAGER_PRODUCT_EXPERIENCE.COMPONENTS.TYPE_DASHBOARD_TARGET_ASSETS_GRID,
            action: DASHBOARD_MANAGER_PRODUCT_EXPERIENCE.ACTIONS.OPEN_DASHBOARD_INSTANCE_TO_EDIT
        });
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: TypeDashboardTargetAssetsGridComponent, deps: [{ token: i1.Router }, { token: TypeDashboardAssetsGridService }, { token: i3.ContextDashboardService }, { token: i2.GainsightService }], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "20.3.16", type: TypeDashboardTargetAssetsGridComponent, isStandalone: true, selector: "c8y-type-dashboard-target-assets-grid", inputs: { dashboard: "dashboard" }, outputs: { onNavigateToAsset: "onNavigateToAsset" }, ngImport: i0, template: "<c8y-data-grid\n  [title]=\"''\"\n  [loadMoreItemsLabel]=\"loadMoreItemsLabel\"\n  [loadingItemsLabel]=\"loadingItemsLabel\"\n  [columns]=\"columns\"\n  [pagination]=\"pagination\"\n  [infiniteScroll]=\"'auto'\"\n  [actionControls]=\"actionControls\"\n  [serverSideDataCallback]=\"serverSideDataCallback\"\n  [showSearch]=\"true\"\n>\n  <c8y-ui-empty-state\n    [icon]=\"'search'\"\n    [title]=\"'No results to display.' | translate\"\n    [subtitle]=\"'Refine your search terms.' | translate\"\n    [horizontal]=\"true\"\n  ></c8y-ui-empty-state>\n\n  <ng-container *ngFor=\"let column of columns; trackBy: trackByName\">\n    <c8y-column [name]=\"column.name\"></c8y-column>\n  </ng-container>\n</c8y-data-grid>\n", dependencies: [{ kind: "component", type: DataGridComponent, selector: "c8y-data-grid", inputs: ["title", "loadMoreItemsLabel", "loadingItemsLabel", "showSearch", "refresh", "columns", "rows", "pagination", "childNodePagination", "infiniteScroll", "serverSideDataCallback", "selectable", "singleSelection", "selectionPrimaryKey", "displayOptions", "actionControls", "bulkActionControls", "headerActionControls", "searchText", "configureColumnsEnabled", "showCounterWarning", "activeClassName", "expandableRows", "treeGrid", "hideReload", "childNodesProperty", "parentNodeLabelProperty"], outputs: ["rowMouseOver", "rowMouseLeave", "rowClick", "onConfigChange", "onBeforeFilter", "onBeforeSearch", "onFilter", "itemsSelect", "onReload", "onAddCustomColumn", "onRemoveCustomColumn", "onColumnFilterReset", "onSort", "onPageSizeChange", "onColumnReordered", "onColumnVisibilityChange"] }, { kind: "component", type: EmptyStateComponent, selector: "c8y-ui-empty-state", inputs: ["icon", "title", "subtitle", "horizontal"] }, { kind: "directive", type: NgFor, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: ColumnDirective, selector: "c8y-column", inputs: ["name"] }, { kind: "pipe", type: C8yTranslatePipe, name: "translate" }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: TypeDashboardTargetAssetsGridComponent, decorators: [{
            type: Component,
            args: [{ selector: 'c8y-type-dashboard-target-assets-grid', imports: [DataGridComponent, EmptyStateComponent, NgFor, ColumnDirective, C8yTranslatePipe], template: "<c8y-data-grid\n  [title]=\"''\"\n  [loadMoreItemsLabel]=\"loadMoreItemsLabel\"\n  [loadingItemsLabel]=\"loadingItemsLabel\"\n  [columns]=\"columns\"\n  [pagination]=\"pagination\"\n  [infiniteScroll]=\"'auto'\"\n  [actionControls]=\"actionControls\"\n  [serverSideDataCallback]=\"serverSideDataCallback\"\n  [showSearch]=\"true\"\n>\n  <c8y-ui-empty-state\n    [icon]=\"'search'\"\n    [title]=\"'No results to display.' | translate\"\n    [subtitle]=\"'Refine your search terms.' | translate\"\n    [horizontal]=\"true\"\n  ></c8y-ui-empty-state>\n\n  <ng-container *ngFor=\"let column of columns; trackBy: trackByName\">\n    <c8y-column [name]=\"column.name\"></c8y-column>\n  </ng-container>\n</c8y-data-grid>\n" }]
        }], ctorParameters: () => [{ type: i1.Router }, { type: TypeDashboardAssetsGridService }, { type: i3.ContextDashboardService }, { type: i2.GainsightService }], propDecorators: { dashboard: [{
                type: Input
            }], onNavigateToAsset: [{
                type: Output
            }] } });

class TypeDashboardTargetAssetsModalComponent {
    constructor(bsModalRef) {
        this.bsModalRef = bsModalRef;
        this.labels = { cancel: gettext('Cancel') };
    }
    handleKeyboardEvent(event) {
        if (event.key === 'Escape') {
            this.close();
        }
    }
    close() {
        this.bsModalRef.hide();
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: TypeDashboardTargetAssetsModalComponent, deps: [{ token: i1$2.BsModalRef }], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "20.3.16", type: TypeDashboardTargetAssetsModalComponent, isStandalone: true, selector: "c8y-type-dashboard-target-assets-modal", inputs: { dashboard: "dashboard" }, host: { listeners: { "document:keydown": "handleKeyboardEvent($event)" } }, ngImport: i0, template: "<c8y-modal\n  title=\"{{ 'Select dashboard instance to edit' | translate }}\"\n  (onClose)=\"close()\"\n  (onDismiss)=\"close()\"\n  [labels]=\"labels\"\n  [disabled]=\"true\"\n  [headerClasses]=\"'has-data-grid'\"\n>\n  <c8y-type-dashboard-target-assets-grid\n    [dashboard]=\"dashboard\"\n    (onNavigateToAsset)=\"close()\"\n  ></c8y-type-dashboard-target-assets-grid>\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: "component", type: TypeDashboardTargetAssetsGridComponent, selector: "c8y-type-dashboard-target-assets-grid", inputs: ["dashboard"], outputs: ["onNavigateToAsset"] }, { kind: "pipe", type: C8yTranslatePipe, name: "translate" }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: TypeDashboardTargetAssetsModalComponent, decorators: [{
            type: Component,
            args: [{ selector: 'c8y-type-dashboard-target-assets-modal', imports: [ModalComponent, TypeDashboardTargetAssetsGridComponent, C8yTranslatePipe], template: "<c8y-modal\n  title=\"{{ 'Select dashboard instance to edit' | translate }}\"\n  (onClose)=\"close()\"\n  (onDismiss)=\"close()\"\n  [labels]=\"labels\"\n  [disabled]=\"true\"\n  [headerClasses]=\"'has-data-grid'\"\n>\n  <c8y-type-dashboard-target-assets-grid\n    [dashboard]=\"dashboard\"\n    (onNavigateToAsset)=\"close()\"\n  ></c8y-type-dashboard-target-assets-grid>\n</c8y-modal>\n" }]
        }], ctorParameters: () => [{ type: i1$2.BsModalRef }], propDecorators: { dashboard: [{
                type: Input
            }], handleKeyboardEvent: [{
                type: HostListener,
                args: ['document:keydown', ['$event']]
            }] } });

class DeviceTypeValueGridColumn extends BaseColumn {
    constructor(initialColumnConfig) {
        super(initialColumnConfig);
        this.name = 'deviceTypeValue';
        this.path = 'c8y_Dashboard.deviceTypeValue';
        this.header = gettext('Target asset model');
        this.filterable = true;
        this.sortable = false;
        this.filteringConfig = {
            fields: getBasicInputArrayFormFieldConfig({
                key: 'deviceTypeValues',
                label: gettext('Filter dashboards by target asset model'),
                addText: gettext('Add next`target asset model`'),
                tooltip: gettext('Use * as a wildcard character'),
                placeholder: 'c8y_MQTTDevice'
            }),
            getFilter: (model) => {
                const filter = {};
                if (model.deviceTypeValues.length) {
                    filter[this.path] = { __in: model.deviceTypeValues };
                }
                return filter;
            }
        };
    }
}

class DashboardManagerService extends DataGridService {
    constructor(inventory, userPreferencesService, modal, translateService, contextDashboardService) {
        super(userPreferencesService);
        this.inventory = inventory;
        this.userPreferencesService = userPreferencesService;
        this.modal = modal;
        this.translateService = translateService;
        this.contextDashboardService = contextDashboardService;
        this.baseQuery = {
            __filter: {
                __and: [
                    { 'c8y_Dashboard.deviceType': { __eq: true } },
                    { __has: 'c8y_Dashboard.deviceTypeValue' }
                ]
            }
        };
        this.baseTypeDashboardsFilter = {
            __filter: {
                __and: [
                    { 'c8y_Dashboard.deviceType': { __eq: true } },
                    { __has: 'c8y_Dashboard.deviceTypeValue' }
                ]
            }
        };
        this.queriesUtil = new QueriesUtil();
    }
    getColumns() {
        return [
            {
                name: 'icon',
                header: gettext('Icon'),
                path: 'c8y_Dashboard.icon',
                sortable: false,
                gridTrackSize: '45px'
            },
            {
                name: 'name',
                header: gettext('Name'),
                path: 'name',
                sortable: false,
                gridTrackSize: '200px'
            },
            {
                name: 'description',
                header: gettext('Description'),
                path: 'c8y_Dashboard.description',
                sortable: false
            },
            new DeviceTypeValueGridColumn(),
            {
                name: 'lastUpdated',
                header: gettext('Last update'),
                path: 'lastUpdated',
                sortable: false,
                gridTrackSize: '200px'
            }
        ];
    }
    getDefaultPagination() {
        return {
            pageSize: 25,
            currentPage: 1
        };
    }
    async getData(columns, pagination, text) {
        const filters = this.getFilters(columns, pagination, text);
        return await this.inventory.list(filters);
    }
    async getTotal() {
        const query = this.queriesUtil.buildQuery({
            __filter: {
                __and: [
                    this.baseTypeDashboardsFilter.__filter,
                    this.contextDashboardService.appliedToFilter()
                ]
            }
        });
        const res = await this.inventory.list({ query, withTotalElements: true, pageSize: 1 });
        return res.paging.totalElements;
    }
    async delete(dashboard, onSuccess) {
        try {
            const msg = gettext(`You are about to delete the dashboard "{{ dashboardName }}" from all devices of type "{{ deviceType }}".
           Do you want to proceed?`);
            await this.modal.confirm(gettext('Delete dashboard'), this.translateService.instant(msg, {
                dashboardName: dashboard.c8y_Dashboard.name,
                deviceType: dashboard.c8y_Dashboard.deviceTypeValue
            }), Status.DANGER, {
                ok: gettext('Delete'),
                cancel: gettext('Cancel')
            }, {}, {
                eventName: DASHBOARD_MANAGER_PRODUCT_EXPERIENCE.EVENTS.DASHBOARD_TEMPLATE,
                data: {
                    action: DASHBOARD_MANAGER_PRODUCT_EXPERIENCE.ACTIONS.DELETE_TYPE_DASHBOARD,
                    component: DASHBOARD_MANAGER_PRODUCT_EXPERIENCE.COMPONENTS.TYPE_DASHBOARDS_LIST
                }
            });
            await this.inventory.delete(dashboard);
            onSuccess();
        }
        catch (ex) {
            // intended empty
        }
    }
    getFilters(columns, pagination, text) {
        return {
            query: this.getQueryString(columns),
            ...(text && { text }),
            pageSize: pagination.pageSize,
            currentPage: pagination.currentPage,
            withTotalPages: true,
            withTotalElements: true
        };
    }
    getQueryString(columns) {
        const queryFromColumns = this.getQueryObj(columns);
        const base = this.queriesUtil.addAndFilter(queryFromColumns, this.baseTypeDashboardsFilter);
        const withAppliedTo = this.queriesUtil.addAndFilter(base, {
            __filter: this.contextDashboardService.appliedToFilter()
        });
        return this.queriesUtil.buildQuery(withAppliedTo);
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: DashboardManagerService, deps: [{ token: i1$1.InventoryService }, { token: i2.UserPreferencesService }, { token: i2.ModalService }, { token: i3$1.TranslateService }, { token: i3.ContextDashboardService }], target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: DashboardManagerService, providedIn: 'root' }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: DashboardManagerService, decorators: [{
            type: Injectable,
            args: [{
                    providedIn: 'root'
                }]
        }], ctorParameters: () => [{ type: i1$1.InventoryService }, { type: i2.UserPreferencesService }, { type: i2.ModalService }, { type: i3$1.TranslateService }, { type: i3.ContextDashboardService }] });

class TypeDashboardsListComponent {
    constructor(dashboardManagerService, bsModalService, gainsightService) {
        this.dashboardManagerService = dashboardManagerService;
        this.bsModalService = bsModalService;
        this.gainsightService = gainsightService;
        this.title = gettext('Type dashboards');
        this.loadMoreItemsLabel = gettext('Load more dashboards');
        this.loadingItemsLabel = gettext('Loading dashboards…');
        this.columns = this.dashboardManagerService.getColumns();
        this.pagination = this.dashboardManagerService.getDefaultPagination();
        this.actionControls = [
            {
                type: BuiltInActionType.Edit,
                text: gettext('Edit dashboard'),
                callback: item => this.openTargetAssetsModal(item)
            },
            {
                type: BuiltInActionType.Delete,
                text: gettext('Delete dashboard'),
                callback: item => this.delete(item)
            }
        ];
        this.displayOptions = {
            striped: true,
            bordered: false,
            gridHeader: true,
            filter: true,
            hover: false
        };
        this.refresh = new EventEmitter();
        this.serverSideDataCallback = this.onDataSourceModifier.bind(this);
    }
    async delete(dashboard) {
        await this.dashboardManagerService.delete(dashboard, () => this.refresh.emit());
    }
    openTargetAssetsModal(dashboard) {
        const initialState = { dashboard };
        this.bsModalService.show(TypeDashboardTargetAssetsModalComponent, {
            class: 'modal-lg',
            ariaDescribedby: 'modal-body',
            ariaLabelledBy: 'modal-title',
            ignoreBackdropClick: true,
            initialState
        });
        this.gainsightService.triggerEvent(DASHBOARD_MANAGER_PRODUCT_EXPERIENCE.EVENTS.DASHBOARD_TEMPLATE, {
            component: DASHBOARD_MANAGER_PRODUCT_EXPERIENCE.COMPONENTS.TYPE_DASHBOARDS_LIST,
            action: DASHBOARD_MANAGER_PRODUCT_EXPERIENCE.ACTIONS.EDIT_TYPE_DASHBOARD
        });
    }
    trackByName(_index, column) {
        return column.name;
    }
    async onDataSourceModifier(dataSourceModifier) {
        const { res, data, paging } = await alertOnError(this.dashboardManagerService.getData(dataSourceModifier.columns, dataSourceModifier.pagination, dataSourceModifier.searchText));
        const filteredSize = paging.totalElements;
        const size = await alertOnError(this.dashboardManagerService.getTotal());
        return {
            res,
            data,
            paging,
            filteredSize,
            size
        };
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: TypeDashboardsListComponent, deps: [{ token: DashboardManagerService }, { token: i1$2.BsModalService }, { token: i2.GainsightService }], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "20.3.16", type: TypeDashboardsListComponent, isStandalone: true, selector: "c8y-dashboard-manager", ngImport: i0, template: "<c8y-title>\n  {{ 'Dashboard manager' | translate }}\n</c8y-title>\n\n<div class=\"content-fullpage d-flex d-col border-top border-bottom\">\n  <c8y-data-grid\n    [title]=\"title\"\n    [loadMoreItemsLabel]=\"loadMoreItemsLabel\"\n    [loadingItemsLabel]=\"loadingItemsLabel\"\n    [columns]=\"columns\"\n    [pagination]=\"pagination\"\n    [serverSideDataCallback]=\"serverSideDataCallback\"\n    [infiniteScroll]=\"'auto'\"\n    [actionControls]=\"actionControls\"\n    [showSearch]=\"true\"\n    [displayOptions]=\"displayOptions\"\n    [refresh]=\"refresh\"\n    [expandableRows]=\"'ASYNC'\"\n  >\n    <div\n      *c8yExpandableRow=\"\n        let context;\n        let asyncRenderSuccess = asyncRenderSuccess;\n        let asyncRenderFail = asyncRenderFail\n      \"\n    >\n      <c8y-type-dashboard-info\n        [context]=\"context\"\n        [asyncRenderSuccess]=\"asyncRenderSuccess\"\n        [asyncRenderFail]=\"asyncRenderFail\"\n      ></c8y-type-dashboard-info>\n    </div>\n\n    <c8y-ui-empty-state\n      [icon]=\"'search'\"\n      [title]=\"'No matching dashboards.' | translate\"\n      [subtitle]=\"'Refine your search terms' | translate\"\n      [horizontal]=\"true\"\n    ></c8y-ui-empty-state>\n\n    <ng-container *ngFor=\"let column of columns; trackBy: trackByName\">\n      <c8y-column name=\"icon\">\n        <ng-container *c8yCellRendererDef=\"let context\">\n          <i [c8yIcon]=\"context.value\"></i>\n        </ng-container>\n      </c8y-column>\n\n      <c8y-column name=\"deviceTypeValue\">\n        <ng-container *c8yCellRendererDef=\"let context\">\n          <span class=\"label label-info\">\n            {{ context.value }}\n          </span>\n        </ng-container>\n      </c8y-column>\n\n      <c8y-column name=\"name\">\n        <ng-container *c8yCellRendererDef=\"let context\">\n          @let dashboardItem = context.item.c8y_Dashboard;\n          @let dashboardName =\n            dashboardItem.translateDashboardTitle\n              ? (dashboardItem.name | translate)\n              : dashboardItem.name;\n\n          {{ dashboardName }}\n        </ng-container>\n      </c8y-column>\n\n      <c8y-column [name]=\"column.name\"></c8y-column>\n    </ng-container>\n  </c8y-data-grid>\n</div>\n", dependencies: [{ kind: "component", type: TitleComponent, selector: "c8y-title", inputs: ["pageTitleUpdate"] }, { kind: "component", type: DataGridComponent, selector: "c8y-data-grid", inputs: ["title", "loadMoreItemsLabel", "loadingItemsLabel", "showSearch", "refresh", "columns", "rows", "pagination", "childNodePagination", "infiniteScroll", "serverSideDataCallback", "selectable", "singleSelection", "selectionPrimaryKey", "displayOptions", "actionControls", "bulkActionControls", "headerActionControls", "searchText", "configureColumnsEnabled", "showCounterWarning", "activeClassName", "expandableRows", "treeGrid", "hideReload", "childNodesProperty", "parentNodeLabelProperty"], outputs: ["rowMouseOver", "rowMouseLeave", "rowClick", "onConfigChange", "onBeforeFilter", "onBeforeSearch", "onFilter", "itemsSelect", "onReload", "onAddCustomColumn", "onRemoveCustomColumn", "onColumnFilterReset", "onSort", "onPageSizeChange", "onColumnReordered", "onColumnVisibilityChange"] }, { kind: "directive", type: ExpandableRowDirective, selector: "[c8yExpandableRow]" }, { kind: "component", type: TypeDashboardInfoComponent, selector: "c8y-type-dashboard-info", inputs: ["deviceTypeValue", "displayDeviceTypeValue", "context", "asyncRenderSuccess", "asyncRenderFail"] }, { kind: "component", type: EmptyStateComponent, selector: "c8y-ui-empty-state", inputs: ["icon", "title", "subtitle", "horizontal"] }, { kind: "directive", type: NgFor, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: ColumnDirective, selector: "c8y-column", inputs: ["name"] }, { kind: "directive", type: CellRendererDefDirective, selector: "[c8yCellRendererDef]" }, { kind: "directive", type: IconDirective, selector: "[c8yIcon]", inputs: ["c8yIcon"] }, { kind: "pipe", type: C8yTranslatePipe, name: "translate" }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: TypeDashboardsListComponent, decorators: [{
            type: Component,
            args: [{ selector: 'c8y-dashboard-manager', imports: [
                        TitleComponent,
                        DataGridComponent,
                        ExpandableRowDirective,
                        TypeDashboardInfoComponent,
                        EmptyStateComponent,
                        NgFor,
                        ColumnDirective,
                        CellRendererDefDirective,
                        IconDirective,
                        C8yTranslatePipe
                    ], template: "<c8y-title>\n  {{ 'Dashboard manager' | translate }}\n</c8y-title>\n\n<div class=\"content-fullpage d-flex d-col border-top border-bottom\">\n  <c8y-data-grid\n    [title]=\"title\"\n    [loadMoreItemsLabel]=\"loadMoreItemsLabel\"\n    [loadingItemsLabel]=\"loadingItemsLabel\"\n    [columns]=\"columns\"\n    [pagination]=\"pagination\"\n    [serverSideDataCallback]=\"serverSideDataCallback\"\n    [infiniteScroll]=\"'auto'\"\n    [actionControls]=\"actionControls\"\n    [showSearch]=\"true\"\n    [displayOptions]=\"displayOptions\"\n    [refresh]=\"refresh\"\n    [expandableRows]=\"'ASYNC'\"\n  >\n    <div\n      *c8yExpandableRow=\"\n        let context;\n        let asyncRenderSuccess = asyncRenderSuccess;\n        let asyncRenderFail = asyncRenderFail\n      \"\n    >\n      <c8y-type-dashboard-info\n        [context]=\"context\"\n        [asyncRenderSuccess]=\"asyncRenderSuccess\"\n        [asyncRenderFail]=\"asyncRenderFail\"\n      ></c8y-type-dashboard-info>\n    </div>\n\n    <c8y-ui-empty-state\n      [icon]=\"'search'\"\n      [title]=\"'No matching dashboards.' | translate\"\n      [subtitle]=\"'Refine your search terms' | translate\"\n      [horizontal]=\"true\"\n    ></c8y-ui-empty-state>\n\n    <ng-container *ngFor=\"let column of columns; trackBy: trackByName\">\n      <c8y-column name=\"icon\">\n        <ng-container *c8yCellRendererDef=\"let context\">\n          <i [c8yIcon]=\"context.value\"></i>\n        </ng-container>\n      </c8y-column>\n\n      <c8y-column name=\"deviceTypeValue\">\n        <ng-container *c8yCellRendererDef=\"let context\">\n          <span class=\"label label-info\">\n            {{ context.value }}\n          </span>\n        </ng-container>\n      </c8y-column>\n\n      <c8y-column name=\"name\">\n        <ng-container *c8yCellRendererDef=\"let context\">\n          @let dashboardItem = context.item.c8y_Dashboard;\n          @let dashboardName =\n            dashboardItem.translateDashboardTitle\n              ? (dashboardItem.name | translate)\n              : dashboardItem.name;\n\n          {{ dashboardName }}\n        </ng-container>\n      </c8y-column>\n\n      <c8y-column [name]=\"column.name\"></c8y-column>\n    </ng-container>\n  </c8y-data-grid>\n</div>\n" }]
        }], ctorParameters: () => [{ type: DashboardManagerService }, { type: i1$2.BsModalService }, { type: i2.GainsightService }] });

const DASHBOARD_MANAGER_PATH = 'dashboard-manager';
class DashboardManagerModule {
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: DashboardManagerModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
    static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.3.16", ngImport: i0, type: DashboardManagerModule, imports: [CoreModule,
            TooltipModule,
            DeviceGridModule,
            ContextDashboardModule,
            ModalModule,
            TypeDashboardInfoComponent,
            TypeDashboardsListComponent,
            TypeDashboardTargetAssetsModalComponent,
            TypeDashboardTargetAssetsGridComponent] }); }
    static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: DashboardManagerModule, providers: [
            hookTab(DashboardManagerTabsFactory),
            hookRoute([
                {
                    path: DASHBOARD_MANAGER_PATH,
                    redirectTo: `${DASHBOARD_MANAGER_PATH}/type-dashboards`,
                    pathMatch: 'full'
                },
                {
                    path: `${DASHBOARD_MANAGER_PATH}/type-dashboards`,
                    component: TypeDashboardsListComponent
                }
            ]),
            hookNavigator(new NavigatorNode({
                parent: gettext('Configuration'),
                path: DASHBOARD_MANAGER_PATH,
                label: gettext('Dashboard manager'),
                icon: 'management1',
                routerLinkExact: false,
                featureId: 'dashboardManager'
            }))
        ], imports: [CoreModule,
            TooltipModule,
            DeviceGridModule,
            ContextDashboardModule,
            ModalModule,
            TypeDashboardInfoComponent,
            TypeDashboardsListComponent,
            TypeDashboardTargetAssetsModalComponent,
            TypeDashboardTargetAssetsGridComponent] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: DashboardManagerModule, decorators: [{
            type: NgModule,
            args: [{
                    imports: [
                        CoreModule,
                        TooltipModule,
                        DeviceGridModule,
                        ContextDashboardModule,
                        ModalModule,
                        TypeDashboardInfoComponent,
                        TypeDashboardsListComponent,
                        TypeDashboardTargetAssetsModalComponent,
                        TypeDashboardTargetAssetsGridComponent
                    ],
                    providers: [
                        hookTab(DashboardManagerTabsFactory),
                        hookRoute([
                            {
                                path: DASHBOARD_MANAGER_PATH,
                                redirectTo: `${DASHBOARD_MANAGER_PATH}/type-dashboards`,
                                pathMatch: 'full'
                            },
                            {
                                path: `${DASHBOARD_MANAGER_PATH}/type-dashboards`,
                                component: TypeDashboardsListComponent
                            }
                        ]),
                        hookNavigator(new NavigatorNode({
                            parent: gettext('Configuration'),
                            path: DASHBOARD_MANAGER_PATH,
                            label: gettext('Dashboard manager'),
                            icon: 'management1',
                            routerLinkExact: false,
                            featureId: 'dashboardManager'
                        }))
                    ]
                }]
        }] });

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

export { DASHBOARD_MANAGER_PRODUCT_EXPERIENCE, DashboardManagerModule, TypeDashboardsListComponent };
//# sourceMappingURL=c8y-ngx-components-dashboard-manager.mjs.map
