#!/bin/bash
# DYNR Module: System Pulse v2.3.6

run_system_pulse() {
    BLUE='\033[38;5;45m'; PURPLE='\033[38;5;127m'; GOLD='\033[38;5;178m'; RED='\033[38;5;196m'; NC='\033[0m'
    
    clear
    echo -e "${PURPLE}=================================================${NC}"
    echo -e "${BLUE}    🐉  DYNASTY REVOLUTION: SYSTEM PULSE  🐉     ${NC}"
    echo -e "${PURPLE}=================================================${NC}"

    # Quick Snapshot using built-ins
    LOAD=$(uptime | awk -F'load average:' '{ print $2 }')
    MEM_FREE=$(free -h | awk '/^Mem:/ {print $4 "/" $2}')
    DISK_USAGE=$(df -h / | awk 'NR==2 {print $5}')

    echo -e "${GOLD}CPU LOAD (1/5/15): ${NC}$LOAD"
    echo -e "${GOLD}MEMORY (Avail/Tot):${NC}$MEM_FREE"
    echo -e "${GOLD}ROOT DISK USAGE:   ${NC}$DISK_USAGE"
    echo -e "${PURPLE}-------------------------------------------------${NC}"

    echo -e "Choose a detailed monitor:"
    echo -e "1) ${BLUE}Standard Top${NC} (Built-in)"
    echo -e "2) ${BLUE}BTop / HTop${NC} (Enhanced - May require install)"
    echo -e "3) Return"

    read -p "Selection [1-3]: " pulse_opt < /dev/tty

    case $pulse_opt in
        1) top ;;
        2)
            if command -v btop &> /dev/null; then btop
            elif command -v htop &> /dev/null; then htop
            else
                echo -e "${GOLD}Enhanced monitors not found.${NC}"
                read -p "Install htop now? (y/n): " inst_pulse
                if [[ "$inst_pulse" == "y" ]]; then
                    sudo apt update -qq && sudo apt install -y htop && htop
                fi
            fi
            ;;
        *) echo "Returning...";;
    esac

    read -p "Press Enter to return to the Dynasty..." < /dev/tty
    dynr
}