#!/usr/bin/env python3
"""
Week 28: Repeated Addition → Multiplication
Phase 5: Multiplication Introduction

Standards: 2.OA.A.4 — connect repeated addition to multiplication notation

New Standard:
- Reduced drill (4-6 problems per section)
- Estimation before calculating
- Multiple strategies (repeated addition vs skip counting vs arrays)
- Better word problems (reasoning, "groups of" vocabulary)
- Open-ended challenges (Create Your Own)
- Number talks (explain WITHOUT calculating)
- Friday self-check with emoji reflection
"""

import os
import glob
from weasyprint import HTML

from math_helpers import (
    CSS, TEACHER_CSS,
    page, page_multi, hdr, sec, b, bw, bl,
    tg_page_multi, tg_sec, tg_note, tg_section_title,
    array_svg, eq_group_svg, grid_svg,
    star_svg, medal_svg, trophy_svg, check_svg,
    times_table_html, skip_count_html, mini_chart_html,
)
from activity_builders import (
    build_equal_groups,
    build_skip_counting,
    build_times_table,
    build_challenge_box,
    build_two_step_problems,
)

BASE = os.path.expanduser("~/Home_School/2nd_Grade/Math")
WEEK = os.path.join(BASE, "Week_28")


# ═══════════════════════════════════════════════════
# MONDAY — Meet the × Sign
# ═══════════════════════════════════════════════════
def monday():
    # 1: Fluency warmup — repeated addition review
    s1 = '<div class="abox" style="background:#e8f5e9;">'\
         '<p><b>2-min Fluency Warm-up</b> — Add the equal groups in your head.</p>'\
         '<div class="mgrid c3">'
    for expr in ["4 + 4", "3 + 3 + 3", "5 + 5", "2 + 2 + 2 + 2"]:
        s1 += f'<div class="abox"><p>{expr} = {b("3em")}</p></div>'
    s1 += '</div></div>'

    # 2: The × sign — guided intro (new concept)
    s2 = '<p class="note">The <b>×</b> sign means "groups of." '\
         '<b>3 × 4</b> means "3 groups of 4" — the same as 4 + 4 + 4!</p>'\
         '<div class="mgrid c2">'
    examples = [
        (3, 4, "4 + 4 + 4"),
        (2, 5, "5 + 5"),
    ]
    for g, n, add in examples:
        pic = ''.join(eq_group_svg(n) for _ in range(g))
        s2 += f'<div class="abox">{pic}'\
              f'<p>{add} = {g * n}</p>'\
              f'<p style="color:#1565c0; font-weight:700;">{g} × {n} = {g * n}</p>'\
              '<p style="font-size:11px; color:#666;">Say it: "' + f'{g} groups of {n}' + '"</p></div>'
    s2 += '</div>'

    # 3: Match repeated addition to multiplication (reduced from 6 to 4)
    s3 = '<p class="note">Write the multiplication sentence that matches. The first number is HOW MANY groups.</p>'\
         '<div class="mgrid c2">'
    for add, g, n in [("3 + 3 + 3 + 3", 4, 3), ("6 + 6", 2, 6), ("2 + 2 + 2", 3, 2), ("5 + 5 + 5", 3, 5)]:
        s3 += f'<div class="abox"><p>{add} = {g * n}</p>'\
              f'<p>{b("3em")} × {b("3em")} = {b("5em")}</p></div>'
    s3 += '</div>'

    # 4: Number Talk — what does × mean?
    s4 = '<div class="abox" style="background:#e3f2fd;">'\
         '<p><b>Number Talk</b> — Explain WITHOUT calculating.</p>'\
         '<div class="mgrid c2">'
    s4 += '<div class="abox"><p>Ben says 4 × 2 means "4 + 2."</p>'\
          '<p>Is Ben right? What does 4 × 2 REALLY mean?</p>'\
          '<p style="font-size:11px;">My thinking: ' + bw() + '</p></div>'
    s4 += '<div class="abox"><p>Which is bigger: 5 × 2 or 5 + 2?</p>'\
          '<p>How do you know?</p>'\
          '<p style="font-size:11px;">My thinking: ' + bw() + '</p></div>'
    s4 += '</div></div>'

    # 5: Challenge — write it three ways
    s5 = '<div class="abox" style="background:#f3e5f5;">'\
         '<p><b>Challenge</b> — Show 4 × 3 in <b>two different ways</b>: '\
         'as repeated addition AND as a drawing (groups or an array).</p>'\
         '<p>Way 1 (repeated addition): ' + bw("12em") + '</p>'\
         '<p>Way 2 (drawing):</p>'\
         '<p style="min-height:80px; border:1px dashed #999; border-radius:4px;"></p>'\
         '<p>4 × 3 = ' + b("3em") + '</p>'\
         '</div>'

    return page(28, "Monday", "Meet the × Sign",
        f'''{sec(1, "Warm-up: Add Equal Groups", s1)}
{sec(2, "The × Sign Means Groups Of", s2)}
{sec(3, "Match: Addition to Multiplication", s3)}
{sec(4, "Number Talk: What Does × Mean?", s4)}
{sec(5, "Challenge: Show Two Different Ways", s5)}''')


