"use strict";

exports.__esModule = true;
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _classnames = _interopRequireDefault(require("classnames"));
var _meetReactComponentOne = require("@alifd/meet-react-component-one");
var _icon = _interopRequireDefault(require("../icon"));
var _utils = require("../utils");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
var CreateChildren = function (children, classes, prefix, size) {
  var count = _react.Children.count(children);
  return _react.Children.map(children, function (child, index) {
    var _classNames;
    if ((0, _utils.isNil)(child) || (0, _utils.isBoolean)(child)) {
      return null;
    }
    var key = child.key || "mt-tag-" + index;
    if ((0, _utils.isNumber)(child) || (0, _utils.isString)(child)) {
      return /*#__PURE__*/(0, _react.createElement)(_meetReactComponentOne.Text, {
        key: key,
        className: classes.textCls
      }, child);
    }
    if (!(0, _react.isValidElement)(child)) {
      return child;
    }
    switch (true) {
      case child.type === _meetReactComponentOne.Text:
        return (0, _react.cloneElement)(child, {
          key: key,
          className: classes.textCls,
          style: child.props.style || {}
        });
      case child.type === _icon.default:
        return (0, _react.cloneElement)(child, {
          key: key,
          className: (0, _classnames.default)(classes.iconCls, (_classNames = {}, _classNames[prefix + "tag-icon--" + size + "-first"] = index === 0, _classNames[prefix + "tag-icon--" + size + "-last"] = index === count - 1, _classNames)),
          style: child.props.style || {}
        });
      default:
        return (0, _react.cloneElement)(child, {
          key: key
        });
    }
  });
};
var _default = CreateChildren;
exports.default = _default;