import React, { Component } from "react";
import { Trans } from "./../../wix-rich-content-common/index.js";
import { ErrorMessageMap } from "./../../wix-rich-content-common/lib/error-message-map.js";
import { Toast } from "./../../ui-components/index.js";
class ErrorNotifier extends Component {
  constructor(props) {
    super(props);
    this.notify = (error) => {
      this.setState((state) => ({ error, errorCount: state.errorCount + 1 }));
    };
    this.close = () => {
      this.setState({ errorCount: 0 });
    };
    this.state = { error: {}, errorCount: 0 };
  }
  render() {
    const { error, errorCount } = this.state;
    const { isMobile, languageDir } = this.props;
    if (errorCount <= 0) {
      return null;
    }
    return /* @__PURE__ */ React.createElement("div", { style: { display: "contents" }, dir: languageDir }, /* @__PURE__ */ React.createElement(ErrorToast, { ...{ error, errorCount, onClose: this.close, isMobile } }));
  }
}
const ErrorToast = (props) => {
  const { errorCount, error, onClose, isMobile } = props;
  const isOpen = errorCount > 0;
  if (!isOpen) {
    return null;
  }
  const translationKey = errorCount === 1 && error.key ? ErrorMessageMap[error.key] : "UploadFile_Error_Generic_Toast_Multiple";
  const upgradeUrl = error.args?.upgradeUrl;
  const errorMsg = translationKey ? /* @__PURE__ */ React.createElement(
    Trans,
    {
      i18nKey: translationKey,
      values: { ...error.args, errors: errorCount },
      components: {
        error: error.msg,
        ...upgradeUrl && {
          link: /* @__PURE__ */ React.createElement("a", { href: upgradeUrl, target: "_blank", rel: "noreferrer" }, " ")
        }
      }
    }
  ) : error.msg;
  return /* @__PURE__ */ React.createElement(Toast, { message: errorMsg || "", isError: true, onClose, isMobile });
};
export {
  ErrorNotifier
};
//# sourceMappingURL=error-notifier.js.map
