#!/bin/bash

# 簡單的問題狀態檢查
ISSUE_FILE="ISSUES.md"

if [ ! -f "$ISSUE_FILE" ]; then
    echo "❌ 找不到 $ISSUE_FILE"
    exit 1
fi

echo "🔍 問題狀態總覽"
echo "=================="

urgent=$(grep -c "^- \[ \]" "$ISSUE_FILE" | head -1)
urgent_section=$(sed -n '/## 🔥 緊急問題/,/## /p' "$ISSUE_FILE" | grep -c "^- \[ \]")
important_section=$(sed -n '/## ⚠️ 重要問題/,/## /p' "$ISSUE_FILE" | grep -c "^- \[ \]")
normal_section=$(sed -n '/## 📝 一般問題/,/## /p' "$ISSUE_FILE" | grep -c "^- \[ \]")
resolved=$(grep -c "^- \[x\]" "$ISSUE_FILE")

echo "🔥 緊急問題: $urgent_section 個"
echo "⚠️ 重要問題: $important_section 個"  
echo "📝 一般問題: $normal_section 個"
echo "✅ 已解決: $resolved 個"

total_open=$((urgent_section + important_section + normal_section))
echo ""
echo "📊 總計: $total_open 個待處理問題"

if [ $urgent_section -gt 0 ]; then
    echo ""
    echo "🚨 緊急問題列表:"
    sed -n '/## 🔥 緊急問題/,/## /p' "$ISSUE_FILE" | grep "^- \[ \]" | head -3
fi

if [ $total_open -eq 0 ]; then
    echo "🎉 沒有待處理問題！"
elif [ $urgent_section -gt 3 ]; then
    echo "⚠️ 緊急問題過多，建議優先處理"
elif [ $total_open -gt 10 ]; then
    echo "💡 問題較多，建議分類處理"
else
    echo "👍 問題數量合理"
fi