# Desktop environment aggregator — only loaded when context=desktop.
# Includes window manager, applications, theming, and desktop session config.
{
  m3taHomeInputs,
  pkgs,
  ...
}: {
  imports = [
    ./wm
    ./apps
    ./theme
  ];

  xdg = {
    enable = true;
    configFile."mimeapps.list".force = true;
    mimeApps = {
      enable = true;
      associations.added = {
        "application/zip" = ["org.gnome.FileRoller.desktop"];
        "application/csv" = ["calc.desktop"];
        "application/pdf" = ["okularApplication_pdf.desktop"];
      };
      defaultApplications = {
        "application/zip" = ["org.gnome.FileRoller.desktop"];
        "application/csv" = ["calc.desktop"];
        "application/pdf" = ["okularApplication_pdf.desktop"];
        "application/md" = ["nvim.desktop"];
        "application/text" = ["nvim.desktop"];
        "x-scheme-handler/http" = ["io.github.zen_browser.zen"];
        "x-scheme-handler/https" = ["io.github.zen_browser.zen"];
      };
    };
    userDirs = {
      enable = true;
      createDirectories = true;
      setSessionVariables = true;
    };
  };

  home = {
    sessionVariables = {
      WEBKIT_DISABLE_COMPOSITING_MODE = "1";
      NIXOS_OZONE_WL = "1";
      TERMINAL = "ghostty";
      QT_QPA_PLATFORM = "wayland";
      XDG_CURRENT_DESKTOP = "Hyprland";
      XDG_SESSION_TYPE = "wayland";
      XDG_SESSION_DESKTOP = "Hyprland";
    };

    sessionPath = [
      "\${XDG_BIN_HOME}"
      "\${HOME}/.cargo/bin"
      "$HOME/.npm-global/bin"
      "$HOME/.cache/.bun/bin"
    ];

    pointerCursor = {
      gtk.enable = true;
      package = pkgs.bibata-cursors;
      name = "Bibata-Modern-Ice";
      size = 20;
    };

    packages = with pkgs; [
      appimage-run
      bemoji
      google-chrome
      dconf
      (element-desktop.override {
        commandLineArgs = "--password-store=gnome-libsecret";
      })
      m3taHomeInputs.hermes-agent.packages.${pkgs.system}.desktop
      launch-webapp
      file-roller
      gsettings-desktop-schemas
      seahorse
      sushi
      ksnip
      nwg-look
      qt6Packages.qt6ct
      rose-pine-hyprcursor
      remmina
      slack
      vivaldi
      vivaldi-ffmpeg-codecs
      vibetyper
    ];
  };

  fonts.fontconfig.enable = true;

  programs.ghostty = {
    enable = true;
    enableFishIntegration = true;
    enableBashIntegration = true;
    settings = {
      font-family = "Fira Code";
      copy-on-select = "clipboard";
      theme = "dankcolors";
      # foreground = "#${config.colorScheme.palette.base05}";
      # background = "#${config.colorScheme.palette.base00}";
      # selection-foreground = "#${config.colorScheme.palette.base07}";
      # selection-background = "#${config.colorScheme.palette.base02}";
      # cursor-color = "#${config.colorScheme.palette.base05}";
      # palette = [
      #   "0=#${config.colorScheme.palette.base01}"
      #   "1=#${config.colorScheme.palette.base08}"
      #   "2=#${config.colorScheme.palette.base0B}"
      #   "3=#${config.colorScheme.palette.base0A}"
      #   "4=#${config.colorScheme.palette.base0D}"
      #   "5=#${config.colorScheme.palette.base0E}"
      #   "6=#${config.colorScheme.palette.base0C}"
      #   "7=#${config.colorScheme.palette.base05}"
      #   "8=#${config.colorScheme.palette.base03}"
      #   "9=#${config.colorScheme.palette.base08}"
      #   "10=#${config.colorScheme.palette.base0B}"
      #   "11=#${config.colorScheme.palette.base0A}"
      #   "12=#${config.colorScheme.palette.base0D}"
      #   "13=#${config.colorScheme.palette.base0E}"
      #   "14=#${config.colorScheme.palette.base0C}"
      #   "15=#${config.colorScheme.palette.base07}"
      # ];
    };
  };
}
