import { useToast } from "primevue/usetoast";

const DEFAULT_LIFE = 3000;

const DEFAULT_SUMMARIES_NL = {
  success: "Succes",
  error: "Fout",
  info: "Info",
  warn: "Waarschuwing",
};

export function useBaseToast() {
  const toast = useToast();

  function add(severity, detail, summary = null, life = DEFAULT_LIFE) {
    const fallback =
      DEFAULT_SUMMARIES_NL[severity] ??
      severity.charAt(0).toUpperCase() + severity.slice(1);
    const summaryText = summary ?? fallback;
    toast.add({ severity, summary: summaryText, detail, life });
  }

  return {
    success: (detail, summary, life) => add("success", detail, summary, life),
    error: (detail, summary, life) =>
      add("error", detail, summary, life ?? 4000),
    info: (detail, summary, life) => add("info", detail, summary, life),
    warn: (detail, summary, life) => add("warn", detail, summary, life),
    add: (options) => toast.add({ life: DEFAULT_LIFE, ...options }),
  };
}
