import { jsxs, jsx, Fragment } from "react/jsx-runtime";
import { T as Toast, a as ToastTitle, b as ToastDescription, c as Toaster$1, t as toast } from "../../toast-Ba42YgO0.js";
import { useState, useEffect } from "react";
import { cn } from "../utils/cn.js";
import { Button } from "../button/button.js";
function ToastContentInternal({
  title,
  description,
  icon,
  variant = "default",
  actionButton,
  cancelButton,
  showDismiss,
  toastId
}) {
  const handleDismiss = () => {
    if (typeof toastId !== "undefined") {
      toast.dismiss(toastId);
    } else {
      toast.dismiss();
    }
  };
  return /* @__PURE__ */ jsxs("div", { className: "relative w-full", children: [
    /* @__PURE__ */ jsxs(Toast, { variant, className: "shadow-none", children: [
      icon && icon,
      title && /* @__PURE__ */ jsx(ToastTitle, { children: title }),
      description && /* @__PURE__ */ jsx(ToastDescription, { children: description }),
      (actionButton || cancelButton) && /* @__PURE__ */ jsx(ToastDescription, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-2 sm:flex-row sm:gap-2 mt-3", children: [
        cancelButton && /* @__PURE__ */ jsx(
          Button,
          {
            variant: "secondary",
            size: "sm",
            className: "flex-1 sm:flex-initial cursor-pointer",
            onClick: (e) => {
              e.stopPropagation();
              cancelButton.onClick?.(e);
              handleDismiss();
            },
            ...cancelButton,
            children: cancelButton.children
          }
        ),
        actionButton && /* @__PURE__ */ jsx(
          Button,
          {
            variant: "default",
            size: "sm",
            className: "flex-1 sm:flex-initial cursor-pointer",
            onClick: (e) => {
              e.stopPropagation();
              actionButton.onClick?.(e);
              handleDismiss();
            },
            ...actionButton,
            children: actionButton.children
          }
        )
      ] }) })
    ] }),
    showDismiss && /* @__PURE__ */ jsx(
      "button",
      {
        type: "button",
        "aria-label": "Dismiss",
        className: cn(
          "absolute top-2 right-2 shrink-0 text-secondary hover:text-primary hover:bg-muted rounded-sm transition-all focus:outline-none focus:ring-2 focus:ring-ring p-1 cursor-pointer"
        ),
        onClick: (e) => {
          e.stopPropagation();
          handleDismiss();
        },
        children: /* @__PURE__ */ jsx(
          "svg",
          {
            xmlns: "http://www.w3.org/2000/svg",
            viewBox: "0 0 24 24",
            fill: "none",
            stroke: "currentColor",
            className: "h-3.5 w-3.5",
            children: /* @__PURE__ */ jsx(
              "path",
              {
                strokeLinecap: "round",
                strokeLinejoin: "round",
                strokeWidth: "2",
                d: "M6 18L18 6M6 6l12 12"
              }
            )
          }
        )
      }
    )
  ] });
}
const Toaster = ({
  children,
  position = "top-center",
  max = 5,
  ...props
}) => {
  const [theme, setTheme] = useState(() => {
    if (typeof document !== "undefined") {
      return document.documentElement.classList.contains("dark") ? "dark" : "light";
    }
    return "light";
  });
  useEffect(() => {
    const observer = new MutationObserver((mutations) => {
      mutations.forEach((mutation) => {
        if (mutation.type === "attributes" && mutation.attributeName === "class") {
          const isDark = document.documentElement.classList.contains("dark");
          setTheme(isDark ? "dark" : "light");
        }
      });
    });
    observer.observe(document.documentElement, {
      attributes: true,
      attributeFilter: ["class"]
    });
    return () => observer.disconnect();
  }, []);
  return /* @__PURE__ */ jsxs(Fragment, { children: [
    children,
    /* @__PURE__ */ jsx(
      Toaster$1,
      {
        theme,
        position,
        visibleToasts: max,
        expand: false,
        richColors: true,
        ...props
      }
    )
  ] });
};
export {
  ToastContentInternal,
  Toaster
};
