{
  pkgs,
  outputs,
  system,
  lib,
  config,
  ...
}: let
  cfg = config.youthlic.programs.firefox;
in {
  options = {
    youthlic.programs.firefox = {
      enable = lib.mkEnableOption "firefox";
    };
  };
  config = lib.mkIf cfg.enable {
    stylix.targets.firefox.profileNames = [
      "default"
    ];
    programs.firefox = {
      enable = true;
      betterfox = {
        enable = true;
      };
      languagePacks = [
        "zh-CN"
        "en-US"
      ];
      profiles.default = {
        betterfox = {
          enable = true;
          enableAllSections = true;
        };
        name = "default";
        isDefault = true;
        extensions.packages = with outputs.packages."${system}"; [
          immersive-translate
          tridactyl
        ];
        search = {
          force = true;
          default = "ddg";
          engines = {
            "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"];
            };
            "Nix Options" = {
              urls = [
                {
                  template = "https://search.nixos.org/options";
                  params = [
                    {
                      name = "channel";
                      value = "unstable";
                    }
                    {
                      name = "query";
                      value = "{searchTerms}";
                    }
                  ];
                }
              ];
              definedAliases = ["@no"];
            };
            "Home Manager Options" = {
              urls = [
                {
                  template = "https://home-manager-options.extranix.com";
                  params = [
                    {
                      name = "query";
                      value = "{searchTerms}";
                    }
                    {
                      name = "release";
                      value = "master";
                    }
                  ];
                }
              ];
              definedAliases = ["hm"];
            };
            "NUR Packages" = {
              urls = [
                {
                  template = "https://nur.nix-community.org/";
                }
              ];
              definedAliases = ["nu"];
            };
            "Nix Flakes" = {
              urls = [
                {
                  template = "https://search.nixos.org/flakes";
                  params = [
                    {
                      name = "channel";
                      value = "unstable";
                    }
                    {
                      name = "query";
                      value = "{searchTerms}";
                    }
                  ];
                }
              ];
              definedAliases = ["nf"];
            };
            "NixOS Wiki" = {
              urls = [
                {
                  template = "https://nixos.wiki/index.php";
                  params = [
                    {
                      name = "search";
                      value = "{searchTerms}";
                    }
                  ];
                }
              ];
              definedAliases = ["nw"];
            };
            "bing".metaData.hidden = true;
            "google".metaData.alias = "@g"; # builtin engines only support specifying one additional alias
          };
        };
      };
    };
  };
}
