import { defineConfig } from 'vitepress'
import vitepressMermaidConfig from '@unify-js/vitepress-mermaid/config'
import { copyBrandResearchIndexes } from '../scripts/copy-brand-research-indexes.mjs'

// https://vitepress.dev/reference/site-config
// V5：工程入口共享 sidebar —— 9 块内容（骨架 + 五阶段 + 协作 + 主题 + 指引）
// 同一个 navbar 入口"工程"下，sidebar 组即层次。
const engineeringSidebar = [
  {
    text: '工程实践骨架', collapsed: false, items: [
      { text: '总览', link: '/engineering/' },
      { text: 'E1 价值流', link: '/engineering/value-stream' },
      { text: 'E2 质量保障', link: '/engineering/quality-assurance' },
      { text: 'E3 反馈机制', link: '/engineering/feedback-mechanisms' },
      { text: 'E4 变更管理', link: '/engineering/change-management' },
      { text: 'E5 度量改进', link: '/engineering/metrics-improvement' },
    ],
  },
  {
    text: '建模', collapsed: true, items: [
      { text: '建模总览', link: '/modeling/' },
      { text: '开环控制', link: '/modeling/00-structures/open-loop' },
      { text: '概览', link: '/modeling/01-overview/' },
      { text: '战略建模', link: '/modeling/02-strategic/' },
      { text: '战术建模', link: '/modeling/03-tactical/' },
      { text: '跨上下文协作', link: '/modeling/04-cross-context/' },
      { text: '建模工具', link: '/modeling/05-tools/' },
      { text: '建模案例', link: '/modeling/06-cases/' },
      { text: '源典精读', link: '/modeling/07-source/' },
    ],
  },
  {
    text: '设计', collapsed: true, items: [
      { text: '设计总览', link: '/design/' },
      { text: '复合控制', link: '/design/00-structures/compound' },
      { text: '解耦控制', link: '/design/00-structures/decoupling' },
      { text: '最优控制', link: '/design/00-structures/optimal' },
      { text: '概览', link: '/design/01-overview/' },
      { text: '架构风格', link: '/design/02-architecture/' },
      { text: '边界与契约', link: '/design/03-boundaries/' },
      { text: '设计模式', link: '/design/04-patterns/' },
      { text: '质量属性', link: '/design/05-quality/' },
      { text: '设计案例', link: '/design/06-cases/' },
      { text: '源典精读', link: '/design/07-source/' },
    ],
  },
  {
    text: '实现', collapsed: true, items: [
      { text: '实现总览', link: '/implementation/' },
      { text: '概览', link: '/implementation/01-overview/' },
      { text: '代码实现', link: '/implementation/02-code/' },
      { text: '测试策略', link: '/implementation/03-testing/' },
      { text: '事件驱动', link: '/implementation/03-events/' },
      { text: '部署与运维', link: '/implementation/04-deployment/' },
      { text: '可观测性', link: '/implementation/05-observability/' },
      { text: '实现案例', link: '/implementation/06-cases/' },
      { text: '源典精读', link: '/implementation/07-source/' },
    ],
  },
  {
    text: '运营', collapsed: true, items: [
      { text: '运营总览', link: '/operation/' },
      { text: '闭环反馈', link: '/operation/00-structures/closed-loop' },
      { text: '串级控制', link: '/operation/00-structures/cascade' },
      { text: '概览', link: '/operation/01-overview/' },
      { text: '监控', link: '/operation/02-monitoring/' },
      { text: '反馈', link: '/operation/03-feedback/' },
      { text: '迭代', link: '/operation/04-iteration/' },
      { text: '运营案例', link: '/operation/05-cases/' },
      { text: '源典精读', link: '/operation/06-source/' },
    ],
  },
  {
    text: '演化', collapsed: true, items: [
      { text: '演化总览', link: '/evolution/' },
      { text: '自适应控制', link: '/evolution/00-structures/adaptive' },
      { text: '协调控制', link: '/evolution/00-structures/coordination' },
      { text: '概览', link: '/evolution/01-overview/' },
      { text: '复杂性', link: '/evolution/02-complexity/' },
      { text: '适应性', link: '/evolution/03-adaptation/' },
      { text: '组织', link: '/evolution/04-organization/' },
      { text: '演化案例', link: '/evolution/05-cases/' },
      { text: '源典精读', link: '/evolution/06-source/' },
    ],
  },
  {
    text: '工程协作方法论', collapsed: true, items: [
      { text: '总览', link: '/engineering-collab/' },
      { text: '01 两个角色视角与全局图', link: '/engineering-collab/01-overview' },
      { text: '02 立项与 Roadmap', link: '/engineering-collab/02-roadmap' },
      { text: '03 需求打磨', link: '/engineering-collab/03-requirements' },
      { text: '04 架构与设计', link: '/engineering-collab/04-architecture' },
      { text: '05 任务与冲刺', link: '/engineering-collab/05-tasks' },
      { text: '06 代码与评审', link: '/engineering-collab/06-code-review' },
      { text: '07 部署与运营', link: '/engineering-collab/07-deploy' },
      { text: '08 团队与流程', link: '/engineering-collab/08-team' },
    ],
  },
  {
    text: '业务主题', collapsed: true, items: [
      { text: '主题索引', link: '/themes/' },
      { text: '四源对位索引', link: '/themes/cross-source-index' },
      { text: '系统稳定性', link: '/themes/system-stability' },
      { text: '架构演进', link: '/themes/architecture-evolution' },
      { text: '可观测性建设', link: '/themes/observability' },
      { text: '性能调优', link: '/themes/performance-tuning' },
      { text: '数据一致性', link: '/themes/data-consistency' },
      { text: '故障应急', link: '/themes/incident-response' },
      { text: '成本优化', link: '/themes/cost-optimization' },
      { text: '安全合规', link: '/themes/security-compliance' },
      { text: 'AI 工程化', link: '/themes/ai-engineering' },
    ],
  },
  {
    text: '实践指引', collapsed: true, items: [
      { text: '总览', link: '/book-guides/' },
      { text: 'IDDD 实践指引', link: '/book-guides/iddd/' },
      { text: 'L1 入门：为什么要 DDD', link: '/book-guides/iddd/l1-getting-started' },
      { text: 'L2 业务空间', link: '/book-guides/iddd/l2-domain-subdomain' },
      { text: 'L3 限界上下文', link: '/book-guides/iddd/l3-bounded-context' },
      { text: 'L4 上下文映射', link: '/book-guides/iddd/l4-context-maps' },
      { text: 'L5 实体与值对象', link: '/book-guides/iddd/l5-entity-value-object' },
      { text: 'L6 聚合', link: '/book-guides/iddd/l6-aggregate' },
      { text: 'L7 领域服务/工厂/仓储/模块', link: '/book-guides/iddd/l7-tactical-details' },
      { text: 'L8 跨 BC 集成 + 应用层', link: '/book-guides/iddd/l8-bc-integration' },
      { text: 'EDM 实践指引', link: '/book-guides/event-driven/' },
      { text: 'E1 入门', link: '/book-guides/event-driven/e1-getting-started' },
      { text: 'E2 微服务基础', link: '/book-guides/event-driven/e2-microservice-basics' },
      { text: 'E3 通信契约', link: '/book-guides/event-driven/e3-communication-contracts' },
      { text: 'E4 集成老系统', link: '/book-guides/event-driven/e4-integrating-legacy' },
      { text: 'E5 处理基础', link: '/book-guides/event-driven/e5-processing-basics' },
      { text: 'E6 状态物化', link: '/book-guides/event-driven/e6-state-materialization' },
      { text: 'E7 跨服务工作流', link: '/book-guides/event-driven/e7-cross-service-workflows' },
      { text: 'E8 部署 + FaaS + 集群', link: '/book-guides/event-driven/e8-deployment-faas-cluster' },
      { text: 'E9 流处理框架与实时查询', link: '/book-guides/event-driven/e9-streaming-realtime' },
      { text: 'E10 测试与总结', link: '/book-guides/event-driven/e10-testing-conclusion' },
    ],
  },
]

