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

let
  cfg = config.cspark-desktop-gnome;
in
{
  options.cspark-desktop-gnome = {
    enable 
      = lib.mkEnableOption "Enable GNOME Plasma Desktop Setup";
  };

  config = lib.mkIf cfg.enable {
    services.xserver = {
      # Enable the X11 windowing system.
      enable = true;

      # Remove/disable xterm, we are using Foot.
      desktopManager.xterm.enable = false;
      excludePackages = with pkgs; [ xterm ];

      # Enable the GDM display manager
      displayManager.gdm = {
        enable = true;
        wayland = true;
      };

    # Enable the GNOME Desktop Environment.
      desktopManager.gnome.enable = true;

      # Enable touchpad support (enabled default in most desktopManager).
      # libinput.enable = true;
    };

    # Exclude default GNOME applications
    environment.gnome.excludePackages = (with pkgs; [
      gnome-photos
      gnome-tour
      gedit # text editor
      gnome-console
      cheese # webcam tool
      gnome-music
      gnome-terminal
      gnome-calendar
      gnome-weather
      gnome-contacts
      gnome-calculator
      gnome-maps
      simple-scan
      epiphany # web browser
      geary # email reader
      evince # document viewer
      gnome-characters
      totem # video player
      tali # poker game
      iagno # go game
      hitori # sudoku game
      atomix # puzzle game
    ]) ++ (with pkgs.gnome; [
    ]);

    services.udev.packages = with pkgs; [ gnome-settings-daemon ];
    # services.dbus.packages = with pkgs; [ gnome2.GConf ];

    # GTK themes are not applied in Wayland applications / Window Decorations missing / Cursor looks different
    programs.dconf.enable = true;

    # Enable CUPS to print documents.
    services.printing.enable = true;

    # Enable sound with pipewire.
    # sound.enable = true; # Apparently now deprecated
    hardware.pulseaudio.enable = false;
    security.rtkit.enable = true;
    services.pipewire = {
      enable = true;
      alsa.enable = true;
      alsa.support32Bit = true;
      pulse.enable = true;
      # If you want to use JACK applications, uncomment this
      jack.enable = true;

      # use the example session manager (no others are packaged yet so this is enabled by default,
      # no need to redefine it in your config for now)
      #media-session.enable = true;
    };

    # Set konsole to be default terminal
    environment.sessionVariables = {
      TERM = "foot";
      QT_QPA_PLATFORM = "wayland";
      QT_WAYLAND_DISABLE_WINDOWDECORATION = "1";
      SDL_VIDEODRIVER = "wayland,x11,windows";
      MOZ_ENABLE_WAYLAND = "1";
      # Enable native wayland support for chromium and electron based applications
      NIXOS_OZONE_WL = "1";
    };
    environment.variables = {
      TERM = "foot";
      QT_QPA_PLATFORM = "wayland";
      QT_WAYLAND_DISABLE_WINDOWDECORATION = "1";
      SDL_VIDEODRIVER = "wayland,x11,windows";
      MOZ_ENABLE_WAYLAND = "1";
      # Enable native wayland support for chromium and electron based applications
      NIXOS_OZONE_WL = "1";
    };

    environment.systemPackages = with pkgs; [
      # GNOME plugins
      gnomeExtensions.appindicator
      gnomeExtensions.paperwm
      gnomeExtensions.notification-timeout
      gnomeExtensions.blur-my-shell
      gnomeExtensions.gsconnect
      gnomeExtensions.wallpaper-slideshow
      
      gnome-tweaks
      foot # Terminal Emulator
      wl-clipboard
      wev # Clone of X11 xev for wayland
      wofi
      wofi-pass

    ];
    
  };
}
