"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

var _typeof = require("@babel/runtime/helpers/typeof");

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

var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));

var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));

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

var _lodash = _interopRequireDefault(require("lodash.omit"));

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

var _theme = _interopRequireDefault(require("./theme.css"));

var _index = require("../../index");

var _uiIcons = require("@teamleader/ui-icons");

var _excluded = ["children", "className", "scrollable", "title", "form", "onSubmit", "tertiaryAction", "secondaryAction", "primaryAction", "leftAction", "onCloseClick"];

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

var Dialog = function Dialog(_ref) {
  var children = _ref.children,
      className = _ref.className,
      _ref$scrollable = _ref.scrollable,
      scrollable = _ref$scrollable === void 0 ? true : _ref$scrollable,
      title = _ref.title,
      form = _ref.form,
      onSubmit = _ref.onSubmit,
      tertiaryAction = _ref.tertiaryAction,
      secondaryAction = _ref.secondaryAction,
      primaryAction = _ref.primaryAction,
      leftAction = _ref.leftAction,
      onCloseClick = _ref.onCloseClick,
      otherProps = (0, _objectWithoutProperties2.default)(_ref, _excluded);
  var bodyRef = /*#__PURE__*/(0, _react.createRef)();
  var dragHandleRef = /*#__PURE__*/(0, _react.createRef)();

  var getHeader = function getHeader() {
    var dragIcon = /*#__PURE__*/_react.default.createElement("div", {
      className: _theme.default['drag-icon'],
      ref: dragHandleRef
    }, /*#__PURE__*/_react.default.createElement(_uiIcons.IconDragMediumFilled, null));

    return /*#__PURE__*/_react.default.createElement(_index.DialogBase.Header, {
      icon: dragIcon,
      onCloseClick: onCloseClick
    }, /*#__PURE__*/_react.default.createElement(_index.Heading3, {
      maxLines: 1
    }, title));
  };

  var getFooter = function getFooter() {
    return /*#__PURE__*/_react.default.createElement(_index.DialogBase.Footer, {
      display: "flex",
      justifyContent: leftAction ? 'space-between' : 'flex-end'
    }, leftAction && /*#__PURE__*/_react.default.createElement(_index.Button, leftAction), /*#__PURE__*/_react.default.createElement(_index.ButtonGroup, {
      justifyContent: "flex-end"
    }, tertiaryAction && /*#__PURE__*/_react.default.createElement(_index.Button, (0, _extends2.default)({}, tertiaryAction, {
      level: "link"
    })), secondaryAction && /*#__PURE__*/_react.default.createElement(_index.Button, secondaryAction), /*#__PURE__*/_react.default.createElement(_index.Button, (0, _extends2.default)({
      level: "primary"
    }, primaryAction))));
  };

  var classNames = (0, _classnames.default)(_theme.default['dialog'], className);
  var restProps = (0, _lodash.default)(otherProps, ['onCloseClick', 'primaryAction', 'secondaryAction', 'tertiaryAction', 'leftAction']);
  return /*#__PURE__*/_react.default.createElement(_index.DialogBase, (0, _extends2.default)({
    className: classNames
  }, restProps, {
    scrollable: false,
    initialFocusRef: bodyRef,
    dragHandleRef: dragHandleRef,
    form: form,
    onSubmit: onSubmit
  }), title && getHeader(), /*#__PURE__*/_react.default.createElement(_index.DialogBase.Body, {
    ref: bodyRef,
    scrollable: scrollable
  }, children), getFooter());
};

var _default = Dialog;
exports.default = _default;