const thoughtSidebar = [
        {
          text: '思想', collapsed: false, items: [
            { text: '总览', link: '/thought/' },
          ],
        },
        {
          text: '源典精读', collapsed: false, items: [
            { text: '精读索引', link: '/distillation/源典精读/' },
            { text: '海德格尔《存在与时间》', link: '/distillation/源典精读/海德格尔/' },
            { text: 'James《实用主义》', link: '/distillation/源典精读/James/实用主义-v4精读' },
            { text: 'Kant《纯粹理性批判》', link: '/distillation/源典精读/Kant/纯粹理性批判-v4精读' },
            { text: 'Wittgenstein《逻辑哲学论》', link: '/distillation/源典精读/Wittgenstein/逻辑哲学论-v4精读' },
            { text: '老子《道德经》（待精读）', link: '/distillation/源典精读/老子/' },
            { text: '钱学森《论系统工程》（待精读）', link: '/distillation/源典精读/钱学森/' },
          ],
        },
        {
          text: '骨架是怎么来的', collapsed: false, items: [
            { text: '蒸馏器总览', link: '/distillation/' },
            { text: '骨架的骨架 · 三重结构定理', link: '/distillation/double-structure' },
            { text: '骨架演化日志', link: '/distillation/骨架演化日志' },
          ],
        },
      ]

