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

/*
 * @Author: codingfly
 * @Description:
 * @Date: 2021-08-11 11:11:10
 * @LastEditTime: 2021-09-09 16:37:46
 * @FilePath: \my-remax-ui\components\popup\index.tsx
 */
import React, { useMemo } from 'react';
import { View } from 'remax/one';
import classNames from 'classnames';
import Mask from '../overlay';
import Icon from '../icon';
import { getPrefixCls } from './../common';
var prefixCls = 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 = classNames(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 = 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.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(View, {
    className: classes,
    style: new_style
  }, title ? /*#__PURE__*/React.createElement(View, {
    className: "".concat(prefixCls, "-title")
  }, title) : null, children, closeable ? /*#__PURE__*/React.createElement(View, {
    className: "".concat(prefixCls, "-close"),
    onTap: function onTap() {
      onClose === null || onClose === void 0 ? void 0 : onClose();
    }
  }, /*#__PURE__*/React.createElement(Icon, {
    type: "close",
    color: "#999",
    size: 20
  })) : null), mask ? /*#__PURE__*/React.createElement(Mask, {
    show: overlay,
    onTap: handleClickMask
  }) : null);
};

export default Popup;