#!/bin/bash
# SURYA Render Script

SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
cd "$SCRIPT_DIR"

# Activate virtual environment
if [ -d "venv" ]; then
    source venv/bin/activate
else
    echo "⚠️  Virtual environment not found. Creating..."
    python3 -m venv venv
    source venv/bin/activate
    pip install manim
fi

case "$1" in
    "preview")
        echo "🌟 Rendering SURYA preview (480p, 15fps)..."
        manim -pql surya_journey.py SuryaJourney
        ;;
    "medium")
        echo "🌟 Rendering SURYA medium quality (720p, 30fps)..."
        manim -pqm surya_journey.py SuryaJourney
        ;;
    "full")
        echo "🌟 Rendering SURYA full quality (1080p, 60fps)..."
        manim -pqh --fps 60 surya_journey.py SuryaJourney
        ;;
    "4k")
        echo "🌟 Rendering SURYA in 4K..."
        manim -p --resolution 3840,2160 --fps 60 surya_journey.py SuryaJourney
        ;;
    "track")
        if [ -z "$2" ]; then
            echo "Usage: ./render.sh track <number>"
            echo "Example: ./render.sh track 09"
            exit 1
        fi
        TRACK_NUM=$(printf "%02d" "$2")
        case "$TRACK_NUM" in
            "01") TRACK_NAME="Track01_Skin" ;;
            "02") TRACK_NAME="Track02_USavedMe" ;;
            "03") TRACK_NAME="Track03_Nothing" ;;
            "04") TRACK_NAME="Track04_SweetRelief" ;;
            "05") TRACK_NAME="Track05_Tiptoe" ;;
            "06") TRACK_NAME="Track06_NaturesCall" ;;
            "07") TRACK_NAME="Track07_Dreamcatcher" ;;
            "08") TRACK_NAME="Track08_IDK" ;;
            "09") TRACK_NAME="Track09_WithU" ;;
            "10") TRACK_NAME="Track10_PoorYouPoorMe" ;;
            "11") TRACK_NAME="Track11_Wait4U" ;;
            "12") TRACK_NAME="Track12_RunToU" ;;
            "13") TRACK_NAME="Track13_Medications" ;;
            "14") TRACK_NAME="Track14_Hollow" ;;
            *) echo "❌ Invalid track number. Use 1-14."; exit 1 ;;
        esac
        echo "🌟 Rendering track $TRACK_NUM: $TRACK_NAME..."
        manim -pql surya_journey.py "$TRACK_NAME"
        ;;
    "test")
        echo "🌟 Testing soul orb..."
        manim -ql --format gif surya_journey.py TestSoul
        echo "✓ Output: media/videos/surya_journey/480p15/TestSoul*.gif"
        ;;
    "math")
        echo "🌟 Testing mathematical objects..."
        manim -ql --format gif surya_journey.py TestMathObjects
        echo "✓ Output: media/videos/surya_journey/480p15/TestMathObjects*.gif"
        ;;
    *)
        echo "☀️  SURYA — A Mathematical Journey Through Feeling"
        echo ""
        echo "Usage: ./render.sh <command>"
        echo ""
        echo "Commands:"
        echo "  preview  - Quick 480p @ 15fps preview"
        echo "  medium   - 720p @ 30fps"
        echo "  full     - 1080p @ 60fps (final quality)"
        echo "  4k       - 4K @ 60fps"
        echo "  track N  - Render individual track (1-14)"
        echo "  test     - Quick soul orb test (GIF)"
        echo "  math     - Test mathematical objects (GIF)"
        echo ""
        echo "Examples:"
        echo "  ./render.sh preview"
        echo "  ./render.sh track 9"
        echo "  ./render.sh full"
        echo ""
        echo "Track list:"
        echo "  1: Skin        5: Tiptoe        9: With U (THE TURN)   13: Medications"
        echo "  2: U Saved Me  6: Nature's Call 10: Poor You Poor Me   14: Hollow"
        echo "  3: Nothing     7: Dreamcatcher  11: Wait 4 U"
        echo "  4: Sweet Relief 8: IDK          12: Run to U"
        ;;
esac
