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

platform :ios, '14.7'

target 'BigBlueButtonMobileSdkBroadcastExample' do
  pod 'bigbluebutton-mobile-sdk-common', :path => '../../ios-common'
  pod 'bigbluebutton-mobile-sdk-broadcast-upload-extension', :path => '../../ios-broadcast-upload-extension'
end

target 'BigbluebuttonMobileSdkExample' do
  config = use_native_modules!

  use_react_native!(:path => config["reactNativePath"])

  pod 'bigbluebutton-mobile-sdk', :path => '../..'
  pod 'bigbluebutton-mobile-sdk-common', :path => '../../ios-common'

  # Enables Flipper.
  #
  # Note that if you have use_frameworks! enabled, Flipper will not work and
  # you should disable these next few lines.
  # use_flipper!({ 'Flipper' => '0.80.0' })
  #post_install do |installer|
  #  flipper_post_install(installer)
  #end
  
  post_install do |installer|
    fix_deployment_target(installer)
  end

  def fix_deployment_target(installer)
    return if !installer
    project = installer.pods_project
    project_deployment_target = project.build_configurations.first.build_settings['IPHONEOS_DEPLOYMENT_TARGET']

    puts "Make sure all pods deployment target is #{project_deployment_target.green}"
    project.targets.each do |target|
      puts "  #{target.name}".blue
      target.build_configurations.each do |config|
        config.build_settings['SWIFT_VERSION'] = '5.5.2'
        
        old_target = config.build_settings['IPHONEOS_DEPLOYMENT_TARGET']
        new_target = project_deployment_target
        next if old_target == new_target
        puts "    #{config.name}: #{old_target.yellow} -> #{new_target.green}"
        config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = new_target
      end
    end
  end

end
