#!/bin/bash
# KB Stats — quick statistics
# Usage: ./scripts/stats.sh

KB_DIR="$(cd "$(dirname "$0")/.." && pwd)"
cd "$KB_DIR"

echo "📊 KB Statistics"
echo "================"
echo ""

# Raw counts
raw_total=$(find raw/ -name "*.md" 2>/dev/null | wc -l)
raw_inbox=$(rg -l --glob '*.md' '^status:\s*inbox\s*$' raw/ 2>/dev/null | wc -l)
raw_absorbed=$(rg -l --glob '*.md' '^status:\s*absorbed\s*$' raw/ 2>/dev/null | wc -l)
raw_skipped=$(rg -l --glob '*.md' '^status:\s*skipped\s*$' raw/ 2>/dev/null | wc -l)

echo "📥 Raw Files"
echo "  Total:     $raw_total"
echo "  Inbox:     $raw_inbox (pending review)"
echo "  Absorbed:  $raw_absorbed"
echo "  Skipped:   $raw_skipped"
echo ""

# Wiki counts
wiki_total=$(find wiki/ -name "*.md" 2>/dev/null | wc -l)
wiki_investing=$(find wiki/investing/ -name "*.md" 2>/dev/null | wc -l)
wiki_tech=$(find wiki/tech/ -name "*.md" 2>/dev/null | wc -l)
wiki_life=$(find wiki/life/ -name "*.md" 2>/dev/null | wc -l)
wiki_decisions=$(find wiki/decisions/ -name "*.md" 2>/dev/null | wc -l)

echo "📘 Wiki Pages"
echo "  Total:      $wiki_total"
echo "  Investing:  $wiki_investing"
echo "  Tech:       $wiki_tech"
echo "  Life:       $wiki_life"
echo "  Decisions:  $wiki_decisions"
echo ""

# Git
last_commit=$(git log -1 --format="%ci %s" 2>/dev/null)
echo "🔧 Git"
echo "  Last: $last_commit"
echo ""

# Size
size=$(du -sh . 2>/dev/null | cut -f1)
echo "💾 Size: $size"
