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"),
  },
  {
    path: "/invite",
    component: () => import("@/views/invite/index.vue"),
  },
];

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

createRouterGuard(router);

export { router };
