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