"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard")["default"];

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

var _react = _interopRequireWildcard(require("react"));

var _isFunction = _interopRequireDefault(require("lodash/isFunction"));

var _TableContext = _interopRequireDefault(require("./TableContext"));

var _enum = require("./enum");

var _TableRow = _interopRequireDefault(require("./TableRow"));

var _utils = require("./utils");

function useRenderClone(columnGroups) {
  var _useContext = (0, _react.useContext)(_TableContext["default"]),
      tableStore = _useContext.tableStore,
      dataSet = _useContext.dataSet,
      rowDragRender = _useContext.rowDragRender,
      prefixCls = _useContext.prefixCls;

  return (0, _react.useCallback)(function (provided, snapshot, rubric) {
    if (!(0, _utils.isStickySupport)() && snapshot.isDragging && tableStore.overflowX && tableStore.dragColumnAlign === _enum.DragColumnAlign.right) {
      var style = provided.draggableProps.style;

      if ((0, _utils.isDraggingStyle)(style)) {
        var left = style.left,
            width = style.width;
        style.left = left - Math.max(tableStore.columnGroups.leafColumnsWidth - tableStore.columnGroups.rightLeafColumnsWidth, width);
      }
    }

    var record = dataSet.find(function (record) {
      return String(record.key) === rubric.draggableId;
    });

    if (record) {
      var leafColumnsBody = columnGroups || tableStore.columnGroups;
      var renderClone = rowDragRender && rowDragRender.renderClone;
      var id = record.id;

      if (renderClone && (0, _isFunction["default"])(renderClone)) {
        return renderClone({
          provided: provided,
          snapshot: snapshot,
          rubric: rubric,
          key: id,
          hidden: false,
          lock: false,
          prefixCls: prefixCls,
          columns: leafColumnsBody.leafs.map(function (_ref) {
            var column = _ref.column;
            return column;
          }),
          columnGroups: leafColumnsBody,
          record: record,
          index: 0
        });
      }

      return /*#__PURE__*/_react["default"].createElement(_TableRow["default"], {
        provided: provided,
        snapshot: snapshot,
        key: id,
        hidden: false,
        lock: false,
        columnGroups: leafColumnsBody,
        record: record,
        index: id,
        className: "dragging-row"
      });
    }

    return /*#__PURE__*/_react["default"].createElement("span", null);
  }, [tableStore, dataSet, rowDragRender, columnGroups]);
}
//# sourceMappingURL=hooks.js.map
