#!/usr/bin/env bash
set -euo pipefail
APP_DIR="${APP_DIR:-sociowire-frontend}"
FILE="$APP_DIR/src/components/Layout/TopBar.jsx"

cp -a "$FILE" "$FILE.bak.$(date +%s)"

# Ajoute l'affichage lastError dans le form login (sous le bouton)
perl -0777 -i -pe '
s|(</button>\s*</form>)|</button>\n                {lastError && <div className="auth-error" style={{marginTop:"0.6rem"}}>{lastError}</div>}\n              </form>|ms
' "$FILE"

echo "OK patched: $FILE"
