import _pt from "prop-types";

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

import Icon from 'react-oui-icons';
import classNames from 'classnames';
import React from 'react';
import Button from '../Button';
import { getAssistiveTextFromColorClass } from '../../utils/accessibility';

var renderDismissButton = function renderDismissButton(testSection) {
  return React.createElement("div", {
    className: "oui-attention__close"
  }, React.createElement(Button, {
    style: "plain",
    size: "small",
    ariaLabel: "Close alert",
    testSection: "".concat(testSection, "-dismiss")
  }, React.createElement(Icon, {
    name: "close",
    size: "small"
  })));
};

var Attention = function Attention(_ref) {
  var _ref$alignment = _ref.alignment,
      alignment = _ref$alignment === void 0 ? 'left' : _ref$alignment,
      children = _ref.children,
      isDismissible = _ref.isDismissible,
      testSection = _ref.testSection,
      _ref$type = _ref.type,
      type = _ref$type === void 0 ? 'brand' : _ref$type;
  var colorClassName = "oui-attention--".concat(type);
  var alignmentClassName = "oui-text--".concat(alignment);
  var attentionAriaLabel = getAssistiveTextFromColorClass(type);
  var alignClass = "oui-attention ".concat(colorClassName, " ").concat(alignmentClassName).trim();
  var classes = classNames(_defineProperty({}, "".concat(alignClass), true));
  var dismissBtn = isDismissible ? renderDismissButton(testSection) : null;
  return React.createElement("div", {
    "data-oui-component": true,
    className: classes,
    "data-test-section": testSection,
    "aria-label": attentionAriaLabel,
    role: "alert"
  }, children, dismissBtn);
};

Attention.propTypes = {
  alignment: _pt.oneOf(['left', 'center']),
  children: _pt.any,
  isDismissible: _pt.bool,
  testSection: _pt.string,
  type: _pt.oneOf(['bad-news', 'brand', 'good-news', 'warning'])
};
export default Attention;