@isaiahiroko/tilmart-ngx-apps-admin 0.2.12 → 0.2.14

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 (89) hide show
  1. package/fesm2022/isaiahiroko-tilmart-ngx-apps-admin-banners.module-sbSJXda_.mjs +92 -0
  2. package/fesm2022/isaiahiroko-tilmart-ngx-apps-admin-banners.module-sbSJXda_.mjs.map +1 -0
  3. package/fesm2022/isaiahiroko-tilmart-ngx-apps-admin-brands.module-EooAWVy_.mjs +73 -0
  4. package/fesm2022/isaiahiroko-tilmart-ngx-apps-admin-brands.module-EooAWVy_.mjs.map +1 -0
  5. package/fesm2022/isaiahiroko-tilmart-ngx-apps-admin-catalog.module-CnS35rup.mjs +605 -0
  6. package/fesm2022/isaiahiroko-tilmart-ngx-apps-admin-catalog.module-CnS35rup.mjs.map +1 -0
  7. package/fesm2022/isaiahiroko-tilmart-ngx-apps-admin-categories.module-u5VyaNWX.mjs +97 -0
  8. package/fesm2022/isaiahiroko-tilmart-ngx-apps-admin-categories.module-u5VyaNWX.mjs.map +1 -0
  9. package/fesm2022/{isaiahiroko-tilmart-ngx-apps-admin-claims.module-Dk9mz7Wj.mjs → isaiahiroko-tilmart-ngx-apps-admin-claims.module-CLtalsnJ.mjs} +3 -3
  10. package/fesm2022/isaiahiroko-tilmart-ngx-apps-admin-claims.module-CLtalsnJ.mjs.map +1 -0
  11. package/fesm2022/isaiahiroko-tilmart-ngx-apps-admin-coupons.module-BCkLIQta.mjs +88 -0
  12. package/fesm2022/isaiahiroko-tilmart-ngx-apps-admin-coupons.module-BCkLIQta.mjs.map +1 -0
  13. package/fesm2022/{isaiahiroko-tilmart-ngx-apps-admin-customers.module-CslGiOdq.mjs → isaiahiroko-tilmart-ngx-apps-admin-customers.module-BohEH2SB.mjs} +2 -2
  14. package/fesm2022/{isaiahiroko-tilmart-ngx-apps-admin-customers.module-CslGiOdq.mjs.map → isaiahiroko-tilmart-ngx-apps-admin-customers.module-BohEH2SB.mjs.map} +1 -1
  15. package/fesm2022/isaiahiroko-tilmart-ngx-apps-admin-flash-sales.module-z6apTF3A.mjs +86 -0
  16. package/fesm2022/isaiahiroko-tilmart-ngx-apps-admin-flash-sales.module-z6apTF3A.mjs.map +1 -0
  17. package/fesm2022/{isaiahiroko-tilmart-ngx-apps-admin-installation-requests.module-TryMzSXT.mjs → isaiahiroko-tilmart-ngx-apps-admin-installation-requests.module-Dnh9hEz_.mjs} +3 -3
  18. package/fesm2022/isaiahiroko-tilmart-ngx-apps-admin-installation-requests.module-Dnh9hEz_.mjs.map +1 -0
  19. package/fesm2022/isaiahiroko-tilmart-ngx-apps-admin-json-builder.component-BFroIYk9.mjs +1579 -0
  20. package/fesm2022/isaiahiroko-tilmart-ngx-apps-admin-json-builder.component-BFroIYk9.mjs.map +1 -0
  21. package/fesm2022/{isaiahiroko-tilmart-ngx-apps-admin-list-page.base-Cl7JZ-Tp.mjs → isaiahiroko-tilmart-ngx-apps-admin-list-page.base-ChfiBo_X.mjs} +29 -5
  22. package/fesm2022/isaiahiroko-tilmart-ngx-apps-admin-list-page.base-ChfiBo_X.mjs.map +1 -0
  23. package/fesm2022/isaiahiroko-tilmart-ngx-apps-admin-orders.module-aIW0jRhm.mjs +239 -0
  24. package/fesm2022/isaiahiroko-tilmart-ngx-apps-admin-orders.module-aIW0jRhm.mjs.map +1 -0
  25. package/fesm2022/isaiahiroko-tilmart-ngx-apps-admin-overview.module-C6gjcJ84.mjs +105 -0
  26. package/fesm2022/isaiahiroko-tilmart-ngx-apps-admin-overview.module-C6gjcJ84.mjs.map +1 -0
  27. package/fesm2022/{isaiahiroko-tilmart-ngx-apps-admin-payments.module-DstLDYM7.mjs → isaiahiroko-tilmart-ngx-apps-admin-payments.module-Bej9cdwM.mjs} +3 -3
  28. package/fesm2022/isaiahiroko-tilmart-ngx-apps-admin-payments.module-Bej9cdwM.mjs.map +1 -0
  29. package/fesm2022/isaiahiroko-tilmart-ngx-apps-admin-promotions.module-Dh7PTGG7.mjs +88 -0
  30. package/fesm2022/isaiahiroko-tilmart-ngx-apps-admin-promotions.module-Dh7PTGG7.mjs.map +1 -0
  31. package/fesm2022/isaiahiroko-tilmart-ngx-apps-admin-redirects.module-B8gaByYE.mjs +81 -0
  32. package/fesm2022/isaiahiroko-tilmart-ngx-apps-admin-redirects.module-B8gaByYE.mjs.map +1 -0
  33. package/fesm2022/{isaiahiroko-tilmart-ngx-apps-admin-referrals.module-BIAY4L_u.mjs → isaiahiroko-tilmart-ngx-apps-admin-referrals.module-7OLTrySw.mjs} +3 -3
  34. package/fesm2022/isaiahiroko-tilmart-ngx-apps-admin-referrals.module-7OLTrySw.mjs.map +1 -0
  35. package/fesm2022/isaiahiroko-tilmart-ngx-apps-admin-reports.module-fjoFzY6t.mjs +137 -0
  36. package/fesm2022/isaiahiroko-tilmart-ngx-apps-admin-reports.module-fjoFzY6t.mjs.map +1 -0
  37. package/fesm2022/{isaiahiroko-tilmart-ngx-apps-admin-returns.module-C9Iu9CX6.mjs → isaiahiroko-tilmart-ngx-apps-admin-returns.module-D0RKEzAr.mjs} +3 -3
  38. package/fesm2022/isaiahiroko-tilmart-ngx-apps-admin-returns.module-D0RKEzAr.mjs.map +1 -0
  39. package/fesm2022/isaiahiroko-tilmart-ngx-apps-admin-routes.module-BWZ9OBPH.mjs +84 -0
  40. package/fesm2022/isaiahiroko-tilmart-ngx-apps-admin-routes.module-BWZ9OBPH.mjs.map +1 -0
  41. package/fesm2022/{isaiahiroko-tilmart-ngx-apps-admin-settings.module-D8HLxbUb.mjs → isaiahiroko-tilmart-ngx-apps-admin-settings.module-DZWUhyJg.mjs} +14 -7
  42. package/fesm2022/isaiahiroko-tilmart-ngx-apps-admin-settings.module-DZWUhyJg.mjs.map +1 -0
  43. package/fesm2022/{isaiahiroko-tilmart-ngx-apps-admin-shipments.module-CWXgE2E_.mjs → isaiahiroko-tilmart-ngx-apps-admin-shipments.module-BG9DCmG-.mjs} +3 -3
  44. package/fesm2022/isaiahiroko-tilmart-ngx-apps-admin-shipments.module-BG9DCmG-.mjs.map +1 -0
  45. package/fesm2022/{isaiahiroko-tilmart-ngx-apps-admin-staff.module-YjJJe00X.mjs → isaiahiroko-tilmart-ngx-apps-admin-staff.module-Br80U5_k.mjs} +2 -2
  46. package/fesm2022/{isaiahiroko-tilmart-ngx-apps-admin-staff.module-YjJJe00X.mjs.map → isaiahiroko-tilmart-ngx-apps-admin-staff.module-Br80U5_k.mjs.map} +1 -1
  47. package/fesm2022/isaiahiroko-tilmart-ngx-apps-admin-status-badge-AXfNPKaS.mjs +66 -0
  48. package/fesm2022/isaiahiroko-tilmart-ngx-apps-admin-status-badge-AXfNPKaS.mjs.map +1 -0
  49. package/fesm2022/isaiahiroko-tilmart-ngx-apps-admin-stock.module-BFbm7118.mjs +178 -0
  50. package/fesm2022/isaiahiroko-tilmart-ngx-apps-admin-stock.module-BFbm7118.mjs.map +1 -0
  51. package/fesm2022/{isaiahiroko-tilmart-ngx-apps-admin-users.module-C31RJJJ_.mjs → isaiahiroko-tilmart-ngx-apps-admin-users.module-C8nNzJ5X.mjs} +2 -2
  52. package/fesm2022/{isaiahiroko-tilmart-ngx-apps-admin-users.module-C31RJJJ_.mjs.map → isaiahiroko-tilmart-ngx-apps-admin-users.module-C8nNzJ5X.mjs.map} +1 -1
  53. package/fesm2022/isaiahiroko-tilmart-ngx-apps-admin.mjs +56 -46
  54. package/fesm2022/isaiahiroko-tilmart-ngx-apps-admin.mjs.map +1 -1
  55. package/package.json +1 -1
  56. package/fesm2022/isaiahiroko-tilmart-ngx-apps-admin-banners.module-ClIiV2uK.mjs +0 -76
  57. package/fesm2022/isaiahiroko-tilmart-ngx-apps-admin-banners.module-ClIiV2uK.mjs.map +0 -1
  58. package/fesm2022/isaiahiroko-tilmart-ngx-apps-admin-brands.module-CSp0tWes.mjs +0 -70
  59. package/fesm2022/isaiahiroko-tilmart-ngx-apps-admin-brands.module-CSp0tWes.mjs.map +0 -1
  60. package/fesm2022/isaiahiroko-tilmart-ngx-apps-admin-catalog.module-BwjfFXDU.mjs +0 -562
  61. package/fesm2022/isaiahiroko-tilmart-ngx-apps-admin-catalog.module-BwjfFXDU.mjs.map +0 -1
  62. package/fesm2022/isaiahiroko-tilmart-ngx-apps-admin-categories.module-uKkUREjb.mjs +0 -94
  63. package/fesm2022/isaiahiroko-tilmart-ngx-apps-admin-categories.module-uKkUREjb.mjs.map +0 -1
  64. package/fesm2022/isaiahiroko-tilmart-ngx-apps-admin-claims.module-Dk9mz7Wj.mjs.map +0 -1
  65. package/fesm2022/isaiahiroko-tilmart-ngx-apps-admin-coupons.module-Dcu1nJBW.mjs +0 -85
  66. package/fesm2022/isaiahiroko-tilmart-ngx-apps-admin-coupons.module-Dcu1nJBW.mjs.map +0 -1
  67. package/fesm2022/isaiahiroko-tilmart-ngx-apps-admin-flash-sales.module-DF7iSJaN.mjs +0 -83
  68. package/fesm2022/isaiahiroko-tilmart-ngx-apps-admin-flash-sales.module-DF7iSJaN.mjs.map +0 -1
  69. package/fesm2022/isaiahiroko-tilmart-ngx-apps-admin-installation-requests.module-TryMzSXT.mjs.map +0 -1
  70. package/fesm2022/isaiahiroko-tilmart-ngx-apps-admin-list-page.base-Cl7JZ-Tp.mjs.map +0 -1
  71. package/fesm2022/isaiahiroko-tilmart-ngx-apps-admin-orders.module-vldWwcAr.mjs +0 -190
  72. package/fesm2022/isaiahiroko-tilmart-ngx-apps-admin-orders.module-vldWwcAr.mjs.map +0 -1
  73. package/fesm2022/isaiahiroko-tilmart-ngx-apps-admin-payments.module-DstLDYM7.mjs.map +0 -1
  74. package/fesm2022/isaiahiroko-tilmart-ngx-apps-admin-promotions.module-BO4zRytg.mjs +0 -94
  75. package/fesm2022/isaiahiroko-tilmart-ngx-apps-admin-promotions.module-BO4zRytg.mjs.map +0 -1
  76. package/fesm2022/isaiahiroko-tilmart-ngx-apps-admin-redirects.module-D8H6ujoy.mjs +0 -78
  77. package/fesm2022/isaiahiroko-tilmart-ngx-apps-admin-redirects.module-D8H6ujoy.mjs.map +0 -1
  78. package/fesm2022/isaiahiroko-tilmart-ngx-apps-admin-referrals.module-BIAY4L_u.mjs.map +0 -1
  79. package/fesm2022/isaiahiroko-tilmart-ngx-apps-admin-reports.module-DORiIVLQ.mjs +0 -104
  80. package/fesm2022/isaiahiroko-tilmart-ngx-apps-admin-reports.module-DORiIVLQ.mjs.map +0 -1
  81. package/fesm2022/isaiahiroko-tilmart-ngx-apps-admin-returns.module-C9Iu9CX6.mjs.map +0 -1
  82. package/fesm2022/isaiahiroko-tilmart-ngx-apps-admin-routes.module-fYKd3AOq.mjs +0 -81
  83. package/fesm2022/isaiahiroko-tilmart-ngx-apps-admin-routes.module-fYKd3AOq.mjs.map +0 -1
  84. package/fesm2022/isaiahiroko-tilmart-ngx-apps-admin-settings.module-D8HLxbUb.mjs.map +0 -1
  85. package/fesm2022/isaiahiroko-tilmart-ngx-apps-admin-shipments.module-CWXgE2E_.mjs.map +0 -1
  86. package/fesm2022/isaiahiroko-tilmart-ngx-apps-admin-simple-crud.base-C8SPw14H.mjs +0 -140
  87. package/fesm2022/isaiahiroko-tilmart-ngx-apps-admin-simple-crud.base-C8SPw14H.mjs.map +0 -1
  88. package/fesm2022/isaiahiroko-tilmart-ngx-apps-admin-stock.module-BSAe0CfZ.mjs +0 -102
  89. package/fesm2022/isaiahiroko-tilmart-ngx-apps-admin-stock.module-BSAe0CfZ.mjs.map +0 -1
