(function exposePageRegistry(global) {
  "use strict";

  const pages = [
    ["sentimentCycleView", "情绪周期", "sentiment", "market", "authenticated", true],
    ["limitPool", "涨停池", "pools", "market", "authenticated", false],
    ["brokenView", "炸板池", "pools", "market", "authenticated", false],
    ["downView", "跌停板", "pools", "market", "authenticated", false],
    ["yesterdayView", "昨日涨停", "pools", "market", "authenticated", false],
    ["performanceView", "涨停表现", "pools", "market", "authenticated", false],
    ["ladderView", "市场天梯", "ladder", "market", "authenticated", false],
    ["rotationView", "板块轮动", "rotation", "market", "authenticated", false],
    ["auctionView", "集合竞价", "auction", "market", "authenticated", false],
    ["themeLibraryView", "题材库", "themes", "market", "authenticated", false],
    ["popularityView", "人气热榜", "popularity", "market", "authenticated", false],
    ["dragonView", "龙虎榜", "dragon_tiger", "market", "authenticated", false],
    ["screenerView", "智能选股", "screener", "intelligence", "member", false],
    ["mentorView", "问师", "mentor", "intelligence", "member", false],
    ["heavenView", "问天", "heaven", "intelligence", "member", false],
    ["reviewWorkspaceView", "我的复盘", "review", "personal", "authenticated", false],
  ].map(([id, title, feature, group, access, isDefault]) => Object.freeze({
    id,
    title,
    feature,
    group,
    access,
    default: isDefault,
    desktop_scroll: "page",
    mobile_layout: "dedicated",
  }));

  const internalPages = [
    Object.freeze({
      id: "screenerTrackingView",
      title: "策略持续跟踪",
      feature: "screener",
      group: "intelligence",
      access: "member",
      internal: true,
      navigation_alias: "screenerView",
    }),
  ];

  const fragments = [
    ["pools", "/pages/pools/page.html?v=20260820-1", ["limitPool", "brokenView", "downView", "yesterdayView", "performanceView"]],
    ["sentiment", "/pages/sentiment/page.html?v=20260803-1", ["sentimentCycleView"]],
    ["heaven", "/pages/heaven/page.html?v=20260803-1", ["heavenView"]],
    ["ladder", "/pages/ladder/page.html?v=20260820-1", ["ladderView"]],
    ["screener", "/pages/screener/page.html?v=20260804-1", ["screenerView", "screenerTrackingView"]],
    ["mentor", "/pages/mentor/page.html?v=20260820-1", ["mentorView"]],
    ["rotation", "/pages/rotation/page.html?v=20260820-1", ["rotationView"]],
    ["auction", "/pages/auction/page.html?v=20260803-1", ["auctionView"]],
    ["themes", "/pages/themes/page.html?v=20260820-1", ["themeLibraryView"]],
    ["popularity", "/pages/popularity/page.html?v=20260803-1", ["popularityView"]],
    ["dragon_tiger", "/pages/dragon-tiger/page.html?v=20260803-1", ["dragonView"]],
    ["review", "/pages/review/page.html?v=20260803-1", ["reviewWorkspaceView"]],
  ].map(([feature, url, viewIds]) => Object.freeze({
    feature,
    url,
    viewIds: Object.freeze(viewIds),
  }));

  const runtimeScripts = [
    "/vendor/lucide.min.js",
    "/shared/ui-core.js",
    "/shared/components.js?v=20260729-1",
    "/pages/runtime.js?v=20260729-1",
    "/pages/sentiment/page.js?v=20260729-1",
    "/pages/pools/page.js?v=20260820-1",
    "/pages/market/breadth.js?v=20260803-1",
    "/pages/market/charts.js?v=20260803-1",
    "/pages/market/entity-detail.js?v=20260803-1",
    "/pages/market/stock-detail.js?v=20260803-1",
    "/pages/market/preview.js?v=20260806-1",
    "/pages/market/search.js?v=20260803-1",
    "/pages/market/bindings.js?v=20260803-1",
    "/pages/ladder/page.js?v=20260820-1",
    "/pages/rotation/page.js?v=20260820-1",
    "/pages/auction/page.js?v=20260729-1",
    "/pages/themes/page.js?v=20260820-1",
    "/pages/popularity/page.js?v=20260820-1",
    "/pages/dragon-tiger/page.js?v=20260820-1",
    "/pages/screener/page.js?v=20260806-1",
    "/pages/mentor/page.js?v=20260820-1",
    "/pages/heaven/page.js?v=20260729-1",
    "/pages/review/page.js?v=20260729-1",
    "/shared/state.js?v=20260729-1",
    "/shared/api.js?v=20260729-1",
    "/shared/shell.js?v=20260820-2",
    "/shared/export.js?v=20260731-1",
    "/pages/heaven/loading-v2.js?v=20260728-2",
    "/shared/context.js?v=20260804-1",
    "/shared/feedback.js?v=20260803-1",
    "/shared/application.js?v=20260803-1",
    "/shared/table.js?v=20260803-1",
    "/shared/theme.js?v=20260803-1",
    "/shared/dashboard.js?v=20260820-1",
    "/shared/session.js?v=20260829-hel243",
    "/shared/admin.js?v=20260803-1",
    "/app.js?v=20260803-2",
  ];

  const all = [...pages, ...internalPages];
  const byId = new Map(all.map((page) => [page.id, page]));
  const defaultPage = pages.find((page) => page.default);
  const aliases = Object.freeze({ sectorView: "rotationView", breadthView: "limitPool" });

  global.XiaobaiPages = Object.freeze({
    schemaVersion: 1,
    pages: Object.freeze(pages),
    internalPages: Object.freeze(internalPages),
    all: Object.freeze(all),
    fragments: Object.freeze(fragments),
    runtimeScripts: Object.freeze(runtimeScripts),
    defaultPage,
    aliases,
    resolve(id) {
      return aliases[id] || id;
    },
    get(id) {
      return byId.get(id) || null;
    },
    has(id) {
      return byId.has(id);
    },
    inGroup(id, group) {
      return byId.get(id)?.group === group;
    },
  });
})(window);
