"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const eventEnum = require("../enums/eventEnum.js");
const index = require("../../node_modules/.pnpm/echarts@5.4.3/node_modules/echarts/index.js");
const components = {};
const npmPkgs = { echarts: index };
const useLifeHandler = (chartConfig) => {
  if (!chartConfig.events)
    return {};
  const baseEvent = {};
  for (const key in chartConfig.events.baseEvent) {
    const fnStr = chartConfig.events.baseEvent[key];
    if (fnStr) {
      baseEvent[key] = generateBaseFunc(fnStr);
    }
  }
  const events = chartConfig.events.advancedEvents || {};
  const lifeEvents = {
    [eventEnum.EventLife.VNODE_BEFORE_MOUNT](e) {
      components[chartConfig.id] = e.component;
      const fnStr = (events[eventEnum.EventLife.VNODE_BEFORE_MOUNT] || "").trim();
      generateFunc(fnStr, e);
    },
    [eventEnum.EventLife.VNODE_MOUNTED](e) {
      const fnStr = (events[eventEnum.EventLife.VNODE_MOUNTED] || "").trim();
      generateFunc(fnStr, e);
    }
  };
  return { ...baseEvent, ...lifeEvents };
};
function generateBaseFunc(fnStr) {
  try {
    return new Function(`
      return (
        async function(components,mouseEvent){
          ${fnStr}
        }
      )`)().bind(void 0, components);
  } catch (error) {
    console.error(error);
  }
}
function generateFunc(fnStr, e) {
  try {
    Function(`
      "use strict";
      return (
        async function(e, components, node_modules){
          const {${Object.keys(npmPkgs).join()}} = node_modules;
          ${fnStr}
        }
      )`)().bind(e == null ? void 0 : e.component)(e, components, npmPkgs);
  } catch (error) {
    console.error(error);
  }
}
exports.generateBaseFunc = generateBaseFunc;
exports.npmPkgs = npmPkgs;
exports.useLifeHandler = useLifeHandler;
