import {
  RiCheckboxCircleFill,
  RiErrorWarningFill,
  RiInformationFill,
} from '@remixicon/react';
import { toast } from 'sonner';
import {
  Alert,
  AlertIcon,
  AlertTitle,
} from '@rutatiina/ui/components/ui/alert';

type Tone = 'success' | 'destructive' | 'info' | 'warning';

function show(message: string, tone: Tone) {
  const Icon =
    tone === 'success'
      ? RiCheckboxCircleFill
      : tone === 'info'
        ? RiInformationFill
        : RiErrorWarningFill;

  toast.custom(
    (t) => (
      <Alert
        variant="mono"
        icon={tone}
        close={tone !== 'success'}
        onClose={() => toast.dismiss(t)}
      >
        <AlertIcon>
          <Icon />
        </AlertIcon>
        <AlertTitle>{message}</AlertTitle>
      </Alert>
    ),
    { position: 'top-center' },
  );
}

/** Larabase-styled toasts (the "mono" alert used across the original Next.js demo). */
export const notify = {
  success: (message: string) => show(message, 'success'),
  error: (message: string) => show(message, 'destructive'),
  info: (message: string) => show(message, 'info'),
  warning: (message: string) => show(message, 'warning'),
};
