import { _ as _defineProperty } from '../_verture/defineProperty-62acccfc.js';
import { jsx, jsxs } from 'react/jsx-runtime';
import React__default from 'react';
import Notification from 'rc-notification';
import WarningCircleF from '@iam-com/icons/WarningCircleF';
import CompleteIcon from '@iam-com/icons/CheckCircleF';
import CloseIcon from '@iam-com/icons/Close';
import CloseCircleFilled from '@iam-com/icons/CloseCircleF';
import clsx from 'clsx';
import { $ as $prefixCls } from '../_verture/constant-66aa48a1.js';
import { s as styleInject } from '../_verture/style-inject.es-300983ab.js';
import '../_verture/typeof-498dd2b1.js';

var css_248z = "@charset \"UTF-8\";\n/**\n * @author Hanz\n * @date 2022/1/13 上午10:30\n * @description 通知提醒框\n */\n/**\n* @author Hanz\n* @date 2021/10/20 下午2:08\n* @description color\n*/\n.paraui-v3-notification {\n  position: fixed;\n  margin: 0 24px 0 0;\n  padding: 0;\n  color: rgb(46, 55, 67);\n  font-size: 14px;\n  z-index: 9999;\n}\n.paraui-v3-notification-topLeft, .paraui-v3-notification-bottomLeft {\n  margin-right: 0;\n  margin-left: 24px;\n}\n.paraui-v3-notification-topLeft .paraui-v3-notification-fade-enter.paraui-v3-notification-fade-enter-active, .paraui-v3-notification-bottomLeft .paraui-v3-notification-fade-enter.paraui-v3-notification-fade-enter-active, .paraui-v3-notification-topLeft .paraui-v3-notification-fade-appear.paraui-v3-notification-fade-appear-active, .paraui-v3-notification-bottomLeft .paraui-v3-notification-fade-appear.paraui-v3-notification-fade-appear-active {\n  animation-name: NotificationLeftFadeIn;\n}\n.paraui-v3-notification-hook-holder, .paraui-v3-notification-notice {\n  position: relative;\n  width: 430px;\n  max-width: calc(100vw - 48px);\n  margin-bottom: 16px;\n  margin-left: auto;\n  overflow: hidden;\n  word-wrap: break-word;\n  background: rgb(255, 255, 255);\n  border-radius: 4px;\n  box-shadow: 0px 2px 8px 0px rgba(171, 176, 185, 0.4);\n}\n.paraui-v3-notification-topLeft .paraui-v3-notification-hook-holder, .paraui-v3-notification-topLeft .paraui-v3-notification-notice, .paraui-v3-notification-bottomLeft .paraui-v3-notification-hook-holder, .paraui-v3-notification-bottomLeft .paraui-v3-notification-notice {\n  margin-right: auto;\n  margin-left: 0;\n}\n.paraui-v3-notification-hook-holder > .paraui-v3-notification-notice {\n  margin-bottom: 0;\n  box-shadow: none;\n}\n.paraui-v3-notification-notice {\n  padding: 20px;\n  line-height: 1.5715;\n}\n.paraui-v3-notification-notice-content {\n  position: relative;\n}\n.paraui-v3-notification-notice-message {\n  margin-bottom: 8px;\n  color: rgb(46, 55, 67);\n  font-size: 14px;\n  font-weight: 700;\n  line-height: 24px;\n}\n.paraui-v3-notification-notice-message-single-line-auto-margin {\n  display: block;\n  width: calc(264px - 100%);\n  max-width: 4px;\n  background-color: transparent;\n  pointer-events: none;\n}\n.paraui-v3-notification-notice-message-single-line-auto-margin::before {\n  display: block;\n  content: \"\";\n}\n.paraui-v3-notification-notice-description {\n  font-size: 14px;\n  font-weight: 400;\n}\n.paraui-v3-notification-notice-closable .paraui-v3-notification-notice-message {\n  padding-right: 24px;\n}\n.paraui-v3-notification-notice-with-icon .paraui-v3-notification-notice-message {\n  margin-bottom: 4px;\n  margin-left: 24px;\n}\n.paraui-v3-notification-notice-with-icon .paraui-v3-notification-notice-description {\n  margin-left: 24px;\n}\n.paraui-v3-notification-notice-without-description .paraui-v3-notification-notice-message {\n  margin-bottom: 0;\n}\n.paraui-v3-notification .paraui-v3-notification-notice-icon {\n  position: absolute;\n  top: 4px;\n  font-size: 16px;\n  line-height: 24px;\n}\n.paraui-v3-notification .paraui-v3-notification-notice-icon-success {\n  color: rgb(83, 195, 27);\n}\n.paraui-v3-notification .paraui-v3-notification-notice-icon-info {\n  color: rgb(54, 102, 214);\n}\n.paraui-v3-notification .paraui-v3-notification-notice-icon-warning {\n  color: rgb(255, 161, 80);\n}\n.paraui-v3-notification .paraui-v3-notification-notice-icon-error {\n  color: rgb(235, 96, 84);\n}\n.paraui-v3-notification-notice-close {\n  position: absolute;\n  top: 16px;\n  right: 22px;\n  color: rgba(46, 55, 67, 0.7);\n  outline: none;\n}\n.paraui-v3-notification-notice-close:hover {\n  color: rgba(46, 55, 67, 0.7);\n}\n.paraui-v3-notification .paraui-v3-notification-close-icon {\n  font-size: 18px;\n  cursor: pointer;\n  color: rgba(46, 55, 67, 0.7);\n}\n.paraui-v3-notification-notice-btn {\n  float: right;\n  margin-top: 16px;\n}\n.paraui-v3-notification .notification-fade-effect {\n  animation-duration: 0.24s;\n  animation-timing-function: cubic-bezier(0.645, 0.045, 0.355, 1);\n  animation-fill-mode: both;\n}\n.paraui-v3-notification-fade-enter, .paraui-v3-notification-fade-appear {\n  animation-duration: 0.24s;\n  animation-timing-function: cubic-bezier(0.645, 0.045, 0.355, 1);\n  animation-fill-mode: both;\n  opacity: 0;\n  animation-play-state: paused;\n}\n.paraui-v3-notification-fade-leave {\n  animation-duration: 0.24s;\n  animation-timing-function: cubic-bezier(0.645, 0.045, 0.355, 1);\n  animation-fill-mode: both;\n  animation-play-state: paused;\n}\n.paraui-v3-notification-fade-enter.paraui-v3-notification-fade-enter-active, .paraui-v3-notification-fade-appear.paraui-v3-notification-fade-appear-active {\n  animation-name: NotificationFadeIn;\n  animation-play-state: running;\n}\n.paraui-v3-notification-fade-leave.paraui-v3-notification-fade-leave-active {\n  animation-name: NotificationFadeOut;\n  animation-play-state: running;\n}\n@keyframes NotificationFadeIn {\n  0% {\n    left: 430px;\n    opacity: 0;\n  }\n  100% {\n    left: 0;\n    opacity: 1;\n  }\n}\n@keyframes NotificationLeftFadeIn {\n  0% {\n    right: 430px;\n    opacity: 0;\n  }\n  100% {\n    right: 0;\n    opacity: 1;\n  }\n}\n@keyframes NotificationFadeOut {\n  0% {\n    max-height: 150px;\n    margin-bottom: 16px;\n    opacity: 1;\n  }\n  100% {\n    max-height: 0;\n    margin-bottom: 0;\n    padding-top: 0;\n    padding-bottom: 0;\n    opacity: 0;\n  }\n}";
styleInject(css_248z);

