import { Component } from "react";
import IconClose from "../../icon/react-icon/IconClose/index.js";
import IconCheckCircleFill from "../../icon/react-icon/IconCheckCircleFill/index.js";
import IconCloseCircleFill from "../../icon/react-icon/IconCloseCircleFill/index.js";
import IconInfoCircleFill from "../../icon/react-icon/IconInfoCircleFill/index.js";
import IconExclamationCircleFill from "../../icon/react-icon/IconExclamationCircleFill/index.js";
import IconLoading from "../../icon/react-icon/IconLoading/index.js";
import cs from "../_util/classNames.js";
import IconHover from "./icon-hover.js";
import { IconContext } from "../../icon/react-icon/context.js";
import { jsx, jsxs } from "../../../../../../@emotion_react@11.10.4_3toe27fv7etiytxb5kxc7fxaw4/node_modules/@emotion/react/jsx-runtime/dist/emotion-react-jsx-runtime.browser.esm.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 Notice = function(_super) {
  __extends(Notice2, _super);
  function Notice2() {
    var _this = _super !== null && _super.apply(this, arguments) || this;
    _this.startTimer = function() {
      var _a = _this.props, duration = _a.duration, onClose = _a.onClose, id = _a.id;
      if (duration !== 0) {
        _this.timer = window.setTimeout(function() {
          onClose && onClose(id);
          _this.removeTimer();
        }, duration);
      }
    };
    _this.removeTimer = function() {
      if (_this.timer) {
        window.clearTimeout(_this.timer);
        _this.timer = null;
      }
    };
    _this.onClose = function() {
      _this.props.onClose && _this.props.onClose(_this.props.id);
    };
    _this.renderIcon = function() {
      var _a = _this.props, showIcon = _a.showIcon, icon = _a.icon, type = _a.type, prefixCls = _a.prefixCls, iconPrefix = _a.iconPrefix;
      var content;
      if (icon) {
        content = icon;
      } else if (showIcon) {
        switch (type) {
          case "info":
            content = /* @__PURE__ */ jsx(IconInfoCircleFill, {});
            break;
          case "success":
            content = /* @__PURE__ */ jsx(IconCheckCircleFill, {});
            break;
          case "error":
            content = /* @__PURE__ */ jsx(IconCloseCircleFill, {});
            break;
          case "warning":
            content = /* @__PURE__ */ jsx(IconExclamationCircleFill, {});
            break;
          case "loading":
            content = /* @__PURE__ */ jsx(IconLoading, {});
            break;
        }
        content = /* @__PURE__ */ jsx(IconContext.Provider, {
          value: iconPrefix ? {
            prefixCls: iconPrefix
          } : {},
          children: content
        });
      }
      return /* @__PURE__ */ jsx("span", {
        className: prefixCls + "-icon",
        children: content
      });
    };
    _this.onMouseEnter = function() {
      _this.removeTimer();
    };
    _this.onMouseLeave = function() {
      _this.startTimer();
    };
    return _this;
  }
  Notice2.prototype.componentDidMount = function() {
    this.startTimer();
  };
  Notice2.prototype.componentDidUpdate = function(nextProps) {
    if (nextProps.duration !== this.props.duration || this.props.update) {
      this.removeTimer();
      this.startTimer();
    }
  };
  Notice2.prototype.componentWillUnmount = function() {
    this.removeTimer();
  };
  Notice2.prototype.render = function() {
    var _a;
    var _b = this.props, title = _b.title, content = _b.content, showIcon = _b.showIcon, className = _b.className, style = _b.style, type = _b.type, btn = _b.btn, icon = _b.icon, prefixCls = _b.prefixCls, closable = _b.closable, noticeType = _b.noticeType, iconPrefix = _b.iconPrefix, rtl = _b.rtl;
    var classNames = cs(prefixCls, prefixCls + "-" + type, (_a = {}, _a[prefixCls + "-closable"] = closable, _a[prefixCls + "-rtl"] = rtl, _a), className);
    var _closable = "closable" in this.props ? closable : true;
    var shouldRenderIcon = showIcon;
    if (type === "normal" && !icon) {
      shouldRenderIcon = false;
    }
    if (noticeType === "message") {
      _closable = closable;
      return /* @__PURE__ */ jsx("div", {
        style: {
          textAlign: "center"
        },
        onMouseEnter: this.onMouseEnter,
        onMouseLeave: this.onMouseLeave,
        children: /* @__PURE__ */ jsxs("div", {
          className: classNames,
          style,
          role: "alert",
          children: [shouldRenderIcon && this.renderIcon(), /* @__PURE__ */ jsx("span", {
            className: prefixCls + "-content",
            children: content
          }), _closable && /* @__PURE__ */ jsx(IconHover, {
            prefix: prefixCls,
            className: prefixCls + "-close-btn",
            onClick: this.onClose,
            children: /* @__PURE__ */ jsx(IconClose, {})
          })]
        })
      });
    }
    if (noticeType === "notification") {
      return /* @__PURE__ */ jsx("div", {
        onMouseEnter: this.onMouseEnter,
        onMouseLeave: this.onMouseLeave,
        children: /* @__PURE__ */ jsxs("div", {
          className: classNames,
          style,
          role: "alert",
          children: [shouldRenderIcon && /* @__PURE__ */ jsx("div", {
            className: prefixCls + "-left",
            children: this.renderIcon()
          }), /* @__PURE__ */ jsxs("div", {
            className: prefixCls + "-right",
            children: [title && /* @__PURE__ */ jsx("div", {
              className: prefixCls + "-title",
              children: title
            }), /* @__PURE__ */ jsx("div", {
              className: prefixCls + "-content",
              children: content
            }), btn && /* @__PURE__ */ jsx("div", {
              className: prefixCls + "-btn-wrapper",
              children: btn
            })]
          }), _closable && /* @__PURE__ */ jsx(IconHover, {
            prefix: prefixCls,
            className: prefixCls + "-close-btn",
            onClick: this.onClose,
            children: /* @__PURE__ */ jsx(IconContext.Provider, {
              value: iconPrefix ? {
                prefixCls: iconPrefix
              } : {},
              children: /* @__PURE__ */ jsx(IconClose, {})
            })
          })]
        })
      });
    }
  };
  Notice2.defaultProps = {
    type: "info",
    showIcon: true,
    noticeType: "message",
    duration: 3e3
  };
  return Notice2;
}(Component);
const Notice$1 = Notice;
export {
  Notice$1 as default
};
//# sourceMappingURL=notice.js.map
