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

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

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

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

      # Enable the SDDM display manager
      displayManager.sddm = {
        enable = true;
        wayland.enable = true;
      };

      # Enable touchpad support (enabled default in most desktopManager).
      # libinput.enable = true;
    };
    # Enable the KDE Plasma Desktop Environment.
    services.desktopManager.plasma6.enable = true;
    environment.plasma6.excludePackages = with pkgs.kdePackages; [ elisa ];

    # 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;
    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 = "konsole";
      # Enable native wayland support for chromium and electron based applications
      NIXOS_OZONE_WL = "1";
    };
    environment.variables = {
      TERM = "konsole";
      # Enable native wayland support for chromium and electron based applications
      NIXOS_OZONE_WL = "1";
    };

    environment.systemPackages = with pkgs; [
      wl-clipboard
      wev # Clone of X11 xev for wayland

      # libsForQt5.polonium
    ];
    
  };
}
