@bytebrand/fe-ui-core-autobahn 1.0.226 → 1.0.228

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/campaign/CampaignBand.tsx +26 -0
  2. package/campaign/campaignVars.ts +12 -0
  3. package/campaign/campaigns.ts +74 -0
  4. package/campaign/index.ts +6 -0
  5. package/cards/CarCard.tsx +393 -366
  6. package/cards/CarRow.tsx +8 -28
  7. package/cards/cardParts.tsx +23 -48
  8. package/cards/dealSignals.ts +36 -0
  9. package/cards/index.ts +0 -6
  10. package/chrome/Footer.tsx +3 -16
  11. package/chrome/TopBar.tsx +266 -139
  12. package/compat/CookieModal/CookieModal.tsx +6 -20
  13. package/compat/CookieModal/Modal.tsx +3 -6
  14. package/compat/CookieModal/modals/ManageCookieModal/ManageCookieModal.tsx +15 -43
  15. package/compat/CookieModal/modals/PreviewCookieModal/PreviewCookieModal.tsx +3 -4
  16. package/compat/CookieModal/useModal.ts +1 -5
  17. package/compat/Loader/Loader.tsx +7 -1
  18. package/compat/MdField/MdField.tsx +4 -28
  19. package/compat/PriceRating/PriceRating.styl +7 -5
  20. package/compat/PriceRatingDetailed/PriceRatingDetailed.styl +6 -8
  21. package/compat/TimePicker/TimePicker.tsx +2 -12
  22. package/compat/legacy-theme/priceReviewColors.styl +5 -18
  23. package/constants/app.ts +11 -1
  24. package/constants/autobahn.ts +0 -39
  25. package/constants/core.ts +12 -1
  26. package/data/fieldMapping.ts +3 -3
  27. package/data/toAutobahnCar.ts +14 -30
  28. package/iconsvg/IconSVG.tsx +5 -1
  29. package/index.ts +19 -18
  30. package/locales/de/autobahn.json +862 -903
  31. package/locales/en/autobahn.json +862 -903
  32. package/package.json +2 -2
  33. package/theme/md3.css +11808 -15866
  34. package/ui/Dropdown.tsx +10 -29
  35. package/ui/FormCheckbox.tsx +2 -22
  36. package/ui/FormField.tsx +1 -2
  37. package/ui/Icon.tsx +0 -6
  38. package/ui/Modal.tsx +6 -84
  39. package/ui/Skeleton.tsx +20 -79
  40. package/ui/Stars.tsx +18 -36
  41. package/ui/StatChip.tsx +3 -8
  42. package/ui/index.ts +0 -3
  43. package/ui/usePortalMenuPosition.ts +15 -27
  44. package/utils/index.ts +0 -10
  45. package/vdp/FinanceCalculator.tsx +34 -162
  46. package/vdp/VdpModules.tsx +976 -348
  47. package/vdp/index.ts +3 -6
  48. package/vdp/types.ts +15 -25
  49. package/vehiclesProps/decoratedLightProps.tsx +0 -4
  50. package/vehiclesProps/decoratedProps.tsx +0 -4
  51. package/cards/CarCardSkeleton.tsx +0 -103
  52. package/cards/CarRowSkeleton.tsx +0 -152
  53. package/chrome/AccountMenuIcon.tsx +0 -109
  54. package/ui/MfieldCheckIcon.tsx +0 -13
  55. package/ui/ratingLink.ts +0 -36
  56. package/ui/scrollFieldIntoView.ts +0 -41
  57. package/utils/cookieConsent.ts +0 -84
  58. package/vehiclesProps/accidentDisclosure.ts +0 -25
