import {themes as prismThemes} from 'prism-react-renderer';
import type {Config} from '@docusaurus/types';
import type * as Preset from '@docusaurus/preset-classic';

const config: Config = {
  title: '洪荒大陆 · 设计文档站',
  tagline: '洪荒大陆挂机修仙RPG游戏设计文档',
  favicon: 'img/favicon.ico',

  url: 'https://docs.xuqinmin.com',
  baseUrl: '/',

  // 关闭断链检查，防止因文档引用问题导致构建失败
  onBrokenLinks: 'warn',
  onBrokenMarkdownLinks: 'warn',

  // 使用纯 Markdown 模式，避免 MDX 对 HTML 标签的严格检查
  markdown: {
    format: 'md',
    mermaid: true,
  },

  i18n: {
    defaultLocale: 'zh-Hans',
    locales: ['zh-Hans'],
  },

  presets: [
    [
      'classic',
      {
        docs: {
          // 使用仓库根目录的 docs 作为文档源
          path: '../docs',
          // 文档路由放在根路径，访问 / 直接进入文档首页
          routeBasePath: '/',
          // 自动生成的侧边栏，基于目录结构
          sidebarPath: './sidebars.ts',
          // 去掉文件名中的数字前缀 (如 00_项目概述 → 项目概述)
          numberPrefixParser: false,
          // 编辑链接
          editUrl: 'https://xuqinmin.com/xuqinmin12/lawless-design/edit/main/',
          // 显示最后更新时间和作者
          showLastUpdateAuthor: true,
          showLastUpdateTime: true,
          // 转义大括号，防止 {variable} 被当作 JSX 表达式
          remarkPlugins: [require('./remark-escape-braces')],
        },
        blog: false,
        theme: {
          customCss: './src/css/custom.css',
        },
      } satisfies Preset.Options,
    ],
  ],

  plugins: [
    [
      '@easyops-cn/docusaurus-search-local',
      {
        hashed: true,
        language: ['zh', 'en'],
        docsRouteBasePath: '/',
        docsDir: '../docs',
      },
    ],
    [
      '@docusaurus/plugin-client-redirects',
      {
        redirects: require('./redirects'),
      },
    ],
  ],

  themeConfig: {
    // 搜索配置 (中文搜索)
    docs: {
      sidebar: {
        hideable: true,
        autoCollapseCategories: false,
      },
    },
    navbar: {
      title: '洪荒大陆 · 设计文档站',
      items: [
        {
          type: 'docSidebar',
          sidebarId: 'defaultSidebar',
          position: 'left',
          label: '文档',
        },
      ],
    },
    footer: {
      style: 'dark',
      links: [
        {
          title: '文档',
          items: [
            { label: '决策总索引', to: '/gdd-00' },
            { label: '核心玩法需求', to: '/prd-01' },
          ],
        },
      ],
      copyright: `Copyright © ${new Date().getFullYear()} 洪荒大陆. Built with Docusaurus.`,
    },
    prism: {
      theme: prismThemes.github,
      darkTheme: prismThemes.dracula,
    },
  } satisfies Preset.ThemeConfig,
};

export default config;
