#!/bin/bash

# AUTO-INSTALL MISSING DEPENDENCIES SCRIPT
# This runs when dependencies are missing in CodeSandbox

echo "📦 Auto-installing missing dependencies..."

# Check if react-wrap-balancer is installed
if ! npm list react-wrap-balancer >/dev/null 2>&1; then
  echo "Installing react-wrap-balancer..."
  npm install --save react-wrap-balancer@latest --legacy-peer-deps --no-audit --no-fund || true
fi

# Check if cobe is installed
if ! npm list cobe >/dev/null 2>&1; then
  echo "Installing cobe..."
  npm install --save cobe@latest --legacy-peer-deps --no-audit --no-fund || true
fi

# Check if sharp is installed
if ! npm list sharp >/dev/null 2>&1; then
  echo "Installing sharp..."
  npm install --save sharp@latest --legacy-peer-deps --no-audit --no-fund || true
fi

# Check if fast-glob is installed
if ! npm list fast-glob >/dev/null 2>&1; then
  echo "Installing fast-glob..."
  npm install --save fast-glob@latest --legacy-peer-deps --no-audit --no-fund || true
fi

# Check if reading-time is installed
if ! npm list reading-time >/dev/null 2>&1; then
  echo "Installing reading-time..."
  npm install --save reading-time@latest --legacy-peer-deps --no-audit --no-fund || true
fi

echo "✅ Dependencies check complete!"
exit 0