{ pkgs
, lib
, config
, ... }: with lib; let
  cfg = config.passthrough.catppuccin;
  palette = (import ./palette.nix).${cfg.palette};
in mkIf cfg.enable {
  # cursor theme
  home.pointerCursor = { inherit (cfg.cursor) package name; };
  gtk.cursorTheme = { inherit (cfg.cursor) package name; };

  # gtk theme
  gtk.theme = { inherit (cfg.gtk) package name; };
  gtk.iconTheme = {
    package = pkgs.catppuccin-papirus-folders.override {
      flavor = cfg.palette;
      accent = "pink";
    };
    name = "Papirus-Dark";
  };

  # sway colour palette override
  wayland.windowManager.sway.config = {
    colors = with palette; {
      focused =         { border = lavender; background = base; text = text;  indicator = rosewater; childBorder = lavender; };
      focusedInactive = { border = overlay0; background = base; text = text;  indicator = rosewater; childBorder = overlay0; };
      unfocused =       { border = overlay0; background = base; text = text;  indicator = rosewater; childBorder = overlay0; };
      urgent =          { border = peach;    background = base; text = peach; indicator = overlay0;  childBorder = peach; };
      placeholder =     { border = overlay0; background = base; text = text;  indicator = overlay0;  childBorder = overlay0; };
      background =                 base;
    };

    bars = mkForce [ {
      colors = let
        p = palette;
      in {
        background =                   p.base;
        statusline =                   p.text;
        focusedStatusline =            p.text;
        focusedSeparator =             p.base;
        focusedWorkspace =  { border = p.base; background = p.base; text = p.green; };
        activeWorkspace =   { border = p.base; background = p.base; text = p.blue; };
        inactiveWorkspace = { border = p.base; background = p.base; text = p.surface1; };
        urgentWorkspace =   { border = p.base; background = p.base; text = p.surface1; };
        bindingMode =       { border = p.base; background = p.base; text = p.surface1; };
      };

      mode = "dock";
      position = "bottom";
      workspaceButtons = true;
      workspaceNumbers = true;
      statusCommand = "${pkgs.i3status}/bin/i3status";
      fonts = {
        names = [ "monospace" ];
        size = 8.0;
      };
      trayOutput = "primary";
    } ];

    output."*".bg = mkForce "${./flake.png} fill";
    gaps.inner = 12;
    gaps.outer = 5;
    # dodge the status bar
    gaps.bottom = 0;
  };

  # swaylock colour palette override
  programs.swaylock.settings = with palette; let
    transparent = "00000000";
  in {
    color = base;
    bs-hl-color = rosewater;
    caps-lock-bs-hl-color = rosewater;
    caps-lock-key-hl-color = green;
    inside-color = transparent;
    inside-clear-color = transparent;
    inside-caps-lock-color = transparent;
    inside-ver-color = transparent;
    inside-wrong-color = transparent;
    key-hl-color = green;
    layout-bg-color = transparent;
    layout-border-color = transparent;
    layout-text-color = text;
    line-color = transparent;
    line-clear-color = transparent;
    line-caps-lock-color = transparent;
    line-ver-color = transparent;
    line-wrong-color = transparent;
    ring-color = lavender;
    ring-clear-color = rosewater;
    ring-caps-lock-color = peach;
    ring-ver-color = blue;
    ring-wrong-color = maroon;
    separator-color = transparent;
    text-color = text;
    text-clear-color = rosewater;
    text-caps-lock-color = peach;
    text-ver-color = blue;
    text-wrong-color = maroon;
  };

  # i3status colour palette override
  programs.i3status.general = with palette; {
    color_good = lavender;
    color_degraded = yellow;
    color_bad = red;
  };

  # mako colour palette override
  services.mako = with palette; {
    backgroundColor = base;
    textColor = text;
    borderColor = blue;
    progressColor = "over ${surface0}";
    extraConfig = ''
      [urgency=high]
      border-color=${peach}
    '';
  };

  # foot colour palette override
  programs.foot.settings.colors = with palette; let
    c = substring 1 7;
  in {
    foreground = c text; background = c base;
    regular0 = c overlay2; regular1 = c red;
    regular2 = c green; regular3 = c yellow;
    regular4 = c blue; regular5 = c pink;
    regular6 = c teal; regular7 = c surface2;
    bright0 = c subtext0; bright1 = c red;
    bright2 = c green; bright3 = c yellow;
    bright4 = c blue; bright5 = c pink;
    bright6 = c teal; bright7 = c surface1;
  };
}
