'use client';

import { useEffect, useRef } from 'react';
import { AppToast } from '@/app/components/AppToast';
import type { Toast } from 'primereact/toast';
import { useToastStore } from '@/store/toastStore';

export default function GlobalToast() {
  const toastRef = useRef<Toast>(null);
  const current = useToastStore((s) => s.current);
  const nonce = useToastStore((s) => s.nonce);

  useEffect(() => {
    if (!current) return;
    toastRef.current?.show(current);
  }, [current, nonce]);

  return <AppToast ref={toastRef} position="top-right" />;
}
