"use strict";

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

var _preact = require("preact");

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

var _icon = require("./icon");

var _object = require("./utils/object");

var _portal = require("./portal");

var _shield = require("./shield");

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

const Dialog = incomingProps => {
  const {
    className,
    title,
    doClose,
    forceChoice,
    style,
    bottom,
    children
  } = incomingProps;
  const props = (0, _object.omit)(incomingProps, ['className', 'title', 'doClose', 'forceChoice', 'style', 'children', 'bottom']);
  return (0, _preact.h)(_portal.Portal, {
    into: "body"
  }, (0, _preact.h)("div", {
    className: "fixed z-999 vh-100 w-100 top-0 left-0 flex items-center justify-center"
  }, (0, _preact.h)(_shield.Shield, {
    onClick: forceChoice ? null : doClose
  }), (0, _preact.h)("dialog", _extends({
    open: true,
    style: Object.assign({
      minHeight: '150px',
      minWidth: '300px',
      width: '600px',
      // this is important for iOS
      maxHeight: 'calc(100vh - 120px)'
    }, style),
    className: (0, _classnames.default)('ph2 pt2 pb1 bg-white bn br3 shadow-2 z-999 relative flex flex-column', className)
  }, props), (0, _preact.h)("div", {
    className: "w-100 pt1 ph1"
  }, !forceChoice && // this is just a spacer
  (0, _preact.h)("div", {
    className: "fr",
    style: {
      width: '44px',
      height: '10px'
    }
  }, (0, _preact.h)("button", {
    onClick: doClose,
    style: {
      top: '-16px',
      right: '-4px'
    },
    className: "button-reset bn bg-transparent relative pa3"
  }, (0, _preact.h)(_icon.Icon, {
    icon: "close"
  }))), title && (0, _preact.h)("h3", {
    className: "mt0 mb2"
  }, title)), (0, _preact.h)("div", {
    className: "pa1 prevent-overscroll overflow-y-scroll w-100 overflow-x-hidden"
  }, children), (0, _preact.h)("div", {
    className: "ph1 pv2"
  }, bottom))));
};

exports.Dialog = Dialog;