var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
        r = Reflect.decorate(decorators, target, key, desc);
    else
        for (var i = decorators.length - 1; i >= 0; i--)
            if (d = decorators[i])
                r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s)
        if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
            t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
import { Host, h } from "@stencil/core";
import { PieChart } from "../../../helpers/chart/pie-chart";
import { sanitizeVegaComponent } from "../../../utils/component";
import { InjectVegaGlobalSlimmer, InjectVegaSlimmer } from "../../../../../../vega-slimmer/vega-slimmer-core";
import { VegaComponentUsageRuntimeMetricsSlimmer } from "../../../helpers/slimmers/component-usage-runtime-metrics";
/**
 * @vegaVersion 1.35.0
 */
export class VegaPieChart {
    constructor() {
        this.globalSlimmers = {};
        this.vegaComponentUsageRuntimeMetricsSlimmer = new VegaComponentUsageRuntimeMetricsSlimmer();
    }
    watchOptionsHandel(options) {
        this.updateChart(options);
    }
    disconnectedCallback() {
        this.chart = null;
        this.reRenderTimer && clearTimeout(this.reRenderTimer);
    }
    componentWillLoad() {
        this.updateChart(this.options);
    }
    /**
     * Invoke this method to render the chart using the existing options.
     *    If the chart is displayed incorrectly within a modal or tab,
     *    ensure that this method is invoked after the chart is shown
     *    to ensure proper rendering.
     *
     * @vegaVersion 1.35.0
     */
    async reRender() {
        this.reRenderTimer && clearTimeout(this.reRenderTimer);
        /* istanbul ignore next */
        this.reRenderTimer = setTimeout(() => {
            this.chart.reRender();
        }, 0);
    }
    render() {
        return sanitizeVegaComponent(h(Host, null), this.host);
    }
    /**
     * This function draws a pie chart using the provided options and data source.
     *
     * @param {PieChartOptions} options - The options parameter is an object that contains various options for configuring and rendering a line chart.
     */
    updateChart(options) {
        if (!options)
            return;
        const { mode = 'svg', dataSource } = options, restOptions = __rest(options, ["mode", "dataSource"]);
        const mergedOptions = Object.assign(Object.assign({}, restOptions), { mode, container: this.host, dataSource: dataSource || [] });
        if (this.chart) {
            this.chart.updateOptions(mergedOptions);
        }
        else {
            this.chart = new PieChart(mergedOptions);
            this.chart.render();
        }
    }
    static get is() { return "vega-pie-chart"; }
    static get encapsulation() { return "shadow"; }
    static get originalStyleUrls() {
        return {
            "$": ["vega-pie-chart.scss"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["vega-pie-chart.css"]
        };
    }
    static get properties() {
        return {
            "options": {
                "type": "unknown",
                "mutable": false,
                "complexType": {
                    "original": "PieChartOptions",
                    "resolved": "\"container\" | \"xAxis\" | \"yAxis\" | { dataSource: RecordChartData[]; donutRadius?: number; type?: \"Pie\" | \"Donut\"; }",
                    "references": {
                        "PieChartOptions": {
                            "location": "import",
                            "path": "../../../helpers/chart/pie-chart",
                            "id": "src/helpers/chart/pie-chart.ts::PieChartOptions",
                            "referenceLocation": "PieChartOptions"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [{
                            "name": "vegaVersion",
                            "text": "1.35.0"
                        }],
                    "text": "Specifies the rendering options for the pie chart."
                },
                "getter": false,
                "setter": false
            }
        };
    }
    static get methods() {
        return {
            "reRender": {
                "complexType": {
                    "signature": "() => Promise<void>",
                    "parameters": [],
                    "references": {
                        "Promise": {
                            "location": "global",
                            "id": "global::Promise"
                        }
                    },
                    "return": "Promise<void>"
                },
                "docs": {
                    "text": "Invoke this method to render the chart using the existing options.\n   If the chart is displayed incorrectly within a modal or tab,\n   ensure that this method is invoked after the chart is shown\n   to ensure proper rendering.",
                    "tags": [{
                            "name": "vegaVersion",
                            "text": "1.35.0"
                        }]
                }
            }
        };
    }
    static get elementRef() { return "host"; }
    static get watchers() {
        return [{
                "propName": "options",
                "methodName": "watchOptionsHandel"
            }];
    }
}
__decorate([
    InjectVegaGlobalSlimmer()
], VegaPieChart.prototype, "globalSlimmers", void 0);
__decorate([
    InjectVegaSlimmer()
], VegaPieChart.prototype, "vegaComponentUsageRuntimeMetricsSlimmer", void 0);
