"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ChartingInternalApi = void 0;
const ApiBase_1 = require("../Implementation/ApiBase");
class ChartingInternalApi extends ApiBase_1.ApiBase {
    getContainerElement(chartContainer) {
        const element = typeof chartContainer?.element === 'string'
            ? document.querySelector(chartContainer.element)
            : chartContainer?.element;
        if (!element && typeof chartContainer?.element === 'string') {
            this.getAdatableLogger().consoleLogByMessageType(`Chart container element not found: ${chartContainer.element}`, 'Error');
            return null;
        }
        return element;
    }
    getContainerElemetnByName(containerName) {
        const chartContainers = this.getChartingOptions().chartContainers ?? [];
        const chartContainer = chartContainers.find((container) => container.name === containerName);
        return this.getContainerElement(chartContainer);
    }
    getUniqueChartName() {
        const charts = this.getChartingApi().getChartDefinitions();
        const externalCharts = this.getChartingApi().getExternalChartDefinitions();
        return `Chart ${charts.length + externalCharts.length + 1}`;
    }
    // External lib charting service
    isExternalChartOpened(chartDefinition) {
        const externalChartingOptions = this.getChartingOptions().externalChartingOptions;
        if (!externalChartingOptions?.isChartOpened) {
            return false;
        }
        if (!chartDefinition) {
            return false;
        }
        return externalChartingOptions.isChartOpened({
            chartDefinition: chartDefinition,
            ...this.getAdaptableInternalApi().buildBaseContext(),
        });
    }
    onHideExternalChart(chartDefinition) {
        const externalChartingOptions = this.getChartingOptions().externalChartingOptions;
        if (!externalChartingOptions?.onHideChart) {
            return;
        }
        externalChartingOptions.onHideChart({
            chartDefinition: chartDefinition,
            ...this.getAdaptableInternalApi().buildBaseContext(),
        });
    }
    onShowExternalChart(chartDefinition, container) {
        const externalChartingOptions = this.getChartingOptions().externalChartingOptions;
        if (!externalChartingOptions?.onShowChart) {
            return;
        }
        externalChartingOptions.onShowChart({
            chartDefinition: chartDefinition,
            container: container,
            ...this.getAdaptableInternalApi().buildBaseContext(),
        });
    }
    onPreviewExternalChart(chartDefinition, container) {
        const externalChartingOptions = this.getChartingOptions().externalChartingOptions;
        if (!externalChartingOptions?.onPreviewChart) {
            return;
        }
        return externalChartingOptions.onPreviewChart({
            chartDefinition: chartDefinition,
            container: container,
            ...this.getAdaptableInternalApi().buildBaseContext(),
        });
    }
    onDeleteExternalChart(chartDefinition) {
        const externalChartingOptions = this.getChartingOptions().externalChartingOptions;
        if (!externalChartingOptions?.onDeleteChart) {
            return;
        }
        externalChartingOptions.onDeleteChart({
            chartDefinition: chartDefinition,
            ...this.getAdaptableInternalApi().buildBaseContext(),
        });
    }
}
exports.ChartingInternalApi = ChartingInternalApi;
