#! /bin/bash

echo "Let's get set up"
echo """

░▒█▀▀▀█░▀▀█▀▀░█▀▀▄░▀▀█▀▀░▀█▀░▒█▀▀▀█░▒█▄░▒█░░░▒█▀▀▀█░▒█▀▀▀░▀▀█▀▀░▒█░▒█░▒█▀▀█
░░▀▀▀▄▄░░▒█░░▒█▄▄█░░▒█░░░▒█░░▒█░░▒█░▒█▒█▒█░░░░▀▀▀▄▄░▒█▀▀▀░░▒█░░░▒█░▒█░▒█▄▄█
░▒█▄▄▄█░░▒█░░▒█░▒█░░▒█░░░▄█▄░▒█▄▄▄█░▒█░░▀█░░░▒█▄▄▄█░▒█▄▄▄░░▒█░░░░▀▄▄▀░▒█░░░

"""

export MASTERPW=$(gum input --header="Enpass Master password" --password)

station-setup-password
station-setup-password-manager

CHECKPW=$(enpass-cli -vault="$HOME/.local/share/Enpass/Enpass/Vaults/primary" -sort list 2>&1)

while [[ "$CHECKPW" == *level=error* ]]; do
    export MASTERPW=$(gum input --header="Enpass Master password (incorrect, try again)" --password)
    CHECKPW=$(enpass-cli -vault="$VAULT_DIR" -sort list)
done

    ["Firefox"]="https://accounts.firefox.com/signin?action=email&service=sync,false"
    ["Google"]="https://accounts.google.com,true"
    ["Discord"]="https://discord.com/channels/@me,true"
    ["Netflix"]="https://netflix.com/gb/login,true"
    ["GitHub"]="https://github.com/login,true,GitHub (1)"
    ["Zoom"]="https://apps.zoom.us/wc/home,true"
    ["Scarif: Tower"]="https://tower.scarif.space,true"
    ["Scarif: Labs"]="https://labs.scarif.space/user/login,true"
    ["Scarif: Droid"]="https://droid.scarif.space,true"

STEPS=(
    ["SSH"]="station-setup-ssh"
    ["Server"]="station-setup-server"
    ["Firefox"]="station-setup-website \"Firefox\" https://accounts.firefox.com/signin?action=email&service=sync"
    ["Nextcloud"]="station-setup-nextcloud"
    ["Google"]="station-setup-website \"Google\" https://accounts.google.com"
    ["Discord"]="station-setup-website \"Discord\" https://discord.com/channels/@me"
    ["Netflix"]="station-setup-website \"Netflix\" https://netflix.com/gb/login"
    ["GitHub"]="station-setup-website \"GitHub\" https://github.com/login true \"GitHub (1)\""
    ["Zoom"]="station-setup-website \"Zoom\" https://apps.zoom.us/wc/home"
    ["Tower"]="station-setup-website \"Scarif: Tower\" https://tower.scarif.space"
    ["Labs"]="station-setup-website \"Scarif: Labs\" https://labs.scarif.space/user/login"
    ["Droid"]="station-setup-website \"Scarif: Droid\" https://droid.scarif.space"
    ["ExpressVPN"]="station-setup-vpn"
    ["Spotify"]="station-setup-spotify"
    ["Antigravity"]="station-setup-antigravity"
    ["Minecraft"]="station-setup-minecraft"
    ["Mail"]="station-setup-mail"
    ["Steam"]="station-setup-steam"
    ["Super Productivity"]="station-setup-super-productivity"
)

CHOICE=$(print -l ${(k)STEPS} | gum choose --header "Select accounts to setup (ctrl + a to toggle all)" --no-limit --selected="*" --height="${#STEPS[@]}" --ordered)

if [[ -z "$CHOICE" ]]; then
    echo "No choice made, skipping."
    exit 1
fi

for key in ${(@f)CHOICE}; do
    eval "${ACCOUNTS[$key]}"
done
