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

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 +1 -8
  2. package/cards/CarRow.tsx +1 -5
  3. package/cards/cardParts.tsx +1363 -1368
  4. package/cards/index.ts +0 -6
  5. package/cards/types.ts +182 -182
  6. package/chrome/Footer.tsx +3 -16
  7. package/chrome/TopBar.tsx +266 -139
  8. package/compat/CookieModal/CookieModal.tsx +6 -20
  9. package/compat/CookieModal/Modal.tsx +3 -6
  10. package/compat/CookieModal/modals/ManageCookieModal/ManageCookieModal.tsx +15 -43
  11. package/compat/CookieModal/modals/PreviewCookieModal/PreviewCookieModal.tsx +3 -4
  12. package/compat/CookieModal/useModal.ts +1 -5
  13. package/compat/Loader/Loader.tsx +7 -1
  14. package/compat/MdField/MdField.tsx +4 -28
  15. package/compat/TimePicker/TimePicker.tsx +2 -12
  16. package/data/toAutobahnCar.ts +586 -600
  17. package/iconsvg/IconSVG.tsx +5 -1
  18. package/locales/de/autobahn.json +857 -891
  19. package/locales/en/autobahn.json +857 -891
  20. package/package.json +2 -2
  21. package/theme/md3.css +11743 -15678
  22. package/ui/CreditCostNotice.tsx +44 -44
  23. package/ui/CreditKeyFigures.tsx +244 -244
  24. package/ui/Dropdown.tsx +10 -29
  25. package/ui/FormCheckbox.tsx +2 -22
  26. package/ui/FormField.tsx +1 -2
  27. package/ui/Icon.tsx +0 -6
  28. package/ui/Modal.tsx +6 -84
  29. package/ui/Skeleton.tsx +20 -79
  30. package/ui/index.ts +94 -96
  31. package/ui/usePortalMenuPosition.ts +15 -27
  32. package/utils/index.ts +0 -10
  33. package/vdp/FinanceCalculator.tsx +1134 -1148
  34. package/vdp/VdpModules.tsx +4437 -3869
  35. package/vdp/index.ts +3 -0
  36. package/vdp/types.ts +17 -7
  37. package/vehiclesProps/decoratedLightProps.tsx +0 -4
  38. package/vehiclesProps/decoratedProps.tsx +0 -4
  39. package/cards/CarCardSkeleton.tsx +0 -103
  40. package/cards/CarRowSkeleton.tsx +0 -152
  41. package/chrome/AccountMenuIcon.tsx +0 -109
  42. package/ui/MfieldCheckIcon.tsx +0 -13
  43. package/ui/scrollFieldIntoView.ts +0 -41
  44. package/utils/cookieConsent.ts +0 -84
  45. package/vehiclesProps/accidentDisclosure.ts +0 -25
