import "react";
import { render } from "../_util/react-dom.js";
import BaseNotification from "../_class/notification.js";
import Notice from "../_class/notice.js";
import cs from "../_util/classNames.js";
import { isNumber, isUndefined } from "../_util/is.js";
import useNotification from "./useNotification.js";
import { jsx } from "../../../../../../@emotion_react@11.10.4_3toe27fv7etiytxb5kxc7fxaw4/node_modules/@emotion/react/jsx-runtime/dist/emotion-react-jsx-runtime.browser.esm.js";
import TransitionGroup from "../../../../../../react-transition-group@4.4.5_biqbaboplfbrettd7655fr4n2y/node_modules/react-transition-group/esm/TransitionGroup.js";
import CSSTransition from "../../../../../../react-transition-group@4.4.5_biqbaboplfbrettd7655fr4n2y/node_modules/react-transition-group/esm/CSSTransition.js";
var __extends = globalThis && globalThis.__extends || function() {
  var extendStatics = function(d, b) {
    extendStatics = Object.setPrototypeOf || {
      __proto__: []
    } instanceof Array && function(d2, b2) {
      d2.__proto__ = b2;
    } || function(d2, b2) {
      for (var p in b2)
        if (Object.prototype.hasOwnProperty.call(b2, p))
          d2[p] = b2[p];
    };
    return extendStatics(d, b);
  };
  return function(d, b) {
    if (typeof b !== "function" && b !== null)
      throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
    extendStatics(d, b);
    function __() {
      this.constructor = d;
    }
    d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  };
}();
var __assign = globalThis && globalThis.__assign || function() {
  __assign = Object.assign || function(t) {
    for (var s, i = 1, n = arguments.length; i < n; i++) {
      s = arguments[i];
      for (var p in s)
        if (Object.prototype.hasOwnProperty.call(s, p))
          t[p] = s[p];
    }
    return t;
  };
  return __assign.apply(this, arguments);
};
var notificationTypes = ["info", "success", "error", "warning", "normal"];
var notificationInstance = {};
var maxCount;
var prefixCls;
var duration;
var container;
var rtl;
var Notification = function(_super) {
  __extends(Notification2, _super);
  function Notification2() {
    var _this = _super !== null && _super.apply(this, arguments) || this;
    _this.remove = function(id) {
      var noticeItem = _this.state.notices.find(function(item) {
        return item.id === id;
      });
      if (noticeItem) {
        _this.update(__assign(__assign({}, noticeItem), {
          style: __assign(__assign({}, noticeItem.style), {
            opacity: 0
          })
        }));
      }
      setTimeout(function() {
        _super.prototype.remove.call(_this, id);
      }, 200);
    };
    return _this;
  }
  Notification2.prototype.render = function() {
    var _a;
    var _this = this;
    var notices = this.state.notices;
    var _b = this.props, _prefixCls = _b.prefixCls, _rtl = _b.rtl;
    var position = this.state.position;
    var mergedRtl = !isUndefined(_rtl) ? _rtl : rtl;
    if (isUndefined(position)) {
      position = mergedRtl ? "topLeft" : "topRight";
    }
    var mergedPrefixCls = _prefixCls || prefixCls;
    var prefixClsNotification = mergedPrefixCls ? mergedPrefixCls + "-notification" : "arco-notification";
    var transitionClass;
    if (position === "topLeft" || position === "bottomLeft") {
      transitionClass = "slideNoticeLeft";
    } else {
      transitionClass = "slideNoticeRight";
    }
    var classNames = cs(prefixClsNotification + "-wrapper", prefixClsNotification + "-wrapper-" + position, (_a = {}, _a[prefixClsNotification + "-wrapper-rtl"] = rtl, _a));
    return /* @__PURE__ */ jsx("div", {
      className: classNames,
      children: /* @__PURE__ */ jsx(TransitionGroup, {
        component: null,
        children: notices.map(function(notice) {
          return /* @__PURE__ */ jsx(CSSTransition, {
            timeout: {
              enter: 400,
              exit: 300
            },
            classNames: transitionClass,
            onExit: function(e) {
              e.style.height = e.scrollHeight + "px";
            },
            onExiting: function(e) {
              e.style.height = 0;
            },
            onExited: function(e) {
              e.style.height = 0;
              notice.onClose && notice.onClose();
            },
            children: /* @__PURE__ */ jsx(Notice, {
              ...__assign({}, notice, {
                onClose: _this.remove,
                prefixCls: prefixClsNotification,
                iconPrefix: mergedPrefixCls,
                noticeType: "notification",
                rtl: mergedRtl
              })
            })
          }, notice.id);
        })
      })
    });
  };
  Notification2.config = function(options) {
    if (options === void 0) {
      options = {};
    }
    if (options.maxCount) {
      maxCount = options.maxCount;
    }
    if (options.prefixCls) {
      prefixCls = options.prefixCls;
    }
    if (isNumber(options.duration)) {
      duration = options.duration;
    }
    if (options.rtl) {
      rtl = options.rtl;
    }
    if (options.getContainer && options.getContainer() !== container) {
      container = options.getContainer();
      Object.keys(notificationInstance).forEach(function(notice) {
        return notificationInstance[notice].clear();
      });
      notificationInstance = {};
    }
  };
  Notification2.clear = function() {
    Object.keys(notificationInstance).forEach(function(ins) {
      notificationInstance[ins].clear();
    });
  };
  Notification2.remove = function(id) {
    Object.keys(notificationInstance).forEach(function(ins) {
      notificationInstance[ins].remove(id);
    });
  };
  Notification2.addInstance = function(noticeProps) {
    var position = noticeProps.position;
    if (isUndefined(noticeProps.position)) {
      position = rtl ? "topLeft" : "topRight";
    }
    var _noticeProps = __assign({
      duration
    }, noticeProps);
    if (notificationInstance[position]) {
      var notices = notificationInstance[position].state.notices;
      if (notices.length >= maxCount) {
        var updated = notices[0];
        notices.shift();
        notificationInstance[position].add(__assign(__assign({}, _noticeProps), {
          id: updated.id
        }));
      } else {
        notificationInstance[position].add(_noticeProps);
      }
      return notificationInstance[position];
    }
    var div = document.createElement("div");
    var instance = null;
    (container || document.body).appendChild(div);
    render(/* @__PURE__ */ jsx(Notification2, {
      ref: function(ref) {
        notificationInstance[position] = ref;
        notificationInstance[position].add(_noticeProps);
        instance = notificationInstance[position];
        return instance;
      }
    }), div);
  };
  return Notification2;
}(BaseNotification);
notificationTypes.forEach(function(type) {
  Notification[type] = function(noticeProps) {
    return Notification.addInstance(__assign(__assign({}, noticeProps), {
      type
    }));
  };
});
Notification.useNotification = useNotification;
const Notification$1 = Notification;
export {
  Notification$1 as default
};
//# sourceMappingURL=index.js.map
