import { useEffect } from 'react'
import { useAllProducts } from './prominent-api-hooks'
import { useCentralProductStore } from '../lib/stores/central-product-store'

export function usePopulateCentralProductStore() {
  const { data: productsData } = useAllProducts()
  const setProducts = useCentralProductStore((state) => state.setProducts)

  useEffect(() => {
    if (productsData?.products) {
      setProducts(productsData.products)
    }
  }, [productsData, setProducts])
}
