import React, { cloneElement, forwardRef, memo, useCallback, useImperativeHandle, useMemo, useRef } from 'react';
import isNil from 'lodash/isNil';
var List = /*#__PURE__*/forwardRef(function (_ref, ref) {
  var data = _ref.data,
      prefixCls = _ref.prefixCls,
      children = _ref.children,
      height = _ref.height,
      itemKey = _ref.itemKey;
  var containerRef = useRef(null);
  var innerStyle = useMemo(function () {
    var style = {
      display: 'flex',
      flexDirection: 'column'
    };

    if (height) {
      style.height = height;
      style.overflow = 'hidden auto';
    }

    return style;
  }, [height]);
  var getKey = useCallback(function (item) {
    if (typeof itemKey === 'function') {
      return itemKey(item);
    }

    return isNil(itemKey) ? undefined : item[itemKey];
  }, [itemKey]);
  var renderChild = useCallback(function (child) {
    return /*#__PURE__*/cloneElement(children(child), {
      key: getKey(child)
    });
  }, [children, getKey]);
  var scrollTo = useCallback(function (scroll) {
    var current = containerRef.current;

    if (current) {
      if (current.scrollTo) {
        current.scrollTo(0, scroll);
      } else {
        current.scrollTop = scroll;
      }
    }
  }, [containerRef]);
  useImperativeHandle(ref, function () {
    return {
      scrollTo: scrollTo
    };
  }, [scrollTo]);
  return /*#__PURE__*/React.createElement("div", {
    className: "".concat(prefixCls, "-holder")
  }, /*#__PURE__*/React.createElement("div", {
    className: "".concat(prefixCls, "-holder-inner"),
    style: innerStyle,
    ref: containerRef
  }, data.map(renderChild)));
});
export default /*#__PURE__*/memo(List);
//# sourceMappingURL=List.js.map
