#!/usr/bin/env python3
"""
Remove inline font-size styles from all HTML files in the POS_Help directory.
This allows the CSS rules to properly control font sizes.
"""
import os
import re
from pathlib import Path

def remove_inline_font_styles(file_path):
    """Remove style="font-size: Xpt;" from HTML files."""
    try:
        with open(file_path, 'r', encoding='utf-8', errors='ignore') as f:
            content = f.read()
        
        original_content = content
        
        # Remove style="font-size: 9pt;" and similar patterns
        # Pattern matches: style="font-size: XXpt;" or style="font-size:XXpt;"
        content = re.sub(r'\s+style="font-size:\s*\d+pt;"', '', content)
        
        # Also handle cases where there might be other styles in the attribute
        # Just remove the font-size portion
        content = re.sub(r'(style="[^"]*?)font-size:\s*\d+pt;\s*', r'\1', content)
        
        # Clean up empty style attributes
        content = re.sub(r'\s+style=""', '', content)
        
        if content != original_content:
            with open(file_path, 'w', encoding='utf-8', errors='ignore') as f:
                f.write(content)
            return True
        return False
    except Exception as e:
        print(f"Error processing {file_path}: {e}")
        return False

def main():
    base_dir = Path('/home/pts/Documents/QBPOS_Help_Web/QB_Help_Web/POS_Help')
    
    if not base_dir.exists():
        print(f"Error: Directory {base_dir} not found")
        return
    
    # Find all .htm files
    htm_files = list(base_dir.rglob('*.htm'))
    
    print(f"Found {len(htm_files)} HTML files")
    print("Removing inline font-size styles...")
    
    modified_count = 0
    for htm_file in htm_files:
        if remove_inline_font_styles(htm_file):
            modified_count += 1
            if modified_count % 100 == 0:
                print(f"  Processed {modified_count} files...")
    
    print(f"\nComplete! Modified {modified_count} files")
    print("All inline font-size styles have been removed.")
    print("The CSS rules will now control all font sizes uniformly.")

if __name__ == "__main__":
    main()
