#!/usr/bin/env ruby

require 'xcodeproj'

# Ouvrir le projet
project_path = 'ios/Runner.xcodeproj'
project = Xcodeproj::Project.open(project_path)

# Trouver la cible Runner
target = project.targets.find { |t| t.name == 'Runner' }

# Parcourir toutes les configurations de build
target.build_configurations.each do |config|
  # Obtenir les paramètres de build actuels
  build_settings = config.build_settings
  
  # Définir les chemins de recherche de frameworks
  framework_search_paths = [
    '$(inherited)',
    '"${PODS_CONFIGURATION_BUILD_DIR}/ReachabilitySwift"',
    '"${PODS_CONFIGURATION_BUILD_DIR}/connectivity_plus"',
    '"${PODS_CONFIGURATION_BUILD_DIR}/path_provider_foundation"',
    '"${PODS_CONFIGURATION_BUILD_DIR}/url_launcher_ios"',
    '"${PODS_ROOT}/Flutter"',
    '"${PODS_XCFRAMEWORKS_BUILD_DIR}/Flutter"'
  ]
  
  # Ajouter les chemins de recherche de frameworks
  build_settings['FRAMEWORK_SEARCH_PATHS'] = framework_search_paths
  
  # Ajouter les chemins de recherche d'en-têtes
  header_search_paths = [
    '$(inherited)',
    '"${PODS_ROOT}/Flutter"',
    '"${PODS_CONFIGURATION_BUILD_DIR}"'
  ]
  
  build_settings['HEADER_SEARCH_PATHS'] = header_search_paths
  
  # S'assurer que les modules sont activés
  build_settings['DEFINES_MODULE'] = 'YES'
  
  # Désactiver le bitcode
  build_settings['ENABLE_BITCODE'] = 'NO'
  
  # Inclure tous les assets d'icônes
  build_settings['ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS'] = 'YES'
  
  # Autres paramètres importants
  build_settings['SWIFT_VERSION'] = '5.0'
  build_settings['CLANG_ENABLE_MODULES'] = 'YES'
end

# Enregistrer les modifications
project.save

puts "✅ Chemins de recherche de frameworks ajoutés avec succès !"
