{
  marleylib,
  config,
  lib,
  inputs,
  ...
}: let
  inherit (marleylib.module) enabled disabled;

  cfg = config.marleyos.programs.discord;
in {
  options.marleyos.programs.discord.enable = lib.mkEnableOption "discord";

  imports = [
    inputs.nixcord.homeModules.nixcord
  ];

  config = lib.mkIf cfg.enable {
    programs.nixcord = {
      enable = true;
      discord = disabled;
      vesktop = enabled;

      config = {
        # Stylix does set this but it seems to be overwritten somehow.
        enabledThemes = lib.mkIf config.stylix.enable ["stylix.theme.css"];

        plugins = {
          accountPanelServerProfile = enabled;
          alwaysAnimate = enabled;
          alwaysExpandRoles = enabled;
          alwaysTrust = enabled;

          betterFolders = {
            enable = true;
            closeAllFolders = true;
            closeAllHomeButton = true;
            closeOthers = true;
            forceOpen = true;
          };

          betterGifPicker = enabled;
          clearURLs = enabled;
          copyFileContents = enabled;

          fakeNitro = {
            enable = true;
            transformCompoundSentence = true;
          };

          fakeProfileThemes = enabled;
          favoriteEmojiFirst = enabled;
          favoriteGifSearch = enabled;
          fixImagesQuality = enabled;
          fixSpotifyEmbeds = enabled;
          fixYoutubeEmbeds = enabled;
          forceOwnerCrown = enabled;
          friendsSince = enabled;
          greetStickerPicker = enabled;
          imageZoom = enabled;
          implicitRelationships = enabled;
          memberCount = enabled;
          messageLinkEmbeds = enabled;
          moreKaomoji = enabled;
          mutualGroupDMs = enabled;

          newGuildSettings = {
            enable = true;
            messages = "only@Mentions";
            everyone = false;
            role = false;
            showAllChannels = false;
          };

          noUnblockToJump = enabled;
          normalizeMessageLinks = enabled;
          nsfwGateBypass = enabled;

          onePingPerDM = {
            enable = true;
            allowMentions = true;
            allowEveryone = true;
          };

          openInApp = {
            enable = true;
            spotify = true;
            steam = true;
            epic = true;
            tidal = true;
            itunes = true;
          };

          readAllNotificationsButton = enabled;

          relationshipNotifier = {
            enable = true;
            notices = true;
          };

          replaceGoogleSearch = {
            enable = true;
            customEngineName = "Kagi";
            customEngineURL = "https://kagi.com/search?q=";
          };

          replyTimestamp = enabled;
          reverseImageSearch = enabled;
          roleColorEverywhere = enabled;
          serverInfo = enabled;

          shikiCodeblocks = with config.lib.stylix.colors; let
            scheme = lib.head (lib.splitString "-" scheme-slug);
            flavor = slug: lib.last (lib.splitString "-" slug);

            themes = {
              rose = "https://raw.githubusercontent.com/rose-pine/vscode/refs/heads/main/themes/${scheme-slug}-color-theme.json";
              catppuccin = "https://www.unpkg.com/@catppuccin/vscode@3.16.1/themes/${flavor scheme-slug}.json";
            };

            defaultTheme = "https://raw.githubusercontent.com/shikijs/shiki/0b28ad8ccfbf2615f2d9d38ea8255416b8ac3043/packages/shiki/themes/dark-plus.json";

            theme = themes."${scheme}" or defaultTheme;
          in {
            enable = true;
            inherit theme;
            useDevIcon = "COLOR";
          };

          showMeYourName = {
            enable = true;
            mode = "nick-user";
          };

          sortFriendRequests = {
            enable = true;
            showDates = true;
          };

          translate = enabled;
          userMessagesPronouns = enabled;
          USRBG = enabled;
          voiceChatDoubleClick = enabled;
          whoReacted = enabled;
          youtubeAdblock = enabled;
          webKeybinds = enabled;
          webScreenShareFixes = enabled;
        };
      };
    };
  };
}
