import { hookWidgetConfig } from '@c8y/ngx-components/context-dashboard';
import * as i0 from '@angular/core';
import { inject, Injector, Injectable } from '@angular/core';
import { PreviewService } from '@c8y/ngx-components';
import { gettext } from '@c8y/ngx-components/gettext';
import { AIService } from '@c8y/ngx-components/ai';
import { defaultWidgetIds } from '@c8y/ngx-components/widgets/definitions';
import { combineLatest, from, first, map } from 'rxjs';
import { HTML_AGENT } from '@c8y/ngx-components/ai/agents/html';

const HTML_WIDGET_AGENT_DEFINITIONS = {
    snapshot: __MODE__ === 'development',
    label: gettext('HTML Widget Code assistant'),
    definition: HTML_AGENT
};

class AIHtmlWidgetConfigFactory {
    constructor() {
        this.betaPreviewService = inject(PreviewService);
        this.aiService = inject(AIService);
        this.injector = inject(Injector);
        this.aiWidgetConfigDefinition = {
            widgetId: defaultWidgetIds.HTML,
            label: gettext('AI Code Assistant'),
            loadComponent: () => import('@c8y/ngx-components/ai/agent-chat').then(m => m.WidgetAiChatSectionComponent),
            initialState: {
                agent: HTML_WIDGET_AGENT_DEFINITIONS,
                title: gettext('I’m your AI Code Assistant, here to help you build powerful widgets for your dashboard.'),
                welcomeText: gettext('Describe the widget you want or select one of the options below to get started.'),
                loadRenderStepComponent: () => import('@c8y/ngx-components/widgets/implementations/html-widget').then(m => m.HtmlAiChatFeedbackComponent),
                suggestions: [
                    {
                        label: gettext('Measurement widget'),
                        prompt: gettext('Create a widget that shows the current measurement of this device.')
                    },
                    {
                        label: gettext('Device status widget'),
                        prompt: gettext('Create a widget that shows the status of my devices.')
                    },
                    {
                        label: gettext('Critical alarm widget'),
                        prompt: gettext('Create a widget that shows all critical alarms.')
                    }
                ]
            },
            priority: 100,
            injector: this.injector
        };
    }
    get() {
        return combineLatest([
            from(this.aiService.getAgentHealth()),
            this.betaPreviewService.getState$('ui.html-widget.v2').pipe(first())
        ]).pipe(map(([aiHealthCheck, state]) => {
            if (state && aiHealthCheck.isProviderConfigured) {
                return [this.aiWidgetConfigDefinition];
            }
            return [];
        }));
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.18", ngImport: i0, type: AIHtmlWidgetConfigFactory, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.18", ngImport: i0, type: AIHtmlWidgetConfigFactory, providedIn: 'root' }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.18", ngImport: i0, type: AIHtmlWidgetConfigFactory, decorators: [{
            type: Injectable,
            args: [{
                    providedIn: 'root'
                }]
        }] });

const htmlWidgetAIChatProviders = [hookWidgetConfig(AIHtmlWidgetConfigFactory)];

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

export { htmlWidgetAIChatProviders };
//# sourceMappingURL=c8y-ngx-components-widgets-definitions-html-widget-ai-config.mjs.map
