#!/bin/bash

SESSION="airun-logs"
LOGDIR="$HOME/.airun/logs"

# 세션이 이미 존재하면 attach
tmux has-session -t $SESSION 2>/dev/null
if [ $? -eq 0 ]; then
  tmux attach -t $SESSION
  exit 0
fi

# 새 세션 생성
tmux new-session -d -s $SESSION -n logs

# 첫 번째 패널: airun-api.log
tmux send-keys -t $SESSION "tail -f $LOGDIR/airun-api.log" C-m

# 두 번째 패널: airun-rag.log
tmux split-window -h -t $SESSION
tmux send-keys -t $SESSION "tail -f $LOGDIR/airun-rag.log" C-m

# 세 번째 패널: airun-report.log
tmux select-pane -t 0
tmux split-window -v -t $SESSION
tmux send-keys -t $SESSION "tail -f $LOGDIR/airun-report.log" C-m

# 네 번째 패널: airun-websearch.log
tmux select-pane -t 1
tmux split-window -v -t $SESSION
tmux send-keys -t $SESSION "tail -f /home/airun/ivs/airun/workspaces/web.log" C-m

# 2x2 레이아웃으로 정렬
tmux select-layout -t $SESSION tiled

# 🔑 q 누르면 세션 종료
tmux bind-key -n q kill-session

# 세션 접속
tmux attach -t $SESSION
