{ pkgs
, lib
, config
, ... }: with lib; let
  cfg = config.passthrough.btop;
in mkIf cfg.enable {
  programs.btop = {
    enable = true;
    settings = {
      color_theme = "catppuccin";
      theme_background = false;
    };
  };

  home.file."${config.xdg.configHome}/btop/themes/catppuccin.theme".text = with (import ../gui/catppuccin/palette.nix)
  .${config.passthrough.catppuccin.palette}; ''
    # Main background, empty for terminal default, need to be empty if you want transparent background
    theme[main_bg]="${base}"

    # Main text color
    theme[main_fg]="${text}"

    # Title color for boxes
    theme[title]="${text}"

    # Highlight color for keyboard shortcuts
    theme[hi_fg]="${blue}"

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

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

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

    # Color of text appearing on top of graphs, i.e uptime and current network graph scaling
    theme[graph_text]="${rosewater}"

    # Background color of the percentage meters
    theme[meter_bg]="${surface1}"

    # Misc colors for processes box including mini cpu graphs, details memory graph and details status text
    theme[proc_misc]="${rosewater}"

    # CPU, Memory, Network, Proc box outline colors
    theme[cpu_box]="${mauve}" #Mauve
    theme[mem_box]="${green}" #Green
    theme[net_box]="${maroon}" #Maroon
    theme[proc_box]="${blue}" #Blue

    # Box divider line and small boxes line color
    theme[div_line]="${overlay0}"

    # Temperature graph color (Green -> Yellow -> Red)
    theme[temp_start]="${green}"
    theme[temp_mid]="${yellow}"
    theme[temp_end]="${red}"

    # CPU graph colors (Teal -> Lavender)
    theme[cpu_start]="${teal}"
    theme[cpu_mid]="${sapphire}"
    theme[cpu_end]="${lavender}"

    # Mem/Disk free meter (Mauve -> Lavender -> Blue)
    theme[free_start]="${mauve}"
    theme[free_mid]="${lavender}"
    theme[free_end]="${blue}"

    # Mem/Disk cached meter (Sapphire -> Lavender)
    theme[cached_start]="${sapphire}"
    theme[cached_mid]="${blue}"
    theme[cached_end]="${lavender}"

    # Mem/Disk available meter (Peach -> Red)
    theme[available_start]="${peach}"
    theme[available_mid]="${maroon}"
    theme[available_end]="${red}"

    # Mem/Disk used meter (Green -> Sky)
    theme[used_start]="${green}"
    theme[used_mid]="${teal}"
    theme[used_end]="${sky}"

    # Download graph colors (Peach -> Red)
    theme[download_start]="${peach}"
    theme[download_mid]="${maroon}"
    theme[download_end]="${red}"

    # Upload graph colors (Green -> Sky)
    theme[upload_start]="${green}"
    theme[upload_mid]="${teal}"
    theme[upload_end]="${sky}"

    # Process box color gradient for threads, mem and cpu usage (Sapphire -> Mauve)
    theme[process_start]="${sapphire}"
    theme[process_mid]="${lavender}"
    theme[process_end]="${mauve}"
  '';
}
