#!/usr/bin/env python3
"""
Week 25: Patterns & Rules — REWRITTEN
Phase 4: Geometry, Fractions & Patterns
Standards: 2.OA.A.3 (odd/even — pair objects, write equations of equal addends),
2.OA.C.4 (equal groups / arrays as foundation for patterns)

New Standard:
- Reduced drill (40% fewer problems)
- Estimation before calculating (predict the pattern first)
- Multiple strategies encouraged (pairing, doubling, skip counting)
- Better word problems (reasoning over keywords)
- Real challenges (open-ended: create your own patterns)
- Number talks (odd or even WITHOUT counting every object)
- Friday self-check with reflection
- Fact fluency warmup daily
- Word problems every day
"""

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,
    shape_svg, array_svg, circle_svg, star_svg,
)
from activity_builders import (
    build_skip_counting,
    build_equal_groups,
    build_challenge_box,
)

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

BLUE = "#1e88e5"
RED = "#e53935"
GREEN = "#43a047"


def dot_row(n, color=BLUE):
    """Row of n dots for pairing activities."""
    dots = ''.join(circle_svg(color) for _ in range(n))
    return f'<div style="display:flex; gap:4px; flex-wrap:wrap; align-items:center;">{dots}</div>'


def shape_pattern(shapes, blanks=2):
    """Render a repeating shape pattern with blank boxes at the end."""
    html = '<div style="display:flex; gap:6px; align-items:center; flex-wrap:wrap;">'
    for sh, color in shapes:
        html += shape_svg(sh, color, 30)
    for _ in range(blanks):
        html += '<div style="width:34px; height:34px; border:2px dashed #999; border-radius:4px;"></div>'
    html += '</div>'
    return html


# ═══════════════════════════════════════════════════
# MONDAY — Repeating Patterns: Find the Rule
# ═══════════════════════════════════════════════════
def monday():
    # 1: Fluency warmup
    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 ["6 + 6", "8 + 8", "5 + 5", "9 + 9"]:
        s1 += f'<div class="abox"><p>{expr} = {b("4em")}</p></div>'
    s1 += '</div></div>'

    # 2: Learn — every pattern has a RULE
    s2 = '<p class="note">A <b>pattern</b> repeats by following a <b>rule</b>. '\
         'Find the part that repeats — that is called the <b>core</b>.</p>'
    s2 += '<div class="abox"><p><b>Example:</b> circle, square, circle, square... The rule is: <b>circle, square</b> repeats!</p>'
    s2 += shape_pattern([("circle", BLUE), ("square", RED), ("circle", BLUE), ("square", RED), ("circle", BLUE), ("square", RED)], 0)
    s2 += '</div>'

    # 3: Continue shape patterns (reduced from 6 to 4)
    s3 = '<p class="note">Draw the next 2 shapes in each pattern. Write the rule.</p>'\
         '<div class="mgrid c1">'
    patterns = [
        ([("triangle", GREEN), ("triangle", GREEN), ("circle", BLUE), ("triangle", GREEN), ("triangle", GREEN), ("circle", BLUE)], "AAB"),
        ([("square", RED), ("circle", BLUE), ("star", "#fbc02d"), ("square", RED), ("circle", BLUE), ("star", "#fbc02d")], "ABC"),
        ([("circle", BLUE), ("circle", RED), ("circle", BLUE), ("circle", RED), ("circle", BLUE), ("circle", RED)], "AB colors"),
        ([("square", GREEN), ("square", GREEN), ("triangle", RED), ("triangle", RED), ("square", GREEN), ("square", GREEN)], "AABB"),
    ]
    for shapes, _rule in patterns:
        s3 += f'<div class="abox">{shape_pattern(shapes, 2)}'\
              '<p style="font-size:11px; margin-top:4px;">The rule: ' + bw() + '</p></div>'
    s3 += '</div>'

    # 4: Number Talk — spot the rule WITHOUT continuing
    s4 = '<div class="abox" style="background:#e3f2fd;">'\
         '<p><b>Number Talk</b> — Explain WITHOUT calculating every number.</p>'\
         '<div class="mgrid c2">'
    s4 += '<div class="abox"><p>2, 4, 6, 8, 10, ...</p><p>Will the number <b>25</b> ever appear in this pattern? How do you know without counting all the way?</p>'\
          '<p style="font-size:11px;">My thinking: ' + bw() + '</p></div>'
    s4 += '<div class="abox"><p>5, 10, 15, 20, ...</p><p>Will <b>52</b> ever appear? How do you know?</p>'\
          '<p style="font-size:11px;">My thinking: ' + bw() + '</p></div>'
    s4 += '</div></div>'

    # 5: Challenge — Create Your Own pattern
    s5 = '<div class="abox" style="background:#f3e5f5;">'\
         '<p><b>Create Your Own</b> — Draw your own repeating shape pattern. Use at least 2 different shapes. '\
         'Then write the rule.</p>'\
         '<div style="min-height:80px; border-bottom:1px dashed #999;"></div>'\
         '<p style="font-size:11px; margin-top:6px;">My rule: ' + bw() + '</p>'\
         '</div>'

    return page(25, "Monday", "Repeating Patterns: Find the Rule",
        f'''{sec(1, "Warm-up: Doubles", s1)}
{sec(2, "Learn: Patterns Have Rules", s2)}
{sec(3, "Continue the Pattern", s3)}
{sec(4, "Number Talk: Will It Appear?", s4)}
{sec(5, "Challenge: Create Your Own", s5)}''')


