#!/bin/bash
# Verify all icon components used in Blade/PHP files exist in vendor SVG dirs.
# x-heroicon-{variant}-{name} → vendor/blade-heroicons/resources/svg/{variant}-{name}.svg
# x-tabler-{name}             → vendor/blade-tabler-icons/resources/svg/{name}.svg

set -euo pipefail
cd "$(dirname "$0")/.."

MISS=0

HEROICON_DIR="vendor/blade-ui-kit/blade-heroicons/resources/svg"
TABLER_DIR="vendor/blade-ui-kit/blade-tabler-icons/resources/svg"

while IFS= read -r ICON; do
    if echo "$ICON" | grep -q "^x-heroicon-"; then
        # x-heroicon-{o|s|m|c}-{name} → {variant}-{name}.svg
        REST="${ICON#x-heroicon-}"
        VARIANT="${REST%%-*}"
        NAME="${REST#*-}"
        FILE="$HEROICON_DIR/${VARIANT}-${NAME}.svg"
    elif echo "$ICON" | grep -q "^x-tabler-"; then
        NAME="${ICON#x-tabler-}"
        FILE="$TABLER_DIR/${NAME}.svg"
    else
        continue
    fi

    if [ ! -f "$FILE" ]; then
        echo "❌ $ICON  (expected: $FILE)"
        MISS=$((MISS + 1))
    fi
done < <(grep -rEoh 'x-heroicon-[a-z]-[a-z0-9-]+|x-tabler-[a-z0-9-]+' resources/views app 2>/dev/null | sort -u)

if [ "$MISS" -gt 0 ]; then
    echo ""
    echo "❌ $MISS missing icon(s)"
    exit 1
fi
echo "✅ All icons exist"
