#!/usr/bin/env bash
# ── Dev Session Bootstrap ──────────────────────────────────────────────
# Creates the standard dev tmux session with two windows:
#   Window 1: Hermes TUI
#   Window 2: Timmy devloop (3-pane layout)
#
# Source-controlled: gitea/rockachopa/hermes-config
# ───────────────────────────────────────────────────────────────────────

SESSION="dev"
export PATH="$HOME/.local/bin:$HOME/.hermes/bin:/usr/local/bin:$PATH"

# If session already exists, just attach
if tmux has-session -t "$SESSION" 2>/dev/null; then
    exec tmux attach -t "$SESSION"
fi

# ── Window 1: Hermes TUI ──────────────────────────────────────────────
tmux new-session -d -s "$SESSION" -n "hermes" -x 200 -y 50
tmux send-keys -t "$SESSION:1" "hermes" Enter

# ── Window 2: Timmy Devloop (3-pane) ──────────────────────────────────
tmux new-window -t "$SESSION" -n "timmy-loop"

# Vertical split: left | right
tmux split-window -h -t "$SESSION:2.1"

# Horizontal split on left: top-left / bottom-left
tmux split-window -v -t "$SESSION:2.1"

# Pane map (pane-base-index = 1):
#   1 = top-left      → Loop
#   3 = bottom-left   → Hermes Chat (in Timmy dir)
#   2 = right         → Status Dashboard

# Set pane titles
tmux select-pane -t "$SESSION:2.1" -T "Loop"
tmux select-pane -t "$SESSION:2.3" -T "Chat"
tmux select-pane -t "$SESSION:2.2" -T "Status"

# Resize: give right pane ~40 cols for status
tmux resize-pane -t "$SESSION:2.2" -x 45

# Start processes
tmux send-keys -t "$SESSION:2.1" \
    "export PATH=\"$HOME/.local/bin:$HOME/.hermes/bin:/usr/local/bin:\$PATH\" && $HOME/.hermes/bin/timmy-loop.sh" Enter
tmux send-keys -t "$SESSION:2.2" \
    "$HOME/.hermes/bin/timmy-status.sh" Enter
tmux send-keys -t "$SESSION:2.3" \
    "cd ~/Timmy-Time-dashboard && hermes" Enter

# Focus: start on hermes window
tmux select-window -t "$SESSION:1"

# Attach to the session we just created
exec tmux attach -t "$SESSION"