# ═══════════════════════════════════════════════════
# TUESDAY — Number Patterns & Skip Counting Rules
# ═══════════════════════════════════════════════════
def tuesday():
    # 1: Fluency warmup
    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 ["10 + 10", "20 + 20", "25 + 25", "50 + 50"]:
        s1 += f'<div class="abox"><p>{expr} = {b("4em")}</p></div>'
    s1 += '</div></div>'

    # 2: Estimate First! — predict before filling in
    s2 = '<div class="abox" style="background:#fff3e0;">'\
         '<p><b>Estimate First!</b> Look at each pattern. BEFORE you fill in the blanks, '\
         'predict: will the last number be more or less than 50? Circle your prediction, then solve.</p>'\
         '<div class="mgrid c2">'
    for start, step in [(4, 4), (30, 5)]:
        s2 += f'<div class="abox"><p>Start at {start}, count by {step}s (8 numbers).</p>'\
              '<p style="font-size:12px;">Prediction: last number is &nbsp;<b>more than 50</b> / <b>less than 50</b></p>'\
              f'<p>{start}, {start+step}, {b("5em")}, {b("5em")}, {b("5em")}, {b("5em")}, {b("5em")}, {b("5em")}</p></div>'
    s2 += '</div></div>'

    # 3: Fill in number patterns (reduced from 8 to 4)
    s3 = build_skip_counting({
        "note": "Fill in the missing numbers. What is the rule for each?",
        "sequences": [
            {"start": 2, "step": 2, "count": 8, "blank_indices": [3, 6]},
            {"start": 5, "step": 5, "count": 8, "blank_indices": [2, 5]},
            {"start": 10, "step": 10, "count": 8, "blank_indices": [4, 7]},
            {"start": 3, "step": 3, "count": 8, "blank_indices": [3, 5]},
        ],
    })

    # 4: What's the rule? Growing patterns (reduced from 6 to 4)
    s4 = '<div class="abox">'\
         '<p class="note">Find the rule, then write the next number.</p>'\
         '<div class="mgrid c2">'
    for seq, _rule in [("12, 14, 16, 18", "+2"), ("40, 35, 30, 25", "−5"),
                       ("11, 21, 31, 41", "+10"), ("60, 57, 54, 51", "−3")]:
        s4 += f'<div class="abox"><p>{seq}, {b("3em")}</p>'\
              '<p style="font-size:11px;">Rule: ' + b("5em") + '</p></div>'
    s4 += '</div></div>'

    # 5: Word problem
    s5 = '<div class="wp">'\
         '<p class="note">Read carefully. Think about what is happening. Draw if it helps!</p>'\
         '<div class="abox"><p style="font-size:0.95em;">Zoe saves money in a pattern: $2 the first week, $4 the second week, '\
         '$6 the third week. If the pattern continues, how much will she save in the sixth week?</p>'\
         '<p style="font-size:11px;">Draw or write your thinking: ' + bw() + '</p>'\
         '<p>$' + b("4em") + '</p></div></div>'

    return page(25, "Tuesday", "Number Patterns & Skip Counting Rules",
        f'''{sec(1, "Warm-up: Big Doubles", s1)}
{sec(2, "Estimate First: Predict the Pattern", s2)}
{sec(3, "Fill In the Pattern", s3)}
{sec(4, "What Is the Rule?", s4)}
{sec(5, "Word Problem", s5)}''')


