// 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')
      }
    ]
  },


  /* ==========================================================
   🏠 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' }
      },


      /* ================= 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'
        }
      },


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

      {
        path: 'activity-logs',
        name: 'activity-logs',
        component: () => import('pages/ActivityLogs.vue'),
        meta: { permission: 'system:read' }
      },


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

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

      {
        path: 'market-mail-mapping',
        name: 'market-mail-mapping',
        component: () => import('../pages/MarketMailMapping.vue'),
        meta: { permission: 'system: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-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' }
      },


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

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


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

export default routes
