"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.InternalToast = void 0;
var _antdMobileIcons = require("antd-mobile-icons");
var _classnames = _interopRequireDefault(require("classnames"));
var _react = _interopRequireWildcard(require("react"));
var _withDefaultProps = require("../../utils/with-default-props");
var _autoCenter = _interopRequireDefault(require("../auto-center"));
var _mask = _interopRequireDefault(require("../mask"));
var _spinLoading = _interopRequireDefault(require("../spin-loading"));
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const classPrefix = `adm-toast`;
const defaultProps = {
  maskClickable: true,
  stopPropagation: ['click']
};
const InternalToast = p => {
  const props = (0, _withDefaultProps.mergeProps)(defaultProps, p);
  const {
    maskClickable,
    content,
    icon,
    position
  } = props;
  const iconElement = (0, _react.useMemo)(() => {
    if (icon === null || icon === undefined) return null;
    switch (icon) {
      case 'success':
        return _react.default.createElement(_antdMobileIcons.CheckOutline, {
          className: `${classPrefix}-icon-success`
        });
      case 'fail':
        return _react.default.createElement(_antdMobileIcons.CloseOutline, {
          className: `${classPrefix}-icon-fail`
        });
      case 'loading':
        return _react.default.createElement(_spinLoading.default, {
          color: 'white',
          className: `${classPrefix}-loading`
        });
      default:
        return icon;
    }
  }, [icon]);
  const top = (0, _react.useMemo)(() => {
    switch (position) {
      case 'top':
        return '20%';
      case 'bottom':
        return '80%';
      default:
        return '50%';
    }
  }, [position]);
  return _react.default.createElement(_mask.default, {
    visible: props.visible,
    destroyOnClose: true,
    opacity: 0,
    disableBodyScroll: !maskClickable,
    getContainer: props.getContainer,
    afterClose: props.afterClose,
    style: Object.assign({
      pointerEvents: maskClickable ? 'none' : 'auto'
    }, props.maskStyle),
    className: (0, _classnames.default)(`${classPrefix}-mask`, props.maskClassName),
    stopPropagation: props.stopPropagation
  }, _react.default.createElement("div", {
    className: (0, _classnames.default)(`${classPrefix}-wrap`)
  }, _react.default.createElement("div", {
    style: {
      top
    },
    className: (0, _classnames.default)(`${classPrefix}-main`, icon ? `${classPrefix}-main-icon` : `${classPrefix}-main-text`)
  }, iconElement && _react.default.createElement("div", {
    className: `${classPrefix}-icon`
  }, iconElement), _react.default.createElement(_autoCenter.default, null, content))));
};
exports.InternalToast = InternalToast;