"use strict";

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

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

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

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

var _mobxReactLite = require("mobx-react-lite");

var _classnames = _interopRequireDefault(require("classnames"));

var _UnitConvertor = require("../../../lib/_util/UnitConvertor");

var _measureScrollbar = _interopRequireDefault(require("../../../lib/_util/measureScrollbar"));

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

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

var StickyShadow = function StickyShadow(props) {
  var _classNames;

  var position = props.position,
      children = props.children;

  var _useContext = (0, _react.useContext)(_TableContext["default"]),
      tableStore = _useContext.tableStore,
      prefixCls = _useContext.prefixCls;

  var columnGroups = tableStore.columnGroups;
  var disabled = !children && (position === 'left' && columnGroups.leftLeafs.length === 0 || position === 'right' && (0, _utils.onlyCustomizedColumn)(tableStore));

  if (disabled) {
    return null;
  }

  var classString = (0, _classnames["default"])((_classNames = {}, (0, _defineProperty2["default"])(_classNames, "".concat(prefixCls, "-sticky-shadow"), !children), (0, _defineProperty2["default"])(_classNames, "".concat(prefixCls, "-sticky-shadow-no-transition"), !tableStore.tableColumnResizeTransition), (0, _defineProperty2["default"])(_classNames, "".concat(prefixCls, "-fixed-left"), children && position === 'left'), (0, _defineProperty2["default"])(_classNames, "".concat(prefixCls, "-fixed-right"), children && position === 'right'), (0, _defineProperty2["default"])(_classNames, "".concat(prefixCls, "-sticky-left"), position === 'left' && tableStore.stickyLeft), (0, _defineProperty2["default"])(_classNames, "".concat(prefixCls, "-sticky-right"), position === 'right' && tableStore.stickyRight), _classNames));
  var style = {};

  if (!children) {
    var scrollBarWidth = (0, _measureScrollbar["default"])();

    if (position === 'left') {
      style.left = (0, _UnitConvertor.pxToRem)(columnGroups.leftLeafColumnsWidth - 1, true);
    } else if (position === 'right') {
      style.right = (0, _UnitConvertor.pxToRem)(columnGroups.rightLeafColumnsWidth + (tableStore.overflowY ? scrollBarWidth : 0), true);
    }

    style.bottom = (0, _UnitConvertor.pxToRem)(scrollBarWidth, true);
  }

  return /*#__PURE__*/_react["default"].createElement("div", {
    className: classString,
    style: style
  }, children);
};

StickyShadow.displayName = 'StickyShadow';

var _default = (0, _mobxReactLite.observer)(StickyShadow);

exports["default"] = _default;
//# sourceMappingURL=StickyShadow.js.map
