# ==============================================
# ===           TMUX Configuration           ===
# ==============================================

# General Settings
# ----------------
set -g prefix C-a                          # Use CTRL+a as our tmux command prefix
unbind C-b                                 # Unbind default prefix
set -g base-index 1                        # Start windows numbering at 1
setw -g pane-base-index 1                  # Start pane numbering at 1
set -g renumber-windows on                 # Renumber windows when a window is closed
set -s escape-time 1                       # Lower the default tmux delay
set -g mouse on                            # Enable mouse support
setw -g aggressive-resize on               # Only resize screen if smaller screen is active
set -g history-limit 10000                 # Store 10k lines of history
set-option -g allow-rename off             # Disable automatic window renaming
set-option -s set-clipboard on             # Enable clipboard support


# Key Bindings
# ------------
bind r source-file $XDG_CONFIG_HOME/tmux/tmux.conf \; display "tmux reloaded!"  # Reload config
bind v split-window -h -c "#{pane_current_path}"   # Split vertically
bind s split-window -v -c "#{pane_current_path}"   # Split horizontally

# Vim-like pane navigation
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R

# Vim-like pane resizing
bind -r H resize-pane -L 5
bind -r J resize-pane -D 5
bind -r K resize-pane -U 5
bind -r L resize-pane -R 5

# Move pane to a different window
bind-key m choose-window -F "#{window_index}: #{window_name}" "join-pane -h -t %%"
bind-key M choose-window -F "#{window_index}: #{window_name}" "join-pane -v -t %%"

# Visual Settings
# ---------------
set -g status-interval 2
set-option -g visual-activity off
set-option -g visual-bell off
set-option -g visual-silence off
set-window-option -g monitor-activity off
set-option -g bell-action none

# Terminal Settings
# -----------------
set -gq allow-passthrough on
set -g visual-activity off

set -ga update-environment TERM
set -ga update-environment TERM_PROGRAM
set -g default-terminal "tmux-256color"
set -g terminal-overrides ',xterm-256color:Tc'

# Plugins
# -------
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'
set -g @plugin 'tmux-plugins/tmux-yank'
set -g @plugin 'catppuccin/tmux#v0.2.0'
set -g @plugin 'tmux-plugins/tmux-battery'
set -g @plugin 'MaximilianGaedig/tmux-filter'

# Plugin Settings
# ---------------
set -g @yank_selection_mouse 'clipboard'
set -g @yank_selection 'clipboard'
set -g @yank_action 'copy-pipe' # or 'copy-pipe-and-cancel' for the default

# Catppuccin Theme Configuration
set -g status-position top
set -g @catppuccin_window_left_separator "█"
set -g @catppuccin_window_right_separator "█"
set -g @catppuccin_window_number_position "left"
set -g @catppuccin_window_middle_separator "█ "
set -g @catppuccin_window_default_fill "number"
set -g @catppuccin_window_current_fill "number"
set -g @catppuccin_window_current_text "#W#{?window_zoomed_flag,(🔍),}"
set -g @catppuccin_window_default_text "#W"

# Determine status modules based on hostname
run-shell "if [ $(hostname) = 't14' ]; then \
    tmux set -g @catppuccin_status_modules_right 'date_time battery session'; \
  else \
    tmux set -g @catppuccin_status_modules_right 'date_time session'; \
  fi"

set -g @catppuccin_status_left_separator  ""
set -g @catppuccin_status_right_separator " "
set -g @catppuccin_status_right_separator_inverse "yes"
set -g @catppuccin_status_fill "all"
set -g @catppuccin_status_connect_separator "yes"
set -g @catppuccin_date_time_text "%Y-%m-%d %H:%M:%S"

# Rose Pine Color Scheme
set -g @catppuccin_pane_color "#1e1e2e"
set -g @catppuccin_pane_background_color "#181825"
set -g @catppuccin_window_current_color "#eb6f92"
set -g @catppuccin_window_current_background_color "#f5e0dc"
set -g @catppuccin_window_default_color "#ebbcba"
set -g @catppuccin_window_default_background_color "#f5e0dc"
set -g @catppuccin_session_color "#9ccfd8"
set -g @catppuccin_session_background_color "#f5e0dc"
set -g @catppuccin_directory_color "#c4a7e7"
set -g @catppuccin_directory_background_color "#f5e0dc"
set -g @catppuccin_date_time_color "#f6c177"
set -g @catppuccin_date_time_background_color "#f5e0dc"

# Battery Icons (Glyphs)
set -g @batt_icon_charge_tier8 ''
set -g @batt_icon_charge_tier7 ''
set -g @batt_icon_charge_tier6 ''
set -g @batt_icon_charge_tier5 ''
set -g @batt_icon_charge_tier4 ''
set -g @batt_icon_charge_tier3 ''
set -g @batt_icon_charge_tier2 ''
set -g @batt_icon_charge_tier1 ''

# Plugin Manager
set-environment -g TMUX_PLUGIN_MANAGER_PATH "$XDG_DATA_HOME/tmux/plugins"

# Install TPM if not already installed
if "test ! -d ~/.local/share/tmux/plugins/tpm" \
   "run 'git clone https://github.com/tmux-plugins/tpm ~/.local/share/tmux/plugins/tpm'"

# Initialize TPM (keep this line at the very bottom of tmux.conf)
run '~/.local/share/tmux/plugins/tpm/tpm'

