/**
 * Hook for showing toast notifications
 */

import { useCallback } from "react";

import { useToastStore, type ToastVariant } from "@/stores/toastStore";

interface ToastOptions {
  description?: string;
}

function createToastHelper(variant: ToastVariant, show: ReturnType<typeof useToastStore.getState>["show"]) {
  return (title: string, options?: ToastOptions) => {
    show({ title, description: options?.description, variant });
  };
}

export function useToast() {
  const show = useToastStore((state) => state.show);

  const success = useCallback(createToastHelper("success", show), [show]);
  const error = useCallback(createToastHelper("error", show), [show]);
  const info = useCallback(createToastHelper("info", show), [show]);

  return { success, error, info };
}
