#!/usr/bin/env bash

session_name="$1"
tmux has-session -t $session_name &> /dev/null

if [ $? != 0 ]; then
    case "$session_name" in

        webdev)
            explorer="$COURSES/Angela Yu - The Complete 2022 Web Development Bootcamp"
            webdev_dir="$DEVDIR/web/webproj"

            tmux new-session -s "webdev" -d -n "Explorer" -c "$explorer" "nnn"
            tmux new-window -t "webdev" -d -n "Editor" -c "$webdev_dir" "$EDITOR"
            tmux new-window -t "webdev" -d -n "Terminal" -c "$webdev_dir"
            tmux split-window -h -t "webdev:Terminal" -c "$webdev_dir"
            ;;

        media)
            kvardir="/ar1/Kvar/Running Man"
            moviesdir="/ar1/Movies"
            tvseriesdir="/ar1/TV Series"

            tmux new-session -s "media" -d -n "Running Man" -c "$kvardir" "nnn"
            tmux new-window -t "media" -d -n "Movies" -c "$moviesdir" "nnn"
            tmux new-window -t "media" -d -n "TV Series" -c "$tvseriesdir" "nnn"
            ;;

        *)
            tmux new-session -s "$session_name"
            ;;
    esac
fi

if [[ -z $session_name ]]; then
    session_name="main"
    tmux new-session -s "$session_name"
fi

tmux attach -t "$session_name"
