"use strict";
var import_Toast = require("../Toast.css");
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const jsxRuntime = require("react/jsx-runtime");
const antd = require("antd");
const React = require("react");
const kit_Theme_UI = require("./Theme/UI.cjs");
require("./Theme/themeUtils.cjs");
require("./Theme/themes.cjs");
const kit_Icon = require("./Icon.cjs");
const kit_internal_functions = require("./internal/functions.cjs");
const message = "Toast_message_fd7a6";
const notification = "Toast_notification_fd7a6";
const css = {
  message,
  notification
};
exports.notification = antd.notification;
const useInitApi = () => {
  const api = antd.App.useApp();
  React.useEffect(() => {
    ({ notification: exports.notification } = api);
  }, [api]);
};
const ToastThemeProvider = ({ children }) => {
  const ref = React.useRef(null);
  const {
    themeSettings: { className }
  } = kit_Theme_UI.useTheme();
  React.useLayoutEffect(() => {
    if (ref.current) {
      const notificationContainer = kit_internal_functions.findParentByClass(ref.current, "ant-notification");
      notificationContainer.classList.add(className);
    }
  });
  return /* @__PURE__ */ jsxRuntime.jsx("div", { ref, children });
};
const getIconName = (s) => {
  if (s === "Confirm")
    return "checkmark";
  return s.toLowerCase();
};
const makeToast = ({
  title,
  severity = "Info",
  closeable = true,
  duration = 8,
  description,
  link
}) => {
  const args = {
    className: css.notification,
    closeIcon: closeable ? /* @__PURE__ */ jsxRuntime.jsx(kit_Icon.default, { decorative: true, name: "close" }) : null,
    description: description ? link ? /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
      /* @__PURE__ */ jsxRuntime.jsx("p", { children: description }),
      link
    ] }) : description : void 0,
    duration,
    message: /* @__PURE__ */ jsxRuntime.jsx(ToastThemeProvider, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: css.message, children: [
      /* @__PURE__ */ jsxRuntime.jsx(kit_Icon.default, { decorative: true, name: getIconName(severity) }),
      /* @__PURE__ */ jsxRuntime.jsx("span", { children: title })
    ] }) })
  };
  exports.notification.open(args);
};
const useToast = () => {
  const {
    themeSettings: { theme, themeIsDark, className }
  } = kit_Theme_UI.useTheme();
  const openToast = ({
    title,
    severity = "Info",
    closeable = true,
    duration = 4.5,
    description,
    link
  }) => {
    const args = {
      className: [className, css.notification].join(" "),
      closeIcon: closeable ? /* @__PURE__ */ jsxRuntime.jsx(kit_Theme_UI.UIProvider, { theme, themeIsDark, children: /* @__PURE__ */ jsxRuntime.jsx(kit_Icon.default, { decorative: true, name: "close" }) }) : null,
      description: description ? link ? /* @__PURE__ */ jsxRuntime.jsx(kit_Theme_UI.UIProvider, { theme, themeIsDark, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
        /* @__PURE__ */ jsxRuntime.jsx("p", { children: description }),
        link
      ] }) }) : description : void 0,
      duration,
      message: /* @__PURE__ */ jsxRuntime.jsx(kit_Theme_UI.UIProvider, { theme, themeIsDark, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: css.message, children: [
        /* @__PURE__ */ jsxRuntime.jsx(kit_Icon.default, { decorative: true, name: getIconName(severity) }),
        title
      ] }) })
    };
    exports.notification.open(args);
  };
  return { openToast };
};
exports.makeToast = makeToast;
exports.useInitApi = useInitApi;
exports.useToast = useToast;
