import { createRouter, createWebHistory } from 'vue-router'

const routes = [
  { path: '/', name: 'home', component: () => import('@/views/HomeView.vue'), meta: { title: 'RisingCompute — Accelerating the compute' } },
  { path: '/about', name: 'about', component: () => import('@/views/AboutView.vue'), meta: { title: 'About — RisingCompute' } },
  { path: '/products', name: 'products', component: () => import('@/views/ProductsView.vue'), meta: { title: 'Products — RisingCompute' } },
  { path: '/products/:slug', name: 'product-detail', component: () => import('@/views/ProductDetailView.vue'), meta: { title: 'Product — RisingCompute' } },
  { path: '/technology', name: 'technology', component: () => import('@/views/TechnologyView.vue'), meta: { title: 'Technology — RisingCompute' } },
  { path: '/careers', name: 'careers', component: () => import('@/views/CareersView.vue'), meta: { title: 'Careers — RisingCompute' } },
  { path: '/blog', name: 'blog', component: () => import('@/views/BlogView.vue'), meta: { title: 'Insights — RisingCompute' } },
  { path: '/blog/:slug', name: 'blog-post', component: () => import('@/views/BlogPostView.vue'), meta: { title: 'Insights — RisingCompute' } },
  { path: '/contact', name: 'contact', component: () => import('@/views/ContactView.vue'), meta: { title: 'Talk to us — RisingCompute' } },
  { path: '/:pathMatch(.*)*', name: 'not-found', component: () => import('@/views/NotFoundView.vue'), meta: { title: 'Not found — RisingCompute' } },
]

const router = createRouter({
  history: createWebHistory(),
  routes,
  scrollBehavior(to, from, saved) {
    if (saved) return saved
    if (to.hash) return { el: to.hash, behavior: 'smooth' }
    return { top: 0 }
  },
})

router.afterEach((to) => {
  if (to.meta?.title) document.title = to.meta.title
})

export default router
