"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.Dialog = void 0;
var _react = _interopRequireWildcard(require("react"));
require("../styles/dialog.css");
require("../styles/main.css");
var _reactFeather = require("react-feather");
var _IconButton = require("./IconButton");
var _Button = require("./Button");
var Dialog = function Dialog(_ref) {
  var content = _ref.content,
    title = _ref.title,
    removeHeader = _ref.removeHeader,
    open = _ref.open,
    close = _ref.close,
    confirm = _ref.confirm,
    confirmMessage = _ref.confirmMessage,
    removeConfirm = _ref.removeConfirm,
    appearance = _ref.appearance;
  var node = (0, _react.useRef)();
  var handleClickOutside = function handleClickOutside(e) {
    // console.log("clicking anywhere");
    if (node.current.contains(e.target)) {
      // inside click
      return;
    }
    // outside click
    close();
  };
  (0, _react.useEffect)(function () {
    if (open) {
      document.addEventListener("mousedown", handleClickOutside);
    } else {
      document.removeEventListener("mousedown", handleClickOutside);
    }
    return function () {
      document.removeEventListener("mousedown", handleClickOutside);
    };
  }, [open]);
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, open && /*#__PURE__*/_react.default.createElement("div", {
    className: "dialog-background blurred-background"
  }, /*#__PURE__*/_react.default.createElement("div", {
    className: "dialog"
  }, /*#__PURE__*/_react.default.createElement("div", {
    ref: node,
    className: "dialog-wrapper"
  }, /*#__PURE__*/_react.default.createElement("div", {
    style: {
      display: 'flex',
      justifyContent: 'flex-end'
    }
  }, /*#__PURE__*/_react.default.createElement(_IconButton.IconButton, {
    onClick: close,
    icon: /*#__PURE__*/_react.default.createElement(_reactFeather.X, null)
  })), /*#__PURE__*/_react.default.createElement("div", {
    className: "dialog-container"
  }, !removeHeader && /*#__PURE__*/_react.default.createElement("h2", {
    style: {
      marginBottom: 24
    }
  }, title), /*#__PURE__*/_react.default.createElement("div", {
    style: {
      marginBottom: 24
    }
  }, content), !removeConfirm && /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_Button.Button, {
    onClick: close,
    style: {
      marginRight: 8
    }
  }, "Cancel"), /*#__PURE__*/_react.default.createElement(_Button.Button, {
    onClick: confirm,
    intent: "primary",
    appearance: appearance
  }, confirmMessage || 'Confirm')))))));
};
exports.Dialog = Dialog;