'use strict';

var preprocessor = require('./preprocessor.js');
var BrushView = require('./BrushView.js');
var BrushModel = require('./BrushModel.js');
var visualEncoding = require('./visualEncoding.js');
var Brush = require('../toolbox/feature/Brush.js');
var featureManager = require('../toolbox/featureManager.js');
var util = require('../../../../../../zrender@6.0.0/node_modules/zrender/lib/core/util.js');

function install(registers) {
  registers.registerComponentView(BrushView.default);
  registers.registerComponentModel(BrushModel.default);
  registers.registerPreprocessor(preprocessor.default);
  registers.registerVisual(registers.PRIORITY.VISUAL.BRUSH, visualEncoding.default);
  registers.registerAction({
    type: 'brush',
    event: 'brush',
    update: 'updateVisual'
  }, function (payload, ecModel) {
    ecModel.eachComponent({
      mainType: 'brush',
      query: payload
    }, function (brushModel) {
      brushModel.setAreas(payload.areas);
    });
  });
  /**
   * payload: {
   *      brushComponents: [
   *          {
   *              brushId,
   *              brushIndex,
   *              brushName,
   *              series: [
   *                  {
   *                      seriesId,
   *                      seriesIndex,
   *                      seriesName,
   *                      rawIndices: [21, 34, ...]
   *                  },
   *                  ...
   *              ]
   *          },
   *          ...
   *      ]
   * }
   */
  registers.registerAction({
    type: 'brushSelect',
    event: 'brushSelected',
    update: 'none'
  }, util.noop);
  registers.registerAction({
    type: 'brushEnd',
    event: 'brushEnd',
    update: 'none'
  }, util.noop);
  featureManager.registerFeature('brush', Brush.default);
}

exports.install = install;