@@ -0,0 +1,1579 @@
1
+ import { notify, titleCase, ApiService } from '@thescaffold/ngx-core';
2
+ import { firstValueFrom } from 'rxjs';
3
+ import { L as ListPageDirective } from './isaiahiroko-tilmart-ngx-apps-admin-list-page.base-ChfiBo_X.mjs';
4
+ import * as i0 from '@angular/core';
5
+ import { inject, Injectable, EventEmitter, Output, Input, Component } from '@angular/core';
6
+ import * as i1 from '@angular/forms';
7
+ import { FormsModule } from '@angular/forms';
8
+
9
+ /** Value of the "Other…" choice in an `allowCustom` select (never saved). */
10
+ const CUSTOM_OPTION = '__custom__';
11
+ /** The starting value for a field: false for a checkbox, `{}`/`[]` for a builder, else blank. */
12
+ function emptyValueFor(field) {
13
+ if (field.type === 'boolean')
14
+ return false;
15
+ if (field.type === 'builder')
16
+ return field.builder === 'actions' || field.builder === 'rateRules' ? [] : {};
17
+ return '';
18
+ }
19
+ // R1 production-readiness pass. Every small config-table resource in the
20
+ // PRD's back-office map (brands, coupons, promotions, redirects, routes,
21
+ // banners, flash sales, channels, shipping zones/methods, return
22
+ // policies, …) was shipped list-only by P7.1 — ops could see the rows
23
+ // but never create or edit one. Rebuilding each as its own bespoke
24
+ // editor (the Catalog page's approach) would be 10+ near-identical
25
+ // files; this shared base + its one template
26
+ // (`simple-crud.component.html`) render a plain field-by-field form
27
+ // driven by a `CrudFieldSpec[]`, so a concrete page is just its resource
28
+ // mount + column/field lists. Pages with real bespoke workflows (order
29
+ // transitions, shipment dispatch, warranty triage) still hand-roll their
30
+ // own — this is only for the "name/code/a few flags" shape.
31
+ class SimpleCrudDirective extends ListPageDirective {
32
+ constructor() {
33
+ super(...arguments);
34
+ // Set true when the resource has no `remove` support worth exposing
35
+ // (e.g. rows other records reference by id).
36
+ this.hideDelete = false;
37
+ this.editing = false;
38
+ this.saving = false;
39
+ this.draft = null;
40
+ // Dynamic option lists referenced by a field's `optionsKey` — set by a
41
+ // subclass's `init` override before calling `super.init` isn't
42
+ // possible (arrow field, not a method), so subclasses instead load
43
+ // these in their own `init` and re-set `this.dynamicOptions` whenever
44
+ // ready; the template re-reads it on every render.
45
+ this.dynamicOptions = {};
46
+ this.customOption = CUSTOM_OPTION;
47
+ // `allowCustom` selects whose "Other…" box the person opened this edit.
48
+ this.customOpen = {};
49
+ }
50
+ extraCollectionFields() {
51
+ return {
52
+ links: {
53
+ secondary: [{ title: 'Edit', fn: (_link, item) => this.edit(item) }],
54
+ },
55
+ };
56
+ }
57
+ /** What an `allowCustom` select shows: the listed value, or "Other…". */
58
+ selectValue(f) {
59
+ const v = this.draft?.[f.key] ?? '';
60
+ if (!f.allowCustom)
61
+ return v;
62
+ if (this.customOpen[f.key])
63
+ return CUSTOM_OPTION;
64
+ return v && !this.optionsFor(f).some((o) => o.value === v) ? CUSTOM_OPTION : v;
65
+ }
66
+ onSelect(f, value) {
67
+ if (!this.draft)
68
+ return;
69
+ if (f.allowCustom && value === CUSTOM_OPTION) {
70
+ this.customOpen[f.key] = true;
71
+ // keep what was typed/selected so switching to Other… isn't destructive
72
+ if (this.optionsFor(f).some((o) => o.value === this.draft[f.key]))
73
+ this.draft[f.key] = '';
74
+ }
75
+ else {
76
+ this.customOpen[f.key] = false;
77
+ this.draft[f.key] = value;
78
+ }
79
+ }
80
+ optionsFor(f) {
81
+ return (f.optionsKey ? this.dynamicOptions[f.optionsKey] : f.options) ?? [];
82
+ }
83
+ startCreate() {
84
+ this.customOpen = {};
85
+ this.editing = true;
86
+ this.draft = this.emptyDraft();
87
+ }
88
+ edit(item) {
89
+ this.customOpen = {};
90
+ this.editing = true;
91
+ const draft = { ...item };
92
+ // The API returns `json`-type fields already parsed (an object/
93
+ // array); the textarea needs the printed form back, or Angular
94
+ // stringifies it as `[object Object]`.
95
+ for (const field of this.fields) {
96
+ if (field.type === 'json' && draft[field.key] != null && typeof draft[field.key] !== 'string') {
97
+ draft[field.key] = JSON.stringify(draft[field.key], null, 2);
98
+ }
99
+ }
100
+ this.draft = draft;
101
+ }
102
+ cancelEdit() {
103
+ this.editing = false;
104
+ this.draft = null;
105
+ }
106
+ emptyDraft() {
107
+ const draft = {};
108
+ for (const field of this.fields) {
109
+ draft[field.key] = emptyValueFor(field);
110
+ }
111
+ return draft;
112
+ }
113
+ async save() {
114
+ if (!this.draft)
115
+ return;
116
+ this.saving = true;
117
+ try {
118
+ const payload = this.buildPayload();
119
+ if (this.draft['id']) {
120
+ await firstValueFrom(this.dataSource.update(this.draft['id'], payload));
121
+ }
122
+ else {
123
+ await firstValueFrom(this.dataSource.create(payload));
124
+ }
125
+ notify(`${titleCase(this.pluralName)} saved.`, undefined, 'success');
126
+ this.editing = false;
127
+ this.draft = null;
128
+ this.list(this.page, this.perPage, this.query);
129
+ }
130
+ catch {
131
+ notify(`Could not save (check required fields).`, undefined, 'error');
132
+ }
133
+ finally {
134
+ this.saving = false;
135
+ }
136
+ }
137
+ async remove(item) {
138
+ try {
139
+ await firstValueFrom(this.dataSource.remove(item.id));
140
+ notify(`${titleCase(this.pluralName)} deleted.`, undefined, 'success');
141
+ this.list(this.page, this.perPage, this.query);
142
+ }
143
+ catch {
144
+ notify(`Could not delete — it may still be referenced elsewhere.`, undefined, 'error');
145
+ }
146
+ }
147
+ buildPayload() {
148
+ if (!this.draft)
149
+ return {};
150
+ const payload = {};
151
+ for (const field of this.fields) {
152
+ const raw = this.draft[field.key];
153
+ switch (field.type) {
154
+ case 'number':
155
+ payload[field.key] = raw !== null && raw !== undefined && `${raw}` !== '' ? Number(raw) : undefined;
156
+ break;
157
+ case 'select':
158
+ if (field.numericSelect) {
159
+ payload[field.key] = raw !== null && raw !== undefined && `${raw}` !== '' ? Number(raw) : undefined;
160
+ }
161
+ else {
162
+ payload[field.key] = raw || undefined;
163
+ }
164
+ break;
165
+ case 'boolean':
166
+ payload[field.key] = !!raw;
167
+ break;
168
+ case 'builder':
169
+ // Sent even when empty ({} / []) so clearing a field really clears it.
170
+ payload[field.key] = raw ?? emptyValueFor(field);
171
+ break;
172
+ case 'json':
173
+ try {
174
+ payload[field.key] = raw && `${raw}`.trim() ? JSON.parse(raw) : undefined;
175
+ }
176
+ catch {
177
+ payload[field.key] = undefined;
178
+ }
179
+ break;
180
+ default:
181
+ payload[field.key] = raw || undefined;
182
+ }
183
+ }
184
+ return payload;
185
+ }
186
+ }
187
+
188
+ // Shared look for the point-and-click rule builders.
189
+ const BUILDER_STYLES = `
190
+ :host { display: block; }
191
+ .rb { display: flex; flex-direction: column; gap: 12px; }
192
+ .rb-group { display: flex; flex-direction: column; gap: 4px; }
193
+ .rb-label { font-size: 11.5px; font-weight: 700; color: var(--color-text-muted); }
194
+ .rb-help { font-size: 12px; font-weight: 400; color: var(--color-text-muted); }
195
+ .rb-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
196
+ .rb-summary { font-size: 12.5px; color: var(--color-text); background: color-mix(in srgb, var(--color-accent, #0b3a82) 8%, transparent); border-radius: var(--radius-md, 8px); padding: 7px 10px; }
197
+ .rb-input { padding: 6px 10px; border: 1px solid var(--color-border); border-radius: var(--radius-md, 8px); background: transparent; color: inherit; font: inherit; font-size: 13px; min-width: 0; }
198
+ .rb-input-sm { width: 110px; }
199
+ .rb-check { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; color: var(--color-text); cursor: pointer; }
200
+ .rb-btn { appearance: none; border: 1px solid var(--color-border); background: transparent; border-radius: var(--radius-md, 8px); padding: 5px 12px; font-size: 12.5px; font-weight: 700; cursor: pointer; color: var(--color-text-muted); }
201
+ .rb-btn:disabled { opacity: 0.45; cursor: default; }
202
+ .rb-btn-primary { border-color: var(--color-accent); color: var(--color-accent-hover, #0b3a82); }
203
+ .rb-link { appearance: none; background: none; border: 0; padding: 2px 4px; font-size: 12.5px; font-weight: 700; color: var(--color-accent-hover, #0b3a82); cursor: pointer; }
204
+ .rb-link:disabled { opacity: 0.4; cursor: default; }
205
+ .rb-danger { color: var(--color-danger, #c0362c); }
206
+ .rb-card { border: 1px solid var(--color-border); border-radius: var(--radius-md, 8px); padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; }
207
+ .rb-card-head { display: flex; gap: 8px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
208
+ .rb-problem { font-size: 12px; font-weight: 600; color: var(--color-danger, #c0362c); }
209
+ .rb-field { display: flex; flex-direction: column; gap: 3px; font-size: 11.5px; font-weight: 700; color: var(--color-text-muted); }
210
+ .rb-empty { font-size: 13px; color: var(--color-text-muted); }
211
+ .rb-table { width: 100%; border-collapse: collapse; font-size: 13px; }
212
+ .rb-table th { text-align: left; font-size: 11px; font-weight: 700; color: var(--color-text-muted); padding: 0 6px 4px; white-space: nowrap; }
213
+ .rb-table td { padding: 3px 4px; vertical-align: middle; }
214
+ .rb-table .rb-input { width: 100%; min-width: 72px; }
215
+ .rb-scroll { overflow-x: auto; }
216
+ `;
217
+
218
+ // Pure conversions between what the point-and-click builders edit and the
219
+ // JSON the API stores. No Angular here so they unit-test cheaply.
220
+ //
221
+ // Rules shared by every converter:
222
+ // - an empty / unset choice is left OUT of the JSON (no restriction), so
223
+ // "nothing picked" saves as `{}` / `[]`;
224
+ // - keys the builder doesn't know about (written by an engineer in the
225
+ // "Edit as JSON" view, or by a newer server) ride along untouched.
226
+ const isObj = (v) => !!v && typeof v === 'object' && !Array.isArray(v);
227
+ function strArr(v) {
228
+ return Array.isArray(v) ? v.filter((x) => typeof x === 'string') : [];
229
+ }
230
+ function numOrUndef(v) {
231
+ if (v === null || v === undefined || v === '')
232
+ return undefined;
233
+ const n = Number(v);
234
+ return Number.isFinite(n) ? n : undefined;
235
+ }
236
+ /** Copy of `original` (or `{}`) so converters never mutate the draft. */
237
+ function base(original) {
238
+ return isObj(original) ? { ...original } : {};
239
+ }
240
+ function put(out, key, value) {
241
+ if (value === undefined || value === null || (Array.isArray(value) && !value.length) || value === false)
242
+ delete out[key];
243
+ else
244
+ out[key] = value;
245
+ }
246
+ function range(original, min, max) {
247
+ const out = isObj(original) ? { ...original } : {};
248
+ put(out, 'min', min);
249
+ put(out, 'max', max);
250
+ return Object.keys(out).length ? out : undefined;
251
+ }
252
+ /** Labels for ids; an id with no matching option is shown as-is. */
253
+ function labelsFor(ids, options) {
254
+ const byValue = new Map(options.map((o) => [o.value, o.label]));
255
+ return ids.map((id) => byValue.get(id) ?? id);
256
+ }
257
+ function joinList(items, max = 4) {
258
+ if (items.length <= max)
259
+ return items.join(', ');
260
+ return `${items.slice(0, max).join(', ')} +${items.length - max} more`;
261
+ }
262
+ const naira = (n) => `₦${n.toLocaleString('en-NG')}`;
263
+ function toTargetingModel(value) {
264
+ const v = base(value);
265
+ return {
266
+ segmentIds: strArr(v['segmentIds']),
267
+ channelIds: strArr(v['channelIds']),
268
+ states: strArr(v['states']),
269
+ newVisitorOnly: v['newVisitorOnly'] === true,
270
+ };
271
+ }
272
+ function fromTargetingModel(m, original) {
273
+ const out = base(original);
274
+ put(out, 'segmentIds', m.segmentIds);
275
+ put(out, 'channelIds', m.channelIds);
276
+ put(out, 'states', m.states);
277
+ put(out, 'newVisitorOnly', m.newVisitorOnly);
278
+ return out;
279
+ }
280
+ function describeTargeting(m, segments, channels) {
281
+ const parts = [];
282
+ if (m.newVisitorOnly)
283
+ parts.push('new visitors only');
284
+ if (m.segmentIds.length)
285
+ parts.push(`customers in ${joinList(labelsFor(m.segmentIds, segments))}`);
286
+ if (m.states.length)
287
+ parts.push(`delivering to ${joinList(m.states)}`);
288
+ if (m.channelIds.length)
289
+ parts.push(`on ${joinList(labelsFor(m.channelIds, channels))}`);
290
+ return parts.length ? `Shown to: ${parts.join(' · ')}.` : 'Shown to everyone.';
291
+ }
292
+ function toConditionsModel(value) {
293
+ const v = base(value);
294
+ const cart = isObj(v['cartTotal']) ? v['cartTotal'] : {};
295
+ const items = isObj(v['itemCount']) ? v['itemCount'] : {};
296
+ return {
297
+ cartMin: numOrUndef(cart['min']),
298
+ cartMax: numOrUndef(cart['max']),
299
+ itemMin: numOrUndef(items['min']),
300
+ itemMax: numOrUndef(items['max']),
301
+ firstOrder: v['firstOrder'] === true,
302
+ deliveryStates: strArr(v['deliveryStates']),
303
+ segmentIds: strArr(v['segmentIds']),
304
+ categoryIds: strArr(v['categoryIds']),
305
+ brandIds: strArr(v['brandIds']),
306
+ minEligibleQty: numOrUndef(v['minEligibleQty']),
307
+ };
308
+ }
309
+ function fromConditionsModel(m, original) {
310
+ const out = base(original);
311
+ put(out, 'cartTotal', range(out['cartTotal'], numOrUndef(m.cartMin), numOrUndef(m.cartMax)));
312
+ put(out, 'itemCount', range(out['itemCount'], numOrUndef(m.itemMin), numOrUndef(m.itemMax)));
313
+ put(out, 'firstOrder', m.firstOrder);
314
+ put(out, 'deliveryStates', m.deliveryStates);
315
+ put(out, 'segmentIds', m.segmentIds);
316
+ put(out, 'categoryIds', m.categoryIds);
317
+ put(out, 'brandIds', m.brandIds);
318
+ put(out, 'minEligibleQty', numOrUndef(m.minEligibleQty));
319
+ return out;
320
+ }
321
+ function describeConditions(m, o, extraKeys = []) {
322
+ const parts = [];
323
+ if (m.cartMin !== undefined && m.cartMax !== undefined)
324
+ parts.push(`cart between ${naira(m.cartMin)} and ${naira(m.cartMax)}`);
325
+ else if (m.cartMin !== undefined)
326
+ parts.push(`cart is ${naira(m.cartMin)} or more`);
327
+ else if (m.cartMax !== undefined)
328
+ parts.push(`cart is ${naira(m.cartMax)} or less`);
329
+ if (m.itemMin !== undefined && m.itemMax !== undefined)
330
+ parts.push(`${m.itemMin}–${m.itemMax} items`);
331
+ else if (m.itemMin !== undefined)
332
+ parts.push(`${m.itemMin}+ items`);
333
+ else if (m.itemMax !== undefined)
334
+ parts.push(`at most ${m.itemMax} items`);
335
+ if (m.firstOrder)
336
+ parts.push("customer's first order");
337
+ if (m.deliveryStates.length)
338
+ parts.push(`delivering to ${joinList(m.deliveryStates)}`);
339
+ if (m.segmentIds.length)
340
+ parts.push(`customer in ${joinList(labelsFor(m.segmentIds, o.segments))}`);
341
+ if (m.categoryIds.length)
342
+ parts.push(`in ${joinList(labelsFor(m.categoryIds, o.categories))}`);
343
+ if (m.brandIds.length)
344
+ parts.push(`brand ${joinList(labelsFor(m.brandIds, o.brands))}`);
345
+ if (m.minEligibleQty !== undefined)
346
+ parts.push(`at least ${m.minEligibleQty} matching items`);
347
+ if (extraKeys.length)
348
+ parts.push('plus extra rules set in JSON');
349
+ return parts.length ? `Applies when: ${parts.join(' · ')}.` : 'Applies to every cart.';
350
+ }
351
+ /** Condition keys the builder has no control for (kept, but flagged). */
352
+ const KNOWN_CONDITION_KEYS = [
353
+ 'cartTotal',
354
+ 'itemCount',
355
+ 'firstOrder',
356
+ 'deliveryStates',
357
+ 'segmentIds',
358
+ 'categoryIds',
359
+ 'brandIds',
360
+ 'minEligibleQty',
361
+ ];
362
+ function unknownKeys(value, known) {
363
+ return Object.keys(base(value)).filter((k) => !known.includes(k));
364
+ }
365
+ // ── Promotion actions ────────────────────────────────────────────────
366
+ const ACTION_TYPES = [
367
+ { value: 'percentage_off', label: 'Percentage off', hint: 'Takes a % off each matching item.' },
368
+ { value: 'fixed_off', label: 'Fixed amount off', hint: 'Takes a ₦ amount off the matching items, shared across them.' },
369
+ { value: 'free_delivery', label: 'Free delivery', hint: 'Delivery costs nothing.' },
370
+ { value: 'free_gift', label: 'Free gift', hint: 'Adds a free product to the order.' },
371
+ { value: 'buy_x_get_y', label: 'Buy X, get Y free', hint: 'For every X + Y items, the Y cheapest are free.' },
372
+ { value: 'cheapest_free', label: 'Cheapest item free', hint: 'The cheapest matching item is free.' },
373
+ { value: 'tiered_discount', label: 'Tiered discount', hint: 'Bigger % off as the matching spend grows.' },
374
+ ];
375
+ function newAction(type = 'percentage_off') {
376
+ return { type, tiers: type === 'tiered_discount' ? [{}] : [] };
377
+ }
378
+ function toActionRows(value) {
379
+ if (!Array.isArray(value))
380
+ return [];
381
+ return value.filter(isObj).map((a) => {
382
+ const type = String(a['type'] ?? '');
383
+ if (!ACTION_TYPES.some((t) => t.value === type))
384
+ return { type, tiers: [], raw: a };
385
+ const target = a['target'];
386
+ const row = { type, value: numOrUndef(a['value']), tiers: [] };
387
+ if (type === 'buy_x_get_y') {
388
+ row.x = numOrUndef(isObj(target) ? target['x'] : undefined) ?? numOrUndef(a['value']);
389
+ row.y = numOrUndef(isObj(target) ? target['y'] : undefined) ?? 1;
390
+ }
391
+ if (type === 'free_gift') {
392
+ row.variantId = typeof target === 'string' ? target : isObj(target) ? target['variantId'] : undefined;
393
+ }
394
+ if (type === 'tiered_discount') {
395
+ row.tiers = (Array.isArray(target) ? target : []).filter(isObj).map((t) => ({
396
+ min: numOrUndef(t['min']),
397
+ percent: numOrUndef(t['percent']),
398
+ }));
399
+ }
400
+ return row;
401
+ });
402
+ }
403
+ function fromActionRows(rows) {
404
+ return rows.map((r) => {
405
+ if (r.raw)
406
+ return r.raw;
407
+ switch (r.type) {
408
+ case 'percentage_off':
409
+ case 'fixed_off':
410
+ return withoutUndef({ type: r.type, value: numOrUndef(r.value) });
411
+ case 'buy_x_get_y':
412
+ return { type: r.type, target: { x: numOrUndef(r.x) ?? 0, y: numOrUndef(r.y) ?? 1 } };
413
+ case 'free_gift':
414
+ return withoutUndef({ type: r.type, target: r.variantId || undefined });
415
+ case 'tiered_discount':
416
+ return {
417
+ type: r.type,
418
+ target: r.tiers
419
+ .filter((t) => numOrUndef(t.min) !== undefined || numOrUndef(t.percent) !== undefined)
420
+ .map((t) => ({ min: numOrUndef(t.min) ?? 0, percent: numOrUndef(t.percent) ?? 0 })),
421
+ };
422
+ default:
423
+ return { type: r.type };
424
+ }
425
+ });
426
+ }
427
+ function withoutUndef(o) {
428
+ for (const k of Object.keys(o))
429
+ if (o[k] === undefined)
430
+ delete o[k];
431
+ return o;
432
+ }
433
+ /** What is missing on an action that would make it do nothing. */
434
+ function actionProblem(r) {
435
+ if (r.raw)
436
+ return null;
437
+ switch (r.type) {
438
+ case 'percentage_off':
439
+ return r.value === undefined || r.value <= 0 || r.value > 100 ? 'Enter a percentage between 1 and 100.' : null;
440
+ case 'fixed_off':
441
+ return r.value === undefined || r.value <= 0 ? 'Enter an amount greater than 0.' : null;
442
+ case 'buy_x_get_y':
443
+ return !r.x || r.x <= 0 || !r.y || r.y <= 0 ? 'Enter how many to buy and how many are free.' : null;
444
+ case 'free_gift':
445
+ return r.variantId ? null : 'Choose the free product.';
446
+ case 'tiered_discount':
447
+ return r.tiers.some((t) => numOrUndef(t.min) !== undefined && numOrUndef(t.percent) !== undefined) ? null : 'Add at least one tier.';
448
+ default:
449
+ return null;
450
+ }
451
+ }
452
+ function describeAction(r) {
453
+ if (r.raw)
454
+ return `Custom action “${r.type}”`;
455
+ switch (r.type) {
456
+ case 'percentage_off':
457
+ return `${r.value ?? '?'}% off`;
458
+ case 'fixed_off':
459
+ return `${r.value !== undefined ? naira(r.value) : '₦?'} off`;
460
+ case 'free_delivery':
461
+ return 'Free delivery';
462
+ case 'free_gift':
463
+ return 'A free gift';
464
+ case 'buy_x_get_y':
465
+ return `Buy ${r.x ?? '?'}, get ${r.y ?? '?'} free`;
466
+ case 'cheapest_free':
467
+ return 'Cheapest item free';
468
+ case 'tiered_discount':
469
+ return 'Tiered discount';
470
+ default:
471
+ return r.type;
472
+ }
473
+ }
474
+ const RATE_RULE_KEYS = ['minWeightKg', 'maxWeightKg', 'minSubtotal', 'maxSubtotal', 'flatFee', 'perKg', 'freeOverSubtotal'];
475
+ function toRateRuleRows(value) {
476
+ if (!Array.isArray(value))
477
+ return [];
478
+ return value.filter(isObj).map((r) => {
479
+ const row = { extra: {} };
480
+ for (const k of Object.keys(r)) {
481
+ if (RATE_RULE_KEYS.includes(k))
482
+ row[k] = numOrUndef(r[k]);
483
+ else
484
+ row.extra[k] = r[k];
485
+ }
486
+ return row;
487
+ });
488
+ }
489
+ function fromRateRuleRows(rows) {
490
+ return rows.map((row) => {
491
+ const out = { ...row.extra };
492
+ for (const k of RATE_RULE_KEYS) {
493
+ const n = numOrUndef(row[k]);
494
+ if (n !== undefined)
495
+ out[k] = n;
496
+ }
497
+ // The API requires a fee on every tier; a blank means free.
498
+ if (out['flatFee'] === undefined)
499
+ out['flatFee'] = 0;
500
+ return out;
501
+ });
502
+ }
503
+ function describeRateRule(r) {
504
+ const when = [];
505
+ const kg = (min, max) => min !== undefined && max !== undefined ? `${min}–${max} kg` : min !== undefined ? `${min} kg and over` : max !== undefined ? `up to ${max} kg` : '';
506
+ const spend = (min, max) => min !== undefined && max !== undefined
507
+ ? `orders ${naira(min)}–${naira(max)}`
508
+ : min !== undefined
509
+ ? `orders from ${naira(min)}`
510
+ : max !== undefined
511
+ ? `orders under ${naira(max)}`
512
+ : '';
513
+ const w = kg(numOrUndef(r.minWeightKg), numOrUndef(r.maxWeightKg));
514
+ const s = spend(numOrUndef(r.minSubtotal), numOrUndef(r.maxSubtotal));
515
+ if (w)
516
+ when.push(w);
517
+ if (s)
518
+ when.push(s);
519
+ const fee = numOrUndef(r.flatFee) ?? 0;
520
+ const perKg = numOrUndef(r.perKg);
521
+ const free = numOrUndef(r.freeOverSubtotal);
522
+ let cost = fee ? naira(fee) : 'Free';
523
+ if (perKg)
524
+ cost += ` + ${naira(perKg)}/kg`;
525
+ if (free !== undefined)
526
+ cost += `, free over ${naira(free)}`;
527
+ return `${when.length ? `For ${when.join(', ')}` : 'For any parcel'}: ${cost}`;
528
+ }
529
+
530
+ // The lists the point-and-click builders pick from (segments, channels,
531
+ // states, categories, brands) plus a product lookup for "free gift". Each
532
+ // list is fetched once per session and shared by every builder on screen.
533
+ // A failed fetch resolves to an empty list so a builder still renders — and
534
+ // ids already saved in the JSON still show (as their raw id).
535
+ class RuleOptionsService {
536
+ constructor() {
537
+ this.api = inject(ApiService);
538
+ this.cache = new Map();
539
+ this.segments = () => this.cached('segments', () => this.rows('apps/commerce/customer-segment', {}, (r) => ({ value: r.id, label: r.name })));
540
+ this.channels = () => this.cached('channels', () => this.rows('apps/commerce/channel', {}, (r) => ({ value: r.id, label: r.name })));
541
+ this.categories = () => this.cached('categories', () => this.rows('apps/commerce/category', {}, (r) => ({ value: r.id, label: r.name })));
542
+ this.brands = () => this.cached('brands', () => this.rows('apps/commerce/brand', {}, (r) => ({ value: r.id, label: r.name })));
543
+ this.states = () => this.cached('states', () => this.rows('apps/commerce/static-list-item', { listKey: 'ng-state' }, (r) => ({ value: r.code, label: r.label })));
544
+ }
545
+ /** Variants matching a SKU (exact) or a search term. */
546
+ async findVariants(term) {
547
+ const t = term.trim();
548
+ if (!t)
549
+ return [];
550
+ const src = this.api.on('apps/commerce/product-variant');
551
+ const toOption = (v) => ({ value: v.id, label: `${v.name ?? 'Product'} · SKU ${v.sku}` });
552
+ try {
553
+ const bySku = await firstValueFrom(src.getMany({ sku: t, page: 1, perPage: 10 }));
554
+ const exact = (bySku?.data ?? []).filter((v) => String(v.sku).toLowerCase() === t.toLowerCase());
555
+ if (exact.length)
556
+ return exact.map(toOption);
557
+ const byQuery = await firstValueFrom(src.getMany({ query: t, page: 1, perPage: 10 }));
558
+ return (byQuery?.data ?? []).map(toOption);
559
+ }
560
+ catch {
561
+ return [];
562
+ }
563
+ }
564
+ async variantLabel(id) {
565
+ try {
566
+ const res = await firstValueFrom(this.api.on('apps/commerce/product-variant').getOne(id));
567
+ const v = res?.data ?? res;
568
+ return v?.sku ? `${v.name ?? 'Product'} · SKU ${v.sku}` : undefined;
569
+ }
570
+ catch {
571
+ return undefined;
572
+ }
573
+ }
574
+ cached(key, load) {
575
+ let hit = this.cache.get(key);
576
+ if (!hit) {
577
+ hit = load();
578
+ this.cache.set(key, hit);
579
+ // Don't pin an empty (probably failed) list for the whole session.
580
+ void hit.then((list) => {
581
+ if (!list.length)
582
+ this.cache.delete(key);
583
+ });
584
+ }
585
+ return hit;
586
+ }
587
+ // The list endpoint caps perPage at 200, so page until a short page.
588
+ async rows(mount, filter, map) {
589
+ const out = [];
590
+ try {
591
+ for (let page = 1; page <= 10; page++) {
592
+ const res = await firstValueFrom(this.api.on(mount).getMany({ ...filter, page, perPage: 200 }));
593
+ const batch = res?.data ?? [];
594
+ out.push(...batch.map(map));
595
+ if (batch.length < 200)
596
+ break;
597
+ }
598
+ }
599
+ catch {
600
+ /* fall through with what we have */
601
+ }
602
+ return out.filter((o) => o.value && o.label).sort((a, b) => a.label.localeCompare(b.label));
603
+ }
604
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: RuleOptionsService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
605
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: RuleOptionsService, providedIn: 'root' }); }
606
+ }
607
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: RuleOptionsService, decorators: [{
608
+ type: Injectable,
609
+ args: [{ providedIn: 'root' }]
610
+ }] });
611
+
612
+ // Promotion actions: what the discount does. One card per action; each type
613
+ // shows only the inputs it needs.
614
+ class ActionsBuilderComponent {
615
+ constructor() {
616
+ this.options = inject(RuleOptionsService);
617
+ this.valueChange = new EventEmitter();
618
+ this.types = ACTION_TYPES;
619
+ this.rows = [];
620
+ this.search = [];
621
+ this.results = [];
622
+ this.searched = [];
623
+ this.giftLabels = {};
624
+ this.describe = describeAction;
625
+ this.problem = actionProblem;
626
+ }
627
+ ngOnChanges(changes) {
628
+ if (changes['value'] && this.value !== this.emitted) {
629
+ this.rows = toActionRows(this.value);
630
+ for (const r of this.rows)
631
+ if (r.variantId)
632
+ void this.labelGift(r.variantId);
633
+ }
634
+ }
635
+ hint(type) {
636
+ return ACTION_TYPES.find((t) => t.value === type)?.hint ?? '';
637
+ }
638
+ add() {
639
+ this.rows.push(newAction());
640
+ this.emit();
641
+ }
642
+ remove(i) {
643
+ this.rows.splice(i, 1);
644
+ this.search.splice(i, 1);
645
+ this.results.splice(i, 1);
646
+ this.searched.splice(i, 1);
647
+ this.emit();
648
+ }
649
+ changeType(i, type) {
650
+ this.rows[i] = newAction(type);
651
+ this.emit();
652
+ }
653
+ async find(i) {
654
+ this.results[i] = await this.options.findVariants(this.search[i] ?? '');
655
+ this.searched[i] = true;
656
+ }
657
+ pick(i, o) {
658
+ this.giftLabels[o.value] = o.label;
659
+ this.rows[i].variantId = o.value;
660
+ this.results[i] = [];
661
+ this.emit();
662
+ }
663
+ async labelGift(id) {
664
+ const label = await this.options.variantLabel(id);
665
+ if (label)
666
+ this.giftLabels[id] = label;
667
+ }
668
+ emit() {
669
+ this.emitted = fromActionRows(this.rows);
670
+ this.valueChange.emit(this.emitted);
671
+ }
672
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: ActionsBuilderComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
673
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.16", type: ActionsBuilderComponent, isStandalone: true, selector: "x-actions-builder", inputs: { value: "value" }, outputs: { valueChange: "valueChange" }, usesOnChanges: true, ngImport: i0, template: `
674
+ <div class="rb" data-testid="actions-builder">
675
+ @if (!rows.length) {
676
+ <div class="rb-empty">No actions yet — a promotion needs at least one to do anything.</div>
677
+ }
678
+
679
+ @for (r of rows; track $index; let i = $index) {
680
+ <div class="rb-card" [attr.data-testid]="'action-' + i">
681
+ <div class="rb-card-head">
682
+ @if (r.raw) {
683
+ <strong>{{ describe(r) }}</strong>
684
+ <span class="rb-help">Kept as-is. Change it with “Edit as JSON”.</span>
685
+ } @else {
686
+ <select class="rb-input" [ngModel]="r.type" (ngModelChange)="changeType(i, $event)" [attr.data-testid]="'action-type-' + i">
687
+ @for (t of types; track t.value) {
688
+ <option [value]="t.value">{{ t.label }}</option>
689
+ }
690
+ </select>
691
+ }
692
+ <button type="button" class="rb-link rb-danger" (click)="remove(i)">Remove</button>
693
+ </div>
694
+
695
+ @if (!r.raw) {
696
+ <div class="rb-help">{{ hint(r.type) }}</div>
697
+
698
+ @switch (r.type) {
699
+ @case ('percentage_off') {
700
+ <label class="rb-field">Percent off (%)
701
+ <input class="rb-input rb-input-sm" type="number" min="1" max="100" [ngModel]="r.value" (ngModelChange)="r.value = $event; emit()" [attr.data-testid]="'action-value-' + i" />
702
+ </label>
703
+ }
704
+ @case ('fixed_off') {
705
+ <label class="rb-field">Amount off (₦)
706
+ <input class="rb-input rb-input-sm" type="number" min="1" [ngModel]="r.value" (ngModelChange)="r.value = $event; emit()" [attr.data-testid]="'action-value-' + i" />
707
+ </label>
708
+ }
709
+ @case ('buy_x_get_y') {
710
+ <div class="rb-row">
711
+ <label class="rb-field">Customer buys
712
+ <input class="rb-input rb-input-sm" type="number" min="1" [ngModel]="r.x" (ngModelChange)="r.x = $event; emit()" />
713
+ </label>
714
+ <label class="rb-field">…and gets this many free
715
+ <input class="rb-input rb-input-sm" type="number" min="1" [ngModel]="r.y" (ngModelChange)="r.y = $event; emit()" />
716
+ </label>
717
+ </div>
718
+ }
719
+ @case ('free_gift') {
720
+ <div class="rb-group">
721
+ @if (r.variantId) {
722
+ <div class="rb-row">
723
+ <strong>{{ giftLabels[r.variantId] || 'Selected product' }}</strong>
724
+ <button type="button" class="rb-link" (click)="r.variantId = undefined; emit()">Change</button>
725
+ </div>
726
+ } @else {
727
+ <div class="rb-row">
728
+ <input
729
+ class="rb-input"
730
+ style="flex: 1 1 200px"
731
+ type="search"
732
+ placeholder="Type a SKU or product name"
733
+ [ngModel]="search[i]"
734
+ (ngModelChange)="search[i] = $event"
735
+ (keydown.enter)="$event.preventDefault(); find(i)"
736
+ [attr.data-testid]="'gift-search-' + i"
737
+ />
738
+ <button type="button" class="rb-btn" (click)="find(i)">Find</button>
739
+ </div>
740
+ @for (o of results[i] ?? []; track o.value) {
741
+ <button type="button" class="rb-link" style="text-align: left" (click)="pick(i, o)">+ {{ o.label }}</button>
742
+ }
743
+ @if (searched[i] && !(results[i] ?? []).length) {
744
+ <div class="rb-help">No product found for “{{ search[i] }}”.</div>
745
+ }
746
+ }
747
+ </div>
748
+ }
749
+ @case ('tiered_discount') {
750
+ <table class="rb-table">
751
+ <thead><tr><th>When matching spend reaches (₦)</th><th>Take off (%)</th><th></th></tr></thead>
752
+ <tbody>
753
+ @for (t of r.tiers; track $index; let j = $index) {
754
+ <tr>
755
+ <td><input class="rb-input" type="number" min="0" [ngModel]="t.min" (ngModelChange)="t.min = $event; emit()" /></td>
756
+ <td><input class="rb-input" type="number" min="1" max="100" [ngModel]="t.percent" (ngModelChange)="t.percent = $event; emit()" /></td>
757
+ <td><button type="button" class="rb-link rb-danger" (click)="r.tiers.splice(j, 1); emit()">×</button></td>
758
+ </tr>
759
+ }
760
+ </tbody>
761
+ </table>
762
+ <div><button type="button" class="rb-btn" (click)="r.tiers.push({}); emit()">+ Add tier</button></div>
763
+ }
764
+ }
765
+
766
+ @if (problem(r); as p) {
767
+ <div class="rb-problem">{{ p }}</div>
768
+ }
769
+ }
770
+ </div>
771
+ }
772
+
773
+ <div><button type="button" class="rb-btn rb-btn-primary" (click)="add()" data-testid="action-add">+ Add action</button></div>
774
+ </div>
775
+ `, isInline: true, styles: [":host{display:block}.rb{display:flex;flex-direction:column;gap:12px}.rb-group{display:flex;flex-direction:column;gap:4px}.rb-label{font-size:11.5px;font-weight:700;color:var(--color-text-muted)}.rb-help{font-size:12px;font-weight:400;color:var(--color-text-muted)}.rb-row{display:flex;flex-wrap:wrap;gap:10px;align-items:center}.rb-summary{font-size:12.5px;color:var(--color-text);background:color-mix(in srgb,var(--color-accent, #0b3a82) 8%,transparent);border-radius:var(--radius-md, 8px);padding:7px 10px}.rb-input{padding:6px 10px;border:1px solid var(--color-border);border-radius:var(--radius-md, 8px);background:transparent;color:inherit;font:inherit;font-size:13px;min-width:0}.rb-input-sm{width:110px}.rb-check{display:inline-flex;align-items:center;gap:8px;font-size:13px;font-weight:600;color:var(--color-text);cursor:pointer}.rb-btn{appearance:none;border:1px solid var(--color-border);background:transparent;border-radius:var(--radius-md, 8px);padding:5px 12px;font-size:12.5px;font-weight:700;cursor:pointer;color:var(--color-text-muted)}.rb-btn:disabled{opacity:.45;cursor:default}.rb-btn-primary{border-color:var(--color-accent);color:var(--color-accent-hover, #0b3a82)}.rb-link{appearance:none;background:none;border:0;padding:2px 4px;font-size:12.5px;font-weight:700;color:var(--color-accent-hover, #0b3a82);cursor:pointer}.rb-link:disabled{opacity:.4;cursor:default}.rb-danger{color:var(--color-danger, #c0362c)}.rb-card{border:1px solid var(--color-border);border-radius:var(--radius-md, 8px);padding:10px 12px;display:flex;flex-direction:column;gap:8px}.rb-card-head{display:flex;gap:8px;align-items:center;justify-content:space-between;flex-wrap:wrap}.rb-problem{font-size:12px;font-weight:600;color:var(--color-danger, #c0362c)}.rb-field{display:flex;flex-direction:column;gap:3px;font-size:11.5px;font-weight:700;color:var(--color-text-muted)}.rb-empty{font-size:13px;color:var(--color-text-muted)}.rb-table{width:100%;border-collapse:collapse;font-size:13px}.rb-table th{text-align:left;font-size:11px;font-weight:700;color:var(--color-text-muted);padding:0 6px 4px;white-space:nowrap}.rb-table td{padding:3px 4px;vertical-align:middle}.rb-table .rb-input{width:100%;min-width:72px}.rb-scroll{overflow-x:auto}\n"], dependencies: [{ kind: "ngmodule", type: FormsModule }, { kind: "directive", type: i1.NgSelectOption, selector: "option", inputs: ["ngValue", "value"] }, { kind: "directive", type: i1.ɵNgSelectMultipleOption, selector: "option", inputs: ["ngValue", "value"] }, { kind: "directive", type: i1.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { kind: "directive", type: i1.NumberValueAccessor, selector: "input[type=number][formControlName],input[type=number][formControl],input[type=number][ngModel]" }, { kind: "directive", type: i1.SelectControlValueAccessor, selector: "select:not([multiple])[formControlName],select:not([multiple])[formControl],select:not([multiple])[ngModel]", inputs: ["compareWith"] }, { kind: "directive", type: i1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i1.MinValidator, selector: "input[type=number][min][formControlName],input[type=number][min][formControl],input[type=number][min][ngModel]", inputs: ["min"] }, { kind: "directive", type: i1.MaxValidator, selector: "input[type=number][max][formControlName],input[type=number][max][formControl],input[type=number][max][ngModel]", inputs: ["max"] }, { kind: "directive", type: i1.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }] }); }
776
+ }
777
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: ActionsBuilderComponent, decorators: [{
778
+ type: Component,
779
+ args: [{ selector: 'x-actions-builder', standalone: true, imports: [FormsModule], template: `
780
+ <div class="rb" data-testid="actions-builder">
781
+ @if (!rows.length) {
782
+ <div class="rb-empty">No actions yet — a promotion needs at least one to do anything.</div>
783
+ }
784
+
785
+ @for (r of rows; track $index; let i = $index) {
786
+ <div class="rb-card" [attr.data-testid]="'action-' + i">
787
+ <div class="rb-card-head">
788
+ @if (r.raw) {
789
+ <strong>{{ describe(r) }}</strong>
790
+ <span class="rb-help">Kept as-is. Change it with “Edit as JSON”.</span>
791
+ } @else {
792
+ <select class="rb-input" [ngModel]="r.type" (ngModelChange)="changeType(i, $event)" [attr.data-testid]="'action-type-' + i">
793
+ @for (t of types; track t.value) {
794
+ <option [value]="t.value">{{ t.label }}</option>
795
+ }
796
+ </select>
797
+ }
798
+ <button type="button" class="rb-link rb-danger" (click)="remove(i)">Remove</button>
799
+ </div>
800
+
801
+ @if (!r.raw) {
802
+ <div class="rb-help">{{ hint(r.type) }}</div>
803
+
804
+ @switch (r.type) {
805
+ @case ('percentage_off') {
806
+ <label class="rb-field">Percent off (%)
807
+ <input class="rb-input rb-input-sm" type="number" min="1" max="100" [ngModel]="r.value" (ngModelChange)="r.value = $event; emit()" [attr.data-testid]="'action-value-' + i" />
808
+ </label>
809
+ }
810
+ @case ('fixed_off') {
811
+ <label class="rb-field">Amount off (₦)
812
+ <input class="rb-input rb-input-sm" type="number" min="1" [ngModel]="r.value" (ngModelChange)="r.value = $event; emit()" [attr.data-testid]="'action-value-' + i" />
813
+ </label>
814
+ }
815
+ @case ('buy_x_get_y') {
816
+ <div class="rb-row">
817
+ <label class="rb-field">Customer buys
818
+ <input class="rb-input rb-input-sm" type="number" min="1" [ngModel]="r.x" (ngModelChange)="r.x = $event; emit()" />
819
+ </label>
820
+ <label class="rb-field">…and gets this many free
821
+ <input class="rb-input rb-input-sm" type="number" min="1" [ngModel]="r.y" (ngModelChange)="r.y = $event; emit()" />
822
+ </label>
823
+ </div>
824
+ }
825
+ @case ('free_gift') {
826
+ <div class="rb-group">
827
+ @if (r.variantId) {
828
+ <div class="rb-row">
829
+ <strong>{{ giftLabels[r.variantId] || 'Selected product' }}</strong>
830
+ <button type="button" class="rb-link" (click)="r.variantId = undefined; emit()">Change</button>
831
+ </div>
832
+ } @else {
833
+ <div class="rb-row">
834
+ <input
835
+ class="rb-input"
836
+ style="flex: 1 1 200px"
837
+ type="search"
838
+ placeholder="Type a SKU or product name"
839
+ [ngModel]="search[i]"
840
+ (ngModelChange)="search[i] = $event"
841
+ (keydown.enter)="$event.preventDefault(); find(i)"
842
+ [attr.data-testid]="'gift-search-' + i"
843
+ />
844
+ <button type="button" class="rb-btn" (click)="find(i)">Find</button>
845
+ </div>
846
+ @for (o of results[i] ?? []; track o.value) {
847
+ <button type="button" class="rb-link" style="text-align: left" (click)="pick(i, o)">+ {{ o.label }}</button>
848
+ }
849
+ @if (searched[i] && !(results[i] ?? []).length) {
850
+ <div class="rb-help">No product found for “{{ search[i] }}”.</div>
851
+ }
852
+ }
853
+ </div>
854
+ }
855
+ @case ('tiered_discount') {
856
+ <table class="rb-table">
857
+ <thead><tr><th>When matching spend reaches (₦)</th><th>Take off (%)</th><th></th></tr></thead>
858
+ <tbody>
859
+ @for (t of r.tiers; track $index; let j = $index) {
860
+ <tr>
861
+ <td><input class="rb-input" type="number" min="0" [ngModel]="t.min" (ngModelChange)="t.min = $event; emit()" /></td>
862
+ <td><input class="rb-input" type="number" min="1" max="100" [ngModel]="t.percent" (ngModelChange)="t.percent = $event; emit()" /></td>
863
+ <td><button type="button" class="rb-link rb-danger" (click)="r.tiers.splice(j, 1); emit()">×</button></td>
864
+ </tr>
865
+ }
866
+ </tbody>
867
+ </table>
868
+ <div><button type="button" class="rb-btn" (click)="r.tiers.push({}); emit()">+ Add tier</button></div>
869
+ }
870
+ }
871
+
872
+ @if (problem(r); as p) {
873
+ <div class="rb-problem">{{ p }}</div>
874
+ }
875
+ }
876
+ </div>
877
+ }
878
+
879
+ <div><button type="button" class="rb-btn rb-btn-primary" (click)="add()" data-testid="action-add">+ Add action</button></div>
880
+ </div>
881
+ `, styles: [":host{display:block}.rb{display:flex;flex-direction:column;gap:12px}.rb-group{display:flex;flex-direction:column;gap:4px}.rb-label{font-size:11.5px;font-weight:700;color:var(--color-text-muted)}.rb-help{font-size:12px;font-weight:400;color:var(--color-text-muted)}.rb-row{display:flex;flex-wrap:wrap;gap:10px;align-items:center}.rb-summary{font-size:12.5px;color:var(--color-text);background:color-mix(in srgb,var(--color-accent, #0b3a82) 8%,transparent);border-radius:var(--radius-md, 8px);padding:7px 10px}.rb-input{padding:6px 10px;border:1px solid var(--color-border);border-radius:var(--radius-md, 8px);background:transparent;color:inherit;font:inherit;font-size:13px;min-width:0}.rb-input-sm{width:110px}.rb-check{display:inline-flex;align-items:center;gap:8px;font-size:13px;font-weight:600;color:var(--color-text);cursor:pointer}.rb-btn{appearance:none;border:1px solid var(--color-border);background:transparent;border-radius:var(--radius-md, 8px);padding:5px 12px;font-size:12.5px;font-weight:700;cursor:pointer;color:var(--color-text-muted)}.rb-btn:disabled{opacity:.45;cursor:default}.rb-btn-primary{border-color:var(--color-accent);color:var(--color-accent-hover, #0b3a82)}.rb-link{appearance:none;background:none;border:0;padding:2px 4px;font-size:12.5px;font-weight:700;color:var(--color-accent-hover, #0b3a82);cursor:pointer}.rb-link:disabled{opacity:.4;cursor:default}.rb-danger{color:var(--color-danger, #c0362c)}.rb-card{border:1px solid var(--color-border);border-radius:var(--radius-md, 8px);padding:10px 12px;display:flex;flex-direction:column;gap:8px}.rb-card-head{display:flex;gap:8px;align-items:center;justify-content:space-between;flex-wrap:wrap}.rb-problem{font-size:12px;font-weight:600;color:var(--color-danger, #c0362c)}.rb-field{display:flex;flex-direction:column;gap:3px;font-size:11.5px;font-weight:700;color:var(--color-text-muted)}.rb-empty{font-size:13px;color:var(--color-text-muted)}.rb-table{width:100%;border-collapse:collapse;font-size:13px}.rb-table th{text-align:left;font-size:11px;font-weight:700;color:var(--color-text-muted);padding:0 6px 4px;white-space:nowrap}.rb-table td{padding:3px 4px;vertical-align:middle}.rb-table .rb-input{width:100%;min-width:72px}.rb-scroll{overflow-x:auto}\n"] }]
882
+ }], propDecorators: { value: [{
883
+ type: Input
884
+ }], valueChange: [{
885
+ type: Output
886
+ }] } });
887
+
888
+ // Tick-from-a-list picker with removable chips and a search box — used for
889
+ // segments, channels, states, categories and brands. Ids already selected
890
+ // but missing from `options` (deleted since) still show, as their raw id,
891
+ // so saving doesn't silently drop them.
892
+ class OptionPickerComponent {
893
+ constructor() {
894
+ this.options = [];
895
+ this.selected = [];
896
+ this.loading = false;
897
+ /** Plural noun for the search box and empty text, e.g. "segments". */
898
+ this.noun = 'items';
899
+ this.emptyText = 'Nothing to pick from yet.';
900
+ this.testId = '';
901
+ this.selectedChange = new EventEmitter();
902
+ this.query = '';
903
+ }
904
+ get labels() {
905
+ return labelsFor(this.selected, this.options);
906
+ }
907
+ get visible() {
908
+ const q = this.query.trim().toLowerCase();
909
+ return q ? this.options.filter((o) => o.label.toLowerCase().includes(q)) : this.options;
910
+ }
911
+ has(value) {
912
+ return this.selected.includes(value);
913
+ }
914
+ toggle(value) {
915
+ this.selectedChange.emit(this.has(value) ? this.selected.filter((v) => v !== value) : [...this.selected, value]);
916
+ }
917
+ clear() {
918
+ this.selectedChange.emit([]);
919
+ }
920
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: OptionPickerComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
921
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.16", type: OptionPickerComponent, isStandalone: true, selector: "x-option-picker", inputs: { options: "options", selected: "selected", loading: "loading", noun: "noun", emptyText: "emptyText", testId: "testId" }, outputs: { selectedChange: "selectedChange" }, ngImport: i0, template: `
922
+ <div class="op" [attr.data-testid]="testId">
923
+ @if (selected.length) {
924
+ <div class="op-chips">
925
+ @for (s of selected; track s; let i = $index) {
926
+ <span class="op-chip">{{ labels[i] }}<button type="button" [attr.aria-label]="'Remove ' + labels[i]" (click)="toggle(s)">×</button></span>
927
+ }
928
+ </div>
929
+ }
930
+ @if (loading) {
931
+ <div class="rb-empty">Loading…</div>
932
+ } @else if (!options.length) {
933
+ <div class="rb-empty">{{ emptyText }}</div>
934
+ } @else {
935
+ <div class="rb-row">
936
+ <input
937
+ class="rb-input op-search"
938
+ type="search"
939
+ [placeholder]="'Search ' + noun + '…'"
940
+ [ngModel]="query"
941
+ (ngModelChange)="query = $event"
942
+ />
943
+ <span class="rb-help">{{ selected.length }} of {{ options.length }} selected</span>
944
+ <button type="button" class="rb-link" [disabled]="!selected.length" (click)="clear()">Clear</button>
945
+ </div>
946
+ <div class="op-list">
947
+ @for (o of visible; track o.value) {
948
+ <label class="op-item" [class.op-on]="has(o.value)">
949
+ <input type="checkbox" [checked]="has(o.value)" (change)="toggle(o.value)" />
950
+ <span>{{ o.label }}</span>
951
+ </label>
952
+ } @empty {
953
+ <div class="rb-empty">No {{ noun }} match “{{ query }}”.</div>
954
+ }
955
+ </div>
956
+ }
957
+ </div>
958
+ `, isInline: true, styles: [":host{display:block}.rb{display:flex;flex-direction:column;gap:12px}.rb-group{display:flex;flex-direction:column;gap:4px}.rb-label{font-size:11.5px;font-weight:700;color:var(--color-text-muted)}.rb-help{font-size:12px;font-weight:400;color:var(--color-text-muted)}.rb-row{display:flex;flex-wrap:wrap;gap:10px;align-items:center}.rb-summary{font-size:12.5px;color:var(--color-text);background:color-mix(in srgb,var(--color-accent, #0b3a82) 8%,transparent);border-radius:var(--radius-md, 8px);padding:7px 10px}.rb-input{padding:6px 10px;border:1px solid var(--color-border);border-radius:var(--radius-md, 8px);background:transparent;color:inherit;font:inherit;font-size:13px;min-width:0}.rb-input-sm{width:110px}.rb-check{display:inline-flex;align-items:center;gap:8px;font-size:13px;font-weight:600;color:var(--color-text);cursor:pointer}.rb-btn{appearance:none;border:1px solid var(--color-border);background:transparent;border-radius:var(--radius-md, 8px);padding:5px 12px;font-size:12.5px;font-weight:700;cursor:pointer;color:var(--color-text-muted)}.rb-btn:disabled{opacity:.45;cursor:default}.rb-btn-primary{border-color:var(--color-accent);color:var(--color-accent-hover, #0b3a82)}.rb-link{appearance:none;background:none;border:0;padding:2px 4px;font-size:12.5px;font-weight:700;color:var(--color-accent-hover, #0b3a82);cursor:pointer}.rb-link:disabled{opacity:.4;cursor:default}.rb-danger{color:var(--color-danger, #c0362c)}.rb-card{border:1px solid var(--color-border);border-radius:var(--radius-md, 8px);padding:10px 12px;display:flex;flex-direction:column;gap:8px}.rb-card-head{display:flex;gap:8px;align-items:center;justify-content:space-between;flex-wrap:wrap}.rb-problem{font-size:12px;font-weight:600;color:var(--color-danger, #c0362c)}.rb-field{display:flex;flex-direction:column;gap:3px;font-size:11.5px;font-weight:700;color:var(--color-text-muted)}.rb-empty{font-size:13px;color:var(--color-text-muted)}.rb-table{width:100%;border-collapse:collapse;font-size:13px}.rb-table th{text-align:left;font-size:11px;font-weight:700;color:var(--color-text-muted);padding:0 6px 4px;white-space:nowrap}.rb-table td{padding:3px 4px;vertical-align:middle}.rb-table .rb-input{width:100%;min-width:72px}.rb-scroll{overflow-x:auto}\n", ".op{display:flex;flex-direction:column;gap:8px}.op-chips{display:flex;flex-wrap:wrap;gap:6px}.op-chip{display:inline-flex;align-items:center;gap:4px;padding:2px 4px 2px 9px;border-radius:999px;background:color-mix(in srgb,var(--color-brand, #0b3a82) 12%,transparent);font-size:12px;font-weight:600;color:var(--color-text)}.op-chip button{appearance:none;border:0;background:transparent;cursor:pointer;font-size:14px;line-height:1;color:inherit;padding:0 5px}.op-search{flex:1 1 160px}.op-list{max-height:168px;overflow-y:auto;border:1px solid var(--color-border);border-radius:var(--radius-md, 8px);padding:4px;display:grid;grid-template-columns:repeat(auto-fill,minmax(190px,1fr));gap:2px}.op-item{display:flex;align-items:center;gap:8px;padding:4px 8px;border-radius:6px;font-size:13px;font-weight:500;color:var(--color-text);cursor:pointer}.op-item:hover{background:color-mix(in srgb,var(--color-text) 6%,transparent)}.op-on{font-weight:700}\n"], dependencies: [{ kind: "ngmodule", type: FormsModule }, { kind: "directive", type: i1.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { kind: "directive", type: i1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i1.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }] }); }
959
+ }
960
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: OptionPickerComponent, decorators: [{
961
+ type: Component,
962
+ args: [{ selector: 'x-option-picker', standalone: true, imports: [FormsModule], template: `
963
+ <div class="op" [attr.data-testid]="testId">
964
+ @if (selected.length) {
965
+ <div class="op-chips">
966
+ @for (s of selected; track s; let i = $index) {
967
+ <span class="op-chip">{{ labels[i] }}<button type="button" [attr.aria-label]="'Remove ' + labels[i]" (click)="toggle(s)">×</button></span>
968
+ }
969
+ </div>
970
+ }
971
+ @if (loading) {
972
+ <div class="rb-empty">Loading…</div>
973
+ } @else if (!options.length) {
974
+ <div class="rb-empty">{{ emptyText }}</div>
975
+ } @else {
976
+ <div class="rb-row">
977
+ <input
978
+ class="rb-input op-search"
979
+ type="search"
980
+ [placeholder]="'Search ' + noun + '…'"
981
+ [ngModel]="query"
982
+ (ngModelChange)="query = $event"
983
+ />
984
+ <span class="rb-help">{{ selected.length }} of {{ options.length }} selected</span>
985
+ <button type="button" class="rb-link" [disabled]="!selected.length" (click)="clear()">Clear</button>
986
+ </div>
987
+ <div class="op-list">
988
+ @for (o of visible; track o.value) {
989
+ <label class="op-item" [class.op-on]="has(o.value)">
990
+ <input type="checkbox" [checked]="has(o.value)" (change)="toggle(o.value)" />
991
+ <span>{{ o.label }}</span>
992
+ </label>
993
+ } @empty {
994
+ <div class="rb-empty">No {{ noun }} match “{{ query }}”.</div>
995
+ }
996
+ </div>
997
+ }
998
+ </div>
999
+ `, styles: [":host{display:block}.rb{display:flex;flex-direction:column;gap:12px}.rb-group{display:flex;flex-direction:column;gap:4px}.rb-label{font-size:11.5px;font-weight:700;color:var(--color-text-muted)}.rb-help{font-size:12px;font-weight:400;color:var(--color-text-muted)}.rb-row{display:flex;flex-wrap:wrap;gap:10px;align-items:center}.rb-summary{font-size:12.5px;color:var(--color-text);background:color-mix(in srgb,var(--color-accent, #0b3a82) 8%,transparent);border-radius:var(--radius-md, 8px);padding:7px 10px}.rb-input{padding:6px 10px;border:1px solid var(--color-border);border-radius:var(--radius-md, 8px);background:transparent;color:inherit;font:inherit;font-size:13px;min-width:0}.rb-input-sm{width:110px}.rb-check{display:inline-flex;align-items:center;gap:8px;font-size:13px;font-weight:600;color:var(--color-text);cursor:pointer}.rb-btn{appearance:none;border:1px solid var(--color-border);background:transparent;border-radius:var(--radius-md, 8px);padding:5px 12px;font-size:12.5px;font-weight:700;cursor:pointer;color:var(--color-text-muted)}.rb-btn:disabled{opacity:.45;cursor:default}.rb-btn-primary{border-color:var(--color-accent);color:var(--color-accent-hover, #0b3a82)}.rb-link{appearance:none;background:none;border:0;padding:2px 4px;font-size:12.5px;font-weight:700;color:var(--color-accent-hover, #0b3a82);cursor:pointer}.rb-link:disabled{opacity:.4;cursor:default}.rb-danger{color:var(--color-danger, #c0362c)}.rb-card{border:1px solid var(--color-border);border-radius:var(--radius-md, 8px);padding:10px 12px;display:flex;flex-direction:column;gap:8px}.rb-card-head{display:flex;gap:8px;align-items:center;justify-content:space-between;flex-wrap:wrap}.rb-problem{font-size:12px;font-weight:600;color:var(--color-danger, #c0362c)}.rb-field{display:flex;flex-direction:column;gap:3px;font-size:11.5px;font-weight:700;color:var(--color-text-muted)}.rb-empty{font-size:13px;color:var(--color-text-muted)}.rb-table{width:100%;border-collapse:collapse;font-size:13px}.rb-table th{text-align:left;font-size:11px;font-weight:700;color:var(--color-text-muted);padding:0 6px 4px;white-space:nowrap}.rb-table td{padding:3px 4px;vertical-align:middle}.rb-table .rb-input{width:100%;min-width:72px}.rb-scroll{overflow-x:auto}\n", ".op{display:flex;flex-direction:column;gap:8px}.op-chips{display:flex;flex-wrap:wrap;gap:6px}.op-chip{display:inline-flex;align-items:center;gap:4px;padding:2px 4px 2px 9px;border-radius:999px;background:color-mix(in srgb,var(--color-brand, #0b3a82) 12%,transparent);font-size:12px;font-weight:600;color:var(--color-text)}.op-chip button{appearance:none;border:0;background:transparent;cursor:pointer;font-size:14px;line-height:1;color:inherit;padding:0 5px}.op-search{flex:1 1 160px}.op-list{max-height:168px;overflow-y:auto;border:1px solid var(--color-border);border-radius:var(--radius-md, 8px);padding:4px;display:grid;grid-template-columns:repeat(auto-fill,minmax(190px,1fr));gap:2px}.op-item{display:flex;align-items:center;gap:8px;padding:4px 8px;border-radius:6px;font-size:13px;font-weight:500;color:var(--color-text);cursor:pointer}.op-item:hover{background:color-mix(in srgb,var(--color-text) 6%,transparent)}.op-on{font-weight:700}\n"] }]
1000
+ }], propDecorators: { options: [{
1001
+ type: Input
1002
+ }], selected: [{
1003
+ type: Input
1004
+ }], loading: [{
1005
+ type: Input
1006
+ }], noun: [{
1007
+ type: Input
1008
+ }], emptyText: [{
1009
+ type: Input
1010
+ }], testId: [{
1011
+ type: Input
1012
+ }], selectedChange: [{
1013
+ type: Output
1014
+ }] } });
1015
+
1016
+ // Promotion conditions: when the discount applies. Nothing set = every cart.
1017
+ class ConditionsBuilderComponent {
1018
+ constructor() {
1019
+ this.options = inject(RuleOptionsService);
1020
+ this.valueChange = new EventEmitter();
1021
+ this.model = toConditionsModel(undefined);
1022
+ this.segments = [];
1023
+ this.categories = [];
1024
+ this.brands = [];
1025
+ this.states = [];
1026
+ this.loading = true;
1027
+ }
1028
+ ngOnChanges(changes) {
1029
+ if (changes['value'] && this.value !== this.emitted)
1030
+ this.model = toConditionsModel(this.value);
1031
+ }
1032
+ async ngOnInit() {
1033
+ [this.segments, this.categories, this.brands, this.states] = await Promise.all([
1034
+ this.options.segments(),
1035
+ this.options.categories(),
1036
+ this.options.brands(),
1037
+ this.options.states(),
1038
+ ]);
1039
+ this.loading = false;
1040
+ }
1041
+ get summary() {
1042
+ return describeConditions(this.model, { segments: this.segments, categories: this.categories, brands: this.brands }, unknownKeys(this.value, KNOWN_CONDITION_KEYS));
1043
+ }
1044
+ emit() {
1045
+ this.emitted = fromConditionsModel(this.model, this.value);
1046
+ this.valueChange.emit(this.emitted);
1047
+ }
1048
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: ConditionsBuilderComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
1049
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.16", type: ConditionsBuilderComponent, isStandalone: true, selector: "x-conditions-builder", inputs: { value: "value" }, outputs: { valueChange: "valueChange" }, usesOnChanges: true, ngImport: i0, template: `
1050
+ <div class="rb" data-testid="conditions-builder">
1051
+ <div class="rb-summary" data-testid="conditions-summary">{{ summary }}</div>
1052
+
1053
+ <div class="rb-row">
1054
+ <label class="rb-field">Cart value from (₦)
1055
+ <input class="rb-input rb-input-sm" type="number" min="0" [ngModel]="model.cartMin" (ngModelChange)="model.cartMin = $event; emit()" data-testid="cond-cart-min" />
1056
+ </label>
1057
+ <label class="rb-field">Cart value up to (₦)
1058
+ <input class="rb-input rb-input-sm" type="number" min="0" [ngModel]="model.cartMax" (ngModelChange)="model.cartMax = $event; emit()" data-testid="cond-cart-max" />
1059
+ </label>
1060
+ <label class="rb-field">Items in cart, at least
1061
+ <input class="rb-input rb-input-sm" type="number" min="0" [ngModel]="model.itemMin" (ngModelChange)="model.itemMin = $event; emit()" data-testid="cond-item-min" />
1062
+ </label>
1063
+ <label class="rb-field">Items in cart, at most
1064
+ <input class="rb-input rb-input-sm" type="number" min="0" [ngModel]="model.itemMax" (ngModelChange)="model.itemMax = $event; emit()" />
1065
+ </label>
1066
+ </div>
1067
+
1068
+ <label class="rb-check">
1069
+ <input type="checkbox" [ngModel]="model.firstOrder" (ngModelChange)="model.firstOrder = $event; emit()" data-testid="cond-first-order" />
1070
+ Only on a customer's first order
1071
+ </label>
1072
+
1073
+ <div class="rb-group">
1074
+ <span class="rb-label">Only these categories <span class="rb-help">— discount applies to matching items; empty = any item</span></span>
1075
+ <x-option-picker noun="categories" emptyText="No categories yet." testId="cond-categories" [loading]="loading" [options]="categories" [selected]="model.categoryIds" (selectedChange)="model.categoryIds = $event; emit()"></x-option-picker>
1076
+ </div>
1077
+
1078
+ <div class="rb-group">
1079
+ <span class="rb-label">Only these brands <span class="rb-help">— empty = any brand</span></span>
1080
+ <x-option-picker noun="brands" emptyText="No brands yet." testId="cond-brands" [loading]="loading" [options]="brands" [selected]="model.brandIds" (selectedChange)="model.brandIds = $event; emit()"></x-option-picker>
1081
+ </div>
1082
+
1083
+ @if (model.categoryIds.length || model.brandIds.length) {
1084
+ <label class="rb-field">At least this many matching items in the cart
1085
+ <input class="rb-input rb-input-sm" type="number" min="0" [ngModel]="model.minEligibleQty" (ngModelChange)="model.minEligibleQty = $event; emit()" />
1086
+ </label>
1087
+ }
1088
+
1089
+ <div class="rb-group">
1090
+ <span class="rb-label">Customer groups <span class="rb-help">— empty = all customers</span></span>
1091
+ <x-option-picker noun="groups" emptyText="No customer groups exist yet." testId="cond-segments" [loading]="loading" [options]="segments" [selected]="model.segmentIds" (selectedChange)="model.segmentIds = $event; emit()"></x-option-picker>
1092
+ </div>
1093
+
1094
+ <div class="rb-group">
1095
+ <span class="rb-label">Delivery states <span class="rb-help">— empty = anywhere</span></span>
1096
+ <x-option-picker noun="states" emptyText="No states are available." testId="cond-states" [loading]="loading" [options]="states" [selected]="model.deliveryStates" (selectedChange)="model.deliveryStates = $event; emit()"></x-option-picker>
1097
+ </div>
1098
+ </div>
1099
+ `, isInline: true, styles: [":host{display:block}.rb{display:flex;flex-direction:column;gap:12px}.rb-group{display:flex;flex-direction:column;gap:4px}.rb-label{font-size:11.5px;font-weight:700;color:var(--color-text-muted)}.rb-help{font-size:12px;font-weight:400;color:var(--color-text-muted)}.rb-row{display:flex;flex-wrap:wrap;gap:10px;align-items:center}.rb-summary{font-size:12.5px;color:var(--color-text);background:color-mix(in srgb,var(--color-accent, #0b3a82) 8%,transparent);border-radius:var(--radius-md, 8px);padding:7px 10px}.rb-input{padding:6px 10px;border:1px solid var(--color-border);border-radius:var(--radius-md, 8px);background:transparent;color:inherit;font:inherit;font-size:13px;min-width:0}.rb-input-sm{width:110px}.rb-check{display:inline-flex;align-items:center;gap:8px;font-size:13px;font-weight:600;color:var(--color-text);cursor:pointer}.rb-btn{appearance:none;border:1px solid var(--color-border);background:transparent;border-radius:var(--radius-md, 8px);padding:5px 12px;font-size:12.5px;font-weight:700;cursor:pointer;color:var(--color-text-muted)}.rb-btn:disabled{opacity:.45;cursor:default}.rb-btn-primary{border-color:var(--color-accent);color:var(--color-accent-hover, #0b3a82)}.rb-link{appearance:none;background:none;border:0;padding:2px 4px;font-size:12.5px;font-weight:700;color:var(--color-accent-hover, #0b3a82);cursor:pointer}.rb-link:disabled{opacity:.4;cursor:default}.rb-danger{color:var(--color-danger, #c0362c)}.rb-card{border:1px solid var(--color-border);border-radius:var(--radius-md, 8px);padding:10px 12px;display:flex;flex-direction:column;gap:8px}.rb-card-head{display:flex;gap:8px;align-items:center;justify-content:space-between;flex-wrap:wrap}.rb-problem{font-size:12px;font-weight:600;color:var(--color-danger, #c0362c)}.rb-field{display:flex;flex-direction:column;gap:3px;font-size:11.5px;font-weight:700;color:var(--color-text-muted)}.rb-empty{font-size:13px;color:var(--color-text-muted)}.rb-table{width:100%;border-collapse:collapse;font-size:13px}.rb-table th{text-align:left;font-size:11px;font-weight:700;color:var(--color-text-muted);padding:0 6px 4px;white-space:nowrap}.rb-table td{padding:3px 4px;vertical-align:middle}.rb-table .rb-input{width:100%;min-width:72px}.rb-scroll{overflow-x:auto}\n"], dependencies: [{ kind: "ngmodule", type: FormsModule }, { kind: "directive", type: i1.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { kind: "directive", type: i1.NumberValueAccessor, selector: "input[type=number][formControlName],input[type=number][formControl],input[type=number][ngModel]" }, { kind: "directive", type: i1.CheckboxControlValueAccessor, selector: "input[type=checkbox][formControlName],input[type=checkbox][formControl],input[type=checkbox][ngModel]" }, { kind: "directive", type: i1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i1.MinValidator, selector: "input[type=number][min][formControlName],input[type=number][min][formControl],input[type=number][min][ngModel]", inputs: ["min"] }, { kind: "directive", type: i1.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }, { kind: "component", type: OptionPickerComponent, selector: "x-option-picker", inputs: ["options", "selected", "loading", "noun", "emptyText", "testId"], outputs: ["selectedChange"] }] }); }
1100
+ }
1101
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: ConditionsBuilderComponent, decorators: [{
1102
+ type: Component,
1103
+ args: [{ selector: 'x-conditions-builder', standalone: true, imports: [FormsModule, OptionPickerComponent], template: `
1104
+ <div class="rb" data-testid="conditions-builder">
1105
+ <div class="rb-summary" data-testid="conditions-summary">{{ summary }}</div>
1106
+
1107
+ <div class="rb-row">
1108
+ <label class="rb-field">Cart value from (₦)
1109
+ <input class="rb-input rb-input-sm" type="number" min="0" [ngModel]="model.cartMin" (ngModelChange)="model.cartMin = $event; emit()" data-testid="cond-cart-min" />
1110
+ </label>
1111
+ <label class="rb-field">Cart value up to (₦)
1112
+ <input class="rb-input rb-input-sm" type="number" min="0" [ngModel]="model.cartMax" (ngModelChange)="model.cartMax = $event; emit()" data-testid="cond-cart-max" />
1113
+ </label>
1114
+ <label class="rb-field">Items in cart, at least
1115
+ <input class="rb-input rb-input-sm" type="number" min="0" [ngModel]="model.itemMin" (ngModelChange)="model.itemMin = $event; emit()" data-testid="cond-item-min" />
1116
+ </label>
1117
+ <label class="rb-field">Items in cart, at most
1118
+ <input class="rb-input rb-input-sm" type="number" min="0" [ngModel]="model.itemMax" (ngModelChange)="model.itemMax = $event; emit()" />
1119
+ </label>
1120
+ </div>
1121
+
1122
+ <label class="rb-check">
1123
+ <input type="checkbox" [ngModel]="model.firstOrder" (ngModelChange)="model.firstOrder = $event; emit()" data-testid="cond-first-order" />
1124
+ Only on a customer's first order
1125
+ </label>
1126
+
1127
+ <div class="rb-group">
1128
+ <span class="rb-label">Only these categories <span class="rb-help">— discount applies to matching items; empty = any item</span></span>
1129
+ <x-option-picker noun="categories" emptyText="No categories yet." testId="cond-categories" [loading]="loading" [options]="categories" [selected]="model.categoryIds" (selectedChange)="model.categoryIds = $event; emit()"></x-option-picker>
1130
+ </div>
1131
+
1132
+ <div class="rb-group">
1133
+ <span class="rb-label">Only these brands <span class="rb-help">— empty = any brand</span></span>
1134
+ <x-option-picker noun="brands" emptyText="No brands yet." testId="cond-brands" [loading]="loading" [options]="brands" [selected]="model.brandIds" (selectedChange)="model.brandIds = $event; emit()"></x-option-picker>
1135
+ </div>
1136
+
1137
+ @if (model.categoryIds.length || model.brandIds.length) {
1138
+ <label class="rb-field">At least this many matching items in the cart
1139
+ <input class="rb-input rb-input-sm" type="number" min="0" [ngModel]="model.minEligibleQty" (ngModelChange)="model.minEligibleQty = $event; emit()" />
1140
+ </label>
1141
+ }
1142
+
1143
+ <div class="rb-group">
1144
+ <span class="rb-label">Customer groups <span class="rb-help">— empty = all customers</span></span>
1145
+ <x-option-picker noun="groups" emptyText="No customer groups exist yet." testId="cond-segments" [loading]="loading" [options]="segments" [selected]="model.segmentIds" (selectedChange)="model.segmentIds = $event; emit()"></x-option-picker>
1146
+ </div>
1147
+
1148
+ <div class="rb-group">
1149
+ <span class="rb-label">Delivery states <span class="rb-help">— empty = anywhere</span></span>
1150
+ <x-option-picker noun="states" emptyText="No states are available." testId="cond-states" [loading]="loading" [options]="states" [selected]="model.deliveryStates" (selectedChange)="model.deliveryStates = $event; emit()"></x-option-picker>
1151
+ </div>
1152
+ </div>
1153
+ `, styles: [":host{display:block}.rb{display:flex;flex-direction:column;gap:12px}.rb-group{display:flex;flex-direction:column;gap:4px}.rb-label{font-size:11.5px;font-weight:700;color:var(--color-text-muted)}.rb-help{font-size:12px;font-weight:400;color:var(--color-text-muted)}.rb-row{display:flex;flex-wrap:wrap;gap:10px;align-items:center}.rb-summary{font-size:12.5px;color:var(--color-text);background:color-mix(in srgb,var(--color-accent, #0b3a82) 8%,transparent);border-radius:var(--radius-md, 8px);padding:7px 10px}.rb-input{padding:6px 10px;border:1px solid var(--color-border);border-radius:var(--radius-md, 8px);background:transparent;color:inherit;font:inherit;font-size:13px;min-width:0}.rb-input-sm{width:110px}.rb-check{display:inline-flex;align-items:center;gap:8px;font-size:13px;font-weight:600;color:var(--color-text);cursor:pointer}.rb-btn{appearance:none;border:1px solid var(--color-border);background:transparent;border-radius:var(--radius-md, 8px);padding:5px 12px;font-size:12.5px;font-weight:700;cursor:pointer;color:var(--color-text-muted)}.rb-btn:disabled{opacity:.45;cursor:default}.rb-btn-primary{border-color:var(--color-accent);color:var(--color-accent-hover, #0b3a82)}.rb-link{appearance:none;background:none;border:0;padding:2px 4px;font-size:12.5px;font-weight:700;color:var(--color-accent-hover, #0b3a82);cursor:pointer}.rb-link:disabled{opacity:.4;cursor:default}.rb-danger{color:var(--color-danger, #c0362c)}.rb-card{border:1px solid var(--color-border);border-radius:var(--radius-md, 8px);padding:10px 12px;display:flex;flex-direction:column;gap:8px}.rb-card-head{display:flex;gap:8px;align-items:center;justify-content:space-between;flex-wrap:wrap}.rb-problem{font-size:12px;font-weight:600;color:var(--color-danger, #c0362c)}.rb-field{display:flex;flex-direction:column;gap:3px;font-size:11.5px;font-weight:700;color:var(--color-text-muted)}.rb-empty{font-size:13px;color:var(--color-text-muted)}.rb-table{width:100%;border-collapse:collapse;font-size:13px}.rb-table th{text-align:left;font-size:11px;font-weight:700;color:var(--color-text-muted);padding:0 6px 4px;white-space:nowrap}.rb-table td{padding:3px 4px;vertical-align:middle}.rb-table .rb-input{width:100%;min-width:72px}.rb-scroll{overflow-x:auto}\n"] }]
1154
+ }], propDecorators: { value: [{
1155
+ type: Input
1156
+ }], valueChange: [{
1157
+ type: Output
1158
+ }] } });
1159
+
1160
+ // Manual shipping rate tiers. The first tier whose weight / order-value
1161
+ // range fits the cart is the one charged, so order matters.
1162
+ class RateRulesBuilderComponent {
1163
+ constructor() {
1164
+ this.valueChange = new EventEmitter();
1165
+ this.rows = [];
1166
+ this.describe = describeRateRule;
1167
+ }
1168
+ ngOnChanges(changes) {
1169
+ if (changes['value'] && this.value !== this.emitted)
1170
+ this.rows = toRateRuleRows(this.value);
1171
+ }
1172
+ add() {
1173
+ this.rows.push({ extra: {} });
1174
+ this.emit();
1175
+ }
1176
+ remove(i) {
1177
+ this.rows.splice(i, 1);
1178
+ this.emit();
1179
+ }
1180
+ move(i, by) {
1181
+ const j = i + by;
1182
+ if (j < 0 || j >= this.rows.length)
1183
+ return;
1184
+ [this.rows[i], this.rows[j]] = [this.rows[j], this.rows[i]];
1185
+ this.emit();
1186
+ }
1187
+ emit() {
1188
+ this.emitted = fromRateRuleRows(this.rows);
1189
+ this.valueChange.emit(this.emitted);
1190
+ }
1191
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: RateRulesBuilderComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
1192
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.16", type: RateRulesBuilderComponent, isStandalone: true, selector: "x-rate-rules-builder", inputs: { value: "value" }, outputs: { valueChange: "valueChange" }, usesOnChanges: true, ngImport: i0, template: `
1193
+ <div class="rb" data-testid="rate-rules-builder">
1194
+ <div class="rb-help">
1195
+ The first tier that fits the parcel is charged, so put the most specific tiers at the top. Leave a range box empty
1196
+ for “no limit”.
1197
+ </div>
1198
+
1199
+ @if (!rows.length) {
1200
+ <div class="rb-empty">No tiers yet.</div>
1201
+ } @else {
1202
+ <div class="rb-scroll">
1203
+ <table class="rb-table">
1204
+ <thead>
1205
+ <tr>
1206
+ <th>Weight from (kg)</th><th>Weight to (kg)</th>
1207
+ <th>Order from (₦)</th><th>Order to (₦)</th>
1208
+ <th>Fee (₦)</th><th>Extra per kg (₦)</th><th>Free over (₦)</th><th></th>
1209
+ </tr>
1210
+ </thead>
1211
+ <tbody>
1212
+ @for (r of rows; track $index; let i = $index) {
1213
+ <tr [attr.data-testid]="'rate-row-' + i">
1214
+ <td><input class="rb-input" type="number" min="0" [ngModel]="r.minWeightKg" (ngModelChange)="r.minWeightKg = $event; emit()" /></td>
1215
+ <td><input class="rb-input" type="number" min="0" [ngModel]="r.maxWeightKg" (ngModelChange)="r.maxWeightKg = $event; emit()" /></td>
1216
+ <td><input class="rb-input" type="number" min="0" [ngModel]="r.minSubtotal" (ngModelChange)="r.minSubtotal = $event; emit()" /></td>
1217
+ <td><input class="rb-input" type="number" min="0" [ngModel]="r.maxSubtotal" (ngModelChange)="r.maxSubtotal = $event; emit()" /></td>
1218
+ <td><input class="rb-input" type="number" min="0" [ngModel]="r.flatFee" (ngModelChange)="r.flatFee = $event; emit()" [attr.data-testid]="'rate-fee-' + i" /></td>
1219
+ <td><input class="rb-input" type="number" min="0" [ngModel]="r.perKg" (ngModelChange)="r.perKg = $event; emit()" /></td>
1220
+ <td><input class="rb-input" type="number" min="0" [ngModel]="r.freeOverSubtotal" (ngModelChange)="r.freeOverSubtotal = $event; emit()" /></td>
1221
+ <td style="white-space: nowrap">
1222
+ <button type="button" class="rb-link" [disabled]="i === 0" (click)="move(i, -1)" aria-label="Move up">↑</button>
1223
+ <button type="button" class="rb-link" [disabled]="i === rows.length - 1" (click)="move(i, 1)" aria-label="Move down">↓</button>
1224
+ <button type="button" class="rb-link rb-danger" (click)="remove(i)" aria-label="Remove tier">×</button>
1225
+ </td>
1226
+ </tr>
1227
+ }
1228
+ </tbody>
1229
+ </table>
1230
+ </div>
1231
+ <div class="rb-summary" data-testid="rate-summary">
1232
+ @for (r of rows; track $index) {
1233
+ <div>{{ $index + 1 }}. {{ describe(r) }}</div>
1234
+ }
1235
+ </div>
1236
+ }
1237
+
1238
+ <div><button type="button" class="rb-btn rb-btn-primary" (click)="add()" data-testid="rate-add">+ Add tier</button></div>
1239
+ </div>
1240
+ `, isInline: true, styles: [":host{display:block}.rb{display:flex;flex-direction:column;gap:12px}.rb-group{display:flex;flex-direction:column;gap:4px}.rb-label{font-size:11.5px;font-weight:700;color:var(--color-text-muted)}.rb-help{font-size:12px;font-weight:400;color:var(--color-text-muted)}.rb-row{display:flex;flex-wrap:wrap;gap:10px;align-items:center}.rb-summary{font-size:12.5px;color:var(--color-text);background:color-mix(in srgb,var(--color-accent, #0b3a82) 8%,transparent);border-radius:var(--radius-md, 8px);padding:7px 10px}.rb-input{padding:6px 10px;border:1px solid var(--color-border);border-radius:var(--radius-md, 8px);background:transparent;color:inherit;font:inherit;font-size:13px;min-width:0}.rb-input-sm{width:110px}.rb-check{display:inline-flex;align-items:center;gap:8px;font-size:13px;font-weight:600;color:var(--color-text);cursor:pointer}.rb-btn{appearance:none;border:1px solid var(--color-border);background:transparent;border-radius:var(--radius-md, 8px);padding:5px 12px;font-size:12.5px;font-weight:700;cursor:pointer;color:var(--color-text-muted)}.rb-btn:disabled{opacity:.45;cursor:default}.rb-btn-primary{border-color:var(--color-accent);color:var(--color-accent-hover, #0b3a82)}.rb-link{appearance:none;background:none;border:0;padding:2px 4px;font-size:12.5px;font-weight:700;color:var(--color-accent-hover, #0b3a82);cursor:pointer}.rb-link:disabled{opacity:.4;cursor:default}.rb-danger{color:var(--color-danger, #c0362c)}.rb-card{border:1px solid var(--color-border);border-radius:var(--radius-md, 8px);padding:10px 12px;display:flex;flex-direction:column;gap:8px}.rb-card-head{display:flex;gap:8px;align-items:center;justify-content:space-between;flex-wrap:wrap}.rb-problem{font-size:12px;font-weight:600;color:var(--color-danger, #c0362c)}.rb-field{display:flex;flex-direction:column;gap:3px;font-size:11.5px;font-weight:700;color:var(--color-text-muted)}.rb-empty{font-size:13px;color:var(--color-text-muted)}.rb-table{width:100%;border-collapse:collapse;font-size:13px}.rb-table th{text-align:left;font-size:11px;font-weight:700;color:var(--color-text-muted);padding:0 6px 4px;white-space:nowrap}.rb-table td{padding:3px 4px;vertical-align:middle}.rb-table .rb-input{width:100%;min-width:72px}.rb-scroll{overflow-x:auto}\n"], dependencies: [{ kind: "ngmodule", type: FormsModule }, { kind: "directive", type: i1.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { kind: "directive", type: i1.NumberValueAccessor, selector: "input[type=number][formControlName],input[type=number][formControl],input[type=number][ngModel]" }, { kind: "directive", type: i1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i1.MinValidator, selector: "input[type=number][min][formControlName],input[type=number][min][formControl],input[type=number][min][ngModel]", inputs: ["min"] }, { kind: "directive", type: i1.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }] }); }
1241
+ }
1242
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: RateRulesBuilderComponent, decorators: [{
1243
+ type: Component,
1244
+ args: [{ selector: 'x-rate-rules-builder', standalone: true, imports: [FormsModule], template: `
1245
+ <div class="rb" data-testid="rate-rules-builder">
1246
+ <div class="rb-help">
1247
+ The first tier that fits the parcel is charged, so put the most specific tiers at the top. Leave a range box empty
1248
+ for “no limit”.
1249
+ </div>
1250
+
1251
+ @if (!rows.length) {
1252
+ <div class="rb-empty">No tiers yet.</div>
1253
+ } @else {
1254
+ <div class="rb-scroll">
1255
+ <table class="rb-table">
1256
+ <thead>
1257
+ <tr>
1258
+ <th>Weight from (kg)</th><th>Weight to (kg)</th>
1259
+ <th>Order from (₦)</th><th>Order to (₦)</th>
1260
+ <th>Fee (₦)</th><th>Extra per kg (₦)</th><th>Free over (₦)</th><th></th>
1261
+ </tr>
1262
+ </thead>
1263
+ <tbody>
1264
+ @for (r of rows; track $index; let i = $index) {
1265
+ <tr [attr.data-testid]="'rate-row-' + i">
1266
+ <td><input class="rb-input" type="number" min="0" [ngModel]="r.minWeightKg" (ngModelChange)="r.minWeightKg = $event; emit()" /></td>
1267
+ <td><input class="rb-input" type="number" min="0" [ngModel]="r.maxWeightKg" (ngModelChange)="r.maxWeightKg = $event; emit()" /></td>
1268
+ <td><input class="rb-input" type="number" min="0" [ngModel]="r.minSubtotal" (ngModelChange)="r.minSubtotal = $event; emit()" /></td>
1269
+ <td><input class="rb-input" type="number" min="0" [ngModel]="r.maxSubtotal" (ngModelChange)="r.maxSubtotal = $event; emit()" /></td>
1270
+ <td><input class="rb-input" type="number" min="0" [ngModel]="r.flatFee" (ngModelChange)="r.flatFee = $event; emit()" [attr.data-testid]="'rate-fee-' + i" /></td>
1271
+ <td><input class="rb-input" type="number" min="0" [ngModel]="r.perKg" (ngModelChange)="r.perKg = $event; emit()" /></td>
1272
+ <td><input class="rb-input" type="number" min="0" [ngModel]="r.freeOverSubtotal" (ngModelChange)="r.freeOverSubtotal = $event; emit()" /></td>
1273
+ <td style="white-space: nowrap">
1274
+ <button type="button" class="rb-link" [disabled]="i === 0" (click)="move(i, -1)" aria-label="Move up">↑</button>
1275
+ <button type="button" class="rb-link" [disabled]="i === rows.length - 1" (click)="move(i, 1)" aria-label="Move down">↓</button>
1276
+ <button type="button" class="rb-link rb-danger" (click)="remove(i)" aria-label="Remove tier">×</button>
1277
+ </td>
1278
+ </tr>
1279
+ }
1280
+ </tbody>
1281
+ </table>
1282
+ </div>
1283
+ <div class="rb-summary" data-testid="rate-summary">
1284
+ @for (r of rows; track $index) {
1285
+ <div>{{ $index + 1 }}. {{ describe(r) }}</div>
1286
+ }
1287
+ </div>
1288
+ }
1289
+
1290
+ <div><button type="button" class="rb-btn rb-btn-primary" (click)="add()" data-testid="rate-add">+ Add tier</button></div>
1291
+ </div>
1292
+ `, styles: [":host{display:block}.rb{display:flex;flex-direction:column;gap:12px}.rb-group{display:flex;flex-direction:column;gap:4px}.rb-label{font-size:11.5px;font-weight:700;color:var(--color-text-muted)}.rb-help{font-size:12px;font-weight:400;color:var(--color-text-muted)}.rb-row{display:flex;flex-wrap:wrap;gap:10px;align-items:center}.rb-summary{font-size:12.5px;color:var(--color-text);background:color-mix(in srgb,var(--color-accent, #0b3a82) 8%,transparent);border-radius:var(--radius-md, 8px);padding:7px 10px}.rb-input{padding:6px 10px;border:1px solid var(--color-border);border-radius:var(--radius-md, 8px);background:transparent;color:inherit;font:inherit;font-size:13px;min-width:0}.rb-input-sm{width:110px}.rb-check{display:inline-flex;align-items:center;gap:8px;font-size:13px;font-weight:600;color:var(--color-text);cursor:pointer}.rb-btn{appearance:none;border:1px solid var(--color-border);background:transparent;border-radius:var(--radius-md, 8px);padding:5px 12px;font-size:12.5px;font-weight:700;cursor:pointer;color:var(--color-text-muted)}.rb-btn:disabled{opacity:.45;cursor:default}.rb-btn-primary{border-color:var(--color-accent);color:var(--color-accent-hover, #0b3a82)}.rb-link{appearance:none;background:none;border:0;padding:2px 4px;font-size:12.5px;font-weight:700;color:var(--color-accent-hover, #0b3a82);cursor:pointer}.rb-link:disabled{opacity:.4;cursor:default}.rb-danger{color:var(--color-danger, #c0362c)}.rb-card{border:1px solid var(--color-border);border-radius:var(--radius-md, 8px);padding:10px 12px;display:flex;flex-direction:column;gap:8px}.rb-card-head{display:flex;gap:8px;align-items:center;justify-content:space-between;flex-wrap:wrap}.rb-problem{font-size:12px;font-weight:600;color:var(--color-danger, #c0362c)}.rb-field{display:flex;flex-direction:column;gap:3px;font-size:11.5px;font-weight:700;color:var(--color-text-muted)}.rb-empty{font-size:13px;color:var(--color-text-muted)}.rb-table{width:100%;border-collapse:collapse;font-size:13px}.rb-table th{text-align:left;font-size:11px;font-weight:700;color:var(--color-text-muted);padding:0 6px 4px;white-space:nowrap}.rb-table td{padding:3px 4px;vertical-align:middle}.rb-table .rb-input{width:100%;min-width:72px}.rb-scroll{overflow-x:auto}\n"] }]
1293
+ }], propDecorators: { value: [{
1294
+ type: Input
1295
+ }], valueChange: [{
1296
+ type: Output
1297
+ }] } });
1298
+
1299
+ // Banner audience: who sees it. Nothing ticked = everyone.
1300
+ class TargetingBuilderComponent {
1301
+ constructor() {
1302
+ this.options = inject(RuleOptionsService);
1303
+ this.valueChange = new EventEmitter();
1304
+ this.model = toTargetingModel(undefined);
1305
+ this.segments = [];
1306
+ this.channels = [];
1307
+ this.states = [];
1308
+ this.loading = true;
1309
+ }
1310
+ ngOnChanges(changes) {
1311
+ // Ignore the echo of our own emit; rebuild only for an outside change.
1312
+ if (changes['value'] && this.value !== this.emitted)
1313
+ this.model = toTargetingModel(this.value);
1314
+ }
1315
+ async ngOnInit() {
1316
+ [this.segments, this.channels, this.states] = await Promise.all([
1317
+ this.options.segments(),
1318
+ this.options.channels(),
1319
+ this.options.states(),
1320
+ ]);
1321
+ this.loading = false;
1322
+ }
1323
+ get summary() {
1324
+ return describeTargeting(this.model, this.segments, this.channels);
1325
+ }
1326
+ emit() {
1327
+ this.emitted = fromTargetingModel(this.model, this.value);
1328
+ this.valueChange.emit(this.emitted);
1329
+ }
1330
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: TargetingBuilderComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
1331
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "21.2.16", type: TargetingBuilderComponent, isStandalone: true, selector: "x-targeting-builder", inputs: { value: "value" }, outputs: { valueChange: "valueChange" }, usesOnChanges: true, ngImport: i0, template: `
1332
+ <div class="rb" data-testid="targeting-builder">
1333
+ <div class="rb-summary" data-testid="targeting-summary">{{ summary }}</div>
1334
+
1335
+ <label class="rb-check">
1336
+ <input type="checkbox" [ngModel]="model.newVisitorOnly" (ngModelChange)="model.newVisitorOnly = $event; emit()" data-testid="targeting-new-visitors" />
1337
+ Only show to first-time visitors
1338
+ </label>
1339
+
1340
+ <div class="rb-group">
1341
+ <span class="rb-label">Customer groups <span class="rb-help">— leave empty for all customers</span></span>
1342
+ <x-option-picker
1343
+ noun="groups"
1344
+ emptyText="No customer groups exist yet."
1345
+ testId="targeting-segments"
1346
+ [loading]="loading"
1347
+ [options]="segments"
1348
+ [selected]="model.segmentIds"
1349
+ (selectedChange)="model.segmentIds = $event; emit()"
1350
+ ></x-option-picker>
1351
+ </div>
1352
+
1353
+ <div class="rb-group">
1354
+ <span class="rb-label">Delivery states <span class="rb-help">— leave empty for everywhere</span></span>
1355
+ <x-option-picker
1356
+ noun="states"
1357
+ emptyText="No states are available."
1358
+ testId="targeting-states"
1359
+ [loading]="loading"
1360
+ [options]="states"
1361
+ [selected]="model.states"
1362
+ (selectedChange)="model.states = $event; emit()"
1363
+ ></x-option-picker>
1364
+ </div>
1365
+
1366
+ <div class="rb-group">
1367
+ <span class="rb-label">Sales channels <span class="rb-help">— leave empty for all channels</span></span>
1368
+ <x-option-picker
1369
+ noun="channels"
1370
+ emptyText="No sales channels exist yet."
1371
+ testId="targeting-channels"
1372
+ [loading]="loading"
1373
+ [options]="channels"
1374
+ [selected]="model.channelIds"
1375
+ (selectedChange)="model.channelIds = $event; emit()"
1376
+ ></x-option-picker>
1377
+ </div>
1378
+ </div>
1379
+ `, isInline: true, styles: [":host{display:block}.rb{display:flex;flex-direction:column;gap:12px}.rb-group{display:flex;flex-direction:column;gap:4px}.rb-label{font-size:11.5px;font-weight:700;color:var(--color-text-muted)}.rb-help{font-size:12px;font-weight:400;color:var(--color-text-muted)}.rb-row{display:flex;flex-wrap:wrap;gap:10px;align-items:center}.rb-summary{font-size:12.5px;color:var(--color-text);background:color-mix(in srgb,var(--color-accent, #0b3a82) 8%,transparent);border-radius:var(--radius-md, 8px);padding:7px 10px}.rb-input{padding:6px 10px;border:1px solid var(--color-border);border-radius:var(--radius-md, 8px);background:transparent;color:inherit;font:inherit;font-size:13px;min-width:0}.rb-input-sm{width:110px}.rb-check{display:inline-flex;align-items:center;gap:8px;font-size:13px;font-weight:600;color:var(--color-text);cursor:pointer}.rb-btn{appearance:none;border:1px solid var(--color-border);background:transparent;border-radius:var(--radius-md, 8px);padding:5px 12px;font-size:12.5px;font-weight:700;cursor:pointer;color:var(--color-text-muted)}.rb-btn:disabled{opacity:.45;cursor:default}.rb-btn-primary{border-color:var(--color-accent);color:var(--color-accent-hover, #0b3a82)}.rb-link{appearance:none;background:none;border:0;padding:2px 4px;font-size:12.5px;font-weight:700;color:var(--color-accent-hover, #0b3a82);cursor:pointer}.rb-link:disabled{opacity:.4;cursor:default}.rb-danger{color:var(--color-danger, #c0362c)}.rb-card{border:1px solid var(--color-border);border-radius:var(--radius-md, 8px);padding:10px 12px;display:flex;flex-direction:column;gap:8px}.rb-card-head{display:flex;gap:8px;align-items:center;justify-content:space-between;flex-wrap:wrap}.rb-problem{font-size:12px;font-weight:600;color:var(--color-danger, #c0362c)}.rb-field{display:flex;flex-direction:column;gap:3px;font-size:11.5px;font-weight:700;color:var(--color-text-muted)}.rb-empty{font-size:13px;color:var(--color-text-muted)}.rb-table{width:100%;border-collapse:collapse;font-size:13px}.rb-table th{text-align:left;font-size:11px;font-weight:700;color:var(--color-text-muted);padding:0 6px 4px;white-space:nowrap}.rb-table td{padding:3px 4px;vertical-align:middle}.rb-table .rb-input{width:100%;min-width:72px}.rb-scroll{overflow-x:auto}\n"], dependencies: [{ kind: "ngmodule", type: FormsModule }, { kind: "directive", type: i1.CheckboxControlValueAccessor, selector: "input[type=checkbox][formControlName],input[type=checkbox][formControl],input[type=checkbox][ngModel]" }, { kind: "directive", type: i1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i1.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }, { kind: "component", type: OptionPickerComponent, selector: "x-option-picker", inputs: ["options", "selected", "loading", "noun", "emptyText", "testId"], outputs: ["selectedChange"] }] }); }
1380
+ }
1381
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: TargetingBuilderComponent, decorators: [{
1382
+ type: Component,
1383
+ args: [{ selector: 'x-targeting-builder', standalone: true, imports: [FormsModule, OptionPickerComponent], template: `
1384
+ <div class="rb" data-testid="targeting-builder">
1385
+ <div class="rb-summary" data-testid="targeting-summary">{{ summary }}</div>
1386
+
1387
+ <label class="rb-check">
1388
+ <input type="checkbox" [ngModel]="model.newVisitorOnly" (ngModelChange)="model.newVisitorOnly = $event; emit()" data-testid="targeting-new-visitors" />
1389
+ Only show to first-time visitors
1390
+ </label>
1391
+
1392
+ <div class="rb-group">
1393
+ <span class="rb-label">Customer groups <span class="rb-help">— leave empty for all customers</span></span>
1394
+ <x-option-picker
1395
+ noun="groups"
1396
+ emptyText="No customer groups exist yet."
1397
+ testId="targeting-segments"
1398
+ [loading]="loading"
1399
+ [options]="segments"
1400
+ [selected]="model.segmentIds"
1401
+ (selectedChange)="model.segmentIds = $event; emit()"
1402
+ ></x-option-picker>
1403
+ </div>
1404
+
1405
+ <div class="rb-group">
1406
+ <span class="rb-label">Delivery states <span class="rb-help">— leave empty for everywhere</span></span>
1407
+ <x-option-picker
1408
+ noun="states"
1409
+ emptyText="No states are available."
1410
+ testId="targeting-states"
1411
+ [loading]="loading"
1412
+ [options]="states"
1413
+ [selected]="model.states"
1414
+ (selectedChange)="model.states = $event; emit()"
1415
+ ></x-option-picker>
1416
+ </div>
1417
+
1418
+ <div class="rb-group">
1419
+ <span class="rb-label">Sales channels <span class="rb-help">— leave empty for all channels</span></span>
1420
+ <x-option-picker
1421
+ noun="channels"
1422
+ emptyText="No sales channels exist yet."
1423
+ testId="targeting-channels"
1424
+ [loading]="loading"
1425
+ [options]="channels"
1426
+ [selected]="model.channelIds"
1427
+ (selectedChange)="model.channelIds = $event; emit()"
1428
+ ></x-option-picker>
1429
+ </div>
1430
+ </div>
1431
+ `, styles: [":host{display:block}.rb{display:flex;flex-direction:column;gap:12px}.rb-group{display:flex;flex-direction:column;gap:4px}.rb-label{font-size:11.5px;font-weight:700;color:var(--color-text-muted)}.rb-help{font-size:12px;font-weight:400;color:var(--color-text-muted)}.rb-row{display:flex;flex-wrap:wrap;gap:10px;align-items:center}.rb-summary{font-size:12.5px;color:var(--color-text);background:color-mix(in srgb,var(--color-accent, #0b3a82) 8%,transparent);border-radius:var(--radius-md, 8px);padding:7px 10px}.rb-input{padding:6px 10px;border:1px solid var(--color-border);border-radius:var(--radius-md, 8px);background:transparent;color:inherit;font:inherit;font-size:13px;min-width:0}.rb-input-sm{width:110px}.rb-check{display:inline-flex;align-items:center;gap:8px;font-size:13px;font-weight:600;color:var(--color-text);cursor:pointer}.rb-btn{appearance:none;border:1px solid var(--color-border);background:transparent;border-radius:var(--radius-md, 8px);padding:5px 12px;font-size:12.5px;font-weight:700;cursor:pointer;color:var(--color-text-muted)}.rb-btn:disabled{opacity:.45;cursor:default}.rb-btn-primary{border-color:var(--color-accent);color:var(--color-accent-hover, #0b3a82)}.rb-link{appearance:none;background:none;border:0;padding:2px 4px;font-size:12.5px;font-weight:700;color:var(--color-accent-hover, #0b3a82);cursor:pointer}.rb-link:disabled{opacity:.4;cursor:default}.rb-danger{color:var(--color-danger, #c0362c)}.rb-card{border:1px solid var(--color-border);border-radius:var(--radius-md, 8px);padding:10px 12px;display:flex;flex-direction:column;gap:8px}.rb-card-head{display:flex;gap:8px;align-items:center;justify-content:space-between;flex-wrap:wrap}.rb-problem{font-size:12px;font-weight:600;color:var(--color-danger, #c0362c)}.rb-field{display:flex;flex-direction:column;gap:3px;font-size:11.5px;font-weight:700;color:var(--color-text-muted)}.rb-empty{font-size:13px;color:var(--color-text-muted)}.rb-table{width:100%;border-collapse:collapse;font-size:13px}.rb-table th{text-align:left;font-size:11px;font-weight:700;color:var(--color-text-muted);padding:0 6px 4px;white-space:nowrap}.rb-table td{padding:3px 4px;vertical-align:middle}.rb-table .rb-input{width:100%;min-width:72px}.rb-scroll{overflow-x:auto}\n"] }]
1432
+ }], propDecorators: { value: [{
1433
+ type: Input
1434
+ }], valueChange: [{
1435
+ type: Output
1436
+ }] } });
1437
+
1438
+ // One drop-in field editor for the structured values that used to be raw
1439
+ // JSON textareas: shows the point-and-click builder for `kind`, with a small
1440
+ // "Edit as JSON" switch for engineers. The JSON view only applies what
1441
+ // parses to the right shape (object vs. array); otherwise it says so and
1442
+ // keeps the last good value, so a half-typed edit can never wipe a field.
1443
+ class JsonBuilderComponent {
1444
+ constructor() {
1445
+ this.valueChange = new EventEmitter();
1446
+ this.jsonMode = false;
1447
+ this.text = '';
1448
+ this.error = '';
1449
+ }
1450
+ get isArrayKind() {
1451
+ return this.kind === 'actions' || this.kind === 'rateRules';
1452
+ }
1453
+ set(next) {
1454
+ this.value = next;
1455
+ this.valueChange.emit(next);
1456
+ }
1457
+ toggleJson() {
1458
+ if (!this.jsonMode) {
1459
+ this.text = JSON.stringify(this.value ?? (this.isArrayKind ? [] : {}), null, 2);
1460
+ this.error = '';
1461
+ }
1462
+ this.jsonMode = !this.jsonMode;
1463
+ }
1464
+ onText(text) {
1465
+ this.text = text;
1466
+ if (!text.trim()) {
1467
+ this.error = '';
1468
+ this.set(this.isArrayKind ? [] : {});
1469
+ return;
1470
+ }
1471
+ try {
1472
+ const parsed = JSON.parse(text);
1473
+ const isArray = Array.isArray(parsed);
1474
+ if (this.isArrayKind !== isArray || (!isArray && (parsed === null || typeof parsed !== 'object'))) {
1475
+ this.error = this.isArrayKind ? 'This needs a list, like [ { … } ].' : 'This needs an object, like { … }.';
1476
+ return;
1477
+ }
1478
+ this.error = '';
1479
+ this.set(parsed);
1480
+ }
1481
+ catch (e) {
1482
+ this.error = `Not valid JSON yet (${e.message}) — your last valid version is kept.`;
1483
+ }
1484
+ }
1485
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: JsonBuilderComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
1486
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.16", type: JsonBuilderComponent, isStandalone: true, selector: "x-json-builder", inputs: { kind: "kind", value: "value" }, outputs: { valueChange: "valueChange" }, ngImport: i0, template: `
1487
+ <div class="jb" [attr.data-testid]="'json-builder-' + kind">
1488
+ <div class="jb-bar">
1489
+ <button type="button" class="rb-link" (click)="toggleJson()" data-testid="json-toggle">
1490
+ {{ jsonMode ? '← Back to the form' : 'Edit as JSON' }}
1491
+ </button>
1492
+ </div>
1493
+
1494
+ @if (jsonMode) {
1495
+ <textarea
1496
+ class="rb-input jb-json"
1497
+ rows="9"
1498
+ spellcheck="false"
1499
+ [ngModel]="text"
1500
+ (ngModelChange)="onText($event)"
1501
+ data-testid="json-text"
1502
+ ></textarea>
1503
+ @if (error) {
1504
+ <div class="rb-problem" data-testid="json-error">{{ error }}</div>
1505
+ } @else {
1506
+ <div class="rb-help">Valid JSON — changes apply as you type.</div>
1507
+ }
1508
+ } @else {
1509
+ @switch (kind) {
1510
+ @case ('targeting') {
1511
+ <x-targeting-builder [value]="value" (valueChange)="set($event)"></x-targeting-builder>
1512
+ }
1513
+ @case ('conditions') {
1514
+ <x-conditions-builder [value]="value" (valueChange)="set($event)"></x-conditions-builder>
1515
+ }
1516
+ @case ('actions') {
1517
+ <x-actions-builder [value]="value" (valueChange)="set($event)"></x-actions-builder>
1518
+ }
1519
+ @case ('rateRules') {
1520
+ <x-rate-rules-builder [value]="value" (valueChange)="set($event)"></x-rate-rules-builder>
1521
+ }
1522
+ }
1523
+ }
1524
+ </div>
1525
+ `, isInline: true, styles: [":host{display:block}.rb{display:flex;flex-direction:column;gap:12px}.rb-group{display:flex;flex-direction:column;gap:4px}.rb-label{font-size:11.5px;font-weight:700;color:var(--color-text-muted)}.rb-help{font-size:12px;font-weight:400;color:var(--color-text-muted)}.rb-row{display:flex;flex-wrap:wrap;gap:10px;align-items:center}.rb-summary{font-size:12.5px;color:var(--color-text);background:color-mix(in srgb,var(--color-accent, #0b3a82) 8%,transparent);border-radius:var(--radius-md, 8px);padding:7px 10px}.rb-input{padding:6px 10px;border:1px solid var(--color-border);border-radius:var(--radius-md, 8px);background:transparent;color:inherit;font:inherit;font-size:13px;min-width:0}.rb-input-sm{width:110px}.rb-check{display:inline-flex;align-items:center;gap:8px;font-size:13px;font-weight:600;color:var(--color-text);cursor:pointer}.rb-btn{appearance:none;border:1px solid var(--color-border);background:transparent;border-radius:var(--radius-md, 8px);padding:5px 12px;font-size:12.5px;font-weight:700;cursor:pointer;color:var(--color-text-muted)}.rb-btn:disabled{opacity:.45;cursor:default}.rb-btn-primary{border-color:var(--color-accent);color:var(--color-accent-hover, #0b3a82)}.rb-link{appearance:none;background:none;border:0;padding:2px 4px;font-size:12.5px;font-weight:700;color:var(--color-accent-hover, #0b3a82);cursor:pointer}.rb-link:disabled{opacity:.4;cursor:default}.rb-danger{color:var(--color-danger, #c0362c)}.rb-card{border:1px solid var(--color-border);border-radius:var(--radius-md, 8px);padding:10px 12px;display:flex;flex-direction:column;gap:8px}.rb-card-head{display:flex;gap:8px;align-items:center;justify-content:space-between;flex-wrap:wrap}.rb-problem{font-size:12px;font-weight:600;color:var(--color-danger, #c0362c)}.rb-field{display:flex;flex-direction:column;gap:3px;font-size:11.5px;font-weight:700;color:var(--color-text-muted)}.rb-empty{font-size:13px;color:var(--color-text-muted)}.rb-table{width:100%;border-collapse:collapse;font-size:13px}.rb-table th{text-align:left;font-size:11px;font-weight:700;color:var(--color-text-muted);padding:0 6px 4px;white-space:nowrap}.rb-table td{padding:3px 4px;vertical-align:middle}.rb-table .rb-input{width:100%;min-width:72px}.rb-scroll{overflow-x:auto}\n", ".jb{border:1px solid var(--color-border);border-radius:var(--radius-md, 8px);padding:10px 12px;display:flex;flex-direction:column;gap:8px}.jb-bar{display:flex;justify-content:flex-end}.jb-json{font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:12.5px;width:100%;resize:vertical}\n"], dependencies: [{ kind: "ngmodule", type: FormsModule }, { kind: "directive", type: i1.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { kind: "directive", type: i1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i1.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }, { kind: "component", type: TargetingBuilderComponent, selector: "x-targeting-builder", inputs: ["value"], outputs: ["valueChange"] }, { kind: "component", type: ConditionsBuilderComponent, selector: "x-conditions-builder", inputs: ["value"], outputs: ["valueChange"] }, { kind: "component", type: ActionsBuilderComponent, selector: "x-actions-builder", inputs: ["value"], outputs: ["valueChange"] }, { kind: "component", type: RateRulesBuilderComponent, selector: "x-rate-rules-builder", inputs: ["value"], outputs: ["valueChange"] }] }); }
1526
+ }
1527
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: JsonBuilderComponent, decorators: [{
1528
+ type: Component,
1529
+ args: [{ selector: 'x-json-builder', standalone: true, imports: [FormsModule, TargetingBuilderComponent, ConditionsBuilderComponent, ActionsBuilderComponent, RateRulesBuilderComponent], template: `
1530
+ <div class="jb" [attr.data-testid]="'json-builder-' + kind">
1531
+ <div class="jb-bar">
1532
+ <button type="button" class="rb-link" (click)="toggleJson()" data-testid="json-toggle">
1533
+ {{ jsonMode ? '← Back to the form' : 'Edit as JSON' }}
1534
+ </button>
1535
+ </div>
1536
+
1537
+ @if (jsonMode) {
1538
+ <textarea
1539
+ class="rb-input jb-json"
1540
+ rows="9"
1541
+ spellcheck="false"
1542
+ [ngModel]="text"
1543
+ (ngModelChange)="onText($event)"
1544
+ data-testid="json-text"
1545
+ ></textarea>
1546
+ @if (error) {
1547
+ <div class="rb-problem" data-testid="json-error">{{ error }}</div>
1548
+ } @else {
1549
+ <div class="rb-help">Valid JSON — changes apply as you type.</div>
1550
+ }
1551
+ } @else {
1552
+ @switch (kind) {
1553
+ @case ('targeting') {
1554
+ <x-targeting-builder [value]="value" (valueChange)="set($event)"></x-targeting-builder>
1555
+ }
1556
+ @case ('conditions') {
1557
+ <x-conditions-builder [value]="value" (valueChange)="set($event)"></x-conditions-builder>
1558
+ }
1559
+ @case ('actions') {
1560
+ <x-actions-builder [value]="value" (valueChange)="set($event)"></x-actions-builder>
1561
+ }
1562
+ @case ('rateRules') {
1563
+ <x-rate-rules-builder [value]="value" (valueChange)="set($event)"></x-rate-rules-builder>
1564
+ }
1565
+ }
1566
+ }
1567
+ </div>
1568
+ `, styles: [":host{display:block}.rb{display:flex;flex-direction:column;gap:12px}.rb-group{display:flex;flex-direction:column;gap:4px}.rb-label{font-size:11.5px;font-weight:700;color:var(--color-text-muted)}.rb-help{font-size:12px;font-weight:400;color:var(--color-text-muted)}.rb-row{display:flex;flex-wrap:wrap;gap:10px;align-items:center}.rb-summary{font-size:12.5px;color:var(--color-text);background:color-mix(in srgb,var(--color-accent, #0b3a82) 8%,transparent);border-radius:var(--radius-md, 8px);padding:7px 10px}.rb-input{padding:6px 10px;border:1px solid var(--color-border);border-radius:var(--radius-md, 8px);background:transparent;color:inherit;font:inherit;font-size:13px;min-width:0}.rb-input-sm{width:110px}.rb-check{display:inline-flex;align-items:center;gap:8px;font-size:13px;font-weight:600;color:var(--color-text);cursor:pointer}.rb-btn{appearance:none;border:1px solid var(--color-border);background:transparent;border-radius:var(--radius-md, 8px);padding:5px 12px;font-size:12.5px;font-weight:700;cursor:pointer;color:var(--color-text-muted)}.rb-btn:disabled{opacity:.45;cursor:default}.rb-btn-primary{border-color:var(--color-accent);color:var(--color-accent-hover, #0b3a82)}.rb-link{appearance:none;background:none;border:0;padding:2px 4px;font-size:12.5px;font-weight:700;color:var(--color-accent-hover, #0b3a82);cursor:pointer}.rb-link:disabled{opacity:.4;cursor:default}.rb-danger{color:var(--color-danger, #c0362c)}.rb-card{border:1px solid var(--color-border);border-radius:var(--radius-md, 8px);padding:10px 12px;display:flex;flex-direction:column;gap:8px}.rb-card-head{display:flex;gap:8px;align-items:center;justify-content:space-between;flex-wrap:wrap}.rb-problem{font-size:12px;font-weight:600;color:var(--color-danger, #c0362c)}.rb-field{display:flex;flex-direction:column;gap:3px;font-size:11.5px;font-weight:700;color:var(--color-text-muted)}.rb-empty{font-size:13px;color:var(--color-text-muted)}.rb-table{width:100%;border-collapse:collapse;font-size:13px}.rb-table th{text-align:left;font-size:11px;font-weight:700;color:var(--color-text-muted);padding:0 6px 4px;white-space:nowrap}.rb-table td{padding:3px 4px;vertical-align:middle}.rb-table .rb-input{width:100%;min-width:72px}.rb-scroll{overflow-x:auto}\n", ".jb{border:1px solid var(--color-border);border-radius:var(--radius-md, 8px);padding:10px 12px;display:flex;flex-direction:column;gap:8px}.jb-bar{display:flex;justify-content:flex-end}.jb-json{font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:12.5px;width:100%;resize:vertical}\n"] }]
1569
+ }], propDecorators: { kind: [{
1570
+ type: Input,
1571
+ args: [{ required: true }]
1572
+ }], value: [{
1573
+ type: Input
1574
+ }], valueChange: [{
1575
+ type: Output
1576
+ }] } });
1577
+
1578
+ export { JsonBuilderComponent as J, SimpleCrudDirective as S, emptyValueFor as e };
1579
+ //# sourceMappingURL=isaiahiroko-tilmart-ngx-apps-admin-json-builder.component-BFroIYk9.mjs.map