import { useEffect } from 'react'
import { Navigate, useParams } from 'react-router-dom'
import { rememberBrandId } from '../lib/brandContext'

export function LegacyBrandRouteRedirect({ to }: { to: string }) {
  const { id = '' } = useParams()

  useEffect(() => {
    if (id) rememberBrandId(id)
  }, [id])

  return <Navigate to={id ? `${to}?brand=${encodeURIComponent(id)}` : to} replace />
}