#!/usr/bin/env python3
"""生成 U22 L1「承」剧本 V2 的 Excel 文件，4列标准格式。"""

import sys, os
sys.path.insert(0, os.path.expanduser("~/.openclaw/workspace-xiaobian/skills/office-document-specialist-suite/.venv/lib/python3.12/site-packages"))

from openpyxl import Workbook
from openpyxl.styles import Font, Alignment, PatternFill, Border, Side

wb = Workbook()
ws = wb.active
ws.title = "U22 L1 承"

# 列宽
ws.column_dimensions['A'].width = 16
ws.column_dimensions['B'].width = 55
ws.column_dimensions['C'].width = 10
ws.column_dimensions['D'].width = 45

# 表头
header_font = Font(bold=True, size=11)
header_fill = PatternFill(start_color="D9E1F2", end_color="D9E1F2", fill_type="solid")
headers = ["类型", "剧情描述", "名字", "台词"]
for col, h in enumerate(headers, 1):
    cell = ws.cell(row=1, column=col, value=h)
    cell.font = header_font
    cell.fill = header_fill
    cell.alignment = Alignment(horizontal="center", vertical="center")

# 剧本数据 — 每行: (类型, 描述, 角色, 台词)
# 知识点用 ** 标注（富文本在Excel中用大写加粗表示）
rows = [
    # === 桥段1: 抵达农场 ===
    ("TL", "【场景】May的农场（大门口）\n【角色】User、May、Sam", "", ""),
    ("", "May推开农场大门，一片绿色映入眼帘。Sam愣住了。", "", ""),
    ("", "", "May", "This is my farm!"),
    ("", "", "Sam", "Green... in the desert?"),
    ("", "May得意比了个✌️", "", ""),
    ("", "", "May", "Come!"),

    # === 桥段2: 水果亮相 — Sam想起爷爷 ===
    ("TL", "【场景】May的农场（果园内部）\nMay带大家走到果树前，逐一指向水果。", "", ""),
    ("", "", "May", "Look! Lime."),
    ("", "【教研图】酸橙树，结满青色小果", "", ""),
    ("", "", "May", "Pear!"),
    ("", "【教研图】梨树，挂着饱满的梨子", "", ""),
    ("", "", "May", "And grape!"),
    ("", "【教研图】紫色葡萄挂在藤蔓上", "", ""),
    ("", "Sam盯着水果，眼眶慢慢红了。他轻轻碰了碰梨树。", "", ""),
    ("", "", "Sam", "My grandpa... he grew these."),
    ("", "Sam低下头，声音有些颤。", "", ""),
    ("", "", "Sam", "I need a moment."),
    ("", "May柔和地点头。", "", ""),
    ("", "", "May", "Enjoy yourself."),
    ("", "Sam独自走向果树深处。", "", ""),

    # === 桥段3: DiDi的秘密 ===
    ("TL", "Sam走远后，User好奇地看向May。", "", ""),
    ("", "", "User", "How? In the desert?"),
    ("", "May低头看自己的小包包，神秘一笑。\nDiDi从包包里蹦出来，表情骄傲。\n【spine动画】DiDi从包包弹出", "", ""),
    ("", "", "DiDi", "Me! I grow them!"),
    ("", "", "DiDi", "I know ALL the plants!"),
    ("", "DiDi蹦到果树旁，指着水果让User认。", "", ""),
    ("", "", "DiDi", "What are these? You pick!"),
    ("图片互动-多选", "【教研图】5-6种水果图片（含lime、pear、grape + 干扰项），User选出DiDi种的三种", "", ""),
    ("", "", "DiDi", "Pick the ones I grow!"),
    ("", "User选对，DiDi开心转了个圈。", "", ""),
    ("", "", "DiDi", "Lime, pear, grape! My babies!"),
    ("", "【emoji】DiDi开心跳跃", "", ""),

    # === 桥段4: 帮Sam唤醒记忆 ===
    ("TL", "Sam走回来，眼眶微红但表情平和了。手里拿着几个水果端详。DiDi缩回包包。", "", ""),
    ("", "", "Sam", "I remember these... but the names..."),
    ("", "Sam举起一个梨子。", "", ""),
    ("", "", "Sam", "This one... what is it called?"),
    ("对话互动", "【教研图】Sam手中梨子特写。User告诉Sam名字。", "", ""),
    ("", "", "User", "Pear!"),
    ("", "Sam眼睛一亮。", "", ""),
    ("", "", "Sam", "Pear! We ate sweet pears... after hard work on the farm."),
    ("", "Sam拿起一个酸橙。", "", ""),
    ("", "", "Sam", "This green one...?"),
    ("对话互动", "【教研图】Sam手中酸橙特写。", "", ""),
    ("", "", "User", "Lime!"),
    ("", "", "Sam", "Lime! Grandpa made sour water with lime in summer!"),
    ("", "【emoji】Sam快乐回忆", "", ""),
    ("", "Sam拿起一串葡萄。", "", ""),
    ("", "", "Sam", "This purple one... I stole these..."),
    ("对话互动", "【教研图】Sam手中葡萄特写。", "", ""),
    ("", "", "User", "Grape!"),
    ("", "", "Sam", "Grape! Grandpa ran after me! He was not angry. He laughed!"),
    ("", "【emoji】Sam大笑", "", ""),

    # === 桥段5: 过渡钩子 ===
    ("TL", "Sam看着手中的水果，下定决心。", "", ""),
    ("", "", "Sam", "I can make that drink now!"),
    ("", "Sam就地从农场找来工具，准备现场调配果汁。May也张罗起来。", "", ""),
    ("", "", "May", "Yes! Do it here!"),
    ("对话互动", "User激动说出。", "", ""),
    ("", "", "User", "Make the drink!"),
    ("", "Sam开始现场挑选水果、调配。", "", ""),
]

# 知识点关键词列表（需要加粗标注）
KP_WORDS = ["Lime", "Pear", "Grape", "Drink", "Enjoy yourself",
            "lime", "pear", "grape", "drink", "enjoy yourself",
            "pears", "grapes"]

# 写入样式
thin_border = Border(
    left=Side(style='thin'),
    right=Side(style='thin'),
    top=Side(style='thin'),
    bottom=Side(style='thin')
)
wrap_align = Alignment(wrap_text=True, vertical="top")
type_font = Font(bold=True, color="4472C4", size=10)
normal_font = Font(size=10)
kp_font = Font(bold=True, size=10)

for i, (tp, desc, name, line) in enumerate(rows, 2):
    c1 = ws.cell(row=i, column=1, value=tp)
    c2 = ws.cell(row=i, column=2, value=desc)
    c3 = ws.cell(row=i, column=3, value=name)
    c4 = ws.cell(row=i, column=4, value=line)

    for c in (c1, c2, c3, c4):
        c.border = thin_border
        c.alignment = wrap_align
        c.font = normal_font

    if tp:
        c1.font = type_font

    # 知识点台词加粗
    if line:
        for kw in KP_WORDS:
            if kw in line:
                c4.font = kp_font
                break

out = os.path.expanduser("~/.openclaw/workspace-xiaobian/output/U22_L1_承_剧本V2.xlsx")
os.makedirs(os.path.dirname(out), exist_ok=True)
wb.save(out)
print(f"OK: {out}")
