{
  config,
  lib,
  ...
}: let
  inherit (config.rose-pine) sources;
  cfg = config.programs.fish.rose-pine;
  enable = cfg.enable && config.programs.fish.enable;

  themeName =
    if (cfg.flavor == "main")
    then "Rosé Pine"
    else "Rosé Pine ${lib.rp.mkUpper cfg.flavor}";
  themePath = "/themes/${themeName}.theme";
in {
  options.programs.fish.rose-pine = lib.rp.mkRosePineOpt {name = "fish";};

  config = lib.mkIf enable {
    xdg.configFile."fish${themePath}".source = "${sources.fish}${themePath}";

    programs.fish.shellInit = ''
      fish_config theme choose "${themeName}"
    '';
  };
}
