var _excluded = ["children", "onClose", "title", "variant"];
var _VARIANT_ICON_MAP;
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
import React from 'react';
import { IconInfo, IconError, IconCheckCircle, IconWarning } from '@defencedigital/icon-library';
import { ALERT_VARIANT } from './constants';
import { useOpenClose } from '../../hooks';
import { StyledAlert } from './partials/StyledAlert';
import { StyledIcon } from './partials/StyledIcon';
import { StyledContent } from './partials/StyledContent';
import { StyledTitle } from './partials/StyledTitle';
import { StyledDescription } from './partials/StyledDescription';
import { StyledFooter } from './partials/StyledFooter';
import { StyledCloseButton } from './partials/StyledCloseButton';
import { useExternalId } from '../../hooks/useExternalId';
var VARIANT_ICON_MAP = (_VARIANT_ICON_MAP = {}, _defineProperty(_VARIANT_ICON_MAP, ALERT_VARIANT.DANGER, /*#__PURE__*/React.createElement(IconError, null)), _defineProperty(_VARIANT_ICON_MAP, ALERT_VARIANT.INFO, /*#__PURE__*/React.createElement(IconInfo, null)), _defineProperty(_VARIANT_ICON_MAP, ALERT_VARIANT.SUCCESS, /*#__PURE__*/React.createElement(IconCheckCircle, null)), _defineProperty(_VARIANT_ICON_MAP, ALERT_VARIANT.WARNING, /*#__PURE__*/React.createElement(IconWarning, null)), _VARIANT_ICON_MAP);
export var Alert = function Alert(_ref) {
  var children = _ref.children,
    onClose = _ref.onClose,
    title = _ref.title,
    _ref$variant = _ref.variant,
    variant = _ref$variant === void 0 ? ALERT_VARIANT.INFO : _ref$variant,
    rest = _objectWithoutProperties(_ref, _excluded);
  var _useOpenClose = useOpenClose(true, onClose),
    open = _useOpenClose.open,
    handleOnClose = _useOpenClose.handleOnClose;
  var titleId = useExternalId('alert-title');
  var descriptionId = useExternalId('alert-description');
  if (!open) {
    return null;
  }
  return /*#__PURE__*/React.createElement(StyledAlert, _extends({
    $variant: variant,
    "aria-describedby": descriptionId,
    "aria-labelledby": title ? titleId : undefined,
    role: "alert"
  }, rest), /*#__PURE__*/React.createElement(StyledIcon, {
    $variant: variant,
    "aria-hidden": "true"
  }, VARIANT_ICON_MAP[variant]), /*#__PURE__*/React.createElement(StyledContent, null, title && /*#__PURE__*/React.createElement(StyledTitle, {
    $variant: variant,
    id: titleId
  }, title), /*#__PURE__*/React.createElement(StyledDescription, {
    id: descriptionId
  }, children), /*#__PURE__*/React.createElement(StyledFooter, null, /*#__PURE__*/React.createElement(StyledCloseButton, {
    onClick: handleOnClose
  }, "Dismiss"))));
};