{ config, pkgs, ... }:

let
  extensions = with pkgs.gnomeExtensions; [
        # appindicator
        blur-my-shell
        caffeine
        dash-to-panel
        gsconnect
        just-perfection
        vitals
        weather-oclock
        background-logo
    ];
in
{
  imports = [
    ./dconf.nix
  ];

  # Directories
  xdg = {
    userDirs = {
      enable = true;
      createDirectories = true;
      desktop = "${config.home.homeDirectory}/Bureau";
      documents = "${config.home.homeDirectory}/Documents";
      download = "${config.home.homeDirectory}/Téléchargements";
      pictures = "${config.home.homeDirectory}/Images";
      music = "${config.home.homeDirectory}/Musique";
      videos = "${config.home.homeDirectory}/Vidéos";
      templates = "${config.home.homeDirectory}/Modèles";
      publicShare = "${config.home.homeDirectory}/Public";
    };
    configHome = "${config.home.homeDirectory}/.config";
    cacheHome = "${config.home.homeDirectory}/.cache";
    dataHome = "${config.home.homeDirectory}/.local/share";
    stateHome = "${config.home.homeDirectory}/.local/state";
  };

  # Default apps
  xdg.mimeApps = {
    enable = true;
    associations.added = {
      "x-scheme-handler/sms" = "org.gnome.Shell.Extensions.GSConnect.desktop;";
      "x-scheme-handler/tel" = "org.gnome.Shell.Extensions.GSConnect.desktop;";
    };
    defaultApplications = {
      "text/plain" = "org.gnome.TextEditor.desktop";
      "text/markdown" = "org.gnome.TextEditor.desktop";
      "text/json" = "org.gnome.TextEditor.desktop";
      "text/html" = "zen-beta.desktop";
      "text/xml" = "org.gnome.TextEditor.desktop";
      "image/avif" = "org.gnome.Loupe.desktop";
      "image/png" = "org.gnome.Loupe.desktop";
      "image/jpeg" = "org.gnome.Loupe.desktop";
      "image/svg+xml" = "org.gnome.Loupe.desktop";
      "image/gif" = "org.gnome.Loupe.desktop";
      "image/webp" = "org.gnome.Loupe.desktop";
      "audio/mpeg" = "mpv.desktop";
      "audio/aac" = "mpv.desktop";
      "audio/webm" = "mpv.desktop";
      "audio/ogg" = "mpv.desktop";
      "video/x-matroska" = "mpv.desktop";
      "video/mp4" = "mpv.desktop";
      "video/webm" = "mpv.desktop";
      "video/ogg" = "mpv.desktop";
      "application/pdf" = "org.gnome.Papers.desktop";
      "application/msword" = "onlyoffice-desktopeditors.desktop";
      "application/vnd.ms-powerpoint" = "onlyoffice-desktopeditors.desktop";
      "application/vnd.ms-excel" = "onlyoffice-desktopeditors.desktop";
      "application/vnd.openxmlformats-officedocument.wordprocessingml.document" = "onlyoffice-desktopeditors.desktop";
      "application/vnd.openxmlformats-officedocument.presentationml.presentation" = "onlyoffice-desktopeditors.desktop";
      "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" = "onlyoffice-desktopeditors.desktop";
      "application/vnd.oasis.opendocument.text" = "onlyoffice-desktopeditors.desktop";
      "application/vnd.oasis.opendocument.presentation" = "onlyoffice-desktopeditors.desktop";
      "application/vnd.oasis.opendocument.spreadsheet" = "onlyoffice-desktopeditors.desktop";
      "application/epub+zip" = "com.github.johnfactotum.Foliate.desktop";
      "application/ogg" = "mpv.desktop";
      "application/xml" = "org.gnome.TextEditor.desktop";
      "application/xhtml+xml" = "zen-beta.desktop";
      "application/x-extension-htm" = "zen-beta.desktop";
      "application/x-extension-html" = "zen-beta.desktop";
      "application/x-extension-shtml" = "zen-beta.desktop";
      "application/x-extension-xhtml" = "zen-beta.desktop";
      "application/x-extension-xht" = "zen-beta.desktop";
      "application/x-bittorrent" = "de.haeckerfelix.Fragments.desktop";
      "message/rfc822" = "thunderbird.desktop";
      "x-scheme-handler/mailto" = "thunderbird.desktop";
      "x-scheme-handler/mid" = "thunderbird.desktop";
      "x-scheme-handler/discord" = "vesktop.desktop";
      "x-scheme-handler/http" = "zen-beta.desktop";
      "x-scheme-handler/https" = "zen-beta.desktop";
      "x-scheme-handler/chrome" = "zen-beta.desktop";
    };
  };

  # Desktop
  programs.gnome-shell = {
    enable = true;
    extensions = map (x: { id = x.extensionUuid; package = x; }) extensions;
  };

  # Background
  xdg.configFile."background".source = ./background;

  # MPD
  services.mpd = {
    enable = true;
    musicDirectory = "${config.xdg.userDirs.music}/MPD";
    extraConfig =
      ''
        audio_output {
          type            "pipewire"
          name            "PipeWire Sound Server"
        }

        audio_output {
          type            "fifo"
          name            "mpd"
          path            "~/.local/share/mpd/.mpd_fifo"
          format          "44100:16:2"
        }
      '';
  };
}