const aestheticsSidebar = [
  {
    text: '从这里开始', collapsed: false, items: [
      { text: '美学总览', link: '/aesthetics/' },
      { text: '第一轮：观察与改变', link: '/aesthetics/01-learning/relations-to-expression' },
      { text: '下一轮：渐进学习路径', link: '/aesthetics/00-structures/learning-path' },
    ],
  },
  {
    text: '认知骨架：按问题深入', collapsed: true, items: [
      { text: '骨架与生长规则', link: '/aesthetics/00-structures/' },
      { text: '研究领域与认知路径', link: '/aesthetics/00-structures/research-fields' },
      { text: 'A1 经验与问题', link: '/aesthetics/00-structures/experience-question' },
      { text: 'A2 形式与关系', link: '/aesthetics/00-structures/form-relations' },
      { text: 'A3 媒介与生成', link: '/aesthetics/00-structures/medium-generation' },
      { text: 'A4 语境与解释', link: '/aesthetics/00-structures/context-interpretation' },
      { text: 'A5 构想与创作', link: '/aesthetics/00-structures/conception-creation' },
      { text: 'A6 批评与发展', link: '/aesthetics/00-structures/critique-development' },
    ],
  },
  {
    text: '继续课题与实践', collapsed: true, items: [
      { text: '从一张样稿长出规则', link: '/aesthetics/01-learning/rules-to-practice' },
      { text: '从物件发展三个课题', link: '/aesthetics/01-learning/objects-to-inquiry' },
      { text: '自主课题与过程档案', link: '/aesthetics/01-learning/independent-project' },
    ],
  },
  {
    text: '共同方法', collapsed: true, items: [
      { text: '方法调用地图', link: '/aesthetics/02-methods/' },
      { text: '观察与比较', link: '/aesthetics/02-methods/observation-comparison' },
      { text: '转译与生成', link: '/aesthetics/02-methods/translation-generation' },
      { text: '从物件属性发展问题', link: '/aesthetics/02-methods/object-relations' },
      { text: '批评与迁移', link: '/aesthetics/02-methods/critique-transfer' },
    ],
  },
  {
    text: '应用工作台', collapsed: true, items: [
      { text: '艺术观看与创作', link: '/aesthetics/03-applications/art-practice' },
      { text: '品牌 VI 设计', link: '/aesthetics/03-applications/brand-vi' },
      { text: 'VI 规则、参照与交接', link: '/aesthetics/03-applications/vi-rules-handoff' },
      { text: '数字表面与 Hero', link: '/aesthetics/03-applications/digital-surface' },
    ],
  },
  {
    text: '基础与解释专题', collapsed: true, items: [
      { text: '肌理与物质感知', link: '/aesthetics/texture-material-perception' },
      { text: '明度与明暗结构', link: '/aesthetics/value-tonal-structure' },
      { text: '色彩关系与知觉', link: '/aesthetics/color-relations-perception' },
      { text: '审美经验', link: '/aesthetics/aesthetic-experience' },
      { text: '感知与身体', link: '/aesthetics/perception-body-mediation' },
      { text: '维护与劳动', link: '/aesthetics/maintenance-labor' },
      { text: '生命与环境', link: '/aesthetics/life-environment' },
      { text: '形式与意味', link: '/aesthetics/form-meaning' },
      { text: '境界与意境', link: '/aesthetics/realm-conception' },
      { text: '商业艺术广域赏析', link: '/aesthetics/commercial-art-development' },
    ],
  },
  {
    text: '品牌 VI 应用', collapsed: true, items: [
      { text: '品牌 VI 骨架（研究稿）', link: '/aesthetics/brand-vi-framework' },
      { text: '品牌能力补充进度', link: '/aesthetics/brand-capabilities/' },
      { text: '物件关系与品牌创作机制', link: '/aesthetics/brand-creative-mechanisms' },
      { text: '品牌调性与推导策略', link: '/aesthetics/brand-tone-strategy' },
      { text: '肌理与品牌感知方向', link: '/aesthetics/brand-sensory-direction' },
      { text: 'VI 资产推导与协调', link: '/aesthetics/brand-vi-asset-derivation' },
      { text: '字体如何长成排版系统', link: '/aesthetics/brand-vi-typography-system' },
      { text: 'VI 组合与变化规则', link: '/aesthetics/brand-vi-composition-rules' },
      { text: 'VI 探索与迭代流程', link: '/aesthetics/brand-vi-exploration-process' },
      { text: '材料 VI 的推导', link: '/aesthetics/material-vi-derivation' },
    ],
  },
  {
    text: 'VI 方法与武器库', collapsed: true, items: [
      { text: 'VI 品读方法：从提取到判断', link: '/aesthetics/brand-vi-appreciating-method' },
      { text: 'VI 切入点与方法库', link: '/aesthetics/brand-vi-design-reasoning' },
      { text: 'VI 思考策略与启发式路由', link: '/aesthetics/brand-vi-thinking-routes' },
      { text: 'VI 策略与操作卡', link: '/aesthetics/brand-vi-operation-library' },
      { text: '处境条目库', link: '/meta/brand-vi-research/situation-entries' },
      { text: 'VI 阶段性认知与判断', link: '/aesthetics/brand-vi-working-conclusions' },
    ],
  },
  {
    text: '实践与反馈案例', collapsed: true, items: [
      { text: '材料工作室第一轮', link: '/meta/brand-vi-research/practice-round1' },
      { text: '材料工作室第二轮', link: '/meta/brand-vi-research/practice-round2' },
      { text: '纸的平面图形语言', link: '/meta/brand-vi-research/paper-graphic-language' },
      { text: '颗粒感的知觉与修正', link: '/meta/brand-vi-research/grain-perception-study' },
      { text: 'World Map 入口引导', link: '/meta/brand-vi-research/world-map-entry-guidance-study' },
      { text: 'World Map 公共品牌推导', link: '/meta/brand-vi-research/world-map-brand-round1' },
      { text: 'Hero 比例与适配', link: '/meta/brand-vi-research/world-map-hero-proportion-study' },
    ],
  },
  {
    text: '知识维护', collapsed: true, items: [
      { text: '维护与研究入口', link: '/meta/aesthetics-research/' },
      { text: '内容地图与生长规则', link: '/aesthetics/00-structures/content-map' },
      { text: 'VI 新研究回流与采纳', link: '/meta/aesthetics-research/vi-intake' },
      { text: '灵感地图阅读与采纳', link: '/meta/aesthetics-research/mindmap-intake' },
      { text: '灵感地图体系扩读', link: '/meta/aesthetics-research/mindmap-system-reading' },
      { text: '感知 维护与环境深读', link: '/meta/aesthetics-research/mindmap-three-lines' },
      { text: '飞书知识与品牌能力', link: '/meta/aesthetics-research/mindmap-brand-capabilities' },
      { text: '概念推导与选优深读', link: '/meta/aesthetics-research/mindmap-concept-selection' },
      { text: '品牌案例的采纳与推导', link: '/meta/brand-vi-research/capability-integration' },
      { text: '完整文档目录', link: '/meta/aesthetics-research/content-register' },
      { text: '问题与证据台账', link: '/meta/aesthetics-research/open-questions' },
      { text: '教学与源典依据', link: '/meta/aesthetics-research/teaching-foundations' },
      { text: '处境与修正索引', link: '/meta/aesthetics-research/situation-index' },
    ],
  },
  {
    text: '研究与来源档案', collapsed: true, items: [
      { text: 'VI 研究总览', link: '/meta/brand-vi-research/' },
      { text: '全库赏析执行计划', link: '/meta/brand-vi-research/appreciation-plan' },
      { text: '结论依据与待验证项', link: '/meta/brand-vi-research/conclusion-evidence' },
      { text: '商业艺术逐条细查', link: '/meta/brand-vi-research/deep-investigation' },
      { text: '商业艺术第二轮', link: '/meta/brand-vi-research/round2-investigation' },
      { text: '作品、组织与持续使用', link: '/meta/brand-vi-research/round5-investigation' },
      { text: '字体、产品与场景配套', link: '/meta/brand-vi-research/round6-investigation' },
      { text: '消费影像的光与尺度', link: '/meta/brand-vi-research/round7-sensorial-breadth' },
      { text: '包装、影像与日常陈列', link: '/meta/brand-vi-research/round8-sensorial-breadth' },
      { text: '信息、商品与持续使用', link: '/meta/brand-vi-research/round9-14-investigation' },
      { text: '原始演示资料续读', link: '/meta/brand-vi-research/round16-presentations-breadth' },
      { text: '信息、体验与组织训练', link: '/meta/brand-vi-research/round15-18-investigation' },
      { text: '文字、内容与商品情境', link: '/meta/brand-vi-research/round19-21-investigation' },
      { text: '商业艺术第四轮', link: '/meta/brand-vi-research/round4-investigation' },
      { text: '商业艺术第三轮', link: '/meta/brand-vi-research/round3-investigation' },
      { text: '全库覆盖与持续研究', link: '/meta/brand-vi-research/library-coverage' },
    ],
  },
]

