"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;

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

var _propTypes = _interopRequireDefault(require("prop-types"));

var _classnames = _interopRequireDefault(require("classnames"));

var _Button = _interopRequireDefault(require("../Button"));

var _reactOuiIcons = _interopRequireDefault(require("react-oui-icons"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

function _extends() { _extends = Object.assign || 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; }

var Card = function Card(_ref) {
  var children = _ref.children,
      className = _ref.className,
      onClose = _ref.onClose,
      _ref$shadow = _ref.shadow,
      shadow = _ref$shadow === void 0 ? false : _ref$shadow,
      testSection = _ref.testSection,
      title = _ref.title,
      props = _objectWithoutProperties(_ref, ["children", "className", "onClose", "shadow", "testSection", "title"]);

  var closer = _react["default"].createElement(_Button["default"], {
    style: "unstyled",
    onClick: onClose,
    testSection: "".concat(testSection, "-close")
  }, _react["default"].createElement(_reactOuiIcons["default"], {
    name: "close"
  }));

  var classes = (0, _classnames["default"])({
    "push--bottom border--all": true,
    "oui-shadow--light": shadow
  }, className);
  return _react["default"].createElement("div", _extends({
    "data-oui-component": true,
    className: classes
  }, props), title && _react["default"].createElement("div", {
    className: "flex border--bottom background--faint soft soft-half--ends"
  }, _react["default"].createElement("h4", {
    className: "flex--1",
    "data-test-section": "".concat(testSection, "-title")
  }, title), _react["default"].createElement("div", null, onClose && closer)), _react["default"].createElement("div", {
    className: "soft",
    "data-test-section": "".concat(testSection, "-body")
  }, children));
};

Card.propTypes = {
  /** Elements that appears within the component */
  children: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].node]).isRequired,

  /** CSS class names. */
  className: _propTypes["default"].string,

  /** method to invoke when a close element is clicked */
  onClose: _propTypes["default"].func,

  /** Display a subtle shadow around card. */
  shadow: _propTypes["default"].bool,

  /** For automated testing only. */
  testSection: _propTypes["default"].string,

  /** What is the card title */
  title: _propTypes["default"].string.isRequired
};
var _default = Card;
exports["default"] = _default;