import { Navigate, useLocation } from 'react-router-dom'
import { brandIdFromSearch } from '../lib/placementFlow'
import { CopyMatrixPage } from '../pages/CopyMatrixPage'

/** /matrix：無 brand 參數為流程 A；舊書籤 ?brand= 導向 /brand-matrix */
export function MatrixEntryRoute() {
  const { search } = useLocation()
  const brandId = brandIdFromSearch(search)
  if (brandId) {
    return <Navigate to={`/brand-matrix?brand=${encodeURIComponent(brandId)}`} replace />
  }
  return <CopyMatrixPage />
}