require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'

platform :ios, "11.0"

def react_native_post_install(installer)
	installer.pods_project.targets.each do |target|
  		target.build_configurations.each do |config|
			if Gem::Version.new('9.0') > Gem::Version.new(config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'])
				config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = "11.0"
			end
			config.build_settings['BUILD_LIBRARY_FOR_DISTRIBUTION'] = 'YES'
  		end
 	end

	projects = installer.aggregate_targets
	  .map{ |t| t.user_project }
	  .uniq{ |p| p.path }
	  .push(installer.pods_project)

	arm_value = `/usr/sbin/sysctl -n hw.optional.arm64 2>&1`.to_i

	projects.each do |project|
	  project.build_configurations.each do |config|
		if arm_value == 1 then
		  config.build_settings.delete("EXCLUDED_ARCHS[sdk=iphonesimulator*]")
		else
		  config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64"
		end
	  end

	  project.save()
	end
  end

target 'MetaMask' do
  config = use_native_modules!
  # Comment the next line if you don't want to use dynamic frameworks
  # use_frameworks!

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

  # Pods for MetaMask
  pod 'React-RCTPushNotification', :path => '../node_modules/react-native/Libraries/PushNotificationIOS'

  # you should disable the next line.
  use_flipper!({"Flipper" => "0.93.0", "Flipper-DoubleConversion" => "1.1.7"})
  post_install do |installer|
	flipper_post_install(installer)
    react_native_post_install(installer)
    __apply_Xcode_12_5_M1_post_install_workaround(installer)
  end
end
