{
  config,
  lib,
  ...
}: let
  inherit (config.rose-pine) sources;

  cfg = config.programs.kitty.rose-pine;
  enable = cfg.enable && config.programs.kitty.enable;

  themeName =
    if (cfg.flavor == "main")
    then "rose-pine"
    else "rose-pine-${cfg.flavor}";
  themePath = "themes/${themeName}.conf";
  theme = sources.kitty + "/dist/${themeName}.conf";
in {
  options.programs.kitty.rose-pine = lib.rp.mkRosePineOpt {name = "kitty";};

  config = lib.mkIf enable {
    xdg.configFile."kitty/${themePath}".source = theme;

    programs.kitty.settings = {
      include = themePath;
    };
  };
}
