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

app_file="TaxBaik.Web/Components/Admin/App.razor"
login_file="TaxBaik.Web/Components/Admin/Pages/Login.razor"

for file in "$app_file" "$login_file"; do
  if [ ! -f "$file" ]; then
    echo "Missing admin render file: $file" >&2
    exit 1
  fi
done

if ! grep -nE "InteractiveWebAssemblyRenderMode\\(prerender: true\\)" "$app_file" >/dev/null; then
  echo "Admin shell must use InteractiveWebAssemblyRenderMode(prerender: true)." >&2
  exit 1
fi

if grep -nE "InteractiveServerRenderMode|prerender: true" "$app_file" | grep -v "InteractiveWebAssemblyRenderMode(prerender: true)" >/dev/null; then
  echo "Admin shell render mode violation detected." >&2
  exit 1
fi

if ! grep -nE "InteractiveServerRenderMode\\(prerender: true\\)" "$login_file" >/dev/null; then
  echo "Login page must allow server prerender." >&2
  exit 1
fi

echo "Admin render harness passed."
