/**
 * Toast notification store
 *
 * Imperative API for showing snackbar-style feedback across the admin UI.
 */

import { create } from "zustand";
import { nanoid } from "nanoid";

export type ToastVariant = "success" | "error" | "info";

export interface ToastMessage {
  id: string;
  title: string;
  description?: string;
  variant: ToastVariant;
}

interface ToastStore {
  toasts: ToastMessage[];
  show: (toast: Omit<ToastMessage, "id">) => string;
  dismiss: (id: string) => void;
}

export const useToastStore = create<ToastStore>((set) => ({
  toasts: [],

  show: (toast) => {
    const id = nanoid();
    set((state) => ({
      toasts: [...state.toasts, { ...toast, id }],
    }));
    return id;
  },

  dismiss: (id) =>
    set((state) => ({
      toasts: state.toasts.filter((item) => item.id !== id),
    })),
}));
