"use strict";

var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.makeColumnRangeHoverTransform = makeColumnRangeHoverTransform;
exports.useColumnHoverRangeTransform = useColumnHoverRangeTransform;
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/slicedToArray"));
var _extends2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/extends"));
var _react = require("react");
var _utils = require("../utils");
var _warnTransformsDeprecated = require("./warnTransformsDeprecated");
var EMPTY_RANGE = {
  start: -1,
  end: -1
};
/** @deprecated transform 用法已经过时，请使用 pipeline 来对表格进行拓展 */
function makeColumnRangeHoverTransform(_ref) {
  var _ref$hoverColor = _ref.hoverColor,
    hoverColor = _ref$hoverColor === void 0 ? 'var(--hover-bgcolor)' : _ref$hoverColor,
    _ref$headerHoverColor = _ref.headerHoverColor,
    headerHoverColor = _ref$headerHoverColor === void 0 ? 'var(--header-hover-bgcolor)' : _ref$headerHoverColor,
    hoverRange = _ref.hoverRange,
    onChangeHoverRange = _ref.onChangeHoverRange;
  (0, _warnTransformsDeprecated.warnTransformsDeprecated)('makeColumnRangeHoverTransform');
  return (0, _utils.traverseColumn)(function (col, _ref2) {
    var colRange = _ref2.range;
    var match = colRange.end > hoverRange.start && hoverRange.end > colRange.start;
    if (!(0, _utils.isLeafNode)(col)) {
      if (headerHoverColor == null) {
        return col;
      }
      return (0, _extends2.default)((0, _extends2.default)({}, col), {
        headerCellProps: (0, _utils.mergeCellProps)(col.headerCellProps, {
          onMouseEnter: function onMouseEnter() {
            onChangeHoverRange(colRange);
          },
          onMouseLeave: function onMouseLeave() {
            onChangeHoverRange(EMPTY_RANGE);
          },
          style: {
            '--header-bgcolor': match ? headerHoverColor : undefined
          }
        })
      });
    }
    var prevGetCellProps = col.getCellProps;
    return (0, _extends2.default)((0, _extends2.default)({}, col), {
      headerCellProps: (0, _utils.mergeCellProps)(col.headerCellProps, {
        onMouseEnter: function onMouseEnter() {
          onChangeHoverRange(colRange);
        },
        onMouseLeave: function onMouseLeave() {
          onChangeHoverRange(EMPTY_RANGE);
        },
        style: {
          '--header-bgcolor': match ? headerHoverColor : undefined
        }
      }),
      getCellProps: function getCellProps(value, record, rowIndex) {
        var prevCellProps = prevGetCellProps === null || prevGetCellProps === void 0 ? void 0 : prevGetCellProps(value, record, rowIndex);
        return (0, _utils.mergeCellProps)(prevCellProps, {
          onMouseEnter: function onMouseEnter() {
            onChangeHoverRange(colRange);
          },
          onMouseLeave: function onMouseLeave() {
            onChangeHoverRange(EMPTY_RANGE);
          },
          style: {
            '--bgcolor': match ? hoverColor : undefined
          }
        });
      }
    });
  });
}
/** @deprecated transform 用法已经过时，请使用 pipeline 来对表格进行拓展 */
function useColumnHoverRangeTransform() {
  var _ref3 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
    hoverColor = _ref3.hoverColor,
    headerHoverColor = _ref3.headerHoverColor,
    _ref3$defaultHoverRan = _ref3.defaultHoverRange,
    defaultHoverRange = _ref3$defaultHoverRan === void 0 ? EMPTY_RANGE : _ref3$defaultHoverRan;
  var _useState = (0, _react.useState)(defaultHoverRange),
    _useState2 = (0, _slicedToArray2.default)(_useState, 2),
    hoverRange = _useState2[0],
    onChangeHoverRange = _useState2[1];
  return makeColumnRangeHoverTransform({
    hoverColor: hoverColor,
    headerHoverColor: headerHoverColor,
    hoverRange: hoverRange,
    onChangeHoverRange: onChangeHoverRange
  });
}