#--------------------------------------------------------------------------
# General Configuration
#--------------------------------------------------------------------------

# Use Vi mode
setw -g mode-keys vi

# Increase scrollback buffer size
set -g history-limit 10000

# Start window and pane numbering from 1 for easier switching
set -g base-index 1
setw -g pane-base-index 1

# Allow automatic renaming of windows
set -g allow-rename on

# Renumber windows when one is removed.
set -g renumber-windows on

# Allow the mouse to resize windows and select tabs
set -g mouse on

# Allow tmux to set the terminal title
set -g set-titles on

# Monitor window activity to display in the status bar
setw -g monitor-activity on

# A bell in another window should cause a bell in the current window
set -g bell-action any

# Focus events enabled for terminals that support them
set -g focus-events on

# Useful when using sharing a session with different size terminals
setw -g aggressive-resize on

# don't detach tmux when killing a session
set -g detach-on-destroy off

# address vim mode switching delay
set -s escape-time 0

#--------------------------------------------------------------------------
# Key Bindings
#--------------------------------------------------------------------------

unbind C-b
set-option -g prefix C-a

bind f run-shell "sh ~/.tmux-nvim-fzf-opener.sh";
bind r source-file ~/.tmux.conf \; display-message "Config reloaded!"
bind-key C new-session
bind-key -T copy-mode-vi v send-keys -X begin-selection
bind-key -T copy-mode-vi y send-keys -X copy-selection-and-cancel
bind-key -T copy-mode-vi C-v send-keys -X rectangle-toggle


#--------------------------------------------------------------------------
# Plugin Related Configuration
#--------------------------------------------------------------------------

set -g @t-fzf-prompt '  '

set -g @browser_close_on_deattach '1'
set -g @browser_launch_on_attach '1'
set -g @catppuccin_flavour 'mocha' # or frappe, macchiato, mocha

set -g @catppuccin_date_time "%H:%M"

## Restore Vim sessions
set -g @resurrect-strategy-vim 'session'
## Restore Neovim sessions
set -g @resurrect-strategy-nvim 'session'
## Restore Panes
set -g @resurrect-capture-pane-contents 'on'
## Restore last saved environment (automatically)
set -g @continuum-restore 'on'
set -g @continuum-boot 'on'

# List of plugins
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'sainnhe/tmux-fzf'
set -g @plugin 'tmux-plugins/tmux-sensible'
set -g @plugin 'tmux-plugins/tmux-yank'
set -g @plugin 'ofirgall/tmux-window-name'
set -g @plugin 'dreamsofcode-io/catppuccin-tmux'

# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
run '~/.tmux/plugins/tpm/tpm'

#--------------------------------------------------------------------------
# Styling and Visual Customization
#--------------------------------------------------------------------------

set -g status-position top
# Improve colors
set -g default-terminal "${TERM}"

# Enable undercurl
set -as terminal-overrides ',*:Smulx=\E[4::%p1%dm'
#
# Enable undercurl colors
set -as terminal-overrides ',*:Setulc=\E[58::2::%p1%{65536}%/%d::%p1%{256}%/%{255}%&%d::%p1%{255}%&%d%;m'

set -as terminal-features ",*:RGB"
set -g default-terminal "tmux-256color"
set -ag terminal-overrides ",xterm-256color:Tc"


# Don't show distracting notifications
set -g visual-bell off
set -g visual-activity off

# Status line customisation
# set-option -g status-left-length 100
# set-option -g status-right-length 100
# set-option -g status-left " #{session_name}  "
# set-option -g status-right " "
#
# set -g status-bg default
set -g status-style bg=default
# setw window-status-current-style fg=default,bg=default
set-option -g status-style "fg=#828bb1 bg=default" # default will set the background to transparent
#
# set-option -g window-status-format "#{window_index}:#{window_name}#{window_flags} " # window_name -> pane_current_command
# set-option -g window-status-current-format "#{window_index}:#{window_name}#{window_flags} "
# set-option -g window-status-current-style "fg=#a0c6dc"  #for gruvbox use: dcc7a0 or aeb6ff
# set-option -g window-status-activity-style none
