#!/usr/bin/env python3
"""
Fix logo container dimensions directly in header.php.
Change the logo container from 'h-11 w-34.5' to a wider container
and fix the img style to not force fill.
"""

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

# The logo container is: div class="h-11 w-34.5 relative overflow-hidden"
# and img has style="position:absolute;height:100%;width:100%;..."
# Fix: use a wider container and proper img style

# Fix 1: Replace the logo img style to be natural width/height
OLD_IMG = 'alt="kh logo" fetchPriority="high" decoding="async" data-nimg="fill" style="position:absolute;height:100%;width:100%;left:0;top:0;right:0;bottom:0;color:transparent" src="/aaa/infinity_images/logo.png"'
NEW_IMG = 'alt="kh logo" fetchPriority="high" decoding="async" style="height:42px;width:auto;object-fit:contain;display:block;max-width:200px;position:relative;left:0;top:0;" src="/aaa/infinity_images/logo.png"'

# Fix 2: Change the container style to allow natural width
OLD_CONTAINER = 'class="h-11 w-34.5 relative overflow-hidden">'
NEW_CONTAINER = 'style="height:44px;width:auto;display:flex;align-items:center;overflow:visible;max-width:220px;">'

count_img = content.count(OLD_IMG)
count_cont = content.count(OLD_CONTAINER)

print(f"Logo img occurrences: {count_img}")
print(f"Logo container occurrences: {count_cont}")

content = content.replace(OLD_IMG, NEW_IMG)
content = content.replace(OLD_CONTAINER, NEW_CONTAINER)

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

print(f"Fixed {count_img} logo img tags and {count_cont} containers.")
