#! /bin/zsh

key="$1"
url="$2"
also_webapp="$3:-true"
label="$4:-$key"

echo "Signing into $key..."

read -r username password <<< "$(station-get-username-password "$label")"

echo -n "$username" | wl-copy

station-launch-browser "$url"

if [[ "$also_webapp" == "true" ]]; then
    exec setsid uwsm-app -- chromium "$url" 2>/dev/null &
fi

station-confirm-or-close "$key Setup" "Email copied.\nPress OK for password"

echo -n "$password" | wl-copy

station-confirm-or-close "$key Setup" "Click OK when you have finished logging in to move on."

echo -n "" | wl-copy

echo "Finished setting up $key."
