import { jsx } from "react/jsx-runtime";
import * as React from "react";
import { Toaster as Toaster$1, toast as toast$1 } from "sonner";
import { useInverseTheme, Notice } from "../Notice/notice.js";
import { Button } from "../Button/button.js";
function ToastInner({
  id,
  variant = "neutral",
  action,
  ...rest
}) {
  const inverseTheme = useInverseTheme();
  const isInverse = variant === "neutral" || variant === "success";
  const dismiss = () => toast$1.dismiss(id);
  const actionButton = action ? /* @__PURE__ */ jsx(Button, { variant: "tertiary", size: "xs", onClick: action.onClick, children: action.label }) : void 0;
  const isCritical = variant === "error" || variant === "warning";
  const liveRole = isCritical ? "alert" : "status";
  const liveLevel = isCritical ? "assertive" : "polite";
  if (isInverse) {
    return /* @__PURE__ */ jsx("div", { role: liveRole, "aria-live": liveLevel, className: "rounded-lg overflow-hidden", style: { boxShadow: "var(--elevation-200)" }, children: /* @__PURE__ */ jsx("div", { "data-theme": inverseTheme, className: "bg-surface-raised text-foreground", children: /* @__PURE__ */ jsx(
      Notice,
      {
        variant,
        iconClassName: variant === "success" ? "text-success" : void 0,
        endContent: actionButton,
        onDismiss: dismiss,
        ...rest
      }
    ) }) });
  }
  const bg = variant === "warning" ? "bg-warning" : variant === "error" ? "bg-error" : "bg-info";
  const theme = variant === "warning" ? "light" : "dark";
  return /* @__PURE__ */ jsx("div", { role: liveRole, "aria-live": liveLevel, className: "rounded-lg overflow-hidden", style: { boxShadow: "var(--elevation-200)" }, children: /* @__PURE__ */ jsx("div", { className: bg, children: /* @__PURE__ */ jsx("div", { "data-theme": theme, className: "text-foreground", children: /* @__PURE__ */ jsx(Notice, { variant, endContent: actionButton, onDismiss: dismiss, ...rest }) }) }) });
}
function toast(options) {
  const { duration = 4e3, ...rest } = options;
  return toast$1.custom((id) => /* @__PURE__ */ jsx(ToastInner, { id, ...rest }), { duration });
}
const Toaster = React.forwardRef(
  ({ position = "bottom-right", ...props }, _ref) => {
    return /* @__PURE__ */ jsx(
      Toaster$1,
      {
        position,
        toastOptions: { unstyled: true, className: "w-[360px]" },
        ...props
      }
    );
  }
);
Toaster.displayName = "Toaster";
const toastMeta = {
  component: "Toast",
  family: 2,
  // Family 2(List item layout)— 透過 Notice 繼承,對齊 toast.spec.md frontmatter L3 + L39
  variants: {
    neutral: { when: "非狀態通知;一般 announcement / tip" },
    info: { when: "資訊性提示(新版本 / 同步完成)" },
    success: { when: "成功確認(已寄送 / 付款完成)" },
    warning: { when: "可恢復警告(未儲存 / 連線不穩)" },
    error: { when: "錯誤(匯入失敗 / 權限不足);action prop 可加重試" }
  },
  sizes: {},
  states: ["default", "hover", "active", "focus-visible", "disabled"],
  tokens: {
    bg: ["bg-error", "bg-info", "bg-surface-raised", "bg-warning"],
    fg: ["text-foreground"],
    ring: []
  }
};
export {
  Toaster,
  toast,
  toastMeta
};
//# sourceMappingURL=toast.js.map
