"use strict";

var _typeof = require("@babel/runtime-corejs3/helpers/typeof");
var _WeakMap = require("@babel/runtime-corejs3/core-js-stable/weak-map");
var _Object$getOwnPropertyDescriptor = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor");
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.TopBlank = exports.BottomBlank = void 0;
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/slicedToArray"));
var _react = _interopRequireWildcard(require("react"));
var _classnames = _interopRequireDefault(require("classnames"));
var _styles = require("./styles");
function _interopRequireWildcard(e, t) { if ("function" == typeof _WeakMap) var r = new _WeakMap(), n = new _WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && _Object$getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
var TopBlankComponent = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
  var heightFromProps = _ref.height;
  (0, _react.useEffect)(function () {
    setHeight(heightFromProps);
  }, [heightFromProps]);
  var _useState = (0, _react.useState)(heightFromProps),
    _useState2 = (0, _slicedToArray2.default)(_useState, 2),
    height = _useState2[0],
    setHeight = _useState2[1];
  (0, _react.useImperativeHandle)(ref, function () {
    return {
      updateHeight: function updateHeight(newHeight) {
        if (height !== newHeight) {
          setHeight(newHeight);
        }
      }
    };
  }, [height]);
  return /*#__PURE__*/_react.default.createElement("div", {
    key: "top-blank",
    className: (0, _classnames.default)(_styles.Classes.virtualBlank, 'bottom'),
    style: {
      height: height
    }
  });
});
TopBlankComponent.displayName = 'TopBlank';
var BottomBlankComponent = /*#__PURE__*/(0, _react.forwardRef)(function (_ref2, ref) {
  var heightFromProps = _ref2.height;
  var _useState3 = (0, _react.useState)(heightFromProps),
    _useState4 = (0, _slicedToArray2.default)(_useState3, 2),
    height = _useState4[0],
    setHeight = _useState4[1];
  (0, _react.useEffect)(function () {
    setHeight(heightFromProps);
  }, [heightFromProps]);
  (0, _react.useImperativeHandle)(ref, function () {
    return {
      updateHeight: function updateHeight(newHeight) {
        if (height !== newHeight) {
          setHeight(newHeight);
        }
      }
    };
  }, [height]);
  if (height <= 0) {
    return null;
  }
  return /*#__PURE__*/_react.default.createElement("div", {
    key: "bottom-blank",
    className: (0, _classnames.default)(_styles.Classes.virtualBlank, 'bottom'),
    style: {
      height: height
    }
  });
});
BottomBlankComponent.displayName = 'BottomBlank';
// 使用 memo 优化，只有当 height 或 className 改变时才重新渲染
var TopBlank = exports.TopBlank = /*#__PURE__*/(0, _react.memo)(TopBlankComponent, function (prevProps, nextProps) {
  return prevProps.height === nextProps.height;
});
var BottomBlank = exports.BottomBlank = /*#__PURE__*/(0, _react.memo)(BottomBlankComponent, function (prevProps, nextProps) {
  return prevProps.height === nextProps.height;
});