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

with lib;
let
  cfg = config.my.programs.gnome;

  extensions = with pkgs.gnomeExtensions; [
    gsconnect
    vitals
    blur-my-shell
    pop-shell
  ];
in
{
  options.my.programs.gnome.enable = mkEnableOption "gnome";

  config = lib.mkIf cfg.enable {
    hardware = {
      opengl.enable = true;
      pulseaudio.enable = false;
    };
    services.xserver = {
      layout = "de";
      displayManager = {
        autoLogin = {
          enable = true;
          user = "moritz";
        };
        gdm.enable = true;
      };
      enable = true;
      desktopManager.gnome.enable = true;
    };
    environment.systemPackages = extensions;
    home-manager.users.moritz.dconf.settings = {
      "org/gnome/shell" = {
        disable-user-extensions = false;
        enabled-extensions = map (p: p.extensionUuid or p.uuid) extensions ++ [
          "launch-new-instance@gnome-shell-extensions.gcampax.github.com"
          "workspace-indicator@gnome-shell-extensions.gcampax.github.com"
        ];
      };
      "org/gnome/shell/extensions/pop-shell".tile-by-default = true;
      "org/gnome/desktop/interface".enable-hot-corners = false;
      "org/gnome/desktop/wm/preferences".focus-mode = "sloppy";
      "org.gnome.mutter".focus-change-on-pointer-rest = false;
      "org/gnome/desktop/wm/keybindings".close = [ "<Super>q" ];
      "org/gnome/desktop/wm/keybindings".minimize = [ ];
      "org/gnome/desktop/wm/keybindings".move-to-monitor-down = [ "<Shift><Super>j" ];
      "org/gnome/desktop/wm/keybindings".move-to-monitor-left = [ "<Shift><Super>h" ];
      "org/gnome/desktop/wm/keybindings".move-to-monitor-right = [ "<Shift><Super>l" ];
      "org/gnome/desktop/wm/keybindings".move-to-monitor-up = [ "<Shift><Super>k" ];
      "org/gnome/desktop/wm/keybindings".move-to-workspace-1 = [ "<Shift><Super>1" ];
      "org/gnome/desktop/wm/keybindings".move-to-workspace-2 = [ "<Shift><Super>2" ];
      "org/gnome/desktop/wm/keybindings".move-to-workspace-3 = [ "<Shift><Super>3" ];
      "org/gnome/desktop/wm/keybindings".move-to-workspace-4 = [ "<Shift><Super>4" ];
      "org/gnome/desktop/wm/keybindings".switch-to-workspace-1 = [ "<Super>1" ];
      "org/gnome/desktop/wm/keybindings".switch-to-workspace-2 = [ "<Super>2" ];
      "org/gnome/desktop/wm/keybindings".switch-to-workspace-3 = [ "<Super>3" ];
      "org/gnome/desktop/wm/keybindings".switch-to-workspace-4 = [ "<Super>4" ];
      "org/gnome/mutter".dynamic-workspaces = false;
      "org/gnome/mutter/wayland/keybindings".restore-shortcuts = [ ];
      "org/gnome/settings-daemon/plugins/media-keys".screensaver = [ "<Super>Escape" ];
      "org/gnome/shell".favorite-apps = [ ];
      "org/gnome/desktop/wm/preferences".num-workspaces = 4;
    };
  };
}
