{ pkgs, config, lib, ... }:
let
  dracula-gtk = pkgs.fetchFromGitHub {
    owner = "dracula";
    repo = "gtk";
    rev = "502f212d83bc67e8f0499574546b99ec6c8e16f9";
    sha256 = "1wx9nzq7cqyvpaq4j60bs8g7gh4jk8qg4016yi4c331l4iw1ymsa";
  };
in
{
  home.pointerCursor = {
    x11.enable = true;
    x11.defaultCursor = "left_ptr";
    package = pkgs.capitaine-cursors;
    name = "capitaine-cursors";
  };
  # Install themes
  home.packages = with pkgs; [
    ayu-theme-gtk
    dracula-theme
    capitaine-cursors
    paper-icon-theme
    papirus-icon-theme
    libsForQt5.qtstyleplugin-kvantum
    qt5ct
    gtk-engine-murrine
    gtk_engines
    maim
    kitty
    libreoffice
    inotify-tools
    offpunk
    termpdfpy
  ];

  # GTK4 color scheme?
  dconf.settings = {
    "org/gnome/desktop/interface" = {
      color-scheme = "prefer-dark";
    };
  };

  # Move required config files around
  xdg.enable = true; # This doesn't seem to do anything so we have below
  xdg.configHome = "/home/anish/.config"; # TODO bad hardcode
  xdg.configFile = {
    "Kvantum/Dracula/Dracula.kvconfig".source = "${dracula-gtk}/kde/kvantum/Dracula-purple-solid/Dracula-purple-solid.kvconfig";
    "Kvantum/Dracula/Dracula.svg".source = "${dracula-gtk}/kde/kvantum/Dracula-purple-solid/Dracula-purple-solid.svg";
    "Kvantum/kvantum.kvconfig".text = "[General]\ntheme=Dracula";
  };
  home.file = {
    ".config/bspwm/rc.d/polybar".source = ./run.sh;
    ".config/bspwm/bspwmrc".source = ./bspwmrc;
    ".config/sxhkdrc".source = ./sxhkdrc;
    ".config/rofi/theme" = {
      source = ./rofi;
      recursive = true;
    };
    ".config/polybar" = {
      source = ./polybar;
      recursive = true;
    };
    ".config/dunst/dunstrc".source = ./dunstrc;
    ".config/kitty/kitty.conf".source = ./kitty.conf;
    ".config/kitty/ayu.conf".source = ./ayu-kitty.conf;
    ".config/zathura/zathurarc".source = ./zathurarc;
    ".background-image".source = ./background.jpg;
    #gtk4 theme
    ".config/gtk-4.0/settings.ini".text = ''
      [Settings]
      gtk-application-prefer-dark-theme=1
    '';
    # gtk3 theme
    ".config/gtk-3.0/settings.ini".text = ''
      [Settings]
      gtk-theme-name=Dracula
      gtk-icon-theme-name=Paper
      gtk-cursor-theme-name=Capitaine Cursors - White
      gtk-fallback-icon-theme=gnome
      gtk-application-prefer-dark-theme=1
      gtk-xft-hinting=1
      gtk-xft-hintstyle=hintfull
      gtk-xft-rgba=none
    '';
    # GTK2 global theme (widget and icon theme)
    ".config/gtk-2.0/gtkrc".text = ''
      gtk-theme-name=Ayu-Mirage
      gtk-icon-theme-name=Capitaine Cursors - White
      gtk-font-name="Sans 10"
    '';
    ".local/bin/passmenu".source = ./bin/passmenu;
    ".local/bin/paste".source = ./bin/paste;
    ".local/bin/bluetoothmenu".source = ./bin/bluetoothmenu;
    ".local/bin/wifimenu".source = ./bin/wifimenu;
    ".local/bin/powermenu".source = ./bin/powermenu;
    ".local/bin/screenshot".source = ./bin/screenshot;
    ".local/bin/mpv-ify".source = ./bin/mpv-ify;
    ".local/bin/bspswallow".source = ./bin/bspswallow;
    ".config/bspwm/terminals".text = "Kitty";
    ".config/eww/eww.yuck".source = ./eww/eww.yuck;
    ".config/eww/eww.scss".source = ./eww/eww.scss;
    ".config/eww/widgets.yuck".source = ./eww/widgets.yuck;
    # ".local/bin/hotplug-monitor.sh".source = ./bin/hotplug-monitor.sh;
  };

  xdg.desktopEntries = {
    ocr = {
      name = "OCR image";
      exec = "${pkgs.writeScript "ocr" ''
        ${pkgs.xfce.xfce4-screenshooter}/bin/xfce4-screenshooter -r --save /tmp/ocr-tmp.png
        ${pkgs.tesseract}/bin/tesseract /tmp/ocr-tmp.png | ${pkgs.xclip}/bin/xclip -sel clip
        rm /tmp/ocr-tmp.png
      ''}";
    };
    screenshot = {
      name = "Screenshot";
      exec = "screenshot";
    };
  };


  qt = {
    enable = true;
    platformTheme = "gtk";
    style = { name = "qt5ct-style"; };
  };

  # set up env
  xsession.enable = true;

  xresources.properties = {
    "*.foreground" = "#95E6CB";
    "*.background" = "#1F2430";
    "*.cursorColor" = "#BAE67E";
    # Black
    "*.color0" = "#1F2430";
    "*.color8" = "#F28779";
    # Red          
    "*.color1" = "#A6CC70";
    "*.color9" = "#FFCC66";
    # Green        
    "*.color2" = "#5CCFE6";
    "*.color10" = "#F29E74";
    # Yellow
    "*.color3" = "#77A8D9";
    "*.color11" = "#5C6773";
    # Blue         
    "*.color4" = "#707A8C";
    "*.color12" = "#F27983";
    # Magenta      
    "*.color5" = "#BAE67E";
    "*.color13" = "#FFD580";
    # Cyan         
    "*.color6" = "#73D0FF";
    "*.color14" = "#FFA759";
    # White        
    "*.color7" = "#95E6CB";
    "*.color15" = "#CBCCC6";
    # Bold, Italic, Underline
    "*.colorBD" = "#e6e1cf";
  };

  programs.autorandr.enable = true;
  services.udiskie.automount = true;

  services.mpris-proxy.enable = true; # bluetooth media control

  # Compositor
  # services.picom = {
  #   enable = true;
  #   fade = true;
  #   fadeDelta = 1;
  #   fadeSteps = [ "0.01" "0.022" ];
  #   shadow = true;
  #   shadowOffsets = [ (-10) (-10) ];
  #   shadowOpacity = "0.22";
  #   # activeOpacity = "1.00"; 
  #   # inactiveOpacity = "0.92"; 
  #   extraOptions = '' 
  #        shadow-radius = 12;  
  #        # blur-background = true;  
  #        # blur-background-frame = true;  
  #        # blur-background-fixed = true;  
  #        blur-kern = "7x7box"; 
  #        blur-strength = 320;  
  #        corner-radius = 3
  #      '';
  # };
}
