"use strict";

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

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

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

var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));

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

var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));

var _bem = require("@zarm-design/bem");

var _includes = _interopRequireDefault(require("lodash/includes"));

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

var _configProvider = require("../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 = (0, _objectWithoutProperties2.default)(props, ["className", "shape", "animated"]);

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

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

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

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

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

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

  var _shape = shape && (0, _includes.default)(SKELETONLINESHAPE, shape) ? shape : undefined;

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


exports.SkeletonTitle = SkeletonTitle;

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 = (0, _objectWithoutProperties2.default)(props, ["className", "shape", "lineCount", "animated"]);

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

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

  var _shape = shape && (0, _includes.default)(SKELETONLINESHAPE, shape) ? shape : undefined;

  return /*#__PURE__*/React.createElement("div", (0, _extends2.default)({
    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);
};

exports.SkeletonParagraph = SkeletonParagraph;
var _default = Skeleton;
exports.default = _default;