"use strict";

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

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

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

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

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

var _Box = require("../Box");

var _FormControl = require("../FormControl");

var _Text = require("../Text");

var _styles = _interopRequireDefault(require("./styles"));

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

var __jsx = _react["default"].createElement;

var RequiredIndicator = function RequiredIndicator(props) {
  var _useFormLabelStyle = (0, _styles["default"])({}),
      requiredIndicatorStyleProps = _useFormLabelStyle.requiredIndicator;

  return __jsx(_Box.Box, (0, _extends2["default"])({
    as: "span",
    "aria-hidden": "true"
  }, requiredIndicatorStyleProps, props), "*");
};

exports.RequiredIndicator = RequiredIndicator;
var FormLabel = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
  var children = _ref.children,
      props = (0, _objectWithoutProperties2["default"])(_ref, ["children"]);
  var formControl = (0, _FormControl.useFormControl)(props);

  var _useFormLabelStyle2 = (0, _styles["default"])({
    isDisabled: formControl.isDisabled
  }),
      formLabelStyleProps = _useFormLabelStyle2.root;

  return __jsx(_Text.Text, (0, _extends2["default"])({
    ref: ref,
    as: "label"
  }, formLabelStyleProps, props), children, formControl.isRequired && __jsx(RequiredIndicator, null));
});
exports.FormLabel = FormLabel;
//# sourceMappingURL=FormLabel.js.map