@bytebrand/fe-ui-core-autobahn 1.0.210 → 1.0.212

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 (45) hide show
  1. package/cards/CarCard.tsx +8 -1
  2. package/cards/CarCardSkeleton.tsx +103 -0
  3. package/cards/CarRow.tsx +5 -1
  4. package/cards/CarRowSkeleton.tsx +152 -0
  5. package/cards/cardParts.tsx +1368 -1363
  6. package/cards/index.ts +6 -0
  7. package/cards/types.ts +182 -182
  8. package/chrome/AccountMenuIcon.tsx +109 -0
  9. package/chrome/Footer.tsx +16 -3
  10. package/chrome/TopBar.tsx +139 -266
  11. package/compat/CookieModal/CookieModal.tsx +20 -6
  12. package/compat/CookieModal/Modal.tsx +6 -3
  13. package/compat/CookieModal/modals/ManageCookieModal/ManageCookieModal.tsx +43 -15
  14. package/compat/CookieModal/modals/PreviewCookieModal/PreviewCookieModal.tsx +4 -3
  15. package/compat/CookieModal/useModal.ts +5 -1
  16. package/compat/Loader/Loader.tsx +1 -7
  17. package/compat/MdField/MdField.tsx +28 -4
  18. package/compat/TimePicker/TimePicker.tsx +12 -2
  19. package/data/toAutobahnCar.ts +600 -586
  20. package/iconsvg/IconSVG.tsx +1 -5
  21. package/locales/de/autobahn.json +891 -857
  22. package/locales/en/autobahn.json +891 -857
  23. package/package.json +2 -2
  24. package/theme/md3.css +15678 -11743
  25. package/ui/CreditCostNotice.tsx +44 -44
  26. package/ui/CreditKeyFigures.tsx +244 -244
  27. package/ui/Dropdown.tsx +29 -10
  28. package/ui/FormCheckbox.tsx +22 -2
  29. package/ui/FormField.tsx +2 -1
  30. package/ui/Icon.tsx +6 -0
  31. package/ui/MfieldCheckIcon.tsx +13 -0
  32. package/ui/Modal.tsx +84 -6
  33. package/ui/Skeleton.tsx +79 -20
  34. package/ui/index.ts +96 -94
  35. package/ui/scrollFieldIntoView.ts +41 -0
  36. package/ui/usePortalMenuPosition.ts +27 -15
  37. package/utils/cookieConsent.ts +84 -0
  38. package/utils/index.ts +10 -0
  39. package/vdp/FinanceCalculator.tsx +1148 -1134
  40. package/vdp/VdpModules.tsx +3869 -4437
  41. package/vdp/index.ts +0 -3
  42. package/vdp/types.ts +7 -17
  43. package/vehiclesProps/accidentDisclosure.ts +25 -0
  44. package/vehiclesProps/decoratedLightProps.tsx +4 -0
  45. package/vehiclesProps/decoratedProps.tsx +4 -0
