#!/bin/bash

# Fix undefined HVAC_CE_PLUGIN_DIR constant in all PHP files
echo "Fixing undefined HVAC_CE_PLUGIN_DIR constant..."

# List of files to fix
files=(
    "includes/class-hvac-registration.php"
    "includes/class-hvac-settings.php"
    "templates/template-hvac-master-dashboard.php"
    "includes/class-hvac-master-dashboard-data.php"
    "includes/class-hvac-approval-workflow.php"
    "templates/page-community-login.php"
    "includes/class-hvac-manage-event.php"
    "templates/template-trainer-profile.php"
    "templates/template-hvac-dashboard.php"
    "includes/class-attendee-profile.php"
    "includes/class-hvac-dashboard.php"
)

# Replace HVAC_CE_PLUGIN_DIR with HVAC_PLUGIN_DIR in each file
for file in "${files[@]}"; do
    if [ -f "$file" ]; then
        echo "Fixing $file..."
        sed -i.bak 's/HVAC_CE_PLUGIN_DIR/HVAC_PLUGIN_DIR/g' "$file"
        # Remove backup file
        rm -f "$file.bak"
    else
        echo "Warning: $file not found"
    fi
done

# Also check certificate files
echo "Checking certificate files..."
find includes/certificates -name "*.php" -type f -exec grep -l "HVAC_CE_PLUGIN_DIR" {} \; | while read file; do
    echo "Fixing $file..."
    sed -i.bak 's/HVAC_CE_PLUGIN_DIR/HVAC_PLUGIN_DIR/g' "$file"
    rm -f "$file.bak"
done

echo "Done! All occurrences of HVAC_CE_PLUGIN_DIR have been replaced with HVAC_PLUGIN_DIR"