# ═══════════════════════════════════════════════════
# WEDNESDAY — Odd & Even Numbers
# ═══════════════════════════════════════════════════
def wednesday():
    # 1: Fluency warmup
    s1 = '<div class="abox" style="background:#e8f5e9;">'\
         '<p><b>2-min Fluency Warm-up</b> — Count by 2s in your head. Fill the blanks fast!</p>'\
         '<div class="mgrid c3">'
    for expr in ["2, 4, 6, ___", "10, 12, 14, ___", "20, 22, 24, ___", "30, 32, 34, ___"]:
        s1 += f'<div class="abox"><p>{expr.replace("___", b("3em"))}</p></div>'
    s1 += '</div></div>'

    # 2: Learn — even means everyone has a partner
    s2 = '<p class="note"><b>Even</b> numbers can be split into pairs with no one left over. '\
         '<b>Odd</b> numbers always have 1 left over. Even numbers end in 0, 2, 4, 6, 8. Odd numbers end in 1, 3, 5, 7, 9.</p>'
    s2 += '<div class="mgrid c2">'
    s2 += f'<div class="abox"><p><b>6 is EVEN</b> — 3 pairs, nobody left out:</p>{dot_row(6, GREEN)}<p style="font-size:11px;">6 = 3 + 3 (equal addends!)</p></div>'
    s2 += f'<div class="abox"><p><b>7 is ODD</b> — 3 pairs and 1 left over:</p>{dot_row(7, RED)}<p style="font-size:11px;">7 = 3 + 3 + 1</p></div>'
    s2 += '</div>'

    # 3: Pair them up — odd or even? (reduced from 8 to 4)
    s3 = '<p class="note">Circle pairs of dots. Then write <b>odd</b> or <b>even</b>, and the doubles equation if it is even.</p>'\
         '<div class="mgrid c2">'
    for n, color in [(8, BLUE), (11, RED), (14, GREEN), (9, "#fbc02d")]:
        s3 += f'<div class="abox">{dot_row(n, color)}'\
              f'<p>{n} is: ' + b("4em") + '</p>'\
              f'<p style="font-size:11px;">If even: {n} = ' + b("3em") + ' + ' + b("3em") + '</p></div>'
    s3 += '</div>'

    # 4: Number Talk — odd or even WITHOUT counting
    s4 = '<div class="abox" style="background:#e3f2fd;">'\
         '<p><b>Number Talk</b> — Explain WITHOUT counting or pairing.</p>'\
         '<div class="mgrid c2">'
    s4 += '<div class="abox"><p>Is <b>46</b> odd or even? How can you tell just by looking at the number?</p>'\
          '<p style="font-size:11px;">My thinking: ' + bw() + '</p></div>'
    s4 += '<div class="abox"><p>If you add two even numbers, will the answer be odd or even? Why?</p>'\
          '<p style="font-size:11px;">My thinking: ' + bw() + '</p></div>'
    s4 += '</div></div>'

    # 5: Challenge — show two different ways
    s5 = '<div class="abox" style="background:#f3e5f5;">'\
         '<p><b>Challenge</b> — Show two different ways to prove that <b>13 is odd</b>.</p>'\
         '<p style="font-size:11px; color:#666;">Ideas: draw and pair dots, look at the last digit, try to write it as a double.</p>'\
         '<div class="mgrid c2">'\
         '<div class="abox"><p style="font-size:11px;">Way 1: ' + bw() + '</p><div style="min-height:40px;"></div></div>'\
         '<div class="abox"><p style="font-size:11px;">Way 2: ' + bw() + '</p><div style="min-height:40px;"></div></div>'\
         '</div></div>'

    return page(25, "Wednesday", "Odd & Even Numbers",
        f'''{sec(1, "Warm-up: Count by 2s", s1)}
{sec(2, "Learn: Pairs and Leftovers", s2)}
{sec(3, "Odd or Even? Pair Them Up", s3)}
{sec(4, "Number Talk: No Counting Allowed!", s4)}
{sec(5, "Challenge: Show Two Different Ways", s5)}''')


