#!/usr/bin/env bash
# hq-status - Unified status view for HQ orchestration
#
# Shows: available work, active workers, pending reviews

set -euo pipefail

# Colors (if terminal supports it)
if [[ -t 1 ]]; then
    BOLD='\033[1m'
    DIM='\033[2m'
    RESET='\033[0m'
else
    BOLD=''
    DIM=''
    RESET=''
fi

echo -e "${BOLD}=== HQ Status ===${RESET}"
echo ""

# Available work
echo -e "${BOLD}📋 Available Work${RESET}"
if command -v bd &>/dev/null; then
    bd ready 2>/dev/null | head -10 || echo "  (no bd issues found)"
else
    echo "  (bd not available)"
fi
echo ""

# Active workers
echo -e "${BOLD}👷 Active Workers${RESET}"
if command -v worker &>/dev/null; then
    worker status 2>/dev/null || echo "  (no workers found)"
else
    echo "  (worker CLI not available)"
fi
echo ""

# Pending reviews
echo -e "${BOLD}🔍 Review State${RESET}"
if command -v review-gate &>/dev/null; then
    review-gate list 2>/dev/null || echo "  (no pending reviews)"
else
    echo "  (review-gate not available)"
fi
echo ""

# Stale workers (if any)
if command -v worker &>/dev/null; then
    STALE=$(worker status --stale 2>/dev/null | grep -c "STALE" || true)
    if [[ "$STALE" -gt 0 ]]; then
        echo -e "${BOLD}⚠️  Stale Workers: ${STALE}${RESET}"
        worker status --stale 2>/dev/null
        echo ""
    fi
fi

echo -e "${DIM}Run 'bd show <id>' for task details, 'worker status' for worker details${RESET}"
