#!/usr/bin/env bash

if ! command -v gum >/dev/null; then
    echo "Gum command not found"
    exit 0
fi

function gumstyle() {
    GUMSTYLE=$(gum style --foreground="#cba6f7" "$1")
    echo "${GUMSTYLE} : ${2}"
}

echo
source /etc/os-release
gum style --foreground="#f38ba8" "$(echo $PRETTY_NAME)"
echo
gumstyle "Kernel" "$(uname -sr)"
gumstyle "Uptime" "$(uptime -p)"
echo

if [[ -f /etc/debian_version ]]; then
    APT_PACKAGES=$(sudo apt update 2>/dev/null | grep packages | cut -d '.' -f 1 | awk '{print $1}')
    gumstyle "APT updates" "$APT_PACKAGES"
fi

if [[ -f /etc/redhat-release ]]; then
    DNF_PACKAGES=$(sudo dnf check-update | wc -l)
    gumstyle "DNF updates" "$DNF_PACKAGES"
fi

if command -v flatpak >/dev/null; then
    FLATPAK_PACKAGES=$(flatpak remote-ls --updates | wc -l)
    gumstyle "Flatpak updates" "$FLATPAK_PACKAGES"
fi

if [[ -d /home/linuxbrew/.linuxbrew ]]; then
    BREW_PACKAGES=$(cat /home/jas/.homebrew_updates)
    gumstyle "Homebrew updates" "$BREW_PACKAGES"
fi