import {
  Toast,
  ToastClose,
  ToastDescription,
  ToastProvider,
  ToastTitle,
  ToastViewport,
} from "@/components/ui/toast";
import { useToast } from "@/components/ui/use-toast";

export function Toaster() {
  const { toasts } = useToast();

  return (
    <ToastProvider>
      {toasts.map(function ({
        id,
        title,
        description,
        descriptionClassName,
        action,
        domain,
        ...props
      }) {
        return (
          <ToastViewport key={id} position={props.position}>
            <Toast {...props} domain={domain}>
              <div className="grid">
                {title && <ToastTitle>{title}</ToastTitle>}
                {description && (
                  <ToastDescription className={descriptionClassName}>
                    {description}
                  </ToastDescription>
                )}
              </div>
              {action}
              <ToastClose />
            </Toast>
          </ToastViewport>
        );
      })}
    </ToastProvider>
  );
}
