"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

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

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

var _one = require("remax/one");

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

var _overlay = _interopRequireDefault(require("../overlay"));

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

var _common = require("./../common");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

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

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

var prefixCls = (0, _common.getPrefixCls)('popup');

var Popup = function Popup(props) {
  var _classNames;

  var _props$overlay = props.overlay,
      overlay = _props$overlay === void 0 ? false : _props$overlay,
      children = props.children,
      onClose = props.onClose,
      closeable = props.closeable,
      title = props.title,
      _props$position = props.position,
      position = _props$position === void 0 ? 'center' : _props$position,
      _props$mask = props.mask,
      mask = _props$mask === void 0 ? true : _props$mask,
      square = props.square,
      className = props.className,
      curve = props.curve,
      transparent = props.transparent;

  var handleClickMask = function handleClickMask() {
    onClose === null || onClose === void 0 ? void 0 : onClose();
  };

  var classes = (0, _classnames.default)(className, prefixCls, (_classNames = {}, _defineProperty(_classNames, "".concat(prefixCls, "-").concat(position), position), _defineProperty(_classNames, "".concat(prefixCls, "-ease"), curve === 'ease'), _defineProperty(_classNames, "".concat(prefixCls, "-square"), square), _defineProperty(_classNames, "".concat(prefixCls, "-slide-").concat(position), position != 'center'), _defineProperty(_classNames, "".concat(prefixCls, "-transparent"), transparent), _classNames));
  var new_style = (0, _react.useMemo)(function () {
    var style = props.style;
    var set_style = Object.assign({}, style);

    if (!overlay) {
      set_style = {
        display: 'none'
      };
    }

    if (position === 'bottom') {
      if (!(style === null || style === void 0 ? void 0 : style.height) && overlay) {
        set_style = {
          height: '30%'
        };
      }
    }

    return set_style;
  }, [overlay]);
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_one.View, {
    className: classes,
    style: new_style
  }, title ? /*#__PURE__*/_react.default.createElement(_one.View, {
    className: "".concat(prefixCls, "-title")
  }, title) : null, children, closeable ? /*#__PURE__*/_react.default.createElement(_one.View, {
    className: "".concat(prefixCls, "-close"),
    onTap: function onTap() {
      onClose === null || onClose === void 0 ? void 0 : onClose();
    }
  }, /*#__PURE__*/_react.default.createElement(_icon.default, {
    type: "close",
    color: "#999",
    size: 20
  })) : null), mask ? /*#__PURE__*/_react.default.createElement(_overlay.default, {
    show: overlay,
    onTap: handleClickMask
  }) : null);
};

var _default = Popup;
exports.default = _default;