# Resolve react_native_pods.rb with node to allow for hoisting
require Pod::Executable.execute_command('node', ['-p',
  'require.resolve(
    "react-native/scripts/react_native_pods.rb",
    {paths: [process.argv[1]]},
  )', __dir__]).strip

platform :ios, '13.4'
prepare_react_native_project!

# If you are using a `react-native-flipper` your iOS build will fail when `NO_FLIPPER=1` is set.
# because `react-native-flipper` depends on (FlipperKit,...) that will be excluded
#
# To fix this you can also exclude `react-native-flipper` using a `react-native.config.js`
# ```js
# module.exports = {
#   dependencies: {
#     ...(process.env.NO_FLIPPER ? { 'react-native-flipper': { platforms: { ios: null } } } : {}),
# ```

flipper_config = ENV['NO_FLIPPER'] == "1" ? FlipperConfiguration.disabled : FlipperConfiguration.enabled

# Enable concurrent installation and disable input/output paths for CI consistency
install! 'cocoapods',
         warn_for_multiple_pod_sources: false,
         deterministic_uuids: false,
         disable_input_output_paths: true

target 'OnfidoSdk' do
  pod 'Onfido', '~> 33.0.0'

  config = use_native_modules!
  use_react_native!(
    :path => config[:reactNativePath],
    # to enable hermes on iOS, change `false` to `true` and then install pods
    :hermes_enabled => false
    #:hermes_enabled => flags[:hermes_enabled],
    #:fabric_enabled => flags[:fabric_enabled],
  )

  target 'OnfidoSdkTests' do
    # inherit! :search_paths
    # Pods for testing
  end

  # unary_function and binary_function are no longer provided in C++17 and newer standard modes as part of Xcode 15.
  # They can be re-enabled with setting _LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION
  # Ref: https://developer.apple.com/documentation/xcode-release-notes/xcode-15-release-notes#Deprecations
  # Solution: https://github.com/facebook/react-native/issues/37748#issuecomment-1580589448

  # Workarounds and settings for Xcode 15 and Folly coroutines
  post_install do |installer|
    installer.pods_project.targets.each do |target|
      target.build_configurations.each do |config|
        config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)', '_LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION']
      end
    end

    # Workaround for `FOLLY_HAS_COROUTINES` set to `1` on CI causing attempt to import non-existent `Coroutine.h`
    system("chmod -R u+w Pods/RCT-Folly")
    Dir.glob("Pods/RCT-Folly/folly/Portability.h").each do |file|
      text = File.read(file)
      new_contents = text.gsub('#define FOLLY_HAS_COROUTINES 1', '#define FOLLY_HAS_COROUTINES 0')
      File.open(file, "w") { |file| file.puts new_contents }
    end
  end
end
