import { createRouter, createWebHistory } from 'vue-router' import { useAuthStore } from '@/stores/auth' const routes = [ { path: '/login', name: 'Login', component: () => import('@/views/LoginView.vue'), meta: { guest: true } }, { path: '/', component: () => import('@/layouts/AppLayout.vue'), meta: { requiresAuth: true }, children: [ { path: '', name: 'Dashboard', component: () => import('@/views/DashboardView.vue') }, { path: 'inbox', name: 'Inbox', component: () => import('@/views/InboxView.vue') }, { path: 'leads', name: 'Leads', component: () => import('@/views/ContactsView.vue') // Uses contacts view for now }, { path: 'contacts', name: 'Contacts', component: () => import('@/views/ContactsView.vue') }, { path: 'contacts/:id', name: 'ContactDetail', component: () => import('@/views/ContactDetailView.vue') }, { path: 'companies', name: 'Companies', component: () => import('@/views/CompaniesView.vue') }, { path: 'companies/:id', name: 'CompanyDetail', component: () => import('@/views/CompanyDetailView.vue') }, { path: 'pipeline', name: 'Pipeline', component: () => import('@/views/PipelineView.vue') }, { path: 'deals/:id', name: 'DealDetail', component: () => import('@/views/DealDetailView.vue') }, { path: 'activities', name: 'Activities', component: () => import('@/views/ActivitiesView.vue') }, { path: 'settings', name: 'Settings', component: () => import('@/views/SettingsView.vue') }, { path: 'team', name: 'Team', component: () => import('@/views/UsersView.vue'), meta: { roles: ['owner', 'admin'] } } ] }, { path: '/:pathMatch(.*)*', redirect: '/' } ] const router = createRouter({ history: createWebHistory(), routes }) router.beforeEach((to, from, next) => { const auth = useAuthStore() if (to.meta.requiresAuth && !auth.isAuthenticated) { next('/login') } else if (to.meta.guest && auth.isAuthenticated) { next('/') } else { next() } }) export default router