/**
 * Toast host.
 *
 * The shadcn original reads the theme from `next-themes`, which PIG does not
 * use — it has its own provider so a user's choice can be persisted server-side
 * and follow them between devices. Importing next-themes here would have thrown
 * at module load, which is why the Toaster was never mounted and every mutation
 * in the app completed in silence.
 *
 * Rewired to PIG's `useTheme`, which already resolves `system` to a concrete
 * light or dark value.
 */
import { Toaster as Sonner, type ToasterProps } from 'sonner';
import { useTheme } from '@/lib/theme';

export function Toaster(props: ToasterProps) {
  const { resolved } = useTheme();

  return (
    <Sonner
      theme={resolved}
      className="toaster group"
      // Above the sheets and dialogs it confirms, and clear of the phone tab
      // bar and the home indicator beneath it.
      position="bottom-right"
      offset="1rem"
      style={{ marginBottom: 'calc(var(--safe-bottom) + 4rem)' }}
      toastOptions={{
        classNames: {
          toast:
            'group toast group-[.toaster]:bg-surface group-[.toaster]:text-fg ' +
            'group-[.toaster]:border-border group-[.toaster]:shadow-lg',
          description: 'group-[.toast]:text-muted',
          actionButton: 'group-[.toast]:bg-primary group-[.toast]:text-primary-foreground',
          cancelButton: 'group-[.toast]:bg-surface-2 group-[.toast]:text-muted',
          error: 'group-[.toaster]:text-danger',
          success: 'group-[.toaster]:text-positive',
        },
      }}
      {...props}
    />
  );
}
