#!/bin/bash

# Phase 9: Deploy Frontend Applications
# This script builds and deploys frontend applications

set -e

echo "=== Phase 9: Deploy Frontend Applications ==="

echo ""
echo "--- Building Frontend DApp ---"

if [ -d "frontend-dapp" ] && [ -f "frontend-dapp/package.json" ]; then
    cd frontend-dapp
    echo "Installing dependencies..."
    npm install
    echo "Building..."
    npm run build
    echo "✓ Frontend DApp built successfully"
    cd ..
    
    echo ""
    echo "⚠️  Frontend DApp build complete"
    echo "   Deploy dist/ directory to your hosting provider"
    echo "   Examples:"
    echo "     - Vercel: vercel --prod"
    echo "     - Netlify: netlify deploy --prod --dir=dist"
    echo "     - Custom: rsync -avz dist/ user@server:/var/www/dapp/"
else
    echo "⚠️  frontend-dapp directory not found or missing package.json"
fi

echo ""
echo "--- Building Admin Dashboard ---"

if [ -d "/home/intlc/projects/dbis_core/frontend" ] && [ -f "/home/intlc/projects/dbis_core/frontend/package.json" ]; then
    cd /home/intlc/projects/dbis_core/frontend
    echo "Installing dependencies..."
    npm install
    echo "Building..."
    npm run build
    echo "✓ Admin Dashboard built successfully"
    cd ../../smom-dbis-138
    
    echo ""
    echo "⚠️  Admin Dashboard build complete"
    echo "   Deploy dist/ directory to your hosting provider"
    echo "   Examples:"
    echo "     - Vercel: vercel --prod"
    echo "     - Netlify: netlify deploy --prod --dir=dist"
    echo "     - Custom: rsync -avz dist/ user@server:/var/www/admin/"
else
    echo "⚠️  Admin Dashboard directory not found or missing package.json"
fi

echo ""
echo "=== Phase 9 Complete ==="
echo "Frontend applications built"
echo "⚠️  Remember to deploy to hosting provider"

