# ABOUTME: Btop system monitor configuration with nix-colors theming
# ABOUTME: Creates a custom theme file and configures btop settings

{ config, pkgs, ... }:
let
  cfg = import ./config.nix;
  palette = config.colorScheme.palette;
in
{
  home.file.".config/btop/themes/${cfg.theme}.theme".text = ''
    # Main text color
    theme[main_fg]="${palette.base05}"

    # Title color for boxes
    theme[title]="${palette.base05}"

    # Highlight color for keyboard shortcuts
    theme[hi_fg]="${palette.base0D}"

    # Background color of selected item in processes box
    theme[selected_bg]="${palette.base01}"

    # Foreground color of selected item in processes box
    theme[selected_fg]="${palette.base05}"

    # Color of inactive/disabled text
    theme[inactive_fg]="${palette.base04}"

    # Misc colors for processes box
    theme[proc_misc]="${palette.base0D}"

    # Box outline colors
    theme[cpu_box]="${palette.base0B}"
    theme[mem_box]="${palette.base09}"
    theme[net_box]="${palette.base0E}"
    theme[proc_box]="${palette.base0C}"

    # Box divider line
    theme[div_line]="${palette.base04}"

    # Temperature graph colors
    theme[temp_start]="${palette.base0B}"
    theme[temp_mid]="${palette.base0A}"
    theme[temp_end]="${palette.base08}"

    # CPU graph colors
    theme[cpu_start]="${palette.base0B}"
    theme[cpu_mid]="${palette.base0A}"
    theme[cpu_end]="${palette.base08}"

    # Mem/Disk meters
    theme[free_start]="${palette.base0B}"
    theme[cached_start]="${palette.base0A}"
    theme[available_start]="${palette.base09}"
    theme[used_start]="${palette.base08}"

    # Network graph colors
    theme[download_start]="${palette.base0E}"
    theme[download_mid]="${palette.base0D}"
    theme[download_end]="${palette.base0C}"
    theme[upload_start]="${palette.base0E}"
    theme[upload_mid]="${palette.base0D}"
    theme[upload_end]="${palette.base0C}"
  '';

  programs.btop = {
    enable = true;
    settings = {
      color_theme = cfg.theme;
      theme_background = false;
      truecolor = true;
      force_tty = false;
      vim_keys = true;
      rounded_corners = true;
      graph_symbol = "braille";
      shown_boxes = "cpu mem net proc";
      update_ms = 2000;
      proc_sorting = "cpu lazy";
      proc_colors = true;
      proc_gradient = false;
      proc_per_core = false;
      proc_mem_bytes = true;
      proc_cpu_graphs = true;
      show_uptime = true;
      check_temp = true;
      show_coretemp = true;
      temp_scale = "celsius";
      show_cpu_freq = true;
      clock_format = "%X";
      background_update = true;
      mem_graphs = true;
      show_swap = true;
      swap_disk = true;
      show_disks = true;
      only_physical = true;
      use_fstab = true;
      show_io_stat = true;
      net_auto = true;
      net_sync = true;
      show_battery = true;
      log_level = "WARNING";
    };
  };
}
