import { buildRoutesWithDynamicContent } from './helpers';
import { SUPERADMIN_ROUTES } from './superadmin-routes';

const routes = [
  {
    path: '/login',
    component: () => import('layouts/LoginLayout.vue'),
    children: [
      { path: '', component: () => import('pages/auth/Login.vue') },
      { path: 'new-password/:token', component: () => import('pages/auth/NewPass.vue') },
    ],
  },
  { path: '/logout', component: () => import('pages/auth/Logout.vue') },

  {
    path: '/',
    component: () => import('layouts/MainLayout.vue'),
    meta: {
      requiresAuth: true,
    },
    children: [
      ...buildRoutesWithDynamicContent('captaciones', { idKey: 'ID_CAPTACION', ca: [59, 14], dynamicDetail: true, dynamicList: false }),
      ...buildRoutesWithDynamicContent('productos', { idKey: 'ID_PRODUCTO', ca: [279], dynamicDetail: true, dynamicList: false }),
      ...buildRoutesWithDynamicContent('partners', { idKey: 'ID_PARTNER', dynamicDetail: true, dynamicList: true }),
      ...buildRoutesWithDynamicContent('usuarios', { idKey: 'ID_USUARIO', ca: [280] }),
      ...buildRoutesWithDynamicContent('clientes', { idKey: 'ID_CLIENTE', ca: [10] }),
      ...buildRoutesWithDynamicContent('planificacion', { idKey: 'ID_PLANIFICACION' }),
      ...buildRoutesWithDynamicContent('proveedores', { idKey: 'ID_PROVEEDOR' }),
      ...buildRoutesWithDynamicContent('operacion', { idKey: 'ID_USUARIO' }),
      ...buildRoutesWithDynamicContent('llamadas', { idKey: 'ID_LLAMADA' }),
      { path: '/captacion_estudio/:ID_CAPTACION', redirect: (to) => ({ path: `/captaciones/${to.params.ID_CAPTACION}` }) },
      { path: '/roles', component: () => import('pages/Roles.vue'), meta: { ca: [2] } },
      { path: '/roles/:TIPO', component: () => import('pages/Roles.vue'), meta: { ca: [2] } },
      { path: '/paises', component: () => import('pages/Paises.vue'), meta: { ca: [264] } },
      { path: '/pais/:ID_PAIS', component: () => import('pages/PaisDetalle.vue'), meta: { ca: [264] } },
      { path: '/zonas_paises', component: () => import('pages/PaisesZonas.vue'), meta: { ca: [264] } },
      { path: '/marketing', component: () => import('pages/MarketingPage.vue'), meta: { ca: [271] } },
      { path: '/delegaciones', component: () => import('pages/delegaciones/DelegacionesPage.vue'), meta: { ca: [46] } },
      {
        path: '/delegacion',
        meta: { ca: [46] },
        children: [
          {
            path: ':ID_DELEGACION',
            component: () => import('pages/delegaciones/DelegacionPage.vue'),
            children: [
              { path: '', redirect: (to) => ({ path: `${to.path}/estado` }) },
              { path: ':tab', component: () => import('pages/delegaciones/DelegacionDetalle.vue') },
            ],
          },
        ],
      },
      {
        path: '/comerciales',
        meta: { ca: [280] },
        component: () => import('pages/comerciales/Page.vue'),
        children: [
          { path: '', component: () => import('pages/comerciales/Table.vue') },
          {
            path: ':ID_USUARIO',
            component: () => import('src/pages/comerciales/ComercialPage.vue'),
            children: [
              { path: '', redirect: (to) => ({ path: `${to.path}/contacto` }) },
              { path: ':tab', component: () => import('pages/comerciales/Detalle.vue') },
            ],
          },
        ],
      },
      {
        path: '/gerentes',
        meta: { ca: [280] },
        component: () => import('pages/gerentes/Page.vue'),
        children: [
          { path: '', component: () => import('pages/gerentes/Table.vue') },
          {
            path: ':ID_USUARIO',
            component: () => import('src/pages/gerentes/GerentePage.vue'),
            children: [
              { path: '', redirect: (to) => ({ path: `${to.path}/contacto` }) },
              { path: ':tab', component: () => import('pages/gerentes/Detalle.vue') },
            ],
          },
        ],
      },
      {
        path: '/organizadores',
        meta: { ca: [280] },
        component: () => import('pages/organizadores/Page.vue'),
        children: [
          { path: '', component: () => import('pages/organizadores/Table.vue') },
          {
            path: ':ID_USUARIO',
            component: () => import('src/pages/organizadores/OrganizadorPage.vue'),
            children: [
              { path: '', redirect: (to) => ({ path: `${to.path}/contacto` }) },
              { path: ':tab', component: () => import('pages/organizadores/Detalle.vue') },
            ],
          },
        ],
      },
      {
        path: '/liquidaciones',
        meta: { ca: [251] },
        component: () => import('pages/liquidaciones/LiquidacionesPage.vue'),
        children: [
          { path: '', redirect: (to) => ({ path: `${to.path}/red_comercial` }) },
          {
            path: 'red_comercial',
            component: () => import('pages/liquidaciones/red_comercial/LiquidacionesRedComercial.vue'),
          },
          {
            path: 'solicitudes_clientes',
            component: () => import('pages/liquidaciones/solicitudes/LiquidacionesSolicitudesClientesTable.vue'),
          },
          { path: 'reglas', component: () => import('pages/liquidaciones/reglas/ReglasLiquidacionTable.vue') },
          { path: 'comisiones', component: () => import('pages/liquidaciones/comisiones/ComisionesLiquidacionTable.vue') },
          { path: 'situaciones', component: () => import('pages/liquidaciones/situaciones/SituacionesLiquidacionTable.vue') },
          {
            path: ':ID_LIQUIDACION',
            component: () => import('pages/liquidaciones/detalle/LiquidacionPage.vue'),
            children: [
              { path: '', redirect: (to) => ({ path: `${to.path}/resumen` }) },
              { path: 'resumen', component: () => import('pages/liquidaciones/detalle/LiquidacionResumen.vue') },
              { path: 'detalle', component: () => import('pages/liquidaciones/detalle/LiquidacionDetalle.vue') },
              { path: 'reclamos', component: () => import('pages/liquidaciones/detalle/reclamos/LiquidacionReclamos.vue') },
            ],
          },
        ],
      },
      {
        path: '/mis_liquidaciones',
        component: () => import('pages/mis_liquidaciones/MisLiquidacionesPage.vue'),
        children: [
          { path: '', component: () => import('pages/mis_liquidaciones/List.vue') },
          { path: ':ID_LIQUIDACION', component: () => import('pages/mis_liquidaciones/Liquidacion.vue') },
          { path: ':ID_LIQUIDACION/reclamar/:ID_PROMOTOR', component: () => import('pages/mis_liquidaciones/Reclamar.vue') },
        ],
      },
      { path: '/perfil', component: () => import('pages/Profile.vue') },
      { path: '/contactos', meta: { ca: [78] }, component: () => import('src/pages/Contactos.vue') },
      {
        path: '/escaparates',
        meta: { ca: [281] },
        component: () => import('pages/escaparates/EscaparatesPage.vue'),
        children: [
          {
            path: '',
            redirect: (to) => ({ path: `${to.path}/dispositivos` }),
          },
          {
            path: 'canales',
            component: () => import('pages/escaparates/canales/CanalesList.vue'),
          },
          {
            path: 'dispositivos',
            component: () => import('pages/escaparates/dispositivos/DispositivosList.vue'),
          },
          {
            path: 'etiquetas',
            component: () => import('pages/escaparates/etiquetas/EtiquetasList.vue'),
          },
        ],
      },

      {
        path: '/mapa',
        component: () => import('src/pages/maps/SeduvisMapPage.vue'),
      },

      ...SUPERADMIN_ROUTES,
    ],
  },

  {
    path: '/403',
    component: () => import('pages/error/Error403.vue'),
  },

  {
    path: '/:catchAll(.*)',
    component: () => import('pages/error/Error404.vue'),
  },
];

export default routes;
