"use strict";

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

Object.defineProperty(exports, "__esModule", {
  value: true
});
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 _react = _interopRequireDefault(require("react"));

var _box = _interopRequireDefault(require("../box"));

var _isComponentOfType = _interopRequireDefault(require("../utils/is-component-of-type"));

var _isReactElement = _interopRequireDefault(require("../utils/is-react-element"));

var _Label = _interopRequireDefault(require("./Label"));

var _Value = _interopRequireDefault(require("./Value"));

var _excluded = ["alignValue", "children", "inline"];

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); 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 = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }

var LabelValuePair = function LabelValuePair(_ref) {
  var _ref$alignValue = _ref.alignValue,
      alignValue = _ref$alignValue === void 0 ? 'left' : _ref$alignValue,
      children = _ref.children,
      _ref$inline = _ref.inline,
      inline = _ref$inline === void 0 ? true : _ref$inline,
      others = (0, _objectWithoutProperties2.default)(_ref, _excluded);
  return /*#__PURE__*/_react.default.createElement(_box.default, (0, _extends2.default)({}, others, {
    display: "flex",
    flexDirection: inline ? 'row' : 'column',
    marginBottom: inline ? 1 : 3
  }), _react.default.Children.map(children, function (child) {
    if (!(0, _isReactElement.default)(child)) {
      return null;
    }

    if ((0, _isComponentOfType.default)(_Label.default, child) && /*#__PURE__*/_react.default.isValidElement(child)) {
      return /*#__PURE__*/_react.default.cloneElement(child, _objectSpread({
        inline: inline
      }, child.props));
    }

    if ((0, _isComponentOfType.default)(_Value.default, child) && /*#__PURE__*/_react.default.isValidElement(child)) {
      return /*#__PURE__*/_react.default.cloneElement(child, _objectSpread({
        justifyContent: alignValue === 'left' ? 'flex-start' : 'flex-end',
        paddingVertical: inline ? 1 : 0,
        textAlign: alignValue
      }, child.props));
    }
  }));
};

LabelValuePair.Label = _Label.default;
LabelValuePair.Label.displayName = 'LabelValuePair.Label';
LabelValuePair.Value = _Value.default;
LabelValuePair.Value.displayName = 'LabelValuePair.Value';
var _default = LabelValuePair;
exports.default = _default;