#!/usr/bin/env bash
# Auto-recompile paraglide messages when ui/messages/*.json files are staged.
# Prevents svelte-check / CI failures caused by stale generated JS files.

set -euo pipefail

STAGED=$(git diff --cached --name-only)

if echo "$STAGED" | grep -q '^ui/messages/'; then
  echo "[pre-commit] ui/messages/*.json changed — recompiling paraglide..."
  (cd ui && npm run paraglide --silent)
  git add -f ui/src/lib/paraglide/messages/
  echo "[pre-commit] paraglide output re-staged."
fi
