#!/usr/bin/env python3
"""生成 U22 L1「转」剧本 V2 的 Excel 文件"""

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")

rows = [
    # === #1: 颜色 — Grape做Base ===
    ("TL", "【场景】May的农场（调配区，桌上摆着grape、lime、pear和简易榨汁工具。没有green grape。）\n【角色】User、May、Sam", "", ""),
    ("", "Sam闭上眼睛，努力回忆那杯果汁的样子。", "", ""),
    ("", "", "Sam", "It was... purple."),
    ("", "", "Sam", "I need grape."),
    ("", "May看Sam沉浸在回忆中，轻声对User说。", "", ""),
    ("", "", "May", "Let him enjoy himself."),
    ("图片互动-单选", "【教研图】几种水果（含grape、干扰项），User选出grape作为底料。", "", ""),
    ("", "", "May", "Pick the grape!"),
    ("", "User选对，Sam开始榨grape汁，倒进杯子里。紫色的液体。", "", ""),

    # === #2: 口味·酸 — Lime ===
    ("TL", "Sam尝了一口，摇头。", "", ""),
    ("", "", "Sam", "No... not yet."),
    ("", "", "Sam", "The taste... it made me close my eyes. Tight."),
    ("", "May想了想。", "", ""),
    ("", "", "May", "Close your eyes...? Lime! Sour!"),
    ("对话互动", "User说出水果名。", "", ""),
    ("", "", "User", "Lime!"),
    ("", "", "Sam", "Yes! Add lime!"),
    ("图片互动-拖拽", "【教研图】桌上的lime，User把lime拖进果汁杯。需要多次添加。Sam每次尝一口都摇头示意再加。", "", ""),
    ("", "", "Sam", "More."),
    ("", "", "Sam", "More!"),
    ("", "Sam又尝了一口——酸到紧紧闭上眼睛。", "", ""),
    ("", "", "Sam", "...Yes! This is it!"),
    ("", "【emoji】Sam紧闭双眼", "", ""),

    # === #3: 甜味陷阱 — Pear → 不对 ===
    ("TL", "Sam睁开眼，继续回忆。", "", ""),
    ("", "", "Sam", "There was pear too."),
    ("对话互动", "User说出水果名。", "", ""),
    ("", "", "User", "Pear!"),
    ("", "User加入pear。Sam尝了一口。", "", ""),
    ("", "", "Sam", "No... that's not right."),
    ("", "再加一些。Sam又尝。", "", ""),
    ("", "", "Sam", "Still no."),
    ("", "May和User对视，有些担心。", "", ""),
    ("", "", "May", "Maybe you forgot...?"),
    ("", "Sam摇头，语气坚定。", "", ""),
    ("", "", "Sam", "I will never forget."),

    # === #4: 反转 — Green Grape ===
    ("TL", "沉默。Sam盯着杯子，眉头紧锁。忽然，他的目光移到不远处的果树上——一串绿色的葡萄挂在枝头。", "", ""),
    ("", "", "Sam", "Wait..."),
    ("", "", "Sam", "Green grape?"),
    ("", "Sam一拍脑袋。", "", ""),
    ("", "", "Sam", "Green grape is also grape!"),
    ("", "Sam转向May，礼貌地问。", "", ""),
    ("", "", "Sam", "May, can I have some?"),
    ("", "May大方点头。", "", ""),
    ("", "", "May", "Of course!"),
    ("图片互动-单选", "【教研图】果树上几种水果（含green grape、干扰项），User帮忙摘下green grape。", "", ""),
    ("", "", "May", "Pick the green grape!"),
    ("", "User把green grape递给Sam，Sam榨汁加入杯中。深吸一口气，喝了一大口。", "", ""),
    ("", "长停顿。Sam的表情从紧张——到惊讶——到幸福。", "", ""),
    ("", "", "Sam", "This is it."),
    ("", "【emoji】Sam幸福微笑", "", ""),
    ("对话互动", "User开心说出。", "", ""),
    ("", "", "User", "Grape!"),
    ("", "User把调好的果汁递给Sam，自然地说。", "", ""),
    ("对话互动", "User对Sam说。", "", ""),
    ("", "", "User", "Enjoy yourself!"),
    ("", "Sam接过果汁，感动地喝了一口。大家一起品尝，配方还原成功。", "", ""),
]

KP_WORDS = ["Lime", "Pear", "Grape", "Drink", "Enjoy yourself",
            "lime", "pear", "grape", "drink", "enjoy yourself",
            "pears", "grapes", "Green grape", "green grape"]

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}")
