#!/bin/sh

# Run type checking
echo "Running TypeScript type check..."
bun run typecheck
if [ $? -ne 0 ]; then
  echo "TypeScript type check failed. Please fix the errors before committing."
  exit 1
fi

# Parity gate — fast (<1s). Blocks drift between the React and Vue adapter
# exports before it reaches CI. (i18n keys are no longer a parity concern —
# both adapters read the same @eigenpal/docx-editor-i18n package.)
# Spec: openspec/changes/vue-editor-robust-implementation/specs/vue-react-parity/spec.md
echo "Running parity gates..."
bun run check:parity
if [ $? -ne 0 ]; then
  echo "Parity gates failed. Fix the drift or document it in notes/intentional-export-divergence.md."
  exit 1
fi

# API snapshot gate — catches changes to any @public symbol that the
# committer forgot to regenerate. CI runs the same `api:check`, so failing
# here saves a round-trip. Fix is `bun run api:extract` then
# `git add docs/api/` and `git commit --amend --no-edit` (or re-stage on
# a fresh commit).
echo "Running API snapshot check..."
bun run api:check
if [ $? -ne 0 ]; then
  echo "API snapshot drift. Run 'bun run api:extract' and commit the updated docs/api/*.api.md files."
  exit 1
fi

# Run lint-staged (prettier + eslint on staged files)
echo "Running lint-staged..."
npx lint-staged
