{ config
, pkgs
, flavor
, rosewater
, flamingo
, pink
, mauve
, red
, maroon
, peach
, yellow
, green
, teal
, sky
, sapphire
, blue
, lavender
, text
, subtext1
, subtext0
, overlay2
, overlay1
, overlay0
, surface2
, surface1
, surface0
, base
, mantle
, crust
, ...
}:

{
  my.programs.tofi.settings = {
    text-color = "#${text}";
    prompt-color = "#${red}";
    selection-color = "#${yellow}";
    background-color = "#${base}";
  };
  home-manager.users.moritz = {
    programs = {
      fzf.colors = {
        "bg+" = "#${surface0}";
        "fg+" = "#${text}";
        "hl+" = "#${red}";
        bg = "#${base}";
        fg = "#${text}";
        header = "#${red}";
        hl = "#${red}";
        info = "#${mauve}";
        marker = "#${rosewater}";
        pointer = "#${rosewater}";
        prompt = "#${mauve}";
        spinner = "#${rosewater}";
      };
      foot.settings.colors = {
        foreground = text; # Text
        background = base; # Base
        regular0 = surface1; # Surface 1
        regular1 = red; # red
        regular2 = green; # green
        regular3 = yellow; # yellow
        regular4 = blue;
        regular5 = pink;
        regular6 = teal;
        regular7 = subtext1;
        bright0 = surface2;
        bright1 = red;
        bright2 = green;
        bright3 = yellow;
        bright4 = blue;
        bright5 = pink;
        bright6 = teal;
        bright7 = subtext0;
      };
      kitty.extraConfig = ''
        # vim:ft=kitty

        ## name:     Catppuccin-Frappe
        ## author:   Pocco81 (https://github.com/Pocco81)
        ## license:  MIT
        ## upstream: https://github.com/catppuccin/kitty/blob/main/frappe.conf
        ## blurb:    Soothing pastel theme for the high-spirited!



        # The basic colors
        foreground              #${text}
        background              #${base}
        selection_foreground    #${base}
        selection_background    #${rosewater}

        # Cursor colors
        cursor                  #${rosewater}
        cursor_text_color       #${base}

        # URL underline color when hovering with mouse
        url_color               #${rosewater}

        # Kitty window border colors
        active_border_color     #${lavender}
        inactive_border_color   #${overlay0}
        bell_border_color       #${yellow}

        # OS Window titlebar colors
        wayland_titlebar_color system
        macos_titlebar_color system

        # Tab bar colors
        active_tab_foreground   #${crust}
        active_tab_background   #${mauve}
        inactive_tab_foreground #${text}
        inactive_tab_background #${mantle}
        tab_bar_background      #${crust}

        # Colors for marks (marked text in the terminal)
        mark1_foreground #${base}
        mark1_background #${lavender}
        mark2_foreground #${base}
        mark2_background #${mauve}
        mark3_foreground #${base}
        mark3_background #${sapphire}

        # The 16 terminal colors

        # black
        color0 #${surface1}
        color8 #${surface2}

        # red
        color1 #${red}
        color9 #${red}

        # green
        color2  #${green}
        color10 #${green}

        # yellow
        color3  #${yellow}
        color11 #${yellow}

        # blue
        color4  #${blue}
        color12 #${blue}

        # magenta
        color5  #${pink}
        color13 #${pink}

        # cyan
        color6  #${teal}
        color14 #${teal}

        # white
        color7  #${subtext1}
        color15 #${subtext0}
      '';
      tmux.plugins = with pkgs.tmuxPlugins; [
        {
          plugin = catppuccin;
          extraConfig = "set -g @catppuccin_flavour '${flavor}'";
        }
      ];
      zathura.extraConfig = ''
        set window-title-basename "true"
        set selection-clipboard "clipboard"

        set default-fg                "#${text}"
        set default-bg                "#${base}"

        set completion-bg             "#${surface0}"
        set completion-fg             "#${text}"
        set completion-highlight-bg   "#575268"
        set completion-highlight-fg   "#${text}"
        set completion-group-bg       "#${surface0}"
        set completion-group-fg       "#${blue}"

        set statusbar-fg              "#${text}"
        set statusbar-bg              "#${surface0}"

        set notification-bg           "#${surface0}"
        set notification-fg           "#${text}"
        set notification-error-bg     "#${surface0}"
        set notification-error-fg     "#${red}"
        set notification-warning-bg   "#${surface0}"
        set notification-warning-fg   "#FAE3B0"

        set inputbar-fg               "#${text}"
        set inputbar-bg               "#${surface0}"

        set recolor-lightcolor        "#${base}"
        set recolor-darkcolor         "#${text}"

        set index-fg                  "#${text}"
        set index-bg                  "#${base}"
        set index-active-fg           "#${text}"
        set index-active-bg           "#${surface0}"

        set render-loading-bg         "#${base}"
        set render-loading-fg         "#${text}"

        set highlight-color           "#575268"
        set highlight-fg              "#${pink}"
        set highlight-active-color    "#${pink}"
      '';
      rofi = {
        theme = "custom";
        extraConfig = {
          show-icons = true;
          terminal = "alacritty";
          drun-display-format = "{icon} {name}";
          location = 0;
          disable-history = false;
          hide-scrollbar = true;
          display-drun = "   Apps ";
          display-run = "   Run ";
          display-window = " 﩯  Window";
          display-Network = " 󰤨  Network";
          sidebar-mode = true;
        };
      };
    };
    xsession.windowManager.bspwm.settings = {
      focused_border_color = "#${mauve}";
      normal_border_color = "#${base}";
      active_border_color = "#${base}";
    };
    services = {
      dunst.settings = {
        global = {
          # Defines color of the frame around the notification window.
          frame_color = "#${blue}";

          # Define a color for the separator.
          # possible values are:
          #  * auto: dunst tries to find a color fitting to the background;
          #  * foreground: use the same color as the foreground;
          #  * frame: use the same color as the frame;
          #  * anything else will be interpreted as a X color.
          separator_color = "frame";
        };

        urgency_low = {
          background = "#${base}";
          foreground = "#${text}";
        };
        urgency_normal = {
          background = "#${base}";
          foreground = "#${text}";
        };
        urgency_critical = {
          background = "#${base}";
          foreground = "#${text}";
          frame_color = "#${peach}";
        };
      };
      polybar = {
        config = {
          "bar/bottom" = {
            background = base;
            foreground = text;
            border-color = base;
          };
          "module/bspwm" = {
            label-focused-foreground = pink;
            label-occupied-foreground = overlay1;
            label-urgent-foreground = maroon;
            label-empty-foreground = overlay1;
            label-separator-foreground = base;
          };
          "module/cpu" = {
            format-foreground = base;
            format-background = green;
          };
          "module/time" = {
            format-foreground = base;
            format-background = blue;
          };
          "module/date" = {
            format-foreground = base;
            format-background = peach;
          };
          "module/memory" = {
            format-foreground = base;
            format-background = blue;
          };
          "module/pulseaudio" = {
            format-volume-foreground = base;
            format-volume-background = mauve;
            label-muted = "婢 muted";
            format-muted-foreground = base;
            format-muted-background = red;
          };
          "module/network" = {
            format-connected-foreground = base;
            format-connected-background = mauve;
          };
          "module/battery" = {
            format-charging-foreground = base;
            format-charging-background = green;
            format-full-foreground = base;
            format-full-background = green;
            format-discharging-foreground = base;
            format-discharging-background = red;
          };
        };
      };
    };
    xdg.configFile = {
      "fish/conf.d/theme.fish".text = ''
        # Catppuccin color palette

        # --> special
        set -l foreground ${text}
        set -l selection ${surface0}

        # --> palette
        set -l teal ${teal}
        set -l flamingo ${flamingo}
        set -l mauve ${mauve}
        set -l pink ${pink}
        set -l red ${red}
        set -l peach ${peach}
        set -l green ${green}
        set -l yellow ${yellow}
        set -l blue ${blue}
        set -l gray ${overlay0}

        # Syntax Highlighting
        set -g fish_color_normal $foreground
        set -g fish_color_command $blue
        set -g fish_color_param $flamingo
        set -g fish_color_keyword $red
        set -g fish_color_quote $green
        set -g fish_color_redirection $pink
        set -g fish_color_end $peach
        set -g fish_color_error $red
        set -g fish_color_gray $gray
        set -g fish_color_selection --background=$selection
        set -g fish_color_search_match --background=$selection
        set -g fish_color_operator $pink
        set -g fish_color_escape $flamingo
        set -g fish_color_autosuggestion $gray
        set -g fish_color_cancel $red

        # Prompt
        set -g fish_color_cwd $yellow
        set -g fish_color_user $teal
        set -g fish_color_host $blue

        # Completion Pager
        set -g fish_pager_color_progress $gray
        set -g fish_pager_color_prefix $pink
        set -g fish_pager_color_completion $foreground
        set -g fish_pager_color_description $gray
      '';
      "rofi/custom.rasi".text = ''
        * {
            bg-col: #${base};
            bg-col-light: #${base};
            border-col: #${base};
            selected-col: #${base};
            blue: #${blue};
            fg-col: #${text};
            fg-col2: #${red};
            grey: #${overlay0};

            width: 900;
            font: "JetBrainsMono Nerd Font 14";
        }

        element-text, element-icon , mode-switcher {
            background-color: inherit;
            text-color:       inherit;
        }

        window {
            height: 360px;
            border: 3px;
            border-color: @border-col;
            background-color: @bg-col;
        }

        mainbox {
            background-color: @bg-col;
        }

        inputbar {
            children: [prompt,entry];
            background-color: @bg-col;
            border-radius: 5px;
            padding: 2px;
        }

        prompt {
            background-color: @blue;
            padding: 6px;
            text-color: @bg-col;
            border-radius: 3px;
            margin: 20px 0px 0px 20px;
        }

        textbox-prompt-colon {
            expand: false;
            str: ":";
        }

        entry {
            padding: 6px;
            margin: 20px 0px 0px 10px;
            text-color: @fg-col;
            background-color: @bg-col;
        }

        listview {
            border: 0px 0px 0px;
            padding: 6px 0px 0px;
            margin: 10px 0px 0px 20px;
            columns: 2;
            lines: 5;
            background-color: @bg-col;
        }

        element {
            padding: 5px;
            background-color: @bg-col;
            text-color: @fg-col  ;
        }

        element-icon {
            size: 25px;
        }

        element selected {
            background-color:  @selected-col ;
            text-color: @fg-col2  ;
        }

        mode-switcher {
            spacing: 0;
          }

        button {
            padding: 10px;
            background-color: @bg-col-light;
            text-color: @grey;
            vertical-align: 0.5;
            horizontal-align: 0.5;
        }

        button selected {
          background-color: @bg-col;
          text-color: @blue;
        }
      '';
    };
  };
}
