/**
 * Simple toast API for app notifications. Uses PrimeVue Toast under the hood.
 * Use this instead of useToast from primevue so views don't depend on PrimeVue directly.
 *
 * @example
 * const toast = useBaseToast();
 * toast.success('Saved.');
 * toast.error('Something went wrong');
 */

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 }),
  };
}
