#!/bin/bash

# Deploy Frontend Applications
# This script builds and deploys the frontend DApp and admin dashboard

set -e

echo "=== Deploying Frontend Applications ==="

# Load environment variables
if [ -f .env ]; then
    export $(cat .env | grep -v '^#' | xargs)
fi

# Deploy Frontend DApp
echo ""
echo "--- Building Frontend DApp ---"
cd frontend-dapp

if [ -f "package.json" ]; then
    npm install
    npm run build
    echo "Frontend DApp built successfully"
    
    # Deploy to hosting (example: Vercel, Netlify, or custom server)
    # Uncomment and configure based on your hosting provider
    # vercel --prod
    # netlify deploy --prod --dir=dist
    # rsync -avz dist/ user@server:/var/www/dapp/
else
    echo "Warning: package.json not found for frontend-dapp"
fi

cd ..

# Deploy Admin Dashboard
echo ""
echo "--- Building Admin Dashboard ---"
cd /home/intlc/projects/dbis_core/frontend

if [ -f "package.json" ]; then
    npm install
    npm run build
    echo "Admin Dashboard built successfully"
    
    # Deploy to hosting
    # Uncomment and configure based on your hosting provider
    # vercel --prod
    # netlify deploy --prod --dir=dist
    # rsync -avz dist/ user@server:/var/www/admin/
else
    echo "Warning: package.json not found for admin dashboard"
fi

cd ../../smom-dbis-138

echo ""
echo "=== Frontend Deployment Complete ==="

