import {
  createMemoryHistory,
  createRouter,
  createWebHistory,
} from "vue-router";
import type { RouteRecordRaw } from "vue-router";

export const routes = [
  {
    path: "/",
    name: "home",
    component: () => import("@/pages/home/index.vue"),
  },
  {
    path: "/home",
    name: "home_alias",
    component: () => import("@/pages/home/index.vue"),
  },
  {
    path: "/login",
    name: "login",
    component: () => import("@/pages/login/index.vue"),
  },
  {
    path: "/booking",
    name: "booking",
    component: () => import("@/pages/booking/index.vue"),
  },
  {
    path: "/goods",
    name: "goods",
    component: () => import("@/pages/goods/index.vue"),
  },
  {
    path: "/album",
    name: "album",
    component: () => import("@/pages/album/index.vue"),
  },
  {
    path: "/quick",
    name: "quick",
    component: () => import("@/pages/quick/index.vue"),
  },
  {
    path: "/order",
    name: "orderList",
    component: () => import("@/pages/order/list.vue"),
  },
  {
    path: "/order/detail",
    name: "order_detail",
    component: () => import("@/pages/order/detail.vue"),
  },
  {
    path: "/service",
    name: "service",
    component: () => import("@/pages/service/index.vue"),
  },
  {
    path: "/notice",
    name: "notice",
    component: () => import("@/pages/notice/index.vue"),
  },
] satisfies RouteRecordRaw[];

function resolveRouterBase(): string {
  return import.meta.env?.BASE_URL ?? "/";
}

function createRouterHistory() {
  const base = resolveRouterBase();
  return typeof window === "undefined"
    ? createMemoryHistory(base)
    : createWebHistory(base);
}

export const router = createRouter({
  history: createRouterHistory(),
  routes,
  scrollBehavior() {
    return { top: 0 };
  },
});
