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

let
  cfg = config.snowhawk.sxhkd;
in
{
  options.snowhawk.sxhkd = {
    enable = lib.mkEnableOption "custom sxhkd home-manager module";
  };

  config = lib.mkIf cfg.enable {
    systemd.user.services.sxhkd = {
      Unit = {
        Description = "sxhkd service";
        PartOf = [ "graphical-session.target" ];
      };
      Service = {
        Type = "exec";
        ExecStart = "${pkgs.sxhkd}/bin/sxhkd";
      };
      Install.WantedBy = [ "graphical-session.target" ];
    };

    xdg.configFile."sxhkd/sxhkdrc".text =
      lib.concatStringsSep "\n" (lib.mapAttrsToList
        (hotkey: command:
          lib.optionalString (command != null) ''
            ${hotkey}
              ${command}
          '')
        config.services.sxhkd.keybindings);
  };
}