{ lib, config, pkgs, ... }:
let
  gtkThemeFromScheme = import ./gtk-theme-gen.nix { inherit pkgs config; };
  wallpaperGen = import ./wallpaper-gen.nix { inherit pkgs config; };
in {

  config = lib.mkIf (config.syscfg.make.gui) {
    home.pointerCursor = {
      package = pkgs.bibata-cursors;
      name = "Bibata-Modern-Classic";
      size = 24;
      gtk.enable = true;
      x11.enable = true;
    };

    gtk = {
      enable = true;
      theme = {
        name = "${config.colorscheme.slug}-Dark";
        package = gtkThemeFromScheme;
      };
      gtk4.theme = config.gtk.theme; 
      iconTheme = {
        name = "tela-circle-icon-theme";
        package = pkgs.tela-circle-icon-theme;
      };
    };

    qt = {
      enable = true;
      platformTheme.name = "gtk";
    };

    home.packages = [ wallpaperGen pkgs.awww ];

    xdg.configFile."script/wallpaper.sh".text = ''
      #!/bin/sh

      NIXDIR=${wallpaperGen}
      WPDIR=$NIXDIR/share/wallpaper/

      IMGS=$(find $WPDIR -type f -print)


      RES=$(echo "$IMGS" | awk -v dir="$WPDIR" '{
          image_file = $0; 
          gsub("^" dir, "", image_file);
          print "img:" $0 ":text:" image_file;
      }')

      IMG=$WPDIR/$(echo "$RES" | wofi --dmenu --allow-images show-icons true -theme-str '#window { width: 50%; }' -p "Choose wallpaper:")
      IMG=$(echo "$IMG" | awk -F ':' '{print $2}')
      awww img $IMG
    '';
  };
}
