import { PreviewService, gettext, DynamicDatapointsResolver, hookWidget, hookPreview } from '@c8y/ngx-components';
import * as i0 from '@angular/core';
import { inject, Injectable } from '@angular/core';
import { map } from 'rxjs';
import { defaultWidgetIds } from '@c8y/ngx-components/widgets/definitions';
import cloneDeep from 'lodash/cloneDeep';

class DatapointGraphFactory {
    constructor() {
        this.betaPreviewService = inject(PreviewService);
        this.baseWidgetDefinition = {
            id: defaultWidgetIds.DATAPOINTS_GRAPH,
            label: gettext('Data points graph'),
            description: gettext('Displays a graph of selected data points'),
            loadComponent: () => import('@c8y/ngx-components/widgets/implementations/datapoints-graph').then(m => m.DatapointsGraphWidgetViewComponent),
            loadConfigComponent: () => import('@c8y/ngx-components/widgets/implementations/datapoints-graph').then(m => m.DatapointsGraphWidgetConfigComponent),
            previewImage: 'c8y-style-assets/datapoints-graph-widget.png',
            resolve: {
                datapoints: DynamicDatapointsResolver
            },
            data: {
                schema: () => import('c8y-schema-loader?interfaceName=DatapointsGraphWidgetConfig!@c8y/ngx-components/echart'),
                settings: {
                    noNewWidgets: false,
                    widgetDefaults: {
                        _width: 8,
                        _height: 4
                    },
                    noDeviceTarget: true,
                    groupsSelectable: false
                },
                displaySettings: {
                    globalTimeContext: true,
                    globalAggregationContext: true,
                    globalRealtimeContext: true
                }
            }
        };
    }
    get() {
        return this.betaPreviewService.getState$('ui.datapoint-graph.v2').pipe(map(state => {
            if (state) {
                const newWidgetDefinition = cloneDeep(this.baseWidgetDefinition);
                newWidgetDefinition.id = defaultWidgetIds.DATAPOINTS_GRAPH_NEW;
                newWidgetDefinition.data.settings.noNewWidgets = true;
                return [this.baseWidgetDefinition, newWidgetDefinition];
            }
            return [];
        }));
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: DatapointGraphFactory, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: DatapointGraphFactory }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: DatapointGraphFactory, decorators: [{
            type: Injectable
        }] });

const datapointGraphWidgetproviders = [
    hookWidget(DatapointGraphFactory),
    hookPreview({
        key: 'ui.datapoint-graph.v2',
        label: 'Data points graph',
        description: () => import('@c8y/style/markdown-files/datapoint-graph-preview.md').then(m => m.default),
        settings: {
            reload: true
        }
    })
];

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

export { datapointGraphWidgetproviders };
//# sourceMappingURL=c8y-ngx-components-widgets-definitions-datapoints-graph.mjs.map
