#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Kalan kısımları ekle: Deneme 3 (Zor), 3 Okuma, tüm cevap anahtarları."""

from docx import Document
from docx.shared import Pt, Cm, RGBColor
from docx.enum.text import WD_ALIGN_PARAGRAPH
from docx.enum.table import WD_TABLE_ALIGNMENT
from docx.oxml.ns import qn

PATH = "/root/Akademik/İngilizce/5. Sınıf/Unit1_My_Day_Kitap.docx"
doc = Document(PATH)

def heading(text, size=14, color=(0x1a, 0x47, 0x8a)):
    doc.add_paragraph()
    p = doc.add_paragraph()
    p.alignment = WD_ALIGN_PARAGRAPH.CENTER
    r = p.add_run(text)
    r.bold = True; r.font.size = Pt(size); r.font.color.rgb = RGBColor(*color)
    p.paragraph_format.space_before = Pt(12)
    p.paragraph_format.space_after = Pt(6)

def section_header(text):
    doc.add_paragraph()
    p = doc.add_paragraph()
    r = p.add_run(text)
    r.bold = True; r.font.size = Pt(12); r.font.color.rgb = RGBColor(0x1a, 0x47, 0x8a)
    p.paragraph_format.space_before = Pt(10)
    p.paragraph_format.space_after = Pt(6)

def sub(text):
    p = doc.add_paragraph()
    r = p.add_run(text)
    r.font.size = Pt(10); r.font.color.rgb = RGBColor(0x66, 0x66, 0x66)
    r.italic = True

def add_q(num, stem, opts):
    p = doc.add_paragraph()
    r = p.add_run(f"{num}. {stem}")
    r.bold = True; r.font.size = Pt(11)
    for o in opts:
        p2 = doc.add_paragraph()
        p2.paragraph_format.left_indent = Cm(1)
        p2.paragraph_format.space_before = Pt(1)
        p2.paragraph_format.space_after = Pt(1)
        r = p2.add_run(o)
        r.font.size = Pt(11)

def add_passage(text, title=None):
    if title:
        p = doc.add_paragraph()
        r = p.add_run(title)
        r.bold = True; r.font.size = Pt(11); r.italic = True
    table = doc.add_table(rows=1, cols=1)
    table.alignment = WD_TABLE_ALIGNMENT.CENTER
    cell = table.cell(0, 0)
    p = cell.paragraphs[0]
    r = p.add_run(text)
    r.font.size = Pt(11); r.italic = True
    shading = cell._element.get_or_add_tcPr()
    shd = shading.makeelement(qn('w:shd'), {qn('w:val'): 'clear', qn('w:color'): 'auto', qn('w:fill'): 'F0F4F8'})
    shading.append(shd)

def answer_page(answers, title):
    heading(title, size=14)
    doc.add_paragraph()
    # 2-column answers
    half = len(answers) // 2 + len(answers) % 2
    left = answers[:half]
    right = answers[half:]
    while len(right) < len(left):
        right.append(None)
    for a, b in zip(left, right):
        p = doc.add_paragraph()
        p.paragraph_format.space_after = Pt(2)
        r = p.add_run(f"Soru {a[0]}: {a[1]}")
        r.bold = True; r.font.size = Pt(10)
        if b:
            r2 = p.add_run(f"        Soru {b[0]}: {b[1]}")
            r2.bold = True; r2.font.size = Pt(10)
    doc.add_paragraph()
    p = doc.add_paragraph()
    r = p.add_run("AÇIKLAMALAR")
    r.bold = True; r.font.size = Pt(11); r.font.color.rgb = RGBColor(0x1a, 0x47, 0x8a)
    doc.add_paragraph()
    for n, a, e in answers:
        p = doc.add_paragraph()
        p.paragraph_format.space_after = Pt(3)
        r = p.add_run(f"Q{n} ({a}): ")
        r.bold = True; r.font.size = Pt(9)
        r = p.add_run(e)
        r.font.size = Pt(9); r.font.color.rgb = RGBColor(0x55, 0x55, 0x55)

# ================================================================
# DENEME 3 - ZOR
# ================================================================
section_header("DENEME 3 - ZOR")
sub("15 Soru  |  Sure: 20 Dakika  |  Trik Noktalar Odakli")
doc.add_paragraph()

add_q(1,
    "A: Is your mother at home?\nB: No. She _______ at work until 6 o'clock.",
    ["A) is", "B) am", "C) are", "D) be"])
add_q(2,
    "A: Are you and your brother ready?\nB: No, we _______ . We are still eating breakfast.",
    ["A) is", "B) aren't", "C) isn't", "D) not"])
