#!/usr/bin/env bash
# Fail if hard-coded palette colours appear outside CSS token definitions.
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
SRC="$ROOT/apps/dashboard/src"

# Allow hex only in globals.css (token source) and ui-prefs.ts (accent map applied via CSS vars)
EXCLUDE='(globals\.css|ui-prefs\.ts|layout\.tsx)'

hits=$(rg -n --glob '!**/node_modules/**' \
  -e '#[0-9a-fA-F]{3,8}\b' \
  -e '\b(cyan|slate|zinc|neutral)-[0-9]' \
  "$SRC" || true)

filtered=$(echo "$hits" | grep -vE "$EXCLUDE" || true)

if [[ -n "${filtered//[[:space:]]/}" ]]; then
  echo "Hard-coded colours found in dashboard source:"
  echo "$filtered"
  exit 1
fi

echo "OK: no hard-coded colours outside token sources."
