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

let
  inherit (lib) mkOption mkIf types;
  cfg = config.deWm;
in
{
  options.deWm = {
    cinnamon.enable = mkOption {
      default = true; ## at least one of them has to be enabled
      type = types.bool;
    };
    xfce.enable = mkOption {
      default = true;
      type = types.bool;
    };
    hyprland.enable = mkOption {
      default = false;
      type = types.bool;
    };
  };

  config = {
    services = {
      xserver = {
        desktopManager.cinnamon.enable = cfg.cinnamon.enable;
        desktopManager.xfce.enable = cfg.xfce.enable;
      };
    };

    programs.hyprland = {
      enable = cfg.hyprland.enable;
      xwayland.enable = cfg.hyprland.enable;
    };

    environment.systemPackages = with pkgs; [
      xorg.xev xorg.xinit xtitle xwinmosaic xdo xdotool xsel xclip
    ] ++ lib.optionals cfg.xfce.enable [
      xfce.gigolo xfce.xfce4-dict xfce.xfce4-panel xfce.xfce4-pulseaudio-plugin
      xfce.xfce4-whiskermenu-plugin xfce.mousepad xfce.xfwm4-themes xfce.xfce4-netload-plugin
    ] ++ lib.optionals cfg.hyprland.enable [
    ];

    environment.xfce.excludePackages = with pkgs.xfce; mkIf cfg.xfce.enable [
      xfce4-appfinder xfce4-taskmanager xfce4-terminal
    ];
  };
}