export default defineConfig({
  extends: vitepressMermaidConfig,
  buildEnd: copyBrandResearchIndexes,
  title: "World Map",
  description: "连接美学、思想与工程，沿问题找到依据与方法，建立自己的理解。",
  cleanUrls: true,
  lastUpdated: true,
  // AI 工作台不入 build：
  // - drafts/  AI 的多轮阅读草稿
  // - source/ AI 蒸馏方法论的工作台（每本书一个子目录）
  // - notes/  原书解析笔记（不入 git 的原始 dump）
  srcExclude: [
    '**/.tmp/**',
    '**/meta/ai-collaboration/drafts/**',
    '**/meta/source/**',
    '**/notes/**',
    '**/meta/v2-snapshot.md',
    '**/meta/v2-mapping-table.md',
    '**/meta/v2.1-proposal.md',
    '**/meta/v2.2-proposal.md',
    '**/meta/v2.3-proposal.md',
    '**/meta/v2.4-proposal.md',
    '**/meta/v2.5-proposal.md',
    '**/meta/v2.6-proposal.md',
    '**/meta/v2.7-audit-report.md',
    '**/meta/v2.7-mapping.md',
    '**/meta/v2.7-proposal.md',
    '**/meta/v2.8-proposal.md',
    '**/meta/linear-algebra-proposal.md',
    '**/meta/skeleton-review-*.md',
    '**/meta/six-books-foundation-analysis.md',
    '**/meta/berkeley-proposal.md',
    '**/meta/v3-skeleton-proposal.md',
    '**/meta/v3-audit-2026-06-25.md',
    '**/meta/v3-redesign-proposal.md',
    '**/meta/v3-review-2026-06-26.md',
    '**/meta/v3-review-r2-2026-06-26.md',
    '**/meta/v4-skeleton-review-2026-06-26.md',
    '**/meta/v4-skeleton-design-2026-06-26.md',
    '**/meta/v4-read-digestion-2026-06-27.md',
    '**/meta/v4-double-structure-2026-06-27.md',
    '**/meta/v4-triple-structure-2026-06-27.md',
  ],
  themeConfig: {
    siteTitle: 'World Map.',
    // https://vitepress.dev/reference/default-theme-config
    nav: [
      { text: '首页', link: '/' },
      { text: '基石 · 世界观', link: '/worldview/' },
      { text: '美学', link: '/aesthetics/' },
      { text: '思想', link: '/thought/' },
      {
        text: '工程',
        items: [
          { text: '工程实践骨架', link: '/engineering/' },
          { text: '建模', link: '/modeling/' },
          { text: '设计', link: '/design/' },
          { text: '实现', link: '/implementation/' },
          { text: '运营', link: '/operation/' },
          { text: '演化', link: '/evolution/' },
          { text: '业务主题', link: '/themes/' },
          { text: '工程协作', link: '/engineering-collab/' },
          { text: '实践指引', link: '/book-guides/' },
        ],
      },
      { text: '✍️ 写作范式', link: '/meta/writing-style/' },
    ],

    sidebar: {
      '/meta/writing-style/': [
        {
          text: '写作范式', collapsed: false, items: [
            { text: '总览', link: '/meta/writing-style/' },
            { text: 'frontmatter schema', link: '/meta/writing-style/frontmatter-schema' },
            { text: 'Type A: 概览页', link: '/meta/writing-style/type-a-overview' },
            { text: 'Type B: 概念页', link: '/meta/writing-style/type-b-concept' },
            { text: 'Type C: 案例页', link: '/meta/writing-style/type-c-case' },
            { text: 'Type D: stub 占位', link: '/meta/writing-style/type-d-stub' },
            { text: '视觉约束与禁用项', link: '/meta/writing-style/visual-rules' },
            { text: 'L 层概念升格范式', link: '/meta/writing-style/l-layer-concept-promotion' },
          ],
        },
      ],
      // 品牌 VI 研究记录虽然放在 meta/ 下，阅读时仍属于美学内容脉络。
      '/meta/brand-vi-research/': aestheticsSidebar,
      '/meta/aesthetics-research/': aestheticsSidebar,
      '/meta/': [
        {
          text: '元文档区', collapsed: false, items: [
            { text: 'AI 协作约定', link: '/meta/ai-collaboration/' },
            { text: 'Git 流程规范', link: '/meta/git-workflow/' },
            { text: '骨架演进日志', link: '/meta/evolution-log/' },
            { text: 'CI/CD 流水线', link: '/meta/cicd' },
          ],
        },
      ],
      '/engineering/': engineeringSidebar,
      '/modeling/': engineeringSidebar,
      '/design/': engineeringSidebar,
      '/implementation/': engineeringSidebar,
      '/operation/': engineeringSidebar,
      '/evolution/': engineeringSidebar,
      '/themes/': engineeringSidebar,
      '/engineering-collab/': engineeringSidebar,
      '/book-guides/': engineeringSidebar,

      '/aesthetics/': aestheticsSidebar,
      '/thought/': thoughtSidebar,
      '/distillation/': thoughtSidebar,
      '/worldview/': [
        {
          text: '世界观骨架',
          collapsed: false,
          items: [
            { text: '涌现视域 Emergence-Vision', link: '/worldview/wonder-01-emergence-vision' },
            { text: '涌现作为 Emergence-Action', link: '/worldview/wonder-02-emergence-action' },
            { text: '涌现之时 Emergence-Time', link: '/worldview/wonder-03-emergence-time' },
            { text: '照面 Encounter', link: '/worldview/wonder-04-encounter' },
            { text: '隐匿 Concealment', link: '/worldview/wonder-05-concealment' },
          ],
        },
      ],


    },

    socialLinks: [
      { icon: 'github', link: 'https://github.com/vuejs/vitepress' }
    ],

    footer: {
      message: '连接美学、思想与工程，建立自己的理解。',
      copyright: '© World Map'
    }
  }
})
