# Uncomment this line to define a global platform for your project
# Spécifier la version minimale d'iOS pour Stripe Tap to Pay
platform :ios, '15.4'

# Ignorer les avertissements des pods
install! 'cocoapods', :warn_for_unused_master_specs_repo => false

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

project 'Runner', {
  'Debug' => :debug,
  'Profile' => :release,
  'Release' => :release,
}

def flutter_root
  generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__)
  unless File.exist?(generated_xcode_build_settings_path)
    raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first"
  end

  File.foreach(generated_xcode_build_settings_path) do |line|
    matches = line.match(/FLUTTER_ROOT\=(.*)/)
    return matches[1].strip if matches
  end
  raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get"
end

require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)

flutter_ios_podfile_setup

target 'Runner' do
  # Utiliser les frameworks dynamiques
  use_frameworks!
  
  # Désactiver les en-têtes modulaires pour éviter les conflits
  # use_modular_headers!

  flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
  target 'RunnerTests' do
    inherit! :search_paths
  end
end

post_install do |installer|
  # Configuration post-installation
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      # Maintenir la version minimale iOS 15.4 pour Stripe Tap to Pay
      config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '15.4'
      
      # Désactiver Bitcode (recommandé par Flutter)
      config.build_settings['ENABLE_BITCODE'] = 'NO'
      
      # Paramètres pour la compatibilité avec Xcode récent
      config.build_settings['ENABLE_USER_SCRIPT_SANDBOXING'] = 'NO'
      config.build_settings['CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER'] = 'NO'
      
      # Paramètres pour éviter les erreurs de module
      config.build_settings['DEFINES_MODULE'] = 'YES'
      config.build_settings['SWIFT_VERSION'] = '5.0'
      
      # Désactiver le support Mac Catalyst
      config.build_settings['SUPPORTS_MACCATALYST'] = 'NO'
      
      # Paramètres de signature de code
      config.build_settings['CODE_SIGNING_ALLOWED'] = 'NO'
      
      # Ajout des permissions de géolocalisation
      config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [
        '$(inherited)',
        'PERMISSION_LOCATION=1',
      ]
    end
  end
  
  # Flutter post install
  flutter_post_install(installer) if defined?(flutter_post_install)
end
