#!/bin/bash

echo "🚀 Setting up Sessionize Auth Demo..."

# Check if Node.js is installed
if ! command -v node &> /dev/null; then
    echo "❌ Node.js is not installed. Please install Node.js 16+ first."
    exit 1
fi

# Check Node.js version
NODE_VERSION=$(node -v | cut -d'v' -f2 | cut -d'.' -f1)
if [ "$NODE_VERSION" -lt 16 ]; then
    echo "❌ Node.js version 16+ is required. Current version: $(node -v)"
    exit 1
fi

echo "✅ Node.js $(node -v) detected"

# Install demo dependencies
echo "📦 Installing demo dependencies..."
cd demo
npm install

if [ $? -eq 0 ]; then
    echo "✅ Demo dependencies installed successfully"
else
    echo "❌ Failed to install demo dependencies"
    exit 1
fi

# Build the main library
echo "🔨 Building Sessionize Auth library..."
cd ..
npm run build

if [ $? -eq 0 ]; then
    echo "✅ Library built successfully"
else
    echo "❌ Failed to build library"
    exit 1
fi

echo ""
echo "🎉 Setup complete! You can now run the demo:"
echo ""
echo "  npm run demo:dev"
echo ""
echo "Then open http://localhost:3000 in your browser"
echo ""
echo "Demo credentials:"
echo "  Email: demo@example.com"
echo "  Password: password"
echo ""
