#!/bin/bash

# shadcn/ui 색상 통일 스크립트
# 직접 색상 사용을 CSS 변수/variant로 변경

echo "🎨 색상 통일 작업 시작..."

# components 디렉토리로 이동
cd "$(dirname "$0")/.." || exit

# 카운터
count=0

# 1. 버튼 색상: bg-blue-600 hover:bg-blue-700 → variant="default" 사용으로 변경 (이미 Button 태그인 경우만)
echo "📝 1단계: 버튼 색상 변경 중..."

# 2. 배경색: bg-blue-50 → bg-accent 또는 bg-primary/10
echo "📝 2단계: 배경색 변경 중..."
find components -name "*.tsx" -type f -print0 | while IFS= read -r -d '' file; do
  # bg-blue-50 → bg-accent (가벼운 파란 배경)
  if grep -q "bg-blue-50" "$file"; then
    sed -i '' 's/bg-blue-50/bg-accent/g' "$file"
    echo "  ✅ $file: bg-blue-50 → bg-accent"
    ((count++))
  fi
  
  # bg-gray-50 → bg-muted (회색 배경)
  if grep -q "\"bg-gray-50\"" "$file" || grep -q "'bg-gray-50'" "$file"; then
    sed -i '' 's/bg-gray-50/bg-muted/g' "$file"
    echo "  ✅ $file: bg-gray-50 → bg-muted"
    ((count++))
  fi
  
  # bg-blue-100 → bg-primary/20
  if grep -q "bg-blue-100" "$file"; then
    sed -i '' 's/bg-blue-100/bg-primary\/20/g' "$file"
    echo "  ✅ $file: bg-blue-100 → bg-primary/20"
    ((count++))
  fi
  
  # bg-red-50 → bg-destructive/10
  if grep -q "bg-red-50" "$file"; then
    sed -i '' 's/bg-red-50/bg-destructive\/10/g' "$file"
    echo "  ✅ $file: bg-red-50 → bg-destructive/10"
    ((count++))
  fi
  
  # bg-red-100 → bg-destructive/20
  if grep -q "bg-red-100" "$file"; then
    sed -i '' 's/bg-red-100/bg-destructive\/20/g' "$file"
    echo "  ✅ $file: bg-red-100 → bg-destructive/20"
    ((count++))
  fi
done

# 3. 테두리 색상
echo "📝 3단계: 테두리 색상 변경 중..."
find components -name "*.tsx" -type f -print0 | while IFS= read -r -d '' file; do
  # border-blue-500 → border-primary
  if grep -q "border-blue-500" "$file"; then
    sed -i '' 's/border-blue-500/border-primary/g' "$file"
    echo "  ✅ $file: border-blue-500 → border-primary"
    ((count++))
  fi
  
  # border-blue-200 → border-primary/20
  if grep -q "border-blue-200" "$file"; then
    sed -i '' 's/border-blue-200/border-primary\/20/g' "$file"
    echo "  ✅ $file: border-blue-200 → border-primary/20"
    ((count++))
  fi
  
  # border-red-200 → border-destructive/20
  if grep -q "border-red-200" "$file"; then
    sed -i '' 's/border-red-200/border-destructive\/20/g' "$file"
    echo "  ✅ $file: border-red-200 → border-destructive/20"
    ((count++))
  fi
  
  # border-red-500 → border-destructive
  if grep -q "border-red-500" "$file"; then
    sed -i '' 's/border-red-500/border-destructive/g' "$file"
    echo "  ✅ $file: border-red-500 → border-destructive"
    ((count++))
  fi
done

# 4. 텍스트 색상
echo "📝 4단계: 텍스트 색상 변경 중..."
find components -name "*.tsx" -type f -print0 | while IFS= read -r -d '' file; do
  # text-blue-600 → text-primary
  if grep -q "text-blue-600" "$file"; then
    sed -i '' 's/text-blue-600/text-primary/g' "$file"
    echo "  ✅ $file: text-blue-600 → text-primary"
    ((count++))
  fi
  
  # text-red-600 → text-destructive
  if grep -q "text-red-600" "$file"; then
    sed -i '' 's/text-red-600/text-destructive/g' "$file"
    echo "  ✅ $file: text-red-600 → text-destructive"
    ((count++))
  fi
  
  # text-gray-600 → text-muted-foreground
  if grep -q "text-gray-600" "$file"; then
    sed -i '' 's/text-gray-600/text-muted-foreground/g' "$file"
    echo "  ✅ $file: text-gray-600 → text-muted-foreground"
    ((count++))
  fi
done

echo ""
echo "✨ 색상 통일 완료!"
echo "📊 총 $count개 항목 변경됨"
echo ""
echo "⚠️  주의: green, orange, purple 색상은 특수 용도로 유지했습니다."
echo "   (성공, 경고, 정보 표시 등)"

