import categoryFilter from './categoryFilter.mjs';
import categoryVisual from './categoryVisual.mjs';
import graphEdgeVisual from './edgeVisual.mjs';
import graphSimpleLayout from './simpleLayout.mjs';
import graphCircularLayout from './circularLayout.mjs';
import graphForceLayout from './forceLayout.mjs';
import createViewCoordSys from './createView.mjs';
import View from '../../coord/View.mjs';
import GraphView from './GraphView.mjs';
import GraphSeriesModel from './GraphSeries.mjs';
import { updateCenterAndZoomInAction } from '../../component/helper/roamHelper.mjs';
import { noop } from '../../../../../../zrender@6.0.0/node_modules/zrender/lib/core/util.mjs';

function install(registers) {
  registers.registerChartView(GraphView);
  registers.registerSeriesModel(GraphSeriesModel);
  registers.registerProcessor(categoryFilter);
  registers.registerVisual(categoryVisual);
  registers.registerVisual(graphEdgeVisual);
  registers.registerLayout(graphSimpleLayout);
  registers.registerLayout(registers.PRIORITY.VISUAL.POST_CHART_LAYOUT, graphCircularLayout);
  registers.registerLayout(graphForceLayout);
  registers.registerCoordinateSystem('graphView', {
    dimensions: View.dimensions,
    create: createViewCoordSys
  });
  // Register legacy focus actions
  registers.registerAction({
    type: 'focusNodeAdjacency',
    event: 'focusNodeAdjacency',
    update: 'series:focusNodeAdjacency'
  }, noop);
  registers.registerAction({
    type: 'unfocusNodeAdjacency',
    event: 'unfocusNodeAdjacency',
    update: 'series:unfocusNodeAdjacency'
  }, noop);
  // Register roam action.
  registers.registerAction({
    type: 'graphRoam',
    event: 'graphRoam',
    update: 'none'
  }, function (payload, ecModel, api) {
    ecModel.eachComponent({
      mainType: 'series',
      query: payload
    }, function (seriesModel) {
      var graphView = api.getViewOfSeriesModel(seriesModel);
      if (graphView) {
        if (payload.dx != null && payload.dy != null) {
          graphView.updateViewOnPan(seriesModel, api, payload);
        }
        if (payload.zoom != null && payload.originX != null && payload.originY != null) {
          graphView.updateViewOnZoom(seriesModel, api, payload);
        }
      }
      var coordSys = seriesModel.coordinateSystem;
      var res = updateCenterAndZoomInAction(coordSys, payload, seriesModel.get('scaleLimit'));
      seriesModel.setCenter && seriesModel.setCenter(res.center);
      seriesModel.setZoom && seriesModel.setZoom(res.zoom);
    });
  });
}

export { install };