# ═══════════════════════════════════════════════════
# THURSDAY — Patterns in the Real World & Equal Groups
# ═══════════════════════════════════════════════════
def thursday():
    # 1: Fluency warmup
    s1 = '<div class="abox" style="background:#e8f5e9;">'\
         '<p><b>2-min Fluency Warm-up</b> — Odd or even? Write O or E.</p>'\
         '<div class="mgrid c3">'
    for n in [17, 24, 31, 48]:
        s1 += f'<div class="abox"><p>{n}: {b("3em")}</p></div>'
    s1 += '</div></div>'

    # 2: Equal groups make patterns (2.OA.C.4) — reduced from 6 to 3
    s2 = build_equal_groups({
        "note": "Equal groups follow a pattern! Count the groups, then write the repeated addition.",
        "groups": [
            {"num_groups": 3, "items_per_group": 4, "blank_total": True},
            {"num_groups": 4, "items_per_group": 5, "blank_total": True},
            {"num_groups": 2, "items_per_group": 6, "blank_total": True},
        ],
    })
    s2 += '<div class="abox"><p style="font-size:11px;">Write the addition pattern for the first one: '\
          + b("3em") + ' + ' + b("3em") + ' + ' + b("3em") + ' = ' + b("5em") + '</p></div>'

    # 3: Word problems — reasoning (reduced from 5 to 3)
    s3 = '<div class="wp">'\
         '<p class="note">Read carefully. Think about what is happening in the situation. Draw if it helps!</p>'\
         '<div class="mgrid c2">'
    problems = [
        ("A fence has posts in a pattern: red, red, blue, red, red, blue... If the pattern continues, what color is the 9th post?", ""),
        ("Sam sets the table with 2 forks at each of 5 places. Can every fork have a partner fork at its own place? Is the total odd or even?", ""),
        ("Ana reads 10 pages on Monday, 15 on Tuesday, 20 on Wednesday. If her pattern continues, how many pages will she read on Friday?", "pages"),
    ]
    for text, unit in problems:
        s3 += f'<div class="abox"><p style="font-size:0.95em;">{text}</p>'\
              '<p style="font-size:11px;">Draw or write your thinking: ' + bw() + '</p>'\
              '<p>' + b("6em") + f' {unit}</p></div>'
    s3 += '</div></div>'

    # 4: Number Talk — pattern in the hundreds chart
    s4 = '<div class="abox" style="background:#e3f2fd;">'\
         '<p><b>Number Talk</b> — Explain WITHOUT calculating.</p>'\
         '<p>On a hundreds chart, Marco starts at 7 and jumps down one row at a time: 7, 17, 27, 37... '\
         'What digit will ALWAYS be in the ones place? Why does that happen?</p>'\
         '<p style="font-size:11px;">My thinking: ' + bw() + '</p>'\
         '</div>'

    # 5: Create your own pattern word problem
    s5 = '<div class="abox" style="background:#f3e5f5;">'\
         '<p><b>Create Your Own Word Problem</b></p>'\
         '<p>Write a word problem about a pattern you see in real life (beads, stripes, days, songs...). Then solve it.</p>'\
         '<p style="min-height:50px; border-bottom:1px solid #333;"></p>'\
         '<p style="min-height:26px; border-bottom:1px solid #333;"></p>'\
         '<p>Answer: ' + bl() + '</p>'\
         '</div>'

    return page(25, "Thursday", "Patterns in the Real World",
        f'''{sec(1, "Warm-up: Odd or Even?", s1)}
{sec(2, "Equal Groups Make Patterns", s2)}
{sec(3, "Word Problems: Think About What Is Happening", s3)}
{sec(4, "Number Talk: Hundreds Chart Pattern", 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> — Mental math. Go fast!</p>'\
         '<div class="mgrid c3">'
    for expr in ["7 + 7", "12 + 12", "15 − 5", "9 + 8"]:
        s1 += f'<div class="abox"><p>{expr} = {b("4em")}</p></div>'
    s1 += '</div></div>'

    # 2: Estimate First! — pattern prediction
    s2 = '<div class="abox" style="background:#fff3e0;">'\
         '<p><b>Estimate First!</b> Predict FIRST, then check by continuing the pattern.</p>'\
         '<div class="mgrid c2">'
    s2 += '<div class="abox"><p>Pattern: 6, 12, 18, 24, ...</p>'\
          '<p style="font-size:12px;">Predict: will the 7th number be more than 40? &nbsp;<b>yes</b> / <b>no</b></p>'\
          '<p>Check — 7th number: ' + b("3em") + '</p></div>'
    s2 += '<div class="abox"><p>Pattern: 90, 80, 70, 60, ...</p>'\
          '<p style="font-size:12px;">Predict: will the 8th number be less than 30? &nbsp;<b>yes</b> / <b>no</b></p>'\
          '<p>Check — 8th number: ' + b("3em") + '</p></div>'
    s2 += '</div></div>'

    # 3: Mixed review (reduced from 8 to 4)
    s3 = '<div class="abox">'\
         '<p class="note">Use any strategy you prefer.</p>'\
         '<div class="mgrid c2">'
    s3 += '<div class="abox"><p>Continue: 14, 17, 20, 23, ' + b("3em") + '</p><p style="font-size:11px;">Rule: ' + b("4em") + '</p></div>'
    s3 += '<div class="abox"><p>Is 35 odd or even? ' + b("4em") + '</p><p style="font-size:11px;">How do you know? ' + bw() + '</p></div>'
    s3 += '<div class="abox"><p>Write 16 as a double: 16 = ' + b("3em") + ' + ' + b("3em") + '</p></div>'
    s3 += '<div class="abox"><p>4 groups of 3 dots. Total: ' + b("3em") + '</p><p style="font-size:11px;">Addition: 3 + 3 + 3 + 3 = ' + b("3em") + '</p></div>'
    s3 += '</div></div>'

    # 4: Word problem review
    s4 = '<div class="wp">'\
         '<p class="note">Read carefully. Show your work.</p>'\
         '<div class="abox"><p style="font-size:0.95em;">A necklace has beads in the pattern: 2 blue, 1 white, 2 blue, 1 white... '\
         'There are 18 beads in all. How many are blue? Is that number odd or even?</p>'\
         '<p style="font-size:11px;">Draw or write your thinking: ' + bw() + '</p>'\
         '<p>' + b("4em") + ' blue beads — odd / even</p></div></div>'

    # 5: Self-check with emoji reflection
    s5 = '<div class="selfcheck">'\
         '<p><b>Self-Check: How do you feel about patterns and odd/even?</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>Finding Pattern Rules</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>Odd & Even Numbers</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>Number Patterns (Skip Counting)</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>A pattern I noticed in real life:</b> ' + bl() + '</p>'\
         '</div>'

    return page(25, "Friday", "Week 25 Review & Self-Check",
        f'''{sec(1, "Warm-up: Mental Math", s1)}
{sec(2, "Estimate First: Predict Patterns", s2)}
{sec(3, "Mixed Review", s3)}
{sec(4, "Word Problem", s4)}
{sec(5, "Self-Check & Reflection", s5)}''')


# ═══════════════════════════════════════════════════
# TEACHER GUIDE
# ═══════════════════════════════════════════════════
def teacher_guide():
    return tg_page_multi(
        "Week 25", "Patterns & Rules — Teacher Guide",

        tg_section_title("Monday: Repeating Patterns") +
        tg_sec(1, "Warm-up", ["12, 16, 10, 18"]) +
        tg_sec(2, "Learn", ["Core = the part that repeats"]) +
        tg_sec(3, "Continue Patterns", ["1: triangle, triangle (AAB); 2: square, circle (ABC); 3: blue, red (AB); 4: triangle, triangle (AABB)"]) +
        tg_sec(4, "Number Talk", ["25 never appears — pattern is all even numbers; 52 never appears — counting by 5s ends in 0 or 5"]) +
        tg_sec(5, "Create Own", ["Any repeating pattern with a stated rule"]) +
        tg_note("Page break"),

        tg_section_title("Tuesday: Number Patterns") +
        tg_sec(1, "Warm-up", ["20, 40, 50, 100"]) +
        tg_sec(2, "Estimate First", ["4s from 4: last = 32 (less than 50); 5s from 30: last = 65 (more than 50)"]) +
        tg_sec(3, "Fill In", ["2s: blanks 8, 14; 5s: blanks 15, 30; 10s: blanks 50, 80; 3s: blanks 12, 18"]) +
        tg_sec(4, "What's the Rule", ["20 (+2); 20 (−5); 51 (+10); 48 (−3)"]) +
        tg_sec(5, "Word Problem", ["Week 6 = $12 (pattern +$2 each week)"]) +
        tg_note("Page break"),

        tg_section_title("Wednesday: Odd & Even") +
        tg_sec(1, "Warm-up", ["8, 16, 26, 36"]) +
        tg_sec(2, "Learn", ["Even = pairs, no leftover; odd = 1 leftover"]) +
        tg_sec(3, "Pair Them Up", ["8 even (4+4); 11 odd; 14 even (7+7); 9 odd"]) +
        tg_sec(4, "Number Talk", ["46 ends in 6 → even; even + even = even (all pairs stay paired)"]) +
        tg_sec(5, "Two Ways for 13", ["Pairing leaves 1 leftover; last digit 3 is odd; cannot write as a double (6+6=12, 7+7=14)"]) +
        tg_note("Page break"),

        tg_section_title("Thursday: Real-World Patterns") +
        tg_sec(1, "Warm-up", ["17 O, 24 E, 31 O, 48 E"]) +
        tg_sec(2, "Equal Groups", ["3×4=12; 4×5=20; 2×6=12; addition: 4+4+4=12"]) +
        tg_sec(3, "Word Problems", ["9th post = blue (pattern RRB, 9 = 3 full cores); 10 forks, every fork has a partner, even; Friday = 30 pages (+5 per day)"]) +
        tg_sec(4, "Number Talk", ["Ones digit is always 7 — adding 10 changes only the tens digit"]) +
        tg_sec(5, "Create Own", ["Accept student problems with correct solution"]) +
        tg_note("Page break"),

        tg_section_title("Friday: Review & Self-Check") +
        tg_sec(1, "Warm-up", ["14, 24, 10, 17"]) +
        tg_sec(2, "Estimate First", ["6s: 7th = 42 (yes, more than 40); minus 10s: 8th = 20 (yes, less than 30)"]) +
        tg_sec(3, "Mixed Review", ["26 (+3); 35 odd (ends in 5); 16 = 8+8; total 12, 3+3+3+3=12"]) +
        tg_sec(4, "Word Problem", ["18 beads = 6 cores of (2 blue + 1 white) → 12 blue; 12 is even"]) +
        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", "Repeating Patterns: Find the Rule"),
        (tuesday, "Tuesday", "Number Patterns & Skip Counting Rules"),
        (wednesday, "Wednesday", "Odd & Even Numbers"),
        (thursday, "Thursday", "Patterns in the Real World"),
        (friday, "Friday", "Week 25 Review & Self-Check"),
    ]

    for lesson_func, day, title in days:
        html = lesson_func()
        fname = f"Week_25_{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_25_Teacher_Guide.html")
    with open(path, "w") as f:
        f.write(html)
    pdf_path = os.path.join(WEEK, "Week_25_Teacher_Guide.pdf")
    HTML(filename=path).write_pdf(pdf_path)
    print(f"Generated: {pdf_path}")

    print("\nWeek 25 (rewritten to new standard) complete!")
