// Port of shadcn's `sonner.tsx`, which itself is a thin wrapper around the
// `sonner` npm package's `<Toaster>` (plus `next-themes`' `useTheme`).
//
// DEVIATION FROM SOURCE (documented per task instructions): we do NOT add the
// `sonner` dependency. `sonner` ships its own toast *store* + stacking engine
// + DOM renderer; this repo already has an equivalent engine in
// `../toast/store.ts` + `../toast/toast.marko` + `../toast/toast-item.marko`,
// built on `@zag-js/toast`. This file is a thin Toaster tag over THAT
// machinery, arranged to emit the DOM hooks sonner's consumers expect:
//   - the literal `"toaster group"` class on the root region (source line 19)
//   - sonner's five status icons (source lines 20-26): already inlined as
//     lucide SVG paths in `../toast/toast-item.marko` (its
//     `data-slot="toast-icon"` blocks, one per Zag `type`), reused unchanged
//     here — no `lucide-react`/`lucide` dependency is added by this file or
//     that one
//   - the same four `--normal-*`/`--border-radius` CSS custom properties,
//     wired to the same shadcn theme tokens (source lines 27-34)
//   - `{...rest}` spread last, so callers can override anything
//
// WHAT MAPS AND WHAT'S INERT, precisely:
//   - `class` / `style`: LIVE. Merged onto the toaster root exactly as the
//     source merges them onto sonner's `<Toaster>` root.
//   - `theme`: INERT for rendering. Our toast machinery has no light/dark
//     skinning switch of its own — like every other component in this
//     registry it inherits theme from the app's `.dark` class / CSS
//     variables (see `direction-provider.marko` for the project's stance on
//     the absence of a React-context/next-themes equivalent). The prop is
//     still accepted and threaded into `style` as `--sonner-theme` (a
//     harmless custom property, matching nothing in our CSS) purely so a
//     caller migrating from real sonner doesn't get a type error passing it.
//   - `position` (e.g. "top-center"): INERT here. Placement in our machinery
//     is a `Toaster` `Input` prop (`placement`, forwarded to the Zag GROUP
//     machine via `store.ts`'s `createStore({ placement })`), not a per-call
//     sonner prop — sonner's own default is also `"bottom-right"` vs. this
//     registry's toast store default of `"bottom-end"` (RTL-aware logical
//     equivalent). Not wired: changing placement per-`<Toaster>` mount would
//     require re-creating the module-level store, which every trigger
//     (`toast.success(...)` etc.) across the app already closes over.
//   - `richColors`: INERT. Our `toast-item.marko` already hard-codes
//     per-type accent colors (emerald/destructive/amber/blue, see that
//     file's `data-[type=...]` rules) unconditionally — there is no "muted"
//     mode to toggle away from, so there is nothing for this flag to turn on.
//   - `closeButton`, `duration`, `visibleToasts`, `expand`, `gap`, `offset`,
//     `dir`, `icons`, `toastOptions`, `swipeDirections`, `hotkey`: NOT
//     supported as props on this tag. Each has a real analogue somewhere in
//     `store.ts`'s `createStore()` options or per-toast `ToastOptions`
//     instead (module-level store config, or per-`toast.*()` call), which is
//     the correct layer for this codebase's architecture; exposing them here
//     as no-op props would be actively misleading rather than merely inert,
//     so they are omitted from `Input` entirely.
//
// Everything else — the group region itself, individual toast stacking,
// dismiss/action buttons, promise-driven toasts — is `<Toaster>` +
// `<ToastItem>` from `../toast/`, unchanged.
import { cn } from "#lib/utils.ts";
import Toaster from "../toast/toast.marko";
import { sonner as styles } from "./classes.ts";

export interface Input extends Marko.Input<"div"> {
  /**
   * Accepted for source-shape parity with sonner's `ToasterProps["theme"]`.
   * INERT: see file header. Threaded into `style` as `--sonner-theme` only.
   */
  theme?: "light" | "dark" | "system";
}

<const/{ class: className, style, theme, ...rest }=input/>

<Toaster
  ...rest
  toastClass=styles.toast
  class=cn(styles.root, className)
  // An ARRAY, not an object spread: Marko's `style` attribute accepts a
  // string, an object, or an array of those, and merges an array left to
  // right. `...style` assumed it was always an object, which is a type error
  // (and would silently drop a caller's `style="..."` string at runtime).
  style=[
    {
      "--normal-bg": "var(--popover)",
      "--normal-text": "var(--popover-foreground)",
      "--normal-border": "var(--border)",
      "--border-radius": "var(--radius)",
      "--sonner-theme": theme ?? "system",
    },
    style,
  ]
/>
