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

let

  extraPrefs = ''//

// Automatically click cookiebanners although uBlock Origin might block them
lockPref("cookiebanners.bannerClicking.enabled", true);
lockPref("cookiebanners.service.mode", 2);
lockPref("cookiebanners.service.mode.privateBrowsing", 2);

// DNT although PrivacyBadger from policy handles this
lockPref("privacy.donottrackheader.enabled", true);
lockPref("privacy.donottrackheader.value", 1);

// New sidebar
lockPref("sidebar.revamp", true);
lockPref("sidebar.verticalTabs", true);
lockPref("sidebar.visibility", "always-show");
lockPref("sidebar.main.tools", "history,bookmarks");

//'';

  userChrome = ''
/* sidebar hack to flip contents the way i want them (arrows on the left) */
#nav-bar-customization-target {
  flex-direction: row-reverse;
}

/* remove broken padding from sidebar hack */
#unified-extensions-button {
  padding-left: 0 !important;
}

/* remove padding beside search bar */
toolbarspring {
  display: none !important;
}

/* remove overflow menu and everything in it */
#nav-bar-overflow-button,
#firefox-view-button,
#alltabs-button {
  visibility: collapse;
}
'';

  my-firefox = (pkgs.firefox.override {
    extraPrefs = extraPrefs;
  });

in
{
  config = lib.mkIf config.desktop.enable {

    home-manager.users.${config.user} = {
      programs.firefox = {

        enable = true;
        package = my-firefox;

        # import configuration
        policies = import ./policies.nix;

        # create profile for me :3
        profiles.${config.user} = {
          search = {
            force = true;
            default = "DuckDuckGo";
            engines = {
              "Google".metaData.hidden = true;
              "Bing".metaData.hidden = true;
              "Amazon.com".metaData.hidden = true;
              "eBay".metaData.hidden = true;
              "Twitter".metaData.hidden = true;
            };
          };

          # firefox doesnt make styling the toolbar easy using about:config
          # since its just a massive json string. so i did it here in css.
          userChrome = userChrome;
        }; # end profile

      };
    };

  };
}