#!/bin/bash

# Fix Find a Trainer page content
# Usage: ./scripts/fix-find-trainer-page.sh

source .env

echo "=== Fixing Find a Trainer Page Content ==="

ssh -o StrictHostKeyChecking=no "$UPSKILL_STAGING_SSH_USER@$UPSKILL_STAGING_IP" << 'ENDSSH'
cd /home/974670.cloudwaysapps.com/uberrxmprk/public_html

# Update the page with simpler content
wp eval '
$page = get_page_by_path("find-a-trainer");
if ($page) {
    // Simpler content without MapGeo shortcode for now
    $updated_content = \'<div class="hvac-find-trainer-wrapper">
<div class="hvac-find-trainer-intro">
<p>Find certified HVAC trainers in your area. Use the filters below to discover trainers who match your specific needs.</p>
</div>

<!-- Trainer Directory -->
[hvac_trainer_directory]

<div class="hvac-trainer-cta">
<p>Are you an HVAC Trainer that wants to be listed in our directory?</p>
<a href="/trainer-registration/" class="button">Become a Trainer</a>
</div>
</div>\';
    
    wp_update_post([
        "ID" => $page->ID,
        "post_content" => $updated_content
    ]);
    
    echo "Page content updated\n";
} else {
    echo "Page not found\n";
}
'

# Clear cache
wp cache flush

ENDSSH

echo "=== Testing Page Load ==="
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" https://upskill-staging.measurequick.com/find-a-trainer/)
echo "Page returns HTTP $HTTP_CODE"

echo "=== Fix Complete ==="