# Install bundled fonts that have no reliable AUR package (Apple SF Pro,
# MS Windows 11 — proprietary, so the AUR PKGBUILDs keep breaking). Drop the
# font files into 03-user/fonts/ (any subdir layout); they land in
# ~/.local/share/fonts/ and the font cache is rebuilt.
SRC="$REPO_ROOT/03-user/fonts"
DEST="$HOME/.local/share/fonts"
find_fonts() { find "$SRC" -type f \( -iname '*.otf' -o -iname '*.ttf' -o -iname '*.ttc' \) "$@"; }

if [ -z "$(find_fonts -print -quit 2>/dev/null)" ]; then
  echo "   no font files in 03-user/fonts — skipping"
  return 0 2>/dev/null || exit 0
fi

count=0
while IFS= read -r -d '' font; do
  rel="${font#"$SRC"/}"                       # preserve subdir layout under DEST
  install -Dm644 "$font" "$DEST/$rel" && count=$((count + 1))
done < <(find_fonts -print0)

fc-cache -f "$DEST" >/dev/null
info "installed $count font file(s) → $DEST"
