#!/bin/bash

echo "📱 Xcode 安裝監控工具"
echo "==================="

# Function to get current timestamp
get_timestamp() {
    date '+%Y-%m-%d %H:%M:%S'
}

# Function to check installation status
check_installation() {
    if [ -d "/Applications/Xcode.app" ]; then
        return 0  # Installed
    else
        return 1  # Not installed
    fi
}

# Function to get installation size
get_installation_size() {
    if [ -d "/Applications/Xcode.app" ]; then
        du -sh "/Applications/Xcode.app" 2>/dev/null | cut -f1
    else
        echo "0MB"
    fi
}

echo "開始監控 Xcode 安裝狀態..."
echo "按 Ctrl+C 停止監控"
echo ""

# Initial status
echo "[$(get_timestamp)] 初始檢查: Xcode 安裝狀態"

# Monitor loop
while true; do
    if check_installation; then
        SIZE=$(get_installation_size)
        echo "[$(get_timestamp)] ✅ Xcode 安裝完成！ (大小: $SIZE)"
        echo ""
        echo "🎉 安裝完成！現在可以執行配置腳本："
        echo "./tools/environment/xcode/complete_xcode_setup.sh"
        break
    else
        echo "[$(get_timestamp)] ⏳ Xcode 安裝中..."
    fi
    
    # Wait 30 seconds before next check
    sleep 30
done