/* eslint-disable import-x/namespace -- echarts/core uses complex re-exports that static analysis can't resolve */
// Import the echarts core module, which provides the necessary interfaces for using echarts.
import * as echarts from "echarts/core";

// Import charts, all suffixed with Chart
import { BarChart, LineChart, CustomChart } from "echarts/charts";

// Import the title, tooltip, rectangular coordinate system, dataset and transform components
import {
  TooltipComponent,
  DatasetComponent,
  TransformComponent,
  LegendComponent,
  GridComponent,
  DataZoomComponent,
  VisualMapComponent,
  ToolboxComponent,
} from "echarts/components";

// Features like Universal Transition and Label Layout
import { LabelLayout, UniversalTransition } from "echarts/features";

// Import the Canvas renderer
// Note that including the CanvasRenderer or SVGRenderer is a required step
import { CanvasRenderer } from "echarts/renderers";

// Import graphic utilities from zrender for use in charts
// This avoids importing from the full "echarts" package which has a separate registry
// zrender is a direct dependency of echarts and always available
import LinearGradient from "zrender/lib/graphic/LinearGradient";

import "./axis-proxy-patch";

import type {
  // The series option types are defined with the SeriesOption suffix
  BarSeriesOption,
  LineSeriesOption,
  CustomSeriesOption,
  SankeySeriesOption,
  GraphSeriesOption,
  SunburstSeriesOption,
} from "echarts/charts";
import type {
  // The component option types are defined with the ComponentOption suffix
  TooltipComponentOption,
  DatasetComponentOption,
  LegendComponentOption,
  GridComponentOption,
  DataZoomComponentOption,
  VisualMapComponentOption,
} from "echarts/components";
import type { ComposeOption } from "echarts/core";

// Create an Option type with only the required components and charts via ComposeOption
export type ECOption = ComposeOption<
  | BarSeriesOption
  | LineSeriesOption
  | CustomSeriesOption
  | TooltipComponentOption
  | DatasetComponentOption
  | LegendComponentOption
  | GridComponentOption
  | DataZoomComponentOption
  | VisualMapComponentOption
  | SankeySeriesOption
  | GraphSeriesOption
  | SunburstSeriesOption
>;

export type {
  HaECOption,
  HaECSeries,
  HaECSeriesItem,
  HaTooltipOption,
  LitTooltipFormatter,
} from "./ha-ec-option";

// Register the required components
echarts.use([
  BarChart,
  LineChart,
  CustomChart,
  TooltipComponent,
  DatasetComponent,
  LegendComponent,
  GridComponent,
  TransformComponent,
  DataZoomComponent,
  VisualMapComponent,
  LabelLayout,
  UniversalTransition,
  CanvasRenderer,
  ToolboxComponent,
]);

export { LinearGradient };

export default echarts;
