import type { RouteRecordRaw } from 'vue-router'

const routes: RouteRecordRaw[] = [
  {
    path: '/',
    component: () => import('layouts/MainLayout.vue'),
    children: [
      {
        path: '',
        redirect: { name: 'projects' }
      },
      {
        name: 'projects',
        path: '/projects',
        component: () => import('pages/ProjectsPage.vue'),
        meta: { 
          hideBackButton: true,
          requiresAuth: true
        }
      },
      {
        name: 'project_add',
        path: '/project/add',
        component: () => import('pages/ProjectAddPage.vue'),
        meta: { requiresAuth: true }
      },
      {
        name: 'project_info',
        path: '/project/:id(\\d+)/info',
        component: () => import('pages/ProjectEditPage.vue'),
        meta: { requiresAuth: true }
      },
      {
        name: 'company_mask',
        path: '/project/:id(\\d+)/company-mask',
        component: () => import('pages/CompanyMaskPage.vue'),
        meta: { requiresAuth: true }
      },
      {
        path: '/project/:id(\\d+)',
        component: () => import('pages/ProjectPage.vue'),
        meta: { requiresAuth: true },
        children: [
          {
            name: 'project',
            path: '',
            redirect: { name: 'chats' }
          },
          {
            name: 'chats',
            path: 'chats',
            component: () => import('pages/project-page/ProjectPageChats.vue'),
            meta: { 
              backRoute: 'projects',
              requiresAuth: true
            }
          },
          {
            name: 'users',
            path: 'users',
            component: () => import('pages/project-page/ProjectPageUsers.vue'),
            meta: { 
              backRoute: 'projects',
              requiresAuth: true
            }
          },
          {
            name: 'companies',
            path: 'companies',
            component: () => import('pages/project-page/ProjectPageCompanies.vue'),
            meta: { 
              backRoute: 'projects',
              requiresAuth: true
            }
          }
        ]
      },
      {
        name: 'add_company',
        path: '/project/:id(\\d+)/add-company',
        component: () => import('pages/CompanyAddPage.vue'),
        meta: { requiresAuth: true }
      },
      {
        name: 'company_info',
        path: '/project/:id(\\d+)/company/:companyId',
        component: () => import('pages/CompanyEditPage.vue'),
        meta: { requiresAuth: true }
      },
      {
        name: 'user_info',
        path: '/project/:id(\\d+)/user/:userId',
        component: () => import('pages/UserEditPage.vue'),
        meta: { requiresAuth: true }
      },
      {
        name: 'account',
        path: '/account',
        component: () => import('pages/AccountPage.vue'),
        meta: { requiresAuth: true }
      },
      {
        name: 'create_account',
        path: '/create-account',
        component: () => import('pages/AccountCreatePage.vue'),
        meta: { guestOnly: true }
      },
      {
        name: 'change_account_password',
        path: '/change-password',
        component: () => import('pages/AccountChangePasswordPage.vue'),
        meta: { requiresAuth: true }
      },
      {
        name: 'change_account_email',
        path: '/change-email',
        component: () => import('pages/AccountChangeEmailPage.vue'),
        meta: { requiresAuth: true }
      },
      {
        name: 'change_account_auth_method',
        path: '/change-auth-method',
        component: () => import('pages/AccountChangeAuthMethodPage.vue'),
        meta: { requiresAuth: true }
      },
      {
        name: 'subscribe',
        path: '/subscribe',
        component: () => import('pages/account/SubscribePage.vue'),
        meta: { requiresAuth: true }
      },
      {
        name: '3software',
        path: '/3software',
        component: () => import('pages/account/3Software.vue'),
      },
      {
        name: 'terms',
        path: '/terms-of-use',
        component: () => import('pages/account/TermsPage.vue'),
      },
      {
        name: 'privacy',
        path: '/privacy',
        component: () => import('pages/account/PrivacyPage.vue'),
      },
      {
        name: 'support',
        path: '/support',
        component: () => import('src/pages/account/SupportPage.vue'),
      },
      {
        name: 'your_company',
        path: '/your-company',
        component: () => import('pages/CompanyYourPage.vue'),
        meta: { requiresAuth: true }
      },
      {
        name: 'login',
        path: '/login',
        component: () => import('pages/LoginPage.vue'),
        meta: { 
          hideBackButton: true,
          guestOnly: true
        }
      },
      {
        name: 'recovery_password',
        path: '/recovery-password',
        component: () => import('pages/AccountForgotPasswordPage.vue'),
        meta: { guestOnly: true }
      },
      {
        name: 'settings',
        path: '/settings',
        component: () => import('pages/account/SettingsPage.vue'),
        meta: { requiresAuth: true }
      }
    ]
  },
  {
    path: '/:catchAll(.*)*',
    component: () => import('pages/ErrorNotFound.vue'),
  }
]

export default routes