{
  lib,
  config,
  namespace,
  pkgs,
  ...
}:
let
  inherit (lib) mkIf;
  inherit (lib.${namespace}) mkEnableModule;

  cfg = config.${namespace}.programs.cheat;
  inherit (config.${namespace}) theme;

  toYAML = (pkgs.formats.yaml { }).generate;
in
{
  options = mkEnableModule "programs.cheat";

  config = mkIf cfg.enable {
    home.packages = with pkgs; [
      cheat
    ];

    xdg.configFile."cheat/conf.yml".source = toYAML "conf.yml" {
      colorize = true;
      style = "${theme.colors.base}";
      formatter = "terminal256";
      pager = "less -FRX";

      cheatpaths =
        let
          cheatDir = "${config.xdg.configHome}/cheat/cheatsheets";
        in
        [
          {
            name = "community";
            path = "${cheatDir}/community";
            tags = [ "community" ];
            readonly = true;
          }
          {
            name = "personal";
            path = "${cheatDir}/personal";
            tags = [ "personal" ];
            readonly = false;
          }
        ];
    };
  };
}