import { PRIORITY, registerMap, registerLoading, registerTransform, registerVisual, registerLayout, registerCoordinateSystem, registerAction, registerUpdateLifecycle, registerPostUpdate, registerPostInit, registerProcessor, registerPreprocessor } from './core/echarts.mjs';
import ComponentView from './view/Component.mjs';
import ChartView from './view/Chart.mjs';
import ComponentModel from './model/Component.mjs';
import SeriesModel from './model/Series.mjs';
import { isArray, each, indexOf, isFunction } from '../../../../zrender@6.0.0/node_modules/zrender/lib/core/util.mjs';
import { registerImpl } from './core/impl.mjs';
import { registerPainter } from '../../../../zrender@6.0.0/node_modules/zrender/lib/zrender.mjs';
import { registerCustomSeries } from './chart/custom/customSeriesRegister.mjs';

var extensions = [];
var extensionRegisters = {
  registerPreprocessor: registerPreprocessor,
  registerProcessor: registerProcessor,
  registerPostInit: registerPostInit,
  registerPostUpdate: registerPostUpdate,
  registerUpdateLifecycle: registerUpdateLifecycle,
  registerAction: registerAction,
  registerCoordinateSystem: registerCoordinateSystem,
  registerLayout: registerLayout,
  registerVisual: registerVisual,
  registerTransform: registerTransform,
  registerLoading: registerLoading,
  registerMap: registerMap,
  registerImpl: registerImpl,
  PRIORITY: PRIORITY,
  ComponentModel: ComponentModel,
  ComponentView: ComponentView,
  SeriesModel: SeriesModel,
  ChartView: ChartView,
  // TODO Use ComponentModel and SeriesModel instead of Constructor
  registerComponentModel: function (ComponentModelClass) {
    ComponentModel.registerClass(ComponentModelClass);
  },
  registerComponentView: function (ComponentViewClass) {
    ComponentView.registerClass(ComponentViewClass);
  },
  registerSeriesModel: function (SeriesModelClass) {
    SeriesModel.registerClass(SeriesModelClass);
  },
  registerChartView: function (ChartViewClass) {
    ChartView.registerClass(ChartViewClass);
  },
  registerCustomSeries: function (seriesType, renderItem) {
    registerCustomSeries(seriesType, renderItem);
  },
  registerSubTypeDefaulter: function (componentType, defaulter) {
    ComponentModel.registerSubTypeDefaulter(componentType, defaulter);
  },
  registerPainter: function (painterType, PainterCtor) {
    registerPainter(painterType, PainterCtor);
  }
};
function use(ext) {
  if (isArray(ext)) {
    // use([ChartLine, ChartBar]);
    each(ext, function (singleExt) {
      use(singleExt);
    });
    return;
  }
  if (indexOf(extensions, ext) >= 0) {
    return;
  }
  extensions.push(ext);
  if (isFunction(ext)) {
    ext = {
      install: ext
    };
  }
  ext.install(extensionRegisters);
}

export { use };
