import _extends from "@babel/runtime/helpers/extends";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
import { createBEM } from '@zarm-design/bem';
import includes from 'lodash/includes';
import * as React from 'react';
import { ConfigContext } from '../config-provider';
// SkeletonTitle和SkeletonParagraph的shape属性值集合
var SKELETONLINESHAPE = ['radius', 'rect'];

var Skeleton = function Skeleton(props) {
  var _ref;

  var className = props.className,
      shape = props.shape,
      animated = props.animated,
      restProps = _objectWithoutProperties(props, ["className", "shape", "animated"]);

  var _React$useContext = React.useContext(ConfigContext),
      prefixCls = _React$useContext.prefixCls;

  var bem = createBEM('skeleton', {
    prefixCls: prefixCls
  });
  var cls = bem([(_ref = {}, _defineProperty(_ref, "".concat(shape), !!shape), _defineProperty(_ref, "animated", animated), _ref), className]);
  return /*#__PURE__*/React.createElement("div", _extends({
    className: cls
  }, restProps));
};

Skeleton.displayName = 'skeleton';
Skeleton.defaultProps = {
  shape: 'radius'
}; // SkeletonTitle

var SkeletonTitle = function SkeletonTitle(props) {
  var className = props.className,
      shape = props.shape,
      restProps = _objectWithoutProperties(props, ["className", "shape"]);

  var _React$useContext2 = React.useContext(ConfigContext),
      prefixCls = _React$useContext2.prefixCls;

  var bem = createBEM('skeleton', {
    prefixCls: prefixCls
  });
  var cls = bem('title', [className]);

  var _shape = shape && includes(SKELETONLINESHAPE, shape) ? shape : undefined;

  return /*#__PURE__*/React.createElement(Skeleton, _extends({
    shape: _shape,
    className: cls
  }, restProps));
}; // SkeletonParagraph


var SkeletonParagraph = function SkeletonParagraph(props) {
  var className = props.className,
      shape = props.shape,
      _props$lineCount = props.lineCount,
      lineCount = _props$lineCount === void 0 ? 3 : _props$lineCount,
      animated = props.animated,
      restProps = _objectWithoutProperties(props, ["className", "shape", "lineCount", "animated"]);

  var _React$useContext3 = React.useContext(ConfigContext),
      prefixCls = _React$useContext3.prefixCls;

  var bem = createBEM('skeleton', {
    prefixCls: prefixCls
  });
  var cls = bem('paragraph', [className]);
  var lineCls = bem('line');

  var _shape = shape && includes(SKELETONLINESHAPE, shape) ? shape : undefined;

  return /*#__PURE__*/React.createElement("div", _extends({
    className: cls
  }, restProps), lineCount > 0 ? Array(lineCount).fill(1).map(function () {
    return /*#__PURE__*/React.createElement(Skeleton, {
      key: arguments.length <= 1 ? undefined : arguments[1],
      shape: _shape,
      animated: animated,
      className: lineCls
    });
  }) : null);
};

export default Skeleton;
export { SkeletonTitle, SkeletonParagraph };