#!/bin/bash

echo "Starting Project Management Dashboard..."

# Function to kill background processes on exit
cleanup() {
    echo "Stopping servers..."
    kill $BACKEND_PID $FRONTEND_PID 2>/dev/null
    exit 0
}

# Set up trap to cleanup on script exit
trap cleanup SIGINT SIGTERM

# Start backend server
echo "Starting backend server on port 8080..."
cd backend
go run cmd/server/main.go &
BACKEND_PID=$!

# Wait a moment for backend to start
sleep 3

# Start frontend server
echo "Starting frontend server on port 3000..."
cd ../frontend
npm start &
FRONTEND_PID=$!

echo ""
echo "================================================"
echo "Project Management Dashboard is running!"
echo "================================================"
echo "Frontend: http://localhost:3000"
echo "Backend:  http://localhost:8080"
echo ""
echo "Default admin credentials:"
echo "Email:    admin@example.com"
echo "Password: admin123"
echo ""
echo "Press Ctrl+C to stop both servers"
echo "================================================"

# Wait for user to stop the servers
wait