# ═══════════════════════════════════════════════════
# TUESDAY — From Pictures to Multiplication
# ═══════════════════════════════════════════════════
def tuesday():
    # 1: Fluency warmup — skip count by 3s
    s1 = '<div class="abox" style="background:#e8f5e9;">'\
         '<p><b>2-min Fluency Warm-up</b> — Skip count by 3s.</p>'
    s1 += build_skip_counting({
        "sequences": [
            {"start": 3, "step": 3, "count": 8, "blank_indices": [3, 6]},
            {"start": 3, "step": 3, "count": 8, "blank_indices": [2, 5, 7]},
        ],
        "note": "Counting by 3s helps with the 3s times table!"
    })
    s1 += '</div>'

    # 2: Pictures → three equations (reduced to 4)
    s2 = '<p class="note">For each picture write BOTH equations: the addition AND the multiplication.</p>'\
         '<div class="mgrid c2">'
    for r, c in [(3, 4), (2, 6), (4, 2), (3, 5)]:
        s2 += f'<div class="abox">{array_svg(r, c)}'\
              '<p style="font-size:11px;">Addition: ' + bw("10em") + '</p>'\
              f'<p>{b("3em")} × {b("3em")} = {b("5em")}</p></div>'
    s2 += '</div>'

    # 3: Estimate First! — will it be more or less than 20?
    s3 = '<div class="abox" style="background:#fff3e0;">'\
         '<p><b>Estimate First!</b> Before you solve, circle: will the answer be '\
         'MORE or LESS than 20? Then solve.</p>'\
         '<div class="mgrid c2">'
    for g, n in [(3, 5), (4, 6), (2, 7), (5, 5)]:
        s3 += f'<div class="abox"><p><b>{g} × {n}</b></p>'\
              '<p>more than 20 / less than 20</p>'\
              f'<p>Actual: {b("3em")}</p></div>'
    s3 += '</div></div>'

    # 4: Multiplication → repeated addition (reverse direction, reduced to 4)
    s4 = '<p class="note">Now go backwards! Write each multiplication as repeated addition, then solve.</p>'\
         '<div class="mgrid c2">'
    for g, n in [(3, 6), (4, 4), (2, 8), (5, 3)]:
        s4 += f'<div class="abox"><p><b>{g} × {n}</b></p>'\
              '<p style="font-size:11px;">Repeated addition: ' + bw("10em") + '</p>'\
              f'<p>Answer: {b("3em")}</p></div>'
    s4 += '</div>'

    # 5: Challenge — two strategies for one problem
    s5 = '<div class="abox" style="background:#f3e5f5;">'\
         '<p><b>Show Two Different Ways</b> — Solve <b>4 × 5</b> two ways: '\
         '(1) repeated addition, (2) skip counting.</p>'\
         '<p>Way 1 (addition): 5 + 5 + 5 + 5 = ' + b("3em") + '</p>'\
         '<p>Way 2 (skip count by 5s, four times): 5, ___, ___, ___</p>'\
         '<p>4 × 5 = ' + b("3em") + '</p>'\
         '<p style="font-size:11px; color:#666;">Which way felt faster for you? ' + bw() + '</p>'\
         '</div>'

    return page(28, "Tuesday", "From Pictures to Multiplication",
        f'''{sec(1, "Warm-up: Skip Count by 3s", s1)}
{sec(2, "Two Equations for One Picture", s2)}
{sec(3, "Estimate First!", s3)}
{sec(4, "Multiplication Back to Addition", s4)}
{sec(5, "Show Two Different Ways", s5)}''')


