#!/bin/bash

# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title Stop Webflow Dev Tunnel
# @raycast.mode fullOutput
# @raycast.icon 🛑

echo "🛑 Stopping Cloudflare Tunnel..."

# Check if tunnel is running
if pgrep -f "cloudflared tunnel" > /dev/null; then
    # Stop the tunnel
    pkill -f "cloudflared tunnel"
    sleep 1
    
    # Verify it stopped
    if pgrep -f "cloudflared tunnel" > /dev/null; then
        echo "⚠️ Warning: Tunnel process still running. Forcing stop..."
        pkill -9 -f "cloudflared tunnel"
    fi
    
    echo "✅ Tunnel stopped successfully!"
else
    echo "ℹ️ Tunnel is not running."
fi

# Optional: Show tunnel status
echo ""
echo "📊 Tunnel Status:"
if pgrep -f "cloudflared tunnel" > /dev/null; then
    echo "   Status: 🟢 Running"
else
    echo "   Status: 🔴 Stopped"
fi
