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

let
  cfg = config.programs.rofi-rbw;

  inherit (lib)
    generators
    mkEnableOption
    mkIf
    mkOption
    mkPackageOption
    types
    ;
in
{
  options = {
    programs.rofi-rbw = {
      enable = mkEnableOption "rofi-rbw";
      package = mkPackageOption pkgs "rofi-rbw" { };
      settings = mkOption {
        type = types.attrsOf (
          types.oneOf [
            types.str
            types.int
            types.bool
          ]
        );
        default = { };
        example = {
          action = "copy";
          prompt = "Bitwarden";
          selector = "rofi";
          selector-args = "-i";
        };
        description = ''
          Configuration settings for rofi-rbw.
          See https://github.com/fdw/rofi-rbw/blob/main/docs/rofi-rbw.1.md
        '';
      };
    };
  };

  config = mkIf cfg.enable {
    home.packages = [ cfg.package ];

    xdg.configFile."rofi-rbw.rc".text = generators.toKeyValue {
      mkKeyValue = key: value: "${key} = ${toString value}";
    } cfg.settings;
  };
}
