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

  cfg = config.wayland.windowManager.hyprland.rose-pine;
  enable = cfg.enable && config.wayland.windowManager.hyprland.enable;

  themeName =
    if (cfg.flavor == "main")
    then "rose-pine"
    else "rose-pine-${cfg.flavor}";
in {
  options.wayland.windowManager.hyprland.rose-pine =
    lib.rp.mkRosePineOpt {name = "hyprland";}
    // {
      accent = lib.rp.mkAccentOpt "hyprland";
    };

  config = lib.mkIf enable {
    wayland.windowManager.hyprland.settings = {
      source = [
        "${sources.hyprland}/${themeName}.conf"
        # Define accent in file to ensure it appears before user vars
        (builtins.toFile "hyprland-${cfg.accent}-accent.conf" ''
          $accent = ''$${cfg.accent}
        '')
      ];
    };
  };
}
