import _extends from "@babel/runtime/helpers/extends";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
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) { _defineProperty(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; }

import { IconInfoBadgedSmallFilled } from '@teamleader/ui-icons';
import React from 'react';
import Box from '../box';
import Icon from '../icon';
import Tooltip from '../tooltip';
import { TextBodyCompact, TextDisplay, TextSmall } from '../typography';
var TooltippedIcon = Tooltip(Icon);

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 = _objectWithoutProperties(_ref, _excluded);

  var childProps = {
    inverse: inverse,
    marginTop: 1,
    size: size
  };
  var Element = size === 'large' ? TextDisplay : TextBodyCompact;
  return /*#__PURE__*/React.createElement(Box, _extends({
    display: "block",
    element: "label",
    marginBottom: 3
  }, others), React.Children.map(children, function (child) {
    return typeof child !== 'string' && /*#__PURE__*/React.isValidElement(child) ? /*#__PURE__*/React.cloneElement(child, _objectSpread(_objectSpread({}, childProps), child.props)) : /*#__PURE__*/React.createElement(Box, {
      display: "flex",
      alignItems: "center"
    }, /*#__PURE__*/React.createElement(Element, {
      color: inverse ? 'neutral' : 'teal',
      tint: inverse ? 'lightest' : 'darkest',
      element: "span"
    }, child), required && /*#__PURE__*/React.createElement(TextSmall, {
      color: "ruby",
      element: "span",
      marginLeft: 1,
      tint: "dark"
    }, "*"), tooltip && /*#__PURE__*/React.createElement(TooltippedIcon, _extends({
      tooltip: /*#__PURE__*/React.createElement(TextSmall, null, tooltip),
      tooltipSize: "small",
      color: inverse ? 'neutral' : 'teal',
      tint: inverse ? 'lightest' : 'darkest',
      marginLeft: 1
    }, tooltipProps), /*#__PURE__*/React.createElement(IconInfoBadgedSmallFilled, null)));
  }));
};

export default Label;