#!/usr/bin/env python3
"""
Update baby-monitors.html with correct content.
"""

import re

filepath = '/root/clawd/stroller-app/baby-monitors.html'

with open(filepath, 'r') as f:
    html = f.read()

# 1. Update title and meta
html = html.replace(
    '<title>Baby Bottles — One-Time Purchase — True Baby Cost Calculator</title>',
    '<title>Baby Monitor True Cost Calculator — Compare Video, Audio & Smart</title>'
)

html = html.replace(
    '<meta name="description" content="Calculate baby bottles costs and compare 30+ brands. Find the best value for your feeding needs.">',
    '<meta name="description" content="Calculate baby monitor costs. Compare video, audio, and smart monitors. See true costs including subscription fees.">'
)

html = html.replace(
    '<link rel="canonical" href="https://truebabycost.com/bottles.html">',
    '<link rel="canonical" href="https://truebabycost.com/baby-monitors.html">'
)

html = html.replace(
    "data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><text y='.9em' font-size='90'>🍶</text></svg>",
    "data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><text y='.9em' font-size='90'>📹</text></svg>"
)

# 2. Update product page type
html = html.replace('window.productPageType = "bottles";', 'window.productPageType = "baby-monitors";')

# 3. Update hero section
html = re.sub(
    r'<h1>🍶.*?</h1>',
    '<h1>📹 <span data-i18n="hero.title">Baby Monitor True Cost Calculator</span></h1>',
    html
)

html = re.sub(
    r'<p data-i18n="hero\.subtitle">.*?</p>',
    '<p data-i18n="hero.subtitle">Smart monitors, video monitors, audio monitors—they all add up. Some need subscriptions. Here\'s the real cost.</p>',
    html,
    flags=re.DOTALL
)

# 4. Update active nav link
html = html.replace(
    '<a href="bottles.html" class="nav-link active">🍶 Bottles</a>',
    '<a href="bottles.html" class="nav-link">🍶 Bottles</a>'
)

html = html.replace(
    '<a href="breast-pumps.html" class="nav-link">🤱 Pumps</a>',
    '<a href="breast-pumps.html" class="nav-link">🤱 Pumps</a>\n        <a href="baby-monitors.html" class="nav-link active">📹 Monitors</a>'
)

# 5. Update calculator section
calculator_html = '''      <h2 class="section-title">💰 <span data-i18n="calculator.title">Calculate Your Monitor Costs</span></h2>
      <p class="section-subtitle" data-i18n="calculator.subtitle">One-time hardware plus any subscription fees</p>
      <div class="calculator-grid">
        <div class="input-group">
          <label for="monitor-type" data-i18n="calculator.monitorType">Monitor Type</label>
          <select id="monitor-type">
            <option value="audio">Audio Only ($25-70)</option>
            <option value="video" selected>Video ($70-200)</option>
            <option value="smart">Smart/WiFi ($150-500)</option>
          </select>
        </div>
        <div class="input-group">
          <label for="subscription" data-i18n="calculator.subscription">Monthly Subscription</label>
          <select id="subscription">
            <option value="0" selected>None (Free)</option>
            <option value="5">Basic ($5/mo)</option>
            <option value="10">Standard ($10/mo)</option>
            <option value="20">Premium ($20/mo)</option>
          </select>
        </div>
        <div class="input-group">
          <label for="usage-months" data-i18n="calculator.usageMonths">Months of Use</label>
          <select id="usage-months">
            <option value="12">1 Year</option>
            <option value="24" selected>2 Years</option>
            <option value="36">3 Years</option>
            <option value="48">4 Years</option>
          </select>
        </div>
      </div>
      <div class="results-grid">
        <div class="result-card">
          <div class="result-label" data-i18n="calculator.hardwareCost">Hardware Cost</div>
          <div class="result-value" id="hardware-cost">$150</div>
          <div class="result-detail" data-i18n="calculator.oneTime">One-time</div>
        </div>
        <div class="result-card">
          <div class="result-label" data-i18n="calculator.subscriptionCost">Subscription Cost</div>
          <div class="result-value" id="subscription-cost">$0</div>
          <div class="result-detail" id="subscription-detail">No subscription</div>
        </div>
        <div class="result-card highlight">
          <div class="result-label" data-i18n="calculator.totalCost">Total Cost</div>
          <div class="result-value" id="total-cost">$150</div>
          <div class="result-detail" id="total-detail">Over 2 years</div>
        </div>
      </div>'''

html = re.sub(
    r'<h2 class="section-title">💰.*?</div>\s*</div>',
    calculator_html,
    html,
    flags=re.DOTALL
)

# 6. Update data fetch
html = html.replace(
    "const res = await fetch('data/bottles.json');",
    "const res = await fetch('data/baby-monitors.json');"
)

# 7. Update filter types
filters_html = '''          <button class="filter-chip active" data-type="all">All</button>
          <button class="filter-chip" data-type="audio">Audio</button>
          <button class="filter-chip" data-type="video">Video</button>
          <button class="filter-chip" data-type="smart">Smart/WiFi</button>'''

html = re.sub(
    r'<button class="filter-chip active" data-type="all">All</button>.*?<button class="filter-chip"[^>]*>(?:Cow\'s Milk|Standard|Glass|Plastic|Anti-Colic|Wide Neck|Slow Flow|Fast Flow|Newborn|0-3m|3-6m|6\+m)[^<]*</button>',
    filters_html,
    html,
    flags=re.DOTALL
)

# 8. Add calculator JavaScript
calc_js = '''
    const monitorTypeEl = document.getElementById('monitor-type');
    const subscriptionEl = document.getElementById('subscription');
    const usageMonthsEl = document.getElementById('usage-months');
    
    function calculateMonitor() {
      const type = monitorTypeEl.value;
      const subscription = parseInt(subscriptionEl.value);
      const months = parseInt(usageMonthsEl.value);
      
      // Hardware costs
      const hardwareCosts = {
        audio: 50,
        video: 150,
        smart: 350
      };
      
      const hardware = hardwareCosts[type];
      const subTotal = subscription * months;
      const total = hardware + subTotal;
      
      document.getElementById('hardware-cost').textContent = '$' + hardware;
      document.getElementById('subscription-cost').textContent = '$' + subTotal;
      document.getElementById('total-cost').textContent = '$' + total;
      
      const subDetail = subscription === 0 ? 'No subscription' : `$${subscription}/mo × ${months} months`;
      document.getElementById('subscription-detail').textContent = subDetail;
      document.getElementById('total-detail').textContent = `Over ${Math.floor(months/12)} year${months >= 24 ? 's' : ''}`;
    }
    
    monitorTypeEl.addEventListener('change', calculateMonitor);
    subscriptionEl.addEventListener('change', calculateMonitor);
    usageMonthsEl.addEventListener('change', calculateMonitor);
    calculateMonitor();
'''

html = html.replace(
    '    init();',
    calc_js + '\n    init();'
)

with open(filepath, 'w') as f:
    f.write(html)

print('✅ Updated baby-monitors.html!')
