'use strict';

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
var React = require('react');
var classnames = require('classnames');
var Help = require('@bigbinary/neeto-icons/Help');
var jsxRuntime = require('react/jsx-runtime');
var Button = require('./Button.js');
var Popover = require('./Popover.js');
var Tooltip = require('./Tooltip.js');
var Typography = require('./Typography.js');
require('@babel/runtime/helpers/slicedToArray');
require('@tippyjs/react');
require('tippy.js');
require('react-router-dom');
require('@bigbinary/neeto-hotkeys');
require('./overlayManager.js');
require('@babel/runtime/helpers/classCallCheck');
require('@babel/runtime/helpers/createClass');
require('@bigbinary/neeto-cist');
require('qs');
require('ramda');
require('./index-BgzkP01c.js');
require('i18next');
require('./Spinner.js');
require('@babel/runtime/helpers/toConsumableArray');
require('dayjs');
require('dayjs/plugin/localeData');
require('dayjs/plugin/utc');
require('dayjs/plugin/weekday');
require('dayjs/plugin/weekOfYear');
require('./usePrefersReducedMotion-D2Ck84HM.js');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

var _defineProperty__default = /*#__PURE__*/_interopDefault(_defineProperty);
var _objectWithoutProperties__default = /*#__PURE__*/_interopDefault(_objectWithoutProperties);
var classnames__default = /*#__PURE__*/_interopDefault(classnames);
var Help__default = /*#__PURE__*/_interopDefault(Help);

var _excluded$2 = ["onClick", "className", "icon"];
function ownKeys$2(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread$2(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$2(Object(t), true).forEach(function (r) { _defineProperty__default.default(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$2(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var HelpIcon = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
  var onClick = _ref.onClick,
    className = _ref.className,
    icon = _ref.icon,
    otherProps = _objectWithoutProperties__default.default(_ref, _excluded$2);
  var HelpIcon = icon || Help__default.default;
  return /*#__PURE__*/jsxRuntime.jsx("span", {
    onClick: onClick,
    ref: ref,
    className: classnames__default.default("neeto-ui-label__help-icon-wrap", _defineProperty__default.default({}, className, className)),
    children: /*#__PURE__*/jsxRuntime.jsx(HelpIcon, _objectSpread$2({
      size: 20
    }, otherProps))
  });
});
HelpIcon.displayName = "HelpIcon";

var _excluded$1 = ["tooltipProps", "popoverProps"],
  _excluded2 = ["title", "description", "helpLinkProps"];
function ownKeys$1(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread$1(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$1(Object(t), true).forEach(function (r) { _defineProperty__default.default(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$1(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var HelpContent = function HelpContent(_ref) {
  var helpIconProps = _ref.helpIconProps;
  var popoverReferenceElement = React.useRef();
  var _ref2 = helpIconProps || {},
    tooltipProps = _ref2.tooltipProps,
    popoverProps = _ref2.popoverProps,
    otherHelpIconProps = _objectWithoutProperties__default.default(_ref2, _excluded$1);
  if (tooltipProps) {
    return /*#__PURE__*/jsxRuntime.jsx(Tooltip, _objectSpread$1(_objectSpread$1({}, tooltipProps), {}, {
      children: /*#__PURE__*/jsxRuntime.jsx(HelpIcon, _objectSpread$1({}, otherHelpIconProps))
    }));
  }
  if (popoverProps) {
    var title = popoverProps.title,
      description = popoverProps.description,
      helpLinkProps = popoverProps.helpLinkProps,
      otherPopoverProps = _objectWithoutProperties__default.default(popoverProps, _excluded2);
    return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
      children: [/*#__PURE__*/jsxRuntime.jsx(HelpIcon, _objectSpread$1(_objectSpread$1({}, otherHelpIconProps), {}, {
        ref: popoverReferenceElement
      })), /*#__PURE__*/jsxRuntime.jsx(Popover, _objectSpread$1(_objectSpread$1({
        reference: popoverReferenceElement
      }, otherPopoverProps), {}, {
        children: /*#__PURE__*/jsxRuntime.jsxs("div", {
          className: "neeto-ui-flex neeto-ui-flex-col",
          children: [title && /*#__PURE__*/jsxRuntime.jsx(Popover.Title, {
            "data-testid": "help-popover-title",
            children: title
          }), typeof description === "string" ? /*#__PURE__*/jsxRuntime.jsx(Typography, {
            "data-testid": "help-popover-description",
            lineHeight: "normal",
            style: "body2",
            weight: "normal",
            children: description
          }) : description, helpLinkProps && /*#__PURE__*/jsxRuntime.jsx(Button, _objectSpread$1(_objectSpread$1({
            className: "neeto-ui-mt-3",
            "data-testid": "help-popover-link-button",
            size: "small"
          }, helpLinkProps), {}, {
            style: "link",
            target: "_blank"
          }))]
        })
      }))]
    });
  }
  return /*#__PURE__*/jsxRuntime.jsx(HelpIcon, _objectSpread$1({}, otherHelpIconProps));
};

var _excluded = ["children", "className", "required", "helpIconProps"];
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), true).forEach(function (r) { _defineProperty__default.default(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var Label = function Label(_ref) {
  var children = _ref.children,
    _ref$className = _ref.className,
    className = _ref$className === void 0 ? "" : _ref$className,
    _ref$required = _ref.required,
    required = _ref$required === void 0 ? false : _ref$required,
    _ref$helpIconProps = _ref.helpIconProps,
    helpIconProps = _ref$helpIconProps === void 0 ? null : _ref$helpIconProps,
    props = _objectWithoutProperties__default.default(_ref, _excluded);
  return /*#__PURE__*/jsxRuntime.jsxs("label", _objectSpread(_objectSpread({
    className: classnames__default.default("neeto-ui-label neeto-ui-flex neeto-ui-items-center", className)
  }, props), {}, {
    children: [children, required && /*#__PURE__*/jsxRuntime.jsx("span", {
      "aria-hidden": true,
      children: "*"
    }), helpIconProps && /*#__PURE__*/jsxRuntime.jsx(HelpContent, {
      helpIconProps: helpIconProps
    })]
  }));
};

module.exports = Label;
//# sourceMappingURL=Label.js.map
