{lib, config, pkgs, inputs, ...}:
let
  cfg = config.firefoxApp;
in
{
    # imports = [
    #     inputs.nur.hmModules.nur
    # ];

    options.firefoxApp = {
        enable = lib.mkEnableOption "enable firefox browser";
    };
    config = lib.mkIf cfg.enable {
        programs.firefox = {
            # Add pipewire support
            # package = (pkgs.wrapFirefox (pkgs.firefox-unwrapped.override { pipewireSupport = true;}) {});
            enable = true;
            profiles = {
                default = {
                    id = 0;
                    name = "default";
                    isDefault = true;
                    extensions.packages = with pkgs; [
                        nur.repos.rycee.firefox-addons.darkreader
                        nur.repos.rycee.firefox-addons.keepassxc-browser
                        nur.repos.crazazy.firefox-addons.ublock-origin
                        nur.repos.bandithedoge.firefoxAddons.stylus
                    ];
                    search = {
                        # Replace default firefox search engine config with this one
                        force = true;
                        default = "Startpage";
                        engines = {
                            "Startpage" = {
                                urls = [{
                                    template = "https://www.startpage.com/sp/search?query={searchTerms}";
                                }];
                            };
                            "Nix Packages" = {
                                urls = [{
                                    template = "https://search.nixos.org/packages";
                                    params = [
                                        { name = "type"; value = "packages"; }
                                        { name = "query"; value = "{searchTerms}"; }
                                    ];
                                }];
                                icon = "${pkgs.nixos-icons}/share/icons/hicolor/scalable/apps/nix-snowflake.svg";
                                definedAliases = [ "@np" ];
                            };
                            "MySQL Docs" = {
                                urls = [{
                                    template = "https://dev.mysql.com/doc/search";
                                    params = [
                                        { name = "d"; value = "371"; }
                                        { name = "p"; value = "1"; }
                                        { name = "q"; value = "{searchTerms}"; }
                                    ];
                                }];
                                definedAliases = [ "@mysql" ];
                            };
                        };
                    };
                    settings = {
                       "browser.startup.blankWindow" = true;
                       "browser.startup.homepage" = "https://www.startpage.com/do/mypage.pl?prfe=11898a1adf7b7dfb587580692f358773a11ca25e993b8e077476641cec033319e15f2449c345f5be919fd0a082015c3e4ed23143bd4337512466c04c2999831a54abca2eaeb42963c63ff064";
                       "browser.search.region" = "US";
                       "browser.search.isUS" = true;
                       "distribution.searchplugins.defaultLocale" = "en-US";
                       "general.useragent.locale" = "en-US";
                       "extensions.activeThemeID" = "{831b8843-7251-4306-9521-e688f18b4aeb}";
                       "privacy.trackingprotection.enable" = true;
                       "privacy.trackingprotection.emailtracking.enable" = true;
                       "privacy.trackingprotection.socialtracking.enable" = true;
                       "privacy.clearOnShutdown.cookies" = true;
                       "browser.safebrowsing.passwords.enabled" = false;
                       "browser.migrate.interactions.passwords" = false;
                       "pref.privacy.disable_button.view_passwords" = false;
                       "signon.rememberSignon" = false;
                       "extensions.formautofill.creditCards.enabled" = false;
                       "extensions.formautofill.addresses.enabled" = false;
                       "browser.toolbars.bookmarks.visibility" = "always";
                       # For applying userContent.css - not being used
                       # "toolkit.legacyUserProfileCustomizations.stylesheets" = true;
                       # "browser.newtabpage.pinned" = [{
                       #   title = "NixOS";
                       #   url = "https://nixos.org";
                       # }];
                   };
                };
            };
        };
    };
}
