import { create } from "zustand";
import { devtools, persist } from "zustand/middleware";
import type { Product } from "@/lib/products";

interface ProductStore {
  productName: string;
  setProductName: (name: string) => void;
  resetProductName: () => void;
}

export const useProductStore = create<ProductStore>()(
  devtools((set) => ({
    productName: "",
    setProductName: (name: string) => set({ productName: name }),
    resetProductName: () => set({ productName: "" }),
  }))
);

interface ProductDetail {
  product: Product | null;
  setProducts: (product: Product) => void;
}

export const useProduct = create<ProductDetail>()(
  devtools(
    persist(
      (set) => ({
        product: null,
        setProducts: (product: Product) => set({ product }),
      }),
      {
        name: "product-detail-storage",
      }
    )
  )
);
