#!/bin/bash
set -e

SESSION="dandelion"
ROOT="$(cd "$(dirname "$0")" && pwd)"

# Kill any existing session
tmux kill-session -t "$SESSION" 2>/dev/null || true

# Create session with tsc in the first pane
tmux new-session -d -s "$SESSION" -c "$ROOT"
tmux send-keys -t "$SESSION" 'deno task watch' Enter

# Split right: deno server
tmux split-window -h -t "$SESSION" -c "$ROOT/deno"
tmux send-keys -t "$SESSION" 'bash dev.sh' Enter

# Split right: ddln_cli
tmux split-window -h -t "$SESSION" -c "$ROOT/ddln_cli"
tmux send-keys -t "$SESSION" 'bash dev.sh' Enter

tmux select-layout -t "$SESSION" even-horizontal

# Open Chrome silently after a short delay
(sleep 3 && open -a "Google Chrome" "https://localhost:8443" &>/dev/null) &

tmux attach-session -t "$SESSION"
