{
  lib,
  config,
  pkgs,
  ...
}:
let
  inherit (lib) mkEnableOption mkIf;

  cfg = config.marleyos.programs.cheat;
  inherit (config.marleyos.theme) colors;

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

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

    xdg.configFile."cheat/conf.yml".source = toYAML "conf.yml" {
      colorize = true;
      style = "${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;
          }
        ];
    };
  };
}
