#!/bin/bash

# Script to verify page structure on staging

echo "=== Verifying Page Structure on Staging ==="
echo "Date: $(date)"
echo

# SSH credentials
SSH_USER="roodev"
SSH_HOST="146.190.76.204"
SSH_PATH="/home/974670.cloudwaysapps.com/uberrxmprk/public_html"

echo "Checking pages in WordPress database..."
echo

# Check if training-login page exists and its content
ssh $SSH_USER@$SSH_HOST << 'EOF'
cd /home/974670.cloudwaysapps.com/uberrxmprk/public_html

echo "1. Checking training-login page:"
wp post list --post_type=page --name=training-login --fields=ID,post_title,post_name,post_content,post_status

echo -e "\n2. Checking all plugin pages:"
wp post list --post_type=page --meta_key=_hvac_plugin_page --fields=ID,post_title,post_name,post_status

echo -e "\n3. Checking hierarchical pages:"
echo "Trainer pages:"
wp post list --post_type=page --s="trainer" --fields=ID,post_title,post_name,post_parent,post_status | grep -E "(trainer|dashboard|registration)"

echo -e "\n4. Checking shortcode registration:"
wp eval 'global $shortcode_tags; if (isset($shortcode_tags["hvac_community_login"])) { echo "✅ hvac_community_login shortcode is registered\n"; } else { echo "❌ hvac_community_login shortcode is NOT registered\n"; }'

echo -e "\n5. Checking training-login page content:"
wp eval '$page = get_page_by_path("training-login"); if ($page) { echo "Page content:\n"; echo $page->post_content; } else { echo "Page not found"; }'

echo -e "\n6. Checking active plugins:"
wp plugin list --status=active | grep hvac

echo -e "\n7. Testing shortcode rendering:"
wp eval 'echo do_shortcode("[hvac_community_login]");' | head -20
EOF