#!/bin/bash

# Check TEC Community Events plugin status
echo "🔍 Checking The Events Calendar Community Events plugin status..."
echo "=================================================="

source .env

# SSH to staging and check plugin status
ssh -o StrictHostKeyChecking=no roodev@${UPSKILL_STAGING_IP} << 'ENDSSH'
cd /home/974670.cloudwaysapps.com/uberrxmprk/public_html

echo ""
echo "📋 All installed plugins:"
echo "------------------------"
wp plugin list --format=table | grep -E "(the-events-calendar|tribe|community|hvac)"

echo ""
echo "🎯 Specifically checking TEC Community Events:"
echo "----------------------------------------------"
wp plugin list | grep -i "community"

echo ""
echo "📦 Checking plugin directories:"
echo "--------------------------------"
ls -la wp-content/plugins/ | grep -E "(tribe|community|events-calendar)"

echo ""
echo "🔌 Checking if TEC Community Events shortcode is registered:"
echo "------------------------------------------------------------"
wp eval 'echo "Shortcode [tribe_community_events] exists: " . (shortcode_exists("tribe_community_events") ? "YES" : "NO") . "\n";'

echo ""
echo "⚙️ Checking TEC settings:"
echo "-------------------------"
wp option get tribe_events_calendar_options | grep -i community || echo "No community settings found"

echo ""
echo "📝 Checking if TEC Community Events needs activation:"
echo "------------------------------------------------------"
if [ -d "wp-content/plugins/the-events-calendar-community-events" ]; then
    echo "Directory exists: the-events-calendar-community-events"
    if wp plugin is-active the-events-calendar-community-events; then
        echo "✅ Plugin is ACTIVE"
    else
        echo "❌ Plugin is INACTIVE - needs activation"
        echo ""
        echo "To activate, run:"
        echo "wp plugin activate the-events-calendar-community-events"
    fi
elif [ -d "wp-content/plugins/events-calendar-pro" ]; then
    echo "Found Events Calendar Pro directory"
    if wp plugin is-active events-calendar-pro; then
        echo "✅ Events Calendar Pro is ACTIVE"
    else
        echo "❌ Events Calendar Pro is INACTIVE"
    fi
else
    echo "⚠️ TEC Community Events plugin directory not found!"
    echo "Available plugin directories:"
    ls wp-content/plugins/ | grep -E "(calendar|event|community)"
fi

ENDSSH

echo ""
echo "✅ Check complete"