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

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

  themeName =
    if (cfg.flavor == "main")
    then "rose_pine"
    else "rose_pine_${cfg.flavor}";
in {
  options.programs.helix.rose-pine = lib.rp.mkRosePineOpt {name = "helix";};

  config = lib.mkIf enable {
    programs.helix = {
      settings = {
        theme = themeName;
        editor.color-modes = lib.mkDefault true;
      };

      themes."${themeName}" = lib.importTOML "${sources.helix}/${themeName}.toml";
    };
  };
}
