platform :ios, '13.0'

# Disable expo-updates auto create manifest in podspec script_phase
$expo_updates_create_manifest = false

# Require autolinking script
require File.join(File.dirname(`node --print "require.resolve('expo/package.json')"`), "scripts/autolinking")

target 'ExpoKitApp' do
  pod 'ExpoKit',
    :path => "../../../ios",
    :subspecs => [
      "Core"
    ],
    :inhibit_warnings => true

  # Install expo modules
  use_expo_modules!(
    searchPaths: ['../../../packages'],
    exclude: [
      'expo-bluetooth',
      'expo-in-app-purchases',
      'expo-payments-stripe',
      'expo-module-template',
      'expo-module-template-local',
      'expo-image',
      'expo-dev-menu',
      'expo-dev-menu-interface',
      'expo-dev-launcher',
      'expo-dev-client'
    ],
  )

  pod 'Amplitude', :modular_headers => true
  pod 'CocoaLumberjack', :modular_headers => true
  pod 'Google-Maps-iOS-Utils', :modular_headers => true
  pod 'JKBigInteger', :modular_headers => true, :podspec => '../../../ios/vendored/common/JKBigInteger.podspec.json'
  pod 'MBProgressHUD', :modular_headers => true

  # Install React Native and its dependencies
  require_relative '../node_modules/react-native/scripts/react_native_pods'
  use_react_native!(production: true)

  # Install vendored pods.
  require_relative '../../../ios/podfile_helpers.rb'
  excluded_pods = ['stripe-react-native']
  use_pods!('../../../ios/vendored/unversioned/**/*.podspec.json', nil, excluded_pods)

  post_install do |installer|
    installer.pods_project.main_group.tab_width = '2';
    installer.pods_project.main_group.indent_width = '2';

    # Workaround build error for Folly
    __apply_Xcode_12_5_M1_post_install_workaround(installer) if installer.pods_project

    installer.target_installation_results.pod_target_installation_results
      .each do |pod_name, target_installation_result|

      if pod_name == 'ExpoKit'
        target_installation_result.native_target.build_configurations.each do |config|
          config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)']
          config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] << 'EX_DETACHED=1'
          
          # Enable Google Maps support
          config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] << 'HAVE_GOOGLE_MAPS=1'
          config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] << 'HAVE_GOOGLE_MAPS_UTILS=1'
          
        end
      end

      
      if pod_name == 'Branch'
        target_installation_result.native_target.build_configurations.each do |config|
          config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)']
          config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] << 'BRANCH_EXCLUDE_IDFA_CODE=1'
        end
      end



      target_installation_result.native_target.build_configurations.each do |config|
        config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '13.0'
      end


      # Can't specify this in the React podspec because we need to use those podspecs for detached
      # projects which don't reference ExponentCPP.
      if pod_name.start_with?('React')
        target_installation_result.native_target.build_configurations.each do |config|
          config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '13.0'
          config.build_settings['HEADER_SEARCH_PATHS'] ||= ['$(inherited)']
        end
      end

      # Build React Native with RCT_DEV enabled and RCT_ENABLE_INSPECTOR and
      # RCT_ENABLE_PACKAGER_CONNECTION disabled
      next unless pod_name.start_with?('React')
      target_installation_result.native_target.build_configurations.each do |config|
        config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)']
        config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] << 'RCT_DEV=1'
        config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] << 'RCT_ENABLE_INSPECTOR=0'
        config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] << 'ENABLE_PACKAGER_CONNECTION=0'
      end

    end
  end
end