add_q(3,
    "My sister and I _______ twins. _______ birthdays are in June.",
    ["A) are / Us", "B) is / Our", "C) are / Our", "D) am / We"])
add_q(4,
    "A: Is David a good student?\nB: Yes, _______ . He always does his homework.",
    ["A) he is", "B) he's", "C) he does", "D) he has"])
add_q(5,
    "Look at _______ ! She is dancing very well.",
    ["A) she", "B) her", "C) he", "D) him"])
add_q(6,
    "A: _______ is your English lesson?\nB: It is at 9 o'clock _______ the morning.",
    ["A) When / in", "B) What time / at", "C) What time / in", "D) When / at"])
add_q(7,
    "My brother is only 2 years old. I help _______ to brush _______ teeth.",
    ["A) him / his", "B) he / him", "C) her / his", "D) him / he"])
add_q(8,
    "A: Are your parents at home now?\nB: No, _______ . They are at work.",
    ["A) they aren't", "B) they are", "C) they isn't", "D) it isn't"])
add_q(9,
    "It is half past seven. I wake up at 7:30. I wake up _______ half past seven.",
    ["A) before", "B) at", "C) after", "D) in"])
add_q(10,
    "My father gets up _______ 6:30 but I get up _______ 7 o'clock.",
    ["A) at / at", "B) in / at", "C) at / in", "D) in / in"])
add_q(11,
    "A: What time is it?\nB: It is quarter _______ nine. (08:45)",
    ["A) past", "B) to", "C) after", "D) half"])
add_q(12,
    "I like my grandmother very much. I visit _______ every weekend.",
    ["A) she", "B) her", "C) him", "D) they"])
add_q(13,
    "My teacher gives _______ a lot of homework but I like _______ .",
    ["A) we / she", "B) us / her", "C) our / him", "D) they / it"])
add_q(14,
    "A: What do you do _______ breakfast?\nB: I brush my teeth.",
    ["A) after", "B) before", "C) at", "D) in"])
add_q(15,
    "It is 8 o'clock. School starts at 8:30. School starts _______ 8 o'clock.",
    ["A) at", "B) before", "C) after", "D) in"])

# ================================================================
# OKUMA 1 - KOLAY
# ================================================================
section_header("OKUMA 1 - KOLAY")
sub("Asagidaki metni okuyunuz. Sorulari metne gore cevaplayiniz.")

add_passage(
    "Hello! My name is Ayse. I am 10 years old. I am a student. "
    "I live in Nicosia with my family. I wake up at 7 o'clock every morning. "
    "After I wake up, I wash my face and brush my teeth. "
    "Then, I have breakfast with my mother and father. "
    "I eat cereal and drink milk for breakfast. "
    "After breakfast, I get dressed and go to school. "
    "School starts at 8:30. I have lunch at 12 o'clock at school. "
    "I come home at 3 o'clock. Before dinner, I do my homework. "
    "I have dinner with my family at 7 o'clock. After dinner, I watch TV. "
    "I go to bed at 9 o'clock. I am very happy!",
    title="Ayse's Day"
)
doc.add_paragraph()

add_q(1, "How old is Ayse?",
    ["A) 9", "B) 10", "C) 11", "D) 12"])
add_q(2, "What does Ayse do after she wakes up?",
    ["A) She has breakfast.", "B) She goes to school.",
     "C) She washes her face and brushes her teeth.", "D) She gets dressed."])
add_q(3, "What time does school start?",
    ["A) At 7 o'clock", "B) At 8 o'clock", "C) At 8:30", "D) At 9 o'clock"])
add_q(4, "What does Ayse do before dinner?",
    ["A) She watches TV.", "B) She does her homework.",
     "C) She has lunch.", "D) She goes to bed."])
add_q(5, "What time does Ayse go to bed?",
    ["A) At 7 o'clock", "B) At 8 o'clock", "C) At 9 o'clock", "D) At 10 o'clock"])

# ================================================================
# OKUMA 2 - ORTA
# ================================================================
section_header("OKUMA 2 - ORTA")
sub("Asagidaki metni okuyunuz. Sorulari metne gore cevaplayiniz.")

