"use strict";

var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.makeColumnHoverTransform = makeColumnHoverTransform;
exports.useColumnHoverTransform = useColumnHoverTransform;

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");

/** @deprecated transform 用法已经过时，请使用 pipeline 来对表格进行拓展 */
function makeColumnHoverTransform(_ref) {
  var _ref$hoverColor = _ref.hoverColor,
      hoverColor = _ref$hoverColor === void 0 ? 'var(--hover-bgcolor)' : _ref$hoverColor,
      hoverColIndex = _ref.hoverColIndex,
      onChangeHoverColIndex = _ref.onChangeHoverColIndex;
  (0, _warnTransformsDeprecated.warnTransformsDeprecated)('makeColumnHoverTransform');
  return (0, _utils.traverseColumn)(function (col, _ref2) {
    var range = _ref2.range;

    if (!(0, _utils.isLeafNode)(col)) {
      return col;
    }

    var colIndexMatched = range.start <= hoverColIndex && hoverColIndex < range.end;
    var prevGetCellProps = col.getCellProps;
    return (0, _extends2.default)((0, _extends2.default)({}, col), {
      getCellProps: function getCellProps(value, record, rowIndex) {
        var prevCellProps = prevGetCellProps === null || prevGetCellProps === void 0 ? void 0 : prevGetCellProps(value, record, rowIndex);
        return (0, _utils.mergeCellProps)(prevCellProps, {
          style: {
            '--bgcolor': colIndexMatched ? hoverColor : undefined
          },
          onMouseEnter: function onMouseEnter() {
            onChangeHoverColIndex(range.start);
          },
          onMouseLeave: function onMouseLeave() {
            onChangeHoverColIndex(-1);
          }
        });
      }
    });
  });
}
/** @deprecated transform 用法已经过时，请使用 pipeline 来对表格进行拓展 */


function useColumnHoverTransform() {
  var _ref3 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
      hoverColor = _ref3.hoverColor,
      _ref3$defaultHoverCol = _ref3.defaultHoverColIndex,
      defaultHoverColIndex = _ref3$defaultHoverCol === void 0 ? -1 : _ref3$defaultHoverCol;

  var _useState = (0, _react.useState)(defaultHoverColIndex),
      _useState2 = (0, _slicedToArray2.default)(_useState, 2),
      hoverColIndex = _useState2[0],
      onChangeHoverColIndex = _useState2[1];

  return makeColumnHoverTransform({
    hoverColor: hoverColor,
    hoverColIndex: hoverColIndex,
    onChangeHoverColIndex: onChangeHoverColIndex
  });
}