# ═══════════════════════════════════════════════════
# WEDNESDAY — Reading & Writing Multiplication
# ═══════════════════════════════════════════════════
def wednesday():
    # 1: Fluency warmup — quick equal-group adds
    s1 = '<div class="abox" style="background:#e8f5e9;">'\
         '<p><b>2-min Fluency Warm-up</b> — Solve in your head.</p>'\
         '<div class="mgrid c3">'
    for expr in ["2 + 2 + 2", "10 + 10", "4 + 4 + 4", "5 + 5 + 5 + 5"]:
        s1 += f'<div class="abox"><p>{expr} = {b("3em")}</p></div>'
    s1 += '</div></div>'

    # 2: Read the multiplication sentence in words (reduced to 4)
    s2 = '<p class="note">Read each multiplication sentence. Fill in the missing words or numbers.</p>'\
         '<div class="mgrid c2">'
    s2 += f'<div class="abox"><p><b>3 × 6 = 18</b></p><p>{b("3em")} groups of {b("3em")} make {b("5em")}</p></div>'
    s2 += f'<div class="abox"><p><b>5 × 2 = 10</b></p><p>{b("3em")} groups of {b("3em")} make {b("5em")}</p></div>'
    s2 += f'<div class="abox"><p>4 groups of 5 make 20</p><p>{b("3em")} × {b("3em")} = {b("5em")}</p></div>'
    s2 += f'<div class="abox"><p>2 groups of 9 make 18</p><p>{b("3em")} × {b("3em")} = {b("5em")}</p></div>'
    s2 += '</div>'

    # 3: Word problems — write the multiplication sentence
    s3 = '<div class="wp">'\
         '<p class="note">Write a multiplication sentence for each story. Then solve.</p>'\
         '<div class="mgrid c2">'
    problems = [
        ("A spider has 8 legs. How many legs do 2 spiders have?", "legs"),
        ("Each bicycle has 2 wheels. How many wheels are on 5 bicycles?", "wheels"),
    ]
    for text, unit in problems:
        s3 += f'<div class="abox"><p style="font-size:0.95em;">{text}</p>'\
              '<p>Multiplication sentence: ' + bw("9em") + '</p>'\
              '<p>' + b("4em") + f' {unit}</p></div>'
    s3 += '</div></div>'

    # 4: Find the error — mixed-up equations
    s4 = '<div class="abox">'\
         '<p class="note">One friend made a mistake. Check each one: ✓ or ✗? Fix the wrong one.</p>'\
         '<div class="mgrid c2">'
    s4 += '<div class="abox"><p>Ava wrote: 3 + 3 + 3 + 3 = <b>4 × 3</b></p>'\
          '<p>✓ or ✗?</p><p style="font-size:11px;">Explain: ' + bw() + '</p></div>'
    s4 += '<div class="abox"><p>Leo wrote: 5 + 5 + 5 = <b>5 × 3... = 20</b></p>'\
          '<p>✓ or ✗?</p><p style="font-size:11px;">Explain and fix: ' + bw() + '</p></div>'
    s4 += '</div></div>'

    # 5: Create your own
    s5 = '<div class="abox" style="background:#f3e5f5;">'\
         '<p><b>Create Your Own</b> — Pick your own numbers! Fill in the blanks, '\
         'draw the groups, and solve.</p>'\
         '<p>My multiplication: ' + b("3em") + ' × ' + b("3em") + '</p>'\
         '<p>As repeated addition: ' + bw("12em") + '</p>'\
         '<p>My drawing:</p>'\
         '<p style="min-height:60px; border:1px dashed #999; border-radius:4px;"></p>'\
         '<p>Answer: ' + b("3em") + '</p>'\
         '</div>'

    return page(28, "Wednesday", "Reading & Writing Multiplication",
        f'''{sec(1, "Warm-up: Mental Adding", s1)}
{sec(2, "Say It in Words: Groups Of", s2)}
{sec(3, "Word Problems: Write the Sentence", s3)}
{sec(4, "Find the Error", s4)}
{sec(5, "Challenge: Create Your Own", s5)}''')


