'use client'

import { useEffect } from 'react'
import { useProductWorkspaceStore } from '@/stores/product-workspace/store'
import { debugProps } from '@/lib/debug'

// PBI-74 / T-853: workspace-store is nu enige bron voor active product.
// De voorganger (stores/product-store.ts) wordt in Story 8 (T-876) verwijderd.
export function SetCurrentProduct({ id, name }: { id: string; name: string }) {
  useEffect(() => {
    useProductWorkspaceStore
      .getState()
      .setActiveProduct({ id, name }, { load: false, preserveSelection: true })
    return () => {
      useProductWorkspaceStore.getState().setActiveProduct(null, { load: false })
    }
  }, [id, name])

  return <span {...debugProps('set-current-product')} hidden />
}
