import { Chart, BarController, LineController, ScatterController, LineElement, PointElement, BarElement, CategoryScale, LinearScale, LogarithmicScale, TimeScale, TimeSeriesScale, Legend, Tooltip, Title, Interaction } from 'chart.js';
export { Chart as ChartJs } from 'chart.js';
import { MatrixController, MatrixElement } from 'chartjs-chart-matrix';
import AnnotationPlugin from 'chartjs-plugin-annotation';
import Interpolate from './chartjs-plugins/interaction.interpolate.mjs';
import FlowUiColorsPlugin from './chartjs-plugins/plugin.flow-ui-colors.mjs';
import CursorPositioner from './chartjs-plugins/positioner.cursor.mjs';
import SymlogAxis from './chartjs-plugins/symlog.scale.mjs';

let chartJsInitialized = false;
function initializeChartJs() {
  if (chartJsInitialized) {
    return;
  }
  chartJsInitialized = true;
  Chart.register(
    FlowUiColorsPlugin,
    BarController,
    LineController,
    ScatterController,
    LineElement,
    PointElement,
    BarElement,
    CategoryScale,
    LinearScale,
    LogarithmicScale,
    TimeScale,
    TimeSeriesScale,
    SymlogAxis,
    Legend,
    Tooltip,
    Title,
    AnnotationPlugin,
    MatrixController,
    MatrixElement
  );
  Tooltip.positioners.cursor = CursorPositioner;
  Interaction.modes.interpolate = Interpolate;
  Chart.defaults.animation = false;
  Chart.defaults.responsive = true;
  Chart.defaults.maintainAspectRatio = false;
  Chart.defaults.layout.padding = {
    top: 5,
    right: 10,
    bottom: 5,
    left: 5
  };
  Chart.defaults.plugins.legend.position = "bottom";
  Chart.defaults.plugins.legend.align = "start";
  Chart.defaults.plugins.tooltip.position = "cursor";
  Chart.defaults.plugins.title.font = { size: 12 };
  Chart.defaults.plugins.title.align = "start";
  Chart.defaults.plugins.title.padding = { top: 0, bottom: 10 };
}
function registerChartComponent(...components) {
  Chart.register(...components);
}

export { initializeChartJs, registerChartComponent };
