import { activityLogsRoute } from 'src/modules/activityLogs'

// src/router/routes.js

const routes = [

  /* ==========================================================
   🌍 ROOT
  ========================================================== */
  {
    path: '/',
    redirect: '/login'
  },


  /* ==========================================================
   🔐 PUBLIC
  ========================================================== */
  {
    path: '/login',
    component: () => import('layouts/EmptyLayout.vue'),
    meta: { public: true },
    children: [
      {
        path: '',
        name: 'login',
        component: () => import('pages/MainPage.vue')
      }
    ]
  },

  {
    path: '/first-password-change',
    component: () => import('layouts/EmptyLayout.vue'),
    meta: { public: true },
    children: [
      {
        path: '',
        name: 'first-password-change',
        component: () => import('pages/FirstPasswordChange.vue')
      }
    ]
  },

  {
    path: '/password-reset/:token',
    component: () => import('layouts/EmptyLayout.vue'),
    meta: { public: true },
    children: [
      {
        path: '',
        name: 'password-reset',
        component: () => import('pages/ResetPassword.vue')
      }
    ]
  },

  /* ==========================================================
   🚫 UNAUTHORIZED
  ========================================================== */
  {
    path: '/unauthorized',
    component: () => import('layouts/EmptyLayout.vue'),
    children: [
      {
        path: '',
        name: 'unauthorized',
        component: () => import('pages/Unauthorized.vue')
      }
    ]
  },


  /* ==========================================================
   🏠 MAIN APP
  ========================================================== */
  {
    path: '/app',
    component: () => import('layouts/MainLayout.vue'),

    children: [

      /* ================= DASHBOARD ================= */

      {
        path: '',
        name: 'dashboard',
        component: () => import('pages/Dashboard.vue'),
        meta: {}
      },


      /* ================= PERMISSIONS ================= */

      {
        path: 'permissions',
        name: 'permissions',
        component: () => import('pages/PermissionMatrix.vue'),
        meta: { permission: 'system:read' }
      },

      {
        path: 'role-dept-permissions',
        name: 'role-dept-permissions',
        component: () => import('pages/RoleDepartmentPermissionGateway.vue'),
        meta: { permission: 'system:update' }
      },

      {
        path: 'role-dept-permissions/list',
        name: 'role-dept-permissions-list',
        component: () => import('pages/RoleDepartmentPermissionList.vue'),
        meta: { permission: 'system:update' }
      },

      {
        path: 'role-dept-permissions/editor',
        name: 'role-dept-permissions-editor',
        component: () => import('pages/RoleDepartmentPermissionPage.vue'),
        meta: { permission: 'system:update' }
      },

      {
        path: 'user-permissions',
        name: 'user-permissions',
        component: () => import('pages/UserPermissionPage.vue'),
        meta: { permission: 'system:update' }
      },

      /* ================= ACTIVITY LOGS ================= */

      activityLogsRoute,


      /* ================= FINANCE ================= */

      {
        path: 'statementofaccount',
        name: 'statementofaccount',
        component: () => import('pages/statementofaccount.vue'),
        meta: { permission: 'finance:view' }
      },

      {
        path: 'statementreport',
        name: 'statementreport',
        component: () => import('pages/StatementReport.vue'),
        meta: { permission: 'finance:view' }
      },

      {
        path: 'statementheaderreport',
        name: 'statementheaderreport',
        component: () => import('pages/StatementHeaderReport.vue'),
        meta: { permission: 'finance:view' }
      },

      {
        path: 'customer-balance-list',
        name: 'customer-balance-list',
        component: () => import('pages/CustomerBalanceList.vue'),
        meta: { permission: 'finance:view' }
      },
      {
        path: 'account-aging-statement',
        name: 'account-aging-statement',
        component: () => import('pages/AccountAgingStatement.vue'),
        meta: { permission: 'finance:view' }
      },
      {
        path: 'aged-customer-balance-list',
        name: 'aged-customer-balance-list',
        component: () => import('pages/AgingCustomerBalancelist.go.vue'),
        meta: { permission: 'finance:view' }
      },


      /* ================= USERS ================= */

      {
        path: 'users',
        name: 'user-gateway',
        component: () => import('pages/UserGateway.vue'),
        meta: { permission: 'user:view' }
      },

      {
        path: 'users/list',
        name: 'user-list',
        component: () => import('pages/UserList.vue'),
        meta: { permission: 'user:view' }
      },

      {
        path: 'users/new',
        name: 'user-new',
        component: () => import('pages/UserDetail.vue'),
        meta: {
          mode: 'new',
          permission: 'user:insert'
        }
      },

      {
        path: 'users/edit/:id',
        name: 'user-edit',
        component: () => import('pages/UserDetail.vue'),
        props: true,
        meta: {
          mode: 'edit',
          permission: 'user:update'
        }
      },

      {
        path: 'users/view/:id',
        name: 'user-view',
        component: () => import('pages/UserDetail.vue'),
        props: true,
        meta: {
          mode: 'view',
          permission: 'user:view'
        }
      },


      /* ================= TEST MAIL ================= */

      {
        path: 'test-mail',
        name: 'test-mail',
        component: () => import('pages/TestMail.vue'),
        meta: { permission: 'system:update', onlyUserIds: [5] }
      },

      {
        path: 'market-mail-mapping',
        name: 'market-mail-mapping',
        component: () => import('../pages/MarketMailMapping.vue'),
        meta: { permission: 'system:update' }
      },
      {
        path: 'costing-mail-mapping',
        name: 'costing-mail-mapping',
        component: () => import('../pages/CostingMailMapping.vue'),
        meta: { permission: 'system:update' }
      },
      {
        path: 'pricing-mail-mapping',
        name: 'pricing-mail-mapping',
        component: () => import('../pages/PricingMailMapping.vue'),
        meta: { permission: 'system:update' }
      },
      {
        path: 'order-price-list-mail-mapping',
        name: 'order-price-list-mail-mapping',
        component: () => import('../pages/OrderPriceListMailMapping.vue'),
        meta: { permission: 'system:update' }
      },
      {
        path: 'order-price-list-user-price-groups',
        name: 'order-price-list-user-price-groups',
        component: () => import('../pages/OrderPriceListUserPriceGroupMapping.vue'),
        meta: { permission: 'system:update' }
      },
      {
        path: 'language/translations',
        name: 'translation-table',
        component: () => import('pages/TranslationTable.vue'),
        meta: { permission: 'language:update' }
      },


      /* ================= ORDERS ================= */

      {
        path: 'order-gateway',
        name: 'order-gateway',
        component: () => import('pages/OrderGateway.vue'),
        meta: { permission: 'order:view' }
      },

      {
        path: 'order-entry/:orderHeaderID',
        name: 'order-entry',
        component: () => import('pages/OrderEntry.vue'),
        props: true,
        meta: {
          mode: 'new',
          permission: 'order:insert'
        }
      },

      {
        path: 'order-edit/:orderHeaderID',
        name: 'order-edit',
        component: () => import('pages/OrderEntry.vue'),
        props: true,
        meta: {
          mode: 'edit',
          permission: 'order:update'
        }
      },

      {
        path: 'order-list',
        name: 'order-list',
        component: () => import('pages/OrderList.vue'),
        meta: { permission: 'order:view' }
      },

      {
        path: 'orderproductionupdate',
        name: 'orderproductionupdate-list',
        component: () => import('pages/OrderProductionUpdateList.vue'),
        meta: { permission: 'order:update' }
      },
      {
        path: 'orderproductionupdate/:orderHeaderID',
        name: 'orderproductionupdate',
        component: () => import('pages/OrderProductionUpdate.vue'),
        props: true,
        meta: { permission: 'order:update' }
      },

      {
        path: 'order-bulk-close',
        name: 'order-bulk-close',
        component: () => import('pages/OrderBulkClose.vue'),
        meta: { permission: 'order:update' }
      },
      {
        path: 'order-price-list',
        name: 'order-price-list',
        component: () => import('pages/OrderPriceList.vue'),
        meta: { permission: 'order:view' }
      },

      {
        path: 'order-pdf/:id',
        name: 'order-pdf',
        component: () => import('pages/OrderPdf.vue'),
        props: true,
        meta: { permission: 'order:export' }
      },

      /* ================= PRODUCTS ================= */
      {
        path: 'product-stock-query',
        name: 'product-stock-query',
        component: () => import('pages/ProductStockQuery.vue'),
        meta: { permission: 'order:view' }
      },
      {
        path: 'product-stock-by-attributes',
        name: 'product-stock-by-attributes',
        component: () => import('pages/ProductStockByAttributes.vue'),
        meta: { permission: 'order:view' }
      },

      /* ================= PRICING ================= */ 
      // Backward-compatible redirects (old "pricing/production-product-costing" URLs). 
      { 
        path: 'pricing/production-product-costing', 
        redirect: { name: 'production-product-costing' } 
      }, 
      { 
        path: 'pricing/production-product-costing/has-cost', 
        redirect: { name: 'production-product-costing-has-cost' } 
      }, 
      { 
        path: 'pricing/production-product-costing/has-cost/history', 
        redirect: { name: 'production-product-costing-has-cost-history' } 
      }, 
      { 
        path: 'pricing/production-product-costing/has-cost/detail', 
        redirect: { name: 'production-product-costing-has-cost-detail' } 
      }, 
      { 
        path: 'pricing/production-product-costing/no-cost', 
        redirect: { name: 'production-product-costing-no-cost' } 
      }, 
      { 
        path: 'pricing/production-product-costing/maliyet-parca-eslestirme', 
        redirect: { name: 'production-product-costing-maliyet-parca-eslestirme' } 
      }, 
      { 
        path: 'pricing/production-product-costing/default-quantities', 
        redirect: { name: 'production-product-costing-default-quantities' } 
      }, 
      { 
        path: 'pricing/product-pricing', 
        name: 'product-pricing', 
        component: () => import('pages/ProductPricing.vue'), 
        meta: { permission: 'pricing:view' } 
      }, 
      {
        path: 'pricing/product-performance-profitability',
        name: 'product-performance-profitability',
        component: () => import('pages/ProductPerformanceProfitability.vue'),
        meta: { permission: 'pricing:view' }
      },
      { 
        path: 'pricing/brand-classification', 
        name: 'brand-classification', 
        component: () => import('pages/BrandClassification.vue'), 
        meta: { permission: 'pricing:view' } 
      }, 
      { 
        path: 'pricing/brandgroupcurrency',
        alias: ['pricing/brandproupcurrency', 'pricing/brand-group-currency'],
        name: 'brandgroupcurrency',
        component: () => import('pages/BrandGroupCurrency.vue'),
        meta: { permission: 'pricing:view' }
      },
      { 
        path: 'pricing/pricing-rules', 
        name: 'pricing-rules', 
        component: () => import('pages/PricingRules.vue'), 
        meta: { permission: 'pricing:view' } 
      }, 
      {
        path: 'pricing/wholesale-campaigns',
        name: 'wholesale-campaigns',
        component: () => import('pages/WholesaleCampaigns.vue'),
        meta: { permission: 'pricing:view' }
      },
      {
        path: 'pricing/product-series-mappings',
        name: 'product-series-mappings',
        component: () => import('pages/ProductSeriesMappings.vue'),
        meta: { permission: 'pricing:view' }
      },
      {
        path: 'pricing/product-series-mappings-orphans',
        name: 'product-series-mappings-orphans',
        component: () => import('pages/ProductSeriesMappingsOrphans.vue'),
        meta: { permission: 'pricing:view' }
      },
      {
        path: 'pricing/product-series-definitions',
        name: 'product-series-definitions',
        component: () => import('pages/ProductSeriesDefinitions.vue'),
        meta: { permission: 'pricing:view' }
      },
      { 
        path: 'costing/production-product-costing', 
        name: 'production-product-costing', 
        component: () => import('pages/ProductionProductCosting.vue'), 
        meta: { permission: 'costing:view' } 
      }, 
      { 
        path: 'costing/production-product-costing/has-cost', 
        name: 'production-product-costing-has-cost', 
        component: () => import('pages/ProductionProductCostingHasCost.vue'), 
        meta: { permission: 'costing:view' } 
      }, 
      { 
        path: 'costing/production-product-costing/has-cost/history', 
        name: 'production-product-costing-has-cost-history', 
        component: () => import('pages/ProductionProductCostingHasCostHistory.vue'), 
        meta: { permission: 'costing:view' } 
      }, 
      { 
        path: 'costing/production-product-costing/has-cost/detail', 
        name: 'production-product-costing-has-cost-detail', 
        component: () => import('pages/ProductionProductCostingHasCostDetail.vue'), 
        meta: { permission: 'costing:view' } 
      }, 
      { 
        path: 'costing/production-product-costing/no-cost', 
        name: 'production-product-costing-no-cost', 
        component: () => import('pages/ProductionProductCostingNoCost.vue'), 
        meta: { permission: 'costing:view' } 
      }, 
      { 
        path: 'costing/production-product-costing/maliyet-parca-eslestirme', 
        name: 'production-product-costing-maliyet-parca-eslestirme', 
        component: () => import('pages/ProductionProductCostingMTBolumMapping.vue'), 
        meta: { permission: 'costing:view' } 
      }, 
      { 
        path: 'costing/production-product-costing/default-quantities', 
        name: 'production-product-costing-default-quantities', 
        component: () => import('pages/ProductionProductCostingDefaultQuantities.vue'), 
        meta: { permission: 'costing:view' } 
      }, 


      /* ================= PASSWORD ================= */

      {
        path: 'change-password',
        name: 'change-password',
        component: () => import('pages/ChangePassword.vue')
      }
    ]
  },


  /* ==========================================================
   ❌ 404
  ========================================================== */
  {
    path: '/:catchAll(.*)*',
    component: () => import('pages/ErrorNotFound.vue')
  }
]

export default routes
