@mmlogic/components 0.1.24 → 0.1.25

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/dist/cjs/loader.cjs.js +1 -1
  2. package/dist/cjs/mosterdcomponents.cjs.js +1 -1
  3. package/dist/cjs/mrd-boolean-field_19.cjs.entry.js +3150 -0
  4. package/dist/collection/collection-manifest.json +1 -0
  5. package/dist/collection/components/mrd-layout-section/mrd-layout-section.js +715 -0
  6. package/dist/collection/components/mrd-layout-section/mrd-layout-section.scss +339 -0
  7. package/dist/collection/components/mrd-longtext-field/mrd-longtext-field.js +1 -1
  8. package/dist/collection/components/mrd-number-field/mrd-number-field.js +1 -1
  9. package/dist/collection/components/mrd-table/mrd-table.js +41 -4
  10. package/dist/collection/components/mrd-table/mrd-table.scss +23 -0
  11. package/dist/collection/components/mrd-text-field/mrd-text-field.js +1 -1
  12. package/dist/collection/components/mrd-textarea-field/mrd-textarea-field.js +1 -1
  13. package/dist/collection/components/mrd-time-field/mrd-time-field.js +1 -1
  14. package/dist/collection/dev/app.js +109 -3
  15. package/dist/collection/dev/example-data.js +324 -0
  16. package/dist/collection/utils/cell-renderer.js +26 -0
  17. package/dist/components/mrd-layout-section.d.ts +11 -0
  18. package/dist/components/mrd-layout-section.js +1 -0
  19. package/dist/components/mrd-longtext-field2.js +1 -1
  20. package/dist/components/mrd-number-field2.js +1 -1
  21. package/dist/components/mrd-table.js +1 -1
  22. package/dist/components/mrd-table2.js +1 -0
  23. package/dist/components/mrd-text-field2.js +1 -1
  24. package/dist/components/mrd-textarea-field2.js +1 -1
  25. package/dist/components/mrd-time-field2.js +1 -1
  26. package/dist/esm/loader.js +1 -1
  27. package/dist/esm/mosterdcomponents.js +1 -1
  28. package/dist/esm/mrd-boolean-field_19.entry.js +3130 -0
  29. package/dist/mosterdcomponents/mosterdcomponents.esm.js +1 -1
  30. package/dist/mosterdcomponents/p-a3255fc4.entry.js +1 -0
  31. package/dist/types/components/mrd-layout-section/mrd-layout-section.d.ts +92 -0
  32. package/dist/types/components/mrd-table/mrd-table.d.ts +5 -0
  33. package/dist/types/components.d.ts +128 -8
  34. package/dist/types/types/client-layout.d.ts +19 -0
  35. package/dist/types/utils/cell-renderer.d.ts +9 -1
  36. package/package.json +1 -1
  37. package/dist/cjs/format-DExY8_nu.js +0 -328
  38. package/dist/cjs/mrd-boolean-field_17.cjs.entry.js +0 -1554
  39. package/dist/cjs/mrd-table.cjs.entry.js +0 -888
  40. package/dist/esm/format-CcRjWvcb.js +0 -319
  41. package/dist/esm/mrd-boolean-field_17.entry.js +0 -1536
  42. package/dist/esm/mrd-table.entry.js +0 -886
  43. package/dist/mosterdcomponents/p-17fe94c6.entry.js +0 -1
  44. package/dist/mosterdcomponents/p-3d856b27.entry.js +0 -1
  45. package/dist/mosterdcomponents/p-CcRjWvcb.js +0 -1
