import _extends from "@babel/runtime/helpers/extends";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";

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) { _defineProperty(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; }

import { createBEM } from '@zarm-design/bem';
import { Close, Success } from '@zarm-design/icons';
import * as React from 'react';
import { ConfigContext } from '../config-provider';
import Loading from '../loading';
import Popup from '../popup';
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 = _objectWithoutProperties(props, ["className", "style", "icon", "content", "duration", "maskStyle", "maskColor", "maskClickable", "onClose"]);

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

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

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

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

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

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

      default:
        return icon;
    }
  };

  return /*#__PURE__*/React.createElement(Popup, _extends({
    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)));
});
export default Toast;