"use client"

import { useEffect } from "react"
import { usePlayer } from "@/components/player-provider"
import { useUser } from "@/components/user-provider"

export function HistorySync() {
  const { setOnTrackPlay } = usePlayer()
  const { addToHistory } = useUser()

  useEffect(() => {
    setOnTrackPlay((track) => {
      addToHistory(track)
    })

    return () => {
      setOnTrackPlay(undefined)
    }
  }, [setOnTrackPlay, addToHistory])

  return null
}