# ═══════════════════════════════════════════════════
# THURSDAY — Multiplication Stories
# ═══════════════════════════════════════════════════
def thursday():
    # 1: Fluency warmup — skip counting mix
    s1 = '<div class="abox" style="background:#e8f5e9;">'\
         '<p><b>2-min Fluency Warm-up</b> — What comes next?</p>'\
         '<div class="mgrid c3">'
    for seq in ["3, 6, 9, ___", "4, 8, 12, ___", "6, 12, 18, ___", "5, 10, 15, ___"]:
        s1 += f'<div class="abox"><p>{seq.replace("___", b("3em"))}</p></div>'
    s1 += '</div></div>'

    # 2: Better word problems — real-world (reduced to 3)
    s2 = '<div class="wp">'\
         '<p class="note">Read carefully! Underline the important numbers. Think: how many groups? How many in each? Write the multiplication sentence and solve.</p>'\
         '<div class="mgrid c2">'
    problems = [
        ("A pack of juice boxes has 6 boxes. Mom buys 3 packs for the picnic. How many juice boxes did she buy?", "juice boxes"),
        ("There are 4 fish tanks at the pet store. Each tank has 5 fish. How many fish are there in all?", "fish"),
        ("Sam reads 10 pages every night. How many pages does he read in 3 nights?", "pages"),
    ]
    for text, unit in problems:
        s2 += f'<div class="abox"><p style="font-size:0.95em;">{text}</p>'\
              '<p>Multiplication sentence: ' + bw("9em") + '</p>'\
              '<p>' + b("4em") + f' {unit}</p></div>'
    s2 += '</div></div>'

    # 3: Two-step problem
    s3 = '<div class="abox">'\
         '<p class="note">Solve step by step. Write each answer as you go.</p>'\
         + build_two_step_problems({
             "problems": [
                 {
                     "text": "Ella buys 3 packs of stickers. Each pack has 5 stickers. She gives 4 stickers to her brother. How many stickers does Ella have left?",
                     "blanks": 2
                 }
             ],
             "note": "Step 1: multiply to find the total. Step 2: subtract."
         }) + '</div>'

    # 4: Number Talk — compare without calculating
    s4 = '<div class="abox" style="background:#e3f2fd;">'\
         '<p><b>Number Talk</b> — Explain WITHOUT calculating.</p>'\
         '<div class="mgrid c2">'
    s4 += '<div class="abox"><p>A: 3 × 6</p><p>B: 4 × 6</p>'\
          '<p>Which is bigger? How much bigger?</p>'\
          '<p style="font-size:11px;">My thinking: ' + bw() + '</p></div>'
    s4 += '<div class="abox"><p>A: 2 × 10</p><p>B: 10 + 10</p>'\
          '<p>Which is bigger, or are they the same?</p>'\
          '<p style="font-size:11px;">My thinking: ' + bw() + '</p></div>'
    s4 += '</div></div>'

    # 5: Create your own multiplication story
    s5 = '<div class="abox" style="background:#f3e5f5;">'\
         '<p><b>Create Your Own Word Problem</b></p>'\
         '<p>Write a multiplication story about equal groups (packs, teams, legs, wheels, rows...). '\
         'Use the word "each." Then write the multiplication sentence and solve.</p>'\
         '<p style="min-height:60px; border-bottom:1px solid #333;"></p>'\
         '<p style="min-height:30px; border-bottom:1px solid #333;"></p>'\
         '<p>Multiplication sentence: ' + bw("9em") + '</p>'\
         '<p>Answer: ' + bl() + '</p>'\
         '</div>'

    return page(28, "Thursday", "Multiplication Stories",
        f'''{sec(1, "Warm-up: What Comes Next?", s1)}
{sec(2, "Word Problems: Groups in Real Life", s2)}
{sec(3, "Two-Step Problem", s3)}
{sec(4, "Number Talk: Compare", s4)}
{sec(5, "Challenge: Create Your Own", s5)}''')


