import { Flag, FlagProps } from '../flag';
import { toast, type ToastOptions } from 'react-toastify';

function capitalizeText(text: string) {
  return (
    text
      ?.split(' ')
      .map((word) => word.charAt(0).toUpperCase() + word.slice(1))
      .join(' ') || ''
  );
}

export default function customToast(
  message: string,
  type: FlagProps['variant'],
  title?: string,
  options: ToastOptions<unknown> = {},
) {
  toast(
    <div className="w-full overflow-hidden rounded">
      <Flag variant={type} title={title ?? capitalizeText(type)} desc={message} />
    </div>,
    {
      delay: 1000,
      ...options,
    },
  );
}