@@ -1,1134 +1,1148 @@
1
- // Autobahn (auto.de redesign) — VDP offer / finance card (Finanzierung / Leasing /
2
- // Barzahlung).
3
- //
4
- // Structure (desktop rethink, tabs-on-top): payment-type TABS at the top (MD3 underline tabs),
5
- // then the rate (with any discount), then the "Rate anpassen" rate-editor, then the primary
6
- // "Angebot sichern" request CTA, and finally the Finanzierungs-/Leasingdetails info + popup link
7
- // at the foot. Laufzeit is chosen via chips (discrete terms), not a slider.
8
- //
9
- // CONTROLLED / PRESENTATIONAL — computes NOTHING financial: `mode`, `monthly`, `down`, `term` and
10
- // the slider/chip bounds all arrive as props; segment/slider/chip changes are reported back via
11
- // `onModeChange` / `onDownChange` / `onTermChange`. The real numbers come from `financingStore`.
12
- // The only local state is the `adjust` expander (pure view state).
13
- //
14
- // Renders correctly only inside a `<div className="md3">` subtree.
15
-
16
- import React, { useState } from 'react';
17
- import { TranslationFunction } from '../types';
18
-
19
- import { Button, Icon, Switch, CreditCostNotice, CreditKeyFigures, hasCreditKeyFigures } from '../ui';
20
- import type { CreditKeyFiguresData } from '../ui';
21
- import { TIER_LABELS, TIER_KEYS, TIER_COLORS } from '../constants';
22
-
23
- /** Payment mode segment keys. Mirrors the design's ['fin','leasing','cash']. */
24
- export type FinanceMode = 'fin' | 'leasing' | 'cash';
25
-
26
- export interface SliderProps {
27
- min: number;
28
- max: number;
29
- step?: number;
30
- value: number;
31
- onChange: (value: number) => void;
32
- /** formats the min/max end labels (and is reused by callers for the value). */
33
- fmt?: (v: number) => React.ReactNode;
34
- /** render the current value in a floating bubble above the thumb (Figma sheet sliders). */
35
- bubble?: boolean;
36
- /** space reserved below the rail for the bubble's tail (Figma differs per sheet: fin vs leasing). */
37
- bubblePaddingBottom?: number;
38
- }
39
-
40
- /**
41
- * Range slider with a filled track and min/max end labels. The track fill is a
42
- * linear-gradient driven by the value's position; the design's `.mslider` class
43
- * styles the thumb/rail. With `bubble` the current value floats above the thumb
44
- * (mockup "Rate anpassen" sliders) instead of the caller printing it elsewhere.
45
- */
46
- export const Slider: React.FunctionComponent<SliderProps> = ({
47
- min,
48
- max,
49
- step = 1,
50
- value,
51
- onChange,
52
- fmt = (v) => v,
53
- bubble,
54
- bubblePaddingBottom = 34,
55
- }) => {
56
- const span = max - min;
57
- const pct = span > 0 ? ((value - min) / span) * 100 : 0;
58
- return (
59
- <div>
60
- <div style={{ position: 'relative', paddingTop: bubble ? 44 : 0, paddingBottom: bubble ? bubblePaddingBottom : 0 }}>
61
- {bubble && (
62
- // thumb is 22px wide: interpolate the bubble anchor between half-thumb insets so it
63
- // tracks the thumb center (a plain pct% drifts at the rail ends)
64
- <span className="slider-bubble num" style={{ left: `calc(11px + (100% - 22px) * ${pct / 100})` }}>
65
- {fmt(value)}
66
- </span>
67
- )}
68
- <input
69
- type="range"
70
- className="mslider"
71
- min={min}
72
- max={max}
73
- step={step}
74
- value={value}
75
- onChange={(e) => onChange(Number(e.target.value))}
76
- style={{ background: `linear-gradient(90deg, var(--md-primary) ${pct}%, var(--md-sc-highest) ${pct}%)` }}
77
- />
78
- </div>
79
- {!bubble && (
80
- <div style={{ display: 'flex', justifyContent: 'space-between', marginTop: 4 }}>
81
- <span className="md-label-sm">{fmt(min)}</span>
82
- <span className="md-label-sm">{fmt(max)}</span>
83
- </div>
84
- )}
85
- </div>
86
- );
87
- };
88
-
89
- /**
90
- * Segmented price-evaluation bar (Figma: 5 discrete tier segments, NOT a gradient) with a
91
- * white ring marker. `leftPct` overrides the marker position (the Marktwert gauge positions
92
- * it continuously); default = centered on the tier segment.
93
- */
94
- export const EvalBar: React.FunctionComponent<{ tier: number; leftPct?: number }> = ({ tier, leftPct }) => (
95
- <div className="fin-eval-bar">
96
- {TIER_COLORS.map((c, i) => (
97
- <span key={i} className="fin-eval-seg" style={{ background: c }} />
98
- ))}
99
- <div
100
- className={`fin-eval-thumb${TIER_KEYS[Math.max(0, Math.min(4, tier))] === 'good' ? ' fin-eval-thumb--good' : ''}`}
101
- style={{ left: `${leftPct != null ? leftPct : (tier + 0.5) * 20}%`, borderColor: TIER_COLORS[Math.max(0, Math.min(4, tier))] }}
102
- />
103
- </div>
104
- );
105
-
106
- /** Figma CTA icon — document with a check-in-circle badge over its bottom-right corner
107
- * (no single lucide glyph matches; composed from file-text + a knocked-out check-circle).
108
- * The badge backdrop assumes a filled (primary) button. */
109
- export const DocCheckIcon: React.FunctionComponent<{ size?: number }> = ({ size = 19 }) => {
110
- // inline width/height on BOTH icons — `.mbtn .lucide { width/height: 18px }` otherwise
111
- // inflates the badge to full icon size and it swallows the document
112
- const badge = Math.max(9, Math.round(size * 0.5));
113
- return (
114
- <span style={{ position: 'relative', display: 'inline-flex', flex: 'none' }}>
115
- <Icon name="file-text" size={size} stroke={2} style={{ width: size, height: size }} />
116
- <span
117
- style={{
118
- position: 'absolute',
119
- right: -3,
120
- bottom: -2,
121
- display: 'flex',
122
- borderRadius: '50%',
123
- background: 'var(--md-primary)',
124
- padding: 1,
125
- }}
126
- >
127
- <Icon name="check-circle" size={badge} stroke={2.8} style={{ width: badge, height: badge }} />
128
- </span>
129
- </span>
130
- );
131
- };
132
-
133
- export interface TermChipsProps {
134
- /** the selectable term values (months), e.g. [12,24,36,48,60,72]. */
135
- options: number[];
136
- value: number;
137
- onChange: (term: number) => void;
138
- /** i18n function (drilled from the page). */
139
- t: TranslationFunction;
140
- }
141
-
142
- /** Laufzeit selector — discrete term values as tappable chips (replaces the fiddly slider). */
143
- export const TermChips: React.FunctionComponent<TermChipsProps> = ({ options, value, onChange, t }) => (
144
- <div className="term-chips" role="group" aria-label={t('autobahn:finance.termSelection')}>
145
- {options.map((m) => (
146
- <button
147
- key={m}
148
- type="button"
149
- aria-pressed={m === value}
150
- className={'term-chip' + (m === value ? ' on' : '')}
151
- onClick={() => onChange(m)}
152
- >
153
- {m}
154
- <span className="tc-unit">{t('autobahn:finance.monthUnit')}</span>
155
- </button>
156
- ))}
157
- </div>
158
- );
159
-
160
- export interface CalcRowProps {
161
- label: React.ReactNode;
162
- /** when true, drops the bottom hairline (last row). */
163
- last?: boolean;
164
- children?: React.ReactNode;
165
- className?: string;
166
- }
167
-
168
- /** One label/value row inside the "Rate anpassen" / "Details" expander. */
169
- export const CalcRow: React.FunctionComponent<CalcRowProps> = ({ label, last, children, className }) => (
170
- <div
171
- className={'calcrow' + (className ? ' ' + className : '')}
172
- style={{
173
- display: 'flex',
174
- justifyContent: 'space-between',
175
- alignItems: 'baseline',
176
- gap: 12,
177
- padding: '8px 0',
178
- borderBottom: last ? 0 : '1px solid var(--md-outline-variant)',
179
- }}
180
- >
181
- <span className="md-label-sm calcrow-label">{label}</span>
182
- <span className="num calcrow-value" style={{ fontSize: 13.5, fontWeight: 600 }}>
183
- {children}
184
- </span>
185
- </div>
186
- );
187
-
188
- /** full-width label(+optional trailing price) / Switch row — Switch itself is inline-flex
189
- * (track+label), so the "label ...... price switch" full-row layout can't be expressed via
190
- * Switch's `label` prop (which renders track-then-label, not a full-width justified row). */
191
- export const ToggleRow: React.FunctionComponent<{
192
- label: string;
193
- price?: string;
194
- checked: boolean;
195
- disabled?: boolean;
196
- onChange: (checked: boolean) => void;
197
- className?: string;
198
- /** cash mode: the package is always included — shows a static "inklusive" note instead of the switch. */
199
- staticNote?: string;
200
- /** when set, the info icon becomes clickable and opens a popover with this body (e.g. the
201
- * Rundum-Sorglos-Paket contents) — "Mit Schlussrate" rows omit this, keeping their icon inert. */
202
- tooltip?: React.ReactNode;
203
- /** aria-label for the popover's close button — required together with `tooltip`. */
204
- tooltipCloseLabel?: string;
205
- /** required together with `tooltip` — builds the trigger's own accessible name (see `infoLabel` below). */
206
- t?: TranslationFunction;
207
- }> = ({ label, price, checked, disabled, onChange, className, staticNote, tooltip, tooltipCloseLabel, t }) => {
208
- const [tooltipOpen, setTooltipOpen] = useState(false);
209
- const toggleTooltip = (e: { stopPropagation: () => void }) => {
210
- e.stopPropagation();
211
- setTooltipOpen((v) => !v);
212
- };
213
- // the visible label alone ("Rundum-Sorglos-Paket") reads as ambiguous out of context (toggle
214
- // the package? show info about it?) — spell out what activating the trigger actually does.
215
- const infoLabel = tooltip && t ? t('autobahn:finance.moreInfoAria', { label }) : undefined;
216
- return (
217
- <div
218
- className={className}
219
- style={{
220
- display: 'flex',
221
- alignItems: 'center',
222
- justifyContent: staticNote ? undefined : 'space-between',
223
- gap: 10,
224
- position: tooltip ? 'relative' : undefined,
225
- }}
226
- >
227
- <span className="md-title-sm" style={{ display: 'inline-flex', alignItems: 'center', gap: 5 }}>
228
- {label}
229
- {/* custom info glyph (not the shared lucide "info" from the Icon registry — that name is
230
- used in many unrelated places, this swap is scoped to just the Rundum-Sorglos-Paket
231
- tooltip trigger). Shared by all three tabs (Finanzierung/Leasing/Kaufen) and both
232
- desktop/mobile — ToggleRow itself is the one shared render for all of them. Viewbox
233
- already bounds every path (1.875–13.125 within 0–15), so no clip-path needed.
234
- The interactive/focusable/touch-target element is THIS icon wrapper only — the label
235
- text next to it is plain, inert text, not part of the trigger. */}
236
- {tooltip && (
237
- <span
238
- className="fin-toggle-info-trigger"
239
- style={{ display: 'inline-flex', cursor: 'pointer' }}
240
- role="button"
241
- tabIndex={0}
242
- aria-label={infoLabel}
243
- aria-expanded={tooltipOpen}
244
- onClick={toggleTooltip}
245
- onKeyDown={(e) => {
246
- // ARIA authoring practices: a role="button" element must answer to both Enter and
247
- // Space, not just Enter — a native <button> gets this for free, this span doesn't.
248
- if (e.key === 'Enter' || e.key === ' ') {
249
- e.preventDefault();
250
- toggleTooltip(e);
251
- }
252
- }}
253
- >
254
- <svg width="15" height="15" viewBox="0 0 15 15" fill="none" xmlns="http://www.w3.org/2000/svg" className="lucide">
255
- <path d="M7.5 13.125C10.6066 13.125 13.125 10.6066 13.125 7.5C13.125 4.3934 10.6066 1.875 7.5 1.875C4.3934 1.875 1.875 4.3934 1.875 7.5C1.875 10.6066 4.3934 13.125 7.5 13.125Z" stroke="#8B98AA" strokeWidth={1.8} />
256
- <path d="M7.5 7.2V10.5125" stroke="#8B98AA" strokeWidth={1.8} strokeLinecap="round" />
257
- <path d="M7.5 4.8125H7.50625" stroke="#8B98AA" strokeWidth={2.4} strokeLinecap="round" />
258
- </svg>
259
- </span>
260
- )}
261
- </span>
262
- {tooltip && tooltipOpen && (
263
- <div className="pp-uvp-tooltip fin-toggle-tooltip" onClick={(e) => e.stopPropagation()}>
264
- <button
265
- type="button"
266
- className="pp-uvp-tooltip-close fin-toggle-tooltip-close"
267
- aria-label={tooltipCloseLabel}
268
- onClick={(e) => {
269
- e.stopPropagation();
270
- setTooltipOpen(false);
271
- }}
272
- >
273
- <svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
274
- <path d="M5 5L15 15M15 5L5 15" stroke="white" strokeWidth={2.4} strokeLinecap="round" />
275
- </svg>
276
- </button>
277
- <div className="pp-uvp-tooltip-body fin-toggle-tooltip-body">{tooltip}</div>
278
- </div>
279
- )}
280
- <div style={{ display: 'flex', alignItems: 'center', gap: 10, marginLeft: staticNote ? 'auto' : undefined }}>
281
- {/* staticNote (cash mode: package is always included, price already baked into the
282
- fixed price above) fully replaces the price+switch pair — showing "+1.499 €" right
283
- next to "inklusive" read as contradictory, so price is suppressed whenever
284
- staticNote is set, not just the switch. */}
285
- {price && !staticNote && (
286
- <span className="num" style={{ fontWeight: 700, fontSize: 13.5 }}>
287
- {price}
288
- </span>
289
- )}
290
- {staticNote ? (
291
- <span style={{ fontFamily: 'Arial, Arimo, sans-serif', fontWeight: 400, fontSize: 15, lineHeight: '17px', color: '#0E2238' }}>
292
- {staticNote}
293
- </span>
294
- ) : (
295
- <Switch checked={checked} disabled={disabled} onChange={(e) => onChange(e.target.checked)} ariaLabel={label} />
296
- )}
297
- </div>
298
- </div>
299
- );
300
- };
301
-
302
- /** body content for the "Rundum-Sorglos-Paket" ToggleRow tooltip — intro sentence, bold heading,
303
- * the package's contents as a bullet list, then (financing/leasing only) a closing paragraph
304
- * explaining the one-off-vs-financed payment choice. Shared by every addServicesToggle
305
- * ToggleRow (FinanceCalculator's own card + VdpModules' modal/mobile-sheet instances); intro/
306
- * outro vary by mode since cash mode has no "financed into the rate" option. */
307
- export const AddServicesTooltipBody: React.FunctionComponent<{ t: TranslationFunction; isCash?: boolean; isLease?: boolean }> = ({
308
- t,
309
- isCash,
310
- isLease,
311
- }) => (
312
- <>
313
- <p style={{ margin: '0 0 8px' }}>
314
- {t(isCash ? 'autobahn:finance.addServicesTooltipIntroCash' : 'autobahn:finance.addServicesTooltipIntroFinanced')}
315
- </p>
316
- <p style={{ fontFamily: 'Arial, Arimo, sans-serif', fontWeight: 700, fontSize: 10, lineHeight: '13px', color: '#0E2238', margin: '0 0 4px' }}>
317
- {t('autobahn:finance.addServicesTooltipHeading')}
318
- </p>
319
- <ul style={{ margin: 0, padding: '0 0 0 14px' }}>
320
- {t('autobahn:finance.addServicesTooltipItems')
321
- .split('\n')
322
- .map((item) => (
323
- <li key={item}>{item}</li>
324
- ))}
325
- </ul>
326
- {!isCash && (
327
- <p style={{ margin: '8px 0 0' }}>
328
- {t(isLease ? 'autobahn:finance.addServicesTooltipOutroLeasing' : 'autobahn:finance.addServicesTooltipOutroFinancing')}
329
- </p>
330
- )}
331
- </>
332
- );
333
-
334
- export interface FinanceCalculatorProps {
335
- /** active payment mode (controlled). */
336
- mode: FinanceMode;
337
- /** purchase price in EUR (the cash mode hero). */
338
- price: number;
339
- /** previous/list price — when > price, shown struck through as the UVP in cash mode (real discount). */
340
- listPrice?: number;
341
- /** auto.de-ID reference code — shown with the financing/leasing condition line. */
342
- autoDeId?: string;
343
- /** price-rating label, e.g. 'Guter Preis' — drives the Preisbewertung indicator. */
344
- ratingLabel?: string;
345
- /** computed monthly rate in EUR for the current mode — supplied, NOT computed here. */
346
- monthly: number;
347
- /** struck old monthly rate (fe-financing oldMonthlyInstallment, isStrikeShown-gated) —
348
- * rendered as the red line-through figure next to the hero rate (fin/leasing only). */
349
- oldMonthly?: number;
350
- /** effective annual rate (%) for the current mode — supplied, NOT computed here. */
351
- apr: number;
352
- /** ADV-405 follow-up: financing key figures (Kerndaten) of the CURRENT calculation — the same
353
- * financing-config values the Finanzierungsdetails layer shows (paybackPeriod, netLoanAmount,
354
- * totalFinancingAmount else grossLoanAmount, nominalInterestRate, annualPercentageRate). When
355
- * at least one is real, the financing conditions line shows them instead of "0 € Anzahlung ·
356
- * 60 Monate". Financing only (leasing/Kaufen ignore it); omit to keep the old line. */
357
- creditKeyFigures?: CreditKeyFiguresData;
358
- /** ADV-405 follow-up (leasing confirmed 19.11): leasing key figures of the CURRENT leasing
359
- * calculation (kind 'leasing', ui/CreditKeyFigures leasingKeyFigures — the Leasingdetails
360
- * layer's own figures). Shown on the Leasing tab instead of "… Sonderzahlung · … Mon. · … km/Jahr"
361
- * when at least one is real; omit to keep the old line. */
362
- leasingKeyFigures?: CreditKeyFiguresData;
363
- /** current down payment in EUR (controlled). */
364
- down: number;
365
- /** current term in months (controlled). */
366
- term: number;
367
- /** down-payment slider bounds. */
368
- downMin: number;
369
- downMax: number;
370
- /** down-payment slider step (EUR). */
371
- downStep?: number;
372
- /** term slider bounds (months) — used to derive chip options when termOptions is absent. */
373
- termMin: number;
374
- termMax: number;
375
- /** term slider step (months). */
376
- termStep?: number;
377
- /** the discrete selectable terms (months) for the Laufzeit chips. */
378
- termOptions?: number[];
379
- /** annual mileage in km (controlled) — leasing/financing Laufleistung/Jahr. Omit to hide the slider. */
380
- annualMileage?: number;
381
- /** annual-mileage slider bounds + step (km). */
382
- annualMileageMin?: number;
383
- annualMileageMax?: number;
384
- annualMileageStep?: number;
385
- /** annual-mileage slider changed. */
386
- onAnnualMileageChange?: (km: number) => void;
387
- /** "Mit Schlussrate" toggle state (financing only; leasing has no balloon concept). Omit
388
- * onToggleFinalInstallment to hide the row. */
389
- withFinalInstallment?: boolean;
390
- onToggleFinalInstallment?: (checked: boolean) => void;
391
- /** "Rundum-Sorglos-Paket" toggle state (fin/leasing). Omit addServicesCost or
392
- * onToggleAddServices to hide the row. */
393
- withAddServices?: boolean;
394
- addServicesCost?: number;
395
- addServicesDisabled?: boolean;
396
- onToggleAddServices?: (checked: boolean) => void;
397
- /** Kaufen tab only — real carStore.isAvailable, drives the Verfügbarkeit row (replaces the
398
- * static Lieferung row). Same source as VdpTrustRow's "Sofort verfügbar" badge. */
399
- available?: boolean;
400
- /** phone number shown on the secondary CTA (touch only). */
401
- phone?: string;
402
- /** primary CTA click (Angebot sichern). */
403
- onSecure?: () => void;
404
- /** true once the customer already has an offer request/checkout in progress for this car —
405
- * turns the primary CTA green (see .fin-cta-secured) instead of the default filled style. */
406
- secured?: boolean;
407
- /** overrides the primary CTA label while `secured` is true (e.g. "Zur Bestellung"). Ignored
408
- * when `secured` is false — the CTA keeps its own default label in that case. */
409
- secureLabel?: string;
410
- /** secondary CTA click (phone). */
411
- onCall?: () => void;
412
- /** open the Finanzierungs-/Leasingdetails popup (full breakdown + legal, expanded). Omit to hide the link. */
413
- onShowDetails?: () => void;
414
- /** mobile only: open the "Rate anpassen" / "Details anzeigen" sheet (collapsed/default view).
415
- * Omit to hide the trigger row (falls back to the desktop inline expander). */
416
- onOpenAdjust?: () => void;
417
- /** mode segment changed. */
418
- onModeChange: (mode: FinanceMode) => void;
419
- /** down-payment slider changed. */
420
- onDownChange: (down: number) => void;
421
- /** term changed. */
422
- onTermChange: (term: number) => void;
423
- /** whether leasing is actually offered for this car (financingConfig.leasing.isActive — same
424
- * age/mileage-gated flag SearchResultsStore.getLeasingActive stamps for the cards, see
425
- * cardParts.tsx's PriceTabs / toAutobahnCar.ts's `lease`). Default true keeps existing callers'
426
- * behavior; the VDP page passes the real computed value. Hides the Leasing tab when false,
427
- * same as the card — instead of showing a tab that would compute/display a rate the car isn't
428
- * eligible for. */
429
- leasingAvailable?: boolean;
430
- /** i18n function (drilled from the page). */
431
- t: TranslationFunction;
432
- }
433
-
434
- const eur = (n: number): string => n.toLocaleString('de-DE');
435
-
436
- /** build a [min..max] step range (fallback term options when none are supplied). */
437
- const range = (min: number, max: number, step: number): number[] => {
438
- const out: number[] = [];
439
- for (let v = min; v <= max; v += step || 12) out.push(v);
440
- return out.length ? out : [min];
441
- };
442
-
443
- /** quiet primary-colored text link (Finanzierungsdetails / Details anzeigen). */
444
- const DetailsLink: React.FunctionComponent<{ label: string; onClick: () => void }> = ({ label, onClick }) => (
445
- <button
446
- type="button"
447
- onClick={onClick}
448
- style={{
449
- display: 'inline-flex',
450
- alignItems: 'center',
451
- gap: 5,
452
- background: 'none',
453
- border: 0,
454
- padding: 0,
455
- cursor: 'pointer',
456
- color: 'var(--md-primary)',
457
- font: 'inherit',
458
- fontSize: 13,
459
- fontWeight: 600,
460
- }}
461
- >
462
- <Icon name="info" size={15} color="var(--md-primary)" />
463
- {label}
464
- </button>
465
- );
466
-
467
- /** "Rate anpassen" / "Details anzeigen" expander toggle button. */
468
- export const expanderBtnStyle: React.CSSProperties = {
469
- width: '100%',
470
- background: 'none',
471
- border: 0,
472
- cursor: 'pointer',
473
- display: 'flex',
474
- alignItems: 'center',
475
- justifyContent: 'space-between',
476
- padding: '0 0 2px',
477
- color: 'var(--md-primary)',
478
- fontWeight: 600,
479
- fontSize: 14,
480
- };
481
-
482
- const FinanceCalculator: React.FunctionComponent<FinanceCalculatorProps> = ({
483
- mode,
484
- price,
485
- listPrice,
486
- autoDeId,
487
- ratingLabel,
488
- monthly,
489
- oldMonthly,
490
- creditKeyFigures,
491
- leasingKeyFigures,
492
- down,
493
- term,
494
- downMin,
495
- downMax,
496
- downStep = 500,
497
- termMin,
498
- termMax,
499
- termStep = 6,
500
- termOptions,
501
- annualMileage,
502
- annualMileageMin = 5000,
503
- annualMileageMax = 60000,
504
- annualMileageStep = 5000,
505
- onAnnualMileageChange,
506
- withFinalInstallment,
507
- onToggleFinalInstallment,
508
- withAddServices,
509
- addServicesCost,
510
- addServicesDisabled,
511
- onToggleAddServices,
512
- available,
513
- phone = '0800 40 30 182',
514
- onSecure,
515
- secured,
516
- secureLabel,
517
- onCall,
518
- onShowDetails,
519
- onOpenAdjust,
520
- onModeChange,
521
- onDownChange,
522
- onTermChange,
523
- leasingAvailable = true,
524
- t,
525
- }) => {
526
- // Pure view state only — whether the adjust/details expander is open.
527
- const [adjust, setAdjust] = useState(false);
528
- // whether the "UVP-Rate" footnote popover (fin/leasing) is open — same widget as CarCard's.
529
- const [uvpTooltipOpen, setUvpTooltipOpen] = useState(false);
530
- const isCash = mode === 'cash';
531
- const isLease = mode === 'leasing';
532
- const terms = termOptions && termOptions.length ? termOptions : range(termMin, termMax, termStep);
533
- const showStrike = listPrice != null && listPrice > price;
534
- // price-evaluation tier from the rating label (defaults to 'Guter Preis' tier when unmapped).
535
- const tierIdx = TIER_LABELS.indexOf(ratingLabel as (typeof TIER_LABELS)[number]);
536
- const evalTier = tierIdx >= 0 ? tierIdx : 1;
537
- const isGoodTier = TIER_KEYS[evalTier] === 'good';
538
- // each tier shows its own real label now (Top/Guter/Fairer/Erhöht/Hoher Preis) — no more
539
- // collapsing 'good' onto the "Top-Preis" claim. Pill styling (colour/class/footnote) unchanged.
540
- const evalTierLabel = t('autobahn:tier.' + TIER_KEYS[evalTier]);
541
- const evalPillColor = isGoodTier ? TIER_COLORS[0] : TIER_COLORS[evalTier];
542
- // condition summary (current selection) + its own details link — financing: "0 € Anzahlung ·
543
- // 60 Monate · Finanzierungsdetails"; leasing: "25.000 € Sonderzahlung · 60 Mon. · 10.000
544
- // km/Jahr · Details" (same wording/order as CarCard's own PriceTerms leaseTerms).
545
- const condParts: string[] = [];
546
- if (mode === 'leasing') {
547
- condParts.push(
548
- ...t('autobahn:card.price.leaseTerms', {
549
- firstInstallment: eur(down),
550
- months: term,
551
- mileage: annualMileage != null ? eur(annualMileage) : '',
552
- }).split(' · '),
553
- );
554
- } else if (!isCash) {
555
- condParts.push(t('autobahn:finance.downPaymentLabel', { value: eur(down) }));
556
- condParts.push(t('autobahn:finance.monthsLabel', { months: term, count: term }));
557
- }
558
- // ADV-405 follow-up: financing shows the key figures (Kerndaten) in place of the line above —
559
- // only when at least one figure is real, else the old "0 € Anzahlung · 60 Monate" line stays.
560
- const tabKeyFigures = mode === 'fin' ? creditKeyFigures : mode === 'leasing' ? leasingKeyFigures : undefined;
561
- const keyFigures = tabKeyFigures && hasCreditKeyFigures(tabKeyFigures) ? tabKeyFigures : undefined;
562
-
563
- return (
564
- <div className="mcard mcard--elevated fin-calc-card" style={{ padding: 20 }}>
565
- {/* header — desktop only; mobile goes straight into the tabs (see mockup: no card
566
- title above Finanzierung/Leasing/Kaufen on phone). */}
567
- <div className="fin-card-header hide-mobile" style={{ display: 'flex', alignItems: 'center', gap: 10, marginBottom: 14 }}>
568
- <span
569
- style={{
570
- width: 34,
571
- height: 34,
572
- borderRadius: 'var(--md-r-full)',
573
- background: 'var(--md-primary-container)',
574
- display: 'flex',
575
- alignItems: 'center',
576
- justifyContent: 'center',
577
- flex: 'none',
578
- }}
579
- >
580
- <Icon name="tag" size={18} color="var(--md-on-primary-container)" />
581
- </span>
582
- <div style={{ fontFamily: 'var(--md-font-display)', fontSize: 18, fontWeight: 700 }}>{t('autobahn:finance.headerTitle')}</div>
583
- </div>
584
-
585
- {/* payment-type TABS on top — Leasing omitted when the car isn't leasing-eligible, same
586
- rule cardParts.tsx's PriceTabs already applies (car.lease != null there). */}
587
- <div className="fin-tabs" role="tablist">
588
- {(
589
- [
590
- ['fin', 'autobahn:finance.mode.financing'],
591
- ...(leasingAvailable ? ([['leasing', 'autobahn:finance.mode.leasing']] as Array<[FinanceMode, string]>) : []),
592
- ['cash', 'autobahn:finance.mode.cash'],
593
- ] as Array<[FinanceMode, string]>
594
- ).map(([k, labelKey]) => (
595
- <button
596
- key={k}
597
- type="button"
598
- role="tab"
599
- aria-selected={mode === k}
600
- className={'fin-tab' + (mode === k ? ' on' : '')}
601
- onClick={() => onModeChange(k)}
602
- >
603
- {k === 'cash' ? (
604
- <>
605
- {/* cash tab is "Kaufen" on both phone and desktop now — same key both spans. */}
606
- <span className="hide-mobile">{t('autobahn:card.price.buy')}</span>
607
- <span className="show-mobile" style={{ justifyContent: 'center' }}>
608
- {t('autobahn:card.price.buy')}
609
- </span>
610
- </>
611
- ) : (
612
- t(labelKey)
613
- )}
614
- </button>
615
- ))}
616
- </div>
617
-
618
- {/* 2-col grid: rate|pill (row 1) + condLine|bar (row 2) — fixed right column prevents wrapping */}
619
- <div className={'fin-price-grid' + (isCash ? ' fin-price-grid--cash' : '')}>
620
- {/* col 1 row 1: hero rate — Figma: "329 €" all-big, then a small stacked column with
621
- the struck old rate ABOVE "/mtl." (round 11; was a single baseline row) */}
622
- <div className="fin-rate-main">
623
- {/* mobile Kaufen (Figma round 14): struck list price ABOVE the price, right-aligned,
624
- tight to the figure — replaces the Festpreis + UVP lines, which stay desktop-only */}
625
- {isCash && showStrike && (
626
- <div
627
- className="show-mobile"
628
- style={{ justifyContent: 'flex-end', alignItems: 'baseline', gap: 4, lineHeight: 1, marginTop: 7 }}
629
- role="button"
630
- tabIndex={0}
631
- onClick={() => setUvpTooltipOpen((v) => !v)}
632
- >
633
- {/* ADV-423: same size as the struck price next to it (md3.css .pp-uvp-label) */}
634
- <span
635
- className={`pp-uvp-label${
636
- String(Math.round(listPrice as number)).length === 5
637
- ? ' pp-uvp-label--len5'
638
- : String(Math.round(listPrice as number)).length === 4
639
- ? ' pp-uvp-label--len4'
640
- : ''
641
- }`}
642
- >
643
- {t('autobahn:finance.uvp')}
644
- </span>
645
- <span
646
- className={`num pp-hero-old${
647
- String(Math.round(listPrice as number)).length === 5
648
- ? ' pp-hero-old--len5'
649
- : String(Math.round(listPrice as number)).length === 4
650
- ? ' pp-hero-old--len4'
651
- : ''
652
- }`}
653
- >
654
- {eur(Math.round(listPrice as number))} €
655
- <span
656
- className="pp-eyebrow-badge"
657
- role="button"
658
- tabIndex={0}
659
- onClick={(e) => {
660
- e.stopPropagation();
661
- setUvpTooltipOpen((v) => !v);
662
- }}
663
- >
664
- 2
665
- </span>
666
- {uvpTooltipOpen && (
667
- <div className="pp-uvp-tooltip" onClick={(e) => e.stopPropagation()}>
668
- <button
669
- type="button"
670
- className="pp-uvp-tooltip-close"
671
- aria-label={t('autobahn:modal.close')}
672
- onClick={(e) => {
673
- e.stopPropagation();
674
- setUvpTooltipOpen(false);
675
- }}
676
- >
677
- <svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
678
- <path d="M5 5L15 15M15 5L5 15" stroke="white" strokeWidth={2.4} strokeLinecap="round" />
679
- </svg>
680
- </button>
681
- <div className="pp-uvp-tooltip-body">{t('autobahn:card.price.uvpListTooltipBody')}</div>
682
- </div>
683
- )}
684
- </span>
685
- </div>
686
- )}
687
- {/* desktop: same struck list price ABOVE the rate, same fin-rate-old-list styling +
688
- clickable UVP badge/tooltip as the mobile sheet's own Kaufen block.
689
- Wrapper now renders on EVERY Kaufen car (isCash alone, not isCash && showStrike) —
690
- cross-tab height parity (md3.css) reserves this row's height once, assuming it's
691
- always there; a car with no discount used to skip it entirely, landing .fin-rate-main
692
- (and the whole card) ~20px shorter than a discounted one and breaking that parity.
693
- fin-rate-strike-slot (md3.css) gives it a fixed height so the slot itself doesn't
694
- move even though the <s> price inside is still conditional on showStrike. */}
695
- {isCash && (
696
- <div
697
- className="hide-mobile fin-rate-strike-slot"
698
- style={{
699
- display: 'flex',
700
- justifyContent: 'flex-end',
701
- alignItems: 'baseline',
702
- lineHeight: 1,
703
- marginTop: 0,
704
- cursor: showStrike ? 'pointer' : 'default',
705
- }}
706
- role="button"
707
- tabIndex={0}
708
- onClick={() => setUvpTooltipOpen((v) => !v)}
709
- >
710
- {/* ADV-423: "UVP" label right before the struck list price (this slot is desktop-only) */}
711
- {showStrike && <span className="pp-uvp-label">{t('autobahn:finance.uvp')}</span>}
712
- {showStrike && (
713
- <s className="num fin-rate-old fin-rate-old-list">
714
- {eur(listPrice as number)} €
715
- <span
716
- className="pp-eyebrow-badge"
717
- role="button"
718
- tabIndex={0}
719
- onClick={(e) => {
720
- e.stopPropagation();
721
- setUvpTooltipOpen((v) => !v);
722
- }}
723
- >
724
- 2
725
- </span>
726
- {uvpTooltipOpen && (
727
- <div className="pp-uvp-tooltip" onClick={(e) => e.stopPropagation()}>
728
- <button
729
- type="button"
730
- className="pp-uvp-tooltip-close"
731
- aria-label={t('autobahn:modal.close')}
732
- onClick={(e) => {
733
- e.stopPropagation();
734
- setUvpTooltipOpen(false);
735
- }}
736
- >
737
- <svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
738
- <path d="M5 5L15 15M15 5L5 15" stroke="white" strokeWidth={2.4} strokeLinecap="round" />
739
- </svg>
740
- </button>
741
- <div className="pp-uvp-tooltip-body">{t('autobahn:card.price.uvpListTooltipBody')}</div>
742
- </div>
743
- )}
744
- </s>
745
- )}
746
- </div>
747
- )}
748
- <div style={{ display: 'flex', alignItems: 'center', gap: 7 }}>
749
- {isCash ? (
750
- <>
751
- {/* phone: ONE unbreakable "13.249 €" span (a separate € span wraps to its own
752
- line); desktop keeps the number + quiet small € pair */}
753
- <span
754
- className={`num show-mobile fin-rate-cash-mobile${
755
- (() => {
756
- const digits = String(Math.round(price as number)).length;
757
- if (digits >= 8) return ' fin-rate-cash-mobile--len8';
758
- if (digits === 7) return ' fin-rate-cash-mobile--len7';
759
- if (digits === 6) return ' fin-rate-cash-mobile--len6';
760
- return '';
761
- })()
762
- }`}
763
- style={{ fontSize: 48, fontWeight: 800, color: 'var(--md-primary)', letterSpacing: '-2px', whiteSpace: 'nowrap' }}
764
- >
765
- {eur(price)} €<sup>1</sup>
766
- </span>
767
- <span
768
- className="num hide-mobile"
769
- style={{ fontSize: 45, fontWeight: 800, color: 'var(--md-primary)', letterSpacing: '-2px' }}
770
- >
771
- {eur(price)} €<sup>1</sup>
772
- </span>
773
- </>
774
- ) : (
775
- <>
776
- <span
777
- className={`num fin-rate-hero${
778
- (() => {
779
- const digits = String(Math.round(monthly)).length;
780
- if (digits >= 6) return ' fin-rate-hero--len6';
781
- if (digits === 5) return ' fin-rate-hero--len5';
782
- if (digits === 4) return ' fin-rate-hero--len4';
783
- return '';
784
- })()
785
- }`}
786
- style={{ fontSize: 48, fontWeight: 800, color: 'var(--md-primary)', letterSpacing: '-2px' }}
787
- >
788
- {eur(Math.round(monthly))}<span style={{ marginLeft: 6 }}>€</span>
789
- </span>
790
- <span className="fin-rate-unit">
791
- {/* struck old rate (REAL oldMonthlyInstallment; SRP strikes the same source) */}
792
- {oldMonthly != null && (
793
- <span
794
- style={{ display: 'flex', flexDirection: 'column', cursor: 'pointer' }}
795
- role="button"
796
- tabIndex={0}
797
- onClick={() => setUvpTooltipOpen((v) => !v)}
798
- >
799
- <span className="pp-eyebrow">
800
- {t('autobahn:card.price.uvpRateLabel')}
801
- <span
802
- className="pp-eyebrow-badge"
803
- role="button"
804
- tabIndex={0}
805
- onClick={(e) => {
806
- e.stopPropagation();
807
- setUvpTooltipOpen((v) => !v);
808
- }}
809
- >
810
- 3
811
- </span>
812
- {uvpTooltipOpen && (
813
- <div
814
- className={'pp-uvp-tooltip' + (mode === 'leasing' ? ' pp-uvp-tooltip--leasing' : '')}
815
- onClick={(e) => e.stopPropagation()}
816
- >
817
- <button
818
- type="button"
819
- className="pp-uvp-tooltip-close"
820
- aria-label={t('autobahn:modal.close')}
821
- onClick={(e) => {
822
- e.stopPropagation();
823
- setUvpTooltipOpen(false);
824
- }}
825
- >
826
- <svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
827
- <path d="M5 5L15 15M15 5L5 15" stroke="white" strokeWidth={2.4} strokeLinecap="round" />
828
- </svg>
829
- </button>
830
- <div className="pp-uvp-tooltip-body">
831
- {t(
832
- mode === 'leasing'
833
- ? 'autobahn:card.price.uvpRateTooltipBodyLeasing'
834
- : 'autobahn:card.price.uvpRateTooltipBody',
835
- )}
836
- </div>
837
- </div>
838
- )}
839
- </span>
840
- <s
841
- className={`num fin-rate-old fin-rate-example-price${
842
- String(Math.round(oldMonthly)).length >= 5
843
- ? ' fin-rate-example-price--len5'
844
- : String(Math.round(oldMonthly)).length === 4
845
- ? ' fin-rate-example-price--len4'
846
- : ''
847
- }`}
848
- >
849
- {eur(Math.round(oldMonthly))} €
850
- </s>
851
- </span>
852
- )}
853
- {/* no struck old rate above it (strike hidden) — nudge "/mtl." down so it
854
- sits level with the blue hero rate instead of centering high in the row. */}
855
- <span
856
- className="fin-rate-example-suffix"
857
- style={oldMonthly == null ? { paddingTop: 20 } : undefined}
858
- >
859
- {t('autobahn:finance.perMonth')}
860
- </span>
861
- </span>
862
- </>
863
- )}
864
- </div>
865
- {isCash && <div className="md-label-sm hide-mobile">{t('autobahn:finance.fixedPrice')}</div>}
866
- </div>
867
- {/* col 2: pill + eval bar grouped together (display:contents on desktop — no-op,
868
- preserves the original rate|pill / cond|bar auto-placement; mobile turns this into
869
- a real flex column so the two stack tight with a fixed 16px gap). */}
870
- <div className="fin-eval-col">
871
- {/* col 2 row 1: price-rating pill (Figma: bold colored label, NO icon) */}
872
- <div className="fin-eval-pill-cell">
873
- {ratingLabel && (
874
- <span
875
- className={`fin-eval-pill${isGoodTier ? ' fin-eval-pill--good' : ''}`}
876
- style={{ color: evalPillColor, background: `color-mix(in srgb, ${evalPillColor} 16%, transparent)` }}
877
- aria-label={t('autobahn:finance.priceRatingAria', { rating: evalTierLabel })}
878
- >
879
- {evalTierLabel}
880
- {isGoodTier && <sup>4</sup>}
881
- </span>
882
- )}
883
- </div>
884
- {/* segmented evaluation bar (Figma: discrete tiers, not a gradient) */}
885
- <div className="fin-eval-bar-cell">{ratingLabel && <EvalBar tier={evalTier} />}</div>
886
- </div>
887
- {/* col 1 row 2: condition line — financing "0 € Anzahlung · 60 Monate · Finanzierungsdetails",
888
- leasing "25.000 € Sonderzahlung · 60 Mon. · 10.000 km/Jahr · Details". Buy has nothing
889
- to show here (no down payment/term/details link of its own) — not rendered at all
890
- rather than left as an empty reserved-height div.
891
- ADV-405 follow-up: financing with real key figures → the Kerndaten (2 lines, same
892
- .fin-cond grid cell/size/colour, wraps where narrow) ending with the same details link. */}
893
- {keyFigures ? (
894
- <CreditKeyFigures
895
- t={t}
896
- figures={keyFigures}
897
- cls="fin-cond fin-ckf"
898
- details={
899
- onShowDetails && (
900
- <button type="button" className="cc-terms-link" onClick={onShowDetails}>
901
- {mode === 'leasing' ? t('autobahn:card.price.detailsLink') : t('autobahn:finance.financingDetails')}
902
- </button>
903
- )
904
- }
905
- />
906
- ) : !isCash && (
907
- <div className="fin-cond">
908
- {condParts.map((part, i) => (
909
- <React.Fragment key={i}>
910
- {i > 0 && <span className="cc-terms-dot"> · </span>}
911
- {part}
912
- </React.Fragment>
913
- ))}
914
- {onShowDetails && (
915
- <>
916
- <span className="cc-terms-dot"> · </span>
917
- {/* plain underlined text link, same onShowDetails handler as .fin-info used to open. */}
918
- <button type="button" className="cc-terms-link" onClick={onShowDetails}>
919
- {mode === 'leasing' ? t('autobahn:card.price.detailsLink') : t('autobahn:finance.financingDetails')}
920
- </button>
921
- </>
922
- )}
923
- </div>
924
- )}
925
- </div>
926
-
927
- {/* ADV-405/406 Kreditkosten-Hinweis — Preis-Card (mobile) + „Dein Angebot“ (desktop): below the
928
- conditions line, above „Angebot anfragen“/„Anrufen“ (mobile) or „Rate anpassen“ (desktop).
929
- Not on Kaufen (no reserved space — the Kaufen view stays exactly as before). */}
930
- {!isCash && <CreditCostNotice t={t} cls="fin-ccn" />}
931
-
932
- {/* ============================== DESKTOP (≥601px) — unchanged ============================== */}
933
- <div className="hide-mobile">
934
- {/* RATE EDIT (Rate anpassen) — between the rate and the request CTA. fin-adjust--cash:
935
- Kaufen-only margin-top override (0, was the shared 14px) — see md3.css. */}
936
- <div className={'fin-adjust' + (isCash ? ' fin-adjust--cash' : '')}>
937
- <button onClick={() => setAdjust((a) => !a)} style={expanderBtnStyle}>
938
- <span style={{ display: 'inline-flex', alignItems: 'center', gap: 7 }}>
939
- <Icon name={isCash ? 'list' : 'sliders-horizontal'} size={16} color="var(--md-primary)" />
940
- {isCash ? t('autobahn:finance.detailsShow') : t('autobahn:finance.adjustRate')}
941
- </span>
942
- <Icon name={adjust ? 'chevron-up' : 'chevron-down'} size={18} color="var(--md-primary)" />
943
- </button>
944
- {adjust &&
945
- (isCash ? (
946
- <>
947
- <div style={{ marginTop: 4 }}>
948
- <CalcRow label={t('autobahn:finance.paymentLabel')} last={!available && !(addServicesCost != null && onToggleAddServices)}>{t('autobahn:finance.paymentValue')}</CalcRow>
949
- {available && (
950
- <CalcRow label={t('autobahn:finance.availabilityLabel')} last={!(addServicesCost != null && onToggleAddServices)}>
951
- {t('autobahn:finance.availabilityValue')}
952
- </CalcRow>
953
- )}
954
- </div>
955
- {addServicesCost != null && onToggleAddServices && (
956
- <ToggleRow
957
- className="fin-toggle-addservices fin-toggle-addservices--cash"
958
- label={t('autobahn:finance.addServicesToggle')}
959
- price={t('autobahn:finance.addServicesOnce', { value: eur(Math.round(addServicesCost)) })}
960
- checked={!!withAddServices}
961
- disabled={addServicesDisabled}
962
- onChange={onToggleAddServices}
963
- staticNote={t('autobahn:finance.addServicesIncluded')}
964
- tooltip={<AddServicesTooltipBody t={t} isCash />}
965
- tooltipCloseLabel={t('autobahn:modal.close')}
966
- t={t}
967
- />
968
- )}
969
- </>
970
- ) : (
971
- <div style={{ display: 'flex', flexDirection: 'column', marginTop: 8 }}>
972
- <div style={{ marginBottom: 15 }}>
973
- <div style={{ display: 'flex', justifyContent: 'space-between', marginBottom: 6 }}>
974
- <span className="md-title-sm">{t('autobahn:finance.downPaymentSliderLabel')}</span>
975
- <span className="num" style={{ fontWeight: 700 }}>
976
- {eur(down)} €
977
- </span>
978
- </div>
979
- <Slider
980
- min={downMin}
981
- max={downMax}
982
- step={downStep}
983
- value={down}
984
- onChange={onDownChange}
985
- fmt={(v) => `${eur(Number(v))} €`}
986
- />
987
- </div>
988
- {annualMileage != null && onAnnualMileageChange && (
989
- <div style={{ marginBottom: 15 }}>
990
- <div style={{ display: 'flex', justifyContent: 'space-between', marginBottom: 6 }}>
991
- <span className="md-title-sm">{t('autobahn:finance.annualMileageLabel')}</span>
992
- <span className="num" style={{ fontWeight: 700 }}>
993
- {eur(annualMileage)} km
994
- </span>
995
- </div>
996
- <Slider
997
- min={annualMileageMin}
998
- max={annualMileageMax}
999
- step={annualMileageStep}
1000
- value={annualMileage}
1001
- onChange={onAnnualMileageChange}
1002
- fmt={(v) => `${eur(Number(v))} km`}
1003
- />
1004
- </div>
1005
- )}
1006
- <div style={{ marginBottom: 15 }}>
1007
- <div className="md-title-sm" style={{ marginBottom: 8 }}>
1008
- {t('autobahn:finance.termSelection')}
1009
- </div>
1010
- <TermChips options={terms.filter((v) => v !== 12 && v !== 96)} value={term} onChange={onTermChange} t={t} />
1011
- </div>
1012
- {/* same Mit-Schlussrate / Rundum-Sorglos-Paket toggles as the mobile sheet / modal
1013
- desktop block — replaces the static Kaufpreis/Garantie/Lieferung rows. */}
1014
- {!isLease && onToggleFinalInstallment && (
1015
- <ToggleRow
1016
- className="fin-toggle-final"
1017
- label={t('autobahn:finance.finalInstallmentToggle')}
1018
- checked={!!withFinalInstallment}
1019
- onChange={onToggleFinalInstallment}
1020
- />
1021
- )}
1022
- {addServicesCost != null && onToggleAddServices && (
1023
- <ToggleRow
1024
- className={'fin-toggle-addservices' + (isLease ? ' fin-toggle-addservices--leasing' : '')}
1025
- label={t('autobahn:finance.addServicesToggle')}
1026
- price={t('autobahn:finance.addServicesPerMonth', { value: eur(Math.round(addServicesCost)) })}
1027
- checked={!!withAddServices}
1028
- disabled={addServicesDisabled}
1029
- onChange={onToggleAddServices}
1030
- tooltip={<AddServicesTooltipBody t={t} isLease={isLease} />}
1031
- tooltipCloseLabel={t('autobahn:modal.close')}
1032
- t={t}
1033
- />
1034
- )}
1035
- </div>
1036
- ))}
1037
- </div>
1038
-
1039
- {/* REQUEST CTA */}
1040
- <Button
1041
- variant="filled"
1042
- block
1043
- size="lg"
1044
- icon="shield-check"
1045
- className={secured ? 'fin-cta-secured' : undefined}
1046
- style={{ marginTop: 14 }}
1047
- onClick={onSecure}
1048
- >
1049
- {secured && secureLabel ? secureLabel : t('autobahn:finance.secureOffer')}
1050
- </Button>
1051
- {/* phone CTA — touch only (hidden on desktop via .fin-call) */}
1052
- <div className="fin-call">
1053
- <Button variant="outlined" block icon="phone" onClick={onCall}>
1054
- {phone}
1055
- </Button>
1056
- </div>
1057
-
1058
- {/* auto.de-ID in front of the Finanzierungs-/Leasingdetails link — one row, under everything */}
1059
- {(autoDeId || (!isCash && onShowDetails)) && (
1060
- <div className="fin-info">
1061
- {autoDeId && <span className="fin-id">auto.de-ID {autoDeId}</span>}
1062
- {!isCash && onShowDetails && (
1063
- <DetailsLink
1064
- label={mode === 'leasing' ? t('autobahn:finance.leasingDetails') : t('autobahn:finance.financingDetails')}
1065
- onClick={onShowDetails}
1066
- />
1067
- )}
1068
- </div>
1069
- )}
1070
- </div>
1071
-
1072
- {/* ============================== MOBILE (≤600px) — new layout ============================== */}
1073
- <div className="show-mobile" style={{ flexDirection: 'column' }}>
1074
- {/* side-by-side CTAs — mockup ratio ~2:1, with the tiny auto.de-ID sitting
1075
- directly under the Anrufen button (not in its own full-width row). */}
1076
- <div className="fin-cta-row" style={{ display: 'flex', gap: 10, alignItems: 'flex-start' }}>
1077
- {/* Figma CTA icon: document + check badge (composed — no single lucide glyph) */}
1078
- <Button
1079
- variant="filled"
1080
- size="lg"
1081
- className={secured ? 'fin-cta-secured' : undefined}
1082
- style={{ width: 216, height: 50, paddingLeft: 0, paddingRight: 9, gap: secured ? 3 : 18 }}
1083
- onClick={onSecure}
1084
- >
1085
- {/* size 23 either way — was 18 for the secured (shield-check) state, notably
1086
- smaller than DocCheckIcon's 23 in the default state despite sharing the exact
1087
- same 50px button box; nothing about switching to "already secured" should
1088
- shrink the icon. */}
1089
- {secured ? <Icon name="shield-check" size={23} /> : <DocCheckIcon size={23} />}
1090
- {secured && secureLabel ? secureLabel : t('autobahn:finance.secureOffer')}
1091
- </Button>
1092
- <div style={{ flex: 1, display: 'flex', flexDirection: 'column', gap: 4, minWidth: 0 }}>
1093
- <Button variant="outlined" size="lg" icon="phone" style={{ width: 112, height: 50 }} onClick={onCall}>
1094
- {t('autobahn:finance.callCta')}
1095
- </Button>
1096
- {autoDeId && (
1097
- <span
1098
- className="num"
1099
- style={{ fontSize: 10, fontWeight: 700, color: 'var(--md-primary)', textAlign: 'center', whiteSpace: 'nowrap' }}
1100
- >
1101
- auto.de ID: {autoDeId}
1102
- </span>
1103
- )}
1104
- </div>
1105
- </div>
1106
-
1107
- {/* Persönliche Beratung — icon + one line (the details link now lives in .fin-cond above) */}
1108
- <div className="fin-info" style={{ justifyContent: 'flex-start', paddingLeft: 15 }}>
1109
- <Icon name="user" size={26} color="var(--md-on-surface-variant)" style={{ flex: 'none', marginRight: 20 }} />
1110
- <span className="fin-info-line">{t('autobahn:finance.personalConsultationLine')}</span>
1111
- </div>
1112
-
1113
- {/* "Rate anpassen" / "Details anzeigen" — opens the full bottom sheet (not an inline expander) */}
1114
- {onOpenAdjust && (
1115
- <button
1116
- type="button"
1117
- onClick={onOpenAdjust}
1118
- style={{ ...expanderBtnStyle, borderTop: '1px solid var(--md-outline-variant)', marginTop: 11, padding: '11px 0 2px 21px' }}
1119
- >
1120
- <span style={{ display: 'inline-flex', alignItems: 'center', gap: 21 }}>
1121
- <Icon name="sliders-horizontal" size={23} color="var(--md-primary)" />
1122
- <span className="fin-adjust-btn-label">
1123
- {isCash ? t('autobahn:finance.detailsShow') : t('autobahn:finance.adjustRate')}
1124
- </span>
1125
- </span>
1126
- <Icon name="chevron-right" size={23} color="var(--md-primary)" />
1127
- </button>
1128
- )}
1129
- </div>
1130
- </div>
1131
- );
1132
- };
1133
-
1134
- export default FinanceCalculator;
1
+ // Autobahn (auto.de redesign) — VDP offer / finance card (Finanzierung / Leasing /
2
+ // Barzahlung).
3
+ //
4
+ // Structure (desktop rethink, tabs-on-top): payment-type TABS at the top (MD3 underline tabs),
5
+ // then the rate (with any discount), then the "Rate anpassen" rate-editor, then the primary
6
+ // "Angebot sichern" request CTA, and finally the Finanzierungs-/Leasingdetails info + popup link
7
+ // at the foot. Laufzeit is chosen via chips (discrete terms), not a slider.
8
+ //
9
+ // CONTROLLED / PRESENTATIONAL — computes NOTHING financial: `mode`, `monthly`, `down`, `term` and
10
+ // the slider/chip bounds all arrive as props; segment/slider/chip changes are reported back via
11
+ // `onModeChange` / `onDownChange` / `onTermChange`. The real numbers come from `financingStore`.
12
+ // The only local state is the `adjust` expander (pure view state).
13
+ //
14
+ // Renders correctly only inside a `<div className="md3">` subtree.
15
+
16
+ import React, { useState, useEffect } from 'react';
17
+ import { TranslationFunction } from '../types';
18
+
19
+ import { Button, Icon, Switch, CreditCostNotice, CreditKeyFigures, hasCreditKeyFigures } from '../ui';
20
+ import type { CreditKeyFiguresData } from '../ui';
21
+ import { TIER_LABELS, TIER_KEYS, TIER_COLORS } from '../constants';
22
+
23
+ /** Payment mode segment keys. Mirrors the design's ['fin','leasing','cash']. */
24
+ export type FinanceMode = 'fin' | 'leasing' | 'cash';
25
+
26
+ export interface SliderProps {
27
+ min: number;
28
+ max: number;
29
+ step?: number;
30
+ value: number;
31
+ onChange: (value: number) => void;
32
+ /** formats the min/max end labels (and is reused by callers for the value). */
33
+ fmt?: (v: number) => React.ReactNode;
34
+ /** render the current value in a floating bubble above the thumb (Figma sheet sliders). */
35
+ bubble?: boolean;
36
+ /** space reserved below the rail for the bubble's tail (Figma differs per sheet: fin vs leasing). */
37
+ bubblePaddingBottom?: number;
38
+ }
39
+
40
+ /**
41
+ * Range slider with a filled track and min/max end labels. The track fill is a
42
+ * linear-gradient driven by the value's position; the design's `.mslider` class
43
+ * styles the thumb/rail. With `bubble` the current value floats above the thumb
44
+ * (mockup "Rate anpassen" sliders) instead of the caller printing it elsewhere.
45
+ */
46
+ export const Slider: React.FunctionComponent<SliderProps> = ({
47
+ min,
48
+ max,
49
+ step = 1,
50
+ value,
51
+ onChange,
52
+ fmt = (v) => v,
53
+ bubble,
54
+ bubblePaddingBottom = 34,
55
+ }) => {
56
+ // Local mirror of `value`, updated INSTANTLY on every native input event. Callers commonly
57
+ // debounce their own onChange (e.g. CheckoutFinancePanelNext's 50ms setCommonUserConfig,
58
+ // which also triggers a MobX-driven re-render of a much bigger subtree) — without this, the
59
+ // thumb still drags natively/smoothly (the browser owns that), but the gradient fill and any
60
+ // bubble label are driven by the `value` PROP, which only catches up once the debounced commit
61
+ // finally lands, so the fill visibly lags/stutters behind the thumb during a fast drag. Synced
62
+ // back to the prop via useEffect for externally-driven changes (e.g. a reset button).
63
+ const [localValue, setLocalValue] = useState(value);
64
+ useEffect(() => { setLocalValue(value); }, [value]);
65
+
66
+ const span = max - min;
67
+ const pct = span > 0 ? ((localValue - min) / span) * 100 : 0;
68
+ return (
69
+ <div>
70
+ <div style={{ position: 'relative', paddingTop: bubble ? 44 : 0, paddingBottom: bubble ? bubblePaddingBottom : 0 }}>
71
+ {bubble && (
72
+ // thumb is 22px wide: interpolate the bubble anchor between half-thumb insets so it
73
+ // tracks the thumb center (a plain pct% drifts at the rail ends)
74
+ <span className="slider-bubble num" style={{ left: `calc(11px + (100% - 22px) * ${pct / 100})` }}>
75
+ {fmt(localValue)}
76
+ </span>
77
+ )}
78
+ <input
79
+ type="range"
80
+ className="mslider"
81
+ min={min}
82
+ max={max}
83
+ step={step}
84
+ value={localValue}
85
+ onChange={(e) => {
86
+ const v = Number(e.target.value);
87
+ setLocalValue(v);
88
+ onChange(v);
89
+ }}
90
+ style={{ background: `linear-gradient(90deg, var(--md-primary) ${pct}%, var(--md-sc-highest) ${pct}%)` }}
91
+ />
92
+ </div>
93
+ {!bubble && (
94
+ <div style={{ display: 'flex', justifyContent: 'space-between', marginTop: 4 }}>
95
+ <span className="md-label-sm">{fmt(min)}</span>
96
+ <span className="md-label-sm">{fmt(max)}</span>
97
+ </div>
98
+ )}
99
+ </div>
100
+ );
101
+ };
102
+
103
+ /**
104
+ * Segmented price-evaluation bar (Figma: 5 discrete tier segments, NOT a gradient) with a
105
+ * white ring marker. `leftPct` overrides the marker position (the Marktwert gauge positions
106
+ * it continuously); default = centered on the tier segment.
107
+ */
108
+ export const EvalBar: React.FunctionComponent<{ tier: number; leftPct?: number }> = ({ tier, leftPct }) => (
109
+ <div className="fin-eval-bar">
110
+ {TIER_COLORS.map((c, i) => (
111
+ <span key={i} className="fin-eval-seg" style={{ background: c }} />
112
+ ))}
113
+ <div
114
+ className={`fin-eval-thumb${TIER_KEYS[Math.max(0, Math.min(4, tier))] === 'good' ? ' fin-eval-thumb--good' : ''}`}
115
+ style={{ left: `${leftPct != null ? leftPct : (tier + 0.5) * 20}%`, borderColor: TIER_COLORS[Math.max(0, Math.min(4, tier))] }}
116
+ />
117
+ </div>
118
+ );
119
+
120
+ /** Figma CTA icon — document with a check-in-circle badge over its bottom-right corner
121
+ * (no single lucide glyph matches; composed from file-text + a knocked-out check-circle).
122
+ * The badge backdrop assumes a filled (primary) button. */
123
+ export const DocCheckIcon: React.FunctionComponent<{ size?: number }> = ({ size = 19 }) => {
124
+ // inline width/height on BOTH icons — `.mbtn .lucide { width/height: 18px }` otherwise
125
+ // inflates the badge to full icon size and it swallows the document
126
+ const badge = Math.max(9, Math.round(size * 0.5));
127
+ return (
128
+ <span style={{ position: 'relative', display: 'inline-flex', flex: 'none' }}>
129
+ <Icon name="file-text" size={size} stroke={2} style={{ width: size, height: size }} />
130
+ <span
131
+ style={{
132
+ position: 'absolute',
133
+ right: -3,
134
+ bottom: -2,
135
+ display: 'flex',
136
+ borderRadius: '50%',
137
+ background: 'var(--md-primary)',
138
+ padding: 1,
139
+ }}
140
+ >
141
+ <Icon name="check-circle" size={badge} stroke={2.8} style={{ width: badge, height: badge }} />
142
+ </span>
143
+ </span>
144
+ );
145
+ };
146
+
147
+ export interface TermChipsProps {
148
+ /** the selectable term values (months), e.g. [12,24,36,48,60,72]. */
149
+ options: number[];
150
+ value: number;
151
+ onChange: (term: number) => void;
152
+ /** i18n function (drilled from the page). */
153
+ t: TranslationFunction;
154
+ }
155
+
156
+ /** Laufzeit selector — discrete term values as tappable chips (replaces the fiddly slider). */
157
+ export const TermChips: React.FunctionComponent<TermChipsProps> = ({ options, value, onChange, t }) => (
158
+ <div className="term-chips" role="group" aria-label={t('autobahn:finance.termSelection')}>
159
+ {options.map((m) => (
160
+ <button
161
+ key={m}
162
+ type="button"
163
+ aria-pressed={m === value}
164
+ className={'term-chip' + (m === value ? ' on' : '')}
165
+ onClick={() => onChange(m)}
166
+ >
167
+ {m}
168
+ <span className="tc-unit">{t('autobahn:finance.monthUnit')}</span>
169
+ </button>
170
+ ))}
171
+ </div>
172
+ );
173
+
174
+ export interface CalcRowProps {
175
+ label: React.ReactNode;
176
+ /** when true, drops the bottom hairline (last row). */
177
+ last?: boolean;
178
+ children?: React.ReactNode;
179
+ className?: string;
180
+ }
181
+
182
+ /** One label/value row inside the "Rate anpassen" / "Details" expander. */
183
+ export const CalcRow: React.FunctionComponent<CalcRowProps> = ({ label, last, children, className }) => (
184
+ <div
185
+ className={'calcrow' + (className ? ' ' + className : '')}
186
+ style={{
187
+ display: 'flex',
188
+ justifyContent: 'space-between',
189
+ alignItems: 'baseline',
190
+ gap: 12,
191
+ padding: '8px 0',
192
+ borderBottom: last ? 0 : '1px solid var(--md-outline-variant)',
193
+ }}
194
+ >
195
+ <span className="md-label-sm calcrow-label">{label}</span>
196
+ <span className="num calcrow-value" style={{ fontSize: 13.5, fontWeight: 600 }}>
197
+ {children}
198
+ </span>
199
+ </div>
200
+ );
201
+
202
+ /** full-width label(+optional trailing price) / Switch row — Switch itself is inline-flex
203
+ * (track+label), so the "label ...... price switch" full-row layout can't be expressed via
204
+ * Switch's `label` prop (which renders track-then-label, not a full-width justified row). */
205
+ export const ToggleRow: React.FunctionComponent<{
206
+ label: string;
207
+ price?: string;
208
+ checked: boolean;
209
+ disabled?: boolean;
210
+ onChange: (checked: boolean) => void;
211
+ className?: string;
212
+ /** cash mode: the package is always included — shows a static "inklusive" note instead of the switch. */
213
+ staticNote?: string;
214
+ /** when set, the info icon becomes clickable and opens a popover with this body (e.g. the
215
+ * Rundum-Sorglos-Paket contents) — "Mit Schlussrate" rows omit this, keeping their icon inert. */
216
+ tooltip?: React.ReactNode;
217
+ /** aria-label for the popover's close button — required together with `tooltip`. */
218
+ tooltipCloseLabel?: string;
219
+ /** required together with `tooltip` — builds the trigger's own accessible name (see `infoLabel` below). */
220
+ t?: TranslationFunction;
221
+ }> = ({ label, price, checked, disabled, onChange, className, staticNote, tooltip, tooltipCloseLabel, t }) => {
222
+ const [tooltipOpen, setTooltipOpen] = useState(false);
223
+ const toggleTooltip = (e: { stopPropagation: () => void }) => {
224
+ e.stopPropagation();
225
+ setTooltipOpen((v) => !v);
226
+ };
227
+ // the visible label alone ("Rundum-Sorglos-Paket") reads as ambiguous out of context (toggle
228
+ // the package? show info about it?) — spell out what activating the trigger actually does.
229
+ const infoLabel = tooltip && t ? t('autobahn:finance.moreInfoAria', { label }) : undefined;
230
+ return (
231
+ <div
232
+ className={className}
233
+ style={{
234
+ display: 'flex',
235
+ alignItems: 'center',
236
+ justifyContent: staticNote ? undefined : 'space-between',
237
+ gap: 10,
238
+ position: tooltip ? 'relative' : undefined,
239
+ }}
240
+ >
241
+ <span className="md-title-sm" style={{ display: 'inline-flex', alignItems: 'center', gap: 5 }}>
242
+ {label}
243
+ {/* custom info glyph (not the shared lucide "info" from the Icon registry — that name is
244
+ used in many unrelated places, this swap is scoped to just the Rundum-Sorglos-Paket
245
+ tooltip trigger). Shared by all three tabs (Finanzierung/Leasing/Kaufen) and both
246
+ desktop/mobile — ToggleRow itself is the one shared render for all of them. Viewbox
247
+ already bounds every path (1.875–13.125 within 0–15), so no clip-path needed.
248
+ The interactive/focusable/touch-target element is THIS icon wrapper only — the label
249
+ text next to it is plain, inert text, not part of the trigger. */}
250
+ {tooltip && (
251
+ <span
252
+ className="fin-toggle-info-trigger"
253
+ style={{ display: 'inline-flex', cursor: 'pointer' }}
254
+ role="button"
255
+ tabIndex={0}
256
+ aria-label={infoLabel}
257
+ aria-expanded={tooltipOpen}
258
+ onClick={toggleTooltip}
259
+ onKeyDown={(e) => {
260
+ // ARIA authoring practices: a role="button" element must answer to both Enter and
261
+ // Space, not just Enter — a native <button> gets this for free, this span doesn't.
262
+ if (e.key === 'Enter' || e.key === ' ') {
263
+ e.preventDefault();
264
+ toggleTooltip(e);
265
+ }
266
+ }}
267
+ >
268
+ <svg width="15" height="15" viewBox="0 0 15 15" fill="none" xmlns="http://www.w3.org/2000/svg" className="lucide">
269
+ <path d="M7.5 13.125C10.6066 13.125 13.125 10.6066 13.125 7.5C13.125 4.3934 10.6066 1.875 7.5 1.875C4.3934 1.875 1.875 4.3934 1.875 7.5C1.875 10.6066 4.3934 13.125 7.5 13.125Z" stroke="#8B98AA" strokeWidth={1.8} />
270
+ <path d="M7.5 7.2V10.5125" stroke="#8B98AA" strokeWidth={1.8} strokeLinecap="round" />
271
+ <path d="M7.5 4.8125H7.50625" stroke="#8B98AA" strokeWidth={2.4} strokeLinecap="round" />
272
+ </svg>
273
+ </span>
274
+ )}
275
+ </span>
276
+ {tooltip && tooltipOpen && (
277
+ <div className="pp-uvp-tooltip fin-toggle-tooltip" onClick={(e) => e.stopPropagation()}>
278
+ <button
279
+ type="button"
280
+ className="pp-uvp-tooltip-close fin-toggle-tooltip-close"
281
+ aria-label={tooltipCloseLabel}
282
+ onClick={(e) => {
283
+ e.stopPropagation();
284
+ setTooltipOpen(false);
285
+ }}
286
+ >
287
+ <svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
288
+ <path d="M5 5L15 15M15 5L5 15" stroke="white" strokeWidth={2.4} strokeLinecap="round" />
289
+ </svg>
290
+ </button>
291
+ <div className="pp-uvp-tooltip-body fin-toggle-tooltip-body">{tooltip}</div>
292
+ </div>
293
+ )}
294
+ <div style={{ display: 'flex', alignItems: 'center', gap: 10, marginLeft: staticNote ? 'auto' : undefined }}>
295
+ {/* staticNote (cash mode: package is always included, price already baked into the
296
+ fixed price above) fully replaces the price+switch pair — showing "+1.499 €" right
297
+ next to "inklusive" read as contradictory, so price is suppressed whenever
298
+ staticNote is set, not just the switch. */}
299
+ {price && !staticNote && (
300
+ <span className="num" style={{ fontWeight: 700, fontSize: 13.5 }}>
301
+ {price}
302
+ </span>
303
+ )}
304
+ {staticNote ? (
305
+ <span style={{ fontFamily: 'Arial, Arimo, sans-serif', fontWeight: 400, fontSize: 15, lineHeight: '17px', color: '#0E2238' }}>
306
+ {staticNote}
307
+ </span>
308
+ ) : (
309
+ <Switch checked={checked} disabled={disabled} onChange={(e) => onChange(e.target.checked)} ariaLabel={label} />
310
+ )}
311
+ </div>
312
+ </div>
313
+ );
314
+ };
315
+
316
+ /** body content for the "Rundum-Sorglos-Paket" ToggleRow tooltip — intro sentence, bold heading,
317
+ * the package's contents as a bullet list, then (financing/leasing only) a closing paragraph
318
+ * explaining the one-off-vs-financed payment choice. Shared by every addServicesToggle
319
+ * ToggleRow (FinanceCalculator's own card + VdpModules' modal/mobile-sheet instances); intro/
320
+ * outro vary by mode since cash mode has no "financed into the rate" option. */
321
+ export const AddServicesTooltipBody: React.FunctionComponent<{ t: TranslationFunction; isCash?: boolean; isLease?: boolean }> = ({
322
+ t,
323
+ isCash,
324
+ isLease,
325
+ }) => (
326
+ <>
327
+ <p style={{ margin: '0 0 8px' }}>
328
+ {t(isCash ? 'autobahn:finance.addServicesTooltipIntroCash' : 'autobahn:finance.addServicesTooltipIntroFinanced')}
329
+ </p>
330
+ <p style={{ fontFamily: 'Arial, Arimo, sans-serif', fontWeight: 700, fontSize: 10, lineHeight: '13px', color: '#0E2238', margin: '0 0 4px' }}>
331
+ {t('autobahn:finance.addServicesTooltipHeading')}
332
+ </p>
333
+ <ul style={{ margin: 0, padding: '0 0 0 14px' }}>
334
+ {t('autobahn:finance.addServicesTooltipItems')
335
+ .split('\n')
336
+ .map((item) => (
337
+ <li key={item}>{item}</li>
338
+ ))}
339
+ </ul>
340
+ {!isCash && (
341
+ <p style={{ margin: '8px 0 0' }}>
342
+ {t(isLease ? 'autobahn:finance.addServicesTooltipOutroLeasing' : 'autobahn:finance.addServicesTooltipOutroFinancing')}
343
+ </p>
344
+ )}
345
+ </>
346
+ );
347
+
348
+ export interface FinanceCalculatorProps {
349
+ /** active payment mode (controlled). */
350
+ mode: FinanceMode;
351
+ /** purchase price in EUR (the cash mode hero). */
352
+ price: number;
353
+ /** previous/list price — when > price, shown struck through as the UVP in cash mode (real discount). */
354
+ listPrice?: number;
355
+ /** auto.de-ID reference code — shown with the financing/leasing condition line. */
356
+ autoDeId?: string;
357
+ /** price-rating label, e.g. 'Guter Preis' — drives the Preisbewertung indicator. */
358
+ ratingLabel?: string;
359
+ /** computed monthly rate in EUR for the current mode — supplied, NOT computed here. */
360
+ monthly: number;
361
+ /** struck old monthly rate (fe-financing oldMonthlyInstallment, isStrikeShown-gated) —
362
+ * rendered as the red line-through figure next to the hero rate (fin/leasing only). */
363
+ oldMonthly?: number;
364
+ /** effective annual rate (%) for the current mode — supplied, NOT computed here. */
365
+ apr: number;
366
+ /** ADV-405 follow-up: financing key figures (Kerndaten) of the CURRENT calculation — the same
367
+ * financing-config values the Finanzierungsdetails layer shows (paybackPeriod, netLoanAmount,
368
+ * totalFinancingAmount else grossLoanAmount, nominalInterestRate, annualPercentageRate). When
369
+ * at least one is real, the financing conditions line shows them instead of "0 € Anzahlung ·
370
+ * 60 Monate". Financing only (leasing/Kaufen ignore it); omit to keep the old line. */
371
+ creditKeyFigures?: CreditKeyFiguresData;
372
+ /** ADV-405 follow-up (leasing confirmed 19.11): leasing key figures of the CURRENT leasing
373
+ * calculation (kind 'leasing', ui/CreditKeyFigures leasingKeyFigures — the Leasingdetails
374
+ * layer's own figures). Shown on the Leasing tab instead of "… Sonderzahlung · … Mon. · … km/Jahr"
375
+ * when at least one is real; omit to keep the old line. */
376
+ leasingKeyFigures?: CreditKeyFiguresData;
377
+ /** current down payment in EUR (controlled). */
378
+ down: number;
379
+ /** current term in months (controlled). */
380
+ term: number;
381
+ /** down-payment slider bounds. */
382
+ downMin: number;
383
+ downMax: number;
384
+ /** down-payment slider step (EUR). */
385
+ downStep?: number;
386
+ /** term slider bounds (months) — used to derive chip options when termOptions is absent. */
387
+ termMin: number;
388
+ termMax: number;
389
+ /** term slider step (months). */
390
+ termStep?: number;
391
+ /** the discrete selectable terms (months) for the Laufzeit chips. */
392
+ termOptions?: number[];
393
+ /** annual mileage in km (controlled) — leasing/financing Laufleistung/Jahr. Omit to hide the slider. */
394
+ annualMileage?: number;
395
+ /** annual-mileage slider bounds + step (km). */
396
+ annualMileageMin?: number;
397
+ annualMileageMax?: number;
398
+ annualMileageStep?: number;
399
+ /** annual-mileage slider changed. */
400
+ onAnnualMileageChange?: (km: number) => void;
401
+ /** "Mit Schlussrate" toggle state (financing only; leasing has no balloon concept). Omit
402
+ * onToggleFinalInstallment to hide the row. */
403
+ withFinalInstallment?: boolean;
404
+ onToggleFinalInstallment?: (checked: boolean) => void;
405
+ /** "Rundum-Sorglos-Paket" toggle state (fin/leasing). Omit addServicesCost or
406
+ * onToggleAddServices to hide the row. */
407
+ withAddServices?: boolean;
408
+ addServicesCost?: number;
409
+ addServicesDisabled?: boolean;
410
+ onToggleAddServices?: (checked: boolean) => void;
411
+ /** Kaufen tab only — real carStore.isAvailable, drives the Verfügbarkeit row (replaces the
412
+ * static Lieferung row). Same source as VdpTrustRow's "Sofort verfügbar" badge. */
413
+ available?: boolean;
414
+ /** phone number shown on the secondary CTA (touch only). */
415
+ phone?: string;
416
+ /** primary CTA click (Angebot sichern). */
417
+ onSecure?: () => void;
418
+ /** true once the customer already has an offer request/checkout in progress for this car —
419
+ * turns the primary CTA green (see .fin-cta-secured) instead of the default filled style. */
420
+ secured?: boolean;
421
+ /** overrides the primary CTA label while `secured` is true (e.g. "Zur Bestellung"). Ignored
422
+ * when `secured` is false — the CTA keeps its own default label in that case. */
423
+ secureLabel?: string;
424
+ /** secondary CTA click (phone). */
425
+ onCall?: () => void;
426
+ /** open the Finanzierungs-/Leasingdetails popup (full breakdown + legal, expanded). Omit to hide the link. */
427
+ onShowDetails?: () => void;
428
+ /** mobile only: open the "Rate anpassen" / "Details anzeigen" sheet (collapsed/default view).
429
+ * Omit to hide the trigger row (falls back to the desktop inline expander). */
430
+ onOpenAdjust?: () => void;
431
+ /** mode segment changed. */
432
+ onModeChange: (mode: FinanceMode) => void;
433
+ /** down-payment slider changed. */
434
+ onDownChange: (down: number) => void;
435
+ /** term changed. */
436
+ onTermChange: (term: number) => void;
437
+ /** whether leasing is actually offered for this car (financingConfig.leasing.isActive — same
438
+ * age/mileage-gated flag SearchResultsStore.getLeasingActive stamps for the cards, see
439
+ * cardParts.tsx's PriceTabs / toAutobahnCar.ts's `lease`). Default true keeps existing callers'
440
+ * behavior; the VDP page passes the real computed value. Hides the Leasing tab when false,
441
+ * same as the card — instead of showing a tab that would compute/display a rate the car isn't
442
+ * eligible for. */
443
+ leasingAvailable?: boolean;
444
+ /** i18n function (drilled from the page). */
445
+ t: TranslationFunction;
446
+ }
447
+
448
+ const eur = (n: number): string => n.toLocaleString('de-DE');
449
+
450
+ /** build a [min..max] step range (fallback term options when none are supplied). */
451
+ const range = (min: number, max: number, step: number): number[] => {
452
+ const out: number[] = [];
453
+ for (let v = min; v <= max; v += step || 12) out.push(v);
454
+ return out.length ? out : [min];
455
+ };
456
+
457
+ /** quiet primary-colored text link (Finanzierungsdetails / Details anzeigen). */
458
+ const DetailsLink: React.FunctionComponent<{ label: string; onClick: () => void }> = ({ label, onClick }) => (
459
+ <button
460
+ type="button"
461
+ onClick={onClick}
462
+ style={{
463
+ display: 'inline-flex',
464
+ alignItems: 'center',
465
+ gap: 5,
466
+ background: 'none',
467
+ border: 0,
468
+ padding: 0,
469
+ cursor: 'pointer',
470
+ color: 'var(--md-primary)',
471
+ font: 'inherit',
472
+ fontSize: 13,
473
+ fontWeight: 600,
474
+ }}
475
+ >
476
+ <Icon name="info" size={15} color="var(--md-primary)" />
477
+ {label}
478
+ </button>
479
+ );
480
+
481
+ /** "Rate anpassen" / "Details anzeigen" expander toggle button. */
482
+ export const expanderBtnStyle: React.CSSProperties = {
483
+ width: '100%',
484
+ background: 'none',
485
+ border: 0,
486
+ cursor: 'pointer',
487
+ display: 'flex',
488
+ alignItems: 'center',
489
+ justifyContent: 'space-between',
490
+ padding: '0 0 2px',
491
+ color: 'var(--md-primary)',
492
+ fontWeight: 600,
493
+ fontSize: 14,
494
+ };
495
+
496
+ const FinanceCalculator: React.FunctionComponent<FinanceCalculatorProps> = ({
497
+ mode,
498
+ price,
499
+ listPrice,
500
+ autoDeId,
501
+ ratingLabel,
502
+ monthly,
503
+ oldMonthly,
504
+ creditKeyFigures,
505
+ leasingKeyFigures,
506
+ down,
507
+ term,
508
+ downMin,
509
+ downMax,
510
+ downStep = 500,
511
+ termMin,
512
+ termMax,
513
+ termStep = 6,
514
+ termOptions,
515
+ annualMileage,
516
+ annualMileageMin = 5000,
517
+ annualMileageMax = 60000,
518
+ annualMileageStep = 5000,
519
+ onAnnualMileageChange,
520
+ withFinalInstallment,
521
+ onToggleFinalInstallment,
522
+ withAddServices,
523
+ addServicesCost,
524
+ addServicesDisabled,
525
+ onToggleAddServices,
526
+ available,
527
+ phone = '0800 40 30 182',
528
+ onSecure,
529
+ secured,
530
+ secureLabel,
531
+ onCall,
532
+ onShowDetails,
533
+ onOpenAdjust,
534
+ onModeChange,
535
+ onDownChange,
536
+ onTermChange,
537
+ leasingAvailable = true,
538
+ t,
539
+ }) => {
540
+ // Pure view state only — whether the adjust/details expander is open.
541
+ const [adjust, setAdjust] = useState(false);
542
+ // whether the "UVP-Rate" footnote popover (fin/leasing) is open — same widget as CarCard's.
543
+ const [uvpTooltipOpen, setUvpTooltipOpen] = useState(false);
544
+ const isCash = mode === 'cash';
545
+ const isLease = mode === 'leasing';
546
+ const terms = termOptions && termOptions.length ? termOptions : range(termMin, termMax, termStep);
547
+ const showStrike = listPrice != null && listPrice > price;
548
+ // price-evaluation tier from the rating label (defaults to 'Guter Preis' tier when unmapped).
549
+ const tierIdx = TIER_LABELS.indexOf(ratingLabel as (typeof TIER_LABELS)[number]);
550
+ const evalTier = tierIdx >= 0 ? tierIdx : 1;
551
+ const isGoodTier = TIER_KEYS[evalTier] === 'good';
552
+ // each tier shows its own real label now (Top/Guter/Fairer/Erhöht/Hoher Preis) — no more
553
+ // collapsing 'good' onto the "Top-Preis" claim. Pill styling (colour/class/footnote) unchanged.
554
+ const evalTierLabel = t('autobahn:tier.' + TIER_KEYS[evalTier]);
555
+ const evalPillColor = isGoodTier ? TIER_COLORS[0] : TIER_COLORS[evalTier];
556
+ // condition summary (current selection) + its own details link — financing: "0 € Anzahlung ·
557
+ // 60 Monate · Finanzierungsdetails"; leasing: "25.000 € Sonderzahlung · 60 Mon. · 10.000
558
+ // km/Jahr · Details" (same wording/order as CarCard's own PriceTerms leaseTerms).
559
+ const condParts: string[] = [];
560
+ if (mode === 'leasing') {
561
+ condParts.push(
562
+ ...t('autobahn:card.price.leaseTerms', {
563
+ firstInstallment: eur(down),
564
+ months: term,
565
+ mileage: annualMileage != null ? eur(annualMileage) : '',
566
+ }).split(' · '),
567
+ );
568
+ } else if (!isCash) {
569
+ condParts.push(t('autobahn:finance.downPaymentLabel', { value: eur(down) }));
570
+ condParts.push(t('autobahn:finance.monthsLabel', { months: term, count: term }));
571
+ }
572
+ // ADV-405 follow-up: financing shows the key figures (Kerndaten) in place of the line above —
573
+ // only when at least one figure is real, else the old "0 € Anzahlung · 60 Monate" line stays.
574
+ const tabKeyFigures = mode === 'fin' ? creditKeyFigures : mode === 'leasing' ? leasingKeyFigures : undefined;
575
+ const keyFigures = tabKeyFigures && hasCreditKeyFigures(tabKeyFigures) ? tabKeyFigures : undefined;
576
+
577
+ return (
578
+ <div className="mcard mcard--elevated fin-calc-card" style={{ padding: 20 }}>
579
+ {/* header — desktop only; mobile goes straight into the tabs (see mockup: no card
580
+ title above Finanzierung/Leasing/Kaufen on phone). */}
581
+ <div className="fin-card-header hide-mobile" style={{ display: 'flex', alignItems: 'center', gap: 10, marginBottom: 14 }}>
582
+ <span
583
+ style={{
584
+ width: 34,
585
+ height: 34,
586
+ borderRadius: 'var(--md-r-full)',
587
+ background: 'var(--md-primary-container)',
588
+ display: 'flex',
589
+ alignItems: 'center',
590
+ justifyContent: 'center',
591
+ flex: 'none',
592
+ }}
593
+ >
594
+ <Icon name="tag" size={18} color="var(--md-on-primary-container)" />
595
+ </span>
596
+ <div style={{ fontFamily: 'var(--md-font-display)', fontSize: 18, fontWeight: 700 }}>{t('autobahn:finance.headerTitle')}</div>
597
+ </div>
598
+
599
+ {/* payment-type TABS on top — Leasing omitted when the car isn't leasing-eligible, same
600
+ rule cardParts.tsx's PriceTabs already applies (car.lease != null there). */}
601
+ <div className="fin-tabs" role="tablist">
602
+ {(
603
+ [
604
+ ['fin', 'autobahn:finance.mode.financing'],
605
+ ...(leasingAvailable ? ([['leasing', 'autobahn:finance.mode.leasing']] as Array<[FinanceMode, string]>) : []),
606
+ ['cash', 'autobahn:finance.mode.cash'],
607
+ ] as Array<[FinanceMode, string]>
608
+ ).map(([k, labelKey]) => (
609
+ <button
610
+ key={k}
611
+ type="button"
612
+ role="tab"
613
+ aria-selected={mode === k}
614
+ className={'fin-tab' + (mode === k ? ' on' : '')}
615
+ onClick={() => onModeChange(k)}
616
+ >
617
+ {k === 'cash' ? (
618
+ <>
619
+ {/* cash tab is "Kaufen" on both phone and desktop now — same key both spans. */}
620
+ <span className="hide-mobile">{t('autobahn:card.price.buy')}</span>
621
+ <span className="show-mobile" style={{ justifyContent: 'center' }}>
622
+ {t('autobahn:card.price.buy')}
623
+ </span>
624
+ </>
625
+ ) : (
626
+ t(labelKey)
627
+ )}
628
+ </button>
629
+ ))}
630
+ </div>
631
+
632
+ {/* 2-col grid: rate|pill (row 1) + condLine|bar (row 2) — fixed right column prevents wrapping */}
633
+ <div className={'fin-price-grid' + (isCash ? ' fin-price-grid--cash' : '')}>
634
+ {/* col 1 row 1: hero rate — Figma: "329 €" all-big, then a small stacked column with
635
+ the struck old rate ABOVE "/mtl." (round 11; was a single baseline row) */}
636
+ <div className="fin-rate-main">
637
+ {/* mobile Kaufen (Figma round 14): struck list price ABOVE the price, right-aligned,
638
+ tight to the figure — replaces the Festpreis + UVP lines, which stay desktop-only */}
639
+ {isCash && showStrike && (
640
+ <div
641
+ className="show-mobile"
642
+ style={{ justifyContent: 'flex-end', alignItems: 'baseline', gap: 4, lineHeight: 1, marginTop: 7 }}
643
+ role="button"
644
+ tabIndex={0}
645
+ onClick={() => setUvpTooltipOpen((v) => !v)}
646
+ >
647
+ {/* ADV-423: same size as the struck price next to it (md3.css .pp-uvp-label) */}
648
+ <span
649
+ className={`pp-uvp-label${
650
+ String(Math.round(listPrice as number)).length === 5
651
+ ? ' pp-uvp-label--len5'
652
+ : String(Math.round(listPrice as number)).length === 4
653
+ ? ' pp-uvp-label--len4'
654
+ : ''
655
+ }`}
656
+ >
657
+ {t('autobahn:finance.uvp')}
658
+ </span>
659
+ <span
660
+ className={`num pp-hero-old${
661
+ String(Math.round(listPrice as number)).length === 5
662
+ ? ' pp-hero-old--len5'
663
+ : String(Math.round(listPrice as number)).length === 4
664
+ ? ' pp-hero-old--len4'
665
+ : ''
666
+ }`}
667
+ >
668
+ {eur(Math.round(listPrice as number))} €
669
+ <span
670
+ className="pp-eyebrow-badge"
671
+ role="button"
672
+ tabIndex={0}
673
+ onClick={(e) => {
674
+ e.stopPropagation();
675
+ setUvpTooltipOpen((v) => !v);
676
+ }}
677
+ >
678
+ 2
679
+ </span>
680
+ {uvpTooltipOpen && (
681
+ <div className="pp-uvp-tooltip" onClick={(e) => e.stopPropagation()}>
682
+ <button
683
+ type="button"
684
+ className="pp-uvp-tooltip-close"
685
+ aria-label={t('autobahn:modal.close')}
686
+ onClick={(e) => {
687
+ e.stopPropagation();
688
+ setUvpTooltipOpen(false);
689
+ }}
690
+ >
691
+ <svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
692
+ <path d="M5 5L15 15M15 5L5 15" stroke="white" strokeWidth={2.4} strokeLinecap="round" />
693
+ </svg>
694
+ </button>
695
+ <div className="pp-uvp-tooltip-body">{t('autobahn:card.price.uvpListTooltipBody')}</div>
696
+ </div>
697
+ )}
698
+ </span>
699
+ </div>
700
+ )}
701
+ {/* desktop: same struck list price ABOVE the rate, same fin-rate-old-list styling +
702
+ clickable UVP badge/tooltip as the mobile sheet's own Kaufen block.
703
+ Wrapper now renders on EVERY Kaufen car (isCash alone, not isCash && showStrike) —
704
+ cross-tab height parity (md3.css) reserves this row's height once, assuming it's
705
+ always there; a car with no discount used to skip it entirely, landing .fin-rate-main
706
+ (and the whole card) ~20px shorter than a discounted one and breaking that parity.
707
+ fin-rate-strike-slot (md3.css) gives it a fixed height so the slot itself doesn't
708
+ move even though the <s> price inside is still conditional on showStrike. */}
709
+ {isCash && (
710
+ <div
711
+ className="hide-mobile fin-rate-strike-slot"
712
+ style={{
713
+ display: 'flex',
714
+ justifyContent: 'flex-end',
715
+ alignItems: 'baseline',
716
+ lineHeight: 1,
717
+ marginTop: 0,
718
+ cursor: showStrike ? 'pointer' : 'default',
719
+ }}
720
+ role="button"
721
+ tabIndex={0}
722
+ onClick={() => setUvpTooltipOpen((v) => !v)}
723
+ >
724
+ {/* ADV-423: "UVP" label right before the struck list price (this slot is desktop-only) */}
725
+ {showStrike && <span className="pp-uvp-label">{t('autobahn:finance.uvp')}</span>}
726
+ {showStrike && (
727
+ <s className="num fin-rate-old fin-rate-old-list">
728
+ {eur(listPrice as number)} €
729
+ <span
730
+ className="pp-eyebrow-badge"
731
+ role="button"
732
+ tabIndex={0}
733
+ onClick={(e) => {
734
+ e.stopPropagation();
735
+ setUvpTooltipOpen((v) => !v);
736
+ }}
737
+ >
738
+ 2
739
+ </span>
740
+ {uvpTooltipOpen && (
741
+ <div className="pp-uvp-tooltip" onClick={(e) => e.stopPropagation()}>
742
+ <button
743
+ type="button"
744
+ className="pp-uvp-tooltip-close"
745
+ aria-label={t('autobahn:modal.close')}
746
+ onClick={(e) => {
747
+ e.stopPropagation();
748
+ setUvpTooltipOpen(false);
749
+ }}
750
+ >
751
+ <svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
752
+ <path d="M5 5L15 15M15 5L5 15" stroke="white" strokeWidth={2.4} strokeLinecap="round" />
753
+ </svg>
754
+ </button>
755
+ <div className="pp-uvp-tooltip-body">{t('autobahn:card.price.uvpListTooltipBody')}</div>
756
+ </div>
757
+ )}
758
+ </s>
759
+ )}
760
+ </div>
761
+ )}
762
+ <div style={{ display: 'flex', alignItems: 'center', gap: 7 }}>
763
+ {isCash ? (
764
+ <>
765
+ {/* phone: ONE unbreakable "13.249 €" span (a separate € span wraps to its own
766
+ line); desktop keeps the number + quiet small € pair */}
767
+ <span
768
+ className={`num show-mobile fin-rate-cash-mobile${
769
+ (() => {
770
+ const digits = String(Math.round(price as number)).length;
771
+ if (digits >= 8) return ' fin-rate-cash-mobile--len8';
772
+ if (digits === 7) return ' fin-rate-cash-mobile--len7';
773
+ if (digits === 6) return ' fin-rate-cash-mobile--len6';
774
+ return '';
775
+ })()
776
+ }`}
777
+ style={{ fontSize: 48, fontWeight: 800, color: 'var(--md-primary)', letterSpacing: '-2px', whiteSpace: 'nowrap' }}
778
+ >
779
+ {eur(price)} €<sup>1</sup>
780
+ </span>
781
+ <span
782
+ className="num hide-mobile"
783
+ style={{ fontSize: 45, fontWeight: 800, color: 'var(--md-primary)', letterSpacing: '-2px' }}
784
+ >
785
+ {eur(price)} €<sup>1</sup>
786
+ </span>
787
+ </>
788
+ ) : (
789
+ <>
790
+ <span
791
+ className={`num fin-rate-hero${
792
+ (() => {
793
+ const digits = String(Math.round(monthly)).length;
794
+ if (digits >= 6) return ' fin-rate-hero--len6';
795
+ if (digits === 5) return ' fin-rate-hero--len5';
796
+ if (digits === 4) return ' fin-rate-hero--len4';
797
+ return '';
798
+ })()
799
+ }`}
800
+ style={{ fontSize: 48, fontWeight: 800, color: 'var(--md-primary)', letterSpacing: '-2px' }}
801
+ >
802
+ {eur(Math.round(monthly))}<span style={{ marginLeft: 6 }}>€</span>
803
+ </span>
804
+ <span className="fin-rate-unit">
805
+ {/* struck old rate (REAL oldMonthlyInstallment; SRP strikes the same source) */}
806
+ {oldMonthly != null && (
807
+ <span
808
+ style={{ display: 'flex', flexDirection: 'column', cursor: 'pointer' }}
809
+ role="button"
810
+ tabIndex={0}
811
+ onClick={() => setUvpTooltipOpen((v) => !v)}
812
+ >
813
+ <span className="pp-eyebrow">
814
+ {t('autobahn:card.price.uvpRateLabel')}
815
+ <span
816
+ className="pp-eyebrow-badge"
817
+ role="button"
818
+ tabIndex={0}
819
+ onClick={(e) => {
820
+ e.stopPropagation();
821
+ setUvpTooltipOpen((v) => !v);
822
+ }}
823
+ >
824
+ 3
825
+ </span>
826
+ {uvpTooltipOpen && (
827
+ <div
828
+ className={'pp-uvp-tooltip' + (mode === 'leasing' ? ' pp-uvp-tooltip--leasing' : '')}
829
+ onClick={(e) => e.stopPropagation()}
830
+ >
831
+ <button
832
+ type="button"
833
+ className="pp-uvp-tooltip-close"
834
+ aria-label={t('autobahn:modal.close')}
835
+ onClick={(e) => {
836
+ e.stopPropagation();
837
+ setUvpTooltipOpen(false);
838
+ }}
839
+ >
840
+ <svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
841
+ <path d="M5 5L15 15M15 5L5 15" stroke="white" strokeWidth={2.4} strokeLinecap="round" />
842
+ </svg>
843
+ </button>
844
+ <div className="pp-uvp-tooltip-body">
845
+ {t(
846
+ mode === 'leasing'
847
+ ? 'autobahn:card.price.uvpRateTooltipBodyLeasing'
848
+ : 'autobahn:card.price.uvpRateTooltipBody',
849
+ )}
850
+ </div>
851
+ </div>
852
+ )}
853
+ </span>
854
+ <s
855
+ className={`num fin-rate-old fin-rate-example-price${
856
+ String(Math.round(oldMonthly)).length >= 5
857
+ ? ' fin-rate-example-price--len5'
858
+ : String(Math.round(oldMonthly)).length === 4
859
+ ? ' fin-rate-example-price--len4'
860
+ : ''
861
+ }`}
862
+ >
863
+ {eur(Math.round(oldMonthly))} €
864
+ </s>
865
+ </span>
866
+ )}
867
+ {/* no struck old rate above it (strike hidden) — nudge "/mtl." down so it
868
+ sits level with the blue hero rate instead of centering high in the row. */}
869
+ <span
870
+ className="fin-rate-example-suffix"
871
+ style={oldMonthly == null ? { paddingTop: 20 } : undefined}
872
+ >
873
+ {t('autobahn:finance.perMonth')}
874
+ </span>
875
+ </span>
876
+ </>
877
+ )}
878
+ </div>
879
+ {isCash && <div className="md-label-sm hide-mobile">{t('autobahn:finance.fixedPrice')}</div>}
880
+ </div>
881
+ {/* col 2: pill + eval bar grouped together (display:contents on desktop — no-op,
882
+ preserves the original rate|pill / cond|bar auto-placement; mobile turns this into
883
+ a real flex column so the two stack tight with a fixed 16px gap). */}
884
+ <div className="fin-eval-col">
885
+ {/* col 2 row 1: price-rating pill (Figma: bold colored label, NO icon) */}
886
+ <div className="fin-eval-pill-cell">
887
+ {ratingLabel && (
888
+ <span
889
+ className={`fin-eval-pill${isGoodTier ? ' fin-eval-pill--good' : ''}`}
890
+ style={{ color: evalPillColor, background: `color-mix(in srgb, ${evalPillColor} 16%, transparent)` }}
891
+ aria-label={t('autobahn:finance.priceRatingAria', { rating: evalTierLabel })}
892
+ >
893
+ {evalTierLabel}
894
+ {isGoodTier && <sup>4</sup>}
895
+ </span>
896
+ )}
897
+ </div>
898
+ {/* segmented evaluation bar (Figma: discrete tiers, not a gradient) */}
899
+ <div className="fin-eval-bar-cell">{ratingLabel && <EvalBar tier={evalTier} />}</div>
900
+ </div>
901
+ {/* col 1 row 2: condition line — financing "0 € Anzahlung · 60 Monate · Finanzierungsdetails",
902
+ leasing "25.000 € Sonderzahlung · 60 Mon. · 10.000 km/Jahr · Details". Buy has nothing
903
+ to show here (no down payment/term/details link of its own) — not rendered at all
904
+ rather than left as an empty reserved-height div.
905
+ ADV-405 follow-up: financing with real key figures → the Kerndaten (2 lines, same
906
+ .fin-cond grid cell/size/colour, wraps where narrow) ending with the same details link. */}
907
+ {keyFigures ? (
908
+ <CreditKeyFigures
909
+ t={t}
910
+ figures={keyFigures}
911
+ cls="fin-cond fin-ckf"
912
+ details={
913
+ onShowDetails && (
914
+ <button type="button" className="cc-terms-link" onClick={onShowDetails}>
915
+ {mode === 'leasing' ? t('autobahn:card.price.detailsLink') : t('autobahn:finance.financingDetails')}
916
+ </button>
917
+ )
918
+ }
919
+ />
920
+ ) : !isCash && (
921
+ <div className="fin-cond">
922
+ {condParts.map((part, i) => (
923
+ <React.Fragment key={i}>
924
+ {i > 0 && <span className="cc-terms-dot"> · </span>}
925
+ {part}
926
+ </React.Fragment>
927
+ ))}
928
+ {onShowDetails && (
929
+ <>
930
+ <span className="cc-terms-dot"> · </span>
931
+ {/* plain underlined text link, same onShowDetails handler as .fin-info used to open. */}
932
+ <button type="button" className="cc-terms-link" onClick={onShowDetails}>
933
+ {mode === 'leasing' ? t('autobahn:card.price.detailsLink') : t('autobahn:finance.financingDetails')}
934
+ </button>
935
+ </>
936
+ )}
937
+ </div>
938
+ )}
939
+ </div>
940
+
941
+ {/* ADV-405/406 Kreditkosten-Hinweis — Preis-Card (mobile) + „Dein Angebot“ (desktop): below the
942
+ conditions line, above „Angebot anfragen“/„Anrufen“ (mobile) or „Rate anpassen“ (desktop).
943
+ Not on Kaufen (no reserved space — the Kaufen view stays exactly as before). */}
944
+ {!isCash && <CreditCostNotice t={t} cls="fin-ccn" />}
945
+
946
+ {/* ============================== DESKTOP (≥601px) — unchanged ============================== */}
947
+ <div className="hide-mobile">
948
+ {/* RATE EDIT (Rate anpassen) — between the rate and the request CTA. fin-adjust--cash:
949
+ Kaufen-only margin-top override (0, was the shared 14px) — see md3.css. */}
950
+ <div className={'fin-adjust' + (isCash ? ' fin-adjust--cash' : '')}>
951
+ <button onClick={() => setAdjust((a) => !a)} style={expanderBtnStyle}>
952
+ <span style={{ display: 'inline-flex', alignItems: 'center', gap: 7 }}>
953
+ <Icon name={isCash ? 'list' : 'sliders-horizontal'} size={16} color="var(--md-primary)" />
954
+ {isCash ? t('autobahn:finance.detailsShow') : t('autobahn:finance.adjustRate')}
955
+ </span>
956
+ <Icon name={adjust ? 'chevron-up' : 'chevron-down'} size={18} color="var(--md-primary)" />
957
+ </button>
958
+ {adjust &&
959
+ (isCash ? (
960
+ <>
961
+ <div style={{ marginTop: 4 }}>
962
+ <CalcRow label={t('autobahn:finance.paymentLabel')} last={!available && !(addServicesCost != null && onToggleAddServices)}>{t('autobahn:finance.paymentValue')}</CalcRow>
963
+ {available && (
964
+ <CalcRow label={t('autobahn:finance.availabilityLabel')} last={!(addServicesCost != null && onToggleAddServices)}>
965
+ {t('autobahn:finance.availabilityValue')}
966
+ </CalcRow>
967
+ )}
968
+ </div>
969
+ {addServicesCost != null && onToggleAddServices && (
970
+ <ToggleRow
971
+ className="fin-toggle-addservices fin-toggle-addservices--cash"
972
+ label={t('autobahn:finance.addServicesToggle')}
973
+ price={t('autobahn:finance.addServicesOnce', { value: eur(Math.round(addServicesCost)) })}
974
+ checked={!!withAddServices}
975
+ disabled={addServicesDisabled}
976
+ onChange={onToggleAddServices}
977
+ staticNote={t('autobahn:finance.addServicesIncluded')}
978
+ tooltip={<AddServicesTooltipBody t={t} isCash />}
979
+ tooltipCloseLabel={t('autobahn:modal.close')}
980
+ t={t}
981
+ />
982
+ )}
983
+ </>
984
+ ) : (
985
+ <div style={{ display: 'flex', flexDirection: 'column', marginTop: 8 }}>
986
+ <div style={{ marginBottom: 15 }}>
987
+ <div style={{ display: 'flex', justifyContent: 'space-between', marginBottom: 6 }}>
988
+ <span className="md-title-sm">{t('autobahn:finance.downPaymentSliderLabel')}</span>
989
+ <span className="num" style={{ fontWeight: 700 }}>
990
+ {eur(down)} €
991
+ </span>
992
+ </div>
993
+ <Slider
994
+ min={downMin}
995
+ max={downMax}
996
+ step={downStep}
997
+ value={down}
998
+ onChange={onDownChange}
999
+ fmt={(v) => `${eur(Number(v))} €`}
1000
+ />
1001
+ </div>
1002
+ {annualMileage != null && onAnnualMileageChange && (
1003
+ <div style={{ marginBottom: 15 }}>
1004
+ <div style={{ display: 'flex', justifyContent: 'space-between', marginBottom: 6 }}>
1005
+ <span className="md-title-sm">{t('autobahn:finance.annualMileageLabel')}</span>
1006
+ <span className="num" style={{ fontWeight: 700 }}>
1007
+ {eur(annualMileage)} km
1008
+ </span>
1009
+ </div>
1010
+ <Slider
1011
+ min={annualMileageMin}
1012
+ max={annualMileageMax}
1013
+ step={annualMileageStep}
1014
+ value={annualMileage}
1015
+ onChange={onAnnualMileageChange}
1016
+ fmt={(v) => `${eur(Number(v))} km`}
1017
+ />
1018
+ </div>
1019
+ )}
1020
+ <div style={{ marginBottom: 15 }}>
1021
+ <div className="md-title-sm" style={{ marginBottom: 8 }}>
1022
+ {t('autobahn:finance.termSelection')}
1023
+ </div>
1024
+ <TermChips options={terms.filter((v) => v !== 12 && v !== 96)} value={term} onChange={onTermChange} t={t} />
1025
+ </div>
1026
+ {/* same Mit-Schlussrate / Rundum-Sorglos-Paket toggles as the mobile sheet / modal
1027
+ desktop block — replaces the static Kaufpreis/Garantie/Lieferung rows. */}
1028
+ {!isLease && onToggleFinalInstallment && (
1029
+ <ToggleRow
1030
+ className="fin-toggle-final"
1031
+ label={t('autobahn:finance.finalInstallmentToggle')}
1032
+ checked={!!withFinalInstallment}
1033
+ onChange={onToggleFinalInstallment}
1034
+ />
1035
+ )}
1036
+ {addServicesCost != null && onToggleAddServices && (
1037
+ <ToggleRow
1038
+ className={'fin-toggle-addservices' + (isLease ? ' fin-toggle-addservices--leasing' : '')}
1039
+ label={t('autobahn:finance.addServicesToggle')}
1040
+ price={t('autobahn:finance.addServicesPerMonth', { value: eur(Math.round(addServicesCost)) })}
1041
+ checked={!!withAddServices}
1042
+ disabled={addServicesDisabled}
1043
+ onChange={onToggleAddServices}
1044
+ tooltip={<AddServicesTooltipBody t={t} isLease={isLease} />}
1045
+ tooltipCloseLabel={t('autobahn:modal.close')}
1046
+ t={t}
1047
+ />
1048
+ )}
1049
+ </div>
1050
+ ))}
1051
+ </div>
1052
+
1053
+ {/* REQUEST CTA */}
1054
+ <Button
1055
+ variant="filled"
1056
+ block
1057
+ size="lg"
1058
+ icon="shield-check"
1059
+ className={secured ? 'fin-cta-secured' : undefined}
1060
+ style={{ marginTop: 14 }}
1061
+ onClick={onSecure}
1062
+ >
1063
+ {secured && secureLabel ? secureLabel : t('autobahn:finance.secureOffer')}
1064
+ </Button>
1065
+ {/* phone CTA — touch only (hidden on desktop via .fin-call) */}
1066
+ <div className="fin-call">
1067
+ <Button variant="outlined" block icon="phone" onClick={onCall}>
1068
+ {phone}
1069
+ </Button>
1070
+ </div>
1071
+
1072
+ {/* auto.de-ID in front of the Finanzierungs-/Leasingdetails link — one row, under everything */}
1073
+ {(autoDeId || (!isCash && onShowDetails)) && (
1074
+ <div className="fin-info">
1075
+ {autoDeId && <span className="fin-id">auto.de-ID {autoDeId}</span>}
1076
+ {!isCash && onShowDetails && (
1077
+ <DetailsLink
1078
+ label={mode === 'leasing' ? t('autobahn:finance.leasingDetails') : t('autobahn:finance.financingDetails')}
1079
+ onClick={onShowDetails}
1080
+ />
1081
+ )}
1082
+ </div>
1083
+ )}
1084
+ </div>
1085
+
1086
+ {/* ============================== MOBILE (≤600px) — new layout ============================== */}
1087
+ <div className="show-mobile" style={{ flexDirection: 'column' }}>
1088
+ {/* side-by-side CTAs — mockup ratio ~2:1, with the tiny auto.de-ID sitting
1089
+ directly under the Anrufen button (not in its own full-width row). */}
1090
+ <div className="fin-cta-row" style={{ display: 'flex', gap: 10, alignItems: 'flex-start' }}>
1091
+ {/* Figma CTA icon: document + check badge (composed — no single lucide glyph) */}
1092
+ <Button
1093
+ variant="filled"
1094
+ size="lg"
1095
+ className={secured ? 'fin-cta-secured' : undefined}
1096
+ style={{ width: 216, height: 50, paddingLeft: 0, paddingRight: 9, gap: secured ? 3 : 18 }}
1097
+ onClick={onSecure}
1098
+ >
1099
+ {/* size 23 either way — was 18 for the secured (shield-check) state, notably
1100
+ smaller than DocCheckIcon's 23 in the default state despite sharing the exact
1101
+ same 50px button box; nothing about switching to "already secured" should
1102
+ shrink the icon. */}
1103
+ {secured ? <Icon name="shield-check" size={23} /> : <DocCheckIcon size={23} />}
1104
+ {secured && secureLabel ? secureLabel : t('autobahn:finance.secureOffer')}
1105
+ </Button>
1106
+ <div style={{ flex: 1, display: 'flex', flexDirection: 'column', gap: 4, minWidth: 0 }}>
1107
+ <Button variant="outlined" size="lg" icon="phone" style={{ width: 112, height: 50 }} onClick={onCall}>
1108
+ {t('autobahn:finance.callCta')}
1109
+ </Button>
1110
+ {autoDeId && (
1111
+ <span
1112
+ className="num"
1113
+ style={{ fontSize: 10, fontWeight: 700, color: 'var(--md-primary)', textAlign: 'center', whiteSpace: 'nowrap' }}
1114
+ >
1115
+ auto.de ID: {autoDeId}
1116
+ </span>
1117
+ )}
1118
+ </div>
1119
+ </div>
1120
+
1121
+ {/* Persönliche Beratung — icon + one line (the details link now lives in .fin-cond above) */}
1122
+ <div className="fin-info" style={{ justifyContent: 'flex-start', paddingLeft: 15 }}>
1123
+ <Icon name="user" size={26} color="var(--md-on-surface-variant)" style={{ flex: 'none', marginRight: 20 }} />
1124
+ <span className="fin-info-line">{t('autobahn:finance.personalConsultationLine')}</span>
1125
+ </div>
1126
+
1127
+ {/* "Rate anpassen" / "Details anzeigen" — opens the full bottom sheet (not an inline expander) */}
1128
+ {onOpenAdjust && (
1129
+ <button
1130
+ type="button"
1131
+ onClick={onOpenAdjust}
1132
+ style={{ ...expanderBtnStyle, borderTop: '1px solid var(--md-outline-variant)', marginTop: 11, padding: '11px 0 2px 21px' }}
1133
+ >
1134
+ <span style={{ display: 'inline-flex', alignItems: 'center', gap: 21 }}>
1135
+ <Icon name="sliders-horizontal" size={23} color="var(--md-primary)" />
1136
+ <span className="fin-adjust-btn-label">
1137
+ {isCash ? t('autobahn:finance.detailsShow') : t('autobahn:finance.adjustRate')}
1138
+ </span>
1139
+ </span>
1140
+ <Icon name="chevron-right" size={23} color="var(--md-primary)" />
1141
+ </button>
1142
+ )}
1143
+ </div>
1144
+ </div>
1145
+ );
1146
+ };
1147
+
1148
+ export default FinanceCalculator;