#!/bin/bash

# Abbas FIT - Build Script
# This script builds both web and mobile versions

set -e

echo "================================"
echo "  Abbas FIT Build Script"
echo "================================"

# Colors
GREEN='\033[0;32m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color

cd frontend

echo -e "${BLUE}Installing dependencies...${NC}"
npm install

echo ""
echo -e "${GREEN}Choose build option:${NC}"
echo "1) Build Web Version (for website deployment)"
echo "2) Build Android APK"
echo "3) Build Both"
echo "4) Exit"
read -p "Enter choice [1-4]: " choice

case $choice in
    1)
        echo -e "${BLUE}Building Web Version...${NC}"
        npx expo export --platform web
        echo -e "${GREEN}✓ Web build complete! Files in frontend/dist/${NC}"
        echo ""
        echo "To deploy:"
        echo "  1. Upload contents of 'frontend/dist' to your web server"
        echo "  2. Configure your web server to handle SPA routing"
        ;;
    2)
        echo -e "${BLUE}Building Android APK...${NC}"
        npx eas build --platform android --profile preview --local
        echo -e "${GREEN}✓ APK build complete!${NC}"
        ;;
    3)
        echo -e "${BLUE}Building Web Version...${NC}"
        npx expo export --platform web
        echo -e "${GREEN}✓ Web build complete!${NC}"
        
        echo -e "${BLUE}Building Android APK...${NC}"
        npx eas build --platform android --profile preview --local
        echo -e "${GREEN}✓ APK build complete!${NC}"
        ;;
    4)
        echo "Exiting..."
        exit 0
        ;;
    *)
        echo "Invalid choice"
        exit 1
        ;;
esac

echo ""
echo "================================"
echo "  Build Complete!"
echo "================================"
