#!/usr/bin/env python3
"""
Week 2: Place Value (Tens & Ones) β€” Data-Driven Generator
Uses shared day modules for maintainability.
"""
import os
from monday import generate_monday
from tuesday import generate_tuesday
from wednesday import generate_wednesday
from thursday import generate_thursday
from friday import generate_friday
from teacher_guide import generate_teacher_guide

BASE = os.path.expanduser("~/Home_School/2nd_Grade/Math")
WEEK_DIR = os.path.join(BASE, "Week_2")
WEEK_NUM = 2


# ═══════════════════════════════════════════════════
# MONDAY DATA β€” Tens and Ones Introduction
# ═══════════════════════════════════════════════════

monday_data = {
    "topic": "Tens and Ones Introduction",
    "activities": [
        {
            "type": "tens_ones_count",
            "data": {
                "title": "What Is a Ten?",
                "note": "Each group of 10 sticks is called a \"ten\". Count the groups.",
                "items": [
                    {"sticks": "||||||||||", "label": "1 group"},
                    {"sticks": "|||||||||| ||||||||||", "label": "2 groups"},
                    {"sticks": "|||||||||| |||||||||| |||||||||", "label": "3 groups"},
                ]
            }
        },
        {
            "type": "generic",
            "data": {
                "title": "Ones Are Left Over",
                "html": '''<p class="note">The ones that do not make a full ten stay as <b>"ones"</b>.</p>
<div class="mgrid c2">
<div class="abox"><p><span style="color:#4caf50;">||||||||||</span> || ||||</p><p>Tens: <span class="b" style="min-width:4em"></span>  Ones: <span class="b" style="min-width:4em"></span></p></div>
<div class="abox"><p><span style="color:#4caf50;">|||||||||| ||||||||||</span> ||||</p><p>Tens: <span class="b" style="min-width:4em"></span>  Ones: <span class="b" style="min-width:4em"></span></p></div>
<div class="abox"><p><span style="color:#4caf50;">|||||||||| |||||||||| |||||||||| |||||||||</span> || |||</p><p>Tens: <span class="b" style="min-width:4em"></span>  Ones: <span class="b" style="min-width:4em"></span></p></div>
</div>'''
            }
        },
        {
            "type": "generic",
            "data": {
                "title": "Read Tens and Ones",
                "html": '''<p class="note">Write the number each set of tens and ones makes.</p>
<div class="mgrid c2">
<div class="abox"><p>3 tens and 4 ones = <span class="b" style="min-width:4em"></span></p></div>
<div class="abox"><p>5 tens and 2 ones = <span class="b" style="min-width:4em"></span></p></div>
<div class="abox"><p>1 ten and 9 ones = <span class="b" style="min-width:4em"></span></p></div>
<div class="abox"><p>7 tens and 6 ones = <span class="b" style="min-width:4em"></span></p></div>
</div>'''
            }
        },
        {
            "type": "generic",
            "data": {
                "title": "Write Tens and Ones",
                "html": '''<p class="note">Break each number apart into tens and ones.</p>
<div class="mgrid c2">
<div class="abox"><p>27 = <span class="b" style="min-width:4em"></span> tens and <span class="b" style="min-width:4em"></span> ones</p></div>
<div class="abox"><p>63 = <span class="b" style="min-width:4em"></span> tens and <span class="b" style="min-width:4em"></span> ones</p></div>
<div class="abox"><p>15 = <span class="b" style="min-width:4em"></span> tens and <span class="b" style="min-width:4em"></span> ones</p></div>
</div>'''
            }
        },
        {
            "type": "draw_base10",
            "data": {
                "title": "Draw the Number",
                "note": "Draw the tens (as groups of 10) and ones for each number.",
                "numbers": [24, 57]
            }
        },
        {
            "type": "tens_ones_chart",
            "data": {
                "title": "Tens and Ones Chart",
                "note": "Fill in the chart.",
                "numbers": [12, 35, 70, 46]
            }
        }
    ],
    "answers": [
        "1", "2", "3",
        "1 ten, 3 ones; 2 tens, 4 ones; 4 tens, 3 ones",
        "34; 52; 19; 76",
        "27=2/7; 63=6/3; 15=1/5",
        "24: 2 rods, 4 cubes; 57: 5 rods, 7 cubes",
        "12:1/2; 35:3/5; 70:7/0; 46:4/6"
    ]
}


# ═══════════════════════════════════════════════════
# TUESDAY DATA β€” Expanded Form & Decomposing
# ═══════════════════════════════════════════════════

