#!/bin/env fish
begin
    set -l dir (status dirname)

    function initialize -V dir
        source "$dir/../../Common/Scripts/wait-network.fish"
        waitNetwork
        or exit

        sudo systemctl enable --now nix-daemon
        source "$dir/../Scripts/software.fish"
        source "$dir/../Software/base-devel/main.fish"
        source "$dir/../Software/pacman/main.fish"
        source "$dir/../Software/yay/main.fish"

        yayinst \
            pacman-contrib \
            powershell-bin
    end

    if not type -q installSoftware
        function installSoftware -V dir
            source "$dir/../../Common/Scripts/config.fish"
            source "$dir/../Scripts/software.fish"

            if collectionActive essential
                yayinst \
                    mkinitcpio-firmware \
                    neofetch \
                    bash-completion \
                    wget \
                    oh-my-posh-bin \
                    screen \
                    tmux \
                    htop \
                    lsof \
                    zsh \
                    fish \
                    pkgfile \
                    sl \
                    rar

                sudo pkgfile --update
                source "$dir/../../Common/Software/bash/main.fish"
                source "$dir/../Software/openssh/main.fish"
                source "$dir/../Software/vim/main.fish"
                source "$dir/../Software/git/main.fish"
                source "$dir/../Software/zoxide/main.fish"
                source "$dir/../Software/logo-ls/main.fish"

                # GRUB Shenanigans - if that's not an essential I don't know what is!
                source "$dir/../Software/minegrub-theme/main.fish";
            end

            if collectionActive common
                yayinst \
                    tldr \
                    btop \
                    terminal-parrot

                source "$dir/../Software/aliae/main.fish"
            end

            if collectionActive desktopExperience
                yayinst \
                    maliit-keyboard \
                    dconf-editor \
                    flatpak (
                        # Fixes: https://www.reddit.com/r/flatpak/comments/168tav2/how_to_fix_blurry_flatpaks_on_high_resolution/
                    ) xdg-desktop-portal-gtk

                source "$dir/../Software/KDE/main.fish"
                source "$dir/../Software/sddm/main.fish"

                # Fonts
                yayinst \
                    ttf-cascadia-code-nerd \
                    ttf-ms-win11-auto \
                    otf-cascadia-code \
                    ttf-droid

                # Password Management
                yayinst \
                    bitwarden \
                    keepass \
                    keepassxc

                # Tools
                yayinst \
                    android-tools \
                    blackbox-terminal \
                    cpu-x \
                    gnome-calculator \
                    yubikey-manager-qt

                yayinst \
                    remmina (
                        # RDP support for Remmina
                    ) freerdp \
                    wireshark-qt \
                    linux-wifi-hotspot

                # Creativity
                yayinst \
                    gimp \
                    inkscape

                # Office stuff
                yayinst \
                    libreoffice-fresh \
                    naps2-bin \
                    pdfarranger \
                    protonmail-bridge \
                    thunderbird

                yayinst \
                    texlive \
                    texlive-langgerman

                # Browser
                source "$dir/../Software/Firefox/main.fish"
                source "$dir/../Software/brave/main.fish"
                source "$dir/../Software/Pennywise/main.fish"

                # Virtualization
                source "$dir/../Software/waydroid/main.fish"
                source "$dir/../Software/Virtual Machine Manager/main.fish"
                yayinst propertree-git # mac config file editor

                if collectionActive coding
                    yayinst \
                        devdocs-desktop \
                        godot-mono-bin

                    source "$dir/../Software/vscode/main.fish"
                end

                if collectionActive school
                    yayinst \
                        teams-for-linux \
                        xournalpp-git \
                        rnote
                end
            end

            if collectionActive server
            else
                # Energy Saving
                yayinst power-profiles-daemon
                sudo systemctl enable --now power-profiles-daemon

                # Networking
                yayinst \
                    networkmanager-openvpn \
                    networkmanager-openconnect \
                    protonvpn

                if collectionActive common
                    source "$dir/../Software/IcedTea/main.fish"

                    yayinst \
                        img2pdf \
                        numbat-bin \
                        nvtop \
                        pdf2svg \
                        tnef
                end
            end

            if collectionActive media
                yayinst \
                    ytmdesktop-bin \
                    netflix \
                    spotube-bin \
                    stremio \
                    tidal-dl \
                    tidal-hifi-bin \
                    nuclear-player-bin \
                    audius-client-bin
            end

            if collectionActive fileSync
                yayinst nextcloud-client
                source "$dir/../Software/rclone/main.fish"
            end

            if collectionActive socialMedia
                yayinst \
                    signal-desktop \
                    threema-desktop \
                    discord (
                        # Open Source Discord implementation
                    ) openasar-git
            end

            if collectionActive productivity
                yayinst \
                    anki-bin
            end

            if collectionActive school
                yayinst \
                    jdk17-temurin \
                    gradle \
                    jetbrains-toolbox

                source "$dir/../../Common/Software/udev/ct-board.fish"
            end

            if collectionActive coding
                yayinst \
                    archiso \
                    wimlib (
                        # ISO support for wimlib
                    ) cdrkit \
                    tea \
                    woodpecker-cli (
                        # AsciiDocs
                    ) python-docutils (
                        # reStructuredText
                    ) esbonio

                source "$dir/../Software/n/main.fish"
            end

            if collectionActive python
                yayinst \
                    python \
                    python-pip \
                    python-pipenv

                source "$dir/../Software/pyenv/main.fish"
            end

            if collectionActive gaming
                yayinst \
                    steam \
                    chiaki \
                    osu-lazer-bin \
                    libretro \
                    supertux \
                    gamepad-tool-bin

                source "$dir/../Software/Lutris/main.fish"
                sudo flatpak install -y flathub com.usebottles.bottles
            end

            if collectionActive essential
                yayinst \
                    bb
            end
        end
    end

    source "$dir/../../Common/OS/install.fish"
end