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

with lib;
let
  cfg = config.my.programs.ghostty;
  format = pkgs.formats.keyValue {
    listsAsDuplicateKeys = true;
  };
in
{
  options.my.programs.ghostty.enable = mkEnableOption "Ghostty";
  options.my.programs.ghostty.package = (mkPackageOption pkgs "ghostty" { });
  options.my.programs.ghostty.settings = mkOption {
    inherit (format) type;
    description = ''
      Configuration written to {file}`$XDG_CONFIG_HOME/ghostty/config`.
    '';
    default = { };
  };

  config = mkIf cfg.enable {
    my.terminal.package = cfg.package;
    home-manager.users.moritz = {
      home.packages = [ cfg.package ];
      xdg.configFile."ghostty/config".source = format.generate "ghostty-config" cfg.settings;
    };
  };
}
