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

with lib;

let
  cfg = config.roles.desktop;
in
{
  config = mkIf (cfg.enable && cfg.x11) {
    services.xserver = {
      enable = true;

      windowManager.i3 = {
        enable = true;
        extraPackages = with pkgs; [
          dmenu
          i3status
          i3lock
          polkit_gnome                    # GNOME polkit authentication agent (more stable with i3)
          picom                           # Compositor for smooth rendering (important for Nvidia)
          networkmanagerapplet            # NetworkManager system tray applet
          ddcutil                         # DDC/CI monitor control for brightness
        ];
      };
    };

    # Enable DDC/CI support for monitor brightness control
    boot.kernelModules = [ "i2c-dev" ];

    # Add ddcutil udev rules and user permissions
    hardware.i2c.enable = true;

    # Install ddcutil system-wide
    environment.systemPackages = with pkgs; [
      ddcutil
    ];
  };
}
