"use strict";

var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.mergeCellHover = mergeCellHover;
var _extends2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/extends"));
var _utils = require("../../utils");
function mergeCellHover() {
  return function (pipeline) {
    var onMouseEnter = function onMouseEnter(e) {
      var InRangeRow = pipeline.ref.current.domHelper.getInRangeRowByCellEvent(e);
      InRangeRow.forEach(function (row) {
        row.classList.add('row-hover');
      });
    };
    var onMouseLeave = function onMouseLeave(e) {
      var InRangeRow = pipeline.ref.current.domHelper.getInRangeRowByCellEvent(e);
      InRangeRow.forEach(function (row) {
        row.classList.remove('row-hover');
      });
    };
    var hoverHandlers = {
      onMouseEnter: onMouseEnter,
      onMouseLeave: onMouseLeave
    };
    return pipeline.mapColumns((0, _utils.makeRecursiveMapper)(function (col) {
      if (!(0, _utils.isLeafNode)(col)) {
        return col;
      }
      var prevGetCellProps = col.getCellProps;
      return (0, _extends2.default)((0, _extends2.default)({}, col), {
        getCellProps: function getCellProps(value, record, rowIndex) {
          // 大多数列没有自定义 getCellProps，直接返回静态 handlers 避免 mergeCellProps 开销
          if (!prevGetCellProps) return hoverHandlers;
          var prevCellProps = prevGetCellProps(value, record, rowIndex);
          if (!prevCellProps) return hoverHandlers;
          return (0, _utils.mergeCellProps)(prevCellProps, hoverHandlers);
        }
      });
    }));
  };
}