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

import PropTypes from "prop-types";
import React from "react";
import classNames from "classnames";
import Attention from "../Attention";
import ButtonRow from "../ButtonRow";
import CloseButton from "../CloseButton";
/**
 *
 * @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.createElement("p", {
      className: "push--top flush--bottom"
    }, subtitle);
  } else {
    subtitleContent = React.createElement("div", {
      className: "push--top flush--bottom"
    }, subtitle);
  }

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

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

  /**
   *  The body of the sheet to request information and data from the user.
   */
  children: PropTypes.node.isRequired,

  /** CSS class names. */
  className: PropTypes.string,

  /**
   * Array of buttons used in the footer of the sheet.
   */
  footerButtonList: PropTypes.array,

  /**
   *  Used to determine if the sheet should have a close button.
   */
  hasCloseButton: PropTypes.bool,

  /**
   *  Determines if the sheet should have a footer.
   */
  hasFooter: PropTypes.bool,

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

  /**
   * Function to perform when the sheet is closed.
   */
  onClose: PropTypes.func,

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

  /**
   * Identifier used to create data-test-section attributes for testing.
   */
  testSection: PropTypes.string,

  /**
   * Main title of the sheet.
   */
  title: PropTypes.string.isRequired,

  /**
   * Content of the warning Attention bar.
   */
  warningContent: PropTypes.string,

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