function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

import React, { useContext, useRef } from 'react';
import cls from 'clsx';
import ConfigProviderContext from '../config-provider/ConfigProviderContext';
import { useInViewport } from '../hooks';
import { Skeleton } from '../skeleton';

var Lazyload = function Lazyload(props) {
  var _useContext = useContext(ConfigProviderContext),
      prefixCls = _useContext.prefixCls,
      createNamespace = _useContext.createNamespace;

  var _createNamespace = createNamespace('lazyload', prefixCls),
      bem = _createNamespace[0];

  var ref = useRef();
  var inViewPort = useInViewport(ref);
  var height = props.height,
      placeholder = props.placeholder,
      children = props.children,
      className = props.className,
      style = props.style;
  return inViewPort ? /*#__PURE__*/React.createElement(React.Fragment, null, children) : /*#__PURE__*/React.createElement("div", {
    ref: ref,
    className: cls(bem(), className),
    style: _extends({
      height: height
    }, style)
  }, placeholder);
};

Lazyload.defaultProps = {
  placeholder: /*#__PURE__*/React.createElement(Skeleton, {
    title: true
  })
};
export default Lazyload;