#!/usr/bin/env bash
set -euo pipefail

ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"

fail() {
  echo "ERROR: $*" >&2
  exit 1
}

assert_contains() {
  local file="$1"
  local pattern="$2"
  grep -Fq -- "$pattern" "$file" || fail "$file must contain: $pattern"
}

assert_not_contains() {
  local file="$1"
  local pattern="$2"
  if grep -Fq -- "$pattern" "$file"; then
    fail "$file must not contain: $pattern"
  fi
}

for config in \
  "$ROOT_DIR/adminfront/tailwind.config.ts" \
  "$ROOT_DIR/devfront/tailwind.config.ts" \
  "$ROOT_DIR/orgfront/tailwind.config.ts"
do
  assert_not_contains "$config" "../common/**/*.{ts,tsx,css}"
  assert_contains "$config" "../common/core/**/*.{ts,tsx}"
  assert_contains "$config" "../common/shell/**/*.{ts,tsx}"
done

assert_contains "$ROOT_DIR/common/config/vite.base.ts" "/workspace/common"

assert_not_contains \
  "$ROOT_DIR/adminfront/src/features/tenants/routes/TenantDetailPage.tsx" \
  "export function canShowWorksmobileEntry"
assert_not_contains \
  "$ROOT_DIR/adminfront/src/features/tenants/routes/TenantSchemaPage.tsx" \
  "export function createSchemaField"
assert_not_contains \
  "$ROOT_DIR/adminfront/src/features/tenants/routes/TenantWorksmobilePage.tsx" \
  "export function buildWorksmobilePasswordManageUrl"
assert_not_contains \
  "$ROOT_DIR/adminfront/src/features/tenants/components/ParentTenantSelector.tsx" \
  "export function filterParentTenants"

echo "OK: adminfront dev performance settings avoid wide scans and route HMR invalidation"
