"use strict";

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

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.AlertIcon = exports.AlertDescription = exports.AlertTitle = exports.Alert = void 0;

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

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

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

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

var _Heading = require("../Heading");

var _Icon = require("../Icon");

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

var _styles = _interopRequireWildcard(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 AlertContext = /*#__PURE__*/(0, _react.createContext)({});
/**
 * Alerts are used to communicate a state that affects a system, feature or page
 */

var Alert = function Alert(_ref) {
  var _ref$status = _ref.status,
      status = _ref$status === void 0 ? 'info' : _ref$status,
      _ref$variant = _ref.variant,
      variant = _ref$variant === void 0 ? 'left-accent' : _ref$variant,
      rest = (0, _objectWithoutProperties2["default"])(_ref, ["status", "variant"]);

  var _useAlertStyle = (0, _styles["default"])({
    variant: variant,
    status: status
  }),
      alertStyleProps = _useAlertStyle.root;

  var context = {
    status: status,
    variant: variant
  };
  return __jsx(AlertContext.Provider, {
    value: context
  }, __jsx(_Box.Box, (0, _extends2["default"])({
    role: "alert"
  }, alertStyleProps, rest)));
};

exports.Alert = Alert;

var AlertTitle = function AlertTitle(props) {
  return __jsx(_Heading.Heading, (0, _extends2["default"])({
    kind: "h6"
  }, props));
};

exports.AlertTitle = AlertTitle;

var AlertDescription = function AlertDescription(props) {
  return __jsx(_Text.Text, props);
};

exports.AlertDescription = AlertDescription;

var AlertIcon = function AlertIcon(props) {
  var _useContext = (0, _react.useContext)(AlertContext),
      status = _useContext.status,
      variant = _useContext.variant;

  var _useAlertStyle2 = (0, _styles["default"])({
    variant: variant,
    status: status
  }),
      statusProps = _useAlertStyle2.status;

  var iconStyleProps = (0, _styles.useAlertIconStyle)({
    variant: variant,
    color: props.color || status
  });
  return __jsx(_Box.Box, iconStyleProps, __jsx(_Icon.Icon, (0, _extends2["default"])({
    mr: 3,
    size: 5,
    name: statusProps.icon
  }, props)));
};

exports.AlertIcon = AlertIcon;
//# sourceMappingURL=Alert.js.map