import Highcharts from "highcharts";
import HighchartsVue from "highcharts-vue";

export default defineNuxtPlugin(async (nuxtApp) => {
  if (process.client) {
    const ExportingModule = await import("highcharts/modules/exporting");
    const ExportDataModule = await import("highcharts/modules/export-data");

    const applyModule = (mod) => {
      if (typeof mod === "function") {
        mod(Highcharts);
      } else if (mod?.default && typeof mod.default === "function") {
        mod.default(Highcharts);
      }
    };

    applyModule(ExportingModule);
    applyModule(ExportDataModule);
  }

  nuxtApp.vueApp.use(HighchartsVue);
});
