#!/usr/bin/env bash
# Rebuild public/assets/admin/tailwind.css from the current admin markup.
# Run this after ANY change to admin templates — an unbuilt class fails silently
# (the element just renders unstyled). bin/check-admin-css.php enforces it at release.
set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
BUILD="$ROOT/build/admin-css"
OUT="$ROOT/templates/admin/assets/tailwind.css"

command -v npm >/dev/null 2>&1 || { echo "build-admin-css: npm is required" >&2; exit 1; }

cd "$BUILD"
[ -d node_modules ] || npm install --silent --no-audit --no-fund

mkdir -p "$(dirname "$OUT")"
./node_modules/.bin/tailwindcss -c tailwind.config.js -i input.css -o "$OUT" --minify

printf 'built %s (%s bytes)\n' "$OUT" "$(stat -c%s "$OUT")"
