"use strict";

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

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

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

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

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

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

var _Fieldset = _interopRequireDefault(require("../Fieldset"));

var _Footer = _interopRequireDefault(require("./Deprecated/Footer"));

var _Title = _interopRequireDefault(require("./Deprecated/Title"));

var _Wrapper = _interopRequireDefault(require("./Deprecated/Wrapper"));

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 DialogNew = function DialogNew(_ref) {
  var children = _ref.children,
      className = _ref.className,
      footerButtonList = _ref.footerButtonList,
      hasCloseButton = _ref.hasCloseButton,
      hasOverlay = _ref.hasOverlay,
      onClose = _ref.onClose,
      subtitle = _ref.subtitle,
      testSection = _ref.testSection,
      title = _ref.title,
      props = _objectWithoutProperties(_ref, ["children", "className", "footerButtonList", "hasCloseButton", "hasOverlay", "onClose", "subtitle", "testSection", "title"]);

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

  return _react["default"].createElement("div", _extends({
    className: (0, _classnames["default"])("oui-dialog__wrapper", className)
  }, props), hasOverlay && _react["default"].createElement("div", {
    className: "oui-dialog__overlay"
  }), _react["default"].createElement("div", {
    "data-oui-component": true,
    className: "oui-dialog",
    "data-test-section": testSection
  }, hasCloseButton && _react["default"].createElement(_CloseButton["default"], {
    onClick: onClose,
    size: "medium"
  }), _react["default"].createElement("header", {
    className: "oui-dialog__header"
  }, _react["default"].createElement("h2", {
    className: "flush--bottom"
  }, title), subtitleContent), _react["default"].createElement("div", {
    className: "oui-dialog__body overflow-y--auto"
  }, children), _react["default"].createElement("footer", {
    className: "oui-dialog__footer-container"
  }, _react["default"].createElement(_ButtonRow["default"], {
    rightGroup: footerButtonList
  }))));
};

exports.DialogNew = DialogNew;
DialogNew.propTypes = {
  /**
   * The body of the dialog to request minimal information from the user.
   */
  children: _propTypes["default"].node.isRequired,

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

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

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

  /**
   * Used to determine if dialog should have a semi
   * transparent overlay behind it.
   */
  hasOverlay: _propTypes["default"].bool,

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

  /**
   * A subtitle for the dialog.
   */
  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 dialog.
   */
  title: _propTypes["default"].string.isRequired
};
DialogNew.defaultProps = {
  hasCloseButton: true,
  hasOverlay: true,
  onClose: function onClose() {
    return null;
  },
  subtitle: "",
  testSection: ""
};
var Dialog = {
  Fieldset: _Fieldset["default"],
  Footer: _Footer["default"],
  Title: _Title["default"],
  Wrapper: _Wrapper["default"]
};
var _default = Dialog;
exports["default"] = _default;