@@ -1,44 +1,44 @@
1
- import React from 'react';
2
-
3
- import Icon from './Icon';
4
- import { TranslationFunction } from '../types';
5
-
6
- /** ADV-405 statutory German wording. The i18n fallback, so a stale locale cache (or a host that only loads the de locale) never shows the raw key. */
7
- export const CREDIT_COST_WARNING_DE = 'Achtung! Kreditaufnahme kostet Geld.';
8
-
9
- export type CreditCostNoticeTone = 'light' | 'dark';
10
- export type CreditCostNoticeSize = 'standard' | 'small';
11
-
12
- export interface CreditCostNoticeProps {
13
- t: TranslationFunction;
14
- /** light = Figma "Ton=Hell" (default), dark = "Ton=Dunkel" (dark hero backgrounds only). */
15
- tone?: CreditCostNoticeTone;
16
- /** standard ≈ 8×10 px padding, small ≈ 5×6 px (small cards / narrow price columns). */
17
- size?: CreditCostNoticeSize;
18
- /** extra class(es) for the host's size/colour/spacing rules (font size and colour follow the host block's conditions line). */
19
- cls?: string;
20
- }
21
-
22
- /**
23
- * Kreditkosten-Hinweis (ADV-405, Verbraucherkreditreform 2026): the warning
24
- * "Achtung! Kreditaufnahme kostet Geld." with a Lucide info icon. Static, always
25
- * visible, real text; the icon is hidden from screen readers. The English locale
26
- * shows "Warning! Financing comes at a cost." (the text follows the page language,
27
- * so no lang attribute of its own). Hosts decide visibility (financing/leasing
28
- * shown, Kaufen hidden).
29
- */
30
- const CreditCostNotice: React.FunctionComponent<CreditCostNoticeProps> = ({ t, tone = 'light', size = 'standard', cls }) => {
31
- const className = ['ccn', `ccn--${tone}`, size === 'small' ? 'ccn--small' : '', cls || ''].filter(Boolean).join(' ');
32
- return (
33
- <div className={className}>
34
- <span className="ccn-icon" aria-hidden="true">
35
- <Icon name="info" size={16} stroke={2} />
36
- </span>
37
- <span className="ccn-text">
38
- {t('autobahn:finance.creditCostWarning', { defaultValue: CREDIT_COST_WARNING_DE })}
39
- </span>
40
- </div>
41
- );
42
- };
43
-
44
- export default CreditCostNotice;
1
+ import React from 'react';
2
+
3
+ import Icon from './Icon';
4
+ import { TranslationFunction } from '../types';
5
+
6
+ /** ADV-405 statutory German wording. The i18n fallback, so a stale locale cache (or a host that only loads the de locale) never shows the raw key. */
7
+ export const CREDIT_COST_WARNING_DE = 'Achtung! Kreditaufnahme kostet Geld.';
8
+
9
+ export type CreditCostNoticeTone = 'light' | 'dark';
10
+ export type CreditCostNoticeSize = 'standard' | 'small';
11
+
12
+ export interface CreditCostNoticeProps {
13
+ t: TranslationFunction;
14
+ /** light = Figma "Ton=Hell" (default), dark = "Ton=Dunkel" (dark hero backgrounds only). */
15
+ tone?: CreditCostNoticeTone;
16
+ /** standard ≈ 8×10 px padding, small ≈ 5×6 px (small cards / narrow price columns). */
17
+ size?: CreditCostNoticeSize;
18
+ /** extra class(es) for the host's size/colour/spacing rules (font size and colour follow the host block's conditions line). */
19
+ cls?: string;
20
+ }
21
+
22
+ /**
23
+ * Kreditkosten-Hinweis (ADV-405, Verbraucherkreditreform 2026): the warning
24
+ * "Achtung! Kreditaufnahme kostet Geld." with a Lucide info icon. Static, always
25
+ * visible, real text; the icon is hidden from screen readers. The English locale
26
+ * shows "Warning! Financing comes at a cost." (the text follows the page language,
27
+ * so no lang attribute of its own). Hosts decide visibility (financing/leasing
28
+ * shown, Kaufen hidden).
29
+ */
30
+ const CreditCostNotice: React.FunctionComponent<CreditCostNoticeProps> = ({ t, tone = 'light', size = 'standard', cls }) => {
31
+ const className = ['ccn', `ccn--${tone}`, size === 'small' ? 'ccn--small' : '', cls || ''].filter(Boolean).join(' ');
32
+ return (
33
+ <div className={className}>
34
+ <span className="ccn-icon" aria-hidden="true">
35
+ <Icon name="info" size={16} stroke={2} />
36
+ </span>
37
+ <span className="ccn-text">
38
+ {t('autobahn:finance.creditCostWarning', { defaultValue: CREDIT_COST_WARNING_DE })}
39
+ </span>
40
+ </div>
41
+ );
42
+ };
43
+
44
+ export default CreditCostNotice;
@@ -1,244 +1,244 @@
1
- import React, { useEffect, useLayoutEffect, useRef } from 'react';
2
-
3
- import { TranslationFunction } from '../types';
4
- import { formatEur, formatEurCents, formatPct } from '../utils/financeFormat';
5
-
6
- /**
7
- * Financing key figures of the representative example, in the order the PM asked for (ADV-405
8
- * follow-up, 19.11): "60 Mon. · 24.549 € Nettokredit · Gesamtbetrag: 31.776,28 €" /
9
- * "6,78 % Sollzins fest · 6,99 % eff. Jahreszins · Details". Same sources as the
10
- * Finanzierungsdetails layer (FinanceDetailsModal): term = paybackPeriod, net loan =
11
- * netLoanAmount, total = totalFinancingAmount (falls back to grossLoanAmount), nominal rate =
12
- * nominalInterestRate, effective rate = annualPercentageRate. Leasing (kind: 'leasing', 19.11): see
13
- * leasingKeyFigureLines / leasingKeyFigures below.
14
- */
15
- export interface CreditKeyFiguresData {
16
- /** financing (default) or leasing — the two products word their lines differently. */
17
- kind?: 'financing' | 'leasing';
18
- /** contract term (paybackPeriod) — exactly the layer's "Vertragslaufzeit" (e.g. 48, also with a Schlussrate). */
19
- months?: number | null;
20
- /** final instalment (Schlussrate) of the same calculation — not shown; kept for the hosts' data. */
21
- finalInstallment?: number | null;
22
- netLoan?: number | null;
23
- /** financing: Gesamtbetrag; leasing: the layer's "Gesamt inkl. Restwert" (see leasingKeyFigures). */
24
- total?: number | null;
25
- nominal?: number | null;
26
- apr?: number | null;
27
- /** leasing: the layer's "Einmalige Sonderzahlung" (0 is a real figure: "0 € Anzahlung"). */
28
- down?: number | null;
29
- /** leasing: the layer's "Anschaffungspreis" ("… € Barpreis"). */
30
- cashPrice?: number | null;
31
- /** leasing: the layer's "Restwert (verpflichtend)" — "Kaufpflicht" is shown when it is real. */
32
- residual?: number | null;
33
- }
34
-
35
- export interface CreditKeyFiguresProps {
36
- t: TranslationFunction;
37
- figures: CreditKeyFiguresData;
38
- /** optional trailing element of line 2 (the host's existing "Details"/"Finanzierungsdetails" link). */
39
- details?: React.ReactNode;
40
- /** host class(es) for size/colour/spacing (follow the host block's conditions line). */
41
- cls?: string;
42
- /** false: no two-line auto-fit — the host keeps its own font size and lets the figures flow as
43
- * one wrapping paragraph (SRL desktop price column, PM 19.11: "own size, three lines are fine"). */
44
- fit?: boolean;
45
- }
46
-
47
- const real = (n: number | null | undefined): n is number => typeof n === 'number' && isFinite(n) && n > 0;
48
-
49
- /** the parts of both lines — only real figures, never a fabricated value; empty lines are dropped. */
50
- export function creditKeyFigureLines(t: TranslationFunction, f: CreditKeyFiguresData): string[][] {
51
- if (f.kind === 'leasing') return leasingKeyFigureLines(t, f);
52
- const line1: string[] = [];
53
- const line2: string[] = [];
54
- if (real(f.months)) {
55
- // the layer's "Vertragslaufzeit" (not the "N Raten à" count, which is one less with a Schlussrate)
56
- const months = Math.round(f.months);
57
- line1.push(t('autobahn:finance.kfMonths', { months, defaultValue: `${months} Mon.` }));
58
- }
59
- if (real(f.netLoan)) {
60
- const v = formatEur(Math.round(f.netLoan));
61
- line1.push(t('autobahn:finance.kfNetLoan', { value: v, defaultValue: `${v} € Nettokredit` }));
62
- }
63
- if (real(f.total)) {
64
- const v = formatEurCents(f.total);
65
- line1.push(t('autobahn:finance.kfTotal', { value: v, defaultValue: `Gesamtbetrag: ${v} €` }));
66
- }
67
- if (real(f.nominal)) {
68
- const v = formatPct(f.nominal);
69
- line2.push(t('autobahn:finance.kfNominal', { value: v, defaultValue: `${v} Sollzins fest` }));
70
- }
71
- if (real(f.apr)) {
72
- const v = formatPct(f.apr);
73
- line2.push(t('autobahn:finance.kfApr', { value: v, defaultValue: `${v} eff. Jahreszins` }));
74
- }
75
- return [line1.map(keepUnits), line2.map(keepUnits)];
76
- }
77
-
78
- // keep every € / % on its amount's line (no-break space), like the € in the hosts' money strings
79
- const keepUnits = (part: string): string => part.replace(/ (€|%)/g, '\u00a0$1');
80
-
81
- /**
82
- * Leasing key figures, worded as the PM's leasing mock ("Vorschlag: Restwert - Leasing", 19.11):
83
- * "0 € Anzahlung · 60 Mon. · 24.549 € Barpreis · 31.776,28 € Gesamtbetrag" /
84
- * "Kaufpflicht · 6,78 % Sollzins fest · 6,99 % eff. Jahreszins · Details". Anzahlung = the layer's
85
- * Einmalige Sonderzahlung, Barpreis = Anschaffungspreis, Gesamtbetrag = Gesamt inkl. Restwert,
86
- * "Kaufpflicht" = the mandatory Restwert (only when there is one). € with a space, as in the
87
- * financing mock next to it.
88
- */
89
- function leasingKeyFigureLines(t: TranslationFunction, f: CreditKeyFiguresData): string[][] {
90
- const line1: string[] = [];
91
- const line2: string[] = [];
92
- if (typeof f.down === 'number' && isFinite(f.down) && f.down >= 0) {
93
- const v = formatEur(Math.round(f.down));
94
- line1.push(t('autobahn:finance.kfLeaseDown', { value: v, defaultValue: `${v} € Anzahlung` }));
95
- }
96
- if (real(f.months)) {
97
- const months = Math.round(f.months);
98
- line1.push(t('autobahn:finance.kfMonths', { months, defaultValue: `${months} Mon.` }));
99
- }
100
- if (real(f.cashPrice)) {
101
- const v = formatEur(Math.round(f.cashPrice));
102
- line1.push(t('autobahn:finance.kfCashPrice', { value: v, defaultValue: `${v} € Barpreis` }));
103
- }
104
- if (real(f.total)) {
105
- const v = formatEurCents(f.total);
106
- line1.push(t('autobahn:finance.kfLeaseTotal', { value: v, defaultValue: `${v} € Gesamtbetrag` }));
107
- }
108
- if (real(f.residual)) {
109
- line2.push(t('autobahn:finance.kfPurchaseObligation', { defaultValue: 'Kaufpflicht' }));
110
- }
111
- if (real(f.nominal)) {
112
- const v = formatPct(f.nominal);
113
- line2.push(t('autobahn:finance.kfNominal', { value: v, defaultValue: `${v} Sollzins fest` }));
114
- }
115
- if (real(f.apr)) {
116
- const v = formatPct(f.apr);
117
- line2.push(t('autobahn:finance.kfApr', { value: v, defaultValue: `${v} eff. Jahreszins` }));
118
- }
119
- return [line1.map(keepUnits), line2.map(keepUnits)];
120
- }
121
-
122
- /** true when at least one figure is real (otherwise hosts keep their previous conditions line). */
123
- export function hasCreditKeyFigures(f: CreditKeyFiguresData): boolean {
124
- return [f.months, f.netLoan, f.total, f.nominal, f.apr, f.cashPrice].some(real);
125
- }
126
-
127
- /** inputs of the Leasingdetails layer (FinanceDetailsModal, leasing) — see leasingKeyFigures. */
128
- export interface LeasingKeyFigureInputs {
129
- /** currentSalesPrice — the Anschaffungspreis fallback when there is no basePrice. */
130
- price?: number | null;
131
- /** common.basePrice ("no package" price). */
132
- basePrice?: number | null;
133
- monthly?: number | null;
134
- term?: number | null;
135
- /** Einmalige Sonderzahlung (leasing firstInstallment). */
136
- down?: number | null;
137
- /** Restwert (leasing finalInstallment). */
138
- residual?: number | null;
139
- withAddServices?: boolean | null;
140
- /** the leasing package's one-time price (leasing addServicesCostRaw). */
141
- addServicesCostRaw?: number | null;
142
- nominal?: number | null;
143
- apr?: number | null;
144
- }
145
-
146
- /**
147
- * The leasing key figures with the Leasingdetails layer's own arithmetic (FinanceDetailsModal,
148
- * leasing branch), so line and layer never disagree: Anschaffungspreis = (basePrice, else price)
149
- * + the package when it is in the rate; Gesamt inkl. Restwert = term × rate + Sonderzahlung + the
150
- * package when paid separately + Restwert. A missing input leaves its figure out (never invented).
151
- */
152
- export function leasingKeyFigures(i: LeasingKeyFigureInputs): CreditKeyFiguresData {
153
- const raw = real(i.addServicesCostRaw) ? i.addServicesCostRaw : 0;
154
- const base = real(i.basePrice) ? i.basePrice : real(i.price) ? i.price : undefined;
155
- const down = typeof i.down === 'number' && isFinite(i.down) && i.down >= 0 ? i.down : undefined;
156
- const residual = real(i.residual) ? i.residual : 0;
157
- const ratesSum = real(i.monthly) && real(i.term) ? i.monthly * i.term : undefined;
158
- return {
159
- kind: 'leasing',
160
- down,
161
- months: real(i.term) ? i.term : undefined,
162
- cashPrice: base != null ? base + (i.withAddServices && raw > 0 ? raw : 0) : undefined,
163
- total: ratesSum != null ? ratesSum + (down || 0) + (raw > 0 && !i.withAddServices ? raw : 0) + residual : undefined,
164
- residual: residual > 0 ? residual : undefined,
165
- nominal: real(i.nominal) ? i.nominal : undefined,
166
- apr: real(i.apr) ? i.apr : undefined,
167
- };
168
- }
169
-
170
- /** smallest font the auto-fit goes down to (px); the PM wants both lines to stay one line each. */
171
- const MIN_FIT_PX = 6;
172
- const useIsoLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;
173
-
174
- /**
175
- * Exactly two lines with the financing key figures (Kerndaten) — PM 19.11: "from the months to
176
- * Details it has to fit in 2 lines everywhere". Each line is one unbroken line (nowrap); when the
177
- * host is too narrow the block's font size steps down (from the host's conditions-line size) until
178
- * both lines fit, re-measured on resize. The " · " separators reuse the quiet .cc-terms-dot. The
179
- * optional `details` element (the host's details link/button) ends line 2, always labelled
180
- * "Details" (card.price.detailsLink), as in the PM's mock.
181
- */
182
- const CreditKeyFigures: React.FunctionComponent<CreditKeyFiguresProps> = ({ t, figures, details, cls, fit: autoFit = true }) => {
183
- const [line1, line2] = creditKeyFigureLines(t, figures);
184
- const ref = useRef<HTMLDivElement>(null);
185
- const detailsLabel = t('autobahn:card.price.detailsLink', { defaultValue: 'Details' });
186
- const detailsEl = React.isValidElement(details) ? React.cloneElement(details as React.ReactElement<any>, {}, detailsLabel) : details;
187
- const key = `${line1.join('|')}#${line2.join('|')}#${detailsEl ? detailsLabel : ''}`;
188
-
189
- useIsoLayoutEffect(() => {
190
- const el = ref.current;
191
- if (!autoFit || !el || typeof window === 'undefined') return undefined;
192
- const fit = (): void => {
193
- el.style.fontSize = '';
194
- const lines = Array.prototype.slice.call(el.querySelectorAll('.ckf-line')) as HTMLElement[];
195
- const tooWide = (): boolean => lines.some((l) => l.scrollWidth > l.clientWidth + 0.5);
196
- if (!el.clientWidth || !tooWide()) return;
197
- let size = parseFloat(window.getComputedStyle(el).fontSize) || 12;
198
- for (let i = 0; i < 40 && size > MIN_FIT_PX && tooWide(); i++) {
199
- size = Math.max(MIN_FIT_PX, size - 0.25);
200
- el.style.fontSize = `${size}px`;
201
- }
202
- };
203
- fit();
204
- const RO = (window as any).ResizeObserver;
205
- if (!RO) return undefined;
206
- let width = el.clientWidth;
207
- const ro = new RO(() => {
208
- if (el.clientWidth !== width) {
209
- width = el.clientWidth;
210
- fit();
211
- }
212
- });
213
- ro.observe(el);
214
- return () => ro.disconnect();
215
- }, [key, autoFit]);
216
-
217
- const renderParts = (parts: string[]): React.ReactNode =>
218
- parts.map((part, i) => (
219
- <React.Fragment key={i}>
220
- {i > 0 && <span className="cc-terms-dot"> · </span>}
221
- {part}
222
- </React.Fragment>
223
- ));
224
- return (
225
- <div ref={ref} className={'ckf' + (autoFit ? '' : ' ckf--flow') + (cls ? ` ${cls}` : '')}>
226
- {line1.length > 0 && <span className="ckf-line">{renderParts(line1)}</span>}
227
- {/* separator between the two lines — only shown when they flow as one paragraph (ckf--flow) */}
228
- {line1.length > 0 && (line2.length > 0 || detailsEl) && <span className="ckf-sep cc-terms-dot"> · </span>}
229
- {(line2.length > 0 || detailsEl) && (
230
- <span className="ckf-line">
231
- {renderParts(line2)}
232
- {detailsEl && (
233
- <>
234
- {line2.length > 0 && <span className="cc-terms-dot"> · </span>}
235
- <span className="ckf-details">{detailsEl}</span>
236
- </>
237
- )}
238
- </span>
239
- )}
240
- </div>
241
- );
242
- };
243
-
244
- export default CreditKeyFigures;
1
+ import React, { useEffect, useLayoutEffect, useRef } from 'react';
2
+
3
+ import { TranslationFunction } from '../types';
4
+ import { formatEur, formatEurCents, formatPct } from '../utils/financeFormat';
5
+
6
+ /**
7
+ * Financing key figures of the representative example, in the order the PM asked for (ADV-405
8
+ * follow-up, 19.11): "60 Mon. · 24.549 € Nettokredit · Gesamtbetrag: 31.776,28 €" /
9
+ * "6,78 % Sollzins fest · 6,99 % eff. Jahreszins · Details". Same sources as the
10
+ * Finanzierungsdetails layer (FinanceDetailsModal): term = paybackPeriod, net loan =
11
+ * netLoanAmount, total = totalFinancingAmount (falls back to grossLoanAmount), nominal rate =
12
+ * nominalInterestRate, effective rate = annualPercentageRate. Leasing (kind: 'leasing', 19.11): see
13
+ * leasingKeyFigureLines / leasingKeyFigures below.
14
+ */
15
+ export interface CreditKeyFiguresData {
16
+ /** financing (default) or leasing — the two products word their lines differently. */
17
+ kind?: 'financing' | 'leasing';
18
+ /** contract term (paybackPeriod) — exactly the layer's "Vertragslaufzeit" (e.g. 48, also with a Schlussrate). */
19
+ months?: number | null;
20
+ /** final instalment (Schlussrate) of the same calculation — not shown; kept for the hosts' data. */
21
+ finalInstallment?: number | null;
22
+ netLoan?: number | null;
23
+ /** financing: Gesamtbetrag; leasing: the layer's "Gesamt inkl. Restwert" (see leasingKeyFigures). */
24
+ total?: number | null;
25
+ nominal?: number | null;
26
+ apr?: number | null;
27
+ /** leasing: the layer's "Einmalige Sonderzahlung" (0 is a real figure: "0 € Anzahlung"). */
28
+ down?: number | null;
29
+ /** leasing: the layer's "Anschaffungspreis" ("… € Barpreis"). */
30
+ cashPrice?: number | null;
31
+ /** leasing: the layer's "Restwert (verpflichtend)" — "Kaufpflicht" is shown when it is real. */
32
+ residual?: number | null;
33
+ }
34
+
35
+ export interface CreditKeyFiguresProps {
36
+ t: TranslationFunction;
37
+ figures: CreditKeyFiguresData;
38
+ /** optional trailing element of line 2 (the host's existing "Details"/"Finanzierungsdetails" link). */
39
+ details?: React.ReactNode;
40
+ /** host class(es) for size/colour/spacing (follow the host block's conditions line). */
41
+ cls?: string;
42
+ /** false: no two-line auto-fit — the host keeps its own font size and lets the figures flow as
43
+ * one wrapping paragraph (SRL desktop price column, PM 19.11: "own size, three lines are fine"). */
44
+ fit?: boolean;
45
+ }
46
+
47
+ const real = (n: number | null | undefined): n is number => typeof n === 'number' && isFinite(n) && n > 0;
48
+
49
+ /** the parts of both lines — only real figures, never a fabricated value; empty lines are dropped. */
50
+ export function creditKeyFigureLines(t: TranslationFunction, f: CreditKeyFiguresData): string[][] {
51
+ if (f.kind === 'leasing') return leasingKeyFigureLines(t, f);
52
+ const line1: string[] = [];
53
+ const line2: string[] = [];
54
+ if (real(f.months)) {
55
+ // the layer's "Vertragslaufzeit" (not the "N Raten à" count, which is one less with a Schlussrate)
56
+ const months = Math.round(f.months);
57
+ line1.push(t('autobahn:finance.kfMonths', { months, defaultValue: `${months} Mon.` }));
58
+ }
59
+ if (real(f.netLoan)) {
60
+ const v = formatEur(Math.round(f.netLoan));
61
+ line1.push(t('autobahn:finance.kfNetLoan', { value: v, defaultValue: `${v}€ Nettokredit` }));
62
+ }
63
+ if (real(f.total)) {
64
+ const v = formatEurCents(f.total);
65
+ line1.push(t('autobahn:finance.kfTotal', { value: v, defaultValue: `Gesamtbetrag: ${v}€` }));
66
+ }
67
+ if (real(f.nominal)) {
68
+ const v = formatPct(f.nominal);
69
+ line2.push(t('autobahn:finance.kfNominal', { value: v, defaultValue: `${v} Sollzins fest` }));
70
+ }
71
+ if (real(f.apr)) {
72
+ const v = formatPct(f.apr);
73
+ line2.push(t('autobahn:finance.kfApr', { value: v, defaultValue: `${v} eff. Jahreszins` }));
74
+ }
75
+ return [line1.map(keepUnits), line2.map(keepUnits)];
76
+ }
77
+
78
+ // keep every € / % on its amount's line (no-break space), like the € in the hosts' money strings
79
+ const keepUnits = (part: string): string => part.replace(/ (€|%)/g, '\u00a0$1');
80
+
81
+ /**
82
+ * Leasing key figures, worded as the PM's leasing mock ("Vorschlag: Restwert - Leasing", 19.11):
83
+ * "0 € Anzahlung · 60 Mon. · 24.549 € Barpreis · 31.776,28 € Gesamtbetrag" /
84
+ * "Kaufpflicht · 6,78 % Sollzins fest · 6,99 % eff. Jahreszins · Details". Anzahlung = the layer's
85
+ * Einmalige Sonderzahlung, Barpreis = Anschaffungspreis, Gesamtbetrag = Gesamt inkl. Restwert,
86
+ * "Kaufpflicht" = the mandatory Restwert (only when there is one). € without a space before it
87
+ * (client 19.11, financing and leasing alike); % keeps its space.
88
+ */
89
+ function leasingKeyFigureLines(t: TranslationFunction, f: CreditKeyFiguresData): string[][] {
90
+ const line1: string[] = [];
91
+ const line2: string[] = [];
92
+ if (typeof f.down === 'number' && isFinite(f.down) && f.down >= 0) {
93
+ const v = formatEur(Math.round(f.down));
94
+ line1.push(t('autobahn:finance.kfLeaseDown', { value: v, defaultValue: `${v}€ Anzahlung` }));
95
+ }
96
+ if (real(f.months)) {
97
+ const months = Math.round(f.months);
98
+ line1.push(t('autobahn:finance.kfMonths', { months, defaultValue: `${months} Mon.` }));
99
+ }
100
+ if (real(f.cashPrice)) {
101
+ const v = formatEur(Math.round(f.cashPrice));
102
+ line1.push(t('autobahn:finance.kfCashPrice', { value: v, defaultValue: `${v}€ Barpreis` }));
103
+ }
104
+ if (real(f.total)) {
105
+ const v = formatEurCents(f.total);
106
+ line1.push(t('autobahn:finance.kfLeaseTotal', { value: v, defaultValue: `${v}€ Gesamtbetrag` }));
107
+ }
108
+ if (real(f.residual)) {
109
+ line2.push(t('autobahn:finance.kfPurchaseObligation', { defaultValue: 'Kaufpflicht' }));
110
+ }
111
+ if (real(f.nominal)) {
112
+ const v = formatPct(f.nominal);
113
+ line2.push(t('autobahn:finance.kfNominal', { value: v, defaultValue: `${v} Sollzins fest` }));
114
+ }
115
+ if (real(f.apr)) {
116
+ const v = formatPct(f.apr);
117
+ line2.push(t('autobahn:finance.kfApr', { value: v, defaultValue: `${v} eff. Jahreszins` }));
118
+ }
119
+ return [line1.map(keepUnits), line2.map(keepUnits)];
120
+ }
121
+
122
+ /** true when at least one figure is real (otherwise hosts keep their previous conditions line). */
123
+ export function hasCreditKeyFigures(f: CreditKeyFiguresData): boolean {
124
+ return [f.months, f.netLoan, f.total, f.nominal, f.apr, f.cashPrice].some(real);
125
+ }
126
+
127
+ /** inputs of the Leasingdetails layer (FinanceDetailsModal, leasing) — see leasingKeyFigures. */
128
+ export interface LeasingKeyFigureInputs {
129
+ /** currentSalesPrice — the Anschaffungspreis fallback when there is no basePrice. */
130
+ price?: number | null;
131
+ /** common.basePrice ("no package" price). */
132
+ basePrice?: number | null;
133
+ monthly?: number | null;
134
+ term?: number | null;
135
+ /** Einmalige Sonderzahlung (leasing firstInstallment). */
136
+ down?: number | null;
137
+ /** Restwert (leasing finalInstallment). */
138
+ residual?: number | null;
139
+ withAddServices?: boolean | null;
140
+ /** the leasing package's one-time price (leasing addServicesCostRaw). */
141
+ addServicesCostRaw?: number | null;
142
+ nominal?: number | null;
143
+ apr?: number | null;
144
+ }
145
+
146
+ /**
147
+ * The leasing key figures with the Leasingdetails layer's own arithmetic (FinanceDetailsModal,
148
+ * leasing branch), so line and layer never disagree: Anschaffungspreis = (basePrice, else price)
149
+ * + the package when it is in the rate; Gesamt inkl. Restwert = term × rate + Sonderzahlung + the
150
+ * package when paid separately + Restwert. A missing input leaves its figure out (never invented).
151
+ */
152
+ export function leasingKeyFigures(i: LeasingKeyFigureInputs): CreditKeyFiguresData {
153
+ const raw = real(i.addServicesCostRaw) ? i.addServicesCostRaw : 0;
154
+ const base = real(i.basePrice) ? i.basePrice : real(i.price) ? i.price : undefined;
155
+ const down = typeof i.down === 'number' && isFinite(i.down) && i.down >= 0 ? i.down : undefined;
156
+ const residual = real(i.residual) ? i.residual : 0;
157
+ const ratesSum = real(i.monthly) && real(i.term) ? i.monthly * i.term : undefined;
158
+ return {
159
+ kind: 'leasing',
160
+ down,
161
+ months: real(i.term) ? i.term : undefined,
162
+ cashPrice: base != null ? base + (i.withAddServices && raw > 0 ? raw : 0) : undefined,
163
+ total: ratesSum != null ? ratesSum + (down || 0) + (raw > 0 && !i.withAddServices ? raw : 0) + residual : undefined,
164
+ residual: residual > 0 ? residual : undefined,
165
+ nominal: real(i.nominal) ? i.nominal : undefined,
166
+ apr: real(i.apr) ? i.apr : undefined,
167
+ };
168
+ }
169
+
170
+ /** smallest font the auto-fit goes down to (px); the PM wants both lines to stay one line each. */
171
+ const MIN_FIT_PX = 6;
172
+ const useIsoLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;
173
+
174
+ /**
175
+ * Exactly two lines with the financing key figures (Kerndaten) — PM 19.11: "from the months to
176
+ * Details it has to fit in 2 lines everywhere". Each line is one unbroken line (nowrap); when the
177
+ * host is too narrow the block's font size steps down (from the host's conditions-line size) until
178
+ * both lines fit, re-measured on resize. The " · " separators reuse the quiet .cc-terms-dot. The
179
+ * optional `details` element (the host's details link/button) ends line 2, always labelled
180
+ * "Details" (card.price.detailsLink), as in the PM's mock.
181
+ */
182
+ const CreditKeyFigures: React.FunctionComponent<CreditKeyFiguresProps> = ({ t, figures, details, cls, fit: autoFit = true }) => {
183
+ const [line1, line2] = creditKeyFigureLines(t, figures);
184
+ const ref = useRef<HTMLDivElement>(null);
185
+ const detailsLabel = t('autobahn:card.price.detailsLink', { defaultValue: 'Details' });
186
+ const detailsEl = React.isValidElement(details) ? React.cloneElement(details as React.ReactElement<any>, {}, detailsLabel) : details;
187
+ const key = `${line1.join('|')}#${line2.join('|')}#${detailsEl ? detailsLabel : ''}`;
188
+
189
+ useIsoLayoutEffect(() => {
190
+ const el = ref.current;
191
+ if (!autoFit || !el || typeof window === 'undefined') return undefined;
192
+ const fit = (): void => {
193
+ el.style.fontSize = '';
194
+ const lines = Array.prototype.slice.call(el.querySelectorAll('.ckf-line')) as HTMLElement[];
195
+ const tooWide = (): boolean => lines.some((l) => l.scrollWidth > l.clientWidth + 0.5);
196
+ if (!el.clientWidth || !tooWide()) return;
197
+ let size = parseFloat(window.getComputedStyle(el).fontSize) || 12;
198
+ for (let i = 0; i < 40 && size > MIN_FIT_PX && tooWide(); i++) {
199
+ size = Math.max(MIN_FIT_PX, size - 0.25);
200
+ el.style.fontSize = `${size}px`;
201
+ }
202
+ };
203
+ fit();
204
+ const RO = (window as any).ResizeObserver;
205
+ if (!RO) return undefined;
206
+ let width = el.clientWidth;
207
+ const ro = new RO(() => {
208
+ if (el.clientWidth !== width) {
209
+ width = el.clientWidth;
210
+ fit();
211
+ }
212
+ });
213
+ ro.observe(el);
214
+ return () => ro.disconnect();
215
+ }, [key, autoFit]);
216
+
217
+ const renderParts = (parts: string[]): React.ReactNode =>
218
+ parts.map((part, i) => (
219
+ <React.Fragment key={i}>
220
+ {i > 0 && <span className="cc-terms-dot"> · </span>}
221
+ {part}
222
+ </React.Fragment>
223
+ ));
224
+ return (
225
+ <div ref={ref} className={'ckf' + (autoFit ? '' : ' ckf--flow') + (cls ? ` ${cls}` : '')}>
226
+ {line1.length > 0 && <span className="ckf-line">{renderParts(line1)}</span>}
227
+ {/* separator between the two lines — only shown when they flow as one paragraph (ckf--flow) */}
228
+ {line1.length > 0 && (line2.length > 0 || detailsEl) && <span className="ckf-sep cc-terms-dot"> · </span>}
229
+ {(line2.length > 0 || detailsEl) && (
230
+ <span className="ckf-line">
231
+ {renderParts(line2)}
232
+ {detailsEl && (
233
+ <>
234
+ {line2.length > 0 && <span className="cc-terms-dot"> · </span>}
235
+ <span className="ckf-details">{detailsEl}</span>
236
+ </>
237
+ )}
238
+ </span>
239
+ )}
240
+ </div>
241
+ );
242
+ };
243
+
244
+ export default CreditKeyFigures;