package/cards/CarCard.tsx CHANGED
@@ -1,366 +1,393 @@
1
- // Autobahn (auto.de redesign) — vertical grid car card.
2
- //
3
- // Typed React 18 + TS port of `CarCard` from the design kit
4
- // (docs/redesign/design-source/ui_kits/website/CarCard.jsx). Dense, professional
5
- // (AutoScout24 / Carvana style); the whole card is clickable. Used on the home
6
- // page, landing pages and "similar cars" grids.
7
- //
8
- // Pure / presentational: all data comes via the `AutobahnCar` prop, all behaviour
9
- // via injected callbacks. No store/API access — the one guarded `window`-adjacent
10
- // read is IntersectionObserver (see `eagerMedia` below), feature-checked so a
11
- // non-browser render (tests without a polyfill) degrades to a no-op, not a crash.
12
- // Renders correctly only inside a `<div className="md3">` subtree.
13
- //
14
- // Differs from the design kit on purpose:
15
- // - favorite state is INJECTED (isFavorite + onToggleFavorite) instead of the
16
- // design's internal useState, so the parent owns the merkliste.
17
- // - the needs-data deal signals (DropChip / SaveChip) only appear when real
18
- // `drop` / `savings` data is present.
19
-
20
- import React, { useState, useEffect, useRef } from 'react';
21
- import { TranslationFunction } from '../types';
22
-
23
- import { CardCarousel, SaveChip, Button, CreditCostNotice } from '../ui';
24
- import {
25
- SpecLine,
26
- EcoLine,
27
- SeoLine,
28
- DropChip,
29
- PercentChip,
30
- ZeroDownChip,
31
- OfferBadge,
32
- PriceTabs,
33
- PriceHero,
34
- PriceEvalCol,
35
- PriceTerms,
36
- CardCtaRow,
37
- GalleryCounter,
38
- GalleryActivityPill,
39
- cardSpec,
40
- PaymentMode,
41
- callDealerSalesPhone,
42
- DEALER_SALES_PHONE,
43
- } from './cardParts';
44
- import { AutobahnCar } from './types';
45
- import VdpViewer from '../vdp/VdpViewer';
46
-
47
- export interface CarCardProps {
48
- /** fully-resolved car view-model. */
49
- car: AutobahnCar;
50
- /** whether this car is on the user's merkliste (drives the heart). */
51
- isFavorite: boolean;
52
- /** toggle the favorite; the heart calls this (click is kept off the card). */
53
- onToggleFavorite: () => void;
54
- /** fired when the card is clicked (opens the detail page). */
55
- onOpen: (car: AutobahnCar) => void;
56
- /** fired on first hover/touch of the media box — the SRP uses it to lazy-load the gallery. */
57
- onMediaEnter?: () => void;
58
- /**
59
- * Also fire `onMediaEnter` as soon as the card scrolls into view, instead of waiting for a
60
- * hover/touch. Off by default — the SRP's grid is effectively unbounded (pagination/infinite
61
- * scroll), and firing one getImages() request per card the instant it enters the viewport
62
- * reintroduced exactly the failure mode `loadCarImages` was deliberately scoped away from
63
- * (SearchNextPage.tsx: "eager per-card getImages() ... raised an error toast PER failed
64
- * request, stacked toasts on mobile scroll" whenever the image service is degraded).
65
- * Opt into this only for small, BOUNDED grids (e.g. the homepage's ≤6-card "Top-Angebote"),
66
- * where without it the gallery's prev/next arrows and image-count dots stay hidden until the
67
- * user's first hover/touch on THAT card resolves (async) — on touch devices this reads as
68
- * "controls need a preliminary tap", because the very same tap that reveals them is usually
69
- * also the tap the user meant as their real interaction with the card.
70
- */
71
- eagerMedia?: boolean;
72
- /** i18n translate fn (drilled from the page). */
73
- t: TranslationFunction;
74
- /**
75
- * Optional admin-only action (e.g. dealer super admins' "Zum Schieberegler hinzufügen").
76
- * Rendered as a quiet button at the card foot; the page decides visibility (JWT claim).
77
- */
78
- adminAction?: { label: string; onClick: () => void };
79
- /**
80
- * Mobile CTA row (Figma: Angebot anfragen / phone / Rate anpassen) — omitted entirely when
81
- * the page hasn't wired these yet (same optional pattern as adminAction), so pages migrate
82
- * one at a time instead of all breaking at once.
83
- */
84
- onRequestOffer?: () => void;
85
- onCall?: () => void;
86
- /**
87
- * opens the shared FinanceDetailsModal "Rate anpassen" sheet for this car (page-owned) —
88
- * receives the tab the card was showing (Finanzierung/Leasing/Kaufen) so the sheet opens on
89
- * the same one.
90
- */
91
- onOpenRateAdjust?: (mode: PaymentMode) => void;
92
- /**
93
- * takes over the "Finanzierungsdetails"/"Details" link under the price row — e.g. navigate to
94
- * this car's own VDP and open its finance modal already expanded/scrolled to the breakdown,
95
- * instead of the default plain onOpen(car) navigation. Receives the tab the card was showing
96
- * (Finanzierung/Leasing/Kaufen) so the destination modal opens on the same one. Optional/
97
- * page-owned like onOpenRateAdjust; the mobile CTA row's "Rate anpassen" button is untouched
98
- * (still onOpenRateAdjust).
99
- */
100
- onShowFinancingDetails?: (car: AutobahnCar, mode: PaymentMode) => void;
101
- /**
102
- * the price-rating badge + bar were clicked — open this car's VDP at its "Preis & Marktwert"
103
- * section (URL fragment PRICE_SECTION_HASH, #vdp-preis). Page-owned like onShowFinancingDetails;
104
- * when omitted the badge is not a link (a click opens the car via onOpen, as before).
105
- */
106
- onShowPriceRating?: (car: AutobahnCar) => void;
107
- }
108
-
109
- const CarCard: React.FunctionComponent<CarCardProps> = ({
110
- car,
111
- isFavorite,
112
- onToggleFavorite,
113
- onOpen,
114
- onMediaEnter,
115
- eagerMedia,
116
- t,
117
- adminAction,
118
- onRequestOffer,
119
- onCall,
120
- onOpenRateAdjust,
121
- onShowFinancingDetails,
122
- onShowPriceRating,
123
- }) => {
124
- const [mode, setMode] = useState<PaymentMode>('financing');
125
- const [photoIndex, setPhotoIndex] = useState(0);
126
- const [viewerOpen, setViewerOpen] = useState(false);
127
- const mediaRef = useRef<HTMLDivElement | null>(null);
128
- // always call the LATEST onMediaEnter without re-arming the observer on every render (the
129
- // page callers below construct a fresh closure each render) — the effect itself only needs
130
- // to run once per mount.
131
- const onMediaEnterRef = useRef(onMediaEnter);
132
- onMediaEnterRef.current = onMediaEnter;
133
- useEffect(() => {
134
- if (!eagerMedia || typeof IntersectionObserver === 'undefined') return undefined;
135
- const el = mediaRef.current;
136
- if (!el) return undefined;
137
- let fired = false;
138
- // rootMargin starts the fetch a bit before the card is actually on-screen, so by the time
139
- // the user's eye (or finger, on touch) reaches it the gallery has usually already resolved
140
- // — the whole point being no tap is required to make prev/next + the counter "real".
141
- const observer = new IntersectionObserver(
142
- (entries) => {
143
- entries.forEach((entry) => {
144
- if (entry.isIntersecting && !fired) {
145
- fired = true;
146
- onMediaEnterRef.current && onMediaEnterRef.current();
147
- observer.disconnect();
148
- }
149
- });
150
- },
151
- { rootMargin: '200px 0px', threshold: 0 },
152
- );
153
- observer.observe(el);
154
- return () => observer.disconnect();
155
- }, [eagerMedia]);
156
- // as-good-as-new gate (mileage < 1,000 km AND first registration unknown or < 12 months) —
157
- // undefined (older AutobahnCar producer not yet updated) fails OPEN, keeping prior behaviour.
158
- const asGoodAsNew = car.asGoodAsNew !== false;
159
- const showDrop = asGoodAsNew && car.drop != null;
160
- const showSave = asGoodAsNew && !showDrop && car.savings != null && car.savings > 600;
161
- const showPct = asGoodAsNew && car.dropPct != null && car.dropPct > 0;
162
- const showOfferBadge = !!(car.isNew || showDrop || showSave || showPct || car.zeroDown);
163
- // PM call: the badge row only fits 3 pills — when Drop/Save + Percent + ZeroDown are all
164
- // active that's already 3, so NEU is dropped rather than causing a 4th to overflow.
165
- const activeDealChips = [showDrop || showSave, showPct, !!car.zeroDown].filter(Boolean).length;
166
- const showNeu = asGoodAsNew && car.isNew && activeDealChips < 3;
167
- return (
168
- <article
169
- className="mcard mcard--interactive cc-card"
170
- onClick={() => onOpen(car)}
171
- style={{ display: 'flex', flexDirection: 'column' }}
172
- >
173
- <div
174
- className="cc-media"
175
- ref={mediaRef}
176
- style={{ position: 'relative' }}
177
- onMouseEnter={onMediaEnter}
178
- onTouchStart={onMediaEnter}
179
- >
180
- <CardCarousel images={car.gallery} height="100%" fit="contain" padded={false} onChange={setPhotoIndex} />
181
- {/* max two overlays: heart + ONE deal signal — rating moved next to the price */}
182
- <div
183
- className="cc-fav"
184
- style={{ position: 'absolute', top: 14, right: 9, zIndex: 6 }}
185
- onClick={(e) => e.stopPropagation()}
186
- >
187
- {/* Custom heart (not lucide's default 'heart') — scoped here via a hand-rolled
188
- button+svg instead of IconButton/Icon's name-based registry lookup, so this
189
- doesn't change the "heart" icon anywhere else it's used (e.g. CarRow). Same
190
- active/inactive color logic IconButton+Icon had: active fills solid
191
- var(--md-primary), inactive stays an outline (previously 'currentColor',
192
- now this Figma-exact icon's own #08162A stroke). */}
193
- <button
194
- className="icon-btn icon-btn--filled"
195
- onClick={onToggleFavorite}
196
- aria-label={t('autobahn:card.action.save')}
197
- >
198
- <svg width="22" height="22" viewBox="0 0 22 22" fill={isFavorite ? 'var(--md-primary)' : 'none'} xmlns="http://www.w3.org/2000/svg">
199
- <path
200
- d="M11 18.7915C11 18.7915 4.125 14.8498 4.125 9.34981C4.12463 8.54932 4.37379 7.76862 4.83781 7.11634C5.30183 6.46405 5.95763 5.97262 6.71396 5.71043C7.47029 5.44823 8.28955 5.42831 9.05773 5.65343C9.82591 5.87855 10.5048 6.33752 11 6.96648C11.4952 6.33752 12.1741 5.87855 12.9423 5.65343C13.7105 5.42831 14.5297 5.44823 15.286 5.71043C16.0424 5.97262 16.6982 6.46405 17.1622 7.11634C17.6262 7.76862 17.8754 8.54932 17.875 9.34981C17.875 14.8498 11 18.7915 11 18.7915Z"
201
- stroke={isFavorite ? 'var(--md-primary)' : '#08162A'}
202
- strokeWidth={1.8}
203
- strokeLinecap="round"
204
- strokeLinejoin="round"
205
- />
206
- </svg>
207
- </button>
208
- </div>
209
- {/* top-left signal stack (heart is top-right): NEU badge + ONE deal signal + the
210
- "⚡ Angebot" badge (own line, Figma) below it. DropChip takes precedence over
211
- SaveChip; each only renders when its real data exists. */}
212
- {(showOfferBadge || showPct) && (
213
- <div
214
- className="cc-badges"
215
- style={{
216
- position: 'absolute',
217
- top: 16,
218
- left: 10,
219
- zIndex: 3,
220
- display: 'flex',
221
- flexDirection: 'column',
222
- alignItems: 'flex-start',
223
- gap: 5,
224
- maxWidth: 'calc(100% - 52px)',
225
- }}
226
- >
227
- {/* ADV-424: "−X € zum UVP²" no longer fits next to −% and 0 € Anzahlung on narrow cards, so
228
- the row wraps to a second line (inside .cc-badges, clear of the heart). The chips keep their look. */}
229
- <div style={{ display: 'flex', flexWrap: 'wrap', gap: 5, alignItems: 'center' }}>
230
- {showDrop ? <DropChip t={t} amount={car.drop} /> : showSave && <SaveChip t={t} amount={car.savings!} />}
231
- <PercentChip pct={showPct ? car.dropPct : undefined} />
232
- <ZeroDownChip
233
- t={t}
234
- show={car.zeroDown}
235
- style={{
236
- // "€0 down payment" (en) doesn't fit the German pill's 104px — only German's
237
- // "0 € Anzahlung" gets the narrow width, every other locale gets more room.
238
- width: t('autobahn:card.price.zeroDown') === '0 € Anzahlung' ? 104 : 125,
239
- height: 30,
240
- padding: 0,
241
- justifyContent: 'center',
242
- background: 'rgb(204, 222, 255)',
243
- border: '1px solid rgba(0, 92, 255, 0.05)',
244
- borderRadius: 15,
245
- fontFamily: 'Arial, Arimo, sans-serif',
246
- fontWeight: 700,
247
- fontSize: 13,
248
- lineHeight: '15px',
249
- color: '#005CFF',
250
- }}
251
- />
252
- {showNeu && <span className="neu-badge">NEU</span>}
253
- </div>
254
- <OfferBadge show={showOfferBadge} t={t} />
255
- </div>
256
- )}
257
- {/* bottom-left: expand icon + "current | total" photo counter (Figma light pill, node
258
- 281:1016) — opens the full VdpViewer lightbox; stopPropagation keeps the click off
259
- the card's own onOpen (React portals still bubble through the React tree, not the
260
- DOM tree, so this guard is needed even though VdpViewer renders via createPortal). */}
261
- <div
262
- style={{ position: 'absolute', bottom: 10, left: 10, zIndex: 3 }}
263
- onClick={(e) => e.stopPropagation()}
264
- >
265
- <GalleryCounter current={photoIndex + 1} total={car.photos} light onClick={() => setViewerOpen(true)} />
266
- </div>
267
- {/* bottom-right: eye/heart activity pill — real stats only (Figma "Push Chips / Likes", node 297:1037) */}
268
- <div style={{ position: 'absolute', bottom: 10, right: 10, zIndex: 3 }}>
269
- <GalleryActivityPill viewsCount={car.viewsCount} favoritesCount={car.favoritesCount} />
270
- </div>
271
- </div>
272
- {/* padding-top: 0 (was 8px) + marginTop: -5 — not just 0, the ask was 0 AND 5px higher
273
- still than that zero-padding baseline, so a negative margin pulls the whole block up
274
- past where padding-top:0 alone would leave it. Bottom/side padding (8px/18px)
275
- untouched. */}
276
- <div style={{ padding: '0 18px 8px', marginTop: -3, display: 'flex', flexDirection: 'column', gap: 0, flex: 1 }}>
277
- <div>
278
- <div className="md-title" style={{ whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>
279
- {car.make} {car.model}
280
- </div>
281
- <div className="md-body-sm" style={{ whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>
282
- {car.trim}
283
- </div>
284
- </div>
285
- <SpecLine items={cardSpec(car)} oneLine />
286
- <div className="cc-price" style={{ marginTop: 0, borderTop: '1px solid var(--md-outline-variant)' }}>
287
- <PriceTabs car={car} mode={mode} onModeChange={setMode} t={t} />
288
- <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 8, marginTop: 10 }}>
289
- <PriceHero car={car} mode={mode} t={t} alwaysShowUnit />
290
- <PriceEvalCol car={car} t={t} onActivate={onShowPriceRating ? () => onShowPriceRating(car) : undefined} />
291
- </div>
292
- {/* same fallback CardCtaRow already uses below: pages that haven't wired a real
293
- "Rate anpassen" sheet yet still get a working "Details" link (opens the car). */}
294
- <PriceTerms
295
- car={car}
296
- mode={mode}
297
- onOpenRateAdjust={onOpenRateAdjust || (() => onOpen(car))}
298
- onShowDetails={onShowFinancingDetails ? () => onShowFinancingDetails(car, mode) : undefined}
299
- t={t}
300
- />
301
- {/* ADV-405/407 Kreditkosten-Hinweis: below the conditions line, above the CTA row (mobile)
302
- / eco line (desktop); not on Kaufen, which shows no financing terms either. */}
303
- {mode !== 'buy' && <CreditCostNotice t={t} size="small" cls="cc-ccn" />}
304
- </div>
305
- {/* Mobile-only row (CardCtaRow itself carries the show-mobile class) — always
306
- rendered, with real fallbacks the page can override once it wires its own
307
- handlers (e.g. the "Rate anpassen" FinanceDetailsModal sheet). Never hidden. */}
308
- <CardCtaRow
309
- car={car}
310
- mode={mode}
311
- onRequestOffer={onRequestOffer || (() => onOpen(car))}
312
- onCall={onCall || callDealerSalesPhone}
313
- onOpenRateAdjust={onOpenRateAdjust || (() => onOpen(car))}
314
- t={t}
315
- />
316
- <EcoLine
317
- t={t}
318
- car={car}
319
- style={{
320
- marginTop: 'auto',
321
- borderTop: 'none',
322
- fontFamily: 'Arial, Helvetica, Arimo, sans-serif',
323
- fontStyle: 'normal',
324
- fontWeight: 400,
325
- fontSize: 11,
326
- lineHeight: '11px',
327
- textAlign: 'justify',
328
- color: '#0e2238',
329
- }}
330
- />
331
- {/* legacy VehicleSmallCard's "SeoText" footer line (full spec + equipment list) —
332
- renders nothing when the caller hasn't populated car.seoText. */}
333
- <SeoLine car={car} style={{ marginTop: 0 }} />
334
- {adminAction && (
335
- <div style={{ marginTop: 8 }}>
336
- <Button
337
- variant="outlined"
338
- block
339
- onClick={(e) => {
340
- e.stopPropagation();
341
- adminAction.onClick();
342
- }}
343
- >
344
- {adminAction.label}
345
- </Button>
346
- </div>
347
- )}
348
- </div>
349
- {viewerOpen && (
350
- <div onClick={(e) => e.stopPropagation()}>
351
- <VdpViewer
352
- images={car.galleryLarge || car.gallery}
353
- start={photoIndex}
354
- onClose={() => setViewerOpen(false)}
355
- t={t}
356
- phone={DEALER_SALES_PHONE}
357
- onCall={onCall || callDealerSalesPhone}
358
- onEmail={onRequestOffer || (() => onOpen(car))}
359
- />
360
- </div>
361
- )}
362
- </article>
363
- );
364
- };
365
-
366
- export default CarCard;
1
+ // Autobahn (auto.de redesign) — vertical grid car card.
2
+ //
3
+ // Typed React 18 + TS port of `CarCard` from the design kit
4
+ // (docs/redesign/design-source/ui_kits/website/CarCard.jsx). Dense, professional
5
+ // (AutoScout24 / Carvana style); the whole card is clickable. Used on the home
6
+ // page, landing pages and "similar cars" grids.
7
+ //
8
+ // Pure / presentational: all data comes via the `AutobahnCar` prop, all behaviour
9
+ // via injected callbacks. No store/API access — the one guarded `window`-adjacent
10
+ // read is IntersectionObserver (see `eagerMedia` below), feature-checked so a
11
+ // non-browser render (tests without a polyfill) degrades to a no-op, not a crash.
12
+ // Renders correctly only inside a `<div className="md3">` subtree.
13
+ //
14
+ // Differs from the design kit on purpose:
15
+ // - favorite state is INJECTED (isFavorite + onToggleFavorite) instead of the
16
+ // design's internal useState, so the parent owns the merkliste.
17
+ // - the needs-data deal signals (DropChip / SaveChip) only appear when real
18
+ // `drop` / `savings` data is present.
19
+
20
+ import React, { useState, useEffect, useRef } from 'react';
21
+ import { TranslationFunction } from '../types';
22
+
23
+ import { CardCarousel, SaveChip, Button, CreditCostNotice } from '../ui';
24
+ import {
25
+ SpecLine,
26
+ EcoLine,
27
+ SeoLine,
28
+ DropChip,
29
+ PercentChip,
30
+ ZeroDownChip,
31
+ OfferBadge,
32
+ PriceTabs,
33
+ PriceHero,
34
+ PriceEvalCol,
35
+ PriceTerms,
36
+ CardCtaRow,
37
+ GalleryCounter,
38
+ GalleryActivityPill,
39
+ cardSpec,
40
+ PaymentMode,
41
+ callDealerSalesPhone,
42
+ DEALER_SALES_PHONE,
43
+ } from './cardParts';
44
+ import CampaignBand from '../campaign/CampaignBand';
45
+ import { Campaign, campaignFor } from '../campaign/campaigns';
46
+ import { campaignVars } from '../campaign/campaignVars';
47
+ import { dealSignals } from './dealSignals';
48
+ import { AutobahnCar } from './types';
49
+ import VdpViewer from '../vdp/VdpViewer';
50
+
51
+ export interface CarCardProps {
52
+ /** fully-resolved car view-model. */
53
+ car: AutobahnCar;
54
+ /** whether this car is on the user's merkliste (drives the heart). */
55
+ isFavorite: boolean;
56
+ /** toggle the favorite; the heart calls this (click is kept off the card). */
57
+ onToggleFavorite: () => void;
58
+ /** fired when the card is clicked (opens the detail page). */
59
+ onOpen: (car: AutobahnCar) => void;
60
+ /** fired on first hover/touch of the media box — the SRP uses it to lazy-load the gallery. */
61
+ onMediaEnter?: () => void;
62
+ /**
63
+ * Also fire `onMediaEnter` as soon as the card scrolls into view, instead of waiting for a
64
+ * hover/touch. Off by default — the SRP's grid is effectively unbounded (pagination/infinite
65
+ * scroll), and firing one getImages() request per card the instant it enters the viewport
66
+ * reintroduced exactly the failure mode `loadCarImages` was deliberately scoped away from
67
+ * (SearchNextPage.tsx: "eager per-card getImages() ... raised an error toast PER failed
68
+ * request, stacked toasts on mobile scroll" whenever the image service is degraded).
69
+ * Opt into this only for small, BOUNDED grids (e.g. the homepage's ≤6-card "Top-Angebote"),
70
+ * where without it the gallery's prev/next arrows and image-count dots stay hidden until the
71
+ * user's first hover/touch on THAT card resolves (async) — on touch devices this reads as
72
+ * "controls need a preliminary tap", because the very same tap that reveals them is usually
73
+ * also the tap the user meant as their real interaction with the card.
74
+ */
75
+ eagerMedia?: boolean;
76
+ /** i18n translate fn (drilled from the page). */
77
+ t: TranslationFunction;
78
+ /**
79
+ * Optional admin-only action (e.g. dealer super admins' "Zum Schieberegler hinzufügen").
80
+ * Rendered as a quiet button at the card foot; the page decides visibility (JWT claim).
81
+ */
82
+ adminAction?: { label: string; onClick: () => void };
83
+ /**
84
+ * Mobile CTA row (Figma: Angebot anfragen / phone / Rate anpassen) — omitted entirely when
85
+ * the page hasn't wired these yet (same optional pattern as adminAction), so pages migrate
86
+ * one at a time instead of all breaking at once.
87
+ */
88
+ onRequestOffer?: () => void;
89
+ onCall?: () => void;
90
+ /**
91
+ * opens the shared FinanceDetailsModal "Rate anpassen" sheet for this car (page-owned) —
92
+ * receives the tab the card was showing (Finanzierung/Leasing/Kaufen) so the sheet opens on
93
+ * the same one.
94
+ */
95
+ onOpenRateAdjust?: (mode: PaymentMode) => void;
96
+ /**
97
+ * takes over the "Finanzierungsdetails"/"Details" link under the price row — e.g. navigate to
98
+ * this car's own VDP and open its finance modal already expanded/scrolled to the breakdown,
99
+ * instead of the default plain onOpen(car) navigation. Receives the tab the card was showing
100
+ * (Finanzierung/Leasing/Kaufen) so the destination modal opens on the same one. Optional/
101
+ * page-owned like onOpenRateAdjust; the mobile CTA row's "Rate anpassen" button is untouched
102
+ * (still onOpenRateAdjust).
103
+ */
104
+ onShowFinancingDetails?: (car: AutobahnCar, mode: PaymentMode) => void;
105
+ /**
106
+ * The campaign (campaign/campaigns.ts), e.g. CAMPAIGNS.blackFriday: its band is put on top of the card
107
+ * while the campaign runs and applies to this car. The band takes its height from the photo, so the card is as
108
+ * tall as its neighbours and the rows of a grid stay aligned.
109
+ */
110
+ campaign?: Campaign | null;
111
+ }
112
+
113
+ const CarCard: React.FunctionComponent<CarCardProps> = ({
114
+ car,
115
+ isFavorite,
116
+ onToggleFavorite,
117
+ onOpen,
118
+ onMediaEnter,
119
+ eagerMedia,
120
+ t,
121
+ adminAction,
122
+ onRequestOffer,
123
+ onCall,
124
+ onOpenRateAdjust,
125
+ onShowFinancingDetails,
126
+ campaign,
127
+ }) => {
128
+ const [mode, setMode] = useState<PaymentMode>('financing');
129
+ const [photoIndex, setPhotoIndex] = useState(0);
130
+ const [viewerOpen, setViewerOpen] = useState(false);
131
+ const mediaRef = useRef<HTMLDivElement | null>(null);
132
+ // always call the LATEST onMediaEnter without re-arming the observer on every render (the
133
+ // page callers below construct a fresh closure each render) — the effect itself only needs
134
+ // to run once per mount.
135
+ const onMediaEnterRef = useRef(onMediaEnter);
136
+ onMediaEnterRef.current = onMediaEnter;
137
+ useEffect(() => {
138
+ if (!eagerMedia || typeof IntersectionObserver === 'undefined') return undefined;
139
+ const el = mediaRef.current;
140
+ if (!el) return undefined;
141
+ let fired = false;
142
+ // rootMargin starts the fetch a bit before the card is actually on-screen, so by the time
143
+ // the user's eye (or finger, on touch) reaches it the gallery has usually already resolved
144
+ // — the whole point being no tap is required to make prev/next + the counter "real".
145
+ const observer = new IntersectionObserver(
146
+ (entries) => {
147
+ entries.forEach((entry) => {
148
+ if (entry.isIntersecting && !fired) {
149
+ fired = true;
150
+ onMediaEnterRef.current && onMediaEnterRef.current();
151
+ observer.disconnect();
152
+ }
153
+ });
154
+ },
155
+ { rootMargin: '200px 0px', threshold: 0 },
156
+ );
157
+ observer.observe(el);
158
+ return () => observer.disconnect();
159
+ }, [eagerMedia]);
160
+ const { drop: showDrop, save: showSave, percent: showPct, offer: showOfferBadge, neu: showNeu } = dealSignals(car);
161
+ const activeCampaign = campaignFor(car, campaign);
162
+ // tabs the price block can switch to (PriceTabs shows Leasing only when the car has a lease rate)
163
+ const paymentModes: PaymentMode[] = car.lease != null ? ['financing', 'leasing', 'buy'] : ['financing', 'buy'];
164
+ return (
165
+ <article
166
+ className={'mcard mcard--interactive cc-card' + (activeCampaign ? ' mcard--campaign' : '')}
167
+ onClick={() => onOpen(car)}
168
+ style={{ display: 'flex', flexDirection: 'column', ...(activeCampaign ? campaignVars(activeCampaign) : {}) }}
169
+ >
170
+ {activeCampaign && <CampaignBand campaign={activeCampaign} t={t} />}
171
+ <div
172
+ className="cc-media"
173
+ ref={mediaRef}
174
+ style={{ position: 'relative' }}
175
+ onMouseEnter={onMediaEnter}
176
+ onTouchStart={onMediaEnter}
177
+ >
178
+ <CardCarousel images={car.gallery} height="100%" fit="contain" padded={false} onChange={setPhotoIndex} />
179
+ {/* max two overlays: heart + ONE deal signal — rating moved next to the price */}
180
+ <div
181
+ className="cc-fav"
182
+ style={{ position: 'absolute', top: 14, right: 9, zIndex: 6 }}
183
+ onClick={(e) => e.stopPropagation()}
184
+ >
185
+ {/* Custom heart (not lucide's default 'heart') — scoped here via a hand-rolled
186
+ button+svg instead of IconButton/Icon's name-based registry lookup, so this
187
+ doesn't change the "heart" icon anywhere else it's used (e.g. CarRow). Same
188
+ active/inactive color logic IconButton+Icon had: active fills solid
189
+ var(--md-primary), inactive stays an outline (previously 'currentColor',
190
+ now this Figma-exact icon's own #08162A stroke). */}
191
+ <button
192
+ className="icon-btn icon-btn--filled"
193
+ onClick={onToggleFavorite}
194
+ aria-label={t('autobahn:card.action.save')}
195
+ >
196
+ <svg width="22" height="22" viewBox="0 0 22 22" fill={isFavorite ? 'var(--md-primary)' : 'none'} xmlns="http://www.w3.org/2000/svg">
197
+ <path
198
+ d="M11 18.7915C11 18.7915 4.125 14.8498 4.125 9.34981C4.12463 8.54932 4.37379 7.76862 4.83781 7.11634C5.30183 6.46405 5.95763 5.97262 6.71396 5.71043C7.47029 5.44823 8.28955 5.42831 9.05773 5.65343C9.82591 5.87855 10.5048 6.33752 11 6.96648C11.4952 6.33752 12.1741 5.87855 12.9423 5.65343C13.7105 5.42831 14.5297 5.44823 15.286 5.71043C16.0424 5.97262 16.6982 6.46405 17.1622 7.11634C17.6262 7.76862 17.8754 8.54932 17.875 9.34981C17.875 14.8498 11 18.7915 11 18.7915Z"
199
+ stroke={isFavorite ? 'var(--md-primary)' : '#08162A'}
200
+ strokeWidth={1.8}
201
+ strokeLinecap="round"
202
+ strokeLinejoin="round"
203
+ />
204
+ </svg>
205
+ </button>
206
+ </div>
207
+ {/* top-left signal stack (heart is top-right): NEU badge + ONE deal signal + the
208
+ "⚡ Angebot" badge (own line, Figma) below it. DropChip takes precedence over
209
+ SaveChip; each only renders when its real data exists. */}
210
+ {(showOfferBadge || showPct) && (
211
+ <div
212
+ className="cc-badges"
213
+ style={{
214
+ position: 'absolute',
215
+ top: 16,
216
+ left: 10,
217
+ zIndex: 3,
218
+ display: 'flex',
219
+ flexDirection: 'column',
220
+ alignItems: 'flex-start',
221
+ gap: 5,
222
+ maxWidth: 'calc(100% - 52px)',
223
+ }}
224
+ >
225
+ {/* ADV-424: "−X € zum UVP²" no longer fits next to −% and 0 € Anzahlung on narrow cards, so
226
+ the row wraps to a second line (inside .cc-badges, clear of the heart). The chips keep their look. */}
227
+ <div style={{ display: 'flex', flexWrap: 'wrap', gap: 5, alignItems: 'center' }}>
228
+ {showDrop ? <DropChip t={t} amount={car.drop} /> : showSave && <SaveChip t={t} amount={car.savings!} />}
229
+ <PercentChip pct={showPct ? car.dropPct : undefined} />
230
+ <ZeroDownChip
231
+ t={t}
232
+ show={car.zeroDown}
233
+ style={{
234
+ // "€0 down payment" (en) doesn't fit the German pill's 104px — only German's
235
+ // "0 € Anzahlung" gets the narrow width, every other locale gets more room.
236
+ width: t('autobahn:card.price.zeroDown') === '0 € Anzahlung' ? 104 : 125,
237
+ height: 30,
238
+ padding: 0,
239
+ justifyContent: 'center',
240
+ background: 'rgb(204, 222, 255)',
241
+ border: '1px solid rgba(0, 92, 255, 0.05)',
242
+ borderRadius: 15,
243
+ fontFamily: 'Arial, Arimo, sans-serif',
244
+ fontWeight: 700,
245
+ fontSize: 13,
246
+ lineHeight: '15px',
247
+ color: '#005CFF',
248
+ }}
249
+ />
250
+ {showNeu && <span className="neu-badge">NEU</span>}
251
+ </div>
252
+ <OfferBadge show={showOfferBadge} t={t} />
253
+ </div>
254
+ )}
255
+ {/* bottom-left: expand icon + "current | total" photo counter (Figma light pill, node
256
+ 281:1016) — opens the full VdpViewer lightbox; stopPropagation keeps the click off
257
+ the card's own onOpen (React portals still bubble through the React tree, not the
258
+ DOM tree, so this guard is needed even though VdpViewer renders via createPortal). */}
259
+ <div
260
+ style={{ position: 'absolute', bottom: 10, left: 10, zIndex: 3 }}
261
+ onClick={(e) => e.stopPropagation()}
262
+ >
263
+ <GalleryCounter current={photoIndex + 1} total={car.photos} light onClick={() => setViewerOpen(true)} />
264
+ </div>
265
+ {/* bottom-right: eye/heart activity pill — real stats only (Figma "Push Chips / Likes", node 297:1037) */}
266
+ <div style={{ position: 'absolute', bottom: 10, right: 10, zIndex: 3 }}>
267
+ <GalleryActivityPill viewsCount={car.viewsCount} favoritesCount={car.favoritesCount} />
268
+ </div>
269
+ </div>
270
+ {/* padding-top: 0 (was 8px) + marginTop: -5 — not just 0, the ask was 0 AND 5px higher
271
+ still than that zero-padding baseline, so a negative margin pulls the whole block up
272
+ past where padding-top:0 alone would leave it. Bottom/side padding (8px/18px)
273
+ untouched. */}
274
+ <div style={{ padding: '0 18px 8px', marginTop: -3, display: 'flex', flexDirection: 'column', gap: 0, flex: 1 }}>
275
+ <div>
276
+ <div className="md-title" style={{ whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>
277
+ {car.make} {car.model}
278
+ </div>
279
+ <div className="md-body-sm" style={{ whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>
280
+ {car.trim}
281
+ </div>
282
+ </div>
283
+ <SpecLine items={cardSpec(car)} oneLine />
284
+ <div className="cc-price" style={{ marginTop: 0, borderTop: '1px solid var(--md-outline-variant)' }}>
285
+ <PriceTabs car={car} mode={mode} onModeChange={setMode} t={t} />
286
+ <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 8, marginTop: 10 }}>
287
+ {/* every tab's hero stacked in one grid cell (.cc-hero-stack), only the active one
288
+ visible, bottom-aligned — Kaufen's struck list price sits on its own line above
289
+ the price, so without this the row (and the card) grew/shrank by that line on
290
+ every tab switch. Same trick as .cc-terms-stack below. */}
291
+ <div className="cc-hero-stack">
292
+ {paymentModes.map((m) => (
293
+ <div
294
+ key={m}
295
+ className={'cc-hero-slot' + (m === mode ? '' : ' cc-hero-slot--hidden')}
296
+ aria-hidden={m === mode ? undefined : true}
297
+ >
298
+ <PriceHero car={car} mode={m} t={t} alwaysShowUnit />
299
+ </div>
300
+ ))}
301
+ </div>
302
+ <PriceEvalCol car={car} t={t} />
303
+ </div>
304
+ {/* same fallback CardCtaRow already uses below: pages that haven't wired a real
305
+ "Rate anpassen" sheet yet still get a working "Details" link (opens the car).
306
+ Every tab's terms line is rendered into the same grid cell (.cc-terms-stack) and
307
+ only the active one is visible — the cell is as tall as the tallest line, so the
308
+ card keeps one height across Finanzierung/Leasing/Kaufen (Leasing's longer line
309
+ wraps to 2 lines on narrow phones). No change to the visible line itself. */}
310
+ <div className="cc-terms-stack">
311
+ {paymentModes.map((m) => (
312
+ <div
313
+ key={m}
314
+ className={'cc-terms-slot' + (m === mode ? '' : ' cc-terms-slot--hidden')}
315
+ aria-hidden={m === mode ? undefined : true}
316
+ >
317
+ <PriceTerms
318
+ car={car}
319
+ mode={m}
320
+ onOpenRateAdjust={onOpenRateAdjust || (() => onOpen(car))}
321
+ onShowDetails={onShowFinancingDetails ? () => onShowFinancingDetails(car, m) : undefined}
322
+ t={t}
323
+ />
324
+ {/* ADV-405/407 Kreditkosten-Hinweis under the financing/leasing conditions line. Inside the
325
+ slot, so the stack keeps one height across the tabs (no jump on Kaufen); hidden slots
326
+ are visibility:hidden + aria-hidden like their terms line. */}
327
+ {m !== 'buy' && <CreditCostNotice t={t} size="small" cls="cc-ccn" />}
328
+ </div>
329
+ ))}
330
+ </div>
331
+ </div>
332
+ {/* Mobile-only row (CardCtaRow itself carries the show-mobile class) — always
333
+ rendered, with real fallbacks the page can override once it wires its own
334
+ handlers (e.g. the "Rate anpassen" FinanceDetailsModal sheet). Never hidden. */}
335
+ <CardCtaRow
336
+ car={car}
337
+ mode={mode}
338
+ onRequestOffer={onRequestOffer || (() => onOpen(car))}
339
+ onCall={onCall || callDealerSalesPhone}
340
+ onOpenRateAdjust={onOpenRateAdjust || (() => onOpen(car))}
341
+ t={t}
342
+ />
343
+ <EcoLine
344
+ t={t}
345
+ car={car}
346
+ style={{
347
+ marginTop: 'auto',
348
+ borderTop: 'none',
349
+ fontFamily: 'Arial, Helvetica, Arimo, sans-serif',
350
+ fontStyle: 'normal',
351
+ fontWeight: 400,
352
+ fontSize: 11,
353
+ lineHeight: '11px',
354
+ textAlign: 'justify',
355
+ color: '#0e2238',
356
+ }}
357
+ />
358
+ {/* legacy VehicleSmallCard's "SeoText" footer line (full spec + equipment list) —
359
+ renders nothing when the caller hasn't populated car.seoText. */}
360
+ <SeoLine car={car} style={{ marginTop: 0 }} />
361
+ {adminAction && (
362
+ <div style={{ marginTop: 8 }}>
363
+ <Button
364
+ variant="outlined"
365
+ block
366
+ onClick={(e) => {
367
+ e.stopPropagation();
368
+ adminAction.onClick();
369
+ }}
370
+ >
371
+ {adminAction.label}
372
+ </Button>
373
+ </div>
374
+ )}
375
+ </div>
376
+ {viewerOpen && (
377
+ <div onClick={(e) => e.stopPropagation()}>
378
+ <VdpViewer
379
+ images={car.galleryLarge || car.gallery}
380
+ start={photoIndex}
381
+ onClose={() => setViewerOpen(false)}
382
+ t={t}
383
+ phone={DEALER_SALES_PHONE}
384
+ onCall={onCall || callDealerSalesPhone}
385
+ onEmail={onRequestOffer || (() => onOpen(car))}
386
+ />
387
+ </div>
388
+ )}
389
+ </article>
390
+ );
391
+ };
392
+
393
+ export default CarCard;