1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.setBranchApiKey = exports.getBranchApiKey = exports.withBranchAndroid = void 0;
4const config_plugins_1 = require("@expo/config-plugins");
5const { addMetaDataItemToMainApplication, getMainApplicationOrThrow, removeMetaDataItemFromMainApplication, } = config_plugins_1.AndroidConfig.Manifest;
6const META_BRANCH_KEY = 'io.branch.sdk.BranchKey';
7const withBranchAndroid = (config) => {
8    return (0, config_plugins_1.withAndroidManifest)(config, (config) => {
9        config.modResults = setBranchApiKey(config, config.modResults);
10        return config;
11    });
12};
13exports.withBranchAndroid = withBranchAndroid;
14function getBranchApiKey(config) {
15    var _a, _b, _c, _d;
16    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;
17}
18exports.getBranchApiKey = getBranchApiKey;
19function setBranchApiKey(config, androidManifest) {
20    const apiKey = getBranchApiKey(config);
21    const mainApplication = getMainApplicationOrThrow(androidManifest);
22    if (apiKey) {
23        // If the item exists, add it back
24        addMetaDataItemToMainApplication(mainApplication, META_BRANCH_KEY, apiKey);
25    }
26    else {
27        // Remove any existing item
28        removeMetaDataItemFromMainApplication(mainApplication, META_BRANCH_KEY);
29    }
30    return androidManifest;
31}
32exports.setBranchApiKey = setBranchApiKey;
33