#!/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 = [
    ("TL", "May 拿出一个小本子。", "", ""),
    ("", "", "May", "We should write this down!"),
    ("", "", "May", "So no one will forget grandpa's fruit tea!"),
    ("", "", "Sam", "Yes. Please."),
    ("", "Sam、May和User一起把食谱写在本子上。\n【核心互动：写作】", "", ""),
    ("对话互动", "写完后，User说出。", "", ""),
    ("", "", "User", "Good food needs good drink!"),
    ("", "", "Sam", "You are right."),
    ("TL", "Sam看着写好的食谱，想了想，又在旁边写上了自己蛋糕的食谱。", "", ""),
    ("", "", "Sam", "I hope my grandpa's fruit tea will live on."),
    ("", "", "Sam", "Just like our town. One hundred years old..."),
    ("", "May感叹。", "", ""),
    ("", "", "May", "And your cake will live on too!"),
    ("", "", "May", "You and grandpa... your love is in this book now."),
    ("", "", "May", "One hundred more years!"),
    ("", "Sam合上本子，看着大家。", "", ""),
    ("", "", "Sam", "I'm not leaving."),
    ("", "", "Sam", "I want to stay."),
    ("", "", "Sam", "I want to share this with everyone!"),
    ("", "【emoji】Sam_happy", "", ""),
    ("", "May开心跳起来比✌️，User也开心。", "", ""),
    ("", "", "May", "Yay!"),
]

KP_WORDS = ["Good food needs good drink", "good food needs good drink",
            "Enjoy yourself", "enjoy yourself",
            "Lime", "Pear", "Grape", "Drink",
            "lime", "pear", "grape", "drink"]

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