import { Spin } from "antd";
import { Suspense, lazy } from "react";
import type { MenuRoute } from "@/types";

const HomePage = lazy(() => import("@/pages/home"));
const Dashboard = lazy(() => import("@/pages/dashboard"));
const Profile = lazy(() => import("@/pages/profile"));
const Tenants = lazy(() => import("@/pages/organization/tenants"));
const Orgs = lazy(() => import("@/pages/organization/orgs"));
const Users = lazy(() => import("@/pages/access/users"));
const Roles = lazy(() => import("@/pages/access/roles"));
const Permissions = lazy(() => import("@/pages/access/permissions"));
const SysParams = lazy(() => import("@/pages/system/sys-params"));
const PlatformSettings = lazy(() => import("@/pages/system/platform-settings"));
const Dictionaries = lazy(() => import("@/pages/system/dictionaries"));
const Logs = lazy(() => import("@/pages/system/logs"));
const Devices = lazy(() => import("@/pages/devices"));
const UserRoleBinding = lazy(() => import("@/pages/bindings/user-role"));
const RolePermissionBinding = lazy(() => import("@/pages/bindings/role-permission"));

import SpeakerReg from "../pages/business/SpeakerReg";
const RealtimeAsrSession = lazy(async () => { const mod = await import("../pages/business/RealtimeAsrSession"); return { default: mod.default ?? mod.RealtimeAsrSession }; });
import HotWords from "../pages/business/HotWords";
import PromptTemplates from "../pages/business/PromptTemplates";
import AiModels from "../pages/business/AiModels";
import Meetings from "../pages/business/Meetings";
import MeetingDetail from "../pages/business/MeetingDetail";


function RouteFallback() {
  return (
      <div className="app-page__empty-state" style={{ minHeight: 320 }}>
        <Spin />
      </div>
  );
}

function LazyPage({ children }: { children: JSX.Element }) {
  return <Suspense fallback={<RouteFallback />}>{children}</Suspense>;
}
export const menuRoutes: MenuRoute[] = [
  { path: "/", label: "首页", element: <HomePage />, perm: "menu:dashboard" },
  { path: "/profile", label: "个人中心", element: <Profile /> },
  { path: "/speaker-reg", label: "声纹注册", element: <SpeakerReg />, perm: "menu:speaker" },
  { path: "/tenants", label: "租户管理", element: <Tenants />, perm: "menu:tenants" },
  { path: "/orgs", label: "组织管理", element: <Orgs />, perm: "menu:orgs" },
  { path: "/users", label: "用户管理", element: <Users />, perm: "menu:users" },
  { path: "/roles", label: "角色管理", element: <Roles />, perm: "menu:roles" },
  { path: "/permissions", label: "权限管理", element: <Permissions />, perm: "menu:permissions" },
  { path: "/params", label: "系统参数", element: <SysParams />, perm: "menu:params" },
  { path: "/platform-settings", label: "平台设置", element: <PlatformSettings />, perm: "menu:platform" },
  { path: "/dictionaries", label: "字典管理", element: <Dictionaries />, perm: "menu:dict" },
  { path: "/logs", label: "日志管理", element: <Logs />, perm: "menu:logs" },
  { path: "/devices", label: "设备管理", element: <Devices />, perm: "menu:devices" },
  { path: "/user-roles", label: "用户角色绑定", element: <UserRoleBinding />, perm: "menu:user-roles" },
  { path: "/role-permissions", label: "角色权限绑定", element: <RolePermissionBinding />, perm: "menu:role-permissions" },
  { path: "/hotwords", label: "热词管理", element: <HotWords />, perm: "menu:hotword" },
  { path: "/prompts", label: "总结模板", element: <PromptTemplates />, perm: "menu:prompt" },
  { path: "/aimodels", label: "模型配置", element: <AiModels />, perm: "menu:aimodel" },
  { path: "/meetings", label: "会议中心", element: <Meetings />, perm: "menu:meeting" }
];

export const extraRoutes = [
  { path: "/dashboard-monitor", element: <Dashboard />, perm: "menu:dashboard" },
  { path: "/meetings/:id", element: <MeetingDetail />, perm: "menu:meeting" },
  { path: "/meeting-live-session/:id", element: <RealtimeAsrSession />, perm: "menu:meeting" }
];

