import { defineConfig } from 'vitepress'

const releaseId = process.env.VITE_RELEASE_ID?.trim()
if (releaseId && !/^[A-Za-z0-9._-]+$/.test(releaseId)) {
  throw new Error('VITE_RELEASE_ID 只能包含字母、数字、点、下划线和短横线')
}

export default defineConfig({
  title: 'XuqmGroup 开发者文档',
  description: 'XuqmGroup 多端 SDK 接入指南',
  base: '/docs/',
  lang: 'zh-CN',
  assetsDir: releaseId ? `releases/${releaseId}/assets` : 'assets',

  themeConfig: {
    logo: '/logo.svg',
    siteTitle: 'XuqmGroup Dev Docs',

    nav: [
      { text: '快速开始', link: '/guide/quickstart' },
      {
        text: 'SDK',
        items: [
          { text: 'Android', link: '/android/' },
          { text: 'iOS', link: '/ios/' },
          { text: 'React Native', link: '/rn/' },
          { text: 'Vue3', link: '/vue3/' },
          { text: 'Flutter', link: '/flutter/' },
          { text: 'HarmonyOS', link: '/harmony/' },
          { text: '微信小程序', link: '/miniprogram/' },
          { text: 'H5', link: '/h5/' },
        ],
      },
      { text: 'API 速查', link: '/server/api' },
      { text: '平台控制台', link: 'https://dev.xuqinmin.com', target: '_blank' },
    ],

    sidebar: {
      '/guide/': [
        { text: '快速开始', link: '/guide/quickstart' },
        { text: '平台概念', link: '/guide/concepts' },
        { text: '接入流程', link: '/guide/flow' },
      ],
      '/android/': [
        { text: '概览', link: '/android/' },
        { text: '安装配置', link: '/android/setup' },
        { text: 'IM 接入', link: '/android/im' },
        { text: '推送接入', link: '/android/push' },
        { text: '版本管理', link: '/android/update' },
      ],
      '/ios/': [
        { text: '概览', link: '/ios/' },
        { text: '安装配置', link: '/ios/setup' },
        { text: 'IM 接入', link: '/ios/im' },
        { text: '推送接入', link: '/ios/push' },
        { text: '版本管理', link: '/ios/update' },
      ],
      '/rn/': [
        { text: '概览', link: '/rn/' },
        { text: '安装配置', link: '/rn/setup' },
        { text: 'IM 接入', link: '/rn/im' },
        { text: '群聊', link: '/rn/group' },
        { text: '推送接入', link: '/rn/push' },
        { text: '版本管理', link: '/rn/update' },
      ],
      '/vue3/': [
        { text: '概览', link: '/vue3/' },
        { text: '安装配置', link: '/vue3/setup' },
        { text: 'IM 接入', link: '/vue3/im' },
      ],
      '/flutter/': [
        { text: '概览', link: '/flutter/' },
        { text: '安装配置', link: '/flutter/setup' },
        { text: 'IM 接入', link: '/flutter/im' },
        { text: '推送接入', link: '/flutter/push' },
        { text: '版本管理', link: '/flutter/update' },
      ],
      '/harmony/': [
        { text: '概览', link: '/harmony/' },
        { text: '安装配置', link: '/harmony/setup' },
        { text: 'IM 接入', link: '/harmony/im' },
        { text: '推送接入', link: '/harmony/#push-接入' },
        { text: '版本管理', link: '/harmony/#update-接入' },
      ],
      '/miniprogram/': [
        { text: '概览', link: '/miniprogram/' },
        { text: '安装配置', link: '/miniprogram/setup' },
        { text: 'IM 接入', link: '/miniprogram/im' },
      ],
      '/h5/': [
        { text: '概览', link: '/h5/' },
        { text: '安装配置', link: '/h5/setup' },
        { text: 'IM 接入', link: '/h5/im' },
      ],
      '/server/': [
        { text: 'API 速查', link: '/server/api' },
        { text: 'Go Server SDK', link: '/server/go-sdk' },
        { text: 'Java Server SDK', link: '/server/java-sdk' },
        { text: 'Python Server SDK', link: '/server/python-sdk' },
        { text: '错误码', link: '/server/errors' },
      ],
    },

    socialLinks: [
      { icon: 'github', link: 'https://xuqinmin.com/xuqinmin12' },
    ],

    footer: {
      message: 'XuqmGroup 开放平台',
      copyright: 'Copyright © 2026 XuqmGroup',
    },

    search: { provider: 'local' },
  },
})
