import { h } from "@stencil/core";
import ApexCharts from "apexcharts";
const config = (options, type, width, height, series) => {
    const chart = options.chart ? Object.assign({}, options.chart) : {};
    if (type) {
        chart.type = type;
    }
    if (width) {
        chart.width = width;
    }
    if (height) {
        chart.height = height;
    }
    return series ? Object.assign(Object.assign({}, options), { chart, series }) : Object.assign(Object.assign({}, options), { chart });
};
if (window) {
    const win = window;
    win.ApexCharts = ApexCharts;
}
export class chart {
    constructor() {
        /**
         * Internal ApexCharts instance
         */
        this.chartObj = null;
    }
    optionsChanged(options) {
        if (this.chartObj !== null) {
            return this.chartObj.updateOptions(config(options, this.type, this.width, this.height, this.series));
        }
    }
    seriesChanged(series) {
        if (this.chartObj !== null) {
            this.chartObj.updateSeries(series, true);
        }
    }
    /**
     * Updates the configuration object. The new config object is merged with the existing config object preserving the existing configuration.
     * @param newOptions The configuration object to merge on the existing one
     * @param redrawPaths When the chart is re-rendered, should it draw from the existing paths or completely redraw the chart paths from the beginning. By default, the chart is re-rendered from the existing paths
     * @param animate Should the chart animate on re-rendering
     */
    async updateOptions(newOptions, redrawPaths, animate) {
        return this.chartObj.updateOptions(newOptions, redrawPaths, animate);
    }
    async componentDidLoad() {
        if (this.chartObj === null) {
            this.chartObj = new ApexCharts(this.chartRef, config(this.options, this.type, this.width, this.height, this.series));
            return this.chartObj.render();
        }
    }
    disconnectedCallback() {
        if (this.chartObj !== null) {
            this.chartObj.destroy();
        }
    }
    render() {
        return h("div", { key: '76dba280237764cbb1edca2006bb39ba61e29ca8', ref: el => (this.chartRef = el) });
    }
    static get is() { return "dga-apex-chart"; }
    static get originalStyleUrls() {
        return {
            "$": ["dga-apex-chart.scss"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["dga-apex-chart.css"]
        };
    }
    static get properties() {
        return {
            "type": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "ApexChartType",
                    "resolved": "\"area\" | \"bar\" | \"boxPlot\" | \"bubble\" | \"candlestick\" | \"donut\" | \"heatmap\" | \"line\" | \"pie\" | \"polarArea\" | \"radar\" | \"radialBar\" | \"rangeArea\" | \"rangeBar\" | \"scatter\" | \"treemap\"",
                    "references": {
                        "ApexChartType": {
                            "location": "import",
                            "path": ".",
                            "id": "src/components/dga-apex-chart/index.ts::ApexChartType"
                        }
                    }
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [{
                            "name": "see",
                            "text": "https://apexcharts.com/docs/options/chart/type/"
                        }],
                    "text": "(optional) Type"
                },
                "getter": false,
                "setter": false,
                "attribute": "type",
                "reflect": false
            },
            "width": {
                "type": "any",
                "mutable": false,
                "complexType": {
                    "original": "ApexChartWidth",
                    "resolved": "number | string",
                    "references": {
                        "ApexChartWidth": {
                            "location": "import",
                            "path": ".",
                            "id": "src/components/dga-apex-chart/index.ts::ApexChartWidth"
                        }
                    }
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [{
                            "name": "see",
                            "text": "https://apexcharts.com/docs/options/chart/width/"
                        }],
                    "text": "(optional) Width"
                },
                "getter": false,
                "setter": false,
                "attribute": "width",
                "reflect": false
            },
            "height": {
                "type": "any",
                "mutable": false,
                "complexType": {
                    "original": "ApexChartHeight",
                    "resolved": "number | string",
                    "references": {
                        "ApexChartHeight": {
                            "location": "import",
                            "path": ".",
                            "id": "src/components/dga-apex-chart/index.ts::ApexChartHeight"
                        }
                    }
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [{
                            "name": "see",
                            "text": "https://apexcharts.com/docs/options/chart/height/"
                        }],
                    "text": "(optional) Height"
                },
                "getter": false,
                "setter": false,
                "attribute": "height",
                "reflect": false
            },
            "options": {
                "type": "unknown",
                "mutable": true,
                "complexType": {
                    "original": "ApexOptions",
                    "resolved": "ApexOptions",
                    "references": {
                        "ApexOptions": {
                            "location": "import",
                            "path": "apexcharts",
                            "id": "../../node_modules/.pnpm/apexcharts@4.4.0/node_modules/apexcharts/types/apexcharts.d.ts::ApexOptions"
                        }
                    }
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [{
                            "name": "see",
                            "text": "https://apexcharts.com/docs/options/"
                        }],
                    "text": "(optional) Options"
                },
                "getter": false,
                "setter": false
            },
            "series": {
                "type": "unknown",
                "mutable": true,
                "complexType": {
                    "original": "ApexOptionsSeries",
                    "resolved": "number[] | { name?: string; type?: string; color?: string; group?: string; hidden?: boolean; zIndex?: number; data: number[] | { x: any; y: any; fill?: ApexFill; fillColor?: string; strokeColor?: string; meta?: any; goals?: { name?: string; value: number; strokeHeight?: number; strokeWidth?: number; strokeColor?: string; strokeDashArray?: number; strokeLineCap?: \"butt\" | \"round\" | \"square\"; }[]; barHeightOffset?: number; columnWidthOffset?: number; }[] | [number, number][] | [number, number[]][] | number[][]; }[]",
                    "references": {
                        "ApexOptionsSeries": {
                            "location": "import",
                            "path": ".",
                            "id": "src/components/dga-apex-chart/index.ts::ApexOptionsSeries"
                        }
                    }
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [{
                            "name": "see",
                            "text": "https://apexcharts.com/docs/options/series/"
                        }],
                    "text": "(optional) Series"
                },
                "getter": false,
                "setter": false
            }
        };
    }
    static get states() {
        return {
            "chartObj": {}
        };
    }
    static get methods() {
        return {
            "updateOptions": {
                "complexType": {
                    "signature": "(newOptions: ApexOptions, redrawPaths?: boolean, animate?: boolean) => Promise<void>",
                    "parameters": [{
                            "name": "newOptions",
                            "type": "ApexOptions",
                            "docs": "The configuration object to merge on the existing one"
                        }, {
                            "name": "redrawPaths",
                            "type": "boolean",
                            "docs": "When the chart is re-rendered, should it draw from the existing paths or completely redraw the chart paths from the beginning. By default, the chart is re-rendered from the existing paths"
                        }, {
                            "name": "animate",
                            "type": "boolean",
                            "docs": "Should the chart animate on re-rendering"
                        }],
                    "references": {
                        "Promise": {
                            "location": "global",
                            "id": "global::Promise"
                        },
                        "ApexOptions": {
                            "location": "import",
                            "path": "apexcharts",
                            "id": "../../node_modules/.pnpm/apexcharts@4.4.0/node_modules/apexcharts/types/apexcharts.d.ts::ApexOptions"
                        }
                    },
                    "return": "Promise<void>"
                },
                "docs": {
                    "text": "Updates the configuration object. The new config object is merged with the existing config object preserving the existing configuration.",
                    "tags": [{
                            "name": "param",
                            "text": "newOptions The configuration object to merge on the existing one"
                        }, {
                            "name": "param",
                            "text": "redrawPaths When the chart is re-rendered, should it draw from the existing paths or completely redraw the chart paths from the beginning. By default, the chart is re-rendered from the existing paths"
                        }, {
                            "name": "param",
                            "text": "animate Should the chart animate on re-rendering"
                        }]
                }
            }
        };
    }
    static get watchers() {
        return [{
                "propName": "options",
                "methodName": "optionsChanged"
            }, {
                "propName": "series",
                "methodName": "seriesChanged"
            }];
    }
}
//# sourceMappingURL=dga-apex-chart.js.map
