#### TERMINAL ####
set -g default-terminal "tmux-256color"
set -ag terminal-overrides ",xterm-256color:RGB"

#### PREFIX ####
unbind C-b
set -g prefix C-Space
bind C-Space send-prefix

#### GENERAL OPTIONS ####
set -g mouse on
set -g base-index 1
setw -g pane-base-index 1
set -g renumber-windows on
set -sg escape-time 10
set -g repeat-time 600
set -g history-limit 50000
set -g focus-events on
setw -g aggressive-resize on
set -g mode-keys vi
set -g status-keys vi
set -wg automatic-rename on
set -g allow-rename off
setw -g pane-border-status top

#### PANE NAVIGATION (no prefix — smart-splits passthrough) ####
bind -n M-h select-pane -L
bind -n M-j select-pane -D
bind -n M-k select-pane -U
bind -n M-l select-pane -R

#### PANE NAVIGATION (with prefix) ####
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R

#### PANE MOVEMENT (swap) ####
bind H swap-pane -U
bind J swap-pane -D
bind K swap-pane -U
bind L swap-pane -D

#### PANE SPLITS ####
unbind '"'
unbind %
bind s split-window -v -c "#{pane_current_path}"
bind v split-window -h -c "#{pane_current_path}"
bind q kill-pane
bind z resize-pane -Z

#### RESIZE MODE ####
bind r switch-client -T resize
bind -T resize h resize-pane -L 5
bind -T resize j resize-pane -D 5
bind -T resize k resize-pane -U 5
bind -T resize l resize-pane -R 5
bind -T resize H resize-pane -L 15
bind -T resize J resize-pane -D 15
bind -T resize K resize-pane -U 15
bind -T resize L resize-pane -R 15
bind -T resize Escape switch-client -T root
bind -T resize Enter switch-client -T root

#### WINDOWS ####
bind Return new-window -c "#{pane_current_path}"
bind c new-window -c "#{pane_current_path}"
bind Q kill-window
bind Tab next-window
bind BTab previous-window
bind 1 select-window -t :1
bind 2 select-window -t :2
bind 3 select-window -t :3
bind 4 select-window -t :4
bind 5 select-window -t :5
bind 6 select-window -t :6
bind 7 select-window -t :7
bind 8 select-window -t :8
bind 9 select-window -t :9
bind , command-prompt -I "#W" "rename-window '%%'"

#### SESSIONS ####
bind Space choose-tree -Zs
bind '$' command-prompt -I "#S" "rename-session '%%'"
bind d detach-client
bind C-s run-shell "~/.config/tmux/plugins/tpm/plugins/tmux-resurrect/scripts/save.sh"
bind C-r run-shell "~/.config/tmux/plugins/tpm/plugins/tmux-resurrect/scripts/restore.sh"

#### COPY MODE ####
bind '[' copy-mode
bind ']' paste-buffer
bind -T copy-mode-vi v send -X begin-selection
bind -T copy-mode-vi y send -X copy-selection-and-cancel
bind -T copy-mode-vi C-v send -X rectangle-toggle
bind -T copy-mode-vi Escape send -X cancel
bind -T copy-mode-vi q send -X cancel

#### MISC ####
bind R source-file ~/.config/tmux/tmux.conf \; display-message "Config reloaded!"
bind ? list-keys
bind t clock-mode

#### THEME ####
source-file ~/.config/tmux/apex-neon.conf

#### STATUS BAR ####
set -g status-left-length 100
set -g status-right-length 200

set -g status-left "#[fg=#{@void},bg=#{@razor},bold] #S #[fg=#{@razor},bg=default] "
set -g status-right " #{cpu_fg_color}CPU:#{cpu_percentage} #[fg=#{@tech}]MEM:#{ram_percentage} #{battery_color_fg}BAT:#{battery_percentage} #[fg=#{@amber}]#{@tmux-weather-location}:#{weather} #[fg=#{@dim}]%Y-%m-%d #[fg=#{@text}]%H:%M "

set -g window-status-format " #I:#W "
set -g window-status-current-format "#[bold] #I:#W "
set -g status-justify "absolute-centre"

#### RESURRECT / CONTINUUM ####
set -g @continuum-restore 'on'
set -g @continuum-save-interval '15'
set -g @resurrect-capture-pane-contents 'on'

#### PLUGINS (TPM) ####
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'
set -g @plugin 'tmux-plugins/tmux-resurrect'
set -g @plugin 'tmux-plugins/tmux-continuum'
set -g @plugin 'tmux-plugins/tmux-yank'
set -g @plugin 'joshmedeski/tmux-nerd-font-window-name'
set -g @plugin 'tmux-plugins/tmux-cpu'
set -g @plugin 'tmux-plugins/tmux-battery'
set -g @plugin 'xamut/tmux-weather'

set -g @tmux-weather-location "Nospelt"

# Initialize TPM (must be last)
run '~/.config/tmux/plugins/tpm/tpm'