add_passage(
    "Hi! I am Mehmet. I am 11 years old. I am in the 5th grade. "
    "I have a big family. There are five people in my family: my mother, my father, "
    "my two sisters and me. My sisters are younger than me. Their names are Elif and Zeynep. "
    "Elif is 7 and Zeynep is 4 years old. They are very cute but they are noisy in the morning! "
    "My mother is a teacher. She works at a school in Kyrenia. "
    "She wakes up very early at 5:30 every day. After she wakes up, she prepares breakfast for us. "
    "My father is a doctor. He works at a hospital. He wakes up at 6 o'clock. "
    "Before he goes to work, he drinks coffee and reads the newspaper. "
    "I wake up at 7 o'clock. I have breakfast with my sisters at 7:30. "
    "After breakfast, I brush my teeth and get dressed. My mother takes us to school at 8 o'clock. "
    "School starts at 8:30. My favourite lesson is English. Our English teacher is Mrs. Smith. She is very kind. "
    "After school, I come home at 3 o'clock. I do my homework before dinner. "
    "After dinner, I play with my sisters or watch TV. "
    "I go to bed at 9:30. My sisters go to bed at 8:30 because they are younger.",
    title="Mehmet and His Family"
)
doc.add_paragraph()

add_q(1, "How many sisters does Mehmet have?",
    ["A) One", "B) Two", "C) Three", "D) Four"])
add_q(2, "What does Mehmet's mother do?",
    ["A) She is a doctor.", "B) She is a teacher.",
     "C) She is a nurse.", "D) She is a student."])
add_q(3, "What does Mehmet's father do before he goes to work?",
    ["A) He prepares breakfast.", "B) He reads a book.",
     "C) He drinks coffee and reads the newspaper.", "D) He takes a shower."])
add_q(4, "Why do Mehmet's sisters go to bed at 8:30?",
    ["A) Because they are tired.", "B) Because they are younger.",
     "C) Because they don't like TV.", "D) Because Mehmet goes to bed early."])
add_q(5, "What is true about Mrs. Smith?",
    ["A) She is Mehmet's mother.", "B) She is strict.",
     "C) She is very kind.", "D) She teaches Maths."])

# ================================================================
# OKUMA 3 - ZOR
# ================================================================
section_header("OKUMA 3 - ZOR")
sub("Asagidaki metni okuyunuz. Sorulari metne gore cevaplayiniz.")

add_passage(
    "It is a busy morning in the Brown family. Mr. Brown is a carpenter. He works in a workshop near their house. "
    "He usually wakes up at 6 o'clock. But today is different. Today, he is not at the workshop. "
    "He is at home because it is his birthday! Mrs. Brown is in the kitchen. She is preparing a special breakfast for him. "
    "She is a wonderful cook. Their children, Tom and Emily, are in their rooms. "
    "Tom is 12 years old. He is getting dressed. He has a big exam at school today. "
    "He is a little nervous. Emily is 9 years old. She is brushing her long, brown hair in front of the mirror. "
    "She is very happy because today is also her best friend's birthday party after school. "
    "Grandpa Brown is in the garden. He is 75 years old but he is very strong. He is watering the flowers. "
    "He lives with the family. He is a very kind man. He always helps Mrs. Brown in the garden. "
    "At 7 o'clock, the family is at the breakfast table. There are pancakes, eggs, fruit, and orange juice. "
    "Mr. Brown is very happy. 'Thank you, everyone! This is a perfect morning!' he says. "
    "Before they eat, Tom says, 'Happy birthday, Dad!' and gives him a small box. "
    "Inside the box, there is a beautiful pen. Mr. Brown loves it. "
    "After breakfast, Tom goes to school. Emily goes to school too, but after school, she is going to the party. "
    "Mr. Brown stays at home with Mrs. Brown. It is a special day for all of them.",
    title="A Special Morning - The Brown Family"
)
doc.add_paragraph()

add_q(1, "Why is Mr. Brown at home today instead of at the workshop?",
    ["A) He is sick.", "B) It is his birthday.",
     "C) The workshop is closed.", "D) He is on holiday."])
add_q(2, "What is Emily doing before breakfast?",
    ["A) She is studying for an exam.",
     "B) She is getting dressed.",
     "C) She is brushing her hair.",
     "D) She is watering the flowers."])
add_q(3, "Who lives with the Brown family?",
    ["A) Emily's best friend.", "B) Mrs. Brown's mother.",
     "C) Grandpa Brown.", "D) Tom's friend."])
add_q(4, "What does Tom give his father?",
    ["A) A book.", "B) A watch.", "C) A pen.", "D) A box of chocolates."])
add_q(5, "What is Tom nervous about?",
    ["A) His birthday party.", "B) His exam at school.",
     "C) His grandfather's health.", "D) The breakfast."])
add_q(6, "What can we understand about Grandpa Brown from the text?",
    ["A) He is 75 and very weak.",
     "B) He helps in the garden.",
     "C) He doesn't like breakfast.",
     "D) He lives in another house."])

# ================================================================
# CEVAP ANAHTARLARI
# ================================================================
doc.add_page_break()

