import { h } from "@stencil/core";
import * as echarts from "echarts";
export class InternalEchartsRenderer {
    content;
    width = '100%';
    height = '300px';
    theme = 'default';
    responsive = true;
    showLoading = true;
    el;
    chart = null;
    resizeHandler = null;
    async componentDidLoad() {
        await this.renderChart();
    }
    async contentChanged() {
        await this.renderChart();
    }
    disconnectedCallback() {
        this.disposeChart();
    }
    async renderChart() {
        if (!this.content)
            return;
        try {
            // 设置容器样式
            this.el.style.width = this.width;
            this.el.style.height = this.height;
            // 创建图表实例
            this.chart = echarts.init(this.el, this.theme);
            // 显示加载动画
            if (this.showLoading) {
                this.chart.showLoading();
            }
            // 设置配置
            this.chart.setOption(this.content);
            // 隐藏加载动画
            if (this.showLoading) {
                this.chart.hideLoading();
            }
            // 响应式处理
            if (this.responsive) {
                this.resizeHandler = () => {
                    if (this.chart) {
                        this.chart.resize();
                    }
                };
                window.addEventListener('resize', this.resizeHandler);
            }
        }
        catch (error) {
            console.error('ECharts rendering error:', error);
        }
    }
    disposeChart() {
        if (this.chart) {
            this.chart.dispose();
            this.chart = null;
        }
        if (this.resizeHandler) {
            window.removeEventListener('resize', this.resizeHandler);
            this.resizeHandler = null;
        }
    }
    render() {
        return (h("div", { key: '672833fed8f4c7fae1e0625036ee9b3fb7bb1eee', class: "echarts-container" }));
    }
    static get is() { return "internal-echarts-renderer"; }
    static get encapsulation() { return "shadow"; }
    static get originalStyleUrls() {
        return {
            "$": ["echarts-renderer.css"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["echarts-renderer.css"]
        };
    }
    static get properties() {
        return {
            "content": {
                "type": "any",
                "mutable": false,
                "complexType": {
                    "original": "any",
                    "resolved": "any",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "content"
            },
            "width": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "width",
                "defaultValue": "'100%'"
            },
            "height": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "height",
                "defaultValue": "'300px'"
            },
            "theme": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "theme",
                "defaultValue": "'default'"
            },
            "responsive": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "responsive",
                "defaultValue": "true"
            },
            "showLoading": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "show-loading",
                "defaultValue": "true"
            }
        };
    }
    static get elementRef() { return "el"; }
    static get watchers() {
        return [{
                "propName": "content",
                "methodName": "contentChanged"
            }];
    }
}
//# sourceMappingURL=echarts-renderer.js.map
