#!/usr/bin/fish

# 1. Header
set_color blue; echo "--- TUI DESKTOP DASHBOARD ---"; set_color normal
echo "User: "(whoami)"  |  Host: "(hostname)"  |  "(date +'%Y-%m-%d %H:%M')
echo ""

# 2. Quota Logic - Target the specific numbers carefully
set RAW_DATA (quota -u (whoami) -w | grep -i "/dev/" | xargs)

# Extract column 2 (Used) and 3 (Limit), stripping the '*' if present
set USED (echo "$RAW_DATA" | awk '{print $2}' | tr -d '*' | xargs)
set LIMIT (echo "$RAW_DATA" | awk '{print $3}' | tr -d '*' | xargs)

# Fallback to 0 if variables are empty to prevent math errors
if test -z "$USED"; set USED 0; end
if test -z "$LIMIT"; set LIMIT 1; end

if test "$USED" -ge 0
    set PERCENT (math "100 * $USED / $LIMIT")
    
    if test "$PERCENT" -gt 90
        set_color red
    else if test "$PERCENT" -gt 70
        set_color yellow
    else
        set_color green
    end

    echo "Disk Usage: $PERCENT% ($USED"K" / $LIMIT"K")"
    set_color normal
else
    set_color red; echo "Disk Usage: Data Unavailable"; set_color normal
end

echo ""
set_color blue; echo "Quick Access:"; set_color normal
echo " * 'y'      -> Files (Yazi)"
echo " * 'catgirl'-> IRC Chat"
echo " * 'micro'  -> Editor"
echo "---"

# 3. Zellij Check
if command -v zellij >/dev/null
    if zellij list-sessions 2>/dev/null | grep -q "."
        set_color green; echo "Active Desktop Session detected!"; set_color normal
        echo "Run 'zellij attach' to resume."
    end
end
