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

wb = openpyxl.Workbook()

# ===== Sheet1: 完整剧本 =====
ws = wb.active
ws.title = "剧本-段落1"

# 列宽
ws.column_dimensions['A'].width = 15
ws.column_dimensions['B'].width = 60
ws.column_dimensions['C'].width = 12
ws.column_dimensions['D'].width = 45

# 样式
header_font = Font(bold=True, size=11)
header_fill = PatternFill(start_color="D9E2F3", end_color="D9E2F3", fill_type="solid")
wrap = Alignment(wrap_text=True, vertical="top")
thin_border = Border(
    left=Side(style='thin'),
    right=Side(style='thin'),
    top=Side(style='thin'),
    bottom=Side(style='thin')
)

# 表头
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 = wrap
    cell.border = thin_border

# 剧本数据
rows = [
    ["TL", "【场景】教室（放学后，阳光斜照进来，黑板旁贴着本周时间表。教室里只剩几个人在收拾）\n【角色】User、Ben、Vicky、Sue、Kim\n【音效】放学铃声余韵渐弱，远处操场嬉闹声", "", ""],
    ["", "放学了，教室里大部分同学已经走了。Vicky站在黑板旁，手指着贴在墙上的明天时间表，念给大家听", "", ""],
    ["", "", "Vicky", "Okay, let me check tomorrow's timetable."],
    ["", "", "Vicky", "First, we have a math lesson. Then, an English lesson."],
    ["", "User和Ben在座位上一边听一边收拾课本，根据Vicky念的科目把对应的书塞进书包", "", ""],
    ["", "", "User", "Math... English... got it."],
    ["图片互动-拖拽", "【教研图】书桌上摆着几本课本（封面分别写着Math、English、Art等），旁边是打开的书包。根据明天的课表，把需要的课本（即对应的subject）拖进书包", "", ""],
    ["对话互动", "", "User", "I need to pack the right books for each subject."],
    ["TL", "Ben也在翻自己的书桌抽屉，找课本。他手伸进抽屉深处掏了半天，掏出来一团皱巴巴的东西——一件T恤", "", ""],
    ["", "Ben举起那件T恤，愣了一下。一股味道扩散开来\n【音效】一阵诡异的"嗡——"音效（夸张搞笑风格）\n【emoji】Vicky 🤢 Sue 🤢 User 😨", "", ""],
    ["", "", "Vicky", "EWWW! Ben! What IS that?!"],
    ["", "", "Ben", "Oh... my PE shirt..."],
    ["", "", "Sue", "It SMELLS, Ben!"],
    ["", "", "Ben", "I forgot it was in there..."],
    ["", "【教研图】时间表特写，可以看到几天前有一节PE lesson，旁边画了个小人在跑步", "", ""],
    ["", "", "User", "Look! There was a PE lesson three days ago!"],
    ["", "", "User", "Ben, you forgot to wash it for three days?!"],
    ["", "【emoji】Ben 😅 Ben不好意思地把T恤赶紧卷起来塞进书包，Vicky和Sue拼命扇风", "", ""],
    ["", "", "Ben", "Sorry, sorry! I'll wash it tonight! I promise!"],
    ["", "", "Vicky", "You BETTER!"],
    ["", "", "Sue", "Put it away. Far, far away."],
    ["", "Ben手忙脚乱地把臭T恤藏好，大家总算松了口气。Vicky捏着鼻子回到时间表前，继续往下念", "", ""],
    ["", "", "Vicky", "Okay... where was I..."],
    ["", "Vicky的手指滑到时间表的最后一栏，停住了，皱起眉头", "", ""],
    ["", "", "Vicky", "Wait. There is one more subject tomorrow."],
    ["", "", "Vicky", '"China." What is... "China"?'],
    ["", "", "Ben", "China? Is that a new game?"],
    ["", "", "User", "I've never seen this subject before."],
    ["", "Sue已经不知道什么时候抱来了一个地球仪，她把地球仪往桌上一放，转到亚洲方向", "", ""],
    ["", "", "Sue", "I know this one! China is not a subject name. It's a place!"],
    ["", "", "Sue", "Look. China is right here. A very big country!"],
    ["", "Sue用手指点着地球仪上中国的位置，大家围过去", "", ""],
    ["图片互动-单选", "【教研图】简化世界地图，标注几个地点（America、England、Japan、China），User找到China", "", ""],
    ["", "", "User", "Here! This is China!"],
    ["TL", "", "Ben", "Whoa, it's really big!"],
    ["", "大家正围着地球仪研究，突然窗外传来Kim的喊声\n【音效】从走廊远处传来的跑步声，越来越近", "", ""],
    ["", "", "Kim", "(画外音) Hey!! HEYYYY!!"],
    ["", "Kim从教室门口冲进来，上气不接下气", "", ""],
    ["", "", "Kim", "Big news... big news!"],
    ["", "", "Kim", "A new teacher is coming tomorrow!"],
    ["", "", "Sue", "A new teacher?"],
    ["", "", "Kim", "Yes! A SPECIAL teacher! For a new subject!"],
    ["", "", "User", "It must be for China! The new subject!"],
    ["", "", "Ben", "Cool! I wonder what the teacher looks like!"],
    ["", "Vicky没有说话，她盯着时间表上的\"China\"，慢慢皱起了眉\n【emoji】Vicky 😰", "", ""],
    ["", "", "Vicky", "I don't know why... but I have a bad feeling about tomorrow."],
    ["", "", "Ben", "Oh, come on, Vicky! A new teacher! How bad can it be?"],
    ["", "Vicky没接话，只是把书包拉链拉上。窗外夕阳把教室染成橘色，镜头慢慢推向黑板旁的时间表，最后一栏\"China\"旁边是一个大大的问号\n【音乐】轻快校园旋律，尾段带一丝悬念，渐弱", "", ""],
]

