#!/bin/bash
set -e

echo "========================================"
echo "PicoBot Web UI Build Script"
echo "========================================"

# Check if we're in the right directory
if [ ! -f "Cargo.toml" ]; then
    echo "Error: Please run this script from the project root directory"
    exit 1
fi

echo ""
echo "Step 1: Building frontend..."
echo "----------------------------------------"
cd web
npm install
npm run build
cd ..

echo ""
echo "Step 2: Building Rust backend..."
echo "----------------------------------------"
cargo build --release

echo ""
echo "========================================"
echo "Build complete!"
echo "========================================"
echo ""
echo "To run the application:"
echo "  cargo run --release -- gateway"
echo ""
echo "Then open your browser to:"
echo "  http://127.0.0.1:19876"
echo ""
