#!/bin/sh
# Run lint-staged for Python and Frontend
echo "Running pre-commit checks..."

# Python: Run ruff format and check on staged files
echo "Checking Python files..."
git diff --cached --name-only --diff-filter=ACM | grep -E '\.py$' | while read file; do
  if [ -f "$file" ]; then
    ruff format "$file"
    ruff check --fix "$file"
    git add "$file"
  fi
done

# Frontend: Run ESLint fix on staged files
echo "Checking Frontend files..."
git diff --cached --name-only --diff-filter=ACM | grep -E '^frontend/.*\.(js|jsx|ts|tsx)$' | while read file; do
  if [ -f "$file" ]; then
    # Strip frontend/ prefix so eslint resolves relative to frontend/
    rel="${file#frontend/}"
    (cd frontend && npx eslint --fix "$rel" && cd ..)
    git add "$file"
  fi
done

echo "Pre-commit checks complete"
