import { Controller } from '@hotwired/stimulus';

/* Controller générique ApexCharts : prend la config complète via data-chart-options-value (JSON). */
export default class extends Controller {
    static values = { options: Object };

    async connect() {
        const ApexCharts = (await import('apexcharts')).default;
        this.chart = new ApexCharts(this.element, this.optionsValue);
        this.chart.render();
    }

    disconnect() {
        if (this.chart) {
            this.chart.destroy();
            this.chart = null;
        }
    }
}
