'use client'

// PBI-75: URL-deeplink → store sync voor sprint task-edit.
//
// Patroon spiegelt components/backlog/url-task-sync.tsx: zodra de route
// `?editTask=<id>` draagt, schrijven we de taak-hint en roepen we
// setActiveTask aan op de sprint-workspace-store. De dialog wordt
// vervolgens client-side gemount door SprintTaskDialogMount.

import { useEffect } from 'react'
import { useSearchParams } from 'next/navigation'
import { useSprintWorkspaceStore } from '@/stores/sprint-workspace/store'
import { writeTaskHint } from '@/stores/sprint-workspace/restore'

export function SprintUrlTaskSync() {
  const searchParams = useSearchParams()
  const editTask = searchParams.get('editTask')

  useEffect(() => {
    if (!editTask) return
    const sprintId = useSprintWorkspaceStore.getState().context.activeSprintId
    if (sprintId) {
      writeTaskHint(sprintId, editTask)
    }
    useSprintWorkspaceStore.getState().setActiveTask(editTask)
  }, [editTask])

  return null
}
