"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

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

var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));

var _bem = require("@zarm-design/bem");

var _icons = require("@zarm-design/icons");

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

var _configProvider = require("../config-provider");

var _loading = _interopRequireDefault(require("../loading"));

var _popup = _interopRequireDefault(require("../popup"));

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

var Toast = /*#__PURE__*/React.forwardRef(function (props, ref) {
  var className = props.className,
      style = props.style,
      icon = props.icon,
      content = props.content,
      duration = props.duration,
      maskStyle = props.maskStyle,
      _props$maskColor = props.maskColor,
      maskColor = _props$maskColor === void 0 ? 'transparent' : _props$maskColor,
      maskClickable = props.maskClickable,
      onClose = props.onClose,
      rest = (0, _objectWithoutProperties2.default)(props, ["className", "style", "icon", "content", "duration", "maskStyle", "maskColor", "maskClickable", "onClose"]);

  var _React$useContext = React.useContext(_configProvider.ConfigContext),
      prefixCls = _React$useContext.prefixCls;

  var bem = (0, _bem.createBEM)('toast', {
    prefixCls: prefixCls
  });

  var renderIcon = function renderIcon() {
    if (icon === undefined || icon === null) return null;

    switch (icon) {
      case 'success':
        return /*#__PURE__*/React.createElement(_icons.Success, null);

      case 'fail':
        return /*#__PURE__*/React.createElement(_icons.Close, null);

      case 'loading':
        return /*#__PURE__*/React.createElement(_loading.default, {
          type: "spinner",
          size: "lg"
        });

      default:
        return icon;
    }
  };

  return /*#__PURE__*/React.createElement(_popup.default, (0, _extends2.default)({
    direction: "center",
    maskStyle: _objectSpread({
      pointerEvents: maskClickable ? 'none' : 'auto'
    }, maskStyle),
    maskColor: maskColor,
    lockScroll: !maskClickable,
    className: bem('wrapper')
  }, rest), /*#__PURE__*/React.createElement("div", {
    ref: ref,
    className: bem([{
      icon: !!icon,
      text: !icon
    }, className]),
    style: style
  }, icon && /*#__PURE__*/React.createElement("div", {
    className: bem('icon')
  }, renderIcon()), content && /*#__PURE__*/React.createElement("div", {
    className: bem('text')
  }, content)));
});
var _default = Toast;
exports.default = _default;