#!/usr/bin/env python3
"""
Fix All Courses panel display issue.
The panel inner content has style="height:calc(100vh - 0px)" which makes it
render outside the viewport. Also fix the panel wrapper CSS.
"""

with open('/Applications/XAMPP/xamppfiles/htdocs/aaa/header.php', 'r', encoding='utf-8') as f:
    content = f.read()

# Find the All Courses panel wrapper - it has absolute z-[99999] left-1/2
OLD_PANEL_WRAPPER = 'class="absolute  z-[99999] left-1/2  -translate-x-1/2 "'
NEW_PANEL_WRAPPER = 'class="sc-all-domain-panel" style="position:fixed;top:0;left:0;right:0;width:100%;z-index:99999;background:white;box-shadow:0 10px 40px rgba(0,0,0,.18);"'

# Fix the inner flex container that has height:calc(100vh - 0px)
OLD_INNER_FLEX = 'style="height:calc(100vh - 0px)"'
NEW_INNER_FLEX = 'style="height:calc(100vh - 112px);overflow-y:auto;"'

count1 = content.count(OLD_PANEL_WRAPPER)
count2 = content.count(OLD_INNER_FLEX)

print(f"Panel wrapper occurrences: {count1}")
print(f"Inner flex occurrences: {count2}")

content = content.replace(OLD_PANEL_WRAPPER, NEW_PANEL_WRAPPER)
content = content.replace(OLD_INNER_FLEX, NEW_INNER_FLEX)

with open('/Applications/XAMPP/xamppfiles/htdocs/aaa/header.php', 'w', encoding='utf-8') as f:
    f.write(content)

print("Done!")