# ═══════════════════════════════════════════════════
# FRIDAY — Review & Self-Check
# ═══════════════════════════════════════════════════
def friday():
    # 1: Fluency warmup
    s1 = '<div class="abox" style="background:#e8f5e9;">'\
         '<p><b>2-min Fluency Warm-up</b> — Solve in your head. Go fast!</p>'\
         '<div class="mgrid c3">'
    for expr in ["3 + 3 + 3", "5 + 5 + 5", "2 + 2 + 2 + 2 + 2", "4 + 4"]:
        s1 += f'<div class="abox"><p>{expr} = {b("3em")}</p></div>'
    s1 += '</div></div>'

    # 2: Estimate First!
    s2 = '<div class="abox" style="background:#fff3e0;">'\
         '<p><b>Estimate First!</b> Circle MORE or LESS than 15, then solve.</p>'\
         '<div class="mgrid c2">'
    for g, n in [(4, 5), (2, 6), (3, 7), (2, 4)]:
        s2 += f'<div class="abox"><p><b>{g} × {n}</b></p>'\
              '<p>more than 15 / less than 15</p>'\
              f'<p>Actual: {b("3em")}</p></div>'
    s2 += '</div></div>'

    # 3: Review — three representations (reduced to 4)
    s3 = '<p class="note">Complete the table for each picture: addition sentence AND multiplication sentence.</p>'\
         '<div class="mgrid c2">'
    for r, c in [(2, 5), (3, 3), (4, 3), (2, 7)]:
        s3 += f'<div class="abox">{array_svg(r, c)}'\
              '<p style="font-size:11px;">Addition: ' + bw("10em") + '</p>'\
              f'<p>{b("3em")} × {b("3em")} = {b("5em")}</p></div>'
    s3 += '</div>'

    # 4: Word problem review (reduced to 2)
    s4 = '<div class="wp">'\
         '<p class="note">Write the multiplication sentence and solve.</p>'\
         '<div class="mgrid c2">'
    problems = [
        ("A dog has 4 legs. How many legs do 5 dogs have?", "legs"),
        ("Each flower has 5 petals. How many petals are on 4 flowers?", "petals"),
    ]
    for text, unit in problems:
        s4 += f'<div class="abox"><p style="font-size:0.95em;">{text}</p>'\
              '<p>Multiplication sentence: ' + bw("9em") + '</p>'\
              '<p>' + b("4em") + f' {unit}</p></div>'
    s4 += '</div></div>'

    # 5: Self-check with emoji reflection
    s5 = '<div class="selfcheck">'\
         '<p><b>Self-Check: How do you feel about multiplication?</b></p>'\
         '<div style="display:flex; gap:20px; flex-wrap:wrap;">'\
         '<div style="background:#fff3e0; padding:10px; border-radius:5px; flex:1; min-width:150px;">'\
         '<p><b>What the × Sign Means</b></p>'\
         '<p>😊 I got it!  |  😐 Getting there  |  😟 Need help</p>'\
         '</div>'\
         '<div style="background:#e3f2fd; padding:10px; border-radius:5px; flex:1; min-width:150px;">'\
         '<p><b>Repeated Addition ↔ Multiplication</b></p>'\
         '<p>😊 I got it!  |  😐 Getting there  |  😟 Need help</p>'\
         '</div>'\
         '<div style="background:#f3e5f5; padding:10px; border-radius:5px; flex:1; min-width:150px;">'\
         '<p><b>Multiplication Word Problems</b></p>'\
         '<p>😊 I got it!  |  😐 Getting there  |  😟 Need help</p>'\
         '</div>'\
         '</div>'\
         '<p style="margin-top:10px;"><b>One thing I learned this week:</b> ' + bl() + '</p>'\
         '<p><b>One thing I want to practice more:</b> ' + bl() + '</p>'\
         '<p><b>My favorite strategy (adding, skip counting, or drawing):</b> ' + bl() + '</p>'\
         '</div>'

    return page(28, "Friday", "Week 28 Review & Self-Check",
        f'''{sec(1, "Warm-up: Mental Adding", s1)}
{sec(2, "Estimate First!", s2)}
{sec(3, "Review: Picture, Addition, Multiplication", s3)}
{sec(4, "Word Problems", s4)}
{sec(5, "Self-Check & Reflection", s5)}''')


