"use strict";

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

var _react = _interopRequireDefault(require("react"));

var _one = require("remax/one");

var _indexModule = _interopRequireDefault(require("./index.module.less"));

var _classnames = _interopRequireDefault(require("classnames"));

var _rpxToPx = _interopRequireDefault(require("../rpx-to-px"));

require("array-flat-polyfill");

var _excluded = ["style", "children", "size", "className", "margin", "padding", "vertical", "flexWrap", "justify", "alignSelf", "alignItems", "flex", "ignoreNum"];

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

var _default = function _default(_ref) {
  var _flat, _flat$map, _flat$map$flat, _flat$map$flat$filter, _filterChildren$map;

  var style = _ref.style,
      _ref$children = _ref.children,
      children = _ref$children === void 0 ? [/*#__PURE__*/_react.default.createElement(_one.View, null), /*#__PURE__*/_react.default.createElement(_one.View, null)] : _ref$children,
      size = _ref.size,
      className = _ref.className,
      margin = _ref.margin,
      padding = _ref.padding,
      vertical = _ref.vertical,
      flexWrap = _ref.flexWrap,
      justify = _ref.justify,
      alignSelf = _ref.alignSelf,
      alignItems = _ref.alignItems,
      flex = _ref.flex,
      ignoreNum = _ref.ignoreNum,
      props = _objectWithoutProperties(_ref, _excluded);

  var filterChildren = (_flat = (children instanceof Array ? children : [children]).flat(3)) === null || _flat === void 0 ? void 0 : (_flat$map = _flat.map(function (i) {
    var _i$type;

    return (i === null || i === void 0 ? void 0 : (_i$type = i.type) === null || _i$type === void 0 ? void 0 : _i$type.toString()) === 'Symbol(react.fragment)' ? i.props.children : i;
  })) === null || _flat$map === void 0 ? void 0 : (_flat$map$flat = _flat$map.flat(3)) === null || _flat$map$flat === void 0 ? void 0 : (_flat$map$flat$filter = _flat$map$flat.filter) === null || _flat$map$flat$filter === void 0 ? void 0 : _flat$map$flat$filter.call(_flat$map$flat, function (i) {
    return ![undefined, true, false].includes(i);
  });
  return /*#__PURE__*/_react.default.createElement(_one.View, _objectSpread({
    style: _objectSpread({
      lineHeight: vertical ? 1 : undefined,
      flex: flex,
      justifyContent: justify,
      margin: margin,
      padding: padding,
      alignSelf: alignSelf,
      alignItems: alignItems,
      flexWrap: flexWrap
    }, style),
    className: (0, _classnames.default)(_indexModule.default.space, className, _defineProperty({}, _indexModule.default.vertical, vertical))
  }, props), filterChildren === null || filterChildren === void 0 ? void 0 : (_filterChildren$map = filterChildren.map) === null || _filterChildren$map === void 0 ? void 0 : _filterChildren$map.call(filterChildren, function (item, index) {
    item = /*#__PURE__*/_react.default.isValidElement(item) ? item : /*#__PURE__*/_react.default.createElement(_one.View, {
      key: index
    }, item);
    var props = item.props;
    return /*#__PURE__*/_react.default.cloneElement(item, _objectSpread(_objectSpread({}, props), {}, {
      key: index,
      style: _objectSpread(_defineProperty({}, vertical ? 'marginBottom' : 'marginRight', index + 1 === (filterChildren === null || filterChildren === void 0 ? void 0 : filterChildren.length) || ignoreNum && index && (index + 1) % ignoreNum === 0 ? undefined : typeof size === 'number' ? (0, _rpxToPx.default)(size) : size === null || size === void 0 ? void 0 : size.toUpperCase()), props.style)
    }));
  }));
};

exports.default = _default;