cd web && npx lint-staged || exit 1
cd ..

# H3 (ersatztv#303) — never commit a screenshot dropped at the repo root. Belt-and-suspenders with
# .gitignore (catches a forced `git add -f`). Root-level *.png only; nested paths are legit assets.
root_png=$(git diff --cached --name-only --diff-filter=ACM | grep -iE '^[^/]+\.png$' || true)
if [ -n "$root_png" ]; then
  echo "husky - refusing to commit root-level screenshot(s):"
  printf '  %s\n' $root_png
  echo "  Move it out of the repo root or drop it (root *.png are review/debug artifacts; see .gitignore)."
  exit 1
fi

# dotnet format on staged .cs files (repo root). Scoped to the staged files so we
# don't pay the full-tree cost; skip entirely when no .cs is staged (avoids the
# ~20-40s sln load for web-only commits).
cs_files=$(git diff --cached --name-only --diff-filter=ACM -- '*.cs')
if [ -n "$cs_files" ]; then
  echo "husky - dotnet format (verify) on staged .cs files"
  # shellcheck disable=SC2086
  dotnet format ErsatzTV.sln --verify-no-changes --include $cs_files || {
    echo "husky - dotnet format found issues in staged .cs files; run 'dotnet format ErsatzTV.sln --include <files>' to fix"
    exit 1
  }
fi