# ═══════════════════════════════════════════════════
# TEACHER GUIDE — Combined for all days
# ═══════════════════════════════════════════════════
def teacher_guide():
    return tg_page_multi(
        "Week 28", "Repeated Addition → Multiplication — Teacher Guide",

        # Monday
        tg_section_title("Monday: Meet the × Sign") +
        tg_sec(1, "Warm-up", ["8, 9, 10, 8"]) +
        tg_sec(2, "The × Sign", ["Guided examples: 3×4=12, 2×5=10 — emphasize 'groups of' language"]) +
        tg_sec(3, "Match", ["4×3=12, 2×6=12, 3×2=6, 3×5=15"]) +
        tg_sec(4, "Number Talk", ["Ben is wrong — 4×2 means 4 groups of 2 (2+2+2+2)", "5×2=10 is bigger than 5+2=7"]) +
        tg_sec(5, "Challenge", ["3+3+3+3=12; any drawing of 4 groups of 3 or 4×3 array"]) +
        tg_note("Page break"),

        # Tuesday
        tg_section_title("Tuesday: From Pictures to Multiplication") +
        tg_sec(1, "Warm-up 3s", ["Seq 1 blanks: 12, 21 | Seq 2 blanks: 9, 18, 24"]) +
        tg_sec(2, "Two Equations", ["3×4=12 (4+4+4); 2×6=12 (6+6); 4×2=8 (2+2+2+2); 3×5=15 (5+5+5)"]) +
        tg_sec(3, "Estimate First", ["3×5=15 less; 4×6=24 more; 2×7=14 less; 5×5=25 more"]) +
        tg_sec(4, "Back to Addition", ["6+6+6=18; 4+4+4+4=16; 8+8=16; 3+3+3+3+3=15"]) +
        tg_sec(5, "Two Ways", ["20 both ways; skip count 5, 10, 15, 20"]) +
        tg_note("Page break"),

        # Wednesday
        tg_section_title("Wednesday: Reading & Writing Multiplication") +
        tg_sec(1, "Warm-up", ["6, 20, 12, 20"]) +
        tg_sec(2, "Say It in Words", ["3 groups of 6 make 18; 5 groups of 2 make 10; 4×5=20; 2×9=18"]) +
        tg_sec(3, "Word Problems", ["2×8=16 legs; 5×2=10 wheels"]) +
        tg_sec(4, "Find Error", ["Ava ✓ (4 threes)", "Leo ✗ — should be 3×5 and equals 15, not 20"]) +
        tg_sec(5, "Create Own", ["Accept any correct student multiplication with drawing"]) +
        tg_note("Page break"),

        # Thursday
        tg_section_title("Thursday: Multiplication Stories") +
        tg_sec(1, "Warm-up", ["12, 16, 24, 20"]) +
        tg_sec(2, "Word Problems", ["3×6=18 juice boxes; 4×5=20 fish; 3×10=30 pages"]) +
        tg_sec(3, "Two-Step", ["Step 1: 3×5=15 stickers. Step 2: 15−4=11 stickers"]) +
        tg_sec(4, "Number Talk", ["4×6 is bigger by one group of 6", "Same — 2×10 means 10+10=20"]) +
        tg_sec(5, "Create Own", ["Accept student stories with 'each' and correct sentence"]) +
        tg_note("Page break"),

        # Friday
        tg_section_title("Friday: Review & Self-Check") +
        tg_sec(1, "Warm-up", ["9, 15, 10, 8"]) +
        tg_sec(2, "Estimate First", ["4×5=20 more; 2×6=12 less; 3×7=21 more; 2×4=8 less"]) +
        tg_sec(3, "Review", ["2×5=10 (5+5); 3×3=9 (3+3+3); 4×3=12 (3+3+3+3); 2×7=14 (7+7)"]) +
        tg_sec(4, "Word Problems", ["5×4=20 legs; 4×5=20 petals"]) +
        tg_sec(5, "Self-Check", ["Accept student self-assessment and reflection"])
    )


# ═══════════════════════════════════════════════════
# GENERATE
# ═══════════════════════════════════════════════════
if __name__ == "__main__":
    os.makedirs(WEEK, exist_ok=True)
    for f in glob.glob(os.path.join(WEEK, "*.pdf")):
        os.remove(f)
    for f in glob.glob(os.path.join(WEEK, "*.html")):
        os.remove(f)

    days = [
        (monday, "Monday", "Meet the × Sign"),
        (tuesday, "Tuesday", "From Pictures to Multiplication"),
        (wednesday, "Wednesday", "Reading & Writing Multiplication"),
        (thursday, "Thursday", "Multiplication Stories"),
        (friday, "Friday", "Week 28 Review & Self-Check"),
    ]

    for lesson_func, day, title in days:
        html = lesson_func()
        fname = f"Week_28_{day}"
        path = os.path.join(WEEK, f"{fname}.html")
        with open(path, "w") as f:
            f.write(html)
        pdf_path = os.path.join(WEEK, f"{fname}.pdf")
        HTML(filename=path).write_pdf(pdf_path)
        print(f"Generated: {pdf_path}")

    html = teacher_guide()
    path = os.path.join(WEEK, "Week_28_Teacher_Guide.html")
    with open(path, "w") as f:
        f.write(html)
    pdf_path = os.path.join(WEEK, "Week_28_Teacher_Guide.pdf")
    HTML(filename=path).write_pdf(pdf_path)
    print(f"Generated: {pdf_path}")

    print("\nWeek 28 (Repeated Addition → Multiplication) complete!")