a1 = [
    (1,"B","am/is/are: I am 10 years old - I + am"),
    (2,"A","She is a student. She + is"),
    (3,"C","We are friends. We (cogul) + are"),
    (4,"B","It is quarter past eight (8:15 = quarter past)"),
    (5,"C","at 7 o'clock - saatlerde at"),
    (6,"A","You are. You (tekil/cogul) + are"),
    (7,"B","I love her. Fiilden sonra object pronoun"),
    (8,"C","wash my face - face yikanir (vocab)"),
    (9,"C","He is not (isn't) at home. Olumsuz: is + not"),
    (10,"B","brush my teeth - teeth fircalanir (vocab)"),
    (11,"D","Are they happy? - they (cogul) + are + soru"),
    (12,"A","Yes, I am. - kisa cevapta kisaltma olmaz"),
    (13,"B","head, shoulders, knees - body parts (vocab)"),
    (14,"C","before school - okuldan once"),
    (15,"B","Give it to me. - to'dan sonra object pronoun"),
]
answer_page(a1, "DENEME 1 - CEVAP ANAHTARI")

a2 = [
    (1,"A","is not = isn't, 3. tekil sahis"),
    (2,"B","We - are (cogul 1. sahis)"),
    (3,"B","Look at him. - edattan sonra object pronoun"),
    (4,"C","Are you ready? -> Yes, I am. (kisa cevap)"),
    (5,"D","Are... or...? -> They are (cogul)"),
    (6,"C","in the morning (sabahleyin), at night (geceleyin)"),
    (7,"C","Her name - iyelik sifati. She likes me - object pronoun"),
    (8,"B","It is time for school. - zaman ifadesi + for"),
    (9,"A","before I go to bed - before + cumle, ozne gerekir"),
    (10,"C","half past five (5:30)"),
    (11,"C","quarter to twelve (11:45)"),
    (12,"B","I play with them. - Amy+Tom = they (cogul) -> them"),
    (13,"C","quarter to eight (07:45 = 8'e ceyrek var)"),
    (14,"C","wash my face - daily routine (vocab)"),
    (15,"D","What time - saati sorma"),
]
answer_page(a2, "DENEME 2 - CEVAP ANAHTARI")

a3 = [
    (1,"A","Is -> is (soru is, cevap is - yer bildiriyor)"),
    (2,"B","Are you...? -> No, we aren't. aren't = are not"),
    (3,"C","My sister and I = We -> are. Our birthdays (iyelik)"),
    (4,"A","Is he...? -> Yes, he is. (he's X kisa cevapta)"),
    (5,"B","Look at her - edattan sonra object pronoun (she X)"),
    (6,"C","What time (saat sorusu), in the morning"),
    (7,"A","help him (object), his teeth (possessive)"),
    (8,"A","Are your parents? -> No, they aren't. (cogul)"),
    (9,"B","It is half past seven = 7:30. at half past seven"),
    (10,"A","at 6:30 / at 7 o'clock - saatlerde at"),
    (11,"B","quarter to nine = 08:45 (9'a ceyrek var)"),
    (12,"B","visit her - grandmother = she -> her"),
    (13,"B","gives us (object), like her (teacher = she -> her)"),
    (14,"B","Before breakfast - kahvaltidan once dis fircalama"),
    (15,"C","8:00 -> 8:30, school starts AFTER 8 o'clock"),
]
answer_page(a3, "DENEME 3 - CEVAP ANAHTARI")

# Okuma cevaplari
doc.add_page_break()
heading("OKUMA PARCALARI - CEVAP ANAHTARI", size=14)
doc.add_paragraph()

okuma = [
    ("OKUMA 1 - Kolay (Ayse's Day)", [(1,"B"),(2,"C"),(3,"C"),(4,"B"),(5,"C")]),
    ("OKUMA 2 - Orta (Mehmet and His Family)", [(1,"B"),(2,"B"),(3,"C"),(4,"B"),(5,"C")]),
    ("OKUMA 3 - Zor (A Special Morning)", [(1,"B"),(2,"C"),(3,"C"),(4,"C"),(5,"B"),(6,"B")]),
]

for name, qs in okuma:
    p = doc.add_paragraph()
    r = p.add_run(name)
    r.bold = True; r.font.size = Pt(11); r.font.color.rgb = RGBColor(0x1a, 0x47, 0x8a)
    for n, a in qs:
        pp = doc.add_paragraph()
        pp.paragraph_format.left_indent = Cm(0.5)
        pp.paragraph_format.space_after = Pt(2)
        r = pp.add_run(f"Soru {n}: {a}")
        r.font.size = Pt(10)

doc.save(PATH)
print(f"OK! Kaydedildi: {PATH}")
