(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 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),
    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);
