#!/bin/bash

# Quick deployment script for API fixes
# Run this from your local machine with SSH access to VMID 5000

VM_IP="192.168.11.140"
FRONTEND_FILE="/home/intlc/projects/proxmox/explorer-monorepo/frontend/public/index.html"

if [ ! -f "$FRONTEND_FILE" ]; then
    echo "❌ Frontend file not found: $FRONTEND_FILE"
    exit 1
fi

echo "=========================================="
echo "Deploying Fixed Frontend to VMID 5000"
echo "=========================================="
echo ""

# Copy file to server
echo "Step 1: Copying file to server..."
scp "$FRONTEND_FILE" root@$VM_IP:/var/www/html/index.html

if [ $? -eq 0 ]; then
    echo "✅ File copied successfully"
    echo ""
    
    # Set permissions and restart nginx
    echo "Step 2: Setting permissions and restarting nginx..."
    ssh root@$VM_IP "chown www-data:www-data /var/www/html/index.html && nginx -t && systemctl restart nginx"
    
    if [ $? -eq 0 ]; then
        echo "✅ Deployment complete!"
        echo ""
        echo "Frontend is now available at:"
        echo "  - https://explorer.d-bis.org/"
        echo "  - http://$VM_IP/"
        echo ""
        echo "Fixed issues:"
        echo "  ✅ API 'Unknown action' errors resolved"
        echo "  ✅ Blocks and Transactions pages now use Blockscout API"
        echo "  ✅ createSkeletonLoader function properly defined"
    else
        echo "❌ Failed to set permissions or restart nginx"
        exit 1
    fi
else
    echo "❌ Failed to copy file"
    exit 1
fi

