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

with lib;
let
  cfg = config.my.programs.tofi;

  configText =
    let
      settingsStrings = mapAttrsToList (name: value: "${name} = ${value}") cfg.settings;
    in
    concatLines settingsStrings;
in
{
  options.my.programs.tofi = {
    enable = mkEnableOption "tofi";
    settings = mkOption {
      type = with types; attrsOf str;
      default = { };
    };
  };

  config = mkIf cfg.enable {
    environment.systemPackages = with pkgs; [
      (lib.mkIf config.networking.networkmanager.enable networkmanager_dmenu)
      # (lib.mkIf config.hardware.bluetooth.enable rofi-bluetooth)
      # rofi-power-menu
    ];
    home-manager.users.moritz = {
      home.packages = with pkgs; [ tofi ];
      xdg = {
        enable = true;
        configFile."tofi/config".text = configText;
        configFile."networkmanager-dmenu/config.ini".text = ''
          [dmenu]
          dmenu_command = tofi
        '';
      };
    };
  };
}
