#!/bin/bash
set -e

echo ""
echo "  YouTube Transcript Summarizer - Setup"
echo "  ────────────────────────────────────────"
echo ""

# Check for Node.js
if ! command -v node &> /dev/null; then
    echo "  ✗ Node.js not found. Install it from https://nodejs.org"
    exit 1
fi
echo "  ✓ Node.js $(node --version)"

# Check for yt-dlp
if command -v yt-dlp &> /dev/null; then
    echo "  ✓ yt-dlp $(yt-dlp --version)"
else
    echo "  ⚠ yt-dlp not found. Installing..."
    if command -v brew &> /dev/null; then
        brew install yt-dlp
    elif command -v pip3 &> /dev/null; then
        pip3 install yt-dlp
    elif command -v pip &> /dev/null; then
        pip install yt-dlp
    else
        echo "  ✗ Cannot install yt-dlp automatically."
        echo "    Install manually: https://github.com/yt-dlp/yt-dlp#installation"
        exit 1
    fi
    echo "  ✓ yt-dlp installed"
fi

# Install server dependencies
echo ""
echo "  Installing server dependencies..."
cd "$(dirname "$0")/server"
npm install
echo ""
echo "  ✓ Setup complete!"
echo ""
echo "  To start the app:"
echo "    1. cd server && npm start"
echo "    2. Open public/index.html in your browser"
echo "    3. Enter your Gemini API key in the settings"
echo "    4. Paste a YouTube URL and hit Summarize"
echo ""
