#!/bin/bash

echo "=== Copying Page Templates to Theme Directory ==="

# SSH into staging and copy templates
ssh roodev@146.190.76.204 << 'EOF'
cd /home/974670.cloudwaysapps.com/uberrxmprk/public_html

# Get active theme directory
THEME_DIR=$(wp theme path $(wp theme list --status=active --field=name))
echo "Active theme directory: $THEME_DIR"

# Create hvac-community-events directory in theme if it doesn't exist
mkdir -p "$THEME_DIR/hvac-community-events"

# Copy page templates from plugin to theme
PLUGIN_DIR="wp-content/plugins/hvac-community-events"

echo "Copying page templates..."
if [ -d "$PLUGIN_DIR/templates" ]; then
    # Copy all page-*.php files
    find "$PLUGIN_DIR/templates" -name "page-*.php" -exec cp {} "$THEME_DIR/hvac-community-events/" \;
    
    # List copied files
    echo "Templates copied to theme:"
    ls -la "$THEME_DIR/hvac-community-events/"
else
    echo "Plugin templates directory not found!"
fi

# Clear cache
wp cache flush
EOF