"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/components/Toast/Toast.tsx
var Toast_exports = {};
__export(Toast_exports, {
  toast: () => toast
});
module.exports = __toCommonJS(Toast_exports);
var import_icons = require("@simplybusiness/icons");
var import_dedupe2 = __toESM(require("classnames/dedupe"));
var import_sonner = require("sonner");

// src/components/Icon/Icon.tsx
var import_dedupe = __toESM(require("classnames/dedupe"));
var import_Icon = require("@simplybusiness/mobius/src/components/Icon/Icon.css");
var import_jsx_runtime = require("react/jsx-runtime");
var ICON_PREFIX = "mobius-icon";
var capitaliseFirstLetter = (str) => str.charAt(0).toUpperCase() + str.slice(1);
function Icon({
  ref,
  icon,
  className,
  size = "xs",
  color,
  fixedWidth,
  spin,
  spinReverse,
  title,
  ...otherProps
}) {
  if (!icon) {
    throw new Error("Must specify icon object");
  }
  const classes = (0, import_dedupe.default)(
    "mobius",
    "mobius-icon",
    `svg-inline--${ICON_PREFIX}`,
    `--size-${size}`,
    className,
    {
      [`${ICON_PREFIX}-fw`]: fixedWidth,
      [`${ICON_PREFIX}-spin`]: spin || spinReverse,
      [`${ICON_PREFIX}-spin-reverse`]: spinReverse
    }
  );
  const { iconName, width, height, svgPathData } = icon;
  const formattedIconName = iconName.split("-").join(" ");
  const defaultTitle = `${capitaliseFirstLetter(formattedIconName)} icon`;
  const titleText = title || defaultTitle;
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
    "svg",
    {
      ref,
      focusable: "false",
      "data-icon": iconName,
      className: classes,
      role: "img",
      xmlns: "http://www.w3.org/2000/svg",
      viewBox: `0 0 ${width} ${height}`,
      style: { color },
      ...otherProps,
      children: [
        /* @__PURE__ */ (0, import_jsx_runtime.jsx)("title", { children: titleText }),
        /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { fill: "currentColor", d: svgPathData })
      ]
    }
  );
}

// src/components/Toast/state.ts
var toastState = {
  showCloseButton: true
};

// src/components/Toast/Toast.tsx
var import_Toast = require("@simplybusiness/mobius/src/components/Toast/Toast.css");
var import_jsx_runtime2 = require("react/jsx-runtime");
var variantIcons = {
  info: import_icons.circleInfo,
  success: import_icons.circleCheck,
  warning: import_icons.triangleExclamation,
  error: import_icons.circleExclamation
};
var variantColors = {
  info: "var(--color-info)",
  success: "var(--color-valid)",
  warning: "var(--color-warning)",
  error: "var(--color-error)"
};
var ToastIcon = ({ variant }) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "mobius-toast__icon", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Icon, { icon: variantIcons[variant], color: variantColors[variant] }) });
var CloseIcon = () => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "mobius-toast__close-icon", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Icon, { icon: import_icons.cross }) });
var ToastContent = ({
  toastId,
  variant,
  title,
  description,
  action,
  cancel,
  showCloseButton = toastState.showCloseButton
}) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: (0, import_dedupe2.default)("mobius", "mobius-toast", `--${variant}`), children: [
  /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ToastIcon, { variant }),
  /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "mobius-toast__body", children: [
    /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "mobius-toast__content", children: [
      title && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "mobius-toast__title", children: title }),
      description && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "mobius-toast__description", children: description })
    ] }),
    (action || cancel) && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "mobius-toast__actions", children: [
      cancel && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
        "button",
        {
          type: "button",
          className: "mobius-toast__cancel",
          onClick: () => {
            cancel.onClick?.();
            import_sonner.toast.dismiss(toastId);
          },
          children: cancel.label
        }
      ),
      action && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
        "button",
        {
          type: "button",
          className: "mobius-toast__action",
          onClick: () => {
            action.onClick();
            import_sonner.toast.dismiss(toastId);
          },
          children: action.label
        }
      )
    ] })
  ] }),
  showCloseButton && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
    "button",
    {
      type: "button",
      className: "mobius-toast__close",
      onClick: () => import_sonner.toast.dismiss(toastId),
      "aria-label": "Close",
      children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(CloseIcon, {})
    }
  )
] });
var createCustomToast = (message, variant, options) => import_sonner.toast.custom(
  (id) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
    ToastContent,
    {
      toastId: id,
      variant,
      title: options?.title,
      description: options?.description ?? message,
      action: options?.action,
      cancel: options?.cancel,
      showCloseButton: options?.showCloseButton
    }
  ),
  {
    duration: options?.duration,
    onDismiss: options?.onDismiss,
    onAutoClose: options?.onAutoClose
  }
);
var toast = {
  /** Show an info toast */
  info: (message, options) => createCustomToast(message, "info", options),
  /** Show a success toast */
  success: (message, options) => createCustomToast(message, "success", options),
  /** Show a warning toast */
  warning: (message, options) => createCustomToast(message, "warning", options),
  /** Show an error toast */
  error: (message, options) => createCustomToast(message, "error", options),
  /** Dismiss a specific toast by ID or all toasts */
  dismiss: (toastId) => import_sonner.toast.dismiss(toastId)
};
//# sourceMappingURL=Toast.js.map