//通知框实例存储
var notificationInstance = {};
// 默认值
var defaultDuration = 4.5; //默认 4.5 秒后自动关闭，配置为 null 则不自动关闭
var defaultTop = 24;
var defaultBottom = 24;
var defaultPlacement = 'topRight';
var defaultGetContainer;
var prefixCls = "".concat($prefixCls, "-notification");
var defaultCloseIcon = jsx(CloseIcon, {
  className: "".concat(prefixCls, "-close-icon")
});
var rtl = false;
var maxCount;
//设置全局配置
function setNotificationConfig(options) {
  var duration = options.duration,
    placement = options.placement,
    bottom = options.bottom,
    top = options.top,
    getContainer = options.getContainer,
    closeIcon = options.closeIcon;
  if (duration !== undefined) {
    defaultDuration = duration;
  }
  if (placement !== undefined) {
    defaultPlacement = placement;
  }
  if (bottom !== undefined) {
    defaultBottom = bottom;
  }
  if (top !== undefined) {
    defaultTop = top;
  }
  if (getContainer !== undefined) {
    defaultGetContainer = getContainer;
  }
  if (closeIcon !== undefined) {
    defaultCloseIcon = closeIcon;
  }
  if (options.maxCount !== undefined) {
    maxCount = options.maxCount;
  }
}
//获得位置样式
function getPlacementStyle(placement) {
  var top = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultTop;
  var bottom = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : defaultBottom;
  var style;
  switch (placement) {
    case 'topLeft':
      style = {
        left: 0,
        top: top,
        bottom: 'auto'
      };
      break;
    case 'topRight':
      style = {
        right: 0,
        top: top,
        bottom: 'auto'
      };
      break;
    case 'bottomLeft':
      style = {
        left: 0,
        top: 'auto',
        bottom: bottom
      };
      break;
    default:
      style = {
        right: 0,
        top: 'auto',
        bottom: bottom
      };
      break;
  }
  return style;
}
//创建通知框实例
function getNotificationInstance(args, callback) {
  var _args$placement = args.placement,
    placement = _args$placement === void 0 ? defaultPlacement : _args$placement,
    top = args.top,
    bottom = args.bottom,
    _args$getContainer = args.getContainer,
    getContainer = _args$getContainer === void 0 ? defaultGetContainer : _args$getContainer,
    _args$closeIcon = args.closeIcon,
    closeIcon = _args$closeIcon === void 0 ? defaultCloseIcon : _args$closeIcon;
  // const prefixCls = `${$prefixCls}-notification`;
  var cacheKey = "".concat(prefixCls, "-").concat(placement);
  var cacheInstance = notificationInstance[cacheKey];
  if (cacheInstance) {
    Promise.resolve(cacheInstance).then(function (instance) {
      callback({
        prefixCls: "".concat(prefixCls, "-notice"),
        instance: instance
      });
    });
    return;
  }
  //close icon
  var closeIconToRender = jsx("span", Object.assign({
    className: "".concat(prefixCls, "-close-x")
  }, {
    children: closeIcon || jsx(CloseIcon, {
      className: "".concat(prefixCls, "-close-icon")
    })
  }));
  //通知框cls
  var notificationCls = clsx("".concat(prefixCls, "-").concat(placement), _defineProperty({}, "".concat(prefixCls, "-rtl"), rtl === true));
  notificationInstance[cacheKey] = new Promise(function (resolve) {
    Notification.newInstance({
      prefixCls: prefixCls,
      className: notificationCls,
      style: getPlacementStyle(placement, top, bottom),
      getContainer: getContainer,
      closeIcon: closeIconToRender,
      maxCount: maxCount
    }, function (notification) {
      resolve(notification);
      callback({
        prefixCls: "".concat(prefixCls, "-notice"),
        instance: notification
      });
    });
  });
}
//通知框类型图标
var typeToIcon = {
  success: CompleteIcon,
  info: WarningCircleF,
  error: CloseCircleFilled,
  warning: WarningCircleF
};
//创建通知框内容配置
function getNoticeProps(args, prefixCls) {
  var durationArg = args.duration,
    icon = args.icon,
    type = args.type,
    description = args.description,
    message = args.message,
    btn = args.btn,
    onClose = args.onClose,
    onClick = args.onClick,
    key = args.key,
    style = args.style,
    className = args.className,
    _args$closeIcon2 = args.closeIcon,
    closeIcon = _args$closeIcon2 === void 0 ? defaultCloseIcon : _args$closeIcon2;
  var duration = durationArg === undefined ? defaultDuration : durationArg;
  var iconNode = null;
  if (icon) {
    iconNode = jsx("span", Object.assign({
      className: "".concat(prefixCls, "-icon")
    }, {
      children: icon
    }));
  } else if (type) {
    iconNode = /*#__PURE__*/React__default.createElement(typeToIcon[type] || null, {
      className: "".concat(prefixCls, "-icon ").concat(prefixCls, "-icon-").concat(type)
    });
  }
  var autoMarginTag = !description && iconNode ? jsx("span", {
    className: "".concat(prefixCls, "-message-single-line-auto-margin")
  }) : null;
  return {
    content: jsxs("div", Object.assign({
      className: "".concat(iconNode ? "".concat(prefixCls, "-with-icon") : '', " ").concat(description ? '' : prefixCls + '-without-description')
    }, {
      children: [iconNode, jsxs("div", Object.assign({
        className: "".concat(prefixCls, "-message")
      }, {
        children: [autoMarginTag, message]
      })), description && jsx("div", Object.assign({
        className: "".concat(prefixCls, "-description")
      }, {
        children: description
      })), btn ? jsx("span", Object.assign({
        className: "".concat(prefixCls, "-btn")
      }, {
        children: btn
      })) : null]
    })),
    duration: duration,
    closable: true,
    onClose: onClose,
    onClick: onClick,
    key: key,
    style: style || {},
    className: clsx(className, _defineProperty({}, "".concat(prefixCls, "-").concat(type), !!type)),
    closeIcon: closeIcon
  };
}
//通知框调用方法
function notice(args) {
  getNotificationInstance(args, function (_ref) {
    var prefixCls = _ref.prefixCls,
      instance = _ref.instance;
    instance.notice(getNoticeProps(args, prefixCls));
  });
}
//通知框api method
var api = {
  open: notice,
  close: function close(key) {
    Object.keys(notificationInstance).forEach(function (cacheKey) {
      return Promise.resolve(notificationInstance[cacheKey]).then(function (instance) {
        instance.removeNotice(key);
      });
    });
  },
  config: setNotificationConfig,
  destroy: function destroy() {
    Object.keys(notificationInstance).forEach(function (cacheKey) {
      Promise.resolve(notificationInstance[cacheKey]).then(function (instance) {
        instance.destroy();
      });
      delete notificationInstance[cacheKey];
    });
  }
};
//通知框预设类型 'success', 'info', 'warning', 'error'
['success', 'info', 'warning', 'error'].forEach(function (type) {
  api[type] = function (args) {
    return api.open(Object.assign(Object.assign({}, args), {
      type: type
    }));
  };
});
//兼容warn、warning
api.warn = api.warning;

export { api as default };
