{ config, lib, pkgs, inputs, ... }:

let
  cfg = config.samfelag.modules.desktop.tools.rofi;
  hyprCfg = config.samfelag.modules.desktop.wm.hyprland;
  i3Cfg = config.samfelag.modules.desktop.wm.i3;
  nix-colors-lib = inputs.nix-colors.lib-contrib { inherit pkgs; };
in
{
  options.samfelag.modules.desktop.tools.rofi = {
    enable = lib.mkEnableOption "rofi";
  };
  config = lib.mkIf cfg.enable {
    environment.systemPackages = with pkgs; [
        rofi
    ];

    hm.xdg.configFile."rofi/menus".source = ../../../config/rofi/menus;
    hm.xdg.configFile."rofi/nix.png".source = nix-colors-lib.nixWallpaperFromScheme {
      scheme = config.colorScheme;
      width = 600;
      height = 600;
      logoScale = 2.0;
    };

    # Themeing ---------------------------------
    hm.xdg.configFile."rofi/theme.rasi".text = ''
      * {
          font:                        "Iosevka Nerd Font 10";
          background:                  #${config.colorScheme.palette.base00};
          background-alt:              #${config.colorScheme.palette.base02};
          foreground:                  #${config.colorScheme.palette.base05};
          selected:                    #${config.colorScheme.palette.base03};
          active:                      #${config.colorScheme.palette.base07};
          urgent:                      #${config.colorScheme.palette.base06};
      }
    '';

    samfelag.modules.desktop.wm.hyprland = lib.mkIf hyprCfg.enable {
      extraKeybindings = [
        "${hyprCfg.mod}, SPACE, exec, $HOME/.config/rofi/menus/launcher/launcher.sh"
        "${hyprCfg.mod} SHIFT, P, exec, $HOME/.config/rofi/menus/powermenu/powermenu.sh"
        "${hyprCfg.mod} SHIFT, W, exec, $HOME/.config/rofi/menus/wifi/wifi.sh"
      ]; 
      extraGestures = [
        "3, up, dispatcher, exec, $HOME/.config/rofi/menus/launcher/launcher.sh"
      ];
    };

    samfelag.modules.desktop.wm.i3.extraKeybindings = lib.mkIf i3Cfg.enable {
      "${i3Cfg.mod}+space" = "exec $HOME/.config/rofi/menus/launcher/launcher.sh";
      "${i3Cfg.mod}+End" = "exec $HOME/.config/rofi/menus/powermenu/powermenu.sh";
      "${i3Cfg.mod}+Shift+w" = "exec $HOME/.config/rofi/menus/wifi/wifi.sh";
    };

  };
}
