import { hookWidget } from '@c8y/ngx-components';
import { gettext } from '@c8y/ngx-components/gettext';
import { defaultWidgetIds } from '@c8y/ngx-components/widgets/definitions';
import { inject, Injector } from '@angular/core';

const markdownWidgetDefinition = {
    id: defaultWidgetIds.MARKDOWN,
    label: gettext('Markdown widget'),
    description: gettext('Display content provided as Markdown. You can either upload a file, or provide a file path.'),
    loadComponent: () => import('@c8y/ngx-components/widgets/implementations/markdown').then(m => m.MarkdownWidgetViewComponent),
    loadConfigComponent: () => import('@c8y/ngx-components/widgets/implementations/markdown').then(m => m.MarkdownWidgetConfigComponent),
    previewImage: 'c8y-style-assets/markdown-widget.png',
    data: {
        schema: () => import('c8y-schema-loader?interfaceName=MarkdownWidgetConfig!@c8y/ngx-components/widgets/implementations/markdown'),
        export: exportMarkdownWidgetConfig,
        import: importMarkdownWidgetConfig,
        settings: {
            noNewWidgets: false,
            widgetDefaults: {
                _width: 8,
                _height: 4
            },
            ng1: {
                options: {
                    noDeviceTarget: true,
                    groupsSelectable: false
                }
            }
        }
    }
};
const markdownWidgetProviders = [hookWidget(markdownWidgetDefinition)];
async function exportMarkdownWidgetConfig(config, _dashboardData, _options) {
    const { MarkdownWidgetService } = await import('@c8y/ngx-components/widgets/implementations/markdown');
    const injector = inject(Injector);
    if (config.contentUrl && !config.markdownBinaryId) {
        return config;
    }
    const markdownWidgetService = injector.get(MarkdownWidgetService);
    const file = await markdownWidgetService.getFile(config.markdownBinaryId);
    const content = await file.text();
    return {
        ...config,
        markdownDetails: {
            text: content,
            file: {
                name: file.name,
                type: file.type
            }
        }
    };
}
async function importMarkdownWidgetConfig(config, _dashboardData, _options) {
    const { MarkdownWidgetService } = await import('@c8y/ngx-components/widgets/implementations/markdown');
    if (!config.markdownDetails) {
        return config;
    }
    const injector = inject(Injector);
    const markdownService = injector.get(MarkdownWidgetService);
    const fileToUpload = new File([config.markdownDetails.text], config.markdownDetails.file.name, {
        type: config.markdownDetails.file.type
    });
    const markdownBinaryId = await markdownService.uploadFile(fileToUpload);
    return {
        contentUrl: config.contentUrl,
        markdownBinaryId
    };
}

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

export { markdownWidgetDefinition, markdownWidgetProviders };
//# sourceMappingURL=c8y-ngx-components-widgets-definitions-markdown.mjs.map
