# Handwritten!
{ config, lib, pkgs,  ... }:

let
  gnomeExtensions = builtins.attrValues { inherit (pkgs.gnomeExtensions)
    #big-avatar
    tailscale-qs
    bluetooth-quick-connect
    gtile
    just-perfection
    keep-awake
    middle-click-to-close-in-overview
    vertical-workspaces
    appindicator
    removable-drive-menu
    always-show-titles-in-overview
    vitals
    pip-on-top
    /* TODO:
    night-light-slider
    tray-icons-reloaded
    removable-drive-menu
    battery-indicator-upower
    workspace-indicator-2
    forge
    */
  ;};
in

{
  imports = [
    ../. # desktop
    ./dconf-gnome-bindings.nix
    ./dconf-gnome-behaviour.nix
    ./dconf-gnome-extensions.nix
    ./dconf-gnome-theme.nix
  ];

  # TODO: move or remove
  home.file.".local/opt/open-microsoft-url-files.py".source   = ../../../files/opt/open-microsoft-url-files.py;
  home.file.".local/opt/python-interactive-imports.py".source = ../../../files/opt/python-interactive-imports.py;
  home.file.".local/opt/sympy-interactive-imports.py".source  = ../../../files/opt/sympy-interactive-imports.py;

  programs.firefox.enableGnomeExtensions = true;

  # qt theme
  qt.enable = true;
  qt.platformTheme = lib.mkMerge [
    (lib.mkIf (lib.versionAtLeast config.home.version.release "24.05") { name = "advaita"; })
    (lib.mkIf (lib.versionOlder config.home.version.release "24.05") "gnome")
  ];
  # qt.style.name = "Colloid-dark";
  # qt.style.package = pkgs.colloid-kde;
  qt.style.name = "Vimix-dark-doder"; # TODO: build ruby variant
  qt.style.package = pkgs.vimix-gtk-themes;

  home.packages = [
    (pkgs.gnome-tweaks or pkgs.gnome.gnome-tweaks)
    pkgs.vimix-gtk-themes # shell theme
  ] ++ gnomeExtensions;

  dconf.settings = with lib.hm.gvariant; {
    # extensions:
    # kinda manual lol
    "org/gnome/shell" = {
      disable-user-extensions = false;
      enabled-extensions = lib.forEach gnomeExtensions (pkg: pkg.extensionUuid);
    };

    # notifications
    "org/gnome/desktop/notifications" = {
      # "show-banners" = false; # do not disturb mode
      show-in-lock-screen = false; # fucking matrix...
    };

    # wallpaper
    "org/gnome/desktop/background" = {
      color-shading-type = "solid";
      picture-options = "zoom";
      picture-uri = "file://${../../../files/wallpaper.jpg}";
      picture-uri-dark = "file://${../../../files/wallpaper.jpg}";
    };
    "org/gnome/desktop/screensaver" = {
      idle-activation-enabled = false;
      picture-uri = "file://${../../../files/screensaver.jpg}";
    };

    # theme
    "org/gnome/desktop/interface" = {
      color-scheme = "prefer-dark";
      enable-hot-corners = false;
      clock-show-weekday = true;
    };
    #"org/gnome/desktop/wm/preferences" = {
    #  button-layout = ":minimize,close";
    #};

    # behaviour
    "org/gnome/desktop/peripherals/touchpad" = {
      disable-while-typing = false;
      natural-scroll = false;
      two-finger-scrolling-enabled = true;
    };
    "org/gnome/nautilus/preferences" = {
      confirm-trash = true;
      executable-text-activation = "display";
      show-create-link = true;
      sort-directories-first = true;
      #recursive-search = "never";
      show-image-thumbnails = "always";
      show-directory-item-counts = "always";
    };
    "org/gnome/nautilus/list-view" = {
      use-tree-view = true;
    };
    "org/gtk/gtk4/settings/file-chooser" = {
      sort-directories-first = true;
    };
    "org/gtk/settings/file-chooser" = {
      sort-directories-first = true;
    };

    "org/gnome/settings-daemon/plugins/color" = {
      night-light-enabled = true;
      night-light-schedule-automatic = false;
      night-light-schedule-from = 23.5;
      night-light-schedule-to = 5.0;
      night-light-temperature = mkUint32 4150;
    };

    #dump "org/gnome/settings-daemon/plugins/power"

    #"org/gnome/desktop/session" = {
    #  idle-delay = mkUint32 (5 * 60);
    #};
    "org/gnome/settings-daemon/plugins/power" = {
      sleep-inactive-ac-type = "nothing";
      sleep-inactive-battery-type = "suspend";
    };

  };
}
