import type { RouteRecordRaw } from "vue-router";
import { createRouter, createWebHistory } from "@ionic/vue-router";
import authRoutes from "./auth";
import { createRouterGuard } from "./guard";

const routes: Array<RouteRecordRaw> = [
  {
    path: "/",
    redirect: "/layout/home",
  },
  {
    path: "/:pathMatch(.*)*",
    redirect: "/layout/home",
  },
  ...authRoutes,
  {
    path: "/layout",
    component: () => import("@/components/layout/default.vue"),
    children: [
      {
        path: "home",
        component: () => import("@/views/home/index.vue"),
        meta: { requiresAuth: true },
      },
      {
        path: "service",
        component: () => import("@/views/service/index.vue"),
        meta: { requiresAuth: true },
      },
      {
        path: "product",
        component: () => import("@/views/product/index.vue"),
        meta: { requiresAuth: true },
      },
      {
        path: "profile",
        component: () => import("@/views/profile/index.vue"),
        meta: { requiresAuth: true },
      },
    ],
  },
  {
    path: "/check_in",
    component: () => import("@/views/check_in/index.vue"),
    meta: { requiresAuth: true },
  },
  {
    path: "/invite",
    component: () => import("@/views/invite/index.vue"),
    meta: { requiresAuth: true },
  },
  {
    path: "/bind_invite",
    component: () => import("@/views/invite/bind.vue"),
    meta: { requiresAuth: true },
  },
  {
    path: "/settings",
    component: () => import("@/views/settings/index.vue"),
    meta: { requiresAuth: true },
  },
  {
    path: "/real_name",
    component: () => import("@/views/real_name/index.vue"),
    meta: { requiresAuth: true },
  },
  {
    path: "/address",
    component: () => import("@/views/address/index.vue"),
    meta: { requiresAuth: true },
  },
  {
    path: "/address/add",
    component: () => import("@/views/address/add.vue"),
    meta: { requiresAuth: true },
  },
  {
    path: "/payment",
    component: () => import("@/views/payment/index.vue"),
    meta: { requiresAuth: true },
  },
  {
    path: "/payment/add",
    component: () => import("@/views/payment/add.vue"),
    meta: { requiresAuth: true },
  },
  {
    path: "/security",
    component: () => import("@/views/security/index.vue"),
    meta: { requiresAuth: true },
  },
  {
    path: "/security/change_password",
    component: () => import("@/views/security/change_password.vue"),
    meta: { requiresAuth: true },
  },
  {
    path: "/security/change_payment_password",
    component: () => import("@/views/security/change_payment_password.vue"),
    meta: { requiresAuth: true },
  },
  {
    path: "/asset_details",
    component: () => import("@/views/asset_details/index.vue"),
    meta: { requiresAuth: true },
  },
  {
    path: "/recharge",
    component: () => import("@/views/recharge/index.vue"),
    meta: { requiresAuth: true },
  },
  {
    path: "/recharge/records",
    component: () => import("@/views/recharge/records.vue"),
    meta: { requiresAuth: true },
  },
  {
    path: "/team",
    component: () => import("@/views/team/index.vue"),
    meta: { requiresAuth: true },
  },
  {
    path: "/asset_center",
    component: () => import("@/views/asset_center/index.vue"),
    meta: { requiresAuth: true },
  },
  {
    path: "/withdraw",
    component: () => import("@/views/withdraw/index.vue"),
    meta: { requiresAuth: true },
  },
  {
    path: "/transfer",
    component: () => import("@/views/transfer/index.vue"),
    meta: { requiresAuth: true },
  },
  {
    path: "/transfer/records",
    component: () => import("@/views/transfer/records.vue"),
    meta: { requiresAuth: true },
  },
  {
    path: "/exchange",
    component: () => import("@/views/exchange/index.vue"),
    meta: { requiresAuth: true },
  },
];

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes,
});

createRouterGuard(router);

export { router };
