#!/bin/bash
# Balanced Breakfast pre-commit gate: rustfmt + frontend design-system lint
# + JS tests.
# Blocks the commit if either fails (per the no-PR workflow; run locally).
#
# Activate in a fresh clone (one-time):
#   git config core.hooksPath scripts/githooks
#
# Bypass for a work-in-progress commit: git commit --no-verify
set -euo pipefail

ROOT="$(git rev-parse --show-toplevel)"
cd "$ROOT"

echo "pre-commit: rustfmt..."
if ! bash scripts/githooks/rustfmt-gate.sh; then
    echo "pre-commit: rustfmt gate failed, commit aborted (use --no-verify to bypass)."
    exit 1
fi

echo "pre-commit: frontend lint..."
if ! bash scripts/lint-frontend.sh; then
    echo "pre-commit: lint failed, commit aborted (use --no-verify to bypass)."
    exit 1
fi

echo "pre-commit: JS tests..."
if ! node src-tauri/frontend/js/tests/run.js; then
    echo "pre-commit: JS tests failed, commit aborted (use --no-verify to bypass)."
    exit 1
fi

echo "pre-commit: clean."
