export default defineNuxtRouteMiddleware((to) => {
  const redirects: Record<string, string> = {
    '/component-catalog': '/catalogues/composants',
    '/pieces-catalog': '/catalogues/pieces',
    '/product-catalog': '/catalogues/produits',
  }

  // Exact path match redirects
  const redirect = redirects[to.path]
  if (redirect) {
    return navigateTo({ path: redirect, query: to.query }, { redirectCode: 301 })
  }

  // Category index redirects (add tab=categories query param)
  if (to.path === '/component-category') {
    return navigateTo({ path: '/catalogues/composants', query: { ...to.query, tab: 'categories' } }, { redirectCode: 301 })
  }
  if (to.path === '/piece-category') {
    return navigateTo({ path: '/catalogues/pieces', query: { ...to.query, tab: 'categories' } }, { redirectCode: 301 })
  }
  if (to.path === '/product-category') {
    return navigateTo({ path: '/catalogues/produits', query: { ...to.query, tab: 'categories' } }, { redirectCode: 301 })
  }
})
