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

let
  cfg = config.samfelag.modules.system.pass;
  i3Cfg = config.samfelag.modules.desktop.wm.i3;
  hyprCfg = config.samfelag.modules.desktop.wm.hyprland;
in
{
  options.samfelag.modules.system.pass = {
    enable = lib.mkEnableOption "pass";
  };
  config = lib.mkIf cfg.enable {
    samfelag.modules.system.gpg.enable = true;
    environment.systemPackages = with pkgs; [
      pass
    ];

    hm.programs.rofi.pass = {
      enable = true;
      package = if hyprCfg.enable then pkgs.rofi-pass-wayland else pkgs.rofi-pass;
      extraConfig = ''
        default_user="sastrey@gmail.com"
        default_user2="marc"

        # Random value, see https://github.com/carnager/rofi-pass/issues/226
        help_color="#4872FF"

        _rofi () {
          rofi -i -no-auto-select -theme /home/marc/.config/rofi/menus/pass/pass.rasi "$@"
        }

        fix_layout=true
        layout_cmd () {
          setxkbmap
        }
      '';
    };

    samfelag.modules.desktop.wm.i3.extraKeybindings = lib.mkIf i3Cfg.enable {
      "${i3Cfg.mod}+p" = "exec rofi-pass";
    };

    samfelag.modules.desktop.wm.hyprland.extraKeybindings = lib.mkIf hyprCfg.enable [
      "${hyprCfg.mod}, P, exec, rofi-pass"
    ];
  };
}
