import { create } from "zustand";
import type { Project } from "../lib/commands";

interface UIState {
  // Toast
  toast: string | null;
  showToast: (msg: string, duration?: number) => void;

  // Project modal
  editTarget: Project | null | undefined; // undefined = closed, null = new, obj = edit
  openEdit: (project?: Project | null) => void;
  closeEdit: () => void;
}

export const useUIStore = create<UIState>((set) => ({
  toast: null,
  showToast: (msg, duration = 2500) => {
    set({ toast: msg });
    setTimeout(() => set({ toast: null }), duration);
  },

  editTarget: undefined,
  openEdit: (project) => set({ editTarget: project ?? null }),
  closeEdit: () => set({ editTarget: undefined }),
}));
