# install_nbconvert
# ------------------
# Instala nbconvert y playwright con chromium en un proyecto uv existente.
# Idempotente: uv add no reinstala si los paquetes ya estan presentes.
#
# USO (sourced):
#   source install_nbconvert.sh
#   install_nbconvert /path/to/project

install_nbconvert() {
    local project_dir="$1"

    if [ -z "$project_dir" ]; then
        echo "install_nbconvert: se requiere project_dir" >&2
        return 1
    fi

    if [ ! -d "$project_dir/.venv" ]; then
        echo "install_nbconvert: no existe .venv en $project_dir — ejecuta init_uv_venv primero" >&2
        return 1
    fi

    # Instalar nbconvert y playwright via uv add
    (cd "$project_dir" && uv add nbconvert playwright 2>&1)

    # Instalar chromium — capturar output, solo mostrar si hay error
    local playwright_output
    if ! playwright_output=$(cd "$project_dir" && uv run playwright install chromium 2>&1); then
        echo "$playwright_output" >&2
        return 1
    fi
}
