#!/bin/bash

# Quick SCSS compilation test
# Tests that the @c8y/style SCSS entry points compile without errors

set -e

cd "$(dirname "$0")"

echo "==========================================="
echo "Quick SCSS Compilation Test"
echo "==========================================="
echo ""

# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color

ENTRIES=(main.scss login.scss branding.scss branding-login.scss)

for entry in "${ENTRIES[@]}"; do
  printf "${YELLOW}Testing %s...${NC}\n" "$entry"
  npx sass "$entry" "/tmp/test-${entry%.scss}.css" --no-source-map 2>/tmp/sass-errors.log
  if [ $? -eq 0 ]; then
    SIZE=$(wc -c < "/tmp/test-${entry%.scss}.css" | tr -d ' ')
    SIZE_MB=$(echo "scale=1; $SIZE / 1024 / 1024" | bc)
    printf "${GREEN}✓ %s compiled successfully${NC} (${SIZE_MB}M)\n" "$entry"
  else
    printf "${RED}✗ %s compilation failed${NC}\n" "$entry"
    cat /tmp/sass-errors.log
    exit 1
  fi
done

echo "==========================================="
echo ""
echo "All SCSS entry points compiled successfully."
echo "Full log: /tmp/sass-errors.log"
