@@ -1190,6 +1190,18 @@ export default function Simulator() {
11901190 return filtered
11911191 } , [ simulationResult , filterType , filterProvider , showOnlyRecent , sortBy , sortOrder ] )
11921192
1193+ // Find the current offer (the one selected by the user for this PDL)
1194+ const currentOfferResult = useMemo ( ( ) => {
1195+ if ( ! filteredAndSortedResults . length ) return null
1196+
1197+ // Get the current PDL to find its selected offer
1198+ const currentPdl = Array . isArray ( pdlsData ) ? pdlsData . find ( ( p ) => p . usage_point_id === selectedPdl ) : undefined
1199+ if ( ! currentPdl ?. selected_offer_id ) return null
1200+
1201+ // Find the result matching the selected offer ID
1202+ return filteredAndSortedResults . find ( ( r ) => r . offerId === currentPdl . selected_offer_id ) || null
1203+ } , [ filteredAndSortedResults , pdlsData , selectedPdl ] )
1204+
11931205 // Get unique providers and types for filter options
11941206 // IMPORTANT: These hooks must be before any early returns to respect React's rules of hooks
11951207 const availableProviders = useMemo ( ( ) => {
@@ -2454,26 +2466,37 @@ export default function Simulator() {
24542466 { getSortIcon ( 'total' ) }
24552467 </ div >
24562468 </ th >
2457- < th className = "p-3 text-right font-semibold" > Écart</ th >
2469+ < th className = "p-3 text-right font-semibold" title = { currentOfferResult ? "Écart par rapport à votre offre actuelle" : "Écart par rapport à la meilleure offre" } >
2470+ < div className = "flex items-center justify-end gap-1" >
2471+ < span > Écart</ span >
2472+ { currentOfferResult && (
2473+ < span className = "text-xs font-normal text-primary-600 dark:text-primary-400" > (vs actuelle)</ span >
2474+ ) }
2475+ </ div >
2476+ </ th >
24582477 </ tr >
24592478 </ thead >
24602479 < tbody >
24612480 { filteredAndSortedResults . map ( ( result , index ) => {
24622481 const isExpanded = expandedRows . has ( result . offerId )
2463- // Calculate difference from first offer (best offer)
2464- const firstResult = filteredAndSortedResults [ 0 ]
2465- const costDifferenceFromFirst = index > 0 ? result . totalCost - firstResult . totalCost : 0
2482+ // Check if this is the user's current offer
2483+ const isCurrentOffer = currentOfferResult ?. offerId === result . offerId
2484+ // Calculate difference from current offer (if exists) or best offer
2485+ const referenceResult = currentOfferResult || filteredAndSortedResults [ 0 ]
2486+ const costDifferenceFromReference = result . totalCost - referenceResult . totalCost
24662487
24672488 return (
24682489 < React . Fragment key = { result . offerId } >
24692490 < tr
24702491 onClick = { ( ) => toggleRowExpansion ( result . offerId ) }
24712492 className = { `border-t border-gray-200 dark:border-gray-700 cursor-pointer transition-all duration-200 group ${
2472- index === 0
2473- ? 'bg-gradient-to-r from-green-50 to-emerald-50/50 dark:from-green-900/20 dark:to-emerald-900/10 hover:from-green-100 hover:to-emerald-100/50 dark:hover:from-green-900/30 dark:hover:to-emerald-900/20'
2474- : index % 2 === 1
2475- ? 'bg-gray-50 dark:bg-gray-800/50 hover:bg-gray-100 dark:hover:bg-gray-700/50'
2476- : 'bg-white dark:bg-gray-800 hover:bg-gray-50 dark:hover:bg-gray-700/50'
2493+ isCurrentOffer
2494+ ? 'bg-gradient-to-r from-primary-50 to-blue-50/50 dark:from-primary-900/20 dark:to-blue-900/10 hover:from-primary-100 hover:to-blue-100/50 dark:hover:from-primary-900/30 dark:hover:to-blue-900/20 ring-2 ring-primary-400 dark:ring-primary-500 ring-inset'
2495+ : index === 0
2496+ ? 'bg-gradient-to-r from-green-50 to-emerald-50/50 dark:from-green-900/20 dark:to-emerald-900/10 hover:from-green-100 hover:to-emerald-100/50 dark:hover:from-green-900/30 dark:hover:to-emerald-900/20'
2497+ : index % 2 === 1
2498+ ? 'bg-gray-50 dark:bg-gray-800/50 hover:bg-gray-100 dark:hover:bg-gray-700/50'
2499+ : 'bg-white dark:bg-gray-800 hover:bg-gray-50 dark:hover:bg-gray-700/50'
24772500 } `}
24782501 >
24792502 < td className = "p-2 w-8" >
@@ -2528,23 +2551,33 @@ export default function Simulator() {
25282551 { result . totalCost . toFixed ( 0 ) } €
25292552 </ span >
25302553 </ td >
2531- < td className = "p-2 text-right w-24" >
2532- { index === 0 ? (
2554+ < td className = "p-2 text-right w-28" >
2555+ { isCurrentOffer ? (
2556+ < span className = "px-2 py-0.5 text-xs bg-primary-100 dark:bg-primary-900/30 text-primary-700 dark:text-primary-300 rounded-full font-medium" >
2557+ Offre actuelle
2558+ </ span >
2559+ ) : costDifferenceFromReference === 0 ? (
25332560 < span className = "text-xs text-green-600 dark:text-green-400 font-medium" > Meilleur</ span >
2561+ ) : costDifferenceFromReference < 0 ? (
2562+ < span className = "text-sm text-green-600 dark:text-green-400 font-medium" >
2563+ { costDifferenceFromReference . toFixed ( 0 ) } €
2564+ </ span >
25342565 ) : (
25352566 < span className = "text-sm text-red-500 dark:text-red-400 font-medium" >
2536- +{ costDifferenceFromFirst . toFixed ( 0 ) } €
2567+ +{ costDifferenceFromReference . toFixed ( 0 ) } €
25372568 </ span >
25382569 ) }
25392570 </ td >
25402571 </ tr >
25412572 { isExpanded && (
25422573 < tr key = { `${ result . offerId } -details` } className = { `border-t border-dashed border-gray-300 dark:border-gray-600 ${
2543- index === 0
2544- ? 'bg-green-50/50 dark:bg-green-900/10'
2545- : index % 2 === 1
2546- ? 'bg-gray-100 dark:bg-gray-700/30'
2547- : 'bg-gray-50 dark:bg-gray-800/30'
2574+ isCurrentOffer
2575+ ? 'bg-primary-50/50 dark:bg-primary-900/10'
2576+ : index === 0
2577+ ? 'bg-green-50/50 dark:bg-green-900/10'
2578+ : index % 2 === 1
2579+ ? 'bg-gray-100 dark:bg-gray-700/30'
2580+ : 'bg-gray-50 dark:bg-gray-800/30'
25482581 } `} >
25492582 < td colSpan = { 9 } className = "p-4 bg-gradient-to-b from-gray-50 to-white dark:from-gray-800/50 dark:to-gray-900/50" >
25502583 { /* Warning message if present */ }
0 commit comments