tuesday_data = {
    "topic": "Expanded Form & Decomposing",
    "activities": [
        {
            "type": "expanded_form_intro",
            "data": {
                "title": "Expanded Form β€” Examples",
                "intro": "<b>Expanded form</b> shows a number as tens + ones.",
                "examples": ["34 = 30 + 4", "52 = 50 + 2"],
                "practice_numbers": [46, 71]
            }
        },
        {
            "type": "expanded_form",
            "data": {
                "title": "Write in Expanded Form",
                "note": "Write each number as tens + ones.",
                "numbers": [67, 15, 94, 30]
            }
        },
        {
            "type": "build_from_expanded",
            "data": {
                "title": "Put It Together",
                "note": "What number does the expanded form make?",
                "pairs": [(40, 5), (70, 9), (20, 8)]
            }
        },
        {
            "type": "decompose",
            "data": {
                "title": "Decompose in Two Ways",
                "note": "Show each number as two different addends.",
                "numbers": [36, 54]
            }
        },
        {
            "type": "place_value_table",
            "data": {
                "title": "Place Value Table",
                "note": "Fill in the table.",
                "numbers": [41, 73, 28, 95]
            }
        },
        {
            "type": "word_problems",
            "data": {
                "title": "Tens and Ones Word Problems",
                "problems": [
                    {"text": "Tom has 4 tens and 3 ones. How many does he have?", "blanks": 1},
                    {"text": "Sarah has 7 tens and 6 ones. How many does she have?", "blanks": 1}
                ]
            }
        }
    ],
    "answers": [
        "46=40+6; 71=70+1",
        "67=60+7; 15=10+5; 94=90+4; 30=30+0",
        "45; 79; 28",
        "36: 30+6 or 20+16; 54: 50+4 or 40+14",
        "41:4/1/40+1; 73:7/3/70+3; 28:2/8/20+8; 95:9/5/90+5",
        "43; 76"
    ]
}


# ═══════════════════════════════════════════════════
# WEDNESDAY DATA β€” Mixed Place Value Practice
# ═══════════════════════════════════════════════════

wednesday_data = {
    "topic": "Mixed Place Value Practice",
    "activities": [
        {
            "type": "digit_place",
            "data": {
                "title": "Tens or Ones?",
                "note": "Circle whether the digit is in the tens or ones place.",
                "items": [(68, 8), (35, 3), (92, 2)]
            }
        },
        {
            "type": "tens_ones_chart",
            "data": {
                "title": "Fill the Table",
                "numbers": [56, 83, 14, 77]
            }
        },
        {
            "type": "expanded_form",
            "data": {
                "title": "Expanded Form",
                "note": "Write each number as tens + ones.",
                "numbers": [29, 64, 81, 33]
            }
        },
        {
            "type": "build_from_expanded",
            "data": {
                "title": "Build the Number",
                "note": "What number does the expanded form make?",
                "pairs": [(50, 7), (10, 6), (80, 2)]
            }
        },
        {
            "type": "draw_base10",
            "data": {
                "title": "Draw Base-10 Blocks",
                "note": "Draw rods (tens) and cubes (ones).",
                "numbers": [45, 72]
            }
        },
        {
            "type": "compare",
            "data": {
                "title": "Compare Place Values",
                "note": "Write >, <, or =.",
                "pairs": [("3 tens", "2 tens"), ("5 ones", "8 ones"), ("6 tens and 4 ones", "64"), ("4 tens and 9 ones", "40")]
            }
        }
    ],
    "answers": [
        "8β†’ones; 3β†’tens; 2β†’ones",
        "56:5/6; 83:8/3; 14:1/4; 77:7/7",
        "29=20+9; 64=60+4; 81=80+1; 33=30+3",
        "57; 16; 82",
        "45: 4 rods, 5 cubes; 72: 7 rods, 2 cubes",
        ">; <; =; >"
    ]
}


# ═══════════════════════════════════════════════════
# THURSDAY DATA β€” Place Value in Real Life
# ═══════════════════════════════════════════════════

