#!/bin/bash

# Liste des fichiers à modifier
FILES=(
  "lib/presentation/admin/admin_dashboard_page.dart"
  "lib/presentation/user/user_dashboard_page.dart"
  "lib/presentation/admin/admin_dashboard_home_page.dart"
  "lib/presentation/admin/admin_statistics_page.dart"
  "lib/presentation/admin/admin_history_page.dart"
  "lib/presentation/user/user_dashboard_home_page.dart"
  "lib/presentation/user/user_statistics_page.dart"
  "lib/presentation/user/user_history_page.dart"
  "lib/presentation/user/user_communication_page.dart"
  "lib/core/widgets/dashboard_app_bar.dart"
  "lib/presentation/widgets/responsive_navigation.dart"
  "lib/presentation/widgets/charts/activity_chart.dart"
  "lib/presentation/widgets/charts/passage_pie_chart.dart"
  "lib/presentation/widgets/profile_dialog.dart"
)

for file in "${FILES[@]}"; do
  echo "Updating $file..."
  
  # Vérifier si le fichier existe
  if [ ! -f "$file" ]; then
    echo "File $file does not exist, skipping."
    continue
  fi
  
  # Remplacer l'import de provider par l'import de app.dart
  sed -i '' -e '/import .package:provider\/provider.dart.;/d' "$file"
  
  # Ajouter l'import de app.dart s'il n'existe pas déjà
  if ! grep -q "import 'package:geosector_app/app.dart';" "$file"; then
    sed -i '' -e '1,/^import/s/^import/import '\''package:geosector_app\/app.dart'\''; \/\/ Pour accéder aux instances globales\nimport/' "$file"
  fi
  
  echo "Updated $file"
done

echo "All files updated!"
