/** @format */

const fs = require("fs");
const path = require("path");

function readEnvValue(name) {
  const directValue = process.env[name]?.trim();

  if (directValue) {
    return directValue;
  }

  try {
    const envPath = path.join(__dirname, ".env");
    const envContents = fs.readFileSync(envPath, "utf8");
    const line = envContents
      .split(/\r?\n/)
      .find((entry) => entry.startsWith(`${name}=`));

    if (!line) {
      return "";
    }

    return line
      .slice(name.length + 1)
      .split("#")[0]
      .trim()
      .replace(/^"(.*)"$/, "$1")
      .replace(/^'(.*)'$/, "$1");
  } catch {
    return "";
  }
}

const facebookAppId = readEnvValue("EXPO_PUBLIC_FACEBOOK_APP_ID");

module.exports = {
  dependencies: {
    ...(facebookAppId
      ? {}
      : {
          "react-native-fbsdk-next": {
            platforms: {
              android: null,
              ios: null,
            },
          },
        }),
  },
};
