#!/bin/bash
# Add mobile responsiveness to all HTML files

HELP_DIR="/home/pts/Documents/QBPOS_Help_Web/QB_Help_Web/POS_Help"
BACKUP_DIR="/home/pts/Documents/QBPOS_Help_Web/backup_html_$(date +%Y%m%d_%H%M%S)"

echo "Creating backup..."
mkdir -p "$BACKUP_DIR"

# Find all .htm and .html files
find "$HELP_DIR" -type f \( -name "*.htm" -o -name "*.html" \) | while read -r file; do
    # Skip if already has viewport
    if grep -q "viewport" "$file"; then
        echo "Already has viewport: $file"
        continue
    fi
    
    # Create backup
    cp "$file" "$BACKUP_DIR/"
    
    # Add viewport meta tag after <head>
    sed -i '/<head>/I a\
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, user-scalable=yes">' "$file"
    
    # Add mobile CSS link if qbpos.css is present
    if grep -q "qbpos.css" "$file"; then
        # Add mobile-enhancements.css after qbpos.css
        sed -i '/qbpos\.css/a\
<link rel="StyleSheet" href="mobile-enhancements.css" type="text/css">' "$file"
    fi
    
    echo "Updated: $file"
done

echo ""
echo "Update complete!"
echo "Backup created at: $BACKUP_DIR"
echo ""
echo "Changes made:"
echo "  - Added viewport meta tag to all HTML files"
echo "  - Added mobile-enhancements.css link where applicable"
