set -g base-index 1
setw -g pane-base-index 1

# https://old.reddit.com/r/tmux/comments/mesrci/tmux_2_doesnt_seem_to_use_256_colors/
# colors
set -g default-terminal "tmux-256color"
set -ga terminal-overrides ",*256col*:Tc"
set -ga terminal-overrides '*:Ss=\E[%p1%d q:Se=\E[ q'
set-environment -g COLORTERM "truecolor"
set -sa terminal-features ",tmux-256color:RGB:Nobr"
set -g allow-passthrough on

set -g set-clipboard on

# shift enter for amp
set -s extended-keys on
set -as terminal-features 'tmux*:extkeys'

# pane colors for amp diff view
# set-option -g pane-colours[0] "#4D5566"
# set-option -g pane-colours[1] "#F27983"
# set-option -g pane-colours[2] "#A6CC70"
# set-option -g pane-colours[3] "#F29E74"
# set-option -g pane-colours[4] "#77A8D9"
# set-option -g pane-colours[5] "#A37ACC"
# set-option -g pane-colours[6] "#4CBF99"
# set-option -g pane-colours[7] "#F0F0F0"
# set-option -g pane-colours[8] "#000000"
# set-option -g pane-colours[9] "#FF3333"
# set-option -g pane-colours[10] "#BAE67E"
# set-option -g pane-colours[11] "#FFA759"
# set-option -g pane-colours[12] "#73D0FF"
# set-option -g pane-colours[13] "#D4BFFF"
# set-option -g pane-colours[14] "#95E6CB"
# set-option -g pane-colours[15] "#ffffff"

# Mouse works as expected
set-option -g mouse on

# Enable focus events for vim/neovim autoread
set -g focus-events on
# easy-to-remember split pane commands
bind | split-window -h -c "#{pane_current_path}"
bind - split-window -v -c "#{pane_current_path}"

# amp commands
set -g @amp/fork-thread-command 'new-window -n forked-thread $SHELL -c "amp threads fork; amp threads continue"'
bind -N 'Fork Amp thread' f "#{@amp/fork-thread-command}"

# don't rename windows automatically
set-option -g allow-rename off

# DESIGN TWEAKS

# don't do anything when a 'bell' rings
set -g visual-activity off
set -g visual-bell off
set -g visual-silence off
setw -g monitor-activity off
set -g bell-action none

# clock mode
setw -g clock-mode-colour yellow

# copy mode
setw -g mode-style 'fg=black bg=green bold'

# panes
set -g pane-border-style 'fg=green'
set -g pane-active-border-style 'fg=yellow'

# statusbar
set -g status-position bottom
set -g status-justify left
set -g status-style 'fg=green'

set -g status-left ''
set -g status-left-length 10

set -g status-right-style 'fg=black bg=yellow'
set -g status-right '%Y-%m-%d %H:%M '
set -g status-right-length 50

setw -g window-status-current-style 'fg=black bg=green'
setw -g window-status-current-format ' #I #W #F '

setw -g window-status-style 'fg=green bg=black'
setw -g window-status-format ' #I #[fg=white]#W #[fg=yellow]#F '

setw -g window-status-bell-style 'fg=yellow bg=green bold'

# messages
set -g message-style 'fg=yellow bg=green bold'

# Unbind Ctrl+V so it passes through to Kitty for paste
unbind C-v
set -g set-clipboard on

# Vim-aware pane navigation with Alt+hjkl
is_vim="ps -o state= -o comm= -t '#{pane_tty}' | grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|n?vim?x?)(diff)?$'"
bind-key -n M-h if-shell "$is_vim" "send-keys M-h" "select-pane -L"
bind-key -n M-j if-shell "$is_vim" "send-keys M-j" "select-pane -D"
bind-key -n M-k if-shell "$is_vim" "send-keys M-k" "select-pane -U"
bind-key -n M-l if-shell "$is_vim" "send-keys M-l" "select-pane -R"

# Window navigation with Alt+n/p
bind-key -n M-n next-window
bind-key -n M-p previous-window

# Pane resizing with Alt+Shift+hjkl
bind-key -n M-S-h resize-pane -L 2
bind-key -n M-S-j resize-pane -D 2
bind-key -n M-S-k resize-pane -U 2
bind-key -n M-S-l resize-pane -R 2

# Copy mode setup
bind v copy-mode
setw -g mode-keys vi
bind-key -T copy-mode-vi 'v' send -X begin-selection
bind-key -T copy-mode-vi 'y' send -X copy-pipe-and-cancel 'xclip -in -selection clipboard'
