$content = [System.IO.File]::ReadAllText("index.html", [System.Text.Encoding]::UTF8)

# 1. Fix junk characters (Replace corrupted characters with HTML entities)
$replacements = @{
    "â‚¹" = "&#8377;"
    "â€“" = "&ndash;"
    "â€”" = "&mdash;"
    "âœ“" = "&#10003;"
    "âœ•" = "&#10005;"
    "â ®" = "&#10094;"
    "â ¯" = "&#10095;"
    "ðŸ ¢" = "&#127970;"
    "ðŸ“ " = "&#128205;"
    "ðŸ” " = "&#128269;"
    "ðŸ“ž" = "&#128222;"
    "ðŸŽ§" = "&#127911;"
    "â€™" = "&rsquo;"
    "â€œ" = "&ldquo;"
    "â€ " = "&rdquo;"
    "â€¢" = "&bull;"
    "" = ""
}

foreach ($key in $replacements.Keys) {
    $content = $content.Replace($key, $replacements[$key])
}

# 2. Fix the Pricing Section globally
# Replacing the entire pricing grid
$pricingGridStart = $content.IndexOf('<div class="pricing-grid">')
if ($pricingGridStart -ge 0) {
    $pricingGridEnd = $content.IndexOf('</section>', $pricingGridStart)
    if ($pricingGridEnd -ge 0) {
        $before = $content.Substring(0, $pricingGridStart)
        $after = $content.Substring($pricingGridEnd)
        $newPricingGrid = '<div class="pricing-grid">
                <div class="pricing-card">
                    <h4>2 BHK Apartments</h4>
                    <div class="pricing-amount">&#8377;48 L*</div>
                    <ul class="pricing-details">
                        <li>Area: 955 to 1,100 sq. ft.</li>
                        <li>2 Bedrooms + 2 Bathrooms</li>
                        <li>Spacious Living Areas</li>
                        <li>Premium Finishes</li>
                        <li>Lake-Facing Views</li>
                    </ul>
                    <button class="brochure-btn" onclick="toggleDetailsPanel()">Price Breakup</button>
                </div>

                <div class="pricing-card featured">
                    <h4>3 BHK Apartments</h4>
                    <div class="pricing-amount">&#8377;60 L*</div>
                    <ul class="pricing-details">
                        <li>Area: 1,180 to 1,490 sq. ft.</li>
                        <li>3 Bedrooms + 2 Bathrooms</li>
                        <li>Spacious Balconies</li>
                        <li>Luxury Finishes</li>
                        <li>Lake-Facing Views</li>
                    </ul>
                    <button class="brochure-btn" onclick="toggleDetailsPanel()">Price Breakup</button>
                </div>
            </div>
        </div>
    '
        $content = $before + $newPricingGrid + $after
    }
}

# 3. Fix the Hero section price box
$content = $content -replace '<span class="new-price">[^<]+</span>', '<span class="new-price">&#8377;48 L*</span>'
$content = $content -replace '<span class="offer-note">1BHK onwards</span>', '<span class="offer-note">2BHK onwards</span>'
$content = $content -replace '<span class="price-copy">Up to[^<]+for 3BHK</span>', '<span class="price-copy">Up to &#8377;75 L* for 3BHK</span>'

# 4. Fix schema.org SEO prices
$content = $content -replace '88 Lakhs - 1.67 Cr\+', '48 Lakhs - 75 Lakhs+'
$content = $content -replace '88L - 1.67Cr\+', '48L - 75L+'

# 5. Make sure the title tag and SEO prices don't have broken rupees anymore
$content = $content -replace '₹', '&#8377;'

[System.IO.File]::WriteAllText("index.html", $content, [System.Text.Encoding]::UTF8)