@@ -0,0 +1,3150 @@
1
+ 'use strict';
2
+
3
+ var index = require('./index-BPj2cBXs.js');
4
+ var index$1 = require('./index.cjs.js');
5
+
6
+ const mrdBooleanFieldScss = () => `.sc-mrd-boolean-field-h{display:block}.mrd-boolean-field.sc-mrd-boolean-field{display:flex;align-items:center;width:100%}.mrd-boolean-field__toggle-label.sc-mrd-boolean-field{display:flex;align-items:center;gap:var(--mrd-space-3);cursor:pointer;user-select:none}.mrd-boolean-field__checkbox.sc-mrd-boolean-field{position:absolute;opacity:0;width:0;height:0;pointer-events:none}.mrd-boolean-field__checkbox.sc-mrd-boolean-field:checked+.mrd-boolean-field__toggle.sc-mrd-boolean-field{background-color:var(--mrd-color-primary)}.mrd-boolean-field__checkbox.sc-mrd-boolean-field:checked+.mrd-boolean-field__toggle.sc-mrd-boolean-field::after{transform:translateX(20px)}.mrd-boolean-field__checkbox.sc-mrd-boolean-field:focus+.mrd-boolean-field__toggle.sc-mrd-boolean-field{box-shadow:var(--mrd-shadow-focus)}.mrd-boolean-field__checkbox.sc-mrd-boolean-field:disabled+.mrd-boolean-field__toggle.sc-mrd-boolean-field{opacity:0.5;cursor:not-allowed}.mrd-boolean-field__toggle.sc-mrd-boolean-field{position:relative;display:inline-block;width:44px;height:24px;background-color:var(--mrd-color-neutral-300);border-radius:var(--mrd-border-radius-full);transition:background-color var(--mrd-transition);flex-shrink:0}.mrd-boolean-field__toggle.sc-mrd-boolean-field::after{content:'';position:absolute;top:2px;left:2px;width:20px;height:20px;background-color:var(--mrd-color-white);border-radius:50%;transition:transform var(--mrd-transition);box-shadow:var(--mrd-shadow-sm)}.mrd-boolean-field__text.sc-mrd-boolean-field{font-family:var(--mrd-font-family);font-size:var(--mrd-font-size-base);color:var(--mrd-color-neutral-800)}.mrd-boolean-field__text--required.sc-mrd-boolean-field::after{content:' *';color:var(--mrd-color-danger)}`;
7
+
8
+ const MrdBooleanField = class {
9
+ constructor(hostRef) {
10
+ index.registerInstance(this, hostRef);
11
+ this.mrdChange = index.createEvent(this, "mrdChange");
12
+ this.mrdBlur = index.createEvent(this, "mrdBlur");
13
+ this.name = '';
14
+ this.label = '';
15
+ this.value = false;
16
+ this.required = false;
17
+ this.disabled = false;
18
+ this.locale = navigator.language;
19
+ this.checked = false;
20
+ this.handleChange = (e) => {
21
+ this.checked = e.target.checked;
22
+ this.mrdChange.emit({ name: this.name, value: this.checked });
23
+ };
24
+ this.handleBlur = () => {
25
+ this.mrdBlur.emit({ name: this.name, value: this.checked });
26
+ };
27
+ }
28
+ componentWillLoad() {
29
+ this.checked = !!this.value;
30
+ }
31
+ render() {
32
+ return (index.h(index.Host, { key: 'aed1d936d686870114a12aad9fc4cccb76ecd31e' }, index.h("div", { key: '5cc8aaa0f12d4195d02fce8a810d7d993e2e8c99', class: "mrd-boolean-field" }, index.h("label", { key: '41c3b3e0f01778fc2654ba86e3fe4e5a07c8537a', class: "mrd-boolean-field__toggle-label" }, index.h("input", { key: 'c261e6903e050d2f3d8df8abb90c74d99ed20161', class: "mrd-boolean-field__checkbox", type: "checkbox", name: this.name, checked: this.checked, disabled: this.disabled, onChange: this.handleChange, onBlur: this.handleBlur }), index.h("span", { key: '079ee220fe692536af15a7fb4286626102ae940e', class: "mrd-boolean-field__toggle", "aria-hidden": "true" }), this.label && (index.h("span", { key: '1f4f52a41f0bd6ba4c61cf9d4db74ab2f1aa8877', class: `mrd-boolean-field__text${this.required ? ' mrd-boolean-field__text--required' : ''}` }, this.label))))));
33
+ }
34
+ };
35
+ MrdBooleanField.style = mrdBooleanFieldScss();
36
+
37
+ const translations = {
38
+ nl: {
39
+ required: 'Dit veld is verplicht',
40
+ select_placeholder: 'Selecteer een optie',
41
+ search_placeholder: 'Zoeken...',
42
+ upload_file: 'Bestand uploaden',
43
+ choose_file: 'Bestand kiezen',
44
+ clear: 'Wissen',
45
+ today: 'Vandaag',
46
+ invalid_email: 'Voer een geldig e-mailadres in',
47
+ invalid_url: 'Voer een geldige URL in',
48
+ invalid_number: 'Voer een geldig getal in',
49
+ drop_file_here: 'Sleep bestand hierheen of',
50
+ browse: 'bladeren',
51
+ file_too_large: 'Bestand is te groot',
52
+ search_results: 'Zoekresultaten',
53
+ no_results: 'Geen resultaten gevonden',
54
+ loading: 'Laden...',
55
+ submit: 'Opslaan',
56
+ cancel: 'Annuleren',
57
+ remove: 'Verwijderen',
58
+ add: 'Toevoegen',
59
+ yes: 'Ja',
60
+ no: 'Nee',
61
+ // mrd-table footer
62
+ table_of: 'van',
63
+ download: 'Downloaden',
64
+ // mrd-table toolbar
65
+ table_filter: 'Filteren',
66
+ table_filter_hide: 'Filter verbergen',
67
+ table_filter_active: 'actief',
68
+ table_filter_clear_all: 'Alle filters wissen',
69
+ table_new_record: 'Nieuw record',
70
+ table_export_excel: 'Exporteer naar Excel',
71
+ // mrd-table filter popup
72
+ filter_sorting: 'Sortering',
73
+ filter_ascending: 'Oplopend',
74
+ filter_descending: 'Aflopend',
75
+ filter_section: 'Filter',
76
+ filter_apply: 'Toepassen',
77
+ filter_clear: 'Wissen',
78
+ filter_contains: 'Bevat',
79
+ filter_starts_with: 'Begint met',
80
+ filter_equals: 'Gelijk aan',
81
+ filter_has_value: 'Heeft waarde',
82
+ filter_is_empty: 'Is leeg',
83
+ filter_is_not_empty: 'Is niet leeg',
84
+ filter_exact: 'Exact',
85
+ filter_range: 'Bereik',
86
+ filter_from: 'Van',
87
+ filter_to: 'Tot',
88
+ filter_all: 'Alle',
89
+ filter_select_all: 'Alles',
90
+ filter_select_none: 'Geen',
91
+ filter_search_value: 'Zoekwaarde...',
92
+ filter_no_support: 'Geen filtering beschikbaar voor dit veldtype.',
93
+ // mrd-table textblock
94
+ textblock_show_more: 'Meer tonen',
95
+ close: 'Sluiten',
96
+ },
97
+ en: {
98
+ required: 'This field is required',
99
+ select_placeholder: 'Select an option',
100
+ search_placeholder: 'Search...',
101
+ upload_file: 'Upload file',
102
+ choose_file: 'Choose file',
103
+ clear: 'Clear',
104
+ today: 'Today',
105
+ invalid_email: 'Please enter a valid email address',
106
+ invalid_url: 'Please enter a valid URL',
107
+ invalid_number: 'Please enter a valid number',
108
+ drop_file_here: 'Drop file here or',
109
+ browse: 'browse',
110
+ file_too_large: 'File is too large',
111
+ search_results: 'Search results',
112
+ no_results: 'No results found',
113
+ loading: 'Loading...',
114
+ submit: 'Save',
115
+ cancel: 'Cancel',
116
+ remove: 'Remove',
117
+ add: 'Add',
118
+ yes: 'Yes',
119
+ no: 'No',
120
+ // mrd-table footer
121
+ table_of: 'of',
122
+ download: 'Download',
123
+ // mrd-table toolbar
124
+ table_filter: 'Filter',
125
+ table_filter_hide: 'Hide filter',
126
+ table_filter_active: 'active',
127
+ table_filter_clear_all: 'Clear all filters',
128
+ table_new_record: 'New record',
129
+ table_export_excel: 'Export to Excel',
130
+ // mrd-table filter popup
131
+ filter_sorting: 'Sorting',
132
+ filter_ascending: 'Ascending',
133
+ filter_descending: 'Descending',
134
+ filter_section: 'Filter',
135
+ filter_apply: 'Apply',
136
+ filter_clear: 'Clear',
137
+ filter_contains: 'Contains',
138
+ filter_starts_with: 'Starts with',
139
+ filter_equals: 'Equals',
140
+ filter_has_value: 'Has value',
141
+ filter_is_empty: 'Is empty',
142
+ filter_is_not_empty: 'Is not empty',
143
+ filter_exact: 'Exact',
144
+ filter_range: 'Range',
145
+ filter_from: 'From',
146
+ filter_to: 'To',
147
+ filter_all: 'All',
148
+ filter_select_all: 'All',
149
+ filter_select_none: 'None',
150
+ filter_search_value: 'Search value...',
151
+ filter_no_support: 'Filtering is not available for this field type.',
152
+ // mrd-table textblock
153
+ textblock_show_more: 'Show more',
154
+ close: 'Close',
155
+ },
156
+ ar: {
157
+ required: 'هذا الحقل مطلوب',
158
+ select_placeholder: 'اختر خياراً',
159
+ search_placeholder: 'بحث...',
160
+ upload_file: 'رفع ملف',
161
+ choose_file: 'اختر ملفاً',
162
+ clear: 'مسح',
163
+ today: 'اليوم',
164
+ invalid_email: 'يرجى إدخال عنوان بريد إلكتروني صحيح',
165
+ invalid_url: 'يرجى إدخال رابط صحيح',
166
+ invalid_number: 'يرجى إدخال رقم صحيح',
167
+ drop_file_here: 'اسحب الملف هنا أو',
168
+ browse: 'تصفح',
169
+ file_too_large: 'الملف كبير جداً',
170
+ search_results: 'نتائج البحث',
171
+ no_results: 'لم يتم العثور على نتائج',
172
+ loading: 'جار التحميل...',
173
+ submit: 'حفظ',
174
+ cancel: 'إلغاء',
175
+ remove: 'إزالة',
176
+ add: 'إضافة',
177
+ yes: 'نعم',
178
+ no: 'لا',
179
+ // mrd-table footer
180
+ table_of: 'من أصل',
181
+ download: 'تنزيل',
182
+ // mrd-table toolbar
183
+ table_filter: 'تصفية',
184
+ table_filter_hide: 'إخفاء التصفية',
185
+ table_filter_active: 'نشط',
186
+ table_filter_clear_all: 'مسح جميع الفلاتر',
187
+ table_new_record: 'سجل جديد',
188
+ table_export_excel: 'تصدير إلى Excel',
189
+ // mrd-table filter popup
190
+ filter_sorting: 'الترتيب',
191
+ filter_ascending: 'تصاعدي',
192
+ filter_descending: 'تنازلي',
193
+ filter_section: 'تصفية',
194
+ filter_apply: 'تطبيق',
195
+ filter_clear: 'مسح',
196
+ filter_contains: 'يحتوي على',
197
+ filter_starts_with: 'يبدأ بـ',
198
+ filter_equals: 'يساوي',
199
+ filter_has_value: 'له قيمة',
200
+ filter_is_empty: 'فارغ',
201
+ filter_is_not_empty: 'ليس فارغاً',
202
+ filter_exact: 'دقيق',
203
+ filter_range: 'نطاق',
204
+ filter_from: 'من',
205
+ filter_to: 'إلى',
206
+ filter_all: 'الكل',
207
+ filter_select_all: 'الكل',
208
+ filter_select_none: 'لا شيء',
209
+ filter_search_value: 'قيمة البحث...',
210
+ filter_no_support: 'التصفية غير متاحة لهذا النوع من الحقول.',
211
+ // mrd-table textblock
212
+ textblock_show_more: 'عرض المزيد',
213
+ close: 'إغلاق',
214
+ },
215
+ fr: {
216
+ required: 'Ce champ est obligatoire',
217
+ select_placeholder: 'Sélectionner une option',
218
+ search_placeholder: 'Rechercher...',
219
+ upload_file: 'Télécharger un fichier',
220
+ choose_file: 'Choisir un fichier',
221
+ clear: 'Effacer',
222
+ today: "Aujourd'hui",
223
+ invalid_email: 'Veuillez saisir une adresse e-mail valide',
224
+ invalid_url: 'Veuillez saisir une URL valide',
225
+ invalid_number: 'Veuillez saisir un nombre valide',
226
+ drop_file_here: 'Déposez le fichier ici ou',
227
+ browse: 'parcourir',
228
+ file_too_large: 'Le fichier est trop volumineux',
229
+ search_results: 'Résultats de recherche',
230
+ no_results: 'Aucun résultat trouvé',
231
+ loading: 'Chargement...',
232
+ submit: 'Enregistrer',
233
+ cancel: 'Annuler',
234
+ remove: 'Supprimer',
235
+ add: 'Ajouter',
236
+ yes: 'Oui',
237
+ no: 'Non',
238
+ // mrd-table footer
239
+ table_of: 'sur',
240
+ download: 'Télécharger',
241
+ // mrd-table toolbar
242
+ table_filter: 'Filtrer',
243
+ table_filter_hide: 'Masquer le filtre',
244
+ table_filter_active: 'actif',
245
+ table_filter_clear_all: 'Effacer tous les filtres',
246
+ table_new_record: 'Nouvel enregistrement',
247
+ table_export_excel: 'Exporter vers Excel',
248
+ // mrd-table filter popup
249
+ filter_sorting: 'Tri',
250
+ filter_ascending: 'Croissant',
251
+ filter_descending: 'Décroissant',
252
+ filter_section: 'Filtre',
253
+ filter_apply: 'Appliquer',
254
+ filter_clear: 'Effacer',
255
+ filter_contains: 'Contient',
256
+ filter_starts_with: 'Commence par',
257
+ filter_equals: 'Égal à',
258
+ filter_has_value: 'A une valeur',
259
+ filter_is_empty: 'Est vide',
260
+ filter_is_not_empty: "N'est pas vide",
261
+ filter_exact: 'Exact',
262
+ filter_range: 'Plage',
263
+ filter_from: 'De',
264
+ filter_to: 'À',
265
+ filter_all: 'Tous',
266
+ filter_select_all: 'Tous',
267
+ filter_select_none: 'Aucun',
268
+ filter_search_value: 'Valeur de recherche...',
269
+ filter_no_support: "Le filtrage n'est pas disponible pour ce type de champ.",
270
+ // mrd-table textblock
271
+ textblock_show_more: 'Voir plus',
272
+ close: 'Fermer',
273
+ },
274
+ };
275
+ function t(key, locale) {
276
+ var _a, _b, _c;
277
+ const lang = locale.split('-')[0].toLowerCase();
278
+ const dict = (_a = translations[lang]) !== null && _a !== void 0 ? _a : translations['en'];
279
+ return (_c = (_b = dict[key]) !== null && _b !== void 0 ? _b : translations['en'][key]) !== null && _c !== void 0 ? _c : key;
280
+ }
281
+
282
+ function validateRequired(value) {
283
+ if (value === null || value === undefined)
284
+ return false;
285
+ if (typeof value === 'string')
286
+ return value.trim().length > 0;
287
+ if (Array.isArray(value))
288
+ return value.length > 0;
289
+ if (typeof value === 'object') {
290
+ // CurrencyValue check
291
+ const cv = value;
292
+ if ('amount' in cv)
293
+ return cv.amount !== null && cv.amount !== undefined && cv.amount !== '';
294
+ }
295
+ return true;
296
+ }
297
+ function validateEmail(value) {
298
+ if (!value)
299
+ return true;
300
+ return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value);
301
+ }
302
+ function validateUrl(value) {
303
+ if (!value)
304
+ return true;
305
+ try {
306
+ new URL(value);
307
+ return true;
308
+ }
309
+ catch (_a) {
310
+ return false;
311
+ }
312
+ }
313
+ function validateNumber(value, dataType) {
314
+ if (value === null || value === undefined || value === '')
315
+ return true;
316
+ const num = Number(value);
317
+ if (isNaN(num))
318
+ return false;
319
+ if (dataType === index$1.ClientLayoutItemFieldDataType.INTEGER) {
320
+ return Number.isInteger(num);
321
+ }
322
+ if (dataType === index$1.ClientLayoutItemFieldDataType.PERCENTAGE) {
323
+ return num >= 0 && num <= 100;
324
+ }
325
+ return true;
326
+ }
327
+
328
+ function formatNumber(value, locale, options) {
329
+ if (value === null || value === undefined || isNaN(value))
330
+ return '';
331
+ return new Intl.NumberFormat(locale, options).format(value);
332
+ }
333
+ function formatCurrency(amount, currency, locale) {
334
+ if (amount === null || amount === undefined || isNaN(amount))
335
+ return '';
336
+ return new Intl.NumberFormat(locale, {
337
+ style: 'currency',
338
+ currency,
339
+ minimumFractionDigits: 2,
340
+ maximumFractionDigits: 2,
341
+ }).format(amount);
342
+ }
343
+ function formatPercentage(value, locale, decimalPrecision = 2) {
344
+ if (value === null || value === undefined || isNaN(value))
345
+ return '';
346
+ return new Intl.NumberFormat(locale, {
347
+ style: 'percent',
348
+ minimumFractionDigits: decimalPrecision,
349
+ maximumFractionDigits: decimalPrecision,
350
+ }).format(value);
351
+ }
352
+ function formatDate(value, locale) {
353
+ if (!value)
354
+ return '';
355
+ const date = typeof value === 'string' ? new Date(value) : value;
356
+ if (isNaN(date.getTime()))
357
+ return '';
358
+ return new Intl.DateTimeFormat(locale, { year: 'numeric', month: '2-digit', day: '2-digit' }).format(date);
359
+ }
360
+ function formatDateTime(value, locale) {
361
+ if (!value)
362
+ return '';
363
+ const date = typeof value === 'string' ? new Date(value) : value;
364
+ if (isNaN(date.getTime()))
365
+ return '';
366
+ return new Intl.DateTimeFormat(locale, {
367
+ year: 'numeric',
368
+ month: '2-digit',
369
+ day: '2-digit',
370
+ hour: '2-digit',
371
+ minute: '2-digit',
372
+ }).format(date);
373
+ }
374
+ function formatTime(value, locale) {
375
+ if (!value)
376
+ return '';
377
+ // value is HH:MM or HH:MM:SS
378
+ const [hours, minutes] = value.split(':').map(Number);
379
+ const date = new Date();
380
+ date.setHours(hours, minutes, 0, 0);
381
+ return new Intl.DateTimeFormat(locale, { hour: '2-digit', minute: '2-digit' }).format(date);
382
+ }
383
+ function parseLocalizedNumber(str, locale) {
384
+ var _a, _b, _c, _d;
385
+ if (!str || !str.trim())
386
+ return null;
387
+ // Detect decimal and thousands separators from the locale
388
+ const parts = new Intl.NumberFormat(locale).formatToParts(1234567.89);
389
+ const groupSep = (_b = (_a = parts.find((p) => p.type === 'group')) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : ',';
390
+ const decimalSep = (_d = (_c = parts.find((p) => p.type === 'decimal')) === null || _c === void 0 ? void 0 : _c.value) !== null && _d !== void 0 ? _d : '.';
391
+ // Remove group separators, replace decimal separator with '.'
392
+ const normalized = str
393
+ .replace(new RegExp(`\\${groupSep}`, 'g'), '')
394
+ .replace(new RegExp(`\\${decimalSep}`), '.')
395
+ .replace('%', '')
396
+ .trim();
397
+ const parsed = parseFloat(normalized);
398
+ return isNaN(parsed) ? null : parsed;
399
+ }
400
+
401
+ const mrdCurrencyFieldScss = () => `.sc-mrd-currency-field-h{display:block}.mrd-currency-field.sc-mrd-currency-field{display:flex;flex-direction:column;gap:var(--mrd-space-1);width:100%}.mrd-currency-field__label.sc-mrd-currency-field{display:block;font-family:var(--mrd-font-family);font-size:var(--mrd-label-font-size);font-weight:var(--mrd-label-font-weight);color:var(--mrd-label-color)}.mrd-currency-field__label--required.sc-mrd-currency-field::after{content:' *';color:var(--mrd-color-danger)}.mrd-currency-field__row.sc-mrd-currency-field{display:flex;gap:var(--mrd-space-2);align-items:stretch}.mrd-currency-field__amount.sc-mrd-currency-field{flex:1;height:var(--mrd-input-height);padding:var(--mrd-input-padding-y) var(--mrd-input-padding-x);font-family:var(--mrd-font-family);font-size:var(--mrd-font-size-base);color:var(--mrd-input-color);background-color:var(--mrd-input-bg);border:var(--mrd-border-width) solid var(--mrd-border-color);border-radius:var(--mrd-border-radius);transition:border-color var(--mrd-transition), box-shadow var(--mrd-transition);outline:none;appearance:none;text-align:right;box-sizing:border-box}.mrd-currency-field__amount.sc-mrd-currency-field:focus{border-color:var(--mrd-border-color-focus);box-shadow:var(--mrd-shadow-focus)}.mrd-currency-field__amount.sc-mrd-currency-field:disabled{background-color:var(--mrd-input-bg-disabled);cursor:not-allowed;opacity:0.7}.mrd-currency-field__amount--error.sc-mrd-currency-field{border-color:var(--mrd-border-color-error)}.mrd-currency-field__amount--error.sc-mrd-currency-field:focus{box-shadow:var(--mrd-shadow-focus-error)}.mrd-currency-field__currency.sc-mrd-currency-field{width:90px;height:var(--mrd-input-height);padding:var(--mrd-input-padding-y) var(--mrd-space-2);font-family:var(--mrd-font-family);font-size:var(--mrd-font-size-sm);font-weight:var(--mrd-font-weight-medium);color:var(--mrd-input-color);background-color:var(--mrd-color-neutral-50);border:var(--mrd-border-width) solid var(--mrd-border-color);border-radius:var(--mrd-border-radius);outline:none;cursor:pointer;box-sizing:border-box;appearance:none;text-align:center}.mrd-currency-field__currency.sc-mrd-currency-field:focus{border-color:var(--mrd-border-color-focus);box-shadow:var(--mrd-shadow-focus)}.mrd-currency-field__currency.sc-mrd-currency-field:disabled{background-color:var(--mrd-input-bg-disabled);cursor:not-allowed;opacity:0.7}.mrd-currency-field__error.sc-mrd-currency-field{font-family:var(--mrd-font-family);font-size:var(--mrd-error-font-size);color:var(--mrd-error-color)}`;
402
+
403
+ const COMMON_CURRENCIES = [
404
+ 'EUR', 'USD', 'GBP', 'CHF', 'JPY', 'CNY', 'AUD', 'CAD',
405
+ 'SEK', 'NOK', 'DKK', 'NZD', 'SGD', 'HKD', 'PLN', 'CZK',
406
+ 'HUF', 'MXN', 'BRL', 'INR', 'TRY', 'ZAR', 'AED', 'SAR',
407
+ ];
408
+ const MrdCurrencyField = class {
409
+ constructor(hostRef) {
410
+ index.registerInstance(this, hostRef);
411
+ this.mrdChange = index.createEvent(this, "mrdChange");
412
+ this.mrdBlur = index.createEvent(this, "mrdBlur");
413
+ this.name = '';
414
+ this.label = '';
415
+ this.value = { amount: null, currency: 'EUR' };
416
+ this.required = false;
417
+ this.disabled = false;
418
+ this.locale = navigator.language;
419
+ this.amountDisplay = '';
420
+ this.currency = 'EUR';
421
+ this.error = '';
422
+ this.handleAmountInput = (e) => {
423
+ this.amountDisplay = e.target.value;
424
+ };
425
+ this.handleAmountBlur = (e) => {
426
+ const raw = e.target.value;
427
+ const parsed = parseLocalizedNumber(raw, this.locale);
428
+ if (this.required && !validateRequired(raw)) {
429
+ this.error = t('required', this.locale);
430
+ }
431
+ else {
432
+ this.error = '';
433
+ }
434
+ const val = { amount: parsed, currency: this.currency };
435
+ this.mrdChange.emit({ name: this.name, value: val });
436
+ this.mrdBlur.emit({ name: this.name, value: val });
437
+ };
438
+ this.handleCurrencyChange = (e) => {
439
+ this.currency = e.target.value;
440
+ const parsed = parseLocalizedNumber(this.amountDisplay, this.locale);
441
+ this.mrdChange.emit({ name: this.name, value: { amount: parsed, currency: this.currency } });
442
+ };
443
+ }
444
+ componentWillLoad() {
445
+ if (this.value) {
446
+ this.currency = this.value.currency || 'EUR';
447
+ this.amountDisplay = this.value.amount !== null ? String(this.value.amount) : '';
448
+ }
449
+ }
450
+ render() {
451
+ const hasError = !!this.error;
452
+ return (index.h(index.Host, { key: 'd3450e9c26b1a755d3e6a5a3561d93b2ac566a28' }, index.h("div", { key: 'b66942cc1953daff728504deef8a9cc1330ef549', class: "mrd-currency-field" }, this.label && (index.h("label", { key: '3d3f2f06e9ffea944552f0f7cf3150d0246c54f0', class: `mrd-currency-field__label${this.required ? ' mrd-currency-field__label--required' : ''}` }, this.label)), index.h("div", { key: 'd30a2adfceefdbefef2d4fe6633a163a753b15d0', class: "mrd-currency-field__row" }, index.h("input", { key: '9af09b19b6cbe24498d6ca8edf7b28f675afdec5', class: `mrd-currency-field__amount${hasError ? ' mrd-currency-field__amount--error' : ''}`, type: "text", inputMode: "decimal", name: `${this.name}_amount`, value: this.amountDisplay, placeholder: "0.00", required: this.required, disabled: this.disabled, onInput: this.handleAmountInput, onBlur: this.handleAmountBlur }), index.h("select", { key: '21e55b04b7bf16586b5cfaa82d77db45c6dedf21', class: "mrd-currency-field__currency", disabled: this.disabled, onChange: this.handleCurrencyChange }, COMMON_CURRENCIES.map(c => (index.h("option", { key: c, value: c, selected: c === this.currency }, c))))), hasError && index.h("span", { key: '7a0006d4230557cf9c58f82f21de73b5d12f7e17', class: "mrd-currency-field__error" }, this.error))));
453
+ }
454
+ };
455
+ MrdCurrencyField.style = mrdCurrencyFieldScss();
456
+
457
+ const mrdDateFieldScss = () => `.sc-mrd-date-field-h{display:block}.mrd-date-field.sc-mrd-date-field{display:flex;flex-direction:column;gap:var(--mrd-space-1);width:100%}.mrd-date-field__label.sc-mrd-date-field{display:block;font-family:var(--mrd-font-family);font-size:var(--mrd-label-font-size);font-weight:var(--mrd-label-font-weight);color:var(--mrd-label-color)}.mrd-date-field__label--required.sc-mrd-date-field::after{content:' *';color:var(--mrd-color-danger)}.mrd-date-field__input.sc-mrd-date-field{display:block;width:100%;height:var(--mrd-input-height);padding:var(--mrd-input-padding-y) var(--mrd-input-padding-x);font-family:var(--mrd-font-family);font-size:var(--mrd-font-size-base);color:var(--mrd-input-color);background-color:var(--mrd-input-bg);border:var(--mrd-border-width) solid var(--mrd-border-color);border-radius:var(--mrd-border-radius);transition:border-color var(--mrd-transition), box-shadow var(--mrd-transition);outline:none;appearance:none;box-sizing:border-box;cursor:pointer}.mrd-date-field__input.sc-mrd-date-field:focus{border-color:var(--mrd-border-color-focus);box-shadow:var(--mrd-shadow-focus)}.mrd-date-field__input.sc-mrd-date-field:disabled{background-color:var(--mrd-input-bg-disabled);cursor:not-allowed;opacity:0.7}.mrd-date-field__input--error.sc-mrd-date-field{border-color:var(--mrd-border-color-error)}.mrd-date-field__input--error.sc-mrd-date-field:focus{box-shadow:var(--mrd-shadow-focus-error)}.mrd-date-field__error.sc-mrd-date-field{font-family:var(--mrd-font-family);font-size:var(--mrd-error-font-size);color:var(--mrd-error-color)}`;
458
+
459
+ const MrdDateField = class {
460
+ constructor(hostRef) {
461
+ index.registerInstance(this, hostRef);
462
+ this.mrdChange = index.createEvent(this, "mrdChange");
463
+ this.mrdBlur = index.createEvent(this, "mrdBlur");
464
+ this.name = '';
465
+ this.label = '';
466
+ this.value = '';
467
+ this.required = false;
468
+ this.disabled = false;
469
+ this.locale = navigator.language;
470
+ this.error = '';
471
+ this.handleChange = (e) => {
472
+ const val = e.target.value;
473
+ if (this.required && !validateRequired(val)) {
474
+ this.error = t('required', this.locale);
475
+ }
476
+ else {
477
+ this.error = '';
478
+ }
479
+ this.mrdChange.emit({ name: this.name, value: val });
480
+ };
481
+ this.handleBlur = (e) => {
482
+ const val = e.target.value;
483
+ this.mrdBlur.emit({ name: this.name, value: val });
484
+ };
485
+ }
486
+ render() {
487
+ const hasError = !!this.error;
488
+ return (index.h(index.Host, { key: '84c777fc68a95e0b1ceb08d61e3af7afa199ce94' }, index.h("div", { key: '6653d94ab79c74342ce792792547018e4464a814', class: "mrd-date-field" }, this.label && (index.h("label", { key: '2fa7b7ec50c784f9410ca48b93d50e39dc6e0bee', class: `mrd-date-field__label${this.required ? ' mrd-date-field__label--required' : ''}` }, this.label)), index.h("input", { key: 'f79ebbaf0e28ad7668a5400d1df514b66457b72d', class: `mrd-date-field__input${hasError ? ' mrd-date-field__input--error' : ''}`, type: "date", name: this.name, value: this.value, required: this.required, disabled: this.disabled, onChange: this.handleChange, onBlur: this.handleBlur }), hasError && index.h("span", { key: 'e52f0b720d76e8ba0586fb40395b6875860762db', class: "mrd-date-field__error" }, this.error))));
489
+ }
490
+ };
491
+ MrdDateField.style = mrdDateFieldScss();
492
+
493
+ const mrdDatetimeFieldScss = () => `.sc-mrd-datetime-field-h{display:block}.mrd-datetime-field.sc-mrd-datetime-field{display:flex;flex-direction:column;gap:var(--mrd-space-1);width:100%}.mrd-datetime-field__label.sc-mrd-datetime-field{display:block;font-family:var(--mrd-font-family);font-size:var(--mrd-label-font-size);font-weight:var(--mrd-label-font-weight);color:var(--mrd-label-color)}.mrd-datetime-field__label--required.sc-mrd-datetime-field::after{content:' *';color:var(--mrd-color-danger)}.mrd-datetime-field__input.sc-mrd-datetime-field{display:block;width:100%;height:var(--mrd-input-height);padding:var(--mrd-input-padding-y) var(--mrd-input-padding-x);font-family:var(--mrd-font-family);font-size:var(--mrd-font-size-base);color:var(--mrd-input-color);background-color:var(--mrd-input-bg);border:var(--mrd-border-width) solid var(--mrd-border-color);border-radius:var(--mrd-border-radius);transition:border-color var(--mrd-transition), box-shadow var(--mrd-transition);outline:none;appearance:none;box-sizing:border-box;cursor:pointer}.mrd-datetime-field__input.sc-mrd-datetime-field:focus{border-color:var(--mrd-border-color-focus);box-shadow:var(--mrd-shadow-focus)}.mrd-datetime-field__input.sc-mrd-datetime-field:disabled{background-color:var(--mrd-input-bg-disabled);cursor:not-allowed;opacity:0.7}.mrd-datetime-field__input--error.sc-mrd-datetime-field{border-color:var(--mrd-border-color-error)}.mrd-datetime-field__input--error.sc-mrd-datetime-field:focus{box-shadow:var(--mrd-shadow-focus-error)}.mrd-datetime-field__error.sc-mrd-datetime-field{font-family:var(--mrd-font-family);font-size:var(--mrd-error-font-size);color:var(--mrd-error-color)}`;
494
+
495
+ const MrdDatetimeField = class {
496
+ constructor(hostRef) {
497
+ index.registerInstance(this, hostRef);
498
+ this.mrdChange = index.createEvent(this, "mrdChange");
499
+ this.mrdBlur = index.createEvent(this, "mrdBlur");
500
+ this.name = '';
501
+ this.label = '';
502
+ this.value = '';
503
+ this.required = false;
504
+ this.disabled = false;
505
+ this.locale = navigator.language;
506
+ this.error = '';
507
+ this.localValue = '';
508
+ this.handleChange = (e) => {
509
+ const localVal = e.target.value;
510
+ this.localValue = localVal;
511
+ if (this.required && !validateRequired(localVal)) {
512
+ this.error = t('required', this.locale);
513
+ }
514
+ else {
515
+ this.error = '';
516
+ }
517
+ this.mrdChange.emit({ name: this.name, value: this.localToUtc(localVal) });
518
+ };
519
+ this.handleBlur = (e) => {
520
+ const localVal = e.target.value;
521
+ this.mrdBlur.emit({ name: this.name, value: this.localToUtc(localVal) });
522
+ };
523
+ }
524
+ componentWillLoad() {
525
+ this.localValue = this.utcToLocal(this.value);
526
+ }
527
+ valueChanged(newVal) {
528
+ this.localValue = this.utcToLocal(newVal);
529
+ }
530
+ // UTC ISO string → "YYYY-MM-DDTHH:mm" in local timezone (for datetime-local input)
531
+ utcToLocal(utcStr) {
532
+ if (!utcStr)
533
+ return '';
534
+ const d = new Date(utcStr);
535
+ if (isNaN(d.getTime()))
536
+ return '';
537
+ const pad = (n) => String(n).padStart(2, '0');
538
+ return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}T${pad(d.getHours())}:${pad(d.getMinutes())}`;
539
+ }
540
+ // "YYYY-MM-DDTHH:mm" local time → UTC ISO string (for API)
541
+ localToUtc(localStr) {
542
+ if (!localStr)
543
+ return '';
544
+ const d = new Date(localStr);
545
+ if (isNaN(d.getTime()))
546
+ return '';
547
+ return d.toISOString().replace(/\.\d{3}Z$/, 'Z');
548
+ }
549
+ render() {
550
+ const hasError = !!this.error;
551
+ return (index.h(index.Host, { key: '6052b08238484bee345ae4bb9b3025c7f2474c35' }, index.h("div", { key: 'f9073be4496e35a7d40405ae4e6a27a5c1607626', class: "mrd-datetime-field" }, this.label && (index.h("label", { key: '5933c3b2dfcae9bfad378441210ada6b625657a2', class: `mrd-datetime-field__label${this.required ? ' mrd-datetime-field__label--required' : ''}` }, this.label)), index.h("input", { key: '7a947b104c38960d2326a4877e4ca52db9fd9d84', class: `mrd-datetime-field__input${hasError ? ' mrd-datetime-field__input--error' : ''}`, type: "datetime-local", name: this.name, value: this.localValue, required: this.required, disabled: this.disabled, onChange: this.handleChange, onBlur: this.handleBlur }), hasError && index.h("span", { key: 'cea3dba7e14e18a3a08394ef3027b661f1808969', class: "mrd-datetime-field__error" }, this.error))));
552
+ }
553
+ static get watchers() { return {
554
+ "value": [{
555
+ "valueChanged": 0
556
+ }]
557
+ }; }
558
+ };
559
+ MrdDatetimeField.style = mrdDatetimeFieldScss();
560
+
561
+ const mrdEmailFieldScss = () => `.sc-mrd-email-field-h{display:block}.mrd-email-field.sc-mrd-email-field{display:flex;flex-direction:column;gap:var(--mrd-space-1);width:100%}.mrd-email-field__label.sc-mrd-email-field{display:block;font-family:var(--mrd-font-family);font-size:var(--mrd-label-font-size);font-weight:var(--mrd-label-font-weight);color:var(--mrd-label-color)}.mrd-email-field__label--required.sc-mrd-email-field::after{content:' *';color:var(--mrd-color-danger)}.mrd-email-field__input.sc-mrd-email-field{display:block;width:100%;height:var(--mrd-input-height);padding:var(--mrd-input-padding-y) var(--mrd-input-padding-x);font-family:var(--mrd-font-family);font-size:var(--mrd-font-size-base);color:var(--mrd-input-color);background-color:var(--mrd-input-bg);border:var(--mrd-border-width) solid var(--mrd-border-color);border-radius:var(--mrd-border-radius);transition:border-color var(--mrd-transition), box-shadow var(--mrd-transition);outline:none;appearance:none;box-sizing:border-box}.mrd-email-field__input.sc-mrd-email-field::placeholder{color:var(--mrd-input-placeholder-color)}.mrd-email-field__input.sc-mrd-email-field:focus{border-color:var(--mrd-border-color-focus);box-shadow:var(--mrd-shadow-focus)}.mrd-email-field__input.sc-mrd-email-field:disabled{background-color:var(--mrd-input-bg-disabled);cursor:not-allowed;opacity:0.7}.mrd-email-field__input--error.sc-mrd-email-field{border-color:var(--mrd-border-color-error)}.mrd-email-field__input--error.sc-mrd-email-field:focus{box-shadow:var(--mrd-shadow-focus-error)}.mrd-email-field__error.sc-mrd-email-field{font-family:var(--mrd-font-family);font-size:var(--mrd-error-font-size);color:var(--mrd-error-color)}`;
562
+
563
+ const MrdEmailField = class {
564
+ constructor(hostRef) {
565
+ index.registerInstance(this, hostRef);
566
+ this.mrdChange = index.createEvent(this, "mrdChange");
567
+ this.mrdBlur = index.createEvent(this, "mrdBlur");
568
+ this.name = '';
569
+ this.label = '';
570
+ this.value = '';
571
+ this.placeholder = '';
572
+ this.required = false;
573
+ this.disabled = false;
574
+ this.locale = navigator.language;
575
+ this.error = '';
576
+ this.handleInput = (e) => {
577
+ const val = e.target.value;
578
+ this.mrdChange.emit({ name: this.name, value: val });
579
+ };
580
+ this.handleBlur = (e) => {
581
+ const val = e.target.value;
582
+ if (this.required && !validateRequired(val)) {
583
+ this.error = t('required', this.locale);
584
+ }
585
+ else if (val && !validateEmail(val)) {
586
+ this.error = t('invalid_email', this.locale);
587
+ }
588
+ else {
589
+ this.error = '';
590
+ }
591
+ this.mrdBlur.emit({ name: this.name, value: val });
592
+ };
593
+ }
594
+ render() {
595
+ const hasError = !!this.error;
596
+ return (index.h(index.Host, { key: '851ec092957ab86e811b292eaabe29d04a600fe0' }, index.h("div", { key: '2d8969d60378f3161656369494549d682de8ec0e', class: "mrd-email-field" }, this.label && (index.h("label", { key: '7a35cc60d4804097e1a54f984c7da1829f6bbd11', class: `mrd-email-field__label${this.required ? ' mrd-email-field__label--required' : ''}` }, this.label)), index.h("input", { key: '1fc20e860aa021886f7ed522c3a0c8dd2cb1e093', class: `mrd-email-field__input${hasError ? ' mrd-email-field__input--error' : ''}`, type: "email", name: this.name, value: this.value, placeholder: this.placeholder || 'name@example.com', required: this.required, disabled: this.disabled, onInput: this.handleInput, onBlur: this.handleBlur }), hasError && index.h("span", { key: 'a44b3b41b7cd6b8c643cc64e6aadd884a2ba4961', class: "mrd-email-field__error" }, this.error))));
597
+ }
598
+ };
599
+ MrdEmailField.style = mrdEmailFieldScss();
600
+
601
+ const MrdField = class {
602
+ constructor(hostRef) {
603
+ index.registerInstance(this, hostRef);
604
+ this.mrdChange = index.createEvent(this, "mrdChange");
605
+ this.mrdBlur = index.createEvent(this, "mrdBlur");
606
+ this.mrdSearch = index.createEvent(this, "mrdSearch");
607
+ this.mrdFetchAll = index.createEvent(this, "mrdFetchAll");
608
+ this.mrdUpload = index.createEvent(this, "mrdUpload");
609
+ this.locale = navigator.language;
610
+ this.handleChange = (e) => {
611
+ e.stopPropagation();
612
+ this.mrdChange.emit(e.detail);
613
+ };
614
+ this.handleBlur = (e) => {
615
+ e.stopPropagation();
616
+ this.mrdBlur.emit(e.detail);
617
+ };
618
+ this.handleSearch = (e) => {
619
+ e.stopPropagation();
620
+ this.mrdSearch.emit(e.detail);
621
+ };
622
+ this.handleFetchAll = (e) => {
623
+ e.stopPropagation();
624
+ this.mrdFetchAll.emit(e.detail);
625
+ };
626
+ this.handleUpload = (e) => {
627
+ e.stopPropagation();
628
+ this.mrdUpload.emit(e.detail);
629
+ };
630
+ }
631
+ render() {
632
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8;
633
+ const { item, locale, value } = this;
634
+ if (item.type === index$1.ClientLayoutItemType.RELATION && item.relation) {
635
+ const rel = item.relation;
636
+ return (index.h(index.Host, null, index.h("mrd-relation-field", { name: rel.name, label: rel.label, required: rel.required, disabled: (_a = rel.disabled) !== null && _a !== void 0 ? _a : false, locale: locale, relatedClass: rel.relatedClass, mostSignificantClass: (_b = rel.mostSignificantClass) !== null && _b !== void 0 ? _b : '', displayType: (_c = rel.displayType) !== null && _c !== void 0 ? _c : index$1.ClientLayoutItemRelationDisplayType.SEARCH, editBehavior: (_d = rel.editBehavior) !== null && _d !== void 0 ? _d : null, commonRelation: rel.commonRelation, multiple: (_e = rel.multiple) !== null && _e !== void 0 ? _e : false, dropdownValues: (_f = rel.dropdownValues) !== null && _f !== void 0 ? _f : [], value: value, onMrdChange: this.handleChange, onMrdBlur: this.handleBlur, onMrdSearch: this.handleSearch, onMrdFetchAll: this.handleFetchAll })));
637
+ }
638
+ if (item.type !== index$1.ClientLayoutItemType.FIELD || !item.field) {
639
+ return index.h(index.Host, null);
640
+ }
641
+ const field = item.field;
642
+ const commonProps = {
643
+ name: field.name,
644
+ label: field.label,
645
+ required: field.required,
646
+ disabled: (_g = field.disabled) !== null && _g !== void 0 ? _g : false,
647
+ locale,
648
+ onMrdChange: this.handleChange,
649
+ onMrdBlur: this.handleBlur,
650
+ };
651
+ switch (field.dataType) {
652
+ case index$1.ClientLayoutItemFieldDataType.TEXT:
653
+ return (index.h(index.Host, null, index.h("mrd-text-field", Object.assign({}, commonProps, { value: (_h = value) !== null && _h !== void 0 ? _h : '', placeholder: (_j = field.placeholder) !== null && _j !== void 0 ? _j : '' }))));
654
+ case index$1.ClientLayoutItemFieldDataType.TEXTBLOCK:
655
+ return (index.h(index.Host, null, index.h("mrd-textarea-field", Object.assign({}, commonProps, { value: (_k = value) !== null && _k !== void 0 ? _k : '', placeholder: (_l = field.placeholder) !== null && _l !== void 0 ? _l : '' }))));
656
+ case index$1.ClientLayoutItemFieldDataType.INTEGER:
657
+ case index$1.ClientLayoutItemFieldDataType.DECIMAL:
658
+ case index$1.ClientLayoutItemFieldDataType.PERCENTAGE:
659
+ return (index.h(index.Host, null, index.h("mrd-number-field", Object.assign({}, commonProps, { value: (_m = value) !== null && _m !== void 0 ? _m : null, dataType: field.dataType, decimalPrecision: (_o = field.decimalPrecision) !== null && _o !== void 0 ? _o : 2, placeholder: (_p = field.placeholder) !== null && _p !== void 0 ? _p : '' }))));
660
+ case index$1.ClientLayoutItemFieldDataType.CURRENCY:
661
+ return (index.h(index.Host, null, index.h("mrd-currency-field", Object.assign({}, commonProps, { value: (_q = value) !== null && _q !== void 0 ? _q : { amount: null, currency: (_r = field.currencyCode) !== null && _r !== void 0 ? _r : 'EUR' } }))));
662
+ case index$1.ClientLayoutItemFieldDataType.BOOLEAN:
663
+ return (index.h(index.Host, null, index.h("mrd-boolean-field", Object.assign({}, commonProps, { value: (_s = value) !== null && _s !== void 0 ? _s : false }))));
664
+ case index$1.ClientLayoutItemFieldDataType.DATE:
665
+ return (index.h(index.Host, null, index.h("mrd-date-field", Object.assign({}, commonProps, { value: (_t = value) !== null && _t !== void 0 ? _t : '' }))));
666
+ case index$1.ClientLayoutItemFieldDataType.DATETIME:
667
+ return (index.h(index.Host, null, index.h("mrd-datetime-field", Object.assign({}, commonProps, { value: (_u = value) !== null && _u !== void 0 ? _u : '' }))));
668
+ case index$1.ClientLayoutItemFieldDataType.TIME:
669
+ return (index.h(index.Host, null, index.h("mrd-time-field", Object.assign({}, commonProps, { value: (_v = value) !== null && _v !== void 0 ? _v : '' }))));
670
+ case index$1.ClientLayoutItemFieldDataType.EMAIL:
671
+ return (index.h(index.Host, null, index.h("mrd-email-field", Object.assign({}, commonProps, { value: (_w = value) !== null && _w !== void 0 ? _w : '', placeholder: (_x = field.placeholder) !== null && _x !== void 0 ? _x : '' }))));
672
+ case index$1.ClientLayoutItemFieldDataType.HYPERLINK:
673
+ return (index.h(index.Host, null, index.h("mrd-hyperlink-field", Object.assign({}, commonProps, { value: (_y = value) !== null && _y !== void 0 ? _y : '', placeholder: (_z = field.placeholder) !== null && _z !== void 0 ? _z : '' }))));
674
+ case index$1.ClientLayoutItemFieldDataType.LIST:
675
+ return (index.h(index.Host, null, index.h("mrd-list-field", Object.assign({}, commonProps, { value: (_0 = value) !== null && _0 !== void 0 ? _0 : '', multiple: (_1 = field.multiple) !== null && _1 !== void 0 ? _1 : false, listItems: (_2 = field.listItems) !== null && _2 !== void 0 ? _2 : [] }))));
676
+ case index$1.ClientLayoutItemFieldDataType.FILE:
677
+ return (index.h(index.Host, null, index.h("mrd-file-field", Object.assign({}, commonProps, { value: value, accept: (_3 = field.accept) !== null && _3 !== void 0 ? _3 : '', maxSize: (_4 = field.maxSize) !== null && _4 !== void 0 ? _4 : 0, onMrdUpload: this.handleUpload }))));
678
+ case index$1.ClientLayoutItemFieldDataType.IMAGE:
679
+ return (index.h(index.Host, null, index.h("mrd-image-field", Object.assign({}, commonProps, { value: value, accept: (_5 = field.accept) !== null && _5 !== void 0 ? _5 : 'image/*', maxSize: (_6 = field.maxSize) !== null && _6 !== void 0 ? _6 : 0, onMrdUpload: this.handleUpload }))));
680
+ case index$1.ClientLayoutItemFieldDataType.LONGTEXT:
681
+ return (index.h(index.Host, null, index.h("mrd-longtext-field", Object.assign({}, commonProps, { value: (_7 = value) !== null && _7 !== void 0 ? _7 : '', placeholder: (_8 = field.placeholder) !== null && _8 !== void 0 ? _8 : '' }))));
682
+ case index$1.ClientLayoutItemFieldDataType.JSON:
683
+ return index.h(index.Host, null);
684
+ default:
685
+ return index.h(index.Host, null);
686
+ }
687
+ }
688
+ };
689
+
690
+ const mrdFileFieldScss = () => `.sc-mrd-file-field-h{display:block}.mrd-file-field.sc-mrd-file-field{display:flex;flex-direction:column;gap:var(--mrd-space-1);width:100%}.mrd-file-field__label.sc-mrd-file-field{display:block;font-family:var(--mrd-font-family);font-size:var(--mrd-label-font-size);font-weight:var(--mrd-label-font-weight);color:var(--mrd-label-color)}.mrd-file-field__label--required.sc-mrd-file-field::after{content:' *';color:var(--mrd-color-danger)}.mrd-file-field__zone.sc-mrd-file-field{display:flex;align-items:center;justify-content:center;padding:var(--mrd-space-6);border:2px dashed var(--mrd-border-color);border-radius:var(--mrd-border-radius-md);background-color:var(--mrd-color-neutral-50);cursor:pointer;transition:border-color var(--mrd-transition), background-color var(--mrd-transition);min-height:100px;position:relative}.mrd-file-field__zone.sc-mrd-file-field:hover{border-color:var(--mrd-color-primary);background-color:var(--mrd-color-primary-light)}.mrd-file-field__zone--dragging.sc-mrd-file-field{border-color:var(--mrd-color-primary);background-color:var(--mrd-color-primary-light)}.mrd-file-field__zone--error.sc-mrd-file-field{border-color:var(--mrd-border-color-error)}.mrd-file-field__zone--disabled.sc-mrd-file-field{opacity:0.6;cursor:not-allowed}.mrd-file-field__zone--disabled.sc-mrd-file-field:hover{border-color:var(--mrd-border-color);background-color:var(--mrd-color-neutral-50)}.mrd-file-field__input.sc-mrd-file-field{position:absolute;inset:0;opacity:0;width:100%;height:100%;cursor:pointer;pointer-events:none}.mrd-file-field__prompt.sc-mrd-file-field{display:flex;flex-direction:column;align-items:center;gap:var(--mrd-space-2);font-family:var(--mrd-font-family);font-size:var(--mrd-font-size-sm);color:var(--mrd-color-neutral-500);text-align:center}.mrd-file-field__upload-icon.sc-mrd-file-field{width:32px;height:32px;color:var(--mrd-color-neutral-400)}.mrd-file-field__browse.sc-mrd-file-field{color:var(--mrd-color-primary);font-weight:var(--mrd-font-weight-medium);text-decoration:underline}.mrd-file-field__selected.sc-mrd-file-field{display:flex;align-items:center;gap:var(--mrd-space-2);font-family:var(--mrd-font-family);font-size:var(--mrd-font-size-sm);color:var(--mrd-color-neutral-700)}.mrd-file-field__icon.sc-mrd-file-field{width:20px;height:20px;color:var(--mrd-color-primary);flex-shrink:0}.mrd-file-field__filename.sc-mrd-file-field{flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;max-width:200px}.mrd-file-field__clear.sc-mrd-file-field{background:none;border:none;cursor:pointer;color:var(--mrd-color-neutral-400);font-size:var(--mrd-font-size-sm);padding:var(--mrd-space-1);border-radius:var(--mrd-border-radius-sm);line-height:1}.mrd-file-field__clear.sc-mrd-file-field:hover{color:var(--mrd-color-danger);background-color:var(--mrd-color-danger-light)}.mrd-file-field__spinner.sc-mrd-file-field{display:inline-block;flex-shrink:0;width:18px;height:18px;border:2px solid var(--mrd-color-neutral-300);border-top-color:var(--mrd-color-primary);border-radius:50%;animation:mrd-file-spin 0.6s linear infinite}@keyframes mrd-file-spin{to{transform:rotate(360deg)}}.mrd-file-field__error.sc-mrd-file-field{font-family:var(--mrd-font-family);font-size:var(--mrd-error-font-size);color:var(--mrd-error-color)}`;
691
+
692
+ const MrdFileField = class {
693
+ constructor(hostRef) {
694
+ index.registerInstance(this, hostRef);
695
+ this.mrdChange = index.createEvent(this, "mrdChange");
696
+ this.mrdBlur = index.createEvent(this, "mrdBlur");
697
+ this.mrdUpload = index.createEvent(this, "mrdUpload");
698
+ this.name = '';
699
+ this.label = '';
700
+ this.value = null;
701
+ this.required = false;
702
+ this.disabled = false;
703
+ this.locale = navigator.language;
704
+ this.accept = '';
705
+ this.maxSize = 0; // bytes, 0 = no limit
706
+ this.fileName = '';
707
+ this.isDragging = false;
708
+ this.uploading = false;
709
+ this.error = '';
710
+ this.handleInputChange = (e) => {
711
+ var _a;
712
+ const files = e.target.files;
713
+ this.handleFile((_a = files === null || files === void 0 ? void 0 : files[0]) !== null && _a !== void 0 ? _a : null);
714
+ };
715
+ this.handleDragOver = (e) => {
716
+ e.preventDefault();
717
+ this.isDragging = true;
718
+ };
719
+ this.handleDragLeave = () => {
720
+ this.isDragging = false;
721
+ };
722
+ this.handleDrop = (e) => {
723
+ var _a, _b, _c;
724
+ e.preventDefault();
725
+ this.isDragging = false;
726
+ const file = (_c = (_b = (_a = e.dataTransfer) === null || _a === void 0 ? void 0 : _a.files) === null || _b === void 0 ? void 0 : _b[0]) !== null && _c !== void 0 ? _c : null;
727
+ this.handleFile(file);
728
+ };
729
+ this.handleZoneClick = () => {
730
+ var _a;
731
+ if (!this.disabled && !this.uploading) {
732
+ (_a = this.fileInputRef) === null || _a === void 0 ? void 0 : _a.click();
733
+ }
734
+ };
735
+ this.handleClear = (e) => {
736
+ e.stopPropagation();
737
+ this.fileName = '';
738
+ this.error = '';
739
+ this.uploading = false;
740
+ if (this.fileInputRef)
741
+ this.fileInputRef.value = '';
742
+ this.mrdChange.emit({ name: this.name, value: null });
743
+ };
744
+ }
745
+ /** When the host provides a URI back via setFieldValue, the upload is done. */
746
+ valueChanged(newVal) {
747
+ if (typeof newVal === 'string' && newVal) {
748
+ this.uploading = false;
749
+ }
750
+ else if (!newVal) {
751
+ this.uploading = false;
752
+ this.fileName = '';
753
+ }
754
+ }
755
+ handleFile(file) {
756
+ if (!file) {
757
+ this.fileName = '';
758
+ this.uploading = false;
759
+ this.mrdChange.emit({ name: this.name, value: null });
760
+ return;
761
+ }
762
+ if (this.maxSize > 0 && file.size > this.maxSize) {
763
+ this.error = t('file_too_large', this.locale);
764
+ return;
765
+ }
766
+ this.error = '';
767
+ this.fileName = file.name;
768
+ this.uploading = true;
769
+ this.mrdChange.emit({ name: this.name, value: file });
770
+ this.mrdUpload.emit({ name: this.name, file });
771
+ }
772
+ render() {
773
+ const hasFile = this.uploading || (typeof this.value === 'string' && this.value) || this.fileName;
774
+ const hasError = !!this.error;
775
+ const zoneClass = [
776
+ 'mrd-file-field__zone',
777
+ this.isDragging ? 'mrd-file-field__zone--dragging' : '',
778
+ hasError ? 'mrd-file-field__zone--error' : '',
779
+ this.disabled || this.uploading ? 'mrd-file-field__zone--disabled' : '',
780
+ ].filter(Boolean).join(' ');
781
+ return (index.h(index.Host, { key: '2090102df8169226c1e66f87cbc837296e4b55d4' }, index.h("div", { key: '7a37a09df1bfa2eaf28ed04c806ad5f7c0337bb0', class: "mrd-file-field" }, this.label && (index.h("label", { key: '8f1fcb8adbb66b792be902c7c548e50db99b6a53', class: `mrd-file-field__label${this.required ? ' mrd-file-field__label--required' : ''}` }, this.label)), index.h("div", { key: '66d992298f537b24d69ce3ead3dd229f6d124f3d', class: zoneClass, onClick: this.handleZoneClick, onDragOver: this.handleDragOver, onDragLeave: this.handleDragLeave, onDrop: this.handleDrop }, index.h("input", { key: '95ba6560e71ee08c6b2526802727b29a18cdc454', ref: el => (this.fileInputRef = el), class: "mrd-file-field__input", type: "file", name: this.name, accept: this.accept, disabled: this.disabled || this.uploading, required: this.required && !hasFile, onChange: this.handleInputChange }), hasFile ? (index.h("div", { class: "mrd-file-field__selected" }, this.uploading ? (index.h("span", { class: "mrd-file-field__spinner", "aria-label": t('loading', this.locale) })) : (index.h("svg", { class: "mrd-file-field__icon", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", "stroke-width": "2" }, index.h("path", { d: "M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z" }), index.h("polyline", { points: "14 2 14 8 20 8" }))), index.h("span", { class: "mrd-file-field__filename" }, this.fileName), !this.uploading && (index.h("button", { class: "mrd-file-field__clear", type: "button", onClick: this.handleClear, "aria-label": t('clear', this.locale) }, "\u2715")))) : (index.h("div", { class: "mrd-file-field__prompt" }, index.h("svg", { class: "mrd-file-field__upload-icon", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", "stroke-width": "2" }, index.h("polyline", { points: "16 16 12 12 8 16" }), index.h("line", { x1: "12", y1: "12", x2: "12", y2: "21" }), index.h("path", { d: "M20.39 18.39A5 5 0 0 0 18 9h-1.26A8 8 0 1 0 3 16.3" })), index.h("span", null, t('drop_file_here', this.locale), ' ', index.h("span", { class: "mrd-file-field__browse" }, t('browse', this.locale)))))), hasError && index.h("span", { key: 'a6020e63bebb01e31a980a903f81badd486585aa', class: "mrd-file-field__error" }, this.error))));
782
+ }
783
+ static get watchers() { return {
784
+ "value": [{
785
+ "valueChanged": 0
786
+ }]
787
+ }; }
788
+ };
789
+ MrdFileField.style = mrdFileFieldScss();
790
+
791
+ const mrdFormScss = () => `.sc-mrd-form-h{display:block}.mrd-form.sc-mrd-form{font-family:var(--mrd-font-family);width:100%}.mrd-form__title.sc-mrd-form{font-size:var(--mrd-font-size-2xl);font-weight:var(--mrd-font-weight-bold);color:var(--mrd-color-neutral-900);margin:0 0 var(--mrd-space-6) 0}.mrd-form__body.sc-mrd-form{display:flex;flex-direction:column;gap:var(--mrd-space-5)}.mrd-form__field.sc-mrd-form{display:flex;flex-direction:column;gap:var(--mrd-space-1)}.mrd-form__field-error.sc-mrd-form{font-family:var(--mrd-font-family);font-size:var(--mrd-error-font-size);color:var(--mrd-error-color)}.mrd-form__section.sc-mrd-form{border:var(--mrd-border-width) solid var(--mrd-border-color);border-radius:var(--mrd-border-radius-md);padding:var(--mrd-space-4) var(--mrd-space-5);margin:0}.mrd-form__section-legend.sc-mrd-form{font-family:var(--mrd-font-family);font-size:var(--mrd-font-size-base);font-weight:var(--mrd-font-weight-semibold);color:var(--mrd-color-neutral-700);padding:0 var(--mrd-space-2)}.mrd-form__section-body.sc-mrd-form{display:flex;flex-direction:column;gap:var(--mrd-space-4);margin-top:var(--mrd-space-2)}.mrd-form__group.sc-mrd-form{display:flex;flex-direction:column;gap:var(--mrd-space-2)}.mrd-form__group-label.sc-mrd-form{font-family:var(--mrd-font-family);font-size:var(--mrd-font-size-sm);font-weight:var(--mrd-font-weight-semibold);color:var(--mrd-color-neutral-500);text-transform:uppercase;letter-spacing:0.05em}.mrd-form__group-body.sc-mrd-form{display:flex;flex-direction:column;gap:var(--mrd-space-4);padding-left:var(--mrd-space-4);border-left:3px solid var(--mrd-color-neutral-200)}.mrd-form__footer.sc-mrd-form{margin-top:var(--mrd-space-8);padding-top:var(--mrd-space-5);border-top:var(--mrd-border-width) solid var(--mrd-border-color);display:flex;justify-content:flex-end;gap:var(--mrd-space-3)}.mrd-form__submit.sc-mrd-form{display:inline-flex;align-items:center;justify-content:center;height:var(--mrd-input-height);padding:0 var(--mrd-space-6);background-color:var(--mrd-color-primary);color:var(--mrd-color-white);font-family:var(--mrd-font-family);font-size:var(--mrd-font-size-base);font-weight:var(--mrd-font-weight-medium);border:none;border-radius:var(--mrd-border-radius);cursor:pointer;transition:background-color var(--mrd-transition)}.mrd-form__submit.sc-mrd-form:hover{background-color:var(--mrd-color-primary-hover)}.mrd-form__submit.sc-mrd-form:focus{outline:none;box-shadow:var(--mrd-shadow-focus)}.mrd-form__submit.sc-mrd-form:active{background-color:var(--mrd-color-primary-dark)}.mrd-form__cancel.sc-mrd-form{display:inline-flex;align-items:center;justify-content:center;height:var(--mrd-input-height);padding:0 var(--mrd-space-6);background-color:transparent;color:var(--mrd-color-neutral-600);font-family:var(--mrd-font-family);font-size:var(--mrd-font-size-base);font-weight:var(--mrd-font-weight-medium);border:var(--mrd-border-width) solid var(--mrd-border-color);border-radius:var(--mrd-border-radius);cursor:pointer;transition:background-color var(--mrd-transition), color var(--mrd-transition)}.mrd-form__cancel.sc-mrd-form:hover{background-color:var(--mrd-color-neutral-100);color:var(--mrd-color-neutral-800)}.mrd-form__cancel.sc-mrd-form:focus{outline:none;box-shadow:var(--mrd-shadow-focus)}.mrd-form__cancel.sc-mrd-form:active{background-color:var(--mrd-color-neutral-200)}`;
792
+
793
+ const MrdForm = class {
794
+ constructor(hostRef) {
795
+ index.registerInstance(this, hostRef);
796
+ this.mrdSubmit = index.createEvent(this, "mrdSubmit");
797
+ this.mrdCancel = index.createEvent(this, "mrdCancel");
798
+ this.mrdSearch = index.createEvent(this, "mrdSearch");
799
+ this.mrdFetchAll = index.createEvent(this, "mrdFetchAll");
800
+ this.mrdUpload = index.createEvent(this, "mrdUpload");
801
+ this.locale = navigator.language;
802
+ this.values = {};
803
+ /**
804
+ * Absolute href of the parent/reference object (e.g. the clientAgreement href
805
+ * when creating an invoice from within a client agreement).
806
+ * Combined with `referenceClass`, mrd-form will automatically pre-fill the
807
+ * matching relation field so dependent DROPDOWN fields can be fetched on load
808
+ * — without the host app needing to know anything about the form layout.
809
+ */
810
+ /**
811
+ * Absolute href of the parent/reference object (e.g. the clientAgreement href
812
+ * when creating an invoice from within a client agreement).
813
+ * Combined with `referenceClass`, mrd-form will automatically pre-fill the
814
+ * matching relation field so dependent DROPDOWN fields can be fetched on load.
815
+ */
816
+ this.referenceHref = '';
817
+ /**
818
+ * The `mostSignificantClass` of the parent/reference object
819
+ * (e.g. `'clientAgreements'`). Used to locate the matching RELATION field.
820
+ */
821
+ this.referenceClass = '';
822
+ /** When true, a cancel button is shown next to the submit button. */
823
+ this.showCancel = false;
824
+ this.formValues = {};
825
+ this.errors = {};
826
+ this.submitted = false;
827
+ this.initialValues = {};
828
+ this.handleFieldChange = (e) => {
829
+ const { name, value } = e.detail;
830
+ const prevHref = this.getHref(this.formValues[name]);
831
+ this.formValues = Object.assign(Object.assign({}, this.formValues), { [name]: value });
832
+ if (this.errors[name]) {
833
+ this.errors = Object.assign(Object.assign({}, this.errors), { [name]: '' });
834
+ }
835
+ // When a field changes, check if it is the commonRelation dependency for any
836
+ // DROPDOWN relation. If so, reset the dependent field and re-fetch its options.
837
+ // Skip when the effective href did not change (e.g. mrdBlur fires after mrdChange
838
+ // with the same value, which would otherwise trigger a duplicate fetch).
839
+ const newHref = this.getHref(value);
840
+ if (newHref === prevHref)
841
+ return;
842
+ for (const rel of this.collectDependentDropdowns()) {
843
+ if (rel.commonRelation !== name)
844
+ continue;
845
+ // Clear the dependent field's current selection (options have changed)
846
+ this.formValues = Object.assign(Object.assign({}, this.formValues), { [rel.name]: null });
847
+ this.mrdFetchAll.emit({
848
+ name: rel.name,
849
+ relatedClass: rel.relatedClass,
850
+ mostSignificantClass: rel.mostSignificantClass,
851
+ commonRelation: rel.commonRelation,
852
+ filter: rel.commonRelation + '_href',
853
+ filterValue: newHref, // empty string when dependency was cleared → host should clear the list
854
+ });
855
+ }
856
+ };
857
+ this.handleSearch = (e) => {
858
+ e.stopPropagation();
859
+ this.mrdSearch.emit(e.detail);
860
+ };
861
+ this.handleFetchAll = (e) => {
862
+ e.stopPropagation();
863
+ this.mrdFetchAll.emit(e.detail);
864
+ };
865
+ this.handleUpload = (e) => {
866
+ e.stopPropagation();
867
+ this.mrdUpload.emit(e.detail);
868
+ };
869
+ this.handleSubmit = (e) => {
870
+ e.preventDefault();
871
+ this.submitted = true;
872
+ if (this.validate()) {
873
+ this.mrdSubmit.emit(this.buildSubmitPayload());
874
+ }
875
+ };
876
+ }
877
+ componentWillLoad() {
878
+ var _a, _b;
879
+ this.initialValues = Object.assign({}, ((_a = this.values) !== null && _a !== void 0 ? _a : {}));
880
+ this.formValues = Object.assign({}, ((_b = this.values) !== null && _b !== void 0 ? _b : {}));
881
+ }
882
+ componentDidLoad() {
883
+ // Apply reference pre-fill and emit mrdFetchAll for dependent DROPDOWN fields.
884
+ // Deferred so Angular/host prop bindings are settled before we read them.
885
+ setTimeout(() => {
886
+ this.applyReferenceValue();
887
+ this.emitDependentFetchAll();
888
+ }, 0);
889
+ }
890
+ /** Sync formValues when the values prop is set from outside after mount
891
+ * (e.g. when pre-filling an existing record in edit mode). */
892
+ valuesChanged(newValues) {
893
+ this.initialValues = Object.assign({}, (newValues !== null && newValues !== void 0 ? newValues : {}));
894
+ this.formValues = Object.assign({}, (newValues !== null && newValues !== void 0 ? newValues : {}));
895
+ this.applyReferenceValue();
896
+ this.errors = {};
897
+ this.submitted = false;
898
+ // Re-check DROPDOWN dependencies now that formValues are updated
899
+ setTimeout(() => this.emitDependentFetchAll(), 0);
900
+ }
901
+ /**
902
+ * When referenceHref + referenceClass are set, find the matching layout field
903
+ * and inject its value into formValues. This allows dependent DROPDOWN fields
904
+ * (those with commonRelation pointing to that field) to be fetched on load
905
+ * without the host app doing any form-domain logic.
906
+ *
907
+ * Two lookup strategies:
908
+ * 1. Find a RELATION whose mostSignificantClass matches referenceClass.
909
+ * 2. Fallback: find a DROPDOWN whose commonRelation field is absent from the
910
+ * layout (API omitted it because it is implied by the reference context).
911
+ */
912
+ applyReferenceValue() {
913
+ if (!this.referenceHref || !this.referenceClass)
914
+ return;
915
+ const fieldName = this.resolveReferenceFieldName();
916
+ if (!fieldName)
917
+ return;
918
+ // Only set when not already present (don't overwrite an explicit value)
919
+ if (!this.formValues[fieldName]) {
920
+ this.formValues = Object.assign(Object.assign({}, this.formValues), { [fieldName]: this.referenceHref });
921
+ }
922
+ }
923
+ resolveReferenceFieldName() {
924
+ var _a, _b;
925
+ const allItems = this.collectFields((_b = (_a = this.layout) === null || _a === void 0 ? void 0 : _a.items) !== null && _b !== void 0 ? _b : []);
926
+ // Strategy 1: direct match on mostSignificantClass
927
+ const direct = allItems.find(item => {
928
+ var _a;
929
+ return item.type === index$1.ClientLayoutItemType.RELATION &&
930
+ ((_a = item.relation) === null || _a === void 0 ? void 0 : _a.mostSignificantClass) === this.referenceClass;
931
+ });
932
+ if (direct === null || direct === void 0 ? void 0 : direct.relation)
933
+ return direct.relation.name;
934
+ // Strategy 2: a DROPDOWN whose commonRelation field was omitted from the layout
935
+ const layoutRelationNames = new Set(allItems
936
+ .filter(item => item.type === index$1.ClientLayoutItemType.RELATION)
937
+ .map(item => item.relation.name));
938
+ for (const item of allItems) {
939
+ const rel = item.relation;
940
+ if (item.type === index$1.ClientLayoutItemType.RELATION &&
941
+ (rel === null || rel === void 0 ? void 0 : rel.editBehavior) === index$1.ClientLayoutItemRelationEditBehavior.DROPDOWN &&
942
+ rel.commonRelation &&
943
+ !layoutRelationNames.has(rel.commonRelation)) {
944
+ return rel.commonRelation;
945
+ }
946
+ }
947
+ return null;
948
+ }
949
+ async setFieldValue(name, value) {
950
+ this.formValues = Object.assign(Object.assign({}, this.formValues), { [name]: value });
951
+ if (this.errors[name]) {
952
+ this.errors = Object.assign(Object.assign({}, this.errors), { [name]: '' });
953
+ }
954
+ }
955
+ /** Collect all RELATION items that use editBehavior=DROPDOWN with a commonRelation. */
956
+ collectDependentDropdowns() {
957
+ var _a, _b;
958
+ return this.collectFields((_b = (_a = this.layout) === null || _a === void 0 ? void 0 : _a.items) !== null && _b !== void 0 ? _b : [])
959
+ .filter(item => {
960
+ var _a;
961
+ return item.type === index$1.ClientLayoutItemType.RELATION &&
962
+ ((_a = item.relation) === null || _a === void 0 ? void 0 : _a.editBehavior) === index$1.ClientLayoutItemRelationEditBehavior.DROPDOWN &&
963
+ !!item.relation.commonRelation;
964
+ })
965
+ .map(item => item.relation);
966
+ }
967
+ /** Emit mrdFetchAll for every dependent DROPDOWN whose filter value is currently set. */
968
+ emitDependentFetchAll() {
969
+ for (const rel of this.collectDependentDropdowns()) {
970
+ const filterValue = this.getHref(this.formValues[rel.commonRelation]);
971
+ if (filterValue) {
972
+ this.mrdFetchAll.emit({
973
+ name: rel.name,
974
+ relatedClass: rel.relatedClass,
975
+ mostSignificantClass: rel.mostSignificantClass,
976
+ commonRelation: rel.commonRelation,
977
+ filter: rel.commonRelation + '_href',
978
+ filterValue,
979
+ });
980
+ }
981
+ }
982
+ }
983
+ /** Extract a plain href string from a form value, which can be a string or
984
+ * a RelationSearchResult-like object with an `id` field. */
985
+ getHref(value) {
986
+ if (!value)
987
+ return '';
988
+ if (typeof value === 'string')
989
+ return value;
990
+ if (typeof value === 'object' && 'id' in value)
991
+ return value.id;
992
+ return '';
993
+ }
994
+ collectFields(items) {
995
+ const fields = [];
996
+ for (const item of items) {
997
+ if (item.type === index$1.ClientLayoutItemType.FIELD || item.type === index$1.ClientLayoutItemType.RELATION) {
998
+ fields.push(item);
999
+ }
1000
+ if (item.items) {
1001
+ fields.push(...this.collectFields(item.items));
1002
+ }
1003
+ }
1004
+ return fields;
1005
+ }
1006
+ validate() {
1007
+ var _a, _b, _c;
1008
+ const newErrors = {};
1009
+ const allFields = this.collectFields((_b = (_a = this.layout) === null || _a === void 0 ? void 0 : _a.items) !== null && _b !== void 0 ? _b : []);
1010
+ for (const item of allFields) {
1011
+ const def = (_c = item.field) !== null && _c !== void 0 ? _c : item.relation;
1012
+ if (!def)
1013
+ continue;
1014
+ if (def.required && !validateRequired(this.formValues[def.name])) {
1015
+ newErrors[def.name] = t('required', this.locale);
1016
+ }
1017
+ }
1018
+ this.errors = newErrors;
1019
+ return Object.keys(newErrors).length === 0;
1020
+ }
1021
+ normalizeFieldValue(value) {
1022
+ return (value === '' || value == null) ? null : value;
1023
+ }
1024
+ normalizeRelationValue(value) {
1025
+ if (value == null || value === '')
1026
+ return null;
1027
+ if (typeof value === 'string')
1028
+ return value || null;
1029
+ if (Array.isArray(value)) {
1030
+ return value.map(v => typeof v === 'object' && v !== null && 'id' in v ? v.id : String(v));
1031
+ }
1032
+ if (typeof value === 'object' && 'id' in value) {
1033
+ return value.id || null;
1034
+ }
1035
+ return null;
1036
+ }
1037
+ deepEqual(a, b) {
1038
+ if (a === b)
1039
+ return true;
1040
+ if (a == null && b == null)
1041
+ return true;
1042
+ if (a == null || b == null)
1043
+ return false;
1044
+ if (Array.isArray(a) && Array.isArray(b)) {
1045
+ if (a.length !== b.length)
1046
+ return false;
1047
+ const sa = [...a].sort();
1048
+ const sb = [...b].sort();
1049
+ return JSON.stringify(sa) === JSON.stringify(sb);
1050
+ }
1051
+ return JSON.stringify(a) === JSON.stringify(b);
1052
+ }
1053
+ /** Build a submit payload containing only fields that changed relative to
1054
+ * initialValues. For a new record (POST) initialValues is empty, so every
1055
+ * non-null field is included. For edit (PATCH) only modified fields are sent,
1056
+ * including fields explicitly cleared to null.
1057
+ */
1058
+ buildSubmitPayload() {
1059
+ var _a, _b;
1060
+ const payload = {};
1061
+ const allFields = this.collectFields((_b = (_a = this.layout) === null || _a === void 0 ? void 0 : _a.items) !== null && _b !== void 0 ? _b : []);
1062
+ for (const item of allFields) {
1063
+ if (item.type === index$1.ClientLayoutItemType.FIELD && item.field) {
1064
+ const name = item.field.name;
1065
+ const value = this.formValues[name];
1066
+ if (value instanceof File)
1067
+ continue;
1068
+ const current = this.normalizeFieldValue(value);
1069
+ const initial = this.normalizeFieldValue(this.initialValues[name]);
1070
+ if (this.deepEqual(current, initial))
1071
+ continue;
1072
+ payload[name] = current;
1073
+ }
1074
+ else if (item.type === index$1.ClientLayoutItemType.RELATION && item.relation) {
1075
+ const name = item.relation.name;
1076
+ const current = this.normalizeRelationValue(this.formValues[name]);
1077
+ const initial = this.normalizeRelationValue(this.initialValues[name]);
1078
+ if (this.deepEqual(current, initial))
1079
+ continue;
1080
+ payload[name] = current;
1081
+ }
1082
+ }
1083
+ return payload;
1084
+ }
1085
+ renderItems(items) {
1086
+ return items.map(item => {
1087
+ var _a, _b, _c, _d;
1088
+ if (item.type === index$1.ClientLayoutItemType.SECTION) {
1089
+ return (index.h("fieldset", { class: "mrd-form__section" }, item.label && index.h("legend", { class: "mrd-form__section-legend" }, item.label), index.h("div", { class: "mrd-form__section-body" }, item.items && this.renderItems(item.items))));
1090
+ }
1091
+ if (item.type === index$1.ClientLayoutItemType.GROUP) {
1092
+ return (index.h("div", { class: "mrd-form__group" }, item.label && index.h("div", { class: "mrd-form__group-label" }, item.label), index.h("div", { class: "mrd-form__group-body" }, item.items && this.renderItems(item.items))));
1093
+ }
1094
+ const fieldName = (_d = (_b = (_a = item.field) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : (_c = item.relation) === null || _c === void 0 ? void 0 : _c.name) !== null && _d !== void 0 ? _d : '';
1095
+ const fieldValue = this.formValues[fieldName];
1096
+ return (index.h("div", { class: "mrd-form__field" }, index.h("mrd-field", { item: item, locale: this.locale, value: fieldValue, onMrdChange: this.handleFieldChange, onMrdBlur: this.handleFieldChange, onMrdSearch: this.handleSearch, onMrdFetchAll: this.handleFetchAll, onMrdUpload: this.handleUpload }), this.errors[fieldName] && (index.h("span", { class: "mrd-form__field-error" }, this.errors[fieldName]))));
1097
+ });
1098
+ }
1099
+ render() {
1100
+ if (!this.layout) {
1101
+ return index.h(index.Host, null);
1102
+ }
1103
+ const dir = this.locale.startsWith('ar') ? 'rtl' : 'ltr';
1104
+ return (index.h(index.Host, null, index.h("form", { class: "mrd-form", dir: dir, onSubmit: this.handleSubmit, noValidate: true }, this.layout.title && index.h("h2", { class: "mrd-form__title" }, this.layout.title), index.h("div", { class: "mrd-form__body" }, this.renderItems(this.layout.items)), index.h("div", { class: "mrd-form__footer" }, index.h("button", { type: "submit", class: "mrd-form__submit" }, t('submit', this.locale)), this.showCancel && (index.h("button", { type: "button", class: "mrd-form__cancel", onClick: () => this.mrdCancel.emit() }, t('cancel', this.locale)))))));
1105
+ }
1106
+ static get watchers() { return {
1107
+ "values": [{
1108
+ "valuesChanged": 0
1109
+ }]
1110
+ }; }
1111
+ };
1112
+ MrdForm.style = mrdFormScss();
1113
+
1114
+ const mrdHyperlinkFieldScss = () => `.sc-mrd-hyperlink-field-h{display:block}.mrd-hyperlink-field.sc-mrd-hyperlink-field{display:flex;flex-direction:column;gap:var(--mrd-space-1);width:100%}.mrd-hyperlink-field__label.sc-mrd-hyperlink-field{display:block;font-family:var(--mrd-font-family);font-size:var(--mrd-label-font-size);font-weight:var(--mrd-label-font-weight);color:var(--mrd-label-color)}.mrd-hyperlink-field__label--required.sc-mrd-hyperlink-field::after{content:' *';color:var(--mrd-color-danger)}.mrd-hyperlink-field__input.sc-mrd-hyperlink-field{display:block;width:100%;height:var(--mrd-input-height);padding:var(--mrd-input-padding-y) var(--mrd-input-padding-x);font-family:var(--mrd-font-family);font-size:var(--mrd-font-size-base);color:var(--mrd-input-color);background-color:var(--mrd-input-bg);border:var(--mrd-border-width) solid var(--mrd-border-color);border-radius:var(--mrd-border-radius);transition:border-color var(--mrd-transition), box-shadow var(--mrd-transition);outline:none;appearance:none;box-sizing:border-box}.mrd-hyperlink-field__input.sc-mrd-hyperlink-field::placeholder{color:var(--mrd-input-placeholder-color)}.mrd-hyperlink-field__input.sc-mrd-hyperlink-field:focus{border-color:var(--mrd-border-color-focus);box-shadow:var(--mrd-shadow-focus)}.mrd-hyperlink-field__input.sc-mrd-hyperlink-field:disabled{background-color:var(--mrd-input-bg-disabled);cursor:not-allowed;opacity:0.7}.mrd-hyperlink-field__input--error.sc-mrd-hyperlink-field{border-color:var(--mrd-border-color-error)}.mrd-hyperlink-field__input--error.sc-mrd-hyperlink-field:focus{box-shadow:var(--mrd-shadow-focus-error)}.mrd-hyperlink-field__error.sc-mrd-hyperlink-field{font-family:var(--mrd-font-family);font-size:var(--mrd-error-font-size);color:var(--mrd-error-color)}`;
1115
+
1116
+ const MrdHyperlinkField = class {
1117
+ constructor(hostRef) {
1118
+ index.registerInstance(this, hostRef);
1119
+ this.mrdChange = index.createEvent(this, "mrdChange");
1120
+ this.mrdBlur = index.createEvent(this, "mrdBlur");
1121
+ this.name = '';
1122
+ this.label = '';
1123
+ this.value = '';
1124
+ this.placeholder = '';
1125
+ this.required = false;
1126
+ this.disabled = false;
1127
+ this.locale = navigator.language;
1128
+ this.error = '';
1129
+ this.handleInput = (e) => {
1130
+ const val = e.target.value;
1131
+ this.mrdChange.emit({ name: this.name, value: val });
1132
+ };
1133
+ this.handleBlur = (e) => {
1134
+ const val = e.target.value;
1135
+ if (this.required && !validateRequired(val)) {
1136
+ this.error = t('required', this.locale);
1137
+ }
1138
+ else if (val && !validateUrl(val)) {
1139
+ this.error = t('invalid_url', this.locale);
1140
+ }
1141
+ else {
1142
+ this.error = '';
1143
+ }
1144
+ this.mrdBlur.emit({ name: this.name, value: val });
1145
+ };
1146
+ }
1147
+ render() {
1148
+ const hasError = !!this.error;
1149
+ return (index.h(index.Host, { key: '4f642cb037c6e25786593dbf0cbead71ce34580c' }, index.h("div", { key: 'c679d95924bc2d22089c435ec15a35132a4a062d', class: "mrd-hyperlink-field" }, this.label && (index.h("label", { key: 'b391dd2d152c68fe75517926c40779313a23b9d9', class: `mrd-hyperlink-field__label${this.required ? ' mrd-hyperlink-field__label--required' : ''}` }, this.label)), index.h("input", { key: 'ea0d2aba8520ecbde4df8e4507e0f16bd497baa9', class: `mrd-hyperlink-field__input${hasError ? ' mrd-hyperlink-field__input--error' : ''}`, type: "url", name: this.name, value: this.value, placeholder: this.placeholder || 'https://', required: this.required, disabled: this.disabled, onInput: this.handleInput, onBlur: this.handleBlur }), hasError && index.h("span", { key: 'fab1d90c726b69c6c43c7997fd1b7480678c2c78', class: "mrd-hyperlink-field__error" }, this.error))));
1150
+ }
1151
+ };
1152
+ MrdHyperlinkField.style = mrdHyperlinkFieldScss();
1153
+
1154
+ const mrdImageFieldScss = () => `.sc-mrd-image-field-h{display:block}.mrd-image-field.sc-mrd-image-field{display:flex;flex-direction:column;gap:var(--mrd-space-1);width:100%}.mrd-image-field__label.sc-mrd-image-field{display:block;font-family:var(--mrd-font-family);font-size:var(--mrd-label-font-size);font-weight:var(--mrd-label-font-weight);color:var(--mrd-label-color)}.mrd-image-field__label--required.sc-mrd-image-field::after{content:' *';color:var(--mrd-color-danger)}.mrd-image-field__zone.sc-mrd-image-field{display:flex;align-items:center;justify-content:center;border:2px dashed var(--mrd-border-color);border-radius:var(--mrd-border-radius-md);background-color:var(--mrd-color-neutral-50);cursor:pointer;transition:border-color var(--mrd-transition), background-color var(--mrd-transition);min-height:100px;position:relative}.mrd-image-field__zone.sc-mrd-image-field:hover{border-color:var(--mrd-color-primary);background-color:var(--mrd-color-primary-light)}.mrd-image-field__zone--dragging.sc-mrd-image-field{border-color:var(--mrd-color-primary);background-color:var(--mrd-color-primary-light)}.mrd-image-field__zone--error.sc-mrd-image-field{border-color:var(--mrd-border-color-error)}.mrd-image-field__zone--disabled.sc-mrd-image-field{opacity:0.6;cursor:not-allowed}.mrd-image-field__zone--disabled.sc-mrd-image-field:hover{border-color:var(--mrd-border-color);background-color:var(--mrd-color-neutral-50)}.mrd-image-field__input.sc-mrd-image-field{position:absolute;inset:0;opacity:0;width:100%;height:100%;pointer-events:none}.mrd-image-field__prompt.sc-mrd-image-field{display:flex;flex-direction:column;align-items:center;gap:var(--mrd-space-2);padding:var(--mrd-space-6);font-family:var(--mrd-font-family);font-size:var(--mrd-font-size-sm);color:var(--mrd-color-neutral-500);text-align:center}.mrd-image-field__upload-icon.sc-mrd-image-field{width:40px;height:40px;color:var(--mrd-color-neutral-400)}.mrd-image-field__browse.sc-mrd-image-field{color:var(--mrd-color-primary);font-weight:var(--mrd-font-weight-medium);text-decoration:underline}.mrd-image-field__preview-container.sc-mrd-image-field{display:flex;align-items:center;gap:var(--mrd-space-4);padding:var(--mrd-space-4);width:100%}.mrd-image-field__preview-thumb.sc-mrd-image-field{flex-shrink:0;width:80px;height:80px;border-radius:var(--mrd-border-radius);overflow:hidden;border:var(--mrd-border-width) solid var(--mrd-border-color);background-color:var(--mrd-color-neutral-100)}.mrd-image-field__preview.sc-mrd-image-field{width:100%;height:100%;object-fit:cover;display:block}.mrd-image-field__preview-info.sc-mrd-image-field{flex:1;min-width:0;display:flex;flex-direction:column;gap:var(--mrd-space-1)}.mrd-image-field__preview-name.sc-mrd-image-field{font-family:var(--mrd-font-family);font-size:var(--mrd-font-size-sm);font-weight:var(--mrd-font-weight-medium);color:var(--mrd-color-neutral-800);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.mrd-image-field__preview-overlay.sc-mrd-image-field{position:absolute;inset:0;background:rgb(255 255 255 / 0.7);display:flex;align-items:center;justify-content:center;border-radius:var(--mrd-border-radius)}.mrd-image-field__spinner.sc-mrd-image-field{display:inline-block;width:24px;height:24px;border:2px solid var(--mrd-color-neutral-300);border-top-color:var(--mrd-color-primary);border-radius:50%;animation:mrd-image-spin 0.6s linear infinite}@keyframes mrd-image-spin{to{transform:rotate(360deg)}}.mrd-image-field__upload-status.sc-mrd-image-field{font-family:var(--mrd-font-family);font-size:var(--mrd-font-size-xs);color:var(--mrd-color-neutral-500)}.mrd-image-field__clear.sc-mrd-image-field{flex-shrink:0;background-color:var(--mrd-color-white);color:var(--mrd-color-danger);border:var(--mrd-border-width) solid var(--mrd-color-danger);border-radius:var(--mrd-border-radius);padding:var(--mrd-space-1) var(--mrd-space-3);font-family:var(--mrd-font-family);font-size:var(--mrd-font-size-sm);font-weight:var(--mrd-font-weight-medium);cursor:pointer;transition:background-color var(--mrd-transition), color var(--mrd-transition)}.mrd-image-field__clear.sc-mrd-image-field:hover{background-color:var(--mrd-color-danger);color:var(--mrd-color-white)}.mrd-image-field__error.sc-mrd-image-field{font-family:var(--mrd-font-family);font-size:var(--mrd-error-font-size);color:var(--mrd-error-color)}`;
1155
+
1156
+ const MrdImageField = class {
1157
+ constructor(hostRef) {
1158
+ index.registerInstance(this, hostRef);
1159
+ this.mrdChange = index.createEvent(this, "mrdChange");
1160
+ this.mrdBlur = index.createEvent(this, "mrdBlur");
1161
+ this.mrdUpload = index.createEvent(this, "mrdUpload");
1162
+ this.name = '';
1163
+ this.label = '';
1164
+ this.value = null;
1165
+ this.required = false;
1166
+ this.disabled = false;
1167
+ this.locale = navigator.language;
1168
+ this.accept = 'image/*';
1169
+ this.maxSize = 0;
1170
+ this.previewUrl = '';
1171
+ this.fileName = '';
1172
+ this.isDragging = false;
1173
+ this.uploading = false;
1174
+ this.error = '';
1175
+ this.handleInputChange = (e) => {
1176
+ var _a;
1177
+ const files = e.target.files;
1178
+ this.handleFile((_a = files === null || files === void 0 ? void 0 : files[0]) !== null && _a !== void 0 ? _a : null);
1179
+ };
1180
+ this.handleDragOver = (e) => {
1181
+ e.preventDefault();
1182
+ this.isDragging = true;
1183
+ };
1184
+ this.handleDragLeave = () => {
1185
+ this.isDragging = false;
1186
+ };
1187
+ this.handleDrop = (e) => {
1188
+ var _a, _b, _c;
1189
+ e.preventDefault();
1190
+ this.isDragging = false;
1191
+ const file = (_c = (_b = (_a = e.dataTransfer) === null || _a === void 0 ? void 0 : _a.files) === null || _b === void 0 ? void 0 : _b[0]) !== null && _c !== void 0 ? _c : null;
1192
+ this.handleFile(file);
1193
+ };
1194
+ this.handleZoneClick = () => {
1195
+ var _a;
1196
+ if (!this.disabled && !this.uploading) {
1197
+ (_a = this.fileInputRef) === null || _a === void 0 ? void 0 : _a.click();
1198
+ }
1199
+ };
1200
+ this.handleClear = (e) => {
1201
+ e.stopPropagation();
1202
+ this.previewUrl = '';
1203
+ this.fileName = '';
1204
+ this.error = '';
1205
+ this.uploading = false;
1206
+ if (this.fileInputRef)
1207
+ this.fileInputRef.value = '';
1208
+ this.mrdChange.emit({ name: this.name, value: null });
1209
+ };
1210
+ }
1211
+ /** When the host provides a URI back via setFieldValue, the upload is done. */
1212
+ valueChanged(newVal) {
1213
+ if (typeof newVal === 'string' && newVal) {
1214
+ this.uploading = false;
1215
+ }
1216
+ else if (!newVal) {
1217
+ this.uploading = false;
1218
+ this.previewUrl = '';
1219
+ this.fileName = '';
1220
+ }
1221
+ }
1222
+ handleFile(file) {
1223
+ if (!file) {
1224
+ this.previewUrl = '';
1225
+ this.fileName = '';
1226
+ this.uploading = false;
1227
+ this.mrdChange.emit({ name: this.name, value: null });
1228
+ return;
1229
+ }
1230
+ if (this.maxSize > 0 && file.size > this.maxSize) {
1231
+ this.error = t('file_too_large', this.locale);
1232
+ return;
1233
+ }
1234
+ if (!file.type.startsWith('image/')) {
1235
+ this.error = 'Please select an image file';
1236
+ return;
1237
+ }
1238
+ this.error = '';
1239
+ this.fileName = file.name;
1240
+ this.uploading = true;
1241
+ // Show local preview immediately while upload is in progress
1242
+ const reader = new FileReader();
1243
+ reader.onload = (ev) => {
1244
+ var _a;
1245
+ this.previewUrl = (_a = ev.target) === null || _a === void 0 ? void 0 : _a.result;
1246
+ };
1247
+ reader.readAsDataURL(file);
1248
+ this.mrdChange.emit({ name: this.name, value: file });
1249
+ this.mrdUpload.emit({ name: this.name, file });
1250
+ }
1251
+ render() {
1252
+ const hasError = !!this.error;
1253
+ const zoneClass = [
1254
+ 'mrd-image-field__zone',
1255
+ this.isDragging ? 'mrd-image-field__zone--dragging' : '',
1256
+ hasError ? 'mrd-image-field__zone--error' : '',
1257
+ this.disabled || this.uploading ? 'mrd-image-field__zone--disabled' : '',
1258
+ ].filter(Boolean).join(' ');
1259
+ return (index.h(index.Host, { key: '76b5a36a7f5a420ded3400c8a1481843363d1cbe' }, index.h("div", { key: '3544df84aaf427a25518bafe13d60cf89ed28537', class: "mrd-image-field" }, this.label && (index.h("label", { key: 'dca64c1600cb98526eb4b91a908106087f099ad1', class: `mrd-image-field__label${this.required ? ' mrd-image-field__label--required' : ''}` }, this.label)), index.h("div", { key: 'ce07f32126f0956e47ff6fc41ff231590e0503d3', class: zoneClass, onClick: this.handleZoneClick, onDragOver: this.handleDragOver, onDragLeave: this.handleDragLeave, onDrop: this.handleDrop }, index.h("input", { key: '660fbae5f730834c465522a11dd674fc8e50a54e', ref: el => (this.fileInputRef = el), class: "mrd-image-field__input", type: "file", name: this.name, accept: this.accept, disabled: this.disabled || this.uploading, required: this.required && !this.previewUrl, onChange: this.handleInputChange }), this.previewUrl ? (index.h("div", { class: "mrd-image-field__preview-container" }, index.h("div", { class: "mrd-image-field__preview-thumb" }, index.h("img", { class: "mrd-image-field__preview", src: this.previewUrl, alt: this.fileName }), this.uploading && index.h("div", { class: "mrd-image-field__preview-overlay" }, index.h("span", { class: "mrd-image-field__spinner" }))), index.h("div", { class: "mrd-image-field__preview-info" }, index.h("span", { class: "mrd-image-field__preview-name" }, this.fileName), this.uploading && (index.h("span", { class: "mrd-image-field__upload-status" }, t('loading', this.locale)))), !this.uploading && (index.h("button", { class: "mrd-image-field__clear", type: "button", onClick: this.handleClear, "aria-label": t('clear', this.locale) }, t('remove', this.locale))))) : (index.h("div", { class: "mrd-image-field__prompt" }, index.h("svg", { class: "mrd-image-field__upload-icon", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", "stroke-width": "2" }, index.h("rect", { x: "3", y: "3", width: "18", height: "18", rx: "2", ry: "2" }), index.h("circle", { cx: "8.5", cy: "8.5", r: "1.5" }), index.h("polyline", { points: "21 15 16 10 5 21" })), index.h("span", null, t('drop_file_here', this.locale), ' ', index.h("span", { class: "mrd-image-field__browse" }, t('browse', this.locale)))))), hasError && index.h("span", { key: '9b8f9563fea63bd12c38f5c480e9cbd24106c3af', class: "mrd-image-field__error" }, this.error))));
1260
+ }
1261
+ static get watchers() { return {
1262
+ "value": [{
1263
+ "valueChanged": 0
1264
+ }]
1265
+ }; }
1266
+ };
1267
+ MrdImageField.style = mrdImageFieldScss();
1268
+
1269
+ class CellRenderer {
1270
+ static render(column, row, locale) {
1271
+ var _a, _b, _c, _d;
1272
+ if (column.type === index$1.ClientLayoutItemType.RELATION) {
1273
+ const name = (_b = (_a = column.relation) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : '';
1274
+ const link = (_c = row === null || row === void 0 ? void 0 : row._links) === null || _c === void 0 ? void 0 : _c[name];
1275
+ if (!link)
1276
+ return '';
1277
+ if (Array.isArray(link))
1278
+ return link.map((l) => { var _a; return (_a = l.name) !== null && _a !== void 0 ? _a : ''; }).filter(Boolean).join(', ');
1279
+ return (_d = link.name) !== null && _d !== void 0 ? _d : '';
1280
+ }
1281
+ if (column.type !== index$1.ClientLayoutItemType.FIELD || !column.field)
1282
+ return '';
1283
+ const { name, dataType, listItems } = column.field;
1284
+ const raw = row === null || row === void 0 ? void 0 : row[name];
1285
+ if (raw == null || raw === '')
1286
+ return '';
1287
+ const values = Array.isArray(raw) ? raw : [raw];
1288
+ return values
1289
+ .map(v => CellRenderer.renderValue(dataType !== null && dataType !== void 0 ? dataType : 'TEXT', v, listItems !== null && listItems !== void 0 ? listItems : [], locale))
1290
+ .filter(s => s !== '')
1291
+ .join(', ');
1292
+ }
1293
+ static renderValue(dataType, value, listItems, locale) {
1294
+ var _a, _b;
1295
+ switch (dataType) {
1296
+ case 'INTEGER':
1297
+ return formatNumber(Number(value), locale, { maximumFractionDigits: 0 });
1298
+ case 'DECIMAL':
1299
+ return formatNumber(Number(value), locale);
1300
+ case 'PERCENTAGE':
1301
+ return formatPercentage(Number(value), locale);
1302
+ case 'CURRENCY': {
1303
+ const { amount, currency } = typeof value === 'object' && value !== null
1304
+ ? value
1305
+ : { amount: value, currency: '' };
1306
+ return currency
1307
+ ? formatCurrency(Number(amount), currency, locale)
1308
+ : formatNumber(Number(amount), locale);
1309
+ }
1310
+ case 'DATE':
1311
+ return formatDate(value, locale);
1312
+ case 'DATETIME':
1313
+ return formatDateTime(value, locale);
1314
+ case 'TIME':
1315
+ return formatTime(value, locale);
1316
+ case 'BOOLEAN':
1317
+ return value ? '✓' : '';
1318
+ case 'FILE':
1319
+ case 'IMAGE':
1320
+ return typeof value === 'object' && value !== null ? ((_a = value.fileName) !== null && _a !== void 0 ? _a : '') : '';
1321
+ case 'LIST': {
1322
+ const item = listItems.find(li => li.key === String(value));
1323
+ return (_b = item === null || item === void 0 ? void 0 : item.label) !== null && _b !== void 0 ? _b : String(value);
1324
+ }
1325
+ case 'TEXTBLOCK': {
1326
+ const stripped = String(value).replace(/<[^>]*>/g, '');
1327
+ const txt = document.createElement('textarea');
1328
+ txt.innerHTML = stripped;
1329
+ return txt.value.trim();
1330
+ }
1331
+ case 'LONGTEXT':
1332
+ return String(value).replace(/[\r\n]+/g, ' ').trim();
1333
+ case 'JSON': {
1334
+ const str = typeof value === 'object' ? JSON.stringify(value) : String(value);
1335
+ return str.replace(/[\r\n]+/g, ' ').trim();
1336
+ }
1337
+ default:
1338
+ return String(value);
1339
+ }
1340
+ }
1341
+ /**
1342
+ * Returns syntax-highlighted JSON as an HTML string with inline styles.
1343
+ * compact=true → single line (no indentation); compact=false → pretty-printed.
1344
+ */
1345
+ static formatJson(value, compact = false) {
1346
+ try {
1347
+ const parsed = typeof value === 'string' ? JSON.parse(value) : value;
1348
+ const json = compact ? JSON.stringify(parsed) : JSON.stringify(parsed, null, 2);
1349
+ return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, match => {
1350
+ let style = 'color:#2aa198';
1351
+ if (/^"/.test(match)) {
1352
+ style = /:$/.test(match) ? 'color:#881391' : 'color:#268bd2';
1353
+ }
1354
+ else if (/true|false/.test(match)) {
1355
+ style = 'color:#b58900';
1356
+ }
1357
+ else if (/null/.test(match)) {
1358
+ style = 'color:#dc322f';
1359
+ }
1360
+ return `<span style="${style}">${match}</span>`;
1361
+ });
1362
+ }
1363
+ catch (_a) {
1364
+ return String(value);
1365
+ }
1366
+ }
1367
+ }
1368
+
1369
+ const mrdLayoutSectionScss = () => `.mrd-layout-section.sc-mrd-layout-section{font-family:var(--mrd-font-family);font-size:var(--mrd-font-size-base);color:var(--mrd-color-neutral-800)}.mrd-layout-section__field.sc-mrd-layout-section{display:grid;grid-template-columns:200px 1fr;align-items:baseline;gap:0 var(--mrd-space-2);padding:var(--mrd-space-1) 0}.mrd-layout-section__field-label.sc-mrd-layout-section{font-size:var(--mrd-font-size-xs);font-weight:var(--mrd-font-weight-normal);color:var(--mrd-color-neutral-500);padding-top:1px}.mrd-layout-section__field-value.sc-mrd-layout-section{font-size:var(--mrd-font-size-sm);font-weight:var(--mrd-font-weight-medium);color:var(--mrd-color-neutral-800);word-break:break-word}.mrd-layout-section__field-header.sc-mrd-layout-section{font-size:var(--mrd-font-size-2xl);font-weight:var(--mrd-font-weight-bold);color:var(--mrd-color-neutral-900);margin:0 0 var(--mrd-space-4) 0;padding:0}.mrd-layout-section__header.sc-mrd-layout-section{font-size:var(--mrd-font-size-xl);font-weight:var(--mrd-font-weight-semibold);color:var(--mrd-color-neutral-800);margin:var(--mrd-space-4) 0 var(--mrd-space-2) 0;padding:0}.mrd-layout-section__text.sc-mrd-layout-section{font-size:var(--mrd-font-size-base);color:var(--mrd-color-neutral-700);line-height:var(--mrd-line-height-relaxed);margin:var(--mrd-space-2) 0}.mrd-layout-section__navigate.sc-mrd-layout-section{display:inline-flex;align-items:center;gap:var(--mrd-space-2);padding:var(--mrd-space-2) var(--mrd-space-3);background:none;border:1px solid var(--mrd-color-neutral-300);border-radius:var(--mrd-border-radius);font-family:var(--mrd-font-family);font-size:var(--mrd-font-size-sm);color:var(--mrd-color-primary);cursor:pointer;margin:var(--mrd-space-2) 0}.mrd-layout-section__navigate.sc-mrd-layout-section:hover{background-color:var(--mrd-color-primary-light);border-color:var(--mrd-color-primary)}.mrd-layout-section__link.sc-mrd-layout-section{color:var(--mrd-color-primary);text-decoration:none}.mrd-layout-section__link.sc-mrd-layout-section:hover{text-decoration:underline}.mrd-layout-section__relation-link.sc-mrd-layout-section{background:none;border:none;padding:0;font-family:var(--mrd-font-family);font-size:var(--mrd-font-size-sm);font-weight:var(--mrd-font-weight-semibold);color:var(--mrd-color-primary);cursor:pointer;text-align:left}.mrd-layout-section__relation-link.sc-mrd-layout-section:hover{text-decoration:underline}.mrd-layout-section__download-link.sc-mrd-layout-section{background:none;border:none;padding:0;font-family:var(--mrd-font-family);font-size:var(--mrd-font-size-sm);color:var(--mrd-color-primary);cursor:pointer;text-decoration:underline;text-align:left}.mrd-layout-section__boolean--true.sc-mrd-layout-section{color:var(--mrd-color-success);font-weight:var(--mrd-font-weight-semibold)}.mrd-layout-section__boolean--false.sc-mrd-layout-section{color:var(--mrd-color-neutral-400)}.mrd-layout-section__field--block.sc-mrd-layout-section{grid-template-columns:1fr}.mrd-layout-section__badge.sc-mrd-layout-section{display:inline-block;font-size:var(--mrd-font-size-xs);font-weight:var(--mrd-font-weight-medium);padding:2px var(--mrd-space-3);border-radius:10px}.mrd-layout-section__badge-dot-row.sc-mrd-layout-section{display:inline-flex;align-items:center;gap:var(--mrd-space-2)}.mrd-layout-section__badge-dot.sc-mrd-layout-section{display:inline-block;width:10px;height:10px;border-radius:50%;flex-shrink:0}.mrd-layout-section__pre.sc-mrd-layout-section{font-family:var(--mrd-font-family-mono);font-size:var(--mrd-font-size-xs);background-color:var(--mrd-color-neutral-50);border:1px solid var(--mrd-color-neutral-200);border-radius:var(--mrd-border-radius);padding:var(--mrd-space-3);margin:0;overflow-x:auto;white-space:pre-wrap;word-break:break-word}.mrd-layout-section__group.sc-mrd-layout-section{margin:var(--mrd-space-4) 0}.mrd-layout-section__group-title.sc-mrd-layout-section{font-size:var(--mrd-font-size-sm);font-weight:var(--mrd-font-weight-semibold);color:var(--mrd-color-neutral-500);margin:0 0 var(--mrd-space-2) 0;padding-bottom:0;text-transform:uppercase;letter-spacing:0.05em}.mrd-layout-section__related-view.sc-mrd-layout-section{margin:var(--mrd-space-4) 0}.mrd-layout-section__related-view-title.sc-mrd-layout-section{font-size:var(--mrd-font-size-lg);font-weight:var(--mrd-font-weight-semibold);color:var(--mrd-color-neutral-800);margin:0 0 var(--mrd-space-3) 0}.mrd-layout-section__search.sc-mrd-layout-section{position:relative;margin:var(--mrd-space-2) 0}.mrd-layout-section__search-input.sc-mrd-layout-section{display:block;width:100%;height:var(--mrd-input-height);padding:var(--mrd-input-padding-y) var(--mrd-input-padding-x);font-family:var(--mrd-font-family);font-size:var(--mrd-font-size-base);color:var(--mrd-input-color);background-color:var(--mrd-input-bg);border:var(--mrd-border-width) solid var(--mrd-border-color);border-radius:var(--mrd-border-radius);outline:none;appearance:none;box-sizing:border-box}.mrd-layout-section__search-input.sc-mrd-layout-section:focus{border-color:var(--mrd-border-color-focus);box-shadow:var(--mrd-shadow-focus)}.mrd-layout-section__search-input.sc-mrd-layout-section::placeholder{color:var(--mrd-input-placeholder-color)}.mrd-layout-section__search-results.sc-mrd-layout-section{position:absolute;top:100%;left:0;right:0;background-color:var(--mrd-color-white);border:1px solid var(--mrd-color-neutral-300);border-top:none;border-radius:0 0 var(--mrd-border-radius) var(--mrd-border-radius);box-shadow:var(--mrd-shadow-sm);z-index:100;max-height:300px;overflow-y:auto;list-style:none;margin:0;padding:var(--mrd-space-1) 0}.mrd-layout-section__search-result.sc-mrd-layout-section{margin:0;padding:0}.mrd-layout-section__search-result-btn.sc-mrd-layout-section{display:flex;flex-direction:column;width:100%;padding:var(--mrd-space-2) var(--mrd-space-3);background:none;border:none;text-align:left;cursor:pointer;font-family:var(--mrd-font-family)}.mrd-layout-section__search-result-btn.sc-mrd-layout-section:hover{background-color:var(--mrd-color-primary-light)}.mrd-layout-section__search-result-label.sc-mrd-layout-section{font-size:var(--mrd-font-size-sm);font-weight:var(--mrd-font-weight-medium);color:var(--mrd-color-neutral-800)}.mrd-layout-section__search-result-desc.sc-mrd-layout-section{font-size:var(--mrd-font-size-xs);color:var(--mrd-color-neutral-500);margin-top:var(--mrd-space-1)}.mrd-layout-section__image-thumb-btn.sc-mrd-layout-section{background:none;border:none;padding:0;cursor:pointer;display:inline-block;border-radius:var(--mrd-border-radius);overflow:hidden;line-height:0}.mrd-layout-section__image-thumb-btn.sc-mrd-layout-section:hover .mrd-layout-section__image-thumb.sc-mrd-layout-section{opacity:0.85}.mrd-layout-section__image-thumb.sc-mrd-layout-section{display:block;max-width:160px;max-height:100px;border-radius:var(--mrd-border-radius);object-fit:cover;transition:opacity 0.15s}.mrd-layout-section__modal-backdrop.sc-mrd-layout-section{position:fixed;inset:0;background:rgba(0, 0, 0, 0.6);z-index:300;display:flex;align-items:center;justify-content:center}.mrd-layout-section__modal.sc-mrd-layout-section{position:relative;background:#fff;border-radius:var(--mrd-border-radius);padding:var(--mrd-space-3);max-width:min(90vw, 900px);max-height:90vh;display:flex;align-items:center;justify-content:center;box-shadow:var(--mrd-shadow-lg)}.mrd-layout-section__modal-close.sc-mrd-layout-section{position:absolute;top:var(--mrd-space-2);right:var(--mrd-space-2);background:rgba(0, 0, 0, 0.5);border:none;border-radius:50%;width:28px;height:28px;display:flex;align-items:center;justify-content:center;color:#fff;cursor:pointer;font-size:var(--mrd-font-size-sm);line-height:1;z-index:1}.mrd-layout-section__modal-close.sc-mrd-layout-section:hover{background:rgba(0, 0, 0, 0.8)}.mrd-layout-section__modal-image.sc-mrd-layout-section{display:block;max-width:100%;max-height:calc(90vh - 2rem);border-radius:var(--mrd-border-radius);object-fit:contain}`;
1370
+
1371
+ const MrdLayoutSection = class {
1372
+ constructor(hostRef) {
1373
+ index.registerInstance(this, hostRef);
1374
+ this.mrdNavigate = index.createEvent(this, "mrdNavigate");
1375
+ this.mrdSearch = index.createEvent(this, "mrdSearch");
1376
+ this.mrdDownload = index.createEvent(this, "mrdDownload");
1377
+ this.mrdLoadView = index.createEvent(this, "mrdLoadView");
1378
+ this.mrdLoadViewPage = index.createEvent(this, "mrdLoadViewPage");
1379
+ this.mrdLoadImage = index.createEvent(this, "mrdLoadImage");
1380
+ this.mrdViewAction = index.createEvent(this, "mrdViewAction");
1381
+ /** Items from one layout entry in ClientDashboardMetadata.layouts[]. */
1382
+ this.items = [];
1383
+ /** Record data object; keys are field names, _links holds relation and related-view links. */
1384
+ this.data = {};
1385
+ /** View metadata map (ClientDashboardMetadata.views) for RELATED_VIEW and VIEW items. */
1386
+ this.views = {};
1387
+ /** Top-level _links from ClientDashboardMetadata; used to resolve hrefs for VIEW items. */
1388
+ this.links = {};
1389
+ this.locale = navigator.language;
1390
+ this.searchQueryMap = {};
1391
+ this.searchResultsMap = {};
1392
+ this.imagePreviewUrl = null;
1393
+ this.imagePreviews = {};
1394
+ this.viewLinksMap = {};
1395
+ this.searchTimers = {};
1396
+ this.handleViewLoadPage = (e, name) => {
1397
+ e.stopPropagation();
1398
+ this.mrdLoadViewPage.emit({ name, page: e.detail.page, sort: e.detail.sort });
1399
+ };
1400
+ this.handleSearchInput = (dataClass, query) => {
1401
+ this.searchQueryMap = Object.assign(Object.assign({}, this.searchQueryMap), { [dataClass]: query });
1402
+ if (this.searchTimers[dataClass])
1403
+ clearTimeout(this.searchTimers[dataClass]);
1404
+ if (query.length < 2) {
1405
+ this.searchResultsMap = Object.assign(Object.assign({}, this.searchResultsMap), { [dataClass]: [] });
1406
+ return;
1407
+ }
1408
+ this.searchTimers[dataClass] = setTimeout(() => {
1409
+ this.mrdSearch.emit({ query, dataClass });
1410
+ }, 300);
1411
+ };
1412
+ }
1413
+ componentDidLoad() {
1414
+ setTimeout(() => {
1415
+ this.emitLoadViews();
1416
+ this.emitLoadImages();
1417
+ }, 0);
1418
+ }
1419
+ linksChanged(newVal) {
1420
+ if (Object.keys(newVal !== null && newVal !== void 0 ? newVal : {}).length > 0) {
1421
+ this.emitLoadViews();
1422
+ }
1423
+ }
1424
+ dataChanged(newVal) {
1425
+ var _a;
1426
+ if (newVal && Object.keys((_a = newVal === null || newVal === void 0 ? void 0 : newVal._links) !== null && _a !== void 0 ? _a : {}).length > 0) {
1427
+ this.emitLoadViews();
1428
+ }
1429
+ }
1430
+ emitLoadViews() {
1431
+ var _a, _b, _c, _d, _e, _f;
1432
+ const dataLinks = ((_b = (_a = this.data) === null || _a === void 0 ? void 0 : _a._links) !== null && _b !== void 0 ? _b : {});
1433
+ for (const item of this.flattenItems(this.items)) {
1434
+ if (item.type === index$1.ClientLayoutItemType.RELATED_VIEW && item.relatedView) {
1435
+ const rv = item.relatedView;
1436
+ const viewConfig = this.views[rv.name];
1437
+ if (!viewConfig)
1438
+ continue;
1439
+ const href = (_c = dataLinks[rv.relatedClass]) === null || _c === void 0 ? void 0 : _c.href;
1440
+ this.mrdLoadView.emit({ name: rv.name, href, viewConfig });
1441
+ }
1442
+ else if (item.type === index$1.ClientLayoutItemType.VIEW) {
1443
+ const viewName = (_e = (_d = item.view) === null || _d === void 0 ? void 0 : _d.name) !== null && _e !== void 0 ? _e : item.name;
1444
+ if (!viewName)
1445
+ continue;
1446
+ const viewConfig = this.views[viewName];
1447
+ if (!viewConfig)
1448
+ continue;
1449
+ const href = (_f = this.links[viewName]) === null || _f === void 0 ? void 0 : _f.href;
1450
+ this.mrdLoadView.emit({ name: viewName, href, viewConfig });
1451
+ }
1452
+ }
1453
+ }
1454
+ emitLoadImages() {
1455
+ var _a;
1456
+ for (const item of this.flattenItems(this.items)) {
1457
+ if (item.type === index$1.ClientLayoutItemType.FIELD && ((_a = item.field) === null || _a === void 0 ? void 0 : _a.dataType) === index$1.ClientLayoutItemFieldDataType.IMAGE) {
1458
+ const fieldName = item.field.name;
1459
+ const raw = this.data[fieldName];
1460
+ const href = raw === null || raw === void 0 ? void 0 : raw.href;
1461
+ if (href)
1462
+ this.mrdLoadImage.emit({ fieldName, href });
1463
+ }
1464
+ }
1465
+ }
1466
+ flattenItems(items) {
1467
+ const result = [];
1468
+ for (const item of items) {
1469
+ result.push(item);
1470
+ if (item.items)
1471
+ result.push(...this.flattenItems(item.items));
1472
+ }
1473
+ return result;
1474
+ }
1475
+ /** Inject search results. Pass dataClass to target a specific SEARCH item; omit when there is only one. */
1476
+ async setSearchResults(results, dataClass) {
1477
+ const key = dataClass !== null && dataClass !== void 0 ? dataClass : this.resolveSearchKey();
1478
+ if (key) {
1479
+ this.searchResultsMap = Object.assign(Object.assign({}, this.searchResultsMap), { [key]: results });
1480
+ }
1481
+ }
1482
+ /**
1483
+ * Inject data into an embedded mrd-table for a RELATED_VIEW or VIEW item.
1484
+ * Pass totalElements on page 0 to initialise the table; omit on subsequent pages.
1485
+ * Pass pageLinks (_links from the page response) on page 0 to enable action hrefs in mrdViewAction.
1486
+ */
1487
+ async setViewPage(name, page, rows, totalElements, pageLinks) {
1488
+ if (pageLinks) {
1489
+ this.viewLinksMap = Object.assign(Object.assign({}, this.viewLinksMap), { [name]: pageLinks });
1490
+ }
1491
+ const table = this.el.querySelector(`mrd-table[data-view="${name}"]`);
1492
+ if (!table)
1493
+ return;
1494
+ if (totalElements !== undefined) {
1495
+ table.totalElements = totalElements;
1496
+ await table.init();
1497
+ }
1498
+ await table.setPage(page, rows);
1499
+ }
1500
+ /** Provide a resolved URL for an IMAGE field. Shows as thumbnail; clicking opens the lightbox. */
1501
+ async setImagePreview(fieldName, url) {
1502
+ this.imagePreviews = Object.assign(Object.assign({}, this.imagePreviews), { [fieldName]: url });
1503
+ }
1504
+ /** Open the lightbox directly with a URL (e.g. after mrdDownload on a FILE field). */
1505
+ async openImagePreview(url) {
1506
+ this.imagePreviewUrl = url;
1507
+ }
1508
+ resolveSearchKey() {
1509
+ const items = this.flattenItems(this.items).filter(i => i.type === index$1.ClientLayoutItemType.SEARCH);
1510
+ if (items.length === 1 && items[0].search)
1511
+ return items[0].search.dataClass;
1512
+ return null;
1513
+ }
1514
+ renderSingleFieldValue(item, value) {
1515
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
1516
+ const field = item.field;
1517
+ const dt = field.dataType;
1518
+ switch (dt) {
1519
+ case index$1.ClientLayoutItemFieldDataType.HYPERLINK: {
1520
+ const v = value;
1521
+ const href = (_a = v === null || v === void 0 ? void 0 : v.href) !== null && _a !== void 0 ? _a : String(value);
1522
+ const label = (_c = (_b = v === null || v === void 0 ? void 0 : v.text) !== null && _b !== void 0 ? _b : v === null || v === void 0 ? void 0 : v.label) !== null && _c !== void 0 ? _c : href;
1523
+ return (index.h("a", { class: "mrd-layout-section__link", href: href, target: "_blank", rel: "noopener noreferrer" }, label));
1524
+ }
1525
+ case index$1.ClientLayoutItemFieldDataType.TEXTBLOCK:
1526
+ return index.h("span", { innerHTML: String(value) });
1527
+ case index$1.ClientLayoutItemFieldDataType.LONGTEXT:
1528
+ return index.h("pre", { class: "mrd-layout-section__pre" }, String(value));
1529
+ case index$1.ClientLayoutItemFieldDataType.JSON:
1530
+ return index.h("pre", { class: "mrd-layout-section__pre", innerHTML: CellRenderer.formatJson(value) });
1531
+ case index$1.ClientLayoutItemFieldDataType.FILE: {
1532
+ const v = value;
1533
+ const fileName = (_d = v === null || v === void 0 ? void 0 : v.fileName) !== null && _d !== void 0 ? _d : String(value);
1534
+ const href = (_e = v === null || v === void 0 ? void 0 : v.href) !== null && _e !== void 0 ? _e : '';
1535
+ return (index.h("button", { class: "mrd-layout-section__download-link", onClick: () => href && this.mrdDownload.emit({ href, fileName }) }, t('download', this.locale)));
1536
+ }
1537
+ case index$1.ClientLayoutItemFieldDataType.IMAGE: {
1538
+ const v = value;
1539
+ const href = (_f = v === null || v === void 0 ? void 0 : v.href) !== null && _f !== void 0 ? _f : '';
1540
+ const fileName = (_g = v === null || v === void 0 ? void 0 : v.fileName) !== null && _g !== void 0 ? _g : '';
1541
+ const previewUrl = this.imagePreviews[field.name];
1542
+ if (previewUrl) {
1543
+ return (index.h("button", { class: "mrd-layout-section__image-thumb-btn", onClick: () => { this.imagePreviewUrl = previewUrl; }, title: fileName || undefined }, index.h("img", { class: "mrd-layout-section__image-thumb", src: previewUrl, alt: fileName })));
1544
+ }
1545
+ return (index.h("button", { class: "mrd-layout-section__download-link", onClick: () => href && this.mrdDownload.emit({ href, fileName }) }, fileName || href));
1546
+ }
1547
+ case index$1.ClientLayoutItemFieldDataType.BOOLEAN:
1548
+ return (index.h("span", { class: `mrd-layout-section__boolean mrd-layout-section__boolean--${value ? 'true' : 'false'}` }, value ? t('yes', this.locale) : t('no', this.locale)));
1549
+ case index$1.ClientLayoutItemFieldDataType.LIST: {
1550
+ const listItem = ((_h = field.listItems) !== null && _h !== void 0 ? _h : []).find(li => li.key === String(value));
1551
+ const label = (_j = listItem === null || listItem === void 0 ? void 0 : listItem.label) !== null && _j !== void 0 ? _j : String(value);
1552
+ const color = listItem === null || listItem === void 0 ? void 0 : listItem.color;
1553
+ const bg = listItem === null || listItem === void 0 ? void 0 : listItem.backgroundColor;
1554
+ if (color && bg) {
1555
+ return (index.h("span", { class: "mrd-layout-section__badge", style: { color, backgroundColor: bg } }, label));
1556
+ }
1557
+ if (color) {
1558
+ return (index.h("span", { class: "mrd-layout-section__badge-dot-row" }, index.h("span", { class: "mrd-layout-section__badge-dot", style: { backgroundColor: color } }), label));
1559
+ }
1560
+ return label;
1561
+ }
1562
+ default: {
1563
+ const text = CellRenderer.renderValue(dt, value, (_k = field.listItems) !== null && _k !== void 0 ? _k : [], this.locale);
1564
+ return text || null;
1565
+ }
1566
+ }
1567
+ }
1568
+ renderFieldValue(item, rawValue) {
1569
+ if (rawValue == null || rawValue === '')
1570
+ return null;
1571
+ const field = item.field;
1572
+ if (field.multiple && Array.isArray(rawValue)) {
1573
+ const rendered = rawValue.map(v => this.renderSingleFieldValue(item, v));
1574
+ if (rendered.every(r => typeof r === 'string' || r == null)) {
1575
+ return rendered.filter(Boolean).join(', ') || null;
1576
+ }
1577
+ return (index.h("span", null, rendered.map((r, i) => (index.h("span", { key: String(i) }, r, i < rendered.length - 1 ? ', ' : '')))));
1578
+ }
1579
+ return this.renderSingleFieldValue(item, rawValue);
1580
+ }
1581
+ renderField(item) {
1582
+ if (!item.field)
1583
+ return null;
1584
+ const field = item.field;
1585
+ const rawValue = this.data[field.name];
1586
+ const renderedValue = this.renderFieldValue(item, rawValue);
1587
+ if (field.header) {
1588
+ return (index.h("h1", { class: "mrd-layout-section__field-header", key: field.name }, typeof renderedValue === 'string' ? renderedValue : rawValue != null ? String(rawValue) : item.label));
1589
+ }
1590
+ if (renderedValue == null)
1591
+ return null;
1592
+ const isBlock = field.dataType === index$1.ClientLayoutItemFieldDataType.TEXTBLOCK
1593
+ || field.dataType === index$1.ClientLayoutItemFieldDataType.LONGTEXT
1594
+ || field.dataType === index$1.ClientLayoutItemFieldDataType.JSON;
1595
+ return (index.h("div", { class: `mrd-layout-section__field${isBlock ? ' mrd-layout-section__field--block' : ''}`, key: field.name }, index.h("span", { class: "mrd-layout-section__field-label" }, item.label), index.h("span", { class: "mrd-layout-section__field-value" }, renderedValue)));
1596
+ }
1597
+ renderRelation(item) {
1598
+ var _a, _b, _c;
1599
+ if (!item.relation)
1600
+ return null;
1601
+ const links = ((_b = (_a = this.data) === null || _a === void 0 ? void 0 : _a._links) !== null && _b !== void 0 ? _b : {});
1602
+ const link = links[item.relation.name];
1603
+ if (!link)
1604
+ return null;
1605
+ const makeBtn = (href, name) => (index.h("button", { key: href, class: "mrd-layout-section__relation-link", onClick: () => this.mrdNavigate.emit({ href, label: name }) }, name));
1606
+ let valueContent;
1607
+ if ((_c = link.values) === null || _c === void 0 ? void 0 : _c.length) {
1608
+ valueContent = link.values.map(v => makeBtn(v.href, v.name));
1609
+ }
1610
+ else if (link.name) {
1611
+ valueContent = makeBtn(link.href, link.name);
1612
+ }
1613
+ if (!valueContent)
1614
+ return null;
1615
+ return (index.h("div", { class: "mrd-layout-section__field", key: item.relation.name }, index.h("span", { class: "mrd-layout-section__field-label" }, item.label), index.h("span", { class: "mrd-layout-section__field-value" }, valueContent)));
1616
+ }
1617
+ renderSearch(item) {
1618
+ var _a, _b, _c;
1619
+ if (!item.search)
1620
+ return null;
1621
+ const dataClass = item.search.dataClass;
1622
+ const query = (_a = this.searchQueryMap[dataClass]) !== null && _a !== void 0 ? _a : '';
1623
+ const results = (_b = this.searchResultsMap[dataClass]) !== null && _b !== void 0 ? _b : [];
1624
+ return (index.h("div", { class: "mrd-layout-section__search", key: `search-${dataClass}` }, index.h("input", { class: "mrd-layout-section__search-input", type: "text", value: query, placeholder: (_c = item.label) !== null && _c !== void 0 ? _c : '', onInput: e => this.handleSearchInput(dataClass, e.target.value) }), results.length > 0 && (index.h("ul", { class: "mrd-layout-section__search-results" }, results.map(r => (index.h("li", { key: r.id, class: "mrd-layout-section__search-result" }, index.h("button", { class: "mrd-layout-section__search-result-btn", onClick: () => this.mrdNavigate.emit({ href: r.id, label: r.label }) }, index.h("span", { class: "mrd-layout-section__search-result-label" }, r.label), r.description && index.h("span", { class: "mrd-layout-section__search-result-desc" }, r.description)))))))));
1625
+ }
1626
+ renderRelatedView(item) {
1627
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
1628
+ const isRelated = item.type === index$1.ClientLayoutItemType.RELATED_VIEW;
1629
+ // Support both nested (item.view / item.relatedView) and flat API format (item.name)
1630
+ const name = isRelated
1631
+ ? (_a = item.relatedView) === null || _a === void 0 ? void 0 : _a.name
1632
+ : ((_c = (_b = item.view) === null || _b === void 0 ? void 0 : _b.name) !== null && _c !== void 0 ? _c : item.name);
1633
+ if (!name)
1634
+ return null;
1635
+ const viewConfig = this.views[name];
1636
+ if (!viewConfig)
1637
+ return null;
1638
+ const showTitle = isRelated
1639
+ ? (_d = item.relatedView) === null || _d === void 0 ? void 0 : _d.showTitle
1640
+ : ((_g = (_f = (_e = item.view) === null || _e === void 0 ? void 0 : _e.showTitle) !== null && _f !== void 0 ? _f : item.showTitle) !== null && _g !== void 0 ? _g : false);
1641
+ const altViews = isRelated ? undefined : item.alternativeViews;
1642
+ const rawActions = (_h = item.actions) !== null && _h !== void 0 ? _h : ['NEW', 'EXPORT'];
1643
+ const tableActions = rawActions.reduce((acc, a) => {
1644
+ if (a === 'NEW')
1645
+ acc.push({ action: 'create', label: t('table_new_record', this.locale), icon: 'assets/sprites.svg#icon-plus', variant: 'primary' });
1646
+ if (a === 'EXPORT')
1647
+ acc.push({ action: 'export', label: t('table_export_excel', this.locale), icon: 'assets/sprites.svg#icon-file-excel' });
1648
+ return acc;
1649
+ }, []);
1650
+ return (index.h("div", { class: "mrd-layout-section__related-view", key: `view-${name}` }, showTitle && item.label && index.h("h3", { class: "mrd-layout-section__related-view-title" }, item.label), index.h("mrd-table", { "data-view": name, columns: viewConfig.values, locale: this.locale, defaultSort: (_j = viewConfig.defaultSort) !== null && _j !== void 0 ? _j : '', alternativeViews: altViews, actions: tableActions, onMrdLoadPage: (e) => this.handleViewLoadPage(e, name), onMrdAction: (e) => {
1651
+ var _a, _b, _c;
1652
+ e.stopPropagation();
1653
+ const pl = (_a = this.viewLinksMap[name]) !== null && _a !== void 0 ? _a : {};
1654
+ const href = e.detail.action === 'export' ? (_b = pl['excel']) === null || _b === void 0 ? void 0 : _b.href : (_c = pl['self']) === null || _c === void 0 ? void 0 : _c.href;
1655
+ this.mrdViewAction.emit({ name, action: e.detail.action, href });
1656
+ } })));
1657
+ }
1658
+ renderItem(item) {
1659
+ var _a, _b;
1660
+ switch (item.type) {
1661
+ case index$1.ClientLayoutItemType.FIELD:
1662
+ return this.renderField(item);
1663
+ case index$1.ClientLayoutItemType.RELATION:
1664
+ return this.renderRelation(item);
1665
+ case index$1.ClientLayoutItemType.HEADER:
1666
+ return (index.h("h2", { class: "mrd-layout-section__header", key: `header-${item.label}` }, item.label));
1667
+ case index$1.ClientLayoutItemType.TEXT:
1668
+ return index.h("div", { class: "mrd-layout-section__text", key: `text-${item.label}`, innerHTML: (_a = item.label) !== null && _a !== void 0 ? _a : '' });
1669
+ case index$1.ClientLayoutItemType.NAVIGATE:
1670
+ return (index.h("button", { class: "mrd-layout-section__navigate", key: `nav-${item.label}`, onClick: () => { var _a; return this.mrdNavigate.emit({ label: (_a = item.label) !== null && _a !== void 0 ? _a : '', navigate: item.navigate }); } }, item.label));
1671
+ case index$1.ClientLayoutItemType.SEARCH:
1672
+ return this.renderSearch(item);
1673
+ case index$1.ClientLayoutItemType.SECTION:
1674
+ case index$1.ClientLayoutItemType.GROUP:
1675
+ return (index.h("div", { class: "mrd-layout-section__group", key: `group-${item.label}` }, item.label && index.h("h3", { class: "mrd-layout-section__group-title" }, item.label), ((_b = item.items) !== null && _b !== void 0 ? _b : []).map(child => this.renderItem(child))));
1676
+ case index$1.ClientLayoutItemType.RELATED_VIEW:
1677
+ case index$1.ClientLayoutItemType.VIEW:
1678
+ return this.renderRelatedView(item);
1679
+ default:
1680
+ return null;
1681
+ }
1682
+ }
1683
+ renderImageModal() {
1684
+ if (!this.imagePreviewUrl)
1685
+ return null;
1686
+ return (index.h("div", { class: "mrd-layout-section__modal-backdrop", onClick: () => { this.imagePreviewUrl = null; } }, index.h("div", { class: "mrd-layout-section__modal", onClick: (e) => e.stopPropagation() }, index.h("button", { class: "mrd-layout-section__modal-close", onClick: () => { this.imagePreviewUrl = null; } }, "\u2715"), index.h("img", { class: "mrd-layout-section__modal-image", src: this.imagePreviewUrl, alt: "" }))));
1687
+ }
1688
+ render() {
1689
+ return (index.h(index.Host, { key: '007077c73ddcc5c9e6ce546f083f42c07f8b94a4' }, index.h("div", { key: 'e9904536e9361d9a36d613c20af55ddf8d9acda6', class: "mrd-layout-section" }, this.items.map(item => this.renderItem(item))), this.renderImageModal()));
1690
+ }
1691
+ get el() { return index.getElement(this); }
1692
+ static get watchers() { return {
1693
+ "links": [{
1694
+ "linksChanged": 0
1695
+ }],
1696
+ "data": [{
1697
+ "dataChanged": 0
1698
+ }]
1699
+ }; }
1700
+ };
1701
+ MrdLayoutSection.style = mrdLayoutSectionScss();
1702
+
1703
+ const mrdListFieldScss = () => `.sc-mrd-list-field-h{display:block}.mrd-list-field.sc-mrd-list-field{display:flex;flex-direction:column;gap:var(--mrd-space-1);width:100%}.mrd-list-field__label.sc-mrd-list-field{display:block;font-family:var(--mrd-font-family);font-size:var(--mrd-label-font-size);font-weight:var(--mrd-label-font-weight);color:var(--mrd-label-color)}.mrd-list-field__label--required.sc-mrd-list-field::after{content:' *';color:var(--mrd-color-danger)}.mrd-list-field__select.sc-mrd-list-field{display:block;width:100%;height:var(--mrd-input-height);padding:var(--mrd-input-padding-y) var(--mrd-input-padding-x);padding-right:calc(var(--mrd-input-padding-x) + 1.5rem);font-family:var(--mrd-font-family);font-size:var(--mrd-font-size-base);color:var(--mrd-input-color);background-color:var(--mrd-input-bg);background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");background-repeat:no-repeat;background-position:right var(--mrd-space-3) center;border:var(--mrd-border-width) solid var(--mrd-border-color);border-radius:var(--mrd-border-radius);transition:border-color var(--mrd-transition), box-shadow var(--mrd-transition);outline:none;appearance:none;cursor:pointer;box-sizing:border-box}.mrd-list-field__select.sc-mrd-list-field:focus{border-color:var(--mrd-border-color-focus);box-shadow:var(--mrd-shadow-focus)}.mrd-list-field__select.sc-mrd-list-field:disabled{background-color:var(--mrd-input-bg-disabled);cursor:not-allowed;opacity:0.7}.mrd-list-field__select--error.sc-mrd-list-field{border-color:var(--mrd-border-color-error)}.mrd-list-field__select--error.sc-mrd-list-field:focus{box-shadow:var(--mrd-shadow-focus-error)}.mrd-list-field__checkbox-list.sc-mrd-list-field{display:flex;flex-direction:column;gap:var(--mrd-space-2);padding:var(--mrd-space-3);border:var(--mrd-border-width) solid var(--mrd-border-color);border-radius:var(--mrd-border-radius);background-color:var(--mrd-input-bg)}.mrd-list-field__checkbox-list--error.sc-mrd-list-field{border-color:var(--mrd-border-color-error)}.mrd-list-field__checkbox-item.sc-mrd-list-field{display:flex;align-items:center;gap:var(--mrd-space-2);font-family:var(--mrd-font-family);font-size:var(--mrd-font-size-base);color:var(--mrd-input-color);cursor:pointer}.mrd-list-field__checkbox-item.sc-mrd-list-field input[type='checkbox'].sc-mrd-list-field{width:1rem;height:1rem;cursor:pointer;accent-color:var(--mrd-color-primary)}.mrd-list-field__color-dot.sc-mrd-list-field{display:inline-block;width:12px;height:12px;border-radius:50%;flex-shrink:0}.mrd-list-field__error.sc-mrd-list-field{font-family:var(--mrd-font-family);font-size:var(--mrd-error-font-size);color:var(--mrd-error-color)}`;
1704
+
1705
+ const MrdListField = class {
1706
+ constructor(hostRef) {
1707
+ index.registerInstance(this, hostRef);
1708
+ this.mrdChange = index.createEvent(this, "mrdChange");
1709
+ this.mrdBlur = index.createEvent(this, "mrdBlur");
1710
+ this.name = '';
1711
+ this.label = '';
1712
+ this.value = '';
1713
+ this.required = false;
1714
+ this.disabled = false;
1715
+ this.multiple = false;
1716
+ this.locale = navigator.language;
1717
+ /** List items from the API. Each item has a `key` (stored value) and `label`. */
1718
+ this.listItems = [];
1719
+ this.error = '';
1720
+ this.selected = [];
1721
+ this.handleSelectChange = (e) => {
1722
+ const select = e.target;
1723
+ if (this.multiple) {
1724
+ const vals = Array.from(select.selectedOptions).map(o => o.value);
1725
+ this.selected = vals;
1726
+ if (this.required && !validateRequired(vals)) {
1727
+ this.error = t('required', this.locale);
1728
+ }
1729
+ else {
1730
+ this.error = '';
1731
+ }
1732
+ this.mrdChange.emit({ name: this.name, value: vals });
1733
+ }
1734
+ else {
1735
+ const val = select.value;
1736
+ if (this.required && !validateRequired(val)) {
1737
+ this.error = t('required', this.locale);
1738
+ }
1739
+ else {
1740
+ this.error = '';
1741
+ }
1742
+ this.mrdChange.emit({ name: this.name, value: val });
1743
+ }
1744
+ };
1745
+ this.handleBlur = () => {
1746
+ const val = this.multiple ? this.selected : this.value;
1747
+ this.mrdBlur.emit({ name: this.name, value: val });
1748
+ };
1749
+ this.toggleCheckbox = (key) => {
1750
+ if (this.selected.includes(key)) {
1751
+ this.selected = this.selected.filter(v => v !== key);
1752
+ }
1753
+ else {
1754
+ this.selected = [...this.selected, key];
1755
+ }
1756
+ if (this.required && !validateRequired(this.selected)) {
1757
+ this.error = t('required', this.locale);
1758
+ }
1759
+ else {
1760
+ this.error = '';
1761
+ }
1762
+ this.mrdChange.emit({ name: this.name, value: this.selected });
1763
+ };
1764
+ }
1765
+ componentWillLoad() {
1766
+ if (this.multiple) {
1767
+ this.selected = Array.isArray(this.value) ? this.value : this.value ? [this.value] : [];
1768
+ }
1769
+ }
1770
+ getContrastColor(bgColor) {
1771
+ if (!bgColor)
1772
+ return '#000000';
1773
+ const hex = bgColor.replace('#', '');
1774
+ const r = parseInt(hex.substr(0, 2), 16);
1775
+ const g = parseInt(hex.substr(2, 2), 16);
1776
+ const b = parseInt(hex.substr(4, 2), 16);
1777
+ const luminance = (0.299 * r + 0.587 * g + 0.114 * b) / 255;
1778
+ return luminance > 0.5 ? '#000000' : '#ffffff';
1779
+ }
1780
+ render() {
1781
+ var _a, _b;
1782
+ const hasError = !!this.error;
1783
+ const currentValue = Array.isArray(this.value) ? ((_a = this.value[0]) !== null && _a !== void 0 ? _a : '') : ((_b = this.value) !== null && _b !== void 0 ? _b : '');
1784
+ if (this.multiple) {
1785
+ return (index.h(index.Host, null, index.h("div", { class: "mrd-list-field" }, this.label && (index.h("label", { class: `mrd-list-field__label${this.required ? ' mrd-list-field__label--required' : ''}` }, this.label)), index.h("div", { class: `mrd-list-field__checkbox-list${hasError ? ' mrd-list-field__checkbox-list--error' : ''}` }, this.listItems.map(lv => {
1786
+ var _a, _b;
1787
+ return (index.h("label", { key: lv.key, class: "mrd-list-field__checkbox-item" }, index.h("input", { type: "checkbox", checked: this.selected.includes(lv.key), disabled: this.disabled, onChange: () => this.toggleCheckbox(lv.key) }), (lv.color || lv.backgroundColor) && (index.h("span", { class: "mrd-list-field__color-dot", style: { backgroundColor: (_b = (_a = lv.backgroundColor) !== null && _a !== void 0 ? _a : lv.color) !== null && _b !== void 0 ? _b : '' } })), index.h("span", null, lv.label)));
1788
+ })), hasError && index.h("span", { class: "mrd-list-field__error" }, this.error))));
1789
+ }
1790
+ return (index.h(index.Host, null, index.h("div", { class: "mrd-list-field" }, this.label && (index.h("label", { class: `mrd-list-field__label${this.required ? ' mrd-list-field__label--required' : ''}` }, this.label)), index.h("select", { class: `mrd-list-field__select${hasError ? ' mrd-list-field__select--error' : ''}`, name: this.name, required: this.required, disabled: this.disabled, onChange: this.handleSelectChange, onBlur: this.handleBlur }, index.h("option", { value: "" }, t('select_placeholder', this.locale)), this.listItems.map(lv => {
1791
+ var _a, _b;
1792
+ const bg = (_b = (_a = lv.backgroundColor) !== null && _a !== void 0 ? _a : lv.color) !== null && _b !== void 0 ? _b : null;
1793
+ const style = bg ? { backgroundColor: bg, color: this.getContrastColor(bg) } : {};
1794
+ return (index.h("option", { key: lv.key, value: lv.key, selected: lv.key === currentValue, style: style }, lv.label));
1795
+ })), hasError && index.h("span", { class: "mrd-list-field__error" }, this.error))));
1796
+ }
1797
+ };
1798
+ MrdListField.style = mrdListFieldScss();
1799
+
1800
+ const mrdLongtextFieldScss = () => `.sc-mrd-longtext-field-h{display:block}.mrd-longtext-field.sc-mrd-longtext-field{display:flex;flex-direction:column;gap:var(--mrd-space-1);width:100%}.mrd-longtext-field__label.sc-mrd-longtext-field{display:block;font-family:var(--mrd-font-family);font-size:var(--mrd-label-font-size);font-weight:var(--mrd-label-font-weight);color:var(--mrd-label-color)}.mrd-longtext-field__label--required.sc-mrd-longtext-field::after{content:' *';color:var(--mrd-color-danger)}.mrd-longtext-field__input.sc-mrd-longtext-field{display:block;width:100%;min-height:calc(var(--mrd-input-height) * 5);padding:var(--mrd-input-padding-y) var(--mrd-input-padding-x);font-family:var(--mrd-font-family);font-size:var(--mrd-font-size-base);color:var(--mrd-input-color);background-color:var(--mrd-input-bg);border:var(--mrd-border-width) solid var(--mrd-border-color);border-radius:var(--mrd-border-radius);transition:border-color var(--mrd-transition), box-shadow var(--mrd-transition);outline:none;resize:vertical;box-sizing:border-box;line-height:1.5}.mrd-longtext-field__input.sc-mrd-longtext-field::placeholder{color:var(--mrd-input-placeholder-color)}.mrd-longtext-field__input.sc-mrd-longtext-field:focus{border-color:var(--mrd-border-color-focus);box-shadow:var(--mrd-shadow-focus)}.mrd-longtext-field__input--error.sc-mrd-longtext-field{border-color:var(--mrd-border-color-error)}.mrd-longtext-field__input--error.sc-mrd-longtext-field:focus{box-shadow:var(--mrd-shadow-focus-error)}.mrd-longtext-field__content.sc-mrd-longtext-field{font-family:var(--mrd-font-family);font-size:var(--mrd-font-size-base);color:var(--mrd-input-color);white-space:pre-wrap;word-break:break-word;margin:0;padding:var(--mrd-input-padding-y) var(--mrd-input-padding-x);background-color:var(--mrd-input-bg-disabled);border:var(--mrd-border-width) solid var(--mrd-border-color);border-radius:var(--mrd-border-radius);line-height:1.5}.mrd-longtext-field__error.sc-mrd-longtext-field{font-family:var(--mrd-font-family);font-size:var(--mrd-error-font-size);color:var(--mrd-error-color)}`;
1801
+
1802
+ const MrdLongtextField = class {
1803
+ constructor(hostRef) {
1804
+ index.registerInstance(this, hostRef);
1805
+ this.mrdChange = index.createEvent(this, "mrdChange");
1806
+ this.mrdBlur = index.createEvent(this, "mrdBlur");
1807
+ this.name = '';
1808
+ this.label = '';
1809
+ this.value = '';
1810
+ this.placeholder = '';
1811
+ this.required = false;
1812
+ this.disabled = false;
1813
+ this.locale = navigator.language;
1814
+ this.error = '';
1815
+ this.handleInput = (e) => {
1816
+ const val = e.target.value;
1817
+ this.mrdChange.emit({ name: this.name, value: val });
1818
+ };
1819
+ this.handleBlur = (e) => {
1820
+ const val = e.target.value;
1821
+ if (this.required && !validateRequired(val)) {
1822
+ this.error = t('required', this.locale);
1823
+ }
1824
+ else {
1825
+ this.error = '';
1826
+ }
1827
+ this.mrdBlur.emit({ name: this.name, value: val });
1828
+ };
1829
+ }
1830
+ render() {
1831
+ const hasError = !!this.error;
1832
+ return (index.h(index.Host, { key: '3142f97e26fdef5547c8dd9d236ed8bc40d5c65f' }, index.h("div", { key: 'b78567596d8c6459c8e9b28ea6b02d3fe65fd16c', class: "mrd-longtext-field" }, this.label && (index.h("label", { key: 'e85d8657fcc49fc7e15c06b8a98b34c03738ef5b', class: `mrd-longtext-field__label${this.required ? ' mrd-longtext-field__label--required' : ''}` }, this.label)), this.disabled ? (index.h("pre", { class: "mrd-longtext-field__content" }, this.value)) : (index.h("textarea", { class: `mrd-longtext-field__input${hasError ? ' mrd-longtext-field__input--error' : ''}`, name: this.name, placeholder: this.placeholder, required: this.required, rows: 10, onInput: this.handleInput, onBlur: this.handleBlur }, this.value)), hasError && index.h("span", { key: '63cdcaf136e345197c42516f150752ec1d8665fa', class: "mrd-longtext-field__error" }, this.error))));
1833
+ }
1834
+ };
1835
+ MrdLongtextField.style = mrdLongtextFieldScss();
1836
+
1837
+ const mrdNumberFieldScss = () => `.sc-mrd-number-field-h{display:block}.mrd-number-field.sc-mrd-number-field{display:flex;flex-direction:column;gap:var(--mrd-space-1);width:100%}.mrd-number-field__label.sc-mrd-number-field{display:block;font-family:var(--mrd-font-family);font-size:var(--mrd-label-font-size);font-weight:var(--mrd-label-font-weight);color:var(--mrd-label-color)}.mrd-number-field__label--required.sc-mrd-number-field::after{content:' *';color:var(--mrd-color-danger)}.mrd-number-field__input-wrapper.sc-mrd-number-field{position:relative;display:flex;align-items:center}.mrd-number-field__input.sc-mrd-number-field{display:block;width:100%;height:var(--mrd-input-height);padding:var(--mrd-input-padding-y) var(--mrd-input-padding-x);font-family:var(--mrd-font-family);font-size:var(--mrd-font-size-base);color:var(--mrd-input-color);background-color:var(--mrd-input-bg);border:var(--mrd-border-width) solid var(--mrd-border-color);border-radius:var(--mrd-border-radius);transition:border-color var(--mrd-transition), box-shadow var(--mrd-transition);outline:none;appearance:none;box-sizing:border-box;text-align:right}.mrd-number-field__input.sc-mrd-number-field::placeholder{color:var(--mrd-input-placeholder-color);text-align:left}.mrd-number-field__input.sc-mrd-number-field:focus{border-color:var(--mrd-border-color-focus);box-shadow:var(--mrd-shadow-focus)}.mrd-number-field__input.sc-mrd-number-field:disabled{background-color:var(--mrd-input-bg-disabled);cursor:not-allowed;opacity:0.7}.mrd-number-field__input--error.sc-mrd-number-field{border-color:var(--mrd-border-color-error)}.mrd-number-field__input--error.sc-mrd-number-field:focus{box-shadow:var(--mrd-shadow-focus-error)}.mrd-number-field__error.sc-mrd-number-field{font-family:var(--mrd-font-family);font-size:var(--mrd-error-font-size);color:var(--mrd-error-color)}`;
1838
+
1839
+ const MrdNumberField = class {
1840
+ constructor(hostRef) {
1841
+ index.registerInstance(this, hostRef);
1842
+ this.mrdChange = index.createEvent(this, "mrdChange");
1843
+ this.mrdBlur = index.createEvent(this, "mrdBlur");
1844
+ this.name = '';
1845
+ this.label = '';
1846
+ this.value = null;
1847
+ this.placeholder = '';
1848
+ this.required = false;
1849
+ this.disabled = false;
1850
+ this.locale = navigator.language;
1851
+ this.dataType = index$1.ClientLayoutItemFieldDataType.INTEGER;
1852
+ this.decimalPrecision = 2;
1853
+ this.displayValue = '';
1854
+ this.error = '';
1855
+ this.handleInput = (e) => {
1856
+ this.displayValue = e.target.value;
1857
+ };
1858
+ this.handleBlur = (e) => {
1859
+ const raw = e.target.value;
1860
+ const parsed = parseLocalizedNumber(raw, this.locale);
1861
+ if (this.required && (parsed === null || raw === '')) {
1862
+ this.error = t('required', this.locale);
1863
+ }
1864
+ else if (raw !== '' && !validateNumber(parsed, this.dataType)) {
1865
+ this.error = t('invalid_number', this.locale);
1866
+ }
1867
+ else {
1868
+ this.error = '';
1869
+ }
1870
+ if (parsed !== null && validateRequired(raw)) {
1871
+ this.displayValue = this.formatForDisplay(parsed);
1872
+ }
1873
+ this.mrdChange.emit({ name: this.name, value: parsed });
1874
+ this.mrdBlur.emit({ name: this.name, value: parsed });
1875
+ };
1876
+ this.handleFocus = () => {
1877
+ // Show raw number on focus
1878
+ if (this.value !== null && this.value !== undefined) {
1879
+ const str = String(this.value);
1880
+ this.displayValue = str;
1881
+ }
1882
+ };
1883
+ }
1884
+ componentWillLoad() {
1885
+ if (this.value !== null && this.value !== undefined) {
1886
+ this.displayValue = this.formatForDisplay(this.value);
1887
+ }
1888
+ }
1889
+ formatForDisplay(val) {
1890
+ if (this.dataType === index$1.ClientLayoutItemFieldDataType.PERCENTAGE) {
1891
+ return formatNumber(val, this.locale, {
1892
+ minimumFractionDigits: 0,
1893
+ maximumFractionDigits: this.decimalPrecision,
1894
+ }) + '%';
1895
+ }
1896
+ if (this.dataType === index$1.ClientLayoutItemFieldDataType.DECIMAL) {
1897
+ return formatNumber(val, this.locale, {
1898
+ minimumFractionDigits: this.decimalPrecision,
1899
+ maximumFractionDigits: this.decimalPrecision,
1900
+ });
1901
+ }
1902
+ return formatNumber(val, this.locale, { maximumFractionDigits: 0 });
1903
+ }
1904
+ render() {
1905
+ const hasError = !!this.error;
1906
+ const suffix = this.dataType === index$1.ClientLayoutItemFieldDataType.PERCENTAGE ? '%' :
1907
+ this.dataType === index$1.ClientLayoutItemFieldDataType.DECIMAL ? '' : '';
1908
+ return (index.h(index.Host, { key: 'ba3488fb12f72bb04164e3e94c028fb8a085f1f2' }, index.h("div", { key: '582e30a2a256c16cc3b0cab6e64460a0a5ec1fa2', class: "mrd-number-field" }, this.label && (index.h("label", { key: '87fe77ce80e888406ecedaa450e8c3d2a61c790a', class: `mrd-number-field__label${this.required ? ' mrd-number-field__label--required' : ''}` }, this.label)), index.h("div", { key: 'e3d8cf06f585add372e385d6e6ef7d60ece8071b', class: "mrd-number-field__input-wrapper" }, index.h("input", { key: '04710b67ee0dcb9db327e25b2467b1b3499bc9a8', class: `mrd-number-field__input${hasError ? ' mrd-number-field__input--error' : ''}`, type: "text", inputMode: "decimal", name: this.name, value: this.displayValue, placeholder: this.placeholder || (suffix ? `0${suffix}` : '0'), required: this.required, disabled: this.disabled, onInput: this.handleInput, onBlur: this.handleBlur, onFocus: this.handleFocus })), hasError && index.h("span", { key: '9713244d784c82213ea835a5a6d47d468ccb0bb9', class: "mrd-number-field__error" }, this.error))));
1909
+ }
1910
+ };
1911
+ MrdNumberField.style = mrdNumberFieldScss();
1912
+
1913
+ const mrdRelationFieldScss = () => `.sc-mrd-relation-field-h{display:block}.mrd-relation-field.sc-mrd-relation-field{display:flex;flex-direction:column;gap:var(--mrd-space-1);width:100%;position:relative}.mrd-relation-field__label.sc-mrd-relation-field{display:block;font-family:var(--mrd-font-family);font-size:var(--mrd-label-font-size);font-weight:var(--mrd-label-font-weight);color:var(--mrd-label-color)}.mrd-relation-field__label--required.sc-mrd-relation-field::after{content:' *';color:var(--mrd-color-danger)}.mrd-relation-field__select.sc-mrd-relation-field{display:block;width:100%;height:var(--mrd-input-height);padding:var(--mrd-input-padding-y) var(--mrd-input-padding-x);padding-right:calc(var(--mrd-input-padding-x) + 1.5rem);font-family:var(--mrd-font-family);font-size:var(--mrd-font-size-base);color:var(--mrd-input-color);background-color:var(--mrd-input-bg);background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");background-repeat:no-repeat;background-position:right var(--mrd-space-3) center;border:var(--mrd-border-width) solid var(--mrd-border-color);border-radius:var(--mrd-border-radius);outline:none;appearance:none;cursor:pointer;box-sizing:border-box}.mrd-relation-field__select.sc-mrd-relation-field:focus{border-color:var(--mrd-border-color-focus);box-shadow:var(--mrd-shadow-focus)}.mrd-relation-field__select.sc-mrd-relation-field:disabled{background-color:var(--mrd-input-bg-disabled);cursor:not-allowed;opacity:0.7}.mrd-relation-field__select--error.sc-mrd-relation-field{border-color:var(--mrd-border-color-error)}.mrd-relation-field__select--error.sc-mrd-relation-field:focus{box-shadow:var(--mrd-shadow-focus-error)}.mrd-relation-field__tags.sc-mrd-relation-field{display:flex;flex-wrap:wrap;gap:var(--mrd-space-1);margin-bottom:var(--mrd-space-1)}.mrd-relation-field__tag.sc-mrd-relation-field{display:inline-flex;align-items:center;gap:var(--mrd-space-1);padding:var(--mrd-space-1) var(--mrd-space-2);background-color:var(--mrd-color-primary-light);color:var(--mrd-color-primary-dark);border-radius:var(--mrd-border-radius-full);font-family:var(--mrd-font-family);font-size:var(--mrd-font-size-sm);font-weight:var(--mrd-font-weight-medium)}.mrd-relation-field__tag-remove.sc-mrd-relation-field{background:none;border:none;cursor:pointer;color:var(--mrd-color-primary-dark);font-size:var(--mrd-font-size-xs);padding:0;line-height:1;opacity:0.7}.mrd-relation-field__tag-remove.sc-mrd-relation-field:hover{opacity:1}.mrd-relation-field__search-wrapper.sc-mrd-relation-field{position:relative;display:flex;align-items:center}.mrd-relation-field__search.sc-mrd-relation-field{display:block;width:100%;height:var(--mrd-input-height);padding:var(--mrd-input-padding-y) var(--mrd-input-padding-x);font-family:var(--mrd-font-family);font-size:var(--mrd-font-size-base);color:var(--mrd-input-color);background-color:var(--mrd-input-bg);border:var(--mrd-border-width) solid var(--mrd-border-color);border-radius:var(--mrd-border-radius);outline:none;appearance:none;box-sizing:border-box}.mrd-relation-field__search.sc-mrd-relation-field::placeholder{color:var(--mrd-input-placeholder-color)}.mrd-relation-field__search.sc-mrd-relation-field:focus{border-color:var(--mrd-border-color-focus);box-shadow:var(--mrd-shadow-focus)}.mrd-relation-field__search.sc-mrd-relation-field:disabled{background-color:var(--mrd-input-bg-disabled);cursor:not-allowed;opacity:0.7}.mrd-relation-field__search--error.sc-mrd-relation-field{border-color:var(--mrd-border-color-error)}.mrd-relation-field__search--error.sc-mrd-relation-field:focus{box-shadow:var(--mrd-shadow-focus-error)}.mrd-relation-field__spinner.sc-mrd-relation-field{position:absolute;right:var(--mrd-space-3);width:16px;height:16px;border:2px solid var(--mrd-color-neutral-200);border-top-color:var(--mrd-color-primary);border-radius:50%;animation:mrd-spin 0.7s linear infinite}@keyframes mrd-spin{to{transform:rotate(360deg)}}.mrd-relation-field__results.sc-mrd-relation-field{position:absolute;top:calc(100% + var(--mrd-space-1));left:0;right:0;background-color:var(--mrd-color-white);border:var(--mrd-border-width) solid var(--mrd-border-color);border-radius:var(--mrd-border-radius);box-shadow:var(--mrd-shadow-md);z-index:var(--mrd-z-dropdown);max-height:240px;overflow-y:auto}.mrd-relation-field__result-item.sc-mrd-relation-field{display:flex;flex-direction:column;padding:var(--mrd-space-2) var(--mrd-space-3);cursor:pointer;transition:background-color var(--mrd-transition-fast)}.mrd-relation-field__result-item.sc-mrd-relation-field:hover{background-color:var(--mrd-color-neutral-50)}.mrd-relation-field__result-item.sc-mrd-relation-field:not(:last-child){border-bottom:var(--mrd-border-width) solid var(--mrd-color-neutral-100)}.mrd-relation-field__result-label.sc-mrd-relation-field{font-family:var(--mrd-font-family);font-size:var(--mrd-font-size-base);color:var(--mrd-color-neutral-800);font-weight:var(--mrd-font-weight-medium)}.mrd-relation-field__result-desc.sc-mrd-relation-field{font-family:var(--mrd-font-family);font-size:var(--mrd-font-size-xs);color:var(--mrd-color-neutral-500);margin-top:var(--mrd-space-1)}.mrd-relation-field__result-item--highlighted.sc-mrd-relation-field{background-color:var(--mrd-color-primary-light)}.mrd-relation-field__selected-value.sc-mrd-relation-field{display:flex;align-items:center;gap:var(--mrd-space-2);height:var(--mrd-input-height);padding:var(--mrd-input-padding-y) var(--mrd-input-padding-x);background-color:var(--mrd-color-primary-light);border:var(--mrd-border-width) solid var(--mrd-color-primary);border-radius:var(--mrd-border-radius);box-sizing:border-box}.mrd-relation-field__selected-value--error.sc-mrd-relation-field{border-color:var(--mrd-border-color-error);background-color:var(--mrd-color-danger-light)}.mrd-relation-field__selected-name.sc-mrd-relation-field{flex:1;font-family:var(--mrd-font-family);font-size:var(--mrd-font-size-base);font-weight:var(--mrd-font-weight-medium);color:var(--mrd-color-primary-dark);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.mrd-relation-field__selected-clear.sc-mrd-relation-field{flex-shrink:0;background:none;border:none;cursor:pointer;color:var(--mrd-color-primary-dark);font-size:var(--mrd-font-size-sm);padding:0;line-height:1;opacity:0.6;transition:opacity var(--mrd-transition-fast)}.mrd-relation-field__selected-clear.sc-mrd-relation-field:hover{opacity:1}.mrd-relation-field__no-results.sc-mrd-relation-field{padding:var(--mrd-space-4);font-family:var(--mrd-font-family);font-size:var(--mrd-font-size-sm);color:var(--mrd-color-neutral-500);text-align:center}.mrd-relation-field__error.sc-mrd-relation-field{font-family:var(--mrd-font-family);font-size:var(--mrd-error-font-size);color:var(--mrd-error-color)}`;
1914
+
1915
+ const MrdRelationField = class {
1916
+ constructor(hostRef) {
1917
+ index.registerInstance(this, hostRef);
1918
+ this.mrdChange = index.createEvent(this, "mrdChange");
1919
+ this.mrdBlur = index.createEvent(this, "mrdBlur");
1920
+ this.mrdSearch = index.createEvent(this, "mrdSearch");
1921
+ this.mrdFetchAll = index.createEvent(this, "mrdFetchAll");
1922
+ this.name = '';
1923
+ this.label = '';
1924
+ this.required = false;
1925
+ this.disabled = false;
1926
+ this.locale = navigator.language;
1927
+ this.relatedClass = '';
1928
+ /** When set, used instead of relatedClass for search queries (mostSignificantClass from API). */
1929
+ this.mostSignificantClass = '';
1930
+ this.displayType = index$1.ClientLayoutItemRelationDisplayType.SEARCH;
1931
+ this.multiple = false;
1932
+ this.dropdownValues = [];
1933
+ /** Plain href string/array for normal use; pass { id, label } objects to pre-fill a loaded record. */
1934
+ this.value = null;
1935
+ this.searchQuery = '';
1936
+ this.searchResults = [];
1937
+ this.allRecords = [];
1938
+ this.isLoading = false;
1939
+ this.selectedItems = [];
1940
+ this.showResults = false;
1941
+ this.error = '';
1942
+ this.highlightedIndex = -1;
1943
+ this.searchDebounce = null;
1944
+ this.handleKeyDown = (e) => {
1945
+ if (!this.showResults || this.searchResults.length === 0) {
1946
+ if (e.key === 'Escape') {
1947
+ this.showResults = false;
1948
+ this.highlightedIndex = -1;
1949
+ }
1950
+ return;
1951
+ }
1952
+ if (e.key === 'ArrowDown') {
1953
+ e.preventDefault();
1954
+ this.highlightedIndex = Math.min(this.highlightedIndex + 1, this.searchResults.length - 1);
1955
+ }
1956
+ else if (e.key === 'ArrowUp') {
1957
+ e.preventDefault();
1958
+ this.highlightedIndex = Math.max(this.highlightedIndex - 1, 0);
1959
+ }
1960
+ else if (e.key === 'Enter') {
1961
+ e.preventDefault();
1962
+ if (this.highlightedIndex >= 0) {
1963
+ this.handleResultSelect(this.searchResults[this.highlightedIndex]);
1964
+ }
1965
+ }
1966
+ else if (e.key === 'Escape') {
1967
+ this.showResults = false;
1968
+ this.highlightedIndex = -1;
1969
+ }
1970
+ };
1971
+ this.clearSelection = () => {
1972
+ this.selectedItems = [];
1973
+ this.searchQuery = '';
1974
+ this.searchResults = [];
1975
+ this.showResults = false;
1976
+ this.highlightedIndex = -1;
1977
+ this.mrdChange.emit({ name: this.name, value: this.multiple ? [] : null });
1978
+ };
1979
+ this.handleSearchInput = (e) => {
1980
+ const query = e.target.value;
1981
+ this.searchQuery = query;
1982
+ if (this.searchDebounce)
1983
+ clearTimeout(this.searchDebounce);
1984
+ if (query.trim().length >= 2) {
1985
+ this.isLoading = true;
1986
+ this.showResults = true;
1987
+ this.searchDebounce = setTimeout(() => {
1988
+ this.mrdSearch.emit({ name: this.name, query, relatedClass: this.mostSignificantClass });
1989
+ }, 300);
1990
+ }
1991
+ else {
1992
+ this.searchResults = [];
1993
+ this.showResults = false;
1994
+ this.isLoading = false;
1995
+ }
1996
+ };
1997
+ this.handleResultSelect = (result) => {
1998
+ if (this.multiple) {
1999
+ if (!this.selectedItems.find(i => i.id === result.id)) {
2000
+ this.selectedItems = [...this.selectedItems, result];
2001
+ }
2002
+ this.searchQuery = '';
2003
+ this.searchResults = [];
2004
+ this.showResults = false;
2005
+ const ids = this.selectedItems.map(i => i.id);
2006
+ this.mrdChange.emit({ name: this.name, value: ids });
2007
+ }
2008
+ else {
2009
+ this.selectedItems = [result];
2010
+ this.searchQuery = result.label;
2011
+ this.showResults = false;
2012
+ this.mrdChange.emit({ name: this.name, value: result.id });
2013
+ }
2014
+ if (this.required && !validateRequired(this.selectedItems)) {
2015
+ this.error = t('required', this.locale);
2016
+ }
2017
+ else {
2018
+ this.error = '';
2019
+ }
2020
+ };
2021
+ this.handleRemoveSelected = (id) => {
2022
+ this.selectedItems = this.selectedItems.filter(i => i.id !== id);
2023
+ const ids = this.selectedItems.map(i => i.id);
2024
+ this.mrdChange.emit({ name: this.name, value: this.multiple ? ids : null });
2025
+ };
2026
+ this.handleDropdownChange = (e) => {
2027
+ const val = e.target.value;
2028
+ if (this.required && !validateRequired(val)) {
2029
+ this.error = t('required', this.locale);
2030
+ }
2031
+ else {
2032
+ this.error = '';
2033
+ }
2034
+ this.mrdChange.emit({ name: this.name, value: val });
2035
+ };
2036
+ this.handleBlur = () => {
2037
+ var _a, _b;
2038
+ setTimeout(() => {
2039
+ this.showResults = false;
2040
+ this.highlightedIndex = -1;
2041
+ }, 200);
2042
+ const val = this.multiple ? this.selectedItems.map(i => i.id) : ((_b = (_a = this.selectedItems[0]) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : null);
2043
+ this.mrdBlur.emit({ name: this.name, value: val });
2044
+ };
2045
+ }
2046
+ async setAllRecords(records) {
2047
+ this.allRecords = records;
2048
+ }
2049
+ getValueHref() {
2050
+ var _a, _b, _c;
2051
+ const v = Array.isArray(this.value) ? ((_a = this.value[0]) !== null && _a !== void 0 ? _a : '') : ((_b = this.value) !== null && _b !== void 0 ? _b : '');
2052
+ if (!v)
2053
+ return '';
2054
+ if (typeof v === 'object')
2055
+ return (_c = v.id) !== null && _c !== void 0 ? _c : '';
2056
+ return v;
2057
+ }
2058
+ allRecordsChanged() {
2059
+ if (this.editBehavior !== index$1.ClientLayoutItemRelationEditBehavior.DROPDOWN)
2060
+ return;
2061
+ const current = this.getValueHref();
2062
+ if (!current)
2063
+ return;
2064
+ // Defer past Stencil's async render cycle: options must exist in the DOM before
2065
+ // select.value can be set. setAttribute('selected') alone is ignored by browsers
2066
+ // when the select already has an established value.
2067
+ setTimeout(() => {
2068
+ var _a;
2069
+ const select = (_a = this.el) === null || _a === void 0 ? void 0 : _a.querySelector('select');
2070
+ if (select)
2071
+ select.value = current;
2072
+ }, 0);
2073
+ }
2074
+ async setSearchResults(results) {
2075
+ this.searchResults = results;
2076
+ this.isLoading = false;
2077
+ this.showResults = true;
2078
+ this.highlightedIndex = -1;
2079
+ }
2080
+ async setLoading(loading) {
2081
+ this.isLoading = loading;
2082
+ }
2083
+ componentWillLoad() {
2084
+ var _a;
2085
+ // Pre-fill selectedItems when value is passed as { id, label } objects
2086
+ // (e.g. when editing an existing record fetched from the API).
2087
+ if (this.value) {
2088
+ if (Array.isArray(this.value)) {
2089
+ if (this.value.length > 0 && typeof this.value[0] === 'object') {
2090
+ this.selectedItems = this.value;
2091
+ this.searchQuery = '';
2092
+ }
2093
+ }
2094
+ else if (typeof this.value === 'object') {
2095
+ this.selectedItems = [this.value];
2096
+ this.searchQuery = (_a = this.value.label) !== null && _a !== void 0 ? _a : '';
2097
+ }
2098
+ }
2099
+ }
2100
+ componentDidLoad() {
2101
+ // Only emit when there is no commonRelation dependency — the form orchestrates those.
2102
+ if (this.editBehavior === index$1.ClientLayoutItemRelationEditBehavior.DROPDOWN && !this.commonRelation) {
2103
+ // Defer to next tick so parent event listeners are registered after DOM patching
2104
+ setTimeout(() => {
2105
+ this.mrdFetchAll.emit({
2106
+ name: this.name,
2107
+ relatedClass: this.relatedClass,
2108
+ mostSignificantClass: this.mostSignificantClass || undefined,
2109
+ });
2110
+ }, 0);
2111
+ }
2112
+ }
2113
+ render() {
2114
+ var _a, _b;
2115
+ const hasError = !!this.error;
2116
+ if (this.editBehavior === index$1.ClientLayoutItemRelationEditBehavior.DROPDOWN) {
2117
+ const currentValue = this.getValueHref();
2118
+ return (index.h(index.Host, null, index.h("div", { class: "mrd-relation-field" }, this.label && (index.h("label", { class: `mrd-relation-field__label${this.required ? ' mrd-relation-field__label--required' : ''}` }, this.label)), index.h("select", { class: `mrd-relation-field__select${hasError ? ' mrd-relation-field__select--error' : ''}`, name: this.name, required: this.required, disabled: this.disabled, onChange: this.handleDropdownChange }, index.h("option", { value: "" }, t('select_placeholder', this.locale)), this.allRecords.map(record => (index.h("option", { key: record.id, value: record.id, selected: record.id === currentValue }, record.label)))), hasError && index.h("span", { class: "mrd-relation-field__error" }, this.error))));
2119
+ }
2120
+ if (this.displayType === index$1.ClientLayoutItemRelationDisplayType.DROPDOWN) {
2121
+ const currentValue = Array.isArray(this.value) ? ((_a = this.value[0]) !== null && _a !== void 0 ? _a : '') : ((_b = this.value) !== null && _b !== void 0 ? _b : '');
2122
+ return (index.h(index.Host, null, index.h("div", { class: "mrd-relation-field" }, this.label && (index.h("label", { class: `mrd-relation-field__label${this.required ? ' mrd-relation-field__label--required' : ''}` }, this.label)), index.h("select", { class: `mrd-relation-field__select${hasError ? ' mrd-relation-field__select--error' : ''}`, name: this.name, required: this.required, disabled: this.disabled, onChange: this.handleDropdownChange }, index.h("option", { value: "" }, t('select_placeholder', this.locale)), this.dropdownValues.map(dv => (index.h("option", { key: dv.key, value: dv.key, selected: dv.key === currentValue }, dv.label)))), hasError && index.h("span", { class: "mrd-relation-field__error" }, this.error))));
2123
+ }
2124
+ // SEARCH mode
2125
+ const labelEl = this.label && (index.h("label", { class: `mrd-relation-field__label${this.required ? ' mrd-relation-field__label--required' : ''}` }, this.label));
2126
+ // Single selection: show selected value as a badge, hide the search input
2127
+ if (!this.multiple && this.selectedItems.length > 0) {
2128
+ return (index.h(index.Host, null, index.h("div", { class: "mrd-relation-field" }, labelEl, index.h("div", { class: `mrd-relation-field__selected-value${hasError ? ' mrd-relation-field__selected-value--error' : ''}` }, index.h("span", { class: "mrd-relation-field__selected-name" }, this.selectedItems[0].label), index.h("button", { type: "button", class: "mrd-relation-field__selected-clear", onClick: this.clearSelection, "aria-label": t('remove', this.locale) }, "\u2715")), hasError && index.h("span", { class: "mrd-relation-field__error" }, this.error))));
2129
+ }
2130
+ return (index.h(index.Host, null, index.h("div", { class: "mrd-relation-field" }, labelEl, this.multiple && this.selectedItems.length > 0 && (index.h("div", { class: "mrd-relation-field__tags" }, this.selectedItems.map(item => (index.h("span", { key: item.id, class: "mrd-relation-field__tag" }, item.label, index.h("button", { type: "button", class: "mrd-relation-field__tag-remove", onClick: () => this.handleRemoveSelected(item.id), "aria-label": t('remove', this.locale) }, "\u2715")))))), index.h("div", { class: "mrd-relation-field__search-wrapper" }, index.h("input", { class: `mrd-relation-field__search${hasError ? ' mrd-relation-field__search--error' : ''}`, type: "text", value: this.searchQuery, placeholder: t('search_placeholder', this.locale), disabled: this.disabled, onInput: this.handleSearchInput, onKeyDown: this.handleKeyDown, onBlur: this.handleBlur }), this.isLoading && (index.h("span", { class: "mrd-relation-field__spinner", "aria-label": t('loading', this.locale) }))), this.showResults && (index.h("div", { class: "mrd-relation-field__results" }, this.searchResults.length === 0 && !this.isLoading ? (index.h("div", { class: "mrd-relation-field__no-results" }, t('no_results', this.locale))) : (this.searchResults.map((result, i) => (index.h("div", { key: result.id, class: `mrd-relation-field__result-item${i === this.highlightedIndex ? ' mrd-relation-field__result-item--highlighted' : ''}`, onMouseDown: () => this.handleResultSelect(result) }, index.h("span", { class: "mrd-relation-field__result-label" }, result.label), result.description && (index.h("span", { class: "mrd-relation-field__result-desc" }, result.description)))))))), hasError && index.h("span", { class: "mrd-relation-field__error" }, this.error))));
2131
+ }
2132
+ get el() { return index.getElement(this); }
2133
+ static get watchers() { return {
2134
+ "allRecords": [{
2135
+ "allRecordsChanged": 0
2136
+ }]
2137
+ }; }
2138
+ };
2139
+ MrdRelationField.style = mrdRelationFieldScss();
2140
+
2141
+ const mrdTableScss = () => `.sc-mrd-table-h{display:block;width:100%}.mrd-table__scroll.sc-mrd-table{overflow-y:auto;overflow-x:auto;border:1px solid var(--mrd-border-color);border-radius:var(--mrd-border-radius);overflow-anchor:none}.mrd-table.sc-mrd-table{overflow-x:auto}.mrd-table__table.sc-mrd-table{width:auto;min-width:100%;border-collapse:collapse;font-size:var(--mrd-font-size-sm);color:var(--mrd-color-neutral-900)}.mrd-table__scroll.sc-mrd-table .mrd-table__table.sc-mrd-table{min-width:max-content}.mrd-table__header.sc-mrd-table{position:sticky;top:0;z-index:1;background:var(--mrd-color-white);text-align:left;padding:var(--mrd-space-2) var(--mrd-space-4);border-bottom:2px solid var(--mrd-border-color);color:var(--mrd-color-neutral-600);font-weight:var(--mrd-font-weight-medium);white-space:nowrap;font-size:var(--mrd-font-size-xs);text-transform:uppercase;letter-spacing:0.04em}.mrd-table__header--sortable.sc-mrd-table{cursor:pointer;user-select:none}.mrd-table__header--sortable.sc-mrd-table:hover{background:var(--mrd-color-neutral-50);color:var(--mrd-color-neutral-800)}.mrd-table__header--sorted-asc.sc-mrd-table,.mrd-table__header--sorted-desc.sc-mrd-table{color:var(--mrd-color-primary);border-bottom-color:var(--mrd-color-primary)}.mrd-table__header-label.sc-mrd-table{margin-right:var(--mrd-space-1)}.mrd-table__sort-icon.sc-mrd-table{font-size:0.85rem;opacity:0.4;vertical-align:middle}.mrd-table__header--sorted-asc.sc-mrd-table .mrd-table__sort-icon.sc-mrd-table,.mrd-table__header--sorted-desc.sc-mrd-table .mrd-table__sort-icon.sc-mrd-table{opacity:1;color:var(--mrd-color-primary)}.mrd-table__filter-icon.sc-mrd-table{display:inline-flex;align-items:center;vertical-align:middle;margin-left:var(--mrd-space-1);color:var(--mrd-color-primary)}.mrd-table__row.sc-mrd-table{border-bottom:1px solid var(--mrd-border-color)}.mrd-table__row.sc-mrd-table:hover{background:var(--mrd-color-neutral-200) !important}.mrd-table__row--clickable.sc-mrd-table{cursor:pointer}.mrd-table__spacer.sc-mrd-table{border:none}.mrd-table__spacer.sc-mrd-table td.sc-mrd-table{padding:0;border:none}.mrd-table__cell.sc-mrd-table{padding:var(--mrd-space-2) var(--mrd-space-4);vertical-align:top;white-space:nowrap}.mrd-table__cell--numeric.sc-mrd-table{text-align:right;font-variant-numeric:tabular-nums}.mrd-table__row--loading.sc-mrd-table{background:transparent}.mrd-table__cell--placeholder.sc-mrd-table{padding:var(--mrd-space-2) var(--mrd-space-4);border-bottom:1px solid var(--mrd-border-color)}.mrd-table__placeholder-bar.sc-mrd-table{display:block;height:0.75rem;width:55%;border-radius:var(--mrd-border-radius-sm);background:linear-gradient( 90deg, var(--mrd-color-neutral-200) 25%, var(--mrd-color-neutral-100) 50%, var(--mrd-color-neutral-200) 75% );background-size:200% 100%;animation:mrd-shimmer 1.4s ease infinite}@keyframes mrd-shimmer{0%{background-position:200% 0}100%{background-position:-200% 0}}.mrd-table__toolbar.sc-mrd-table{display:flex;align-items:center;justify-content:space-between;padding-bottom:var(--mrd-space-2)}.mrd-table__toolbar-left.sc-mrd-table,.mrd-table__toolbar-right.sc-mrd-table{display:flex;gap:var(--mrd-space-2);align-items:center}.mrd-table__toolbar-center.sc-mrd-table{flex:1;display:flex;justify-content:center;align-items:center;gap:var(--mrd-space-1)}.mrd-table__view-title.sc-mrd-table{font-size:var(--mrd-font-size-sm);font-weight:600;color:var(--mrd-color-neutral-800)}.mrd-table__view-switcher.sc-mrd-table{position:relative}.mrd-table__view-switcher-btn.sc-mrd-table{display:inline-flex;align-items:center;gap:var(--mrd-space-1);background:none;border:none;cursor:pointer;padding:var(--mrd-space-1) var(--mrd-space-2);color:var(--mrd-color-neutral-400);font-size:var(--mrd-font-size-sm);border-radius:var(--mrd-border-radius);transition:color 0.15s, background-color 0.15s;line-height:1.4}.mrd-table__view-switcher-btn.sc-mrd-table:hover{color:var(--mrd-color-neutral-700);background-color:var(--mrd-color-neutral-50)}.mrd-table__view-switcher-label.sc-mrd-table{font-weight:var(--mrd-font-weight-medium)}.mrd-table__view-switcher-chevron.sc-mrd-table{width:1.1rem;height:1.1rem;flex-shrink:0;transition:transform 0.15s}.mrd-table__view-switcher-btn--open.sc-mrd-table .mrd-table__view-switcher-chevron.sc-mrd-table{transform:rotate(180deg)}.mrd-table__view-switcher-dropdown.sc-mrd-table{position:absolute;top:calc(100% + 4px);left:50%;transform:translateX(-50%);min-width:160px;background:var(--mrd-color-white);border:1px solid var(--mrd-border-color);border-radius:var(--mrd-border-radius);box-shadow:var(--mrd-shadow-md, 0 4px 12px rgba(0,0,0,.12));z-index:var(--mrd-z-dropdown, 200);overflow:hidden}.mrd-table__view-switcher-item.sc-mrd-table{display:block;width:100%;padding:var(--mrd-space-2) var(--mrd-space-3);background:none;border:none;text-align:left;cursor:pointer;font-size:var(--mrd-font-size-sm);color:var(--mrd-color-neutral-700);white-space:nowrap;transition:background-color 0.1s, color 0.1s}.mrd-table__view-switcher-item.sc-mrd-table:hover{background-color:var(--mrd-color-neutral-50);color:var(--mrd-color-neutral-900)}.mrd-table__action.sc-mrd-table{position:relative;display:inline-flex;align-items:center;justify-content:center;width:2rem;height:2rem;padding:0;background:transparent;border:1px solid transparent;border-radius:var(--mrd-border-radius);cursor:pointer;color:var(--mrd-color-neutral-400);transition:background-color 0.15s, border-color 0.15s, color 0.15s}.mrd-table__action.sc-mrd-table:hover{background-color:var(--mrd-color-neutral-100);border-color:var(--mrd-color-neutral-300);color:var(--mrd-color-neutral-700)}.mrd-table__action.sc-mrd-table:disabled{opacity:0.4;cursor:not-allowed}.mrd-table__action--primary.sc-mrd-table{color:var(--mrd-color-neutral-500)}.mrd-table__action--primary.sc-mrd-table:hover{background:var(--mrd-color-primary);border-color:var(--mrd-color-primary);color:var(--mrd-color-white)}.mrd-table__action--danger.sc-mrd-table{color:var(--mrd-color-error)}.mrd-table__action--danger.sc-mrd-table:hover{background-color:var(--mrd-color-error-light, #fef2f2);border-color:var(--mrd-color-error)}.mrd-table__action-icon.sc-mrd-table{width:1.25rem;height:1.25rem;pointer-events:none;fill:currentColor}.mrd-table__action-tooltip.sc-mrd-table{display:none;position:absolute;bottom:calc(100% + 6px);right:0;padding:var(--mrd-space-1) var(--mrd-space-2);font-size:var(--mrd-font-size-xs);white-space:nowrap;background:var(--mrd-color-tooltip, #fffce1);color:var(--mrd-color-neutral-900);border:1px solid var(--mrd-border-color);border-radius:var(--mrd-border-radius-sm, var(--mrd-border-radius));pointer-events:none;z-index:10}.mrd-table__action.sc-mrd-table:hover .mrd-table__action-tooltip.sc-mrd-table{display:block}.mrd-table__filter-toggle--active.sc-mrd-table{background:var(--mrd-color-primary);border-color:var(--mrd-color-primary);color:var(--mrd-color-white)}.mrd-table__filter-toggle--active.sc-mrd-table:hover{background:var(--mrd-color-primary-dark, var(--mrd-color-primary));border-color:var(--mrd-color-primary-dark, var(--mrd-color-primary));color:var(--mrd-color-white)}.mrd-table__filter-badge.sc-mrd-table{position:absolute;top:-6px;right:-6px;min-width:1.25rem;height:1.25rem;padding:0 3px;background:var(--mrd-color-error, #e53e3e);color:var(--mrd-color-white);border-radius:9999px;font-size:0.65rem;font-weight:var(--mrd-font-weight-medium);line-height:1.25rem;text-align:center;pointer-events:none}.mrd-table__header--filtered.sc-mrd-table{color:var(--mrd-color-primary);border-bottom-color:var(--mrd-color-primary)}.mrd-table__filter-popup.sc-mrd-table{position:fixed;width:280px;background:var(--mrd-color-white);border:1px solid var(--mrd-border-color);border-radius:var(--mrd-border-radius);box-shadow:var(--mrd-shadow-md, 0 4px 12px rgba(0,0,0,.12));z-index:var(--mrd-z-dropdown, 200);font-size:var(--mrd-font-size-sm)}.mrd-table__filter-popup-header.sc-mrd-table{display:flex;align-items:center;justify-content:space-between;padding:var(--mrd-space-2) var(--mrd-space-3);border-bottom:1px solid var(--mrd-border-color)}.mrd-table__filter-popup-title.sc-mrd-table{font-weight:var(--mrd-font-weight-medium);color:var(--mrd-color-neutral-800);font-size:var(--mrd-font-size-sm)}.mrd-table__filter-close.sc-mrd-table{background:transparent;border:none;cursor:pointer;color:var(--mrd-color-neutral-500);font-size:0.9rem;padding:2px 4px;border-radius:3px;line-height:1}.mrd-table__filter-close.sc-mrd-table:hover{background:var(--mrd-color-neutral-100);color:var(--mrd-color-neutral-800)}.mrd-table__filter-section.sc-mrd-table{padding:var(--mrd-space-2) var(--mrd-space-3)}.mrd-table__filter-section-label.sc-mrd-table{font-size:var(--mrd-font-size-xs);font-weight:var(--mrd-font-weight-medium);text-transform:uppercase;letter-spacing:0.04em;color:var(--mrd-color-neutral-500);margin-bottom:var(--mrd-space-2)}.mrd-table__filter-sort-buttons.sc-mrd-table{display:flex;gap:var(--mrd-space-2)}.mrd-table__filter-sort-btn.sc-mrd-table{flex:1;padding:var(--mrd-space-1) var(--mrd-space-2);background:transparent;border:1px solid var(--mrd-border-color);border-radius:var(--mrd-border-radius);cursor:pointer;font-size:var(--mrd-font-size-xs);color:var(--mrd-color-neutral-700)}.mrd-table__filter-sort-btn.sc-mrd-table:hover{background:var(--mrd-color-neutral-100)}.mrd-table__filter-sort-btn--active.sc-mrd-table{background:var(--mrd-color-primary);border-color:var(--mrd-color-primary);color:var(--mrd-color-white)}.mrd-table__filter-divider.sc-mrd-table{height:1px;background:var(--mrd-border-color);margin:0}.mrd-table__filter-editor.sc-mrd-table{display:flex;flex-direction:column;gap:var(--mrd-space-2)}.mrd-table__filter-select.sc-mrd-table,.mrd-table__filter-input.sc-mrd-table{width:100%;padding:var(--mrd-space-1) var(--mrd-space-2);border:1px solid var(--mrd-border-color);border-radius:var(--mrd-border-radius);font-size:var(--mrd-font-size-sm);color:var(--mrd-color-neutral-900);background:var(--mrd-color-white);box-sizing:border-box}.mrd-table__filter-select.sc-mrd-table:focus,.mrd-table__filter-input.sc-mrd-table:focus{outline:none;border-color:var(--mrd-color-primary);box-shadow:0 0 0 2px rgba(0,0,0,.06)}.mrd-table__filter-range.sc-mrd-table{display:flex;align-items:center;gap:var(--mrd-space-1)}.mrd-table__filter-range.sc-mrd-table .mrd-table__filter-input.sc-mrd-table{flex:1;min-width:0}.mrd-table__filter-range-sep.sc-mrd-table{color:var(--mrd-color-neutral-400);flex-shrink:0}.mrd-table__filter-range--stacked.sc-mrd-table{flex-direction:column;align-items:stretch;gap:var(--mrd-space-2)}.mrd-table__filter-range-label.sc-mrd-table{font-size:var(--mrd-font-size-xs);color:var(--mrd-color-neutral-500);margin-bottom:2px}.mrd-table__filter-radio-group.sc-mrd-table{display:flex;flex-direction:column;gap:var(--mrd-space-1)}.mrd-table__filter-radio-group--inline.sc-mrd-table{flex-direction:row;gap:var(--mrd-space-3)}.mrd-table__filter-radio-label.sc-mrd-table{display:flex;align-items:center;gap:var(--mrd-space-1);cursor:pointer;font-size:var(--mrd-font-size-sm);color:var(--mrd-color-neutral-800)}.mrd-table__filter-list.sc-mrd-table{display:flex;flex-direction:column;gap:var(--mrd-space-1);max-height:180px;overflow-y:auto}.mrd-table__filter-list-controls.sc-mrd-table{display:flex;gap:var(--mrd-space-2);margin-bottom:var(--mrd-space-1)}.mrd-table__filter-list-btn.sc-mrd-table{font-size:var(--mrd-font-size-xs);color:var(--mrd-color-primary);background:transparent;border:none;cursor:pointer;padding:0;text-decoration:underline}.mrd-table__filter-checkbox-label.sc-mrd-table{display:flex;align-items:center;gap:var(--mrd-space-1);cursor:pointer;font-size:var(--mrd-font-size-sm);color:var(--mrd-color-neutral-800)}.mrd-table__filter-no-support.sc-mrd-table{font-size:var(--mrd-font-size-sm);color:var(--mrd-color-neutral-500);margin:0;font-style:italic}.mrd-table__filter-popup-footer.sc-mrd-table{display:flex;justify-content:flex-end;gap:var(--mrd-space-2);padding:var(--mrd-space-2) var(--mrd-space-3);border-top:1px solid var(--mrd-border-color)}.mrd-table__filter-btn.sc-mrd-table{padding:var(--mrd-space-1) var(--mrd-space-3);border-radius:var(--mrd-border-radius);border:1px solid var(--mrd-border-color);font-size:var(--mrd-font-size-sm);cursor:pointer}.mrd-table__filter-btn--clear.sc-mrd-table{background:transparent;color:var(--mrd-color-neutral-600)}.mrd-table__filter-btn--clear.sc-mrd-table:hover{background:var(--mrd-color-neutral-100)}.mrd-table__filter-btn--apply.sc-mrd-table{background:var(--mrd-color-primary);border-color:var(--mrd-color-primary);color:var(--mrd-color-white)}.mrd-table__filter-btn--apply.sc-mrd-table:hover{background:var(--mrd-color-primary-dark, var(--mrd-color-primary));border-color:var(--mrd-color-primary-dark, var(--mrd-color-primary))}.mrd-table__totals-row.sc-mrd-table{border-top:2px solid var(--mrd-border-color)}.mrd-table__totals-cell.sc-mrd-table{position:sticky;bottom:0;z-index:2;padding:var(--mrd-space-2) var(--mrd-space-4);background:var(--mrd-color-white);font-weight:var(--mrd-font-weight-medium);font-variant-numeric:tabular-nums;white-space:nowrap;border-top:2px solid var(--mrd-border-color)}.mrd-table__totals-cell--numeric.sc-mrd-table{text-align:right}.mrd-table__footer.sc-mrd-table{padding:var(--mrd-space-1) var(--mrd-space-2);font-size:var(--mrd-font-size-xs);color:var(--mrd-color-neutral-500);text-align:right}.mrd-table__empty.sc-mrd-table{padding:var(--mrd-space-4) var(--mrd-space-3);color:var(--mrd-color-neutral-500);font-size:var(--mrd-font-size-sm);text-align:center;margin:0}.mrd-table__file-btn.sc-mrd-table{display:inline-flex;align-items:center;gap:var(--mrd-space-1);background:none;border:none;padding:0;cursor:pointer;color:var(--mrd-color-primary);font-size:var(--mrd-font-size-sm);font-family:inherit;max-width:100%;overflow:hidden}.mrd-table__file-btn.sc-mrd-table:hover{text-decoration:underline;color:var(--mrd-color-primary-dark)}.mrd-table__file-icon.sc-mrd-table{flex-shrink:0;width:1rem;height:1rem}.mrd-table__textblock-btn.sc-mrd-table{display:inline;background:none;border:none;padding:0 0 0 var(--mrd-space-1);cursor:pointer;color:var(--mrd-color-primary);font-size:var(--mrd-font-size-sm);font-family:inherit;line-height:inherit;vertical-align:middle}.mrd-table__textblock-btn.sc-mrd-table:hover{color:var(--mrd-color-primary-dark)}.mrd-table__modal-backdrop.sc-mrd-table{position:fixed;inset:0;background:rgba(0, 0, 0, 0.4);z-index:var(--mrd-z-modal, 300);display:flex;align-items:center;justify-content:center}.mrd-table__modal.sc-mrd-table{background:#fff;border-radius:var(--mrd-radius-md, 0.5rem);padding:var(--mrd-space-6);max-width:min(600px, 90vw);max-height:70vh;overflow-y:auto;position:relative;box-shadow:var(--mrd-shadow-lg)}.mrd-table__modal-close.sc-mrd-table{position:absolute;top:var(--mrd-space-3);right:var(--mrd-space-3);background:none;border:none;cursor:pointer;font-size:1.25rem;line-height:1;color:var(--mrd-color-text-muted, #6b7280);padding:0}.mrd-table__modal-close.sc-mrd-table:hover{color:var(--mrd-color-text, #111827)}.mrd-table__modal-text.sc-mrd-table{margin:0;padding-right:var(--mrd-space-6);white-space:pre-wrap;word-break:break-word;font-size:var(--mrd-font-size-sm);line-height:1.6}.mrd-table__json-preview.sc-mrd-table{font-family:var(--mrd-font-family-mono);font-size:var(--mrd-font-size-xs);overflow:hidden;white-space:nowrap;text-overflow:ellipsis;display:inline-block;max-width:calc(100% - 1.5rem);vertical-align:middle}.mrd-table__modal-json.sc-mrd-table{margin:0;padding-right:var(--mrd-space-6);font-family:var(--mrd-font-family-mono);font-size:var(--mrd-font-size-xs);white-space:pre-wrap;word-break:break-word;line-height:1.6;background:none;border:none}`;
2142
+
2143
+ const BUFFER = 10;
2144
+ /** Wacht deze tijd (ms) na het laatste scroll-event voordat pagina's worden
2145
+ * aangevraagd. Pagina's die de gebruiker snel voorbij scrollt worden zo geskipt. */
2146
+ const REQUEST_DEBOUNCE_MS = 150;
2147
+ /** Breedte van de filterpopup in px — voor overflow-correctie. */
2148
+ const POPUP_WIDTH = 280;
2149
+ const TEXT_TYPES = new Set(['TEXT', 'TEXTBLOCK', 'EMAIL', 'HYPERLINK']);
2150
+ const NUMERIC_TYPES = new Set(['INTEGER', 'DECIMAL', 'PERCENTAGE', 'CURRENCY']);
2151
+ const DATE_TYPES = new Set(['DATE', 'DATETIME', 'TIME']);
2152
+ const NO_FILTER_TYPES = new Set(['FILE', 'IMAGE']);
2153
+ /** Column types that cannot be sorted or filtered (not stored in PostgreSQL). */
2154
+ const NON_INTERACTIVE_TYPES = new Set(['LONGTEXT', 'JSON']);
2155
+ const MrdTable = class {
2156
+ constructor(hostRef) {
2157
+ index.registerInstance(this, hostRef);
2158
+ this.mrdLoadPage = index.createEvent(this, "mrdLoadPage");
2159
+ this.mrdRowClick = index.createEvent(this, "mrdRowClick");
2160
+ this.mrdAction = index.createEvent(this, "mrdAction");
2161
+ this.mrdFilter = index.createEvent(this, "mrdFilter");
2162
+ this.mrdDownload = index.createEvent(this, "mrdDownload");
2163
+ this.mrdSwitchView = index.createEvent(this, "mrdSwitchView");
2164
+ this.mrdLoadAggregations = index.createEvent(this, "mrdLoadAggregations");
2165
+ // ── Non-state internals ────────────────────────────────────────────────────
2166
+ this.pendingPages = new Set();
2167
+ this.debounceTimer = null;
2168
+ this.outsideClickHandler = null;
2169
+ this.viewSwitcherClickHandler = null;
2170
+ this.keydownHandler = null;
2171
+ // ── Props ──────────────────────────────────────────────────────────────────
2172
+ this.columns = [];
2173
+ /** Direct rows (non-paginated mode, used when totalElements === 0). */
2174
+ this.rows = [];
2175
+ this.locale = navigator.language;
2176
+ /** Total number of records across all pages. 0 = non-paginated mode. */
2177
+ this.totalElements = 0;
2178
+ /** Records per page (must match the API page size). */
2179
+ this.pageSize = 20;
2180
+ /** Row height in px — used for spacer and scroll-position maths. */
2181
+ this.rowHeight = 36;
2182
+ /** Height of the scroll container in px. */
2183
+ this.tableHeight = 500;
2184
+ /** Initial sort applied on load, e.g. "timestamp,desc" or "name".
2185
+ * Parsed by init() into sortField + sortDir. */
2186
+ this.defaultSort = '';
2187
+ /** Toolbar action buttons rendered above the table. */
2188
+ this.actions = [];
2189
+ /** Display label of the current view — shown in the toolbar center as a view picker trigger. */
2190
+ this.viewLabel = '';
2191
+ /** Alternative views available for this table; renders a dropdown when non-empty. */
2192
+ this.alternativeViews = [];
2193
+ // ── Internal state ─────────────────────────────────────────────────────────
2194
+ this.loadedPages = new Map();
2195
+ this.requestedPages = new Set();
2196
+ this.renderStart = 0;
2197
+ this.renderEnd = 0;
2198
+ this.colWidths = [];
2199
+ this.sortField = '';
2200
+ this.sortDir = 'asc';
2201
+ /** Whether the filter UI is visible on column headers. */
2202
+ this.filterMode = false;
2203
+ /** Active filters keyed by field name. */
2204
+ this.activeFilters = new Map();
2205
+ /** Field name of the currently open filter popup (null = closed). */
2206
+ this.openFilterCol = null;
2207
+ /** Filter state being edited in the open popup. */
2208
+ this.pendingFilter = null;
2209
+ /** Viewport-relative position for the filter popup. */
2210
+ this.popupPos = { top: 0, left: 0 };
2211
+ /** Current scroll offset of the scroll container — drives pagination footer. */
2212
+ this.scrollTop = 0;
2213
+ /** Full text shown in the TEXTBLOCK expand modal (null = closed). */
2214
+ this.textblockModal = null;
2215
+ /** Syntax-highlighted JSON HTML shown in the JSON expand modal (null = closed). */
2216
+ this.jsonModal = null;
2217
+ /** Aggregation totals received from the host via setAggregations(). Null = not yet loaded. */
2218
+ this.aggregations = null;
2219
+ /** Whether the view switcher dropdown is open. */
2220
+ this.viewSwitcherOpen = false;
2221
+ this.handleScroll = (e) => {
2222
+ const scroller = e.currentTarget;
2223
+ const scrollTop = scroller.scrollTop;
2224
+ const total = this.totalElements;
2225
+ const visStart = Math.floor(scrollTop / this.rowHeight);
2226
+ const visEnd = Math.min(visStart + this.visibleCount(), total - 1);
2227
+ this.scrollTop = scrollTop;
2228
+ this.renderStart = Math.max(0, visStart - BUFFER);
2229
+ this.renderEnd = Math.min(total - 1, visEnd + BUFFER);
2230
+ this.requestPagesForWindow(this.renderStart, this.renderEnd);
2231
+ };
2232
+ }
2233
+ // ── Prop watchers ─────────────────────────────────────────────────────────
2234
+ /** Clamp renderEnd when totalElements shrinks (e.g. after a filter is applied). */
2235
+ totalElementsChanged(newVal) {
2236
+ this.renderEnd = Math.min(this.renderEnd, Math.max(0, newVal - 1));
2237
+ }
2238
+ // ── Public API ─────────────────────────────────────────────────────────────
2239
+ /**
2240
+ * Initialise (or reset) the virtual scroll.
2241
+ * Call after setting all props and registering the mrdLoadPage listener,
2242
+ * but before calling setPage(0, rows).
2243
+ */
2244
+ async init() {
2245
+ var _a;
2246
+ if (this.debounceTimer !== null) {
2247
+ clearTimeout(this.debounceTimer);
2248
+ this.debounceTimer = null;
2249
+ }
2250
+ this.pendingPages.clear();
2251
+ this.loadedPages = new Map();
2252
+ this.requestedPages = new Set();
2253
+ this.colWidths = [];
2254
+ if (this.defaultSort) {
2255
+ const parts = this.defaultSort.split(',');
2256
+ this.sortField = parts[0].trim();
2257
+ this.sortDir = ((_a = parts[1]) === null || _a === void 0 ? void 0 : _a.trim()) === 'desc' ? 'desc' : 'asc';
2258
+ }
2259
+ else {
2260
+ this.sortField = '';
2261
+ this.sortDir = 'asc';
2262
+ }
2263
+ this.scrollTop = 0;
2264
+ this.renderStart = 0;
2265
+ // No BUFFER on init — only request what fits the visible area (page 0).
2266
+ // BUFFER is applied during scroll to pre-fetch the next page proactively.
2267
+ this.renderEnd = Math.max(0, Math.min(this.visibleCount() - 1, this.totalElements - 1));
2268
+ const scroller = this.el.querySelector('.mrd-table__scroll');
2269
+ if (scroller)
2270
+ scroller.scrollTop = 0;
2271
+ this.aggregations = null;
2272
+ this.emitLoadAggregations();
2273
+ }
2274
+ /**
2275
+ * Inject the rows for a given page (0-based).
2276
+ * Creates a new Map reference so Stencil detects the state change.
2277
+ *
2278
+ * When the page contains fewer rows than pageSize it is the last page.
2279
+ * renderEnd is clamped immediately so no loading-placeholder rows appear
2280
+ * beyond the actual data — without requiring the host to update totalElements.
2281
+ */
2282
+ async setPage(pageNumber, rows) {
2283
+ if (rows.length < this.pageSize) {
2284
+ // lastRowIdx is -1 when the page is empty; clamp renderEnd to -1 so the
2285
+ // render loop does not execute and no shimmer rows appear.
2286
+ const lastRowIdx = pageNumber * this.pageSize + rows.length - 1;
2287
+ this.renderEnd = Math.min(this.renderEnd, lastRowIdx);
2288
+ }
2289
+ const next = new Map(this.loadedPages);
2290
+ next.set(pageNumber, rows);
2291
+ this.loadedPages = next;
2292
+ }
2293
+ /** Inject aggregation totals returned by the /aggregations endpoint. */
2294
+ async setAggregations(data) {
2295
+ this.aggregations = data;
2296
+ }
2297
+ // ── Lifecycle ──────────────────────────────────────────────────────────────
2298
+ disconnectedCallback() {
2299
+ if (this.outsideClickHandler) {
2300
+ document.removeEventListener('click', this.outsideClickHandler);
2301
+ this.outsideClickHandler = null;
2302
+ }
2303
+ if (this.viewSwitcherClickHandler) {
2304
+ document.removeEventListener('click', this.viewSwitcherClickHandler);
2305
+ this.viewSwitcherClickHandler = null;
2306
+ }
2307
+ if (this.keydownHandler) {
2308
+ document.removeEventListener('keydown', this.keydownHandler);
2309
+ this.keydownHandler = null;
2310
+ }
2311
+ }
2312
+ componentDidRender() {
2313
+ if (this.colWidths.length === 0 && this.loadedPages.size > 0 && this.totalElements > 0) {
2314
+ const ths = this.el.querySelectorAll('.mrd-table__header');
2315
+ if (ths.length > 0) {
2316
+ this.colWidths = Array.from(ths).map(th => th.offsetWidth);
2317
+ }
2318
+ }
2319
+ }
2320
+ // ── Paging / scroll helpers ────────────────────────────────────────────────
2321
+ visibleCount() {
2322
+ return Math.ceil(this.tableHeight / this.rowHeight);
2323
+ }
2324
+ sortParam() {
2325
+ if (!this.sortField)
2326
+ return '';
2327
+ return this.sortDir === 'desc' ? `${this.sortField},desc` : this.sortField;
2328
+ }
2329
+ colName(col) {
2330
+ var _a, _b, _c, _d;
2331
+ return (_d = (_b = (_a = col.field) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : (_c = col.relation) === null || _c === void 0 ? void 0 : _c.name) !== null && _d !== void 0 ? _d : '';
2332
+ }
2333
+ colDataType(col) {
2334
+ var _a, _b;
2335
+ if (col.type === 'RELATION')
2336
+ return 'RELATION';
2337
+ return (_b = (_a = col.field) === null || _a === void 0 ? void 0 : _a.dataType) !== null && _b !== void 0 ? _b : 'TEXT';
2338
+ }
2339
+ // ── Aggregation helpers ────────────────────────────────────────────────────
2340
+ buildAggregationParams() {
2341
+ var _a;
2342
+ const groups = { sum: [], avg: [], count: [] };
2343
+ for (const col of this.columns) {
2344
+ if (col.type !== 'FIELD' || !((_a = col.field) === null || _a === void 0 ? void 0 : _a.aggregate))
2345
+ continue;
2346
+ const fn = col.field.aggregate.toLowerCase();
2347
+ if (fn in groups)
2348
+ groups[fn].push(col.field.name);
2349
+ }
2350
+ const params = {};
2351
+ if (groups.sum.length)
2352
+ params.sum = groups.sum;
2353
+ if (groups.avg.length)
2354
+ params.avg = groups.avg;
2355
+ if (groups.count.length)
2356
+ params.count = groups.count;
2357
+ return Object.keys(params).length > 0 ? params : null;
2358
+ }
2359
+ emitLoadAggregations() {
2360
+ const params = this.buildAggregationParams();
2361
+ if (params)
2362
+ this.mrdLoadAggregations.emit(params);
2363
+ }
2364
+ renderAggregationValue(col) {
2365
+ var _a, _b;
2366
+ if (col.type !== 'FIELD' || !((_a = col.field) === null || _a === void 0 ? void 0 : _a.aggregate) || !this.aggregations)
2367
+ return '';
2368
+ const fn = col.field.aggregate.toLowerCase();
2369
+ const val = (_b = this.aggregations[fn]) === null || _b === void 0 ? void 0 : _b[col.field.name];
2370
+ if (val == null)
2371
+ return '';
2372
+ const dt = col.field.dataType;
2373
+ if (dt === 'INTEGER')
2374
+ return formatNumber(val, this.locale, { maximumFractionDigits: 0 });
2375
+ if (dt === 'PERCENTAGE')
2376
+ return formatPercentage(val, this.locale);
2377
+ if (dt === 'CURRENCY' && col.field.currencyCode)
2378
+ return formatCurrency(val, col.field.currencyCode, this.locale);
2379
+ return formatNumber(val, this.locale);
2380
+ }
2381
+ // ── Reset pagination ───────────────────────────────────────────────────────
2382
+ /** Reset pagination state and scroll to top (used after sort or filter change). */
2383
+ resetPages() {
2384
+ if (this.debounceTimer !== null) {
2385
+ clearTimeout(this.debounceTimer);
2386
+ this.debounceTimer = null;
2387
+ }
2388
+ this.pendingPages.clear();
2389
+ this.loadedPages = new Map();
2390
+ this.requestedPages = new Set();
2391
+ this.colWidths = [];
2392
+ this.scrollTop = 0;
2393
+ this.renderStart = 0;
2394
+ // No BUFFER here — totalElements may be stale after a filter change.
2395
+ // Only request what is visible; BUFFER kicks in during scroll as usual.
2396
+ this.renderEnd = Math.max(0, Math.min(this.visibleCount() - 1, this.totalElements - 1));
2397
+ const scroller = this.el.querySelector('.mrd-table__scroll');
2398
+ if (scroller)
2399
+ scroller.scrollTop = 0;
2400
+ }
2401
+ handleSortClick(col) {
2402
+ const name = this.colName(col);
2403
+ if (this.sortField === name) {
2404
+ this.sortDir = this.sortDir === 'asc' ? 'desc' : 'asc';
2405
+ }
2406
+ else {
2407
+ this.sortField = name;
2408
+ this.sortDir = 'asc';
2409
+ }
2410
+ this.resetPages();
2411
+ this.emitPagesForWindow(this.renderStart, this.renderEnd);
2412
+ }
2413
+ applySort(col, dir) {
2414
+ this.sortField = this.colName(col);
2415
+ this.sortDir = dir;
2416
+ this.resetPages();
2417
+ this.emitPagesForWindow(this.renderStart, this.renderEnd);
2418
+ }
2419
+ emitPagesForWindow(start, end) {
2420
+ const firstPage = Math.floor(start / this.pageSize);
2421
+ const lastPage = Math.floor(end / this.pageSize);
2422
+ const next = new Set(this.requestedPages);
2423
+ let changed = false;
2424
+ for (let p = firstPage; p <= lastPage; p++) {
2425
+ if (!this.loadedPages.has(p) && !next.has(p)) {
2426
+ next.add(p);
2427
+ this.mrdLoadPage.emit({ page: p, sort: this.sortParam() });
2428
+ changed = true;
2429
+ }
2430
+ }
2431
+ if (changed)
2432
+ this.requestedPages = next;
2433
+ }
2434
+ getRow(i) {
2435
+ var _a;
2436
+ const page = this.loadedPages.get(Math.floor(i / this.pageSize));
2437
+ return (_a = page === null || page === void 0 ? void 0 : page[i % this.pageSize]) !== null && _a !== void 0 ? _a : null;
2438
+ }
2439
+ requestPagesForWindow(start, end) {
2440
+ const firstPage = Math.floor(start / this.pageSize);
2441
+ const lastPage = Math.floor(end / this.pageSize);
2442
+ let anyNew = false;
2443
+ for (let p = firstPage; p <= lastPage; p++) {
2444
+ if (!this.loadedPages.has(p) && !this.requestedPages.has(p) && !this.pendingPages.has(p)) {
2445
+ this.pendingPages.add(p);
2446
+ anyNew = true;
2447
+ }
2448
+ }
2449
+ if (!anyNew)
2450
+ return;
2451
+ if (this.debounceTimer !== null)
2452
+ clearTimeout(this.debounceTimer);
2453
+ this.debounceTimer = setTimeout(() => this.flushPendingPages(), REQUEST_DEBOUNCE_MS);
2454
+ }
2455
+ flushPendingPages() {
2456
+ this.debounceTimer = null;
2457
+ if (this.pendingPages.size === 0)
2458
+ return;
2459
+ const next = new Set(this.requestedPages);
2460
+ let changed = false;
2461
+ for (const page of this.pendingPages) {
2462
+ if (this.loadedPages.has(page) || next.has(page))
2463
+ continue;
2464
+ const pageStart = page * this.pageSize;
2465
+ const pageEnd = pageStart + this.pageSize - 1;
2466
+ if (pageEnd < this.renderStart || pageStart > this.renderEnd)
2467
+ continue;
2468
+ next.add(page);
2469
+ this.mrdLoadPage.emit({ page, sort: this.sortParam() });
2470
+ changed = true;
2471
+ }
2472
+ this.pendingPages.clear();
2473
+ if (changed)
2474
+ this.requestedPages = next;
2475
+ }
2476
+ // ── Filter helpers ─────────────────────────────────────────────────────────
2477
+ handleFilterToggle() {
2478
+ this.filterMode = !this.filterMode;
2479
+ if (!this.filterMode)
2480
+ this.closeFilterPopup();
2481
+ }
2482
+ handleFilterOpen(col, e) {
2483
+ e.stopPropagation();
2484
+ const btn = e.currentTarget;
2485
+ const rect = btn.getBoundingClientRect();
2486
+ let left = rect.left;
2487
+ if (left + POPUP_WIDTH > window.innerWidth - 8)
2488
+ left = rect.right - POPUP_WIDTH;
2489
+ this.popupPos = { top: rect.bottom + 4, left: Math.max(8, left) };
2490
+ const name = this.colName(col);
2491
+ const dataType = this.colDataType(col);
2492
+ const existing = this.activeFilters.get(name);
2493
+ // Set the default operator explicitly so it is present in the ColumnFilter
2494
+ // even when the user never touches the operator dropdown.
2495
+ const defaultOperator = (TEXT_TYPES.has(dataType) || dataType === 'RELATION')
2496
+ ? 'startsWith'
2497
+ : undefined;
2498
+ // For DATETIME, stored values are UTC ISO strings; convert back to local
2499
+ // "YYYY-MM-DD" dates so the date inputs show what the user originally entered.
2500
+ // If from and to cover the same local day it was an exact-date filter — restore
2501
+ // to exact mode so the user sees the single-date input again.
2502
+ if (dataType === 'DATETIME' && existing && existing.operator !== 'isEmpty' && existing.operator !== 'isNotEmpty') {
2503
+ const display = Object.assign({}, existing);
2504
+ if (typeof display.from === 'string' && display.from)
2505
+ display.from = this.utcISOToLocalDate(display.from);
2506
+ if (typeof display.to === 'string' && display.to)
2507
+ display.to = this.utcISOToLocalDateExclusiveEnd(display.to);
2508
+ if (display.from && display.to && display.from === display.to) {
2509
+ this.pendingFilter = Object.assign(Object.assign({}, display), { value: display.from, from: undefined, to: undefined });
2510
+ }
2511
+ else {
2512
+ this.pendingFilter = display;
2513
+ }
2514
+ }
2515
+ else {
2516
+ this.pendingFilter = existing ? Object.assign({}, existing) : { field: name, dataType, operator: defaultOperator };
2517
+ }
2518
+ this.openFilterCol = name;
2519
+ // Close on outside click — re-register to replace any stale handler
2520
+ if (this.outsideClickHandler)
2521
+ document.removeEventListener('click', this.outsideClickHandler);
2522
+ this.outsideClickHandler = (ev) => {
2523
+ const popup = this.el.querySelector('.mrd-table__filter-popup');
2524
+ if (popup && !popup.contains(ev.target))
2525
+ this.closeFilterPopup();
2526
+ };
2527
+ document.addEventListener('click', this.outsideClickHandler);
2528
+ }
2529
+ closeFilterPopup() {
2530
+ this.openFilterCol = null;
2531
+ this.pendingFilter = null;
2532
+ if (this.outsideClickHandler) {
2533
+ document.removeEventListener('click', this.outsideClickHandler);
2534
+ this.outsideClickHandler = null;
2535
+ }
2536
+ }
2537
+ openTextblockModal(text) {
2538
+ this.textblockModal = text;
2539
+ if (this.keydownHandler)
2540
+ document.removeEventListener('keydown', this.keydownHandler);
2541
+ this.keydownHandler = (ev) => {
2542
+ if (ev.key === 'Escape')
2543
+ this.closeTextblockModal();
2544
+ };
2545
+ document.addEventListener('keydown', this.keydownHandler);
2546
+ }
2547
+ closeTextblockModal() {
2548
+ this.textblockModal = null;
2549
+ if (this.keydownHandler) {
2550
+ document.removeEventListener('keydown', this.keydownHandler);
2551
+ this.keydownHandler = null;
2552
+ }
2553
+ }
2554
+ openJsonModal(html) {
2555
+ this.jsonModal = html;
2556
+ if (this.keydownHandler)
2557
+ document.removeEventListener('keydown', this.keydownHandler);
2558
+ this.keydownHandler = (ev) => {
2559
+ if (ev.key === 'Escape')
2560
+ this.closeJsonModal();
2561
+ };
2562
+ document.addEventListener('keydown', this.keydownHandler);
2563
+ }
2564
+ closeJsonModal() {
2565
+ this.jsonModal = null;
2566
+ if (this.keydownHandler) {
2567
+ document.removeEventListener('keydown', this.keydownHandler);
2568
+ this.keydownHandler = null;
2569
+ }
2570
+ }
2571
+ setPending(key, val) {
2572
+ this.pendingFilter = Object.assign(Object.assign({}, this.pendingFilter), { [key]: val });
2573
+ }
2574
+ togglePendingValue(key, checked) {
2575
+ var _a, _b;
2576
+ const current = (_b = (_a = this.pendingFilter) === null || _a === void 0 ? void 0 : _a.values) !== null && _b !== void 0 ? _b : [];
2577
+ this.pendingFilter = Object.assign(Object.assign({}, this.pendingFilter), { values: checked ? [...current, key] : current.filter(k => k !== key) });
2578
+ }
2579
+ filterHasValue(f) {
2580
+ if (f.operator === 'isEmpty' || f.operator === 'isNotEmpty')
2581
+ return true;
2582
+ if (f.values !== undefined && f.values.length > 0)
2583
+ return true;
2584
+ if (f.value != null && f.value !== '')
2585
+ return true;
2586
+ if (typeof f.value === 'boolean')
2587
+ return true;
2588
+ if (f.from != null && f.from !== '')
2589
+ return true;
2590
+ if (f.to != null && f.to !== '')
2591
+ return true;
2592
+ return false;
2593
+ }
2594
+ // Convert a local "YYYY-MM-DD" date string to the UTC ISO string at the
2595
+ // start of that local day (midnight). new Date(y, m, d) uses local time.
2596
+ dateLocalToUTCStart(dateStr) {
2597
+ if (!dateStr)
2598
+ return dateStr;
2599
+ const [year, month, day] = dateStr.split('-').map(Number);
2600
+ return new Date(year, month - 1, day).toISOString().replace(/\.\d{3}Z$/, 'Z');
2601
+ }
2602
+ // Start of the day AFTER the given local date (exclusive range end).
2603
+ dateLocalToUTCEndExclusive(dateStr) {
2604
+ if (!dateStr)
2605
+ return dateStr;
2606
+ const [year, month, day] = dateStr.split('-').map(Number);
2607
+ return new Date(year, month - 1, day + 1).toISOString().replace(/\.\d{3}Z$/, 'Z');
2608
+ }
2609
+ // Convert a stored UTC ISO string back to the local "YYYY-MM-DD" date.
2610
+ utcISOToLocalDate(utcStr) {
2611
+ if (!utcStr)
2612
+ return utcStr;
2613
+ const d = new Date(utcStr);
2614
+ if (isNaN(d.getTime()))
2615
+ return utcStr;
2616
+ return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`;
2617
+ }
2618
+ // The stored "to" value is the exclusive end (midnight of the next day).
2619
+ // Subtract one day to recover the local date the user entered.
2620
+ utcISOToLocalDateExclusiveEnd(utcStr) {
2621
+ if (!utcStr)
2622
+ return utcStr;
2623
+ const d = new Date(utcStr);
2624
+ if (isNaN(d.getTime()))
2625
+ return utcStr;
2626
+ d.setDate(d.getDate() - 1);
2627
+ return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`;
2628
+ }
2629
+ applyFilter() {
2630
+ const f = this.pendingFilter;
2631
+ if (!(f === null || f === void 0 ? void 0 : f.field)) {
2632
+ this.closeFilterPopup();
2633
+ return;
2634
+ }
2635
+ // For DATETIME fields the user enters local dates; convert to UTC ISO strings.
2636
+ // Exact date → range covering the full local day (from = midnight, to = next midnight).
2637
+ // "to" is always the exclusive end (midnight of the next local day).
2638
+ let normalized = Object.assign({}, f);
2639
+ if (f.dataType === 'DATETIME' && f.operator !== 'isEmpty' && f.operator !== 'isNotEmpty') {
2640
+ if (typeof normalized.value === 'string' && normalized.value) {
2641
+ normalized.from = this.dateLocalToUTCStart(normalized.value);
2642
+ normalized.to = this.dateLocalToUTCEndExclusive(normalized.value);
2643
+ normalized.value = undefined;
2644
+ }
2645
+ else {
2646
+ if (typeof normalized.from === 'string' && normalized.from)
2647
+ normalized.from = this.dateLocalToUTCStart(normalized.from);
2648
+ if (typeof normalized.to === 'string' && normalized.to)
2649
+ normalized.to = this.dateLocalToUTCEndExclusive(normalized.to);
2650
+ }
2651
+ }
2652
+ const next = new Map(this.activeFilters);
2653
+ if (this.filterHasValue(normalized)) {
2654
+ next.set(normalized.field, normalized);
2655
+ }
2656
+ else {
2657
+ next.delete(normalized.field);
2658
+ }
2659
+ this.activeFilters = next;
2660
+ this.closeFilterPopup();
2661
+ this.mrdFilter.emit({ filters: Array.from(this.activeFilters.values()) });
2662
+ this.aggregations = null;
2663
+ this.emitLoadAggregations();
2664
+ if (this.totalElements > 0) {
2665
+ this.resetPages();
2666
+ this.emitPagesForWindow(this.renderStart, this.renderEnd);
2667
+ }
2668
+ }
2669
+ clearFilter() {
2670
+ const name = this.openFilterCol;
2671
+ const next = new Map(this.activeFilters);
2672
+ if (name)
2673
+ next.delete(name);
2674
+ this.activeFilters = next;
2675
+ this.closeFilterPopup();
2676
+ this.mrdFilter.emit({ filters: Array.from(this.activeFilters.values()) });
2677
+ this.aggregations = null;
2678
+ this.emitLoadAggregations();
2679
+ if (this.totalElements > 0) {
2680
+ this.resetPages();
2681
+ this.emitPagesForWindow(this.renderStart, this.renderEnd);
2682
+ }
2683
+ }
2684
+ clearAllFilters() {
2685
+ this.activeFilters = new Map();
2686
+ this.mrdFilter.emit({ filters: [] });
2687
+ this.aggregations = null;
2688
+ this.emitLoadAggregations();
2689
+ if (this.totalElements > 0) {
2690
+ this.resetPages();
2691
+ this.emitPagesForWindow(this.renderStart, this.renderEnd);
2692
+ }
2693
+ }
2694
+ // ── View switcher ──────────────────────────────────────────────────────────
2695
+ openViewSwitcher() {
2696
+ this.viewSwitcherOpen = true;
2697
+ if (this.viewSwitcherClickHandler)
2698
+ document.removeEventListener('click', this.viewSwitcherClickHandler);
2699
+ this.viewSwitcherClickHandler = (ev) => {
2700
+ const wrapper = this.el.querySelector('.mrd-table__view-switcher');
2701
+ if (wrapper && !wrapper.contains(ev.target))
2702
+ this.closeViewSwitcher();
2703
+ };
2704
+ document.addEventListener('click', this.viewSwitcherClickHandler);
2705
+ }
2706
+ closeViewSwitcher() {
2707
+ this.viewSwitcherOpen = false;
2708
+ if (this.viewSwitcherClickHandler) {
2709
+ document.removeEventListener('click', this.viewSwitcherClickHandler);
2710
+ this.viewSwitcherClickHandler = null;
2711
+ }
2712
+ }
2713
+ handleViewSwitch(view) {
2714
+ this.closeViewSwitcher();
2715
+ this.mrdSwitchView.emit({ name: view.name, class: view.class });
2716
+ }
2717
+ renderViewSwitcher() {
2718
+ return (index.h("div", { class: "mrd-table__view-switcher" }, index.h("button", { class: `mrd-table__view-switcher-btn${this.viewSwitcherOpen ? ' mrd-table__view-switcher-btn--open' : ''}`, "aria-label": this.viewLabel, onClick: (e) => {
2719
+ e.stopPropagation();
2720
+ this.viewSwitcherOpen ? this.closeViewSwitcher() : this.openViewSwitcher();
2721
+ } }, index.h("svg", { class: "mrd-table__view-switcher-chevron", viewBox: "0 0 24 24", "aria-hidden": "true" }, index.h("path", { fill: "currentColor", d: "M7 10l5 5 5-5z" }))), this.viewSwitcherOpen && (index.h("div", { class: "mrd-table__view-switcher-dropdown", onClick: (e) => e.stopPropagation() }, this.alternativeViews.map(view => {
2722
+ var _a;
2723
+ return (index.h("button", { class: "mrd-table__view-switcher-item", onClick: () => this.handleViewSwitch(view) }, (_a = view.label) !== null && _a !== void 0 ? _a : view.name));
2724
+ })))));
2725
+ }
2726
+ // ── Render: toolbar ────────────────────────────────────────────────────────
2727
+ renderToolbar() {
2728
+ var _a, _b;
2729
+ const filterCount = this.activeFilters.size;
2730
+ const hasActions = ((_a = this.actions) === null || _a === void 0 ? void 0 : _a.length) > 0;
2731
+ const hasViewSwitcher = !!this.viewLabel && ((_b = this.alternativeViews) === null || _b === void 0 ? void 0 : _b.length) > 0;
2732
+ return (index.h("div", { class: "mrd-table__toolbar" }, index.h("div", { class: "mrd-table__toolbar-left" }, index.h("button", { class: `mrd-table__action mrd-table__action--secondary mrd-table__filter-toggle${this.filterMode ? ' mrd-table__filter-toggle--active' : ''}`, onClick: () => this.handleFilterToggle() }, index.h("svg", { class: "mrd-table__action-icon", viewBox: "0 0 24 24", "aria-hidden": "true" }, index.h("path", { fill: "currentColor", d: "M10 18h4v-2h-4v2zM3 6v2h18V6H3zm3 7h12v-2H6v2z" })), filterCount > 0 && index.h("span", { class: "mrd-table__filter-badge" }, filterCount), index.h("span", { class: "mrd-table__action-tooltip" }, this.filterMode ? t('table_filter_hide', this.locale) : t('table_filter', this.locale), filterCount > 0 ? ` (${filterCount} ${t('table_filter_active', this.locale)})` : '')), filterCount > 0 && (index.h("button", { class: "mrd-table__action mrd-table__action--secondary", onClick: () => this.clearAllFilters() }, index.h("svg", { class: "mrd-table__action-icon", viewBox: "0 0 24 24", "aria-hidden": "true" }, index.h("path", { fill: "currentColor", d: "M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z" })), index.h("span", { class: "mrd-table__action-tooltip" }, t('table_filter_clear_all', this.locale))))), hasViewSwitcher && (index.h("div", { class: "mrd-table__toolbar-center" }, index.h("span", { class: "mrd-table__view-title" }, this.viewLabel), this.renderViewSwitcher())), hasActions && (index.h("div", { class: "mrd-table__toolbar-right" }, this.actions.map(a => {
2733
+ var _a;
2734
+ return (index.h("button", { class: `mrd-table__action mrd-table__action--${(_a = a.variant) !== null && _a !== void 0 ? _a : 'secondary'}`, disabled: a.disabled, onClick: () => this.mrdAction.emit({ action: a.action }) }, a.icon
2735
+ ? index.h("svg", { class: "mrd-table__action-icon", "aria-hidden": "true" }, index.h("use", { href: a.icon }))
2736
+ : a.label, index.h("span", { class: "mrd-table__action-tooltip" }, a.label)));
2737
+ })))));
2738
+ }
2739
+ // ── Render: filter popup ───────────────────────────────────────────────────
2740
+ renderFilterEditor(col) {
2741
+ var _a, _b, _c, _d, _e, _f, _g, _h;
2742
+ const pf = (_a = this.pendingFilter) !== null && _a !== void 0 ? _a : {};
2743
+ const dataType = this.colDataType(col);
2744
+ if (NO_FILTER_TYPES.has(dataType)) {
2745
+ return index.h("p", { class: "mrd-table__filter-no-support" }, t('filter_no_support', this.locale));
2746
+ }
2747
+ if (dataType === 'BOOLEAN') {
2748
+ const boolOp = pf.operator;
2749
+ const noValueOp = boolOp === 'isEmpty' || boolOp === 'isNotEmpty';
2750
+ return (index.h("div", { class: "mrd-table__filter-radio-group" }, [
2751
+ { labelKey: 'filter_all', value: null },
2752
+ { labelKey: 'yes', value: true },
2753
+ { labelKey: 'no', value: false },
2754
+ ].map(opt => (index.h("label", { class: "mrd-table__filter-radio-label" }, index.h("input", { type: "radio", name: `bf-${this.openFilterCol}`, checked: !noValueOp && pf.value === opt.value, onChange: () => { this.pendingFilter = Object.assign(Object.assign({}, pf), { operator: undefined, value: opt.value }); } }), t(opt.labelKey, this.locale)))), index.h("label", { class: "mrd-table__filter-radio-label" }, index.h("input", { type: "radio", name: `bf-${this.openFilterCol}`, checked: boolOp === 'isEmpty', onChange: () => { this.pendingFilter = Object.assign(Object.assign({}, pf), { operator: 'isEmpty', value: undefined }); } }), t('filter_is_empty', this.locale)), index.h("label", { class: "mrd-table__filter-radio-label" }, index.h("input", { type: "radio", name: `bf-${this.openFilterCol}`, checked: boolOp === 'isNotEmpty', onChange: () => { this.pendingFilter = Object.assign(Object.assign({}, pf), { operator: 'isNotEmpty', value: undefined }); } }), t('filter_is_not_empty', this.locale))));
2755
+ }
2756
+ if (dataType === 'LIST') {
2757
+ const items = (_c = (_b = col.field) === null || _b === void 0 ? void 0 : _b.listItems) !== null && _c !== void 0 ? _c : [];
2758
+ const selected = (_d = pf.values) !== null && _d !== void 0 ? _d : [];
2759
+ return (index.h("div", { class: "mrd-table__filter-list" }, index.h("div", { class: "mrd-table__filter-list-controls" }, index.h("button", { class: "mrd-table__filter-list-btn", onClick: () => { this.pendingFilter = Object.assign(Object.assign({}, pf), { values: items.map(i => i.key) }); } }, t('filter_select_all', this.locale)), index.h("button", { class: "mrd-table__filter-list-btn", onClick: () => { this.pendingFilter = Object.assign(Object.assign({}, pf), { values: [] }); } }, t('filter_select_none', this.locale))), items.map(item => (index.h("label", { class: "mrd-table__filter-checkbox-label" }, index.h("input", { type: "checkbox", checked: selected.includes(item.key), onChange: (e) => this.togglePendingValue(item.key, e.target.checked) }), item.label)))));
2760
+ }
2761
+ if (TEXT_TYPES.has(dataType) || dataType === 'RELATION') {
2762
+ const op = (_e = pf.operator) !== null && _e !== void 0 ? _e : 'startsWith';
2763
+ const noInput = op === 'isEmpty' || op === 'isNotEmpty';
2764
+ return (index.h("div", { class: "mrd-table__filter-editor" }, index.h("select", { class: "mrd-table__filter-select", onChange: (e) => this.setPending('operator', e.target.value) }, [
2765
+ { val: 'startsWith', labelKey: 'filter_starts_with' },
2766
+ { val: 'equals', labelKey: 'filter_equals' },
2767
+ { val: 'isEmpty', labelKey: 'filter_is_empty' },
2768
+ { val: 'isNotEmpty', labelKey: 'filter_is_not_empty' },
2769
+ ].map(o => index.h("option", { value: o.val, selected: op === o.val }, t(o.labelKey, this.locale)))), !noInput && (index.h("input", { type: "text", class: "mrd-table__filter-input", value: String((_f = pf.value) !== null && _f !== void 0 ? _f : ''), placeholder: t('filter_search_value', this.locale), onInput: (e) => this.setPending('value', e.target.value) }))));
2770
+ }
2771
+ if (NUMERIC_TYPES.has(dataType)) {
2772
+ const numOp = pf.operator;
2773
+ const noInput = numOp === 'isEmpty' || numOp === 'isNotEmpty';
2774
+ const rangeMode = !noInput && (pf.from !== undefined || pf.to !== undefined);
2775
+ return (index.h("div", { class: "mrd-table__filter-editor" }, index.h("select", { class: "mrd-table__filter-select", onChange: (e) => {
2776
+ const val = e.target.value;
2777
+ if (val === 'isEmpty' || val === 'isNotEmpty') {
2778
+ this.pendingFilter = Object.assign(Object.assign({}, pf), { operator: val, value: undefined, from: undefined, to: undefined });
2779
+ }
2780
+ else {
2781
+ this.pendingFilter = Object.assign(Object.assign({}, pf), { operator: undefined });
2782
+ }
2783
+ } }, index.h("option", { value: "", selected: !noInput }, t('filter_has_value', this.locale)), index.h("option", { value: "isEmpty", selected: numOp === 'isEmpty' }, t('filter_is_empty', this.locale)), index.h("option", { value: "isNotEmpty", selected: numOp === 'isNotEmpty' }, t('filter_is_not_empty', this.locale))), !noInput && (index.h("div", { class: "mrd-table__filter-editor" }, index.h("div", { class: "mrd-table__filter-radio-group mrd-table__filter-radio-group--inline" }, index.h("label", { class: "mrd-table__filter-radio-label" }, index.h("input", { type: "radio", name: `nm-${this.openFilterCol}`, checked: !rangeMode, onChange: () => { this.pendingFilter = Object.assign(Object.assign({}, pf), { from: undefined, to: undefined }); } }), t('filter_exact', this.locale)), index.h("label", { class: "mrd-table__filter-radio-label" }, index.h("input", { type: "radio", name: `nm-${this.openFilterCol}`, checked: rangeMode, onChange: () => { this.pendingFilter = Object.assign(Object.assign({}, pf), { value: undefined, from: null, to: null }); } }), t('filter_range', this.locale))), !rangeMode ? (index.h("input", { type: "number", class: "mrd-table__filter-input", value: pf.value != null ? String(pf.value) : '', onInput: (e) => this.setPending('value', e.target.value) })) : (index.h("div", { class: "mrd-table__filter-range" }, index.h("input", { type: "number", class: "mrd-table__filter-input", placeholder: t('filter_from', this.locale), value: pf.from != null ? String(pf.from) : '', onInput: (e) => this.setPending('from', e.target.value) }), index.h("span", { class: "mrd-table__filter-range-sep" }, "\u2013"), index.h("input", { type: "number", class: "mrd-table__filter-input", placeholder: t('filter_to', this.locale), value: pf.to != null ? String(pf.to) : '', onInput: (e) => this.setPending('to', e.target.value) })))))));
2784
+ }
2785
+ if (dataType === 'DATETIME') {
2786
+ const dtOp = pf.operator;
2787
+ const noInput = dtOp === 'isEmpty' || dtOp === 'isNotEmpty';
2788
+ const rangeMode = !noInput && (pf.from !== undefined || pf.to !== undefined);
2789
+ return (index.h("div", { class: "mrd-table__filter-editor" }, index.h("select", { class: "mrd-table__filter-select", onChange: (e) => {
2790
+ const val = e.target.value;
2791
+ if (val === 'isEmpty' || val === 'isNotEmpty') {
2792
+ this.pendingFilter = Object.assign(Object.assign({}, pf), { operator: val, value: undefined, from: undefined, to: undefined });
2793
+ }
2794
+ else {
2795
+ this.pendingFilter = Object.assign(Object.assign({}, pf), { operator: undefined });
2796
+ }
2797
+ } }, index.h("option", { value: "", selected: !noInput }, t('filter_has_value', this.locale)), index.h("option", { value: "isEmpty", selected: dtOp === 'isEmpty' }, t('filter_is_empty', this.locale)), index.h("option", { value: "isNotEmpty", selected: dtOp === 'isNotEmpty' }, t('filter_is_not_empty', this.locale))), !noInput && (index.h("div", { class: "mrd-table__filter-editor" }, index.h("div", { class: "mrd-table__filter-radio-group mrd-table__filter-radio-group--inline" }, index.h("label", { class: "mrd-table__filter-radio-label" }, index.h("input", { type: "radio", name: `dt-${this.openFilterCol}`, checked: !rangeMode, onChange: () => { this.pendingFilter = Object.assign(Object.assign({}, pf), { from: undefined, to: undefined }); } }), t('filter_exact', this.locale)), index.h("label", { class: "mrd-table__filter-radio-label" }, index.h("input", { type: "radio", name: `dt-${this.openFilterCol}`, checked: rangeMode, onChange: () => { this.pendingFilter = Object.assign(Object.assign({}, pf), { value: undefined, from: null, to: null }); } }), t('filter_range', this.locale))), !rangeMode ? (index.h("input", { type: "date", class: "mrd-table__filter-input", value: String((_g = pf.value) !== null && _g !== void 0 ? _g : ''), onInput: (e) => this.setPending('value', e.target.value) })) : (index.h("div", { class: "mrd-table__filter-range mrd-table__filter-range--stacked" }, index.h("label", { class: "mrd-table__filter-range-label" }, t('filter_from', this.locale)), index.h("input", { type: "date", class: "mrd-table__filter-input", value: pf.from != null ? String(pf.from) : '', onInput: (e) => this.setPending('from', e.target.value) }), index.h("label", { class: "mrd-table__filter-range-label" }, t('filter_to', this.locale)), index.h("input", { type: "date", class: "mrd-table__filter-input", value: pf.to != null ? String(pf.to) : '', onInput: (e) => this.setPending('to', e.target.value) })))))));
2798
+ }
2799
+ if (DATE_TYPES.has(dataType)) {
2800
+ const inputType = dataType === 'DATE' ? 'date' : 'time';
2801
+ const dtdOp = pf.operator;
2802
+ const noInput = dtdOp === 'isEmpty' || dtdOp === 'isNotEmpty';
2803
+ const rangeMode = !noInput && (pf.from !== undefined || pf.to !== undefined);
2804
+ return (index.h("div", { class: "mrd-table__filter-editor" }, index.h("select", { class: "mrd-table__filter-select", onChange: (e) => {
2805
+ const val = e.target.value;
2806
+ if (val === 'isEmpty' || val === 'isNotEmpty') {
2807
+ this.pendingFilter = Object.assign(Object.assign({}, pf), { operator: val, value: undefined, from: undefined, to: undefined });
2808
+ }
2809
+ else {
2810
+ this.pendingFilter = Object.assign(Object.assign({}, pf), { operator: undefined });
2811
+ }
2812
+ } }, index.h("option", { value: "", selected: !noInput }, t('filter_has_value', this.locale)), index.h("option", { value: "isEmpty", selected: dtdOp === 'isEmpty' }, t('filter_is_empty', this.locale)), index.h("option", { value: "isNotEmpty", selected: dtdOp === 'isNotEmpty' }, t('filter_is_not_empty', this.locale))), !noInput && (index.h("div", { class: "mrd-table__filter-editor" }, index.h("div", { class: "mrd-table__filter-radio-group mrd-table__filter-radio-group--inline" }, index.h("label", { class: "mrd-table__filter-radio-label" }, index.h("input", { type: "radio", name: `dt-${this.openFilterCol}`, checked: !rangeMode, onChange: () => { this.pendingFilter = Object.assign(Object.assign({}, pf), { from: undefined, to: undefined }); } }), t('filter_exact', this.locale)), index.h("label", { class: "mrd-table__filter-radio-label" }, index.h("input", { type: "radio", name: `dt-${this.openFilterCol}`, checked: rangeMode, onChange: () => { this.pendingFilter = Object.assign(Object.assign({}, pf), { value: undefined, from: null, to: null }); } }), t('filter_range', this.locale))), !rangeMode ? (index.h("input", { type: inputType, class: "mrd-table__filter-input", value: String((_h = pf.value) !== null && _h !== void 0 ? _h : ''), onInput: (e) => this.setPending('value', e.target.value) })) : (index.h("div", { class: "mrd-table__filter-range" }, index.h("input", { type: inputType, class: "mrd-table__filter-input", placeholder: t('filter_from', this.locale), value: pf.from != null ? String(pf.from) : '', onInput: (e) => this.setPending('from', e.target.value) }), index.h("input", { type: inputType, class: "mrd-table__filter-input", placeholder: t('filter_to', this.locale), value: pf.to != null ? String(pf.to) : '', onInput: (e) => this.setPending('to', e.target.value) })))))));
2813
+ }
2814
+ return null;
2815
+ }
2816
+ renderFilterPopup() {
2817
+ var _a, _b, _c, _d;
2818
+ if (!this.openFilterCol || !this.pendingFilter)
2819
+ return null;
2820
+ const col = this.columns.find(c => this.colName(c) === this.openFilterCol);
2821
+ if (!col)
2822
+ return null;
2823
+ const label = (_d = (_b = (_a = col.field) === null || _a === void 0 ? void 0 : _a.label) !== null && _b !== void 0 ? _b : (_c = col.relation) === null || _c === void 0 ? void 0 : _c.label) !== null && _d !== void 0 ? _d : this.openFilterCol;
2824
+ const sortActive = this.sortField === this.openFilterCol;
2825
+ return (index.h("div", { class: "mrd-table__filter-popup", style: { top: `${this.popupPos.top}px`, left: `${this.popupPos.left}px` }, onClick: (e) => e.stopPropagation() }, index.h("div", { class: "mrd-table__filter-popup-header" }, index.h("span", { class: "mrd-table__filter-popup-title" }, label), index.h("button", { class: "mrd-table__filter-close", onClick: () => this.closeFilterPopup() }, "\u2715")), index.h("div", { class: "mrd-table__filter-section" }, index.h("div", { class: "mrd-table__filter-section-label" }, t('filter_sorting', this.locale)), index.h("div", { class: "mrd-table__filter-sort-buttons" }, index.h("button", { class: `mrd-table__filter-sort-btn${sortActive && this.sortDir === 'asc' ? ' mrd-table__filter-sort-btn--active' : ''}`, onClick: () => this.applySort(col, 'asc') }, "\u25B2 ", t('filter_ascending', this.locale)), index.h("button", { class: `mrd-table__filter-sort-btn${sortActive && this.sortDir === 'desc' ? ' mrd-table__filter-sort-btn--active' : ''}`, onClick: () => this.applySort(col, 'desc') }, "\u25BC ", t('filter_descending', this.locale)))), index.h("div", { class: "mrd-table__filter-divider" }), index.h("div", { class: "mrd-table__filter-section" }, index.h("div", { class: "mrd-table__filter-section-label" }, t('filter_section', this.locale)), this.renderFilterEditor(col)), index.h("div", { class: "mrd-table__filter-popup-footer" }, index.h("button", { class: "mrd-table__filter-btn mrd-table__filter-btn--clear", onClick: () => this.clearFilter() }, t('filter_clear', this.locale)), index.h("button", { class: "mrd-table__filter-btn mrd-table__filter-btn--apply", onClick: () => this.applyFilter() }, t('filter_apply', this.locale)))));
2826
+ }
2827
+ // ── Render: footer ────────────────────────────────────────────────────────
2828
+ renderFooter(rowCount, effectiveTotal) {
2829
+ const total = this.totalElements;
2830
+ // Non-paginated mode: show plain row count
2831
+ if (total === 0) {
2832
+ const count = rowCount !== null && rowCount !== void 0 ? rowCount : 0;
2833
+ if (count === 0)
2834
+ return null;
2835
+ return (index.h("div", { class: "mrd-table__footer" }, count, " ", t('table_of', this.locale), " ", count));
2836
+ }
2837
+ // Paginated mode: only show once page 0 has loaded (avoids stale total during filter reset)
2838
+ if (!this.loadedPages.has(0))
2839
+ return null;
2840
+ // Use effectiveTotal (derived from actual page lengths) so the counter
2841
+ // is correct even when the host has not yet updated totalElements.
2842
+ const displayTotal = effectiveTotal !== null && effectiveTotal !== void 0 ? effectiveTotal : total;
2843
+ // Compute from/to independently so partial rows at top/bottom are included.
2844
+ const from = Math.min(Math.floor(this.scrollTop / this.rowHeight) + 1, displayTotal);
2845
+ const to = Math.min(Math.ceil((this.scrollTop + this.tableHeight) / this.rowHeight), displayTotal);
2846
+ return (index.h("div", { class: "mrd-table__footer" }, from, "\u2013", to, " ", t('table_of', this.locale), " ", displayTotal));
2847
+ }
2848
+ // ── Render: cell ──────────────────────────────────────────────────────────
2849
+ renderCell(col, row) {
2850
+ var _a, _b, _c, _d, _e, _f;
2851
+ const numericTypes = new Set(['INTEGER', 'DECIMAL', 'PERCENTAGE', 'CURRENCY']);
2852
+ const dataType = (_b = (_a = col.field) === null || _a === void 0 ? void 0 : _a.dataType) !== null && _b !== void 0 ? _b : '';
2853
+ const isNumeric = col.type === 'FIELD' && numericTypes.has(dataType);
2854
+ const isFile = col.type === 'FIELD' && (dataType === 'FILE' || dataType === 'IMAGE');
2855
+ if (isFile) {
2856
+ const name = (_d = (_c = col.field) === null || _c === void 0 ? void 0 : _c.name) !== null && _d !== void 0 ? _d : '';
2857
+ const fileVal = row === null || row === void 0 ? void 0 : row[name];
2858
+ const href = fileVal === null || fileVal === void 0 ? void 0 : fileVal.href;
2859
+ const fileName = fileVal === null || fileVal === void 0 ? void 0 : fileVal.fileName;
2860
+ return (index.h("td", { class: "mrd-table__cell" }, href && fileName ? (index.h("button", { class: "mrd-table__file-btn", title: fileName, onClick: (e) => {
2861
+ e.stopPropagation();
2862
+ this.mrdDownload.emit({ href, fileName });
2863
+ } }, index.h("svg", { class: "mrd-table__file-icon", viewBox: "0 0 24 24", "aria-hidden": "true" }, index.h("path", { fill: "currentColor", d: "M14 2H6c-1.1 0-2 .9-2 2v16c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V8l-6-6zm-1 7V3.5L18.5 9H13zm-3 8l-3-3 1.41-1.41L10 14.17l4.59-4.58L16 11l-6 6z" })), t('download', this.locale))) : ''));
2864
+ }
2865
+ if (dataType === 'JSON') {
2866
+ const name = (_f = (_e = col.field) === null || _e === void 0 ? void 0 : _e.name) !== null && _f !== void 0 ? _f : '';
2867
+ const rawValue = name ? row === null || row === void 0 ? void 0 : row[name] : undefined;
2868
+ if (rawValue == null || rawValue === '')
2869
+ return index.h("td", { class: "mrd-table__cell" });
2870
+ const compactHtml = CellRenderer.formatJson(rawValue, true);
2871
+ const prettyHtml = CellRenderer.formatJson(rawValue, false);
2872
+ return (index.h("td", { class: "mrd-table__cell" }, index.h("span", { class: "mrd-table__json-preview", innerHTML: compactHtml }), index.h("button", { class: "mrd-table__textblock-btn", onClick: (e) => { e.stopPropagation(); this.openJsonModal(prettyHtml); }, "aria-label": t('textblock_show_more', this.locale) }, "\u22EF")));
2873
+ }
2874
+ const TEXTBLOCK_MAX = 200;
2875
+ if (dataType === 'TEXTBLOCK') {
2876
+ const full = CellRenderer.render(col, row, this.locale);
2877
+ if (full.length <= TEXTBLOCK_MAX) {
2878
+ return index.h("td", { class: "mrd-table__cell" }, full);
2879
+ }
2880
+ const preview = full.slice(0, TEXTBLOCK_MAX) + '…';
2881
+ return (index.h("td", { class: "mrd-table__cell" }, preview, index.h("button", { class: "mrd-table__textblock-btn", onClick: (e) => { e.stopPropagation(); this.openTextblockModal(full); }, "aria-label": t('textblock_show_more', this.locale) }, "\u22EF")));
2882
+ }
2883
+ const value = CellRenderer.render(col, row, this.locale);
2884
+ return (index.h("td", { class: `mrd-table__cell${isNumeric ? ' mrd-table__cell--numeric' : ''}` }, value));
2885
+ }
2886
+ // ── Render: totals row ────────────────────────────────────────────────────
2887
+ renderTotalsRow() {
2888
+ if (!this.aggregations)
2889
+ return null;
2890
+ if (!this.columns.some(c => { var _a; return c.type === 'FIELD' && ((_a = c.field) === null || _a === void 0 ? void 0 : _a.aggregate); }))
2891
+ return null;
2892
+ return (index.h("tfoot", null, index.h("tr", { class: "mrd-table__totals-row" }, this.columns.map(col => {
2893
+ var _a, _b;
2894
+ const val = this.renderAggregationValue(col);
2895
+ const isNumeric = col.type === 'FIELD' && NUMERIC_TYPES.has((_b = (_a = col.field) === null || _a === void 0 ? void 0 : _a.dataType) !== null && _b !== void 0 ? _b : '');
2896
+ return (index.h("td", { class: `mrd-table__totals-cell${isNumeric ? ' mrd-table__totals-cell--numeric' : ''}` }, val));
2897
+ }))));
2898
+ }
2899
+ // ── Render ─────────────────────────────────────────────────────────────────
2900
+ render() {
2901
+ var _a, _b, _c;
2902
+ if (!((_a = this.columns) === null || _a === void 0 ? void 0 : _a.length))
2903
+ return null;
2904
+ // ── Non-paginated mode ──────────────────────────────────────────────────
2905
+ if (this.totalElements === 0) {
2906
+ return (index.h(index.Host, null, this.renderToolbar(), index.h("div", { class: "mrd-table" }, index.h("table", { class: "mrd-table__table" }, index.h("thead", null, index.h("tr", null, this.columns.map(col => {
2907
+ var _a, _b, _c, _d;
2908
+ const name = this.colName(col);
2909
+ const isFiltered = this.activeFilters.has(name);
2910
+ const cls = [
2911
+ 'mrd-table__header',
2912
+ isFiltered ? 'mrd-table__header--filtered' : '',
2913
+ this.filterMode ? 'mrd-table__header--sortable' : '',
2914
+ ].filter(Boolean).join(' ');
2915
+ return (index.h("th", { class: cls, onClick: this.filterMode ? (e) => this.handleFilterOpen(col, e) : undefined }, index.h("span", { class: "mrd-table__header-label" }, (_d = (_b = (_a = col.field) === null || _a === void 0 ? void 0 : _a.label) !== null && _b !== void 0 ? _b : (_c = col.relation) === null || _c === void 0 ? void 0 : _c.label) !== null && _d !== void 0 ? _d : ''), isFiltered && this.renderFilterIcon()));
2916
+ }))), index.h("tbody", null, (_b = this.rows) === null || _b === void 0 ? void 0 : _b.map((row, i) => (index.h("tr", { class: "mrd-table__row mrd-table__row--clickable", style: { background: i % 2 === 0 ? '' : 'var(--mrd-color-neutral-100)' }, onClick: () => this.mrdRowClick.emit(row) }, this.columns.map(col => this.renderCell(col, row)))))), this.renderTotalsRow()), (!this.rows || this.rows.length === 0) && (index.h("p", { class: "mrd-table__empty" }, t('no_results', this.locale)))), this.renderFooter((_c = this.rows) === null || _c === void 0 ? void 0 : _c.length), this.renderFilterPopup(), this.renderTextblockModal(), this.renderJsonModal()));
2917
+ }
2918
+ // ── Paginated / virtual-scroll mode ────────────────────────────────────
2919
+ // Derive the authoritative row count from loaded pages:
2920
+ // if any loaded page is shorter than pageSize it is the last page,
2921
+ // so the true total cannot exceed (pageNum * pageSize + pageRows.length).
2922
+ // This self-corrects without requiring the host to update totalElements.
2923
+ let effectiveTotal = this.totalElements;
2924
+ for (const [pageNum, pageRows] of this.loadedPages) {
2925
+ if (pageRows.length < this.pageSize) {
2926
+ effectiveTotal = Math.min(effectiveTotal, pageNum * this.pageSize + pageRows.length);
2927
+ }
2928
+ }
2929
+ // Clamp renderEnd to what we actually know exists (-1 when empty)
2930
+ const clampedEnd = Math.min(this.renderEnd, effectiveTotal - 1);
2931
+ const colCount = this.columns.length;
2932
+ const topSpacerHeight = this.renderStart * this.rowHeight;
2933
+ const bottomSpacerHeight = Math.max(0, (effectiveTotal - 1 - clampedEnd) * this.rowHeight);
2934
+ const tableStyle = this.colWidths.length > 0
2935
+ ? { tableLayout: 'fixed' }
2936
+ : undefined;
2937
+ const renderedRows = [];
2938
+ for (let i = this.renderStart; i <= clampedEnd; i++) {
2939
+ const row = this.getRow(i);
2940
+ if (row === null) {
2941
+ renderedRows.push(index.h("tr", { class: "mrd-table__row mrd-table__row--loading" }, index.h("td", { class: "mrd-table__cell--placeholder", colSpan: colCount }, index.h("span", { class: "mrd-table__placeholder-bar" }))));
2942
+ }
2943
+ else {
2944
+ renderedRows.push(index.h("tr", { class: "mrd-table__row mrd-table__row--clickable", style: { background: i % 2 === 0 ? '' : 'var(--mrd-color-neutral-100)' }, onClick: () => this.mrdRowClick.emit(row) }, this.columns.map(col => this.renderCell(col, row))));
2945
+ }
2946
+ }
2947
+ return (index.h(index.Host, null, this.renderToolbar(), index.h("div", { class: "mrd-table__scroll", style: { height: `${this.tableHeight}px` }, onScroll: this.handleScroll }, index.h("table", { class: "mrd-table__table", style: tableStyle }, index.h("thead", null, index.h("tr", null, this.columns.map((col, idx) => {
2948
+ var _a, _b, _c, _d;
2949
+ const name = this.colName(col);
2950
+ const isActive = this.sortField === name;
2951
+ const isFiltered = this.activeFilters.has(name);
2952
+ const isInteractive = !NON_INTERACTIVE_TYPES.has(this.colDataType(col));
2953
+ const cls = [
2954
+ 'mrd-table__header',
2955
+ isInteractive ? 'mrd-table__header--sortable' : '',
2956
+ isActive ? `mrd-table__header--sorted-${this.sortDir}` : '',
2957
+ isFiltered ? 'mrd-table__header--filtered' : '',
2958
+ ].filter(Boolean).join(' ');
2959
+ return (index.h("th", { class: cls, style: this.colWidths[idx] ? { width: `${this.colWidths[idx]}px` } : undefined, onClick: isInteractive ? ((e) => this.filterMode ? this.handleFilterOpen(col, e) : this.handleSortClick(col)) : undefined }, index.h("span", { class: "mrd-table__header-label" }, (_d = (_b = (_a = col.field) === null || _a === void 0 ? void 0 : _a.label) !== null && _b !== void 0 ? _b : (_c = col.relation) === null || _c === void 0 ? void 0 : _c.label) !== null && _d !== void 0 ? _d : ''), isInteractive && isActive && (index.h("span", { class: "mrd-table__sort-icon", "aria-hidden": "true" }, this.sortDir === 'asc' ? '▲' : '▼')), isInteractive && !isActive && !this.filterMode && (index.h("span", { class: "mrd-table__sort-icon", "aria-hidden": "true" }, "\u21C5")), isInteractive && isFiltered && this.renderFilterIcon()));
2960
+ }))), index.h("tbody", null, topSpacerHeight > 0 && (index.h("tr", { class: "mrd-table__spacer", style: { height: `${topSpacerHeight}px` } }, index.h("td", { colSpan: colCount }))), renderedRows, bottomSpacerHeight > 0 && (index.h("tr", { class: "mrd-table__spacer", style: { height: `${bottomSpacerHeight}px` } }, index.h("td", { colSpan: colCount })))), this.renderTotalsRow())), effectiveTotal === 0 && this.loadedPages.has(0) && (index.h("p", { class: "mrd-table__empty" }, t('no_results', this.locale))), effectiveTotal > 0 && this.renderFooter(undefined, effectiveTotal), this.renderFilterPopup(), this.renderTextblockModal()));
2961
+ }
2962
+ renderFilterIcon() {
2963
+ return (index.h("span", { class: "mrd-table__filter-icon", "aria-hidden": "true" }, index.h("svg", { viewBox: "0 0 24 24", width: "14", height: "14", fill: "currentColor" }, index.h("path", { d: "M10 18h4v-2h-4v2zM3 6v2h18V6H3zm3 7h12v-2H6v2z" }))));
2964
+ }
2965
+ renderTextblockModal() {
2966
+ if (this.textblockModal === null)
2967
+ return null;
2968
+ return (index.h("div", { class: "mrd-table__modal-backdrop", onClick: () => this.closeTextblockModal(), role: "dialog", "aria-modal": "true" }, index.h("div", { class: "mrd-table__modal", onClick: (e) => e.stopPropagation() }, index.h("button", { class: "mrd-table__modal-close", onClick: () => this.closeTextblockModal(), "aria-label": t('close', this.locale) }, "\u2715"), index.h("p", { class: "mrd-table__modal-text" }, this.textblockModal))));
2969
+ }
2970
+ renderJsonModal() {
2971
+ if (this.jsonModal === null)
2972
+ return null;
2973
+ return (index.h("div", { class: "mrd-table__modal-backdrop", onClick: () => this.closeJsonModal(), role: "dialog", "aria-modal": "true" }, index.h("div", { class: "mrd-table__modal", onClick: (e) => e.stopPropagation() }, index.h("button", { class: "mrd-table__modal-close", onClick: () => this.closeJsonModal(), "aria-label": t('close', this.locale) }, "\u2715"), index.h("pre", { class: "mrd-table__modal-json", innerHTML: this.jsonModal }))));
2974
+ }
2975
+ get el() { return index.getElement(this); }
2976
+ static get watchers() { return {
2977
+ "totalElements": [{
2978
+ "totalElementsChanged": 0
2979
+ }]
2980
+ }; }
2981
+ };
2982
+ MrdTable.style = mrdTableScss();
2983
+
2984
+ const mrdTextFieldScss = () => `.sc-mrd-text-field-h{display:block}.mrd-text-field.sc-mrd-text-field{display:flex;flex-direction:column;gap:var(--mrd-space-1);width:100%}.mrd-text-field__label.sc-mrd-text-field{display:block;font-family:var(--mrd-font-family);font-size:var(--mrd-label-font-size);font-weight:var(--mrd-label-font-weight);color:var(--mrd-label-color)}.mrd-text-field__label--required.sc-mrd-text-field::after{content:' *';color:var(--mrd-color-danger)}.mrd-text-field__input.sc-mrd-text-field{display:block;width:100%;height:var(--mrd-input-height);padding:var(--mrd-input-padding-y) var(--mrd-input-padding-x);font-family:var(--mrd-font-family);font-size:var(--mrd-font-size-base);color:var(--mrd-input-color);background-color:var(--mrd-input-bg);border:var(--mrd-border-width) solid var(--mrd-border-color);border-radius:var(--mrd-border-radius);transition:border-color var(--mrd-transition), box-shadow var(--mrd-transition);outline:none;appearance:none;box-sizing:border-box}.mrd-text-field__input.sc-mrd-text-field::placeholder{color:var(--mrd-input-placeholder-color)}.mrd-text-field__input.sc-mrd-text-field:focus{border-color:var(--mrd-border-color-focus);box-shadow:var(--mrd-shadow-focus)}.mrd-text-field__input.sc-mrd-text-field:disabled{background-color:var(--mrd-input-bg-disabled);cursor:not-allowed;opacity:0.7}.mrd-text-field__input--error.sc-mrd-text-field{border-color:var(--mrd-border-color-error)}.mrd-text-field__input--error.sc-mrd-text-field:focus{box-shadow:var(--mrd-shadow-focus-error)}.mrd-text-field__error.sc-mrd-text-field{font-family:var(--mrd-font-family);font-size:var(--mrd-error-font-size);color:var(--mrd-error-color)}`;
2985
+
2986
+ const MrdTextField = class {
2987
+ constructor(hostRef) {
2988
+ index.registerInstance(this, hostRef);
2989
+ this.mrdChange = index.createEvent(this, "mrdChange");
2990
+ this.mrdBlur = index.createEvent(this, "mrdBlur");
2991
+ this.name = '';
2992
+ this.label = '';
2993
+ this.value = '';
2994
+ this.placeholder = '';
2995
+ this.required = false;
2996
+ this.disabled = false;
2997
+ this.locale = navigator.language;
2998
+ this.error = '';
2999
+ this.handleInput = (e) => {
3000
+ const val = e.target.value;
3001
+ this.mrdChange.emit({ name: this.name, value: val });
3002
+ };
3003
+ this.handleBlur = (e) => {
3004
+ const val = e.target.value;
3005
+ if (this.required && !validateRequired(val)) {
3006
+ this.error = t('required', this.locale);
3007
+ }
3008
+ else {
3009
+ this.error = '';
3010
+ }
3011
+ this.mrdBlur.emit({ name: this.name, value: val });
3012
+ };
3013
+ }
3014
+ render() {
3015
+ const hasError = !!this.error;
3016
+ return (index.h(index.Host, { key: 'b1ea3dce848a4ad41b60599804c69a35ccd35570' }, index.h("div", { key: '2e327824843fe02c5851beae96d52f9eb9ee67ce', class: "mrd-text-field" }, this.label && (index.h("label", { key: '99026834b30a53d7cf715c59099895211ff6ddb7', class: `mrd-text-field__label${this.required ? ' mrd-text-field__label--required' : ''}` }, this.label)), index.h("input", { key: '0e56c9115b2016ad3cb3ce8e734297354c70c7e2', class: `mrd-text-field__input${hasError ? ' mrd-text-field__input--error' : ''}`, type: "text", name: this.name, value: this.value, placeholder: this.placeholder, required: this.required, disabled: this.disabled, onInput: this.handleInput, onBlur: this.handleBlur }), hasError && index.h("span", { key: '0430c32b083484747962147e167b11ed7a1597cc', class: "mrd-text-field__error" }, this.error))));
3017
+ }
3018
+ };
3019
+ MrdTextField.style = mrdTextFieldScss();
3020
+
3021
+ const mrdTextareaFieldScss = () => `.sc-mrd-textarea-field-h{display:block}.mrd-textarea-field.sc-mrd-textarea-field{display:flex;flex-direction:column;gap:var(--mrd-space-1);width:100%}.mrd-textarea-field__label.sc-mrd-textarea-field{display:block;font-family:var(--mrd-font-family);font-size:var(--mrd-label-font-size);font-weight:var(--mrd-label-font-weight);color:var(--mrd-label-color)}.mrd-textarea-field__label--required.sc-mrd-textarea-field::after{content:' *';color:var(--mrd-color-danger)}.mrd-textarea-field__container.sc-mrd-textarea-field{border:var(--mrd-border-width) solid var(--mrd-border-color);border-radius:var(--mrd-border-radius);overflow:hidden;background-color:var(--mrd-input-bg);transition:border-color var(--mrd-transition), box-shadow var(--mrd-transition)}.mrd-textarea-field__container.sc-mrd-textarea-field:focus-within{border-color:var(--mrd-border-color-focus);box-shadow:var(--mrd-shadow-focus)}.mrd-textarea-field__container--error.sc-mrd-textarea-field{border-color:var(--mrd-border-color-error)}.mrd-textarea-field__container--error.sc-mrd-textarea-field:focus-within{box-shadow:var(--mrd-shadow-focus-error)}.mrd-textarea-field__editor.sc-mrd-textarea-field{min-height:150px;font-family:var(--mrd-font-family);font-size:var(--mrd-font-size-base)}.mrd-textarea-field__editor.sc-mrd-textarea-field .ql-toolbar.sc-mrd-textarea-field{border:none;border-bottom:var(--mrd-border-width) solid var(--mrd-border-color);font-family:var(--mrd-font-family)}.mrd-textarea-field__editor.sc-mrd-textarea-field .ql-container.sc-mrd-textarea-field{border:none;font-family:var(--mrd-font-family);font-size:var(--mrd-font-size-base)}.mrd-textarea-field__editor.sc-mrd-textarea-field .ql-editor.sc-mrd-textarea-field{min-height:120px;padding:var(--mrd-input-padding-y) var(--mrd-input-padding-x)}.mrd-textarea-field__editor.sc-mrd-textarea-field .ql-editor.ql-blank.sc-mrd-textarea-field::before{color:var(--mrd-input-placeholder-color);font-style:normal}.mrd-textarea-field__error.sc-mrd-textarea-field{font-family:var(--mrd-font-family);font-size:var(--mrd-error-font-size);color:var(--mrd-error-color)}`;
3022
+
3023
+ const MrdTextareaField = class {
3024
+ constructor(hostRef) {
3025
+ index.registerInstance(this, hostRef);
3026
+ this.mrdChange = index.createEvent(this, "mrdChange");
3027
+ this.mrdBlur = index.createEvent(this, "mrdBlur");
3028
+ this.name = '';
3029
+ this.label = '';
3030
+ this.value = '';
3031
+ this.placeholder = '';
3032
+ this.required = false;
3033
+ this.disabled = false;
3034
+ this.locale = navigator.language;
3035
+ this.error = '';
3036
+ this.editorReady = false;
3037
+ }
3038
+ componentDidLoad() {
3039
+ this.initQuill();
3040
+ }
3041
+ async initQuill() {
3042
+ try {
3043
+ // Dynamically import Quill
3044
+ const Quill = (await Promise.resolve().then(function () { return require('./quill-DmFfnC1f.js'); })).default;
3045
+ this.editorEl = this.el.querySelector('.mrd-textarea-field__editor');
3046
+ if (!this.editorEl)
3047
+ return;
3048
+ const quill = new Quill(this.editorEl, {
3049
+ theme: 'snow',
3050
+ placeholder: this.placeholder,
3051
+ readOnly: this.disabled,
3052
+ modules: {
3053
+ toolbar: [
3054
+ ['bold', 'italic', 'underline', 'strike'],
3055
+ [{ list: 'ordered' }, { list: 'bullet' }],
3056
+ [{ header: [1, 2, 3, false] }],
3057
+ ['link'],
3058
+ ['clean'],
3059
+ ],
3060
+ },
3061
+ });
3062
+ if (this.value) {
3063
+ quill.clipboard.dangerouslyPasteHTML(this.value);
3064
+ }
3065
+ quill.on('text-change', () => {
3066
+ var _a, _b;
3067
+ const html = (_b = (_a = this.editorEl.querySelector('.ql-editor')) === null || _a === void 0 ? void 0 : _a.innerHTML) !== null && _b !== void 0 ? _b : '';
3068
+ this.mrdChange.emit({ name: this.name, value: html });
3069
+ });
3070
+ quill.on('selection-change', (range) => {
3071
+ var _a, _b;
3072
+ if (!range) {
3073
+ const html = (_b = (_a = this.editorEl.querySelector('.ql-editor')) === null || _a === void 0 ? void 0 : _a.innerHTML) !== null && _b !== void 0 ? _b : '';
3074
+ if (this.required && !validateRequired(html)) {
3075
+ this.error = t('required', this.locale);
3076
+ }
3077
+ else {
3078
+ this.error = '';
3079
+ }
3080
+ this.mrdBlur.emit({ name: this.name, value: html });
3081
+ }
3082
+ });
3083
+ this.editorReady = true;
3084
+ }
3085
+ catch (err) {
3086
+ console.error('Failed to load Quill editor:', err);
3087
+ }
3088
+ }
3089
+ render() {
3090
+ return (index.h(index.Host, { key: '7bc05fae8d48c43b56bde892537930552605727a' }, index.h("div", { key: '3416e9c5fdf6362602715de8427c5d2ccfa52925', class: "mrd-textarea-field" }, this.label && (index.h("label", { key: 'c6bd35076738b1a700b53092fb0754250c73e085', class: `mrd-textarea-field__label${this.required ? ' mrd-textarea-field__label--required' : ''}` }, this.label)), index.h("div", { key: 'ed0483a25a62399d1ac8ee14bc59e3eb44b91814', class: `mrd-textarea-field__container${this.error ? ' mrd-textarea-field__container--error' : ''}` }, index.h("div", { key: 'd17c6997602b81e8b7f66f1e5cfb12b4836cb892', class: "mrd-textarea-field__editor" })), this.error && index.h("span", { key: '30a068872e73ca78781c9a5e1fac2c9e3ce30765', class: "mrd-textarea-field__error" }, this.error))));
3091
+ }
3092
+ get el() { return index.getElement(this); }
3093
+ };
3094
+ MrdTextareaField.style = mrdTextareaFieldScss();
3095
+
3096
+ const mrdTimeFieldScss = () => `.sc-mrd-time-field-h{display:block}.mrd-time-field.sc-mrd-time-field{display:flex;flex-direction:column;gap:var(--mrd-space-1);width:100%}.mrd-time-field__label.sc-mrd-time-field{display:block;font-family:var(--mrd-font-family);font-size:var(--mrd-label-font-size);font-weight:var(--mrd-label-font-weight);color:var(--mrd-label-color)}.mrd-time-field__label--required.sc-mrd-time-field::after{content:' *';color:var(--mrd-color-danger)}.mrd-time-field__input.sc-mrd-time-field{display:block;width:100%;height:var(--mrd-input-height);padding:var(--mrd-input-padding-y) var(--mrd-input-padding-x);font-family:var(--mrd-font-family);font-size:var(--mrd-font-size-base);color:var(--mrd-input-color);background-color:var(--mrd-input-bg);border:var(--mrd-border-width) solid var(--mrd-border-color);border-radius:var(--mrd-border-radius);transition:border-color var(--mrd-transition), box-shadow var(--mrd-transition);outline:none;appearance:none;box-sizing:border-box;cursor:pointer}.mrd-time-field__input.sc-mrd-time-field:focus{border-color:var(--mrd-border-color-focus);box-shadow:var(--mrd-shadow-focus)}.mrd-time-field__input.sc-mrd-time-field:disabled{background-color:var(--mrd-input-bg-disabled);cursor:not-allowed;opacity:0.7}.mrd-time-field__input--error.sc-mrd-time-field{border-color:var(--mrd-border-color-error)}.mrd-time-field__input--error.sc-mrd-time-field:focus{box-shadow:var(--mrd-shadow-focus-error)}.mrd-time-field__error.sc-mrd-time-field{font-family:var(--mrd-font-family);font-size:var(--mrd-error-font-size);color:var(--mrd-error-color)}`;
3097
+
3098
+ const MrdTimeField = class {
3099
+ constructor(hostRef) {
3100
+ index.registerInstance(this, hostRef);
3101
+ this.mrdChange = index.createEvent(this, "mrdChange");
3102
+ this.mrdBlur = index.createEvent(this, "mrdBlur");
3103
+ this.name = '';
3104
+ this.label = '';
3105
+ this.value = '';
3106
+ this.required = false;
3107
+ this.disabled = false;
3108
+ this.locale = navigator.language;
3109
+ this.error = '';
3110
+ this.handleChange = (e) => {
3111
+ const val = e.target.value;
3112
+ if (this.required && !validateRequired(val)) {
3113
+ this.error = t('required', this.locale);
3114
+ }
3115
+ else {
3116
+ this.error = '';
3117
+ }
3118
+ this.mrdChange.emit({ name: this.name, value: val });
3119
+ };
3120
+ this.handleBlur = (e) => {
3121
+ const val = e.target.value;
3122
+ this.mrdBlur.emit({ name: this.name, value: val });
3123
+ };
3124
+ }
3125
+ render() {
3126
+ const hasError = !!this.error;
3127
+ return (index.h(index.Host, { key: '6a6828d9c5224ddfcc5d17124523037512f4970c' }, index.h("div", { key: '468d5295170cefc93b1e2d49b7189c8366d306b7', class: "mrd-time-field" }, this.label && (index.h("label", { key: '52ea233ea0a7e8563145c326c4ef9d27557b6dc8', class: `mrd-time-field__label${this.required ? ' mrd-time-field__label--required' : ''}` }, this.label)), index.h("input", { key: 'e9f0f75517638bf4e4ead95bf69530b5c395f8bc', class: `mrd-time-field__input${hasError ? ' mrd-time-field__input--error' : ''}`, type: "time", name: this.name, value: this.value, required: this.required, disabled: this.disabled, onChange: this.handleChange, onBlur: this.handleBlur }), hasError && index.h("span", { key: '4f734c3373444df4f686a7ae6bde84a2ee39d9f4', class: "mrd-time-field__error" }, this.error))));
3128
+ }
3129
+ };
3130
+ MrdTimeField.style = mrdTimeFieldScss();
3131
+
3132
+ exports.mrd_boolean_field = MrdBooleanField;
3133
+ exports.mrd_currency_field = MrdCurrencyField;
3134
+ exports.mrd_date_field = MrdDateField;
3135
+ exports.mrd_datetime_field = MrdDatetimeField;
3136
+ exports.mrd_email_field = MrdEmailField;
3137
+ exports.mrd_field = MrdField;
3138
+ exports.mrd_file_field = MrdFileField;
3139
+ exports.mrd_form = MrdForm;
3140
+ exports.mrd_hyperlink_field = MrdHyperlinkField;
3141
+ exports.mrd_image_field = MrdImageField;
3142
+ exports.mrd_layout_section = MrdLayoutSection;
3143
+ exports.mrd_list_field = MrdListField;
3144
+ exports.mrd_longtext_field = MrdLongtextField;
3145
+ exports.mrd_number_field = MrdNumberField;
3146
+ exports.mrd_relation_field = MrdRelationField;
3147
+ exports.mrd_table = MrdTable;
3148
+ exports.mrd_text_field = MrdTextField;
3149
+ exports.mrd_textarea_field = MrdTextareaField;
3150
+ exports.mrd_time_field = MrdTimeField;