#!/bin/bash

# Script pour corriger le problème d'assets dans l'application web
echo "🔍 Fixing assets structure for web deployment..."

# Création du dossier assets/assets/animations si inexistant
mkdir -p build/web/assets/assets/animations

# Copie des animations depuis le répertoire source
cp -r assets/animations/* build/web/assets/assets/animations/

echo "✅ Assets structure fixed!"

# Si besoin de redéployer sans reconstruire l'application
if [ "$1" == "--deploy" ]; then
  # Définition des variables 
  REMOTE_USER="root"
  REMOTE_HOST="87.98.163.161"
  SSH_KEY="/Users/pierre/.ssh/id_rsa_mbpi"
  REMOTE_PATH="/var/www/geosector"
  
  echo "📤 Deploying fixed assets to server..."
  rsync -rltz \
      -e "ssh -i ${SSH_KEY}" \
      build/web/assets/ \
      ${REMOTE_USER}@${REMOTE_HOST}:${REMOTE_PATH}/assets/
  
  if [ $? -ne 0 ]; then
      echo "❌ Deployment failed"
      exit 1
  fi
  
  echo "✅ Assets deployed successfully!"
fi
