'use client'

import { useEffect } from 'react'
import { useBacklogStore, type BacklogPbi, type BacklogStory, type BacklogTask } from '@/stores/backlog-store'

interface InitialData {
  pbis: BacklogPbi[]
  storiesByPbi: Record<string, BacklogStory[]>
  tasksByStory: Record<string, BacklogTask[]>
}

interface BacklogHydrationWrapperProps {
  initialData: InitialData
  children: React.ReactNode
}

export function BacklogHydrationWrapper({ initialData, children }: BacklogHydrationWrapperProps) {
  const setInitialData = useBacklogStore((s) => s.setInitialData)

  useEffect(() => {
    setInitialData(initialData)
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [])

  return <>{children}</>
}
