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

{
  options.modules.hyprland = {
    enable = lib.mkEnableOption "Enable Hyprland";
    additionalPackages = lib.mkOption {
      type = lib.types.listOf lib.types.package;
      description = "Additional Hyprland-related packages to install";
      default = [ ];
    };

    additionalConfig = lib.mkOption {
      type = lib.types.attrs;
      description = "Additional options for Hyprland config";
      default = [ ];
    };

    plugins = lib.mkOption {
      type = lib.types.listOf lib.types.package;
      description = "Additional plugins for Hyprland";
      default = [ ];
    };
  };

  config = lib.mkIf config.modules.hyprland.enable {
    home.packages =
      with pkgs;
      [
        hyprlock
        hypridle
        wl-clipboard
        cliphist
      ]
      ++ config.modules.hyprland.additionalPackages;

    wayland.windowManager.hyprland = {
      enable = true;
      xwayland.enable = true;
      plugins = config.modules.hyprland.plugins;
      settings = config.modules.hyprland.additionalConfig;
    };

    systemd.user.services.authentication-agent = {
      Unit = {
        Description = "GNOME Authentication Agent";
        After = [ "graphical-session.target" ];
        Wants = [ "graphical-session.target" ];
      };

      Install = {
        WantedBy = [ "graphical-session.target" ];
      };

      Service = {
        Type = "simple";
        ExecStart = "${pkgs.hyprpolkitagent}/libexec/hyprpolkitagent";
        Restart = "on-failure";
        RestartSec = 1;
        TimeoutStopSec = 10;
      };
    };
  };
}