for r, row_data in enumerate(rows, 2):
    for c, val in enumerate(row_data, 1):
        cell = ws.cell(row=r, column=c, value=val)
        cell.alignment = wrap
        cell.border = thin_border

# ===== Sheet2: 知识点统计 =====
ws2 = wb.create_sheet("知识点统计")
ws2.column_dimensions['A'].width = 18
ws2.column_dimensions['B'].width = 15
ws2.column_dimensions['C'].width = 45
ws2.column_dimensions['D'].width = 10
ws2.column_dimensions['E'].width = 45
ws2.column_dimensions['F'].width = 10

kp_headers = ["知识点", "词性/类型", "输入详情", "输入次数", "输出详情", "输出次数"]
for col, h in enumerate(kp_headers, 1):
    cell = ws2.cell(row=1, column=col, value=h)
    cell.font = header_font
    cell.fill = header_fill
    cell.alignment = wrap
    cell.border = thin_border

kp_data = [
    ["Subject (n. 科目)", "名词", "User\"each subject\" / Vicky\"one more subject\" / User\"never seen this subject\" / Kim\"for a new subject\"", 4, "User对话互动\"right books for each subject\"", 1],
    ["China (n. 中国)", "名词", "Sue\"China is a place\" / Sue\"China is right here\"", 2, "User图片互动\"This is China!\"", 1],
    ["Lesson (n. 一节课)", "名词", "Vicky\"a math lesson, an English lesson\" / User\"a PE lesson three days ago\"", 2, "—", 0],
    ["Learn (v. 学习)", "动词", "未出现（段落2铺设）", 0, "—", 0],
    ["be proud of (句型)", "句型", "未出现（段落2铺设）", 0, "—", 0],
    ["learn about (句型)", "句型", "未出现（段落2铺设）", 0, "—", 0],
]

for r, row_data in enumerate(kp_data, 2):
    for c, val in enumerate(row_data, 1):
        cell = ws2.cell(row=r, column=c, value=val)
        cell.alignment = wrap
        cell.border = thin_border

output_path = "/root/.openclaw/workspace-xiaobian/output/China_Unit_Lesson1_段落1.xlsx"
wb.save(output_path)
print(f"Saved to {output_path}")