thursday_data = {
    "topic": "Place Value in Real Life",
    "activities": [
        {
            "type": "word_problems",
            "data": {
                "title": "Real-World Tens and Ones",
                "problems": [
                    {"text": "A bakery has 3 boxes of 10 muffins and 4 extra muffins. How many muffins?", "blanks": 1},
                    {"text": "There are 5 packs of 10 pencils and 7 loose pencils. How many pencils?", "blanks": 1}
                ]
            }
        },
        {
            "type": "money_tens_ones",
            "data": {
                "title": "Money Tens and Ones",
                "note": "Each $10 bill is a ten. Each $1 coin is a one.",
                "items": [
                    {"text": "4 ten-dollar bills and 3 one-dollar coins"},
                    {"text": "2 ten-dollar bills and 8 one-dollar coins"}
                ]
            }
        },
        {
            "type": "group_into_tens",
            "data": {
                "title": "Group Into Tens",
                "note": "How many tens and ones can you make?",
                "items": [
                    {"text": "37 buttons"},
                    {"text": "62 marbles"},
                    {"text": "85 stickers"}
                ]
            }
        },
        {
            "type": "expanded_form_word_problems",
            "data": {
                "title": "Expanded Form Word Problems",
                "note": "Write the answer in expanded form.",
                "items": [
                    {"text": "Tom has 2 tens and 6 ones."},
                    {"text": "Maya has 5 tens and 9 ones."}
                ]
            }
        },
        {
            "type": "shopping_table",
            "data": {
                "title": "Shopping with Place Value",
                "items": [("Backpack", 47), ("Shoes", 63), ("Jacket", 81)]
            }
        },
        {
            "type": "riddles",
            "data": {
                "title": "Place Value Riddles",
                "riddles": [
                    "\"I am between 40 and 50. My ones digit is 7.\"",
                    "\"My tens digit is 3 more than my ones digit. My ones digit is 1.\""
                ]
            }
        }
    ],
    "answers": [
        "34 muffins; 57 pencils",
        "$43; $28",
        "37: 3 tens, 7 ones; 62: 6 tens, 2 ones; 85: 8 tens, 5 ones",
        "20+6=26; 50+9=59",
        "Backpack:4/7; Shoes:6/3; Jacket:8/1",
        "47; 41"
    ]
}


# ═══════════════════════════════════════════════════
# FRIDAY DATA β€” Review & Challenge
# ═══════════════════════════════════════════════════

friday_data = {
    "topic": "Week 2 Review & Challenge",
    "activities": [
        {
            "type": "tens_ones_chart",
            "data": {
                "title": "Tens and Ones Review",
                "numbers": [17, 44, 70, 93]
            }
        },
        {
            "type": "expanded_form",
            "data": {
                "title": "Expanded Form Review",
                "note": "Write in expanded form.",
                "numbers": [38, 61, 95, 24]
            }
        },
        {
            "type": "build_from_expanded",
            "data": {
                "title": "Build the Number",
                "note": "What number does the expanded form make?",
                "pairs": [(40, 9), (80, 5), (30, 2)]
            }
        },
        {
            "type": "digit_place",
            "data": {
                "title": "Place Value β€” Which Place?",
                "note": "Which place is the digit in?",
                "items": [
                    "In 58, the 8 is the <span class=\"b\" style=\"min-width:5em\"></span> digit",
                    "In 32, the 3 is the <span class=\"b\" style=\"min-width:5em\"></span> digit",
                    "In 71, the 1 is the <span class=\"b\" style=\"min-width:5em\"></span> digit"
                ]
            }
        },
        {
            "type": "compare",
            "data": {
                "title": "Compare with Place Value",
                "note": "Write >, <, or =.",
                "pairs": [(36, 43), (72, 75), (58, 58)]
            }
        },
        {
            "type": "word_problems",
            "data": {
                "title": "Word Problem Review",
                "problems": [
                    {"text": "Lily has 5 tens and 3 ones. How many does she have?", "blanks": 1},
                    {"text": "Jake has $42. How many $10 bills?", "blanks": 1},
                    {"text": "How many $1 coins?", "blanks": 1}
                ]
            }
        }
    ],
    "answers": [
        "17:1/7; 44:4/4; 70:7/0; 93:9/3",
        "38=30+8; 61=60+1; 95=90+5; 24=20+4",
        "49; 85; 32",
        "ones; tens; ones",
        "<; <; =",
        "53; 4 tens and 2 ones"
    ]
}


# ═══════════════════════════════════════════════════
# GENERATE
# ═══════════════════════════════════════════════════

if __name__ == "__main__":
    os.makedirs(WEEK_DIR, exist_ok=True)
    
    print(f"\n{'='*50}")
    print(f"Generating Week {WEEK_NUM}: Place Value (Tens & Ones)")
    print(f"{'='*50}\n")
    
    # Generate each day
    monday_answers = generate_monday(WEEK_DIR, WEEK_NUM, monday_data)
    tuesday_answers = generate_tuesday(WEEK_DIR, WEEK_NUM, tuesday_data)
    wednesday_answers = generate_wednesday(WEEK_DIR, WEEK_NUM, wednesday_data)
    thursday_answers = generate_thursday(WEEK_DIR, WEEK_NUM, thursday_data)
    friday_answers = generate_friday(WEEK_DIR, WEEK_NUM, friday_data)
    
    # Generate teacher guide
    day_data_list = [monday_data, tuesday_data, wednesday_data, thursday_data, friday_data]
    generate_teacher_guide(WEEK_DIR, WEEK_NUM, "Place Value (Tens & Ones)", day_data_list)
    
    print(f"\n{'='*50}")
    print(f"Week {WEEK_NUM} complete!")
    print(f"{'='*50}\n")