"""§8 收尾 · slide 104-106 (3 内容页) · v0.2 真实内容版

嵌入 1 张图（G6 资源地图）+ 2 张自画（6h 回顾 + 学完下一步按画像）
"""

from pathlib import Path
from pptx.util import Inches
from pptx.enum.text import PP_ALIGN

from build_main import (
    _fill_ph, _add_textbox, _add_card,
    NAVY, CORAL, CORAL_LIGHT, BLUE_ACCENT, GREEN, GOLD,
    GRAY_300, GRAY_500, GRAY_700, WHITE,
)
from build_sec_M1 import _add_centered_image, _title


def build_slide_104_review(prs):
    s = prs.slides.add_slide(prs.slide_layouts[3])
    _title(s, "§9 · 6 小时回顾 · 我们解决了 §0 的 3 个老大难")
    pains = [
        ("痛点 ① 改方向贵",
         "Agile 两周一交付 · brainstorming 澄清在 PRD 阶段反复 · 改方向最多浪费 1 sprint",
         "PRD AC + 派单 6 段 schema + 失败回路"),
        ("痛点 ② 写完才测自欺欺人",
         "TDD red→green→refactor · commit 顺序检查 · 4 齿轮兜底",
         "test: 必须早于 feat: · reviewer 看 git log 反推违规"),
        ("痛点 ③ 多人协作上下文丢",
         "14 同事职责契约 · progress/<role>.md self-reporting · docs/{reviews,qa,adr}/ 沉淀",
         "Worktree 隔离 · 双 verdict review · UAT 签字归档"),
    ]
    pain_colors = [CORAL, GOLD, BLUE_ACCENT]  # 3 痛点按 P0/P1/P2 色阶
    for i, (head, solution, key) in enumerate(pains):
        y = Inches(1.7 + i * 1.7)
        c = pain_colors[i]
        _add_card(s, Inches(0.55), y, Inches(12.2), Inches(1.55),
                  fill=WHITE, border=c, accent=c)
        _add_textbox(s, Inches(0.85), y + Inches(0.15), Inches(11.5), Inches(0.55),
                     head, size_pt=22, bold=True, color=c)
        _add_textbox(s, Inches(0.85), y + Inches(0.75), Inches(11.5), Inches(0.4),
                     f"✓ {solution}", size_pt=13, color=NAVY)
        _add_textbox(s, Inches(0.85), y + Inches(1.15), Inches(11.5), Inches(0.4),
                     f"{key}", size_pt=12, color=GRAY_500)
    return s


def build_slide_105_resources(prs):
    s = prs.slides.add_slide(prs.slide_layouts[3])
    _title(s, "§9 · 资源地图 · 学完后去哪深入")
    # PNG 1486×834 (ratio 1.78) · 按 height 5.8 居中
    _add_centered_image(s, "G6-resource-map.png", top_inch=1.4, height_inch=5.8)
    return s


def build_slide_106_next_steps(prs):
    s = prs.slides.add_slide(prs.slide_layouts[3])
    _title(s, "§9 · 学完后下一步（按画像）")
    profiles = [
        ("P1 业务型",
         "把 /agf-team-start 加入你的工作流",
         [
             "本周内：clone AGF · 跑 init-team.sh · 看 docs/FIRST_RUN.md",
             "下周：用 /agf-team-start 派一个简单 feature（不写代码也行）",
             "持续：观察 dashboard · 学'看产物'而非'看代码'",
         ],
         CORAL),
        ("P2 入门工程型",
         "独立跑完一个 AI feature 6 阶段门",
         [
             "本周内：选一个真实 feature 用 AGF 完整跑（不要选玩具）",
             "下周：写第一份 ADR · 写第一份 PR 含 SIT 证据段",
             "持续：每月做 1 次 retro · 沉淀自己的'5 个反模式'",
         ],
         NAVY),
        ("P3 资深观察型",
         "评估迁移到自己栈",
         [
             "本周内：审 §7 的 4 件保留 + 3 件可替换 · 决定迁移哪些",
             "下周：在自己项目搭基础版（4 层 hook + DoD checklist + AC 派单）",
             "持续：跟踪 AGF release · 看团队 retro 沉淀更新自己的做法",
         ],
         GOLD),
    ]
    for i, (head, mission, steps, color) in enumerate(profiles):
        x = Inches(0.55 + i * 4.27)
        _add_card(s, x, Inches(1.6), Inches(4.05), Inches(5.5),
                  fill=WHITE, border=color, accent=color)
        _add_textbox(s, x + Inches(0.15), Inches(1.75), Inches(3.75), Inches(0.5),
                     head, size_pt=20, bold=True, color=color)
        _add_textbox(s, x + Inches(0.15), Inches(2.3), Inches(3.75), Inches(0.8),
                     f"{mission}", size_pt=13, bold=True, color=NAVY)
        for j, step in enumerate(steps):
            _add_textbox(s, x + Inches(0.15), Inches(3.5 + j * 1.2),
                         Inches(3.75), Inches(1.1),
                         f"▎ {step}", size_pt=11, color=GRAY_700)
    return s


def build(prs):
    """构建 §8 3 张内容 slide (slide 104-106)"""
    build_slide_104_review(prs)
    build_slide_105_resources(prs)
    build_slide_106_next_steps(prs)
