"use strict";

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

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

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

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

var _Attention = _interopRequireDefault(require("../Attention"));

var _ButtonRow = _interopRequireDefault(require("../ButtonRow"));

var _CloseButton = _interopRequireDefault(require("../CloseButton"));

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; }

/**
 *
 * @param {Object} props - Properties passed to component
 * @returns {ReactElement}
 */
var Sheet = function Sheet(_ref) {
  var centerHeader = _ref.centerHeader,
      children = _ref.children,
      className = _ref.className,
      footerButtonList = _ref.footerButtonList,
      hasCloseButton = _ref.hasCloseButton,
      hasFooter = _ref.hasFooter,
      hasRequiredFieldsIndicator = _ref.hasRequiredFieldsIndicator,
      onClose = _ref.onClose,
      subtitle = _ref.subtitle,
      testSection = _ref.testSection,
      title = _ref.title,
      warningContent = _ref.warningContent,
      warningTestSection = _ref.warningTestSection,
      props = _objectWithoutProperties(_ref, ["centerHeader", "children", "className", "footerButtonList", "hasCloseButton", "hasFooter", "hasRequiredFieldsIndicator", "onClose", "subtitle", "testSection", "title", "warningContent", "warningTestSection"]);

  var subtitleContent;

  if (subtitle && typeof subtitle === "string") {
    subtitleContent = _react["default"].createElement("p", {
      className: "push--top flush--bottom"
    }, subtitle);
  } else {
    subtitleContent = _react["default"].createElement("div", {
      className: "push--top flush--bottom"
    }, subtitle);
  }

  var headerClasses = (0, _classnames["default"])({
    "oui-sheet__header": true,
    "text--center": centerHeader
  });
  return _react["default"].createElement("div", _extends({
    className: (0, _classnames["default"])("oui-sheet__wrapper", className)
  }, props), _react["default"].createElement("div", {
    className: "oui-sheet__overlay"
  }), _react["default"].createElement("div", {
    "data-oui-component": true,
    className: "oui-sheet overflow-y--auto",
    "data-test-section": testSection
  }, hasCloseButton && _react["default"].createElement(_CloseButton["default"], {
    onClick: onClose,
    size: "large"
  }), warningContent && _react["default"].createElement("div", {
    className: "oui-sheet__warning"
  }, _react["default"].createElement(_Attention["default"], {
    alignment: "center",
    type: "warning",
    testSection: warningTestSection
  }, warningContent)), _react["default"].createElement("header", {
    className: headerClasses
  }, _react["default"].createElement("h2", {
    className: "flush--bottom"
  }, title), subtitleContent), _react["default"].createElement("div", {
    className: "oui-sheet__body"
  }, children), hasFooter && _react["default"].createElement("footer", {
    className: "oui-sheet__footer"
  }, _react["default"].createElement("div", {
    className: "flex flex-align--center"
  }, hasRequiredFieldsIndicator && _react["default"].createElement("div", {
    className: "oui-sheet__required-indicator cursor--default color--red"
  }, _react["default"].createElement("span", null, "* Required field")), _react["default"].createElement("div", {
    className: "flex--1"
  }, _react["default"].createElement(_ButtonRow["default"], {
    rightGroup: footerButtonList
  }))))));
};

Sheet.propTypes = {
  /**
   *  Used to determine if the title & subtitle of the sheet should be centered.
   */
  centerHeader: _propTypes["default"].bool,

  /**
   *  The body of the sheet to request information and data from the user.
   */
  children: _propTypes["default"].node.isRequired,

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

  /**
   * Array of buttons used in the footer of the sheet.
   */
  footerButtonList: _propTypes["default"].array,

  /**
   *  Used to determine if the sheet should have a close button.
   */
  hasCloseButton: _propTypes["default"].bool,

  /**
   *  Determines if the sheet should have a footer.
   */
  hasFooter: _propTypes["default"].bool,

  /**
   *  Determines if the sheet should have a message in the footer
   *  indicating required fields are marked with an asterisk (*).
   */
  hasRequiredFieldsIndicator: _propTypes["default"].bool,

  /**
   * Function to perform when the sheet is closed.
   */
  onClose: _propTypes["default"].func,

  /**
   * A subtitle for the sheet.
   */
  subtitle: _propTypes["default"].oneOfType([_propTypes["default"].node, _propTypes["default"].string]),

  /**
   * Identifier used to create data-test-section attributes for testing.
   */
  testSection: _propTypes["default"].string,

  /**
   * Main title of the sheet.
   */
  title: _propTypes["default"].string.isRequired,

  /**
   * Content of the warning Attention bar.
   */
  warningContent: _propTypes["default"].string,

  /**
   * Identifier used to create data-test-section
   * attribute for the Attention bar.
   */
  warningTestSection: _propTypes["default"].string
};
Sheet.defaultProps = {
  centerHeader: false,
  footerButtonList: [],
  hasCloseButton: true,
  hasFooter: true,
  hasRequiredFieldsIndicator: false,
  onClose: function onClose() {
    return null;
  },
  subtitle: "",
  testSection: "",
  warningTestSection: ""
};
var _default = Sheet;
exports["default"] = _default;