"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.setBranchApiKey = exports.getBranchApiKey = exports.withBranchAndroid = void 0; const config_plugins_1 = require("@expo/config-plugins"); const { addMetaDataItemToMainApplication, getMainApplicationOrThrow, removeMetaDataItemFromMainApplication, } = config_plugins_1.AndroidConfig.Manifest; const META_BRANCH_KEY = 'io.branch.sdk.BranchKey'; const withBranchAndroid = (config) => { return (0, config_plugins_1.withAndroidManifest)(config, (config) => { config.modResults = setBranchApiKey(config, config.modResults); return config; }); }; exports.withBranchAndroid = withBranchAndroid; function getBranchApiKey(config) { var _a, _b, _c, _d; return (_d = (_c = (_b = (_a = config.android) === null || _a === void 0 ? void 0 : _a.config) === null || _b === void 0 ? void 0 : _b.branch) === null || _c === void 0 ? void 0 : _c.apiKey) !== null && _d !== void 0 ? _d : null; } exports.getBranchApiKey = getBranchApiKey; function setBranchApiKey(config, androidManifest) { const apiKey = getBranchApiKey(config); const mainApplication = getMainApplicationOrThrow(androidManifest); if (apiKey) { // If the item exists, add it back addMetaDataItemToMainApplication(mainApplication, META_BRANCH_KEY, apiKey); } else { // Remove any existing item removeMetaDataItemFromMainApplication(mainApplication, META_BRANCH_KEY); } return androidManifest; } exports.setBranchApiKey = setBranchApiKey;