"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 _uiIcons = require("@teamleader/ui-icons");

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

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

var _icon = _interopRequireDefault(require("../icon"));

var _tooltip = _interopRequireDefault(require("../tooltip"));

var _typography = require("../typography");

var _excluded = ["children", "inverse", "required", "size", "tooltip", "tooltipProps"];

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 TooltippedIcon = (0, _tooltip.default)(_icon.default);

var Label = function Label(_ref) {
  var children = _ref.children,
      _ref$inverse = _ref.inverse,
      inverse = _ref$inverse === void 0 ? false : _ref$inverse,
      _ref$required = _ref.required,
      required = _ref$required === void 0 ? false : _ref$required,
      _ref$size = _ref.size,
      size = _ref$size === void 0 ? 'medium' : _ref$size,
      tooltip = _ref.tooltip,
      tooltipProps = _ref.tooltipProps,
      others = (0, _objectWithoutProperties2.default)(_ref, _excluded);
  var childProps = {
    inverse: inverse,
    marginTop: 1,
    size: size
  };
  var Element = size === 'large' ? _typography.TextDisplay : _typography.TextBodyCompact;
  return /*#__PURE__*/_react.default.createElement(_box.default, (0, _extends2.default)({
    display: "block",
    element: "label",
    marginBottom: 3
  }, others), _react.default.Children.map(children, function (child) {
    return typeof child !== 'string' && /*#__PURE__*/_react.default.isValidElement(child) ? /*#__PURE__*/_react.default.cloneElement(child, _objectSpread(_objectSpread({}, childProps), child.props)) : /*#__PURE__*/_react.default.createElement(_box.default, {
      display: "flex",
      alignItems: "center"
    }, /*#__PURE__*/_react.default.createElement(Element, {
      color: inverse ? 'neutral' : 'teal',
      tint: inverse ? 'lightest' : 'darkest',
      element: "span"
    }, child), required && /*#__PURE__*/_react.default.createElement(_typography.TextSmall, {
      color: "ruby",
      element: "span",
      marginLeft: 1,
      tint: "dark"
    }, "*"), tooltip && /*#__PURE__*/_react.default.createElement(TooltippedIcon, (0, _extends2.default)({
      tooltip: /*#__PURE__*/_react.default.createElement(_typography.TextSmall, null, tooltip),
      tooltipSize: "small",
      color: inverse ? 'neutral' : 'teal',
      tint: inverse ? 'lightest' : 'darkest',
      marginLeft: 1
    }, tooltipProps), /*#__PURE__*/_react.default.createElement(_uiIcons.IconInfoBadgedSmallFilled, null)));
  }));
};

var _default = Label;
exports.default = _default;