@commercelayer/app-elements 6.4.1 → 6.5.1

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 (28) hide show
  1. package/dist/{InputDateComponent-CJtRdbJv.js → InputDateComponent-CPOe--_2.js} +1127 -1050
  2. package/dist/RuleEngineComponent-DdV5Bowp.js +2891 -0
  3. package/dist/{en-Psn8u2uC.js → en-BbX2gWkK.js} +3 -3
  4. package/dist/{it-DsWhEkJp.js → it-P4oHwKfI.js} +2 -2
  5. package/dist/locales/en.d.ts +2 -2
  6. package/dist/{main-DKRFxDxK.js → main-PyYMsnaA.js} +8042 -8358
  7. package/dist/main.js +171 -171
  8. package/dist/{parseISO-Ctdvusm6.js → parseISO-BV-Ib62P.js} +1 -1
  9. package/dist/style.css +1 -1
  10. package/dist/ui/forms/CodeEditor/CodeEditorComponent.d.ts +8 -0
  11. package/dist/ui/forms/InputSelect/overrides.d.ts +8 -2
  12. package/dist/ui/forms/RuleEngine/Action/ActionListItem.d.ts +0 -4
  13. package/dist/ui/forms/RuleEngine/Condition/ValueComponents/InputResourceSelector.d.ts +2 -0
  14. package/dist/ui/forms/RuleEngine/Options/index.d.ts +5 -0
  15. package/dist/ui/forms/RuleEngine/RuleEngineContext.d.ts +25 -4
  16. package/dist/ui/forms/RuleEngine/layout/ListItemContainer.d.ts +1 -0
  17. package/dist/ui/forms/RuleEngine/optionsConfig.d.ts +66 -0
  18. package/dist/ui/forms/RuleEngine/optionsConfig.test.d.ts +1 -0
  19. package/dist/ui/forms/RuleEngine/utils.d.ts +5 -3
  20. package/dist/ui/resources/ResourceListItem/ResourceListItem.mocks.d.ts +8 -0
  21. package/dist/ui/resources/ResourceListItem/types.d.ts +1 -0
  22. package/dist/vendor.css +2 -2
  23. package/package.json +35 -27
  24. package/dist/RuleEngineComponent-DZ7eYNPc.js +0 -2168
  25. package/dist/ui/forms/RuleEngine/Condition/ArrayMatch.d.ts +0 -0
  26. package/dist/ui/forms/RuleEngine/Condition/RangeInputs.d.ts +0 -0
  27. /package/dist/ui/forms/RuleEngine/{schema.order_rules.d.ts → json_schema/order_rules.schema.d.ts} +0 -0
  28. /package/dist/ui/forms/RuleEngine/{schema.price_rules.d.ts → json_schema/price_rules.schema.d.ts} +0 -0
@@ -0,0 +1,2891 @@
1
+ "use client";
2
+ import { t as B, b as Ve, d as ke, e as Me, j as t, i as k, g as q, f as L, h as Re, u as Oe, k as Ee, I as v, D as S, l as A, n as g, o as y, p as _, q as z, B as V, r as j, T as $, s as ae, v as re, w as E, x as oe, y as Ie, z as ie, A as De, C as Y, S as X, H as qe, E as ue, F as Le, G as Fe, J as H, K as ze, L as Ge, M as Je } from "./main-PyYMsnaA.js";
3
+ import P, { useReducer as We, useCallback as M, useMemo as ce, createContext as Ue, useContext as Be, useState as x, useEffect as C, useRef as de } from "react";
4
+ import "react-hook-form";
5
+ import "wouter";
6
+ import { p as Z } from "./parseISO-BV-Ib62P.js";
7
+ function Q(e, s) {
8
+ const n = e.match(
9
+ /(\d{4})-(\d{2})-(\d{2})[T ](\d{2}):(\d{2}):(\d{2})(?:\.(\d{0,7}))?(?:Z|(.)(\d{2}):?(\d{2})?)?/
10
+ );
11
+ return n ? B(
12
+ Date.UTC(
13
+ +n[1],
14
+ +n[2] - 1,
15
+ +n[3],
16
+ +n[4] - (+n[9] || 0) * (n[8] == "-" ? -1 : 1),
17
+ +n[5] - (+n[10] || 0) * (n[8] == "-" ? -1 : 1),
18
+ +n[6],
19
+ +((n[7] || "0") + "00").substring(0, 3)
20
+ ),
21
+ s?.in
22
+ ) : B(NaN, s?.in);
23
+ }
24
+ var Ye = 1, Xe = 4;
25
+ function K(e) {
26
+ return Ve(e, Ye | Xe);
27
+ }
28
+ function O(e, s, n) {
29
+ return e == null ? e : ke(e, s, n);
30
+ }
31
+ function D(e, s) {
32
+ return e == null ? !0 : Me(e, s);
33
+ }
34
+ const pe = Ue(
35
+ void 0
36
+ );
37
+ function He(e, s) {
38
+ switch (s.type) {
39
+ case "SET_PATH": {
40
+ const n = K(e.value);
41
+ if (/actions\.\d\.[\w_]+$/.test(s.path)) {
42
+ const l = s.path.replace(/\.[\w_]+$/, "");
43
+ q(n, l)?.groups == null && O(n, `${l}.groups`, []);
44
+ }
45
+ if (s.value === null && s.allowNullValue === !1)
46
+ if (/\.\d+$/.test(s.path)) {
47
+ const l = s.path.replace(/\.\d+$/, ""), o = parseInt(s.path.match(/\d+$/)?.[0] ?? "0", 10), a = q(n, l);
48
+ Array.isArray(a) && (a.splice(o, 1), O(n, l, a), a.length === 0 && l.endsWith(".nested.conditions") && D(n, l.replace(/\.conditions$/, "")));
49
+ } else
50
+ D(n, s.path);
51
+ else
52
+ O(n, s.path, s.value);
53
+ return {
54
+ ...e,
55
+ value: n
56
+ };
57
+ }
58
+ case "SET_RENDER_OPTION": {
59
+ const n = K(e.renderOptions);
60
+ if (s.value === null)
61
+ if (/\.\d+$/.test(s.path)) {
62
+ const l = s.path.replace(/\.\d+$/, ""), o = parseInt(s.path.match(/\d+$/)?.[0] ?? "0", 10), a = q(n, l);
63
+ Array.isArray(a) && (a.splice(o, 1), O(n, l, a), a.length === 0 && l.endsWith(".nested.conditions") && D(n, l.replace(/\.conditions$/, "")));
64
+ } else
65
+ D(n, s.path);
66
+ else
67
+ O(n, s.path, s.value);
68
+ return {
69
+ ...e,
70
+ renderOptions: n
71
+ };
72
+ }
73
+ case "SET_SELECTED_RULE_INDEX":
74
+ return {
75
+ ...e,
76
+ selectedRuleIndex: s.index
77
+ };
78
+ case "SET_VALUE":
79
+ return k(e.value, s.value) ? e : (s.value.rules?.length ?? 0) === 0 ? {
80
+ selectedRuleIndex: 0,
81
+ value: {
82
+ rules: [
83
+ {
84
+ name: "Rule name",
85
+ // @ts-expect-error Setting `null` is intentional for rendering an empty action
86
+ actions: [null],
87
+ // @ts-expect-error Setting `null` is intentional for rendering an empty condition
88
+ conditions: [null]
89
+ }
90
+ ]
91
+ }
92
+ } : {
93
+ ...e,
94
+ value: s.value
95
+ };
96
+ default:
97
+ return e;
98
+ }
99
+ }
100
+ function Pe({
101
+ children: e,
102
+ initialValue: s
103
+ }) {
104
+ const [n, l] = We(He, {
105
+ value: s.value,
106
+ renderOptions: {},
107
+ selectedRuleIndex: 0
108
+ }), o = M(
109
+ (c, d, m = !1) => {
110
+ l({ type: "SET_PATH", path: c, value: d, allowNullValue: m });
111
+ },
112
+ []
113
+ ), a = M((c) => {
114
+ l({ type: "SET_SELECTED_RULE_INDEX", index: c }), c < 0 && setTimeout(() => {
115
+ l({ type: "SET_SELECTED_RULE_INDEX", index: 0 });
116
+ }, 50);
117
+ }, []), i = M((c) => {
118
+ l({ type: "SET_VALUE", value: c });
119
+ }, []), r = M((c, d) => {
120
+ l({ type: "SET_RENDER_OPTION", path: c, value: d });
121
+ }, []), u = ce(
122
+ () => ({
123
+ state: n,
124
+ setPath: o,
125
+ setSelectedRuleIndex: a,
126
+ setValue: i,
127
+ setRenderOption: r,
128
+ schemaType: s.schemaType,
129
+ optionsConfig: s.optionsConfig
130
+ }),
131
+ [
132
+ n,
133
+ o,
134
+ a,
135
+ i,
136
+ r,
137
+ s.schemaType,
138
+ s.optionsConfig
139
+ ]
140
+ );
141
+ return /* @__PURE__ */ t.jsx(pe.Provider, { value: u, children: e });
142
+ }
143
+ function f() {
144
+ const e = Be(pe);
145
+ if (e === void 0)
146
+ throw new Error("useRuleEngine must be used within a RuleEngineProvider");
147
+ return e;
148
+ }
149
+ const me = [
150
+ {
151
+ /** Matches if field value equals provided value
152
+ * @field Integer, String, Datetime, Boolean
153
+ * @value Integer, String, Datetime, Boolean
154
+ */
155
+ matcher: "eq",
156
+ label: "equals",
157
+ fieldTypes: ["integer", "string", "datetime", "boolean"],
158
+ isMulti: !1,
159
+ exactMatch: !0
160
+ },
161
+ {
162
+ /** Matches if field value is not equal to provided value
163
+ * @field Integer, String, Datetime, Boolean
164
+ * @value Integer, String, Datetime, Boolean
165
+ */
166
+ matcher: "not_eq",
167
+ label: "not equals",
168
+ fieldTypes: ["integer", "string", "datetime", "boolean"],
169
+ isMulti: !1,
170
+ exactMatch: !0
171
+ },
172
+ {
173
+ /** Matches if field value is less than provided value
174
+ * @field Integer, Datetime
175
+ * @value Integer, Datetime
176
+ */
177
+ matcher: "lt",
178
+ label: "<",
179
+ fieldTypes: ["integer", "datetime"],
180
+ isMulti: !1,
181
+ exactMatch: !0
182
+ },
183
+ {
184
+ /** Matches if field value is less than or equal to provided value
185
+ * @field Integer, Datetime
186
+ * @value Integer, Datetime
187
+ */
188
+ matcher: "lteq",
189
+ label: "≤",
190
+ fieldTypes: ["integer", "datetime"],
191
+ isMulti: !1,
192
+ exactMatch: !0
193
+ },
194
+ {
195
+ /** Matches if field value is greater than provided value
196
+ * @field Integer, Datetime
197
+ * @value Integer, Datetime
198
+ */
199
+ matcher: "gt",
200
+ label: ">",
201
+ fieldTypes: ["integer", "datetime"],
202
+ isMulti: !1,
203
+ exactMatch: !0
204
+ },
205
+ {
206
+ /** Matches if field value is greater than or equal to provided value
207
+ * @field Integer, Datetime
208
+ * @value Integer, Datetime
209
+ */
210
+ matcher: "gteq",
211
+ label: "≥",
212
+ fieldTypes: ["integer", "datetime"],
213
+ isMulti: !1,
214
+ exactMatch: !0
215
+ },
216
+ {
217
+ /** Matches if field value is a multiple of provided value
218
+ * @field Integer
219
+ * @value Integer
220
+ */
221
+ matcher: "multiple",
222
+ label: "is a multiple of",
223
+ fieldTypes: ["integer"],
224
+ isMulti: !1,
225
+ exactMatch: !0
226
+ },
227
+ {
228
+ /** Matches if field value matches regex pattern
229
+ * @field String
230
+ * @value String
231
+ */
232
+ matcher: "matches",
233
+ label: "matches regex",
234
+ fieldTypes: ["string"],
235
+ isMulti: !1,
236
+ exactMatch: !1
237
+ },
238
+ {
239
+ /** Matches if field value does not match regex pattern
240
+ * @field String
241
+ * @value String
242
+ */
243
+ matcher: "does_not_match",
244
+ label: "doesn't match regex",
245
+ fieldTypes: ["string"],
246
+ isMulti: !1,
247
+ exactMatch: !1
248
+ },
249
+ {
250
+ /** Matches if field value starts with provided string
251
+ * @field String
252
+ * @value String
253
+ */
254
+ matcher: "start_with",
255
+ label: "starts with",
256
+ fieldTypes: ["string"],
257
+ isMulti: !1,
258
+ exactMatch: !1
259
+ },
260
+ {
261
+ /** Matches if field value does not start with provided string
262
+ * @field String
263
+ * @value String
264
+ */
265
+ matcher: "not_start_with",
266
+ label: "doesn't start with",
267
+ fieldTypes: ["string"],
268
+ isMulti: !1,
269
+ exactMatch: !1
270
+ },
271
+ {
272
+ /** Matches if field value ends with provided string
273
+ * @field String
274
+ * @value String
275
+ */
276
+ matcher: "end_with",
277
+ label: "ends with",
278
+ fieldTypes: ["string"],
279
+ isMulti: !1,
280
+ exactMatch: !1
281
+ },
282
+ {
283
+ /** Matches if field value does not end with provided string
284
+ * @field String
285
+ * @value String
286
+ */
287
+ matcher: "not_end_with",
288
+ label: "doesn't end with",
289
+ fieldTypes: ["string"],
290
+ isMulti: !1,
291
+ exactMatch: !1
292
+ },
293
+ {
294
+ /** Matches if field value is between two values (exclusive)
295
+ * @field Integer, Datetime
296
+ * @value Array
297
+ */
298
+ matcher: "gt_lt",
299
+ label: "> and <",
300
+ fieldTypes: ["integer"],
301
+ isMulti: !1,
302
+ exactMatch: !0
303
+ },
304
+ {
305
+ /** Matches if field value is between two values (inclusive start, exclusive end)
306
+ * @field Integer, Datetime
307
+ * @value Array
308
+ */
309
+ matcher: "gteq_lt",
310
+ label: "≥ and <",
311
+ fieldTypes: ["integer"],
312
+ isMulti: !1,
313
+ exactMatch: !0
314
+ },
315
+ {
316
+ /** Matches if field value is greater than first and less than or equal to second
317
+ * @field Integer, Datetime
318
+ * @value Array
319
+ */
320
+ matcher: "gt_lteq",
321
+ label: "> and ≤",
322
+ fieldTypes: ["integer"],
323
+ isMulti: !1,
324
+ exactMatch: !0
325
+ },
326
+ {
327
+ /** Matches if field value is between two values (inclusive)
328
+ * @field Integer, Datetime
329
+ * @value Array
330
+ */
331
+ matcher: "gteq_lteq",
332
+ label: "≥ and ≤",
333
+ fieldTypes: ["integer"],
334
+ isMulti: !1,
335
+ exactMatch: !0
336
+ },
337
+ {
338
+ /** Matches if field value is between two values (exclusive)
339
+ * @field Integer, Datetime
340
+ * @value Array
341
+ */
342
+ matcher: "gt_lt",
343
+ label: "date range",
344
+ visible: !1,
345
+ fieldTypes: ["datetime"],
346
+ isMulti: !1,
347
+ exactMatch: !0
348
+ },
349
+ {
350
+ /** Matches if field value is between two values (inclusive start, exclusive end)
351
+ * @field Integer, Datetime
352
+ * @value Array
353
+ */
354
+ matcher: "gteq_lt",
355
+ label: "date range",
356
+ visible: !1,
357
+ fieldTypes: ["datetime"],
358
+ isMulti: !1,
359
+ exactMatch: !0
360
+ },
361
+ {
362
+ /** Matches if field value is greater than first and less than or equal to second
363
+ * @field Integer, Datetime
364
+ * @value Array
365
+ */
366
+ matcher: "gt_lteq",
367
+ label: "date range",
368
+ visible: !1,
369
+ fieldTypes: ["datetime"],
370
+ isMulti: !1,
371
+ exactMatch: !0
372
+ },
373
+ {
374
+ /** Matches if field value is between two values (inclusive)
375
+ * @field Integer, Datetime
376
+ * @value Array
377
+ */
378
+ matcher: "gteq_lteq",
379
+ label: "date range",
380
+ visible: !0,
381
+ fieldTypes: ["datetime"],
382
+ isMulti: !1,
383
+ exactMatch: !0
384
+ },
385
+ {
386
+ /** Matches if field value is in provided array
387
+ * @field Integer, String, Datetime
388
+ * @value Array
389
+ */
390
+ matcher: "is_in",
391
+ label: "is one of",
392
+ fieldTypes: ["integer", "string", "datetime"],
393
+ isMulti: !0,
394
+ exactMatch: !0
395
+ },
396
+ {
397
+ /** Matches if field value is not in provided array
398
+ * @field Integer, String, Datetime
399
+ * @value Array
400
+ */
401
+ matcher: "is_not_in",
402
+ label: "is not one of",
403
+ fieldTypes: ["integer", "string", "datetime"],
404
+ isMulti: !0,
405
+ exactMatch: !0
406
+ },
407
+ {
408
+ /** Matches objects within arrays that meet specified requirements
409
+ * @field Array
410
+ * @value Object
411
+ */
412
+ matcher: "array_match",
413
+ label: "is",
414
+ fieldTypes: ["integer", "string", "datetime"],
415
+ isMulti: !0,
416
+ exactMatch: !0
417
+ },
418
+ {
419
+ /** Matches if field value is null or empty string */
420
+ matcher: "blank",
421
+ label: "is blank",
422
+ fieldTypes: ["integer", "string", "datetime", "boolean"],
423
+ isMulti: !1,
424
+ exactMatch: !0
425
+ },
426
+ {
427
+ /** Matches if field value is null */
428
+ matcher: "null",
429
+ label: "is null",
430
+ fieldTypes: ["integer", "string", "datetime", "boolean"],
431
+ isMulti: !1,
432
+ exactMatch: !0
433
+ },
434
+ {
435
+ /** Matches if field value is not null */
436
+ matcher: "not_null",
437
+ label: "is not null",
438
+ fieldTypes: ["integer", "string", "datetime", "boolean"],
439
+ isMulti: !1,
440
+ exactMatch: !0
441
+ },
442
+ {
443
+ /** Matches if field value is not null */
444
+ matcher: "present",
445
+ label: "is present",
446
+ fieldTypes: ["integer", "string", "datetime", "boolean"],
447
+ isMulti: !1,
448
+ exactMatch: !0
449
+ }
450
+ ];
451
+ function fe(e) {
452
+ if (typeof e == "string")
453
+ return L(Q(e)) ? "datetime" : "string";
454
+ if (typeof e == "number")
455
+ return "integer";
456
+ if (typeof e == "boolean")
457
+ return "boolean";
458
+ if (Array.isArray(e)) {
459
+ if (typeof e[0] == "string")
460
+ return L(Q(e[0])) ? "datetime" : "string";
461
+ if (typeof e[0] == "number")
462
+ return "integer";
463
+ }
464
+ return "string";
465
+ }
466
+ const he = {
467
+ market: "markets",
468
+ tag: "tags",
469
+ sku: "skus",
470
+ sku_list: "sku_lists"
471
+ };
472
+ function Ze(e) {
473
+ return he[e];
474
+ }
475
+ function W(e) {
476
+ const [s, n] = x(void 0);
477
+ return C(() => {
478
+ e?.field != null && Re(e.field).then((l) => {
479
+ const o = me.find(
480
+ (a) => a.matcher === e.matcher
481
+ );
482
+ n({
483
+ ...l,
484
+ matcherInfos: o,
485
+ resourceSelectorAvailable: l?.resource?.id != null && Object.keys(he).includes(l.resource.id) && l.path.endsWith(".id") && o?.exactMatch === !0
486
+ });
487
+ }).catch((l) => {
488
+ console.error("Error fetching field info:", l);
489
+ });
490
+ }, [e?.field, e?.matcher]), { infos: s };
491
+ }
492
+ function ge(e) {
493
+ return e == null || e.length === 0 ? [] : Oe(
494
+ Ee(
495
+ e.flatMap((s) => [
496
+ s?.group,
497
+ ...ge(s?.nested?.conditions)
498
+ ])
499
+ )
500
+ );
501
+ }
502
+ function be() {
503
+ const {
504
+ state: { selectedRuleIndex: e, value: s }
505
+ } = f();
506
+ return ge(
507
+ s.rules?.[e]?.conditions
508
+ );
509
+ }
510
+ const Qe = ({ children: e }) => /* @__PURE__ */ t.jsx("div", { className: "bg-white rounded-md p-4 shadow-xs flex flex-col gap-2 empty:hidden", children: e }), xe = ({ children: e, dropdownItems: s, options: n, pathPrefix: l }) => {
511
+ const { state: o, setRenderOption: a } = f(), i = `${l}.isOpen`, r = q(o.renderOptions, i) ?? !0;
512
+ return /* @__PURE__ */ t.jsx("div", { className: "bg-gray-50 rounded-md flex items-center", children: /* @__PURE__ */ t.jsx("div", { className: "flex items-center justify-between gap-2 grow p-2", children: /* @__PURE__ */ t.jsxs("div", { className: "flex flex-col gap-2 grow", children: [
513
+ /* @__PURE__ */ t.jsxs("div", { className: "flex items-center justify-between gap-2", children: [
514
+ e,
515
+ /* @__PURE__ */ t.jsxs("div", { className: "border border-gray-200 rounded self-stretch flex", children: [
516
+ /* @__PURE__ */ t.jsx(
517
+ "button",
518
+ {
519
+ type: "button",
520
+ onClick: () => {
521
+ a(`${i}`, !r);
522
+ },
523
+ className: "w-11 flex self-stretch justify-center items-center",
524
+ children: /* @__PURE__ */ t.jsx(v, { name: r ? "caretUp" : "caretDown", size: 16 })
525
+ }
526
+ ),
527
+ s != null && /* @__PURE__ */ t.jsx(
528
+ S,
529
+ {
530
+ className: "flex self-stretch border-gray-100 border-l",
531
+ dropdownLabel: /* @__PURE__ */ t.jsx(
532
+ "button",
533
+ {
534
+ type: "button",
535
+ className: "w-11 flex self-stretch justify-center items-center",
536
+ children: /* @__PURE__ */ t.jsx(v, { name: "dotsThreeVertical", size: 16, weight: "bold" })
537
+ }
538
+ ),
539
+ dropdownItems: s
540
+ }
541
+ )
542
+ ] })
543
+ ] }),
544
+ r && /* @__PURE__ */ t.jsx(Qe, { children: n })
545
+ ] }) }) });
546
+ }, I = ({ children: e, label: s, className: n }) => /* @__PURE__ */ t.jsxs("div", { className: A("flex gap-4 first-of-type:mt-0", n), children: [
547
+ /* @__PURE__ */ t.jsx("div", { className: "basis-[180px] shrink-0 h-[44px] flex items-center", children: s }),
548
+ /* @__PURE__ */ t.jsx("div", { className: "grow flex flex-col gap-2", children: e })
549
+ ] }), ve = {
550
+ actions: {
551
+ "order-rules": {
552
+ order: {
553
+ round: !0,
554
+ discount_mode: !0,
555
+ apply_on: [
556
+ { label: "Subtotal amount", value: "subtotal_amount_cents" },
557
+ { label: "Total amount", value: "total_amount_cents" }
558
+ ],
559
+ limit: [
560
+ {
561
+ label: "Most expensive",
562
+ value: "most-expensive",
563
+ meta: {
564
+ attribute: "total_amount_cents",
565
+ direction: "desc"
566
+ }
567
+ },
568
+ {
569
+ label: "Less expensive",
570
+ value: "less-expensive",
571
+ meta: {
572
+ attribute: "total_amount_cents",
573
+ direction: "asc"
574
+ }
575
+ }
576
+ ],
577
+ bundle: [
578
+ {
579
+ label: "Most expensive",
580
+ value: "most-expensive",
581
+ meta: {
582
+ attribute: "total_amount_cents",
583
+ direction: "desc"
584
+ }
585
+ },
586
+ {
587
+ label: "Less expensive",
588
+ value: "less-expensive",
589
+ meta: {
590
+ attribute: "total_amount_cents",
591
+ direction: "asc"
592
+ }
593
+ }
594
+ ]
595
+ },
596
+ "order.line_items": {
597
+ round: !0,
598
+ discount_mode: !0,
599
+ apply_on: [
600
+ { label: "Unit amount", value: "unit_amount_cents" },
601
+ { label: "Compare at amount", value: "compare_at_amount_cents" }
602
+ ],
603
+ limit: [
604
+ {
605
+ label: "Most expensive",
606
+ value: "most-expensive",
607
+ meta: {
608
+ attribute: "unit_amount_cents",
609
+ direction: "desc"
610
+ }
611
+ },
612
+ {
613
+ label: "Less expensive",
614
+ value: "less-expensive",
615
+ meta: {
616
+ attribute: "unit_amount_cents",
617
+ direction: "asc"
618
+ }
619
+ }
620
+ ],
621
+ bundle: [
622
+ {
623
+ label: "Most expensive",
624
+ value: "most-expensive",
625
+ meta: {
626
+ attribute: "unit_amount_cents",
627
+ direction: "desc"
628
+ }
629
+ },
630
+ {
631
+ label: "Less expensive",
632
+ value: "less-expensive",
633
+ meta: {
634
+ attribute: "unit_amount_cents",
635
+ direction: "asc"
636
+ }
637
+ }
638
+ ]
639
+ },
640
+ "order.line_items.line_item_options": {},
641
+ "order.line_items.sku": {},
642
+ "order.line_items.bundle": {},
643
+ "order.line_items.shipment": {},
644
+ "order.line_items.payment_method": {},
645
+ "order.line_items.adjustment": {},
646
+ "order.line_items.gift_card": {}
647
+ },
648
+ "price-rules": {
649
+ price: {
650
+ apply_on: [
651
+ { label: "Amount", value: "amount_cents" },
652
+ { label: "Compare at amount", value: "compare_at_amount_cents" }
653
+ ]
654
+ }
655
+ }
656
+ },
657
+ conditions: {
658
+ "order-rules": {
659
+ group: !0,
660
+ scope: !0,
661
+ aggregations: [
662
+ {
663
+ label: "Total quantity",
664
+ value: "total-quantity",
665
+ meta: {
666
+ field: "order.line_items.quantity",
667
+ operator: "sum"
668
+ }
669
+ },
670
+ {
671
+ label: "Total amount",
672
+ value: "total-amount",
673
+ meta: {
674
+ field: "order.line_items.total_amount_cents",
675
+ operator: "sum"
676
+ }
677
+ }
678
+ ]
679
+ },
680
+ "price-rules": {
681
+ group: !0,
682
+ scope: !0
683
+ }
684
+ }
685
+ }, Ke = [
686
+ "apply_on",
687
+ "round",
688
+ "limit",
689
+ "discount_mode",
690
+ "aggregation",
691
+ "bundle"
692
+ ], et = ["group", "scope", "aggregations"], ye = {
693
+ apply_on: "Apply on",
694
+ round: "Round",
695
+ limit: "Limit",
696
+ discount_mode: "Discount mode",
697
+ aggregation: "Aggregation",
698
+ bundle: "Bundle",
699
+ scope: "Scope",
700
+ aggregations: "Aggregations",
701
+ group: "Group"
702
+ };
703
+ function tt(e, s) {
704
+ if (e == null || typeof e != "object")
705
+ return {
706
+ actions: {},
707
+ conditions: []
708
+ };
709
+ const n = e;
710
+ return {
711
+ actions: nt(n, s),
712
+ conditions: st(n, s)
713
+ };
714
+ }
715
+ function nt(e, s) {
716
+ const n = {};
717
+ try {
718
+ const l = e?.properties?.rules?.items?.properties?.actions?.items?.anyOf ?? [], o = lt(l);
719
+ for (const [a, i] of o.entries()) {
720
+ const r = je(i, Ke), u = _e(r, i, e), c = ve.actions[s], d = Object.keys(c);
721
+ n[a] = {};
722
+ for (const m of d) {
723
+ const h = c[m];
724
+ h != null && (n[a][m] = u.filter((p) => h[p.name] != null).map((p) => {
725
+ const b = h[p.name];
726
+ return {
727
+ ...p,
728
+ // Configuration values override schema-derived values
729
+ values: Array.isArray(b) ? b : p.values
730
+ };
731
+ }));
732
+ }
733
+ }
734
+ } catch (l) {
735
+ console.error("Error parsing action options from schema:", l);
736
+ }
737
+ return n;
738
+ }
739
+ function st(e, s) {
740
+ try {
741
+ const n = e?.$defs?.conditions?.items?.anyOf ?? [], l = je(
742
+ n,
743
+ et
744
+ ), o = _e(l, n, e), a = ve.conditions[s];
745
+ return o.filter((i) => a[i.name] != null).map((i) => {
746
+ const r = a[i.name];
747
+ return {
748
+ ...i,
749
+ // Configuration values override schema-derived values
750
+ values: Array.isArray(r) ? r : i.values
751
+ };
752
+ });
753
+ } catch (n) {
754
+ return console.error("Error parsing condition options from schema:", n), [];
755
+ }
756
+ }
757
+ function lt(e) {
758
+ const s = /* @__PURE__ */ new Map();
759
+ for (const n of e) {
760
+ const l = n?.properties?.type?.enum?.[0];
761
+ l != null && (s.has(l) || s.set(l, []), s.get(l)?.push(n));
762
+ }
763
+ return s;
764
+ }
765
+ function je(e, s) {
766
+ const n = /* @__PURE__ */ new Map();
767
+ return e.forEach((l, o) => {
768
+ const a = Object.keys(l.properties ?? {}), i = new Set(l.required ?? []);
769
+ for (const r of a)
770
+ s.includes(r) && (n.has(r) || n.set(r, {
771
+ appearsIn: /* @__PURE__ */ new Set(),
772
+ requiredIn: /* @__PURE__ */ new Set()
773
+ }), n.get(r)?.appearsIn.add(o), i.has(r) && n.get(r)?.requiredIn.add(o));
774
+ }), n;
775
+ }
776
+ function _e(e, s, n) {
777
+ const l = [];
778
+ for (const [o, { appearsIn: a }] of e.entries()) {
779
+ const i = at(
780
+ o,
781
+ a,
782
+ e
783
+ );
784
+ let r = {};
785
+ for (const u of s) {
786
+ const c = u.properties?.[o];
787
+ if (r = rt(c, n), r.values != null || r.valueType != null || r.description != null)
788
+ break;
789
+ }
790
+ l.push({
791
+ name: o,
792
+ label: ye[o],
793
+ mutuallyExclusiveWith: i,
794
+ ...r
795
+ });
796
+ }
797
+ return l;
798
+ }
799
+ function at(e, s, n) {
800
+ const l = [];
801
+ for (const [o, { appearsIn: a }] of n) {
802
+ if (o === e) continue;
803
+ new Set(
804
+ [...s].filter((r) => a.has(r))
805
+ ).size === 0 && s.size > 0 && l.push(o);
806
+ }
807
+ return l;
808
+ }
809
+ function rt(e, s) {
810
+ const n = {};
811
+ let l = e;
812
+ if (e?.$ref != null && typeof e.$ref == "string") {
813
+ const o = e.$ref.replace(/^#\//, "").split("/");
814
+ let a = s;
815
+ for (const i of o)
816
+ a = a?.[i];
817
+ l = a;
818
+ }
819
+ return l?.enum != null && Array.isArray(l.enum) && (n.values = l.enum.map((o) => ({
820
+ label: o.charAt(0).toUpperCase() + o.slice(1),
821
+ value: o
822
+ }))), l?.type != null && (n.valueType = l.type), l?.description != null && typeof l.description == "string" && (n.description = l.description), n;
823
+ }
824
+ function $e(e, s) {
825
+ if (e == null)
826
+ return {
827
+ available: [],
828
+ disabled: [],
829
+ current: []
830
+ };
831
+ const n = s.map((a) => a.name).filter((a) => {
832
+ const i = a in e && e[a] !== void 0, r = Array.isArray(e[a]) && e[a].length > 0;
833
+ return Array.isArray(e[a]) ? r : i;
834
+ }), l = [], o = [];
835
+ for (const a of s) {
836
+ if (n.includes(a.name))
837
+ continue;
838
+ a.mutuallyExclusiveWith.some(
839
+ (r) => n.includes(r)
840
+ ) ? o.push(a) : l.push(a);
841
+ }
842
+ return {
843
+ available: l,
844
+ disabled: o,
845
+ current: n
846
+ };
847
+ }
848
+ function Ne({
849
+ item: e,
850
+ pathPrefix: s
851
+ }) {
852
+ return e == null ? null : /* @__PURE__ */ t.jsxs(t.Fragment, { children: [
853
+ /* @__PURE__ */ t.jsx(ot, { item: e, pathPrefix: s }),
854
+ /* @__PURE__ */ t.jsx(ht, { item: e, pathPrefix: s }),
855
+ /* @__PURE__ */ t.jsx(mt, { item: e, pathPrefix: s }),
856
+ /* @__PURE__ */ t.jsx(ct, { item: e, pathPrefix: s }),
857
+ /* @__PURE__ */ t.jsx(dt, { item: e, pathPrefix: s }),
858
+ /* @__PURE__ */ t.jsx(ut, { item: e, pathPrefix: s }),
859
+ /* @__PURE__ */ t.jsx(pt, { item: e, pathPrefix: s }),
860
+ /* @__PURE__ */ t.jsx(it, { item: e, pathPrefix: s }),
861
+ /* @__PURE__ */ t.jsx(ft, { item: e, pathPrefix: s })
862
+ ] });
863
+ }
864
+ function ot({
865
+ item: e,
866
+ pathPrefix: s
867
+ }) {
868
+ const n = "group", { setPath: l } = f(), o = T({ item: e, optionName: n, pathPrefix: s }), a = be();
869
+ return !(n in e) || o == null || e.group === void 0 ? null : /* @__PURE__ */ t.jsx(o.OptionRow, { children: /* @__PURE__ */ t.jsx(
870
+ g,
871
+ {
872
+ name: `${s}.group`,
873
+ isCreatable: !0,
874
+ initialValues: a.map((i) => ({
875
+ value: i,
876
+ label: i
877
+ })),
878
+ defaultValue: e.group != null ? {
879
+ value: e.group,
880
+ label: e.group
881
+ } : void 0,
882
+ onSelect: (i) => {
883
+ (i == null || y(i)) && l(`${s}.group`, i?.value.toString());
884
+ },
885
+ placeholder: "Select or create group…"
886
+ }
887
+ ) });
888
+ }
889
+ function it({
890
+ item: e,
891
+ pathPrefix: s
892
+ }) {
893
+ const n = "round", { setPath: l } = f(), o = T({ item: e, optionName: n, pathPrefix: s });
894
+ if (!(n in e) || o == null)
895
+ return null;
896
+ const a = [
897
+ { label: "Yes", value: !0 },
898
+ { label: "No", value: !1 }
899
+ ], i = a.find((r) => r.value === e[n]);
900
+ return /* @__PURE__ */ t.jsx(o.OptionRow, { children: /* @__PURE__ */ t.jsx(
901
+ g,
902
+ {
903
+ name: `${s}.${n}`,
904
+ isSearchable: !1,
905
+ defaultValue: i,
906
+ initialValues: a,
907
+ onSelect: (r) => {
908
+ y(r) && l(`${s}.${n}`, r.value);
909
+ }
910
+ }
911
+ ) });
912
+ }
913
+ function ut({
914
+ item: e,
915
+ pathPrefix: s
916
+ }) {
917
+ const n = "limit", { setPath: l } = f(), o = T({ item: e, optionName: n, pathPrefix: s });
918
+ if (!(n in e) || o == null)
919
+ return null;
920
+ const a = o.optionConfig?.values?.find(
921
+ (i) => k(e.limit?.sort, i.meta)
922
+ );
923
+ return /* @__PURE__ */ t.jsx(o.OptionRow, { children: /* @__PURE__ */ t.jsxs("div", { className: "flex gap-2", children: [
924
+ /* @__PURE__ */ t.jsx(
925
+ j,
926
+ {
927
+ type: "number",
928
+ className: "basis-20",
929
+ placeholder: "1",
930
+ onChange: (i) => {
931
+ const r = parseInt(i.currentTarget.value, 10);
932
+ l(`${s}.${n}.value`, r);
933
+ },
934
+ defaultValue: e.limit?.value
935
+ }
936
+ ),
937
+ /* @__PURE__ */ t.jsx(
938
+ g,
939
+ {
940
+ className: "grow",
941
+ defaultValue: a ?? (e.limit?.sort == null ? void 0 : {
942
+ label: e.limit.sort.attribute != null && e.limit.sort.direction ? `${e.limit.sort.attribute} ${e.limit.sort.direction.toUpperCase()}` : "",
943
+ value: JSON.stringify(e.limit.sort),
944
+ meta: e.limit.sort
945
+ }),
946
+ initialValues: o.optionConfig?.values?.map((i) => ({
947
+ label: i.label,
948
+ meta: i.meta,
949
+ value: JSON.stringify(i.meta)
950
+ })) ?? [],
951
+ onSelect: (i) => {
952
+ y(i) && l(`${s}.${n}.sort`, i.meta);
953
+ }
954
+ }
955
+ )
956
+ ] }) });
957
+ }
958
+ function ct({
959
+ item: e,
960
+ pathPrefix: s
961
+ }) {
962
+ const n = "aggregation", l = T({ item: e, optionName: n, pathPrefix: s });
963
+ return !(n in e) || l == null || e[n] == null ? null : /* @__PURE__ */ t.jsx(l.OptionRow, { children: /* @__PURE__ */ t.jsx(
964
+ we,
965
+ {
966
+ aggregation: e[n],
967
+ optionConfig: l.optionConfig,
968
+ pathPrefix: `${s}.${n}`
969
+ }
970
+ ) });
971
+ }
972
+ function we({
973
+ aggregation: e,
974
+ pathPrefix: s,
975
+ optionConfig: n
976
+ }) {
977
+ const { setPath: l } = f(), o = n?.values?.find(
978
+ (i) => k(e.field, i.meta?.field) && k(e.operator, i.meta?.operator)
979
+ ), a = [
980
+ { label: "=", value: "eq" },
981
+ { label: ">", value: "gt" },
982
+ { label: "<", value: "lt" },
983
+ { label: ">=", value: "gteq" },
984
+ { label: "<=", value: "lteq" },
985
+ { label: "≠", value: "not_eq" },
986
+ { label: "multiple", value: "multiple" }
987
+ ];
988
+ return /* @__PURE__ */ t.jsxs("div", { className: "flex gap-2 grow", children: [
989
+ /* @__PURE__ */ t.jsx(
990
+ g,
991
+ {
992
+ className: "grow",
993
+ defaultValue: o ?? (e.field == null || e.operator == null ? void 0 : {
994
+ label: `${e.field} ${e.operator.toUpperCase()}`,
995
+ value: JSON.stringify({
996
+ field: e.field,
997
+ operation: e.operator
998
+ }),
999
+ meta: {
1000
+ field: e.field,
1001
+ operation: e.operator
1002
+ }
1003
+ }),
1004
+ initialValues: n?.values?.map((i) => ({
1005
+ label: i.label,
1006
+ meta: i.meta,
1007
+ value: JSON.stringify(i.meta)
1008
+ })) ?? [],
1009
+ onSelect: (i) => {
1010
+ y(i) && (l(`${s}.field`, i.meta?.field), l(`${s}.operator`, i.meta?.operator));
1011
+ }
1012
+ }
1013
+ ),
1014
+ /* @__PURE__ */ t.jsx(
1015
+ g,
1016
+ {
1017
+ className: "w-34",
1018
+ defaultValue: e.matcher != null ? {
1019
+ label: a.find((i) => i.value === e.matcher)?.label ?? e.matcher,
1020
+ value: e.matcher
1021
+ } : void 0,
1022
+ initialValues: a,
1023
+ onSelect: (i) => {
1024
+ y(i) && l(`${s}.matcher`, i.value);
1025
+ }
1026
+ }
1027
+ ),
1028
+ /* @__PURE__ */ t.jsx(
1029
+ j,
1030
+ {
1031
+ type: "number",
1032
+ className: "basis-20",
1033
+ placeholder: "0",
1034
+ onChange: (i) => {
1035
+ const r = parseInt(i.currentTarget.value, 10);
1036
+ l(`${s}.value`, r);
1037
+ },
1038
+ defaultValue: e.value
1039
+ }
1040
+ )
1041
+ ] });
1042
+ }
1043
+ function dt({
1044
+ item: e,
1045
+ pathPrefix: s
1046
+ }) {
1047
+ const n = "aggregations", { setPath: l } = f(), [o, a] = x(0), i = T({ item: e, optionName: n, pathPrefix: s });
1048
+ return !(n in e) || i == null || e[n] == null || e[n].length === 0 ? null : /* @__PURE__ */ t.jsx(i.OptionRow, { children: e.aggregations?.map((r, u) => {
1049
+ const c = u.toString();
1050
+ return /* @__PURE__ */ t.jsxs("div", { className: "flex justify-between gap-2", children: [
1051
+ /* @__PURE__ */ t.jsx(
1052
+ we,
1053
+ {
1054
+ aggregation: r,
1055
+ optionConfig: i.optionConfig,
1056
+ pathPrefix: `${s}.${n}.${u}`
1057
+ }
1058
+ ),
1059
+ /* @__PURE__ */ t.jsx(
1060
+ S,
1061
+ {
1062
+ className: "grow-0",
1063
+ dropdownLabel: /* @__PURE__ */ t.jsx(V, { variant: "input", className: "h-[44px] bg-gray-50", children: /* @__PURE__ */ t.jsx(v, { name: "dotsThreeVertical", size: 16, weight: "bold" }) }),
1064
+ dropdownItems: [
1065
+ /* @__PURE__ */ t.jsx(
1066
+ _,
1067
+ {
1068
+ label: "Add aggregation",
1069
+ onClick: () => {
1070
+ l(
1071
+ `${s}.aggregations.${e.aggregations?.length}`,
1072
+ {}
1073
+ );
1074
+ }
1075
+ },
1076
+ `${c}-"add-aggregation"`
1077
+ ),
1078
+ /* @__PURE__ */ t.jsx(
1079
+ _,
1080
+ {
1081
+ label: "Duplicate",
1082
+ onClick: () => {
1083
+ l(
1084
+ `${s}.aggregations.${e.aggregations?.length}`,
1085
+ r
1086
+ );
1087
+ }
1088
+ },
1089
+ `${c}-"duplicate"`
1090
+ ),
1091
+ /* @__PURE__ */ t.jsx(z, {}, `${c}-"divider"`),
1092
+ /* @__PURE__ */ t.jsx(
1093
+ _,
1094
+ {
1095
+ label: "Remove",
1096
+ disabled: e.aggregations?.length === 1,
1097
+ onClick: () => {
1098
+ e.aggregations?.length === 1 ? l(`${s}.aggregations`, null) : l(`${s}.aggregations.${u}`, null), a((d) => d + 1);
1099
+ }
1100
+ },
1101
+ `${c}-"remove-aggregation"`
1102
+ )
1103
+ ]
1104
+ }
1105
+ )
1106
+ ] }, c);
1107
+ }) }, o);
1108
+ }
1109
+ function pt({
1110
+ item: e,
1111
+ pathPrefix: s
1112
+ }) {
1113
+ const n = "bundle", { setPath: l } = f(), o = T({ item: e, optionName: n, pathPrefix: s });
1114
+ if (!(n in e) || o == null)
1115
+ return null;
1116
+ const a = o.optionConfig?.values?.find(
1117
+ (r) => k(e.bundle?.sort, r.meta)
1118
+ ), i = [
1119
+ { label: "Balanced", value: "balanced" },
1120
+ { label: "Every", value: "every" }
1121
+ ];
1122
+ return /* @__PURE__ */ t.jsx(o.OptionRow, { children: /* @__PURE__ */ t.jsxs("div", { className: "flex gap-2", children: [
1123
+ /* @__PURE__ */ t.jsx(
1124
+ g,
1125
+ {
1126
+ initialValues: i,
1127
+ defaultValue: e.bundle?.type == null ? void 0 : i.find((r) => r.value === e.bundle?.type) ?? {
1128
+ label: e.bundle.type,
1129
+ value: e.bundle.type
1130
+ },
1131
+ onSelect: (r) => {
1132
+ y(r) && (l(`${s}.${n}.type`, r.value), r.value === "balanced" && l(`${s}.${n}.value`, null));
1133
+ }
1134
+ }
1135
+ ),
1136
+ e.bundle?.type === "every" && /* @__PURE__ */ t.jsx(
1137
+ j,
1138
+ {
1139
+ type: "number",
1140
+ className: "basis-20",
1141
+ placeholder: "1",
1142
+ onChange: (r) => {
1143
+ const u = parseInt(r.currentTarget.value, 10);
1144
+ l(`${s}.${n}.value`, u);
1145
+ },
1146
+ defaultValue: e.bundle?.value
1147
+ }
1148
+ ),
1149
+ /* @__PURE__ */ t.jsx(
1150
+ g,
1151
+ {
1152
+ className: "grow",
1153
+ defaultValue: a ?? (e.bundle?.sort == null ? void 0 : {
1154
+ label: e.bundle.sort.attribute != null && e.bundle.sort.direction ? `${e.bundle.sort.attribute} ${e.bundle.sort.direction.toUpperCase()}` : "",
1155
+ value: JSON.stringify(e.bundle.sort),
1156
+ meta: e.bundle?.sort
1157
+ }),
1158
+ initialValues: o.optionConfig?.values?.map((r) => ({
1159
+ label: r.label,
1160
+ meta: r.meta,
1161
+ value: JSON.stringify(r.meta)
1162
+ })) ?? [],
1163
+ onSelect: (r) => {
1164
+ y(r) && l(`${s}.${n}.sort`, r.meta);
1165
+ }
1166
+ }
1167
+ )
1168
+ ] }) });
1169
+ }
1170
+ function mt({
1171
+ item: e,
1172
+ pathPrefix: s
1173
+ }) {
1174
+ const n = "discount_mode", { setPath: l } = f(), o = T({ item: e, optionName: n, pathPrefix: s });
1175
+ return !(n in e) || o == null ? null : /* @__PURE__ */ t.jsx(o.OptionRow, { children: /* @__PURE__ */ t.jsx(
1176
+ g,
1177
+ {
1178
+ initialValues: o.optionConfig?.values ?? [],
1179
+ defaultValue: e[n] != null ? {
1180
+ label: o.optionConfig?.values?.find(
1181
+ (a) => a.value === e[n]
1182
+ )?.label ?? e[n],
1183
+ value: e[n]
1184
+ } : void 0,
1185
+ onSelect: (a) => {
1186
+ y(a) && l(`${s}.${n}`, a.value);
1187
+ }
1188
+ }
1189
+ ) });
1190
+ }
1191
+ function ft({
1192
+ item: e,
1193
+ pathPrefix: s
1194
+ }) {
1195
+ const n = "scope", { setPath: l } = f(), o = T({ item: e, optionName: n, pathPrefix: s });
1196
+ return !(n in e) || o == null ? null : /* @__PURE__ */ t.jsx(o.OptionRow, { children: /* @__PURE__ */ t.jsx(
1197
+ g,
1198
+ {
1199
+ initialValues: o.optionConfig?.values ?? [],
1200
+ defaultValue: e[n] != null ? {
1201
+ label: o.optionConfig?.values?.find(
1202
+ (a) => a.value === e[n]
1203
+ )?.label ?? e[n],
1204
+ value: e[n]
1205
+ } : void 0,
1206
+ onSelect: (a) => {
1207
+ y(a) && l(`${s}.${n}`, a.value);
1208
+ }
1209
+ }
1210
+ ) });
1211
+ }
1212
+ function ht({
1213
+ item: e,
1214
+ pathPrefix: s
1215
+ }) {
1216
+ const n = "apply_on", { setPath: l } = f(), o = T({ item: e, optionName: n, pathPrefix: s });
1217
+ return !(n in e) || o == null ? null : /* @__PURE__ */ t.jsx(o.OptionRow, { children: /* @__PURE__ */ t.jsx(
1218
+ g,
1219
+ {
1220
+ initialValues: o.optionConfig?.values ?? [],
1221
+ isSearchable: !1,
1222
+ defaultValue: e[n] != null && e[n] !== "" ? {
1223
+ label: o.optionConfig?.values?.find(
1224
+ (a) => a.value === e[n]
1225
+ )?.label ?? e[n],
1226
+ value: e[n]
1227
+ } : void 0,
1228
+ onSelect: (a) => {
1229
+ y(a) && l(`${s}.${n}`, a.value);
1230
+ }
1231
+ }
1232
+ ) });
1233
+ }
1234
+ function T({
1235
+ item: e,
1236
+ optionName: s,
1237
+ pathPrefix: n
1238
+ }) {
1239
+ const { setPath: l, optionsConfig: o, schemaType: a } = f(), i = a === "order-rules" ? "order" : a === "price-rules" ? "price" : void 0, r = "type" in e && e.selector != null ? o.actions[e.type]?.[e.selector]?.find((c) => c.name === s) : o.conditions.find((c) => c.name === s), u = M(
1240
+ ({ children: c }) => /* @__PURE__ */ t.jsx(
1241
+ I,
1242
+ {
1243
+ label: /* @__PURE__ */ t.jsx(
1244
+ S,
1245
+ {
1246
+ className: "inline-flex",
1247
+ menuPosition: "bottom-left",
1248
+ dropdownItems: [
1249
+ /* @__PURE__ */ t.jsx(
1250
+ _,
1251
+ {
1252
+ onClick: () => {
1253
+ l(`${n}.${s}`, null);
1254
+ },
1255
+ label: "Remove"
1256
+ },
1257
+ "remove"
1258
+ )
1259
+ ],
1260
+ dropdownLabel: /* @__PURE__ */ t.jsx("button", { type: "button", children: /* @__PURE__ */ t.jsxs(
1261
+ $,
1262
+ {
1263
+ variant: "info",
1264
+ size: "small",
1265
+ className: "flex gap-2 items-center",
1266
+ children: [
1267
+ r?.label ?? ye[s],
1268
+ /* @__PURE__ */ t.jsx(v, { name: "caretDown" })
1269
+ ]
1270
+ }
1271
+ ) })
1272
+ }
1273
+ ),
1274
+ children: c
1275
+ }
1276
+ ),
1277
+ [n, s, r, l]
1278
+ );
1279
+ return !(s in e) || i == null ? null : {
1280
+ optionConfig: r,
1281
+ mainResourceId: i,
1282
+ OptionRow: u
1283
+ };
1284
+ }
1285
+ function gt({
1286
+ item: e,
1287
+ pathPrefix: s
1288
+ }) {
1289
+ const { setPath: n } = f();
1290
+ if (e == null)
1291
+ return null;
1292
+ switch (e.type) {
1293
+ case "buy_x_pay_y":
1294
+ return /* @__PURE__ */ t.jsxs("div", { className: "w-36 flex items-center gap-0.5", children: [
1295
+ /* @__PURE__ */ t.jsx(
1296
+ j,
1297
+ {
1298
+ name: `${s}.value.x`,
1299
+ type: "number",
1300
+ suffix: "X",
1301
+ defaultValue: e.value?.x,
1302
+ onChange: (l) => {
1303
+ n(
1304
+ `${s}.value.x`,
1305
+ parseInt(l.currentTarget.value, 10)
1306
+ );
1307
+ }
1308
+ }
1309
+ ),
1310
+ /* @__PURE__ */ t.jsx(
1311
+ j,
1312
+ {
1313
+ name: `${s}.value.y`,
1314
+ type: "number",
1315
+ suffix: "Y",
1316
+ defaultValue: e.value?.y,
1317
+ onChange: (l) => {
1318
+ n(
1319
+ `${s}.value.y`,
1320
+ parseInt(l.currentTarget.value, 10)
1321
+ );
1322
+ }
1323
+ }
1324
+ )
1325
+ ] });
1326
+ case "every_x_discount_y":
1327
+ return /* @__PURE__ */ t.jsxs("div", { className: "w-36 flex items-center gap-0.5", children: [
1328
+ /* @__PURE__ */ t.jsx(
1329
+ j,
1330
+ {
1331
+ name: `${s}.value.x`,
1332
+ type: "number",
1333
+ suffix: "X",
1334
+ defaultValue: e.value?.x,
1335
+ onChange: (l) => {
1336
+ n(
1337
+ `${s}.value.x`,
1338
+ parseInt(l.currentTarget.value, 10)
1339
+ );
1340
+ }
1341
+ }
1342
+ ),
1343
+ /* @__PURE__ */ t.jsx(
1344
+ j,
1345
+ {
1346
+ name: `${s}.value.y`,
1347
+ type: "number",
1348
+ suffix: "Y",
1349
+ defaultValue: e.value?.y,
1350
+ onChange: (l) => {
1351
+ n(
1352
+ `${s}.value.y`,
1353
+ parseInt(l.currentTarget.value, 10)
1354
+ );
1355
+ }
1356
+ }
1357
+ )
1358
+ ] });
1359
+ case "fixed_amount":
1360
+ case "fixed_price":
1361
+ return /* @__PURE__ */ t.jsx("div", { className: "w-36", children: /* @__PURE__ */ t.jsx(
1362
+ j,
1363
+ {
1364
+ name: `${s}.value`,
1365
+ type: "number",
1366
+ defaultValue: e.value,
1367
+ min: 0,
1368
+ suffix: "cents",
1369
+ onChange: (l) => {
1370
+ n(
1371
+ `${s}.value`,
1372
+ parseInt(l.currentTarget.value, 10)
1373
+ );
1374
+ }
1375
+ }
1376
+ ) });
1377
+ case "percentage": {
1378
+ const l = (e.value * 100).toFixed(2);
1379
+ return /* @__PURE__ */ t.jsx("div", { className: "w-24", children: /* @__PURE__ */ t.jsx(
1380
+ j,
1381
+ {
1382
+ name: `${s}.value`,
1383
+ type: "number",
1384
+ defaultValue: l.endsWith(".00") ? l.slice(0, -3) : l,
1385
+ min: 0,
1386
+ max: 100,
1387
+ suffix: "%",
1388
+ onChange: (o) => {
1389
+ n(
1390
+ `${s}.value`,
1391
+ parseFloat(o.currentTarget.value) / 100
1392
+ );
1393
+ }
1394
+ }
1395
+ ) });
1396
+ }
1397
+ default:
1398
+ return ae();
1399
+ }
1400
+ }
1401
+ function bt({
1402
+ item: e,
1403
+ index: s,
1404
+ onDelete: n
1405
+ }) {
1406
+ const {
1407
+ setPath: l,
1408
+ setRenderOption: o,
1409
+ state: { selectedRuleIndex: a },
1410
+ optionsConfig: i
1411
+ } = f(), r = Object.keys(
1412
+ i.actions
1413
+ ), u = e?.type != null && e?.selector != null ? i.actions?.[e.type]?.[e.selector] ?? [] : [], { available: c } = $e(
1414
+ e,
1415
+ u
1416
+ ), d = {
1417
+ percentage: "Percentage discount",
1418
+ fixed_amount: "Fixed amount",
1419
+ fixed_price: "Fixed price",
1420
+ buy_x_pay_y: "Buy X, Pay Y",
1421
+ every_x_discount_y: "Every X, Discount Y"
1422
+ }, m = `rules.${a}.actions.${s}`;
1423
+ return /* @__PURE__ */ t.jsx("div", { className: "mb-4 last:mb-0", children: /* @__PURE__ */ t.jsxs(
1424
+ xe,
1425
+ {
1426
+ pathPrefix: m,
1427
+ dropdownItems: n != null ? /* @__PURE__ */ t.jsx(
1428
+ _,
1429
+ {
1430
+ label: "Delete",
1431
+ onClick: () => {
1432
+ l(`${m}`, null), o(`${m}`, null), n();
1433
+ }
1434
+ }
1435
+ ) : void 0,
1436
+ options: /* @__PURE__ */ t.jsxs(t.Fragment, { children: [
1437
+ /* @__PURE__ */ t.jsx(xt, { item: e, pathPrefix: m }),
1438
+ /* @__PURE__ */ t.jsx(vt, { item: e, pathPrefix: m }),
1439
+ /* @__PURE__ */ t.jsx(Ne, { item: e, pathPrefix: m }),
1440
+ c.length > 0 && /* @__PURE__ */ t.jsx(
1441
+ S,
1442
+ {
1443
+ className: "inline-flex mt-6",
1444
+ menuPosition: "bottom-left",
1445
+ dropdownItems: c.map((h) => /* @__PURE__ */ t.jsx(
1446
+ _,
1447
+ {
1448
+ onClick: () => {
1449
+ switch (h.name) {
1450
+ case "round":
1451
+ l(`${m}.round`, !0);
1452
+ break;
1453
+ case "apply_on":
1454
+ l(`${m}.apply_on`, null, !0);
1455
+ break;
1456
+ case "discount_mode":
1457
+ l(`${m}.discount_mode`, "default");
1458
+ break;
1459
+ case "limit":
1460
+ l(`${m}.limit`, {});
1461
+ break;
1462
+ case "aggregation":
1463
+ l(`${m}.aggregation`, {});
1464
+ break;
1465
+ case "bundle":
1466
+ l(`${m}.bundle`, {
1467
+ type: "balanced"
1468
+ });
1469
+ break;
1470
+ }
1471
+ },
1472
+ label: h.label
1473
+ },
1474
+ `option-${h.name}`
1475
+ )),
1476
+ dropdownLabel: /* @__PURE__ */ t.jsx("button", { type: "button", children: /* @__PURE__ */ t.jsxs($, { className: "flex gap-2 items-center", children: [
1477
+ /* @__PURE__ */ t.jsx($, { weight: "bold", size: "small", children: "Add option" }),
1478
+ " ",
1479
+ /* @__PURE__ */ t.jsx(v, { name: "caretDown" })
1480
+ ] }) })
1481
+ }
1482
+ )
1483
+ ] }),
1484
+ children: [
1485
+ /* @__PURE__ */ t.jsx("div", { className: "flex-1", children: /* @__PURE__ */ t.jsx(
1486
+ g,
1487
+ {
1488
+ name: `${m}.type`,
1489
+ defaultValue: e != null && e.type != null ? {
1490
+ label: d[e.type],
1491
+ value: e.type
1492
+ } : void 0,
1493
+ initialValues: r.map((h) => ({
1494
+ value: h,
1495
+ label: d[h]
1496
+ })),
1497
+ onSelect: (h) => {
1498
+ y(h) && l(`${m}.type`, h.value);
1499
+ }
1500
+ }
1501
+ ) }),
1502
+ /* @__PURE__ */ t.jsx(gt, { item: e, pathPrefix: m })
1503
+ ]
1504
+ }
1505
+ ) });
1506
+ }
1507
+ function xt({
1508
+ item: e,
1509
+ pathPrefix: s
1510
+ }) {
1511
+ const { setPath: n, schemaType: l } = f(), { t: o } = re(), a = yt[l].map((r) => ({
1512
+ value: r,
1513
+ label: o(`resource_paths.${r}`).replace(
1514
+ "resource_paths.",
1515
+ ""
1516
+ )
1517
+ })), i = `${s}.selector`;
1518
+ return /* @__PURE__ */ t.jsx(
1519
+ I,
1520
+ {
1521
+ label: /* @__PURE__ */ t.jsx($, { variant: "info", size: "small", children: "Apply to" }),
1522
+ children: /* @__PURE__ */ t.jsx(
1523
+ g,
1524
+ {
1525
+ name: i,
1526
+ isSearchable: !1,
1527
+ initialValues: a,
1528
+ value: e?.selector == null ? void 0 : a.find((r) => r.value === e.selector) ?? {
1529
+ value: e.selector,
1530
+ label: e.selector
1531
+ },
1532
+ onSelect: async (r) => {
1533
+ y(r) && (n(i, r.value), n(`${s}.apply_on`, null));
1534
+ }
1535
+ }
1536
+ )
1537
+ }
1538
+ );
1539
+ }
1540
+ function vt({
1541
+ item: e,
1542
+ pathPrefix: s
1543
+ }) {
1544
+ const { setPath: n, schemaType: l } = f(), o = be();
1545
+ return C(() => {
1546
+ o.length === 0 && (e?.groups ?? []).length > 0 && n(`${s}.groups`, []);
1547
+ }, [o]), o.length <= 0 && (e?.groups ?? []).length <= 0 ? null : /* @__PURE__ */ t.jsx(
1548
+ I,
1549
+ {
1550
+ label: /* @__PURE__ */ t.jsx($, { variant: "info", size: "small", children: "Groups" }),
1551
+ children: /* @__PURE__ */ t.jsx(
1552
+ g,
1553
+ {
1554
+ name: `${s}.groups`,
1555
+ isMulti: !0,
1556
+ isClearable: !1,
1557
+ value: e?.groups?.map((a) => ({
1558
+ label: o.includes(a) ? a : `⚠️   ${a}`,
1559
+ value: a
1560
+ })),
1561
+ initialValues: o.map((a) => ({
1562
+ value: a,
1563
+ label: a
1564
+ })),
1565
+ onSelect: (a) => {
1566
+ E(a) && (n(
1567
+ `${s}.groups`,
1568
+ a.map((i) => i.value)
1569
+ ), l === "order-rules" && a.length > 0 && n(`${s}.selector`, "order.line_items"));
1570
+ }
1571
+ }
1572
+ )
1573
+ }
1574
+ );
1575
+ }
1576
+ const yt = {
1577
+ "order-rules": [
1578
+ "order",
1579
+ "order.line_items",
1580
+ "order.line_items.line_item_options",
1581
+ "order.line_items.sku",
1582
+ "order.line_items.bundle",
1583
+ "order.line_items.shipment",
1584
+ "order.line_items.payment_method",
1585
+ "order.line_items.adjustment",
1586
+ "order.line_items.gift_card"
1587
+ ],
1588
+ "price-rules": ["price"]
1589
+ };
1590
+ function jt({
1591
+ actions: e
1592
+ }) {
1593
+ const [s, n] = x(0), {
1594
+ setPath: l,
1595
+ state: { selectedRuleIndex: o }
1596
+ } = f();
1597
+ return /* @__PURE__ */ t.jsxs(t.Fragment, { children: [
1598
+ /* @__PURE__ */ t.jsx("div", { children: e?.map((a, i, r) => /* @__PURE__ */ t.jsx(
1599
+ bt,
1600
+ {
1601
+ item: a,
1602
+ index: i,
1603
+ onDelete: r.length > 1 ? () => {
1604
+ n((u) => u + 1);
1605
+ } : void 0
1606
+ },
1607
+ `${o}-${i}-${s}`
1608
+ )) }),
1609
+ /* @__PURE__ */ t.jsx("div", { className: "mt-6", children: /* @__PURE__ */ t.jsxs(
1610
+ V,
1611
+ {
1612
+ size: "small",
1613
+ variant: "secondary",
1614
+ alignItems: "center",
1615
+ onClick: () => {
1616
+ l(
1617
+ `rules.${o}.actions.${e?.length ?? 0}`,
1618
+ {
1619
+ selector: "order"
1620
+ }
1621
+ );
1622
+ },
1623
+ children: [
1624
+ /* @__PURE__ */ t.jsx(v, { name: "plusCircle" }),
1625
+ " Add action"
1626
+ ]
1627
+ }
1628
+ ) })
1629
+ ] });
1630
+ }
1631
+ function _t({
1632
+ value: e,
1633
+ name: s
1634
+ }) {
1635
+ const { setPath: n, schemaType: l } = f(), { t: o } = re(), a = de(null), i = l === "order-rules" ? "order" : l === "price-rules" ? "price" : void 0, r = oe(
1636
+ $t.filter(
1637
+ (u) => i != null && u.startsWith(i)
1638
+ ).map((u) => ({
1639
+ value: u,
1640
+ label: o(`resource_paths.${u}`).replace(
1641
+ "resource_paths.",
1642
+ ""
1643
+ )
1644
+ })),
1645
+ "label"
1646
+ );
1647
+ return /* @__PURE__ */ t.jsx(
1648
+ g,
1649
+ {
1650
+ ref: a,
1651
+ name: s,
1652
+ initialValues: r,
1653
+ defaultValue: e != null ? r.find((u) => u.value === e) ?? {
1654
+ value: e,
1655
+ label: e
1656
+ } : void 0,
1657
+ asTextSearch: !0,
1658
+ isCreatable: !0,
1659
+ loadAsyncValues: async (u) => {
1660
+ if (i == null)
1661
+ return [];
1662
+ const c = r.filter(
1663
+ (p) => p.label.includes(u)
1664
+ ), d = (await Ie([i], u)).filter((p) => p.value.startsWith(u)).map((p) => {
1665
+ const b = p.type === "relationship" || p.value.endsWith(".metadata") ? `${p.value}.` : p.value;
1666
+ return {
1667
+ value: b,
1668
+ label: b
1669
+ };
1670
+ }), m = u.includes(".metadata") ? [{ label: u, value: u }] : [];
1671
+ return [...c, ...d, ...m];
1672
+ },
1673
+ onSelect: async (u) => {
1674
+ y(u) && (n(s, u.value), u.value.toString().endsWith(".") && a.current?.openMenu("first"));
1675
+ }
1676
+ }
1677
+ );
1678
+ }
1679
+ const $t = [
1680
+ "order.billing_address.country_code",
1681
+ "order.country_code",
1682
+ "order.currency_code",
1683
+ "order.customer_email",
1684
+ "order.customer.email",
1685
+ "order.customer.customer_group.id",
1686
+ "order.customer.customer_group.name",
1687
+ "order.customer.tags.id",
1688
+ "order.customer.tags.name",
1689
+ "order.line_items.item_type",
1690
+ "order.line_items.line_item_options.sku_option.tags.name",
1691
+ "order.line_items.options_amount_cents",
1692
+ "order.line_items.quantity",
1693
+ "order.line_items.reference",
1694
+ "order.line_items.shipment.id",
1695
+ "order.line_items.shipment.shipping_method.id",
1696
+ "order.line_items.shipment.shipping_method.name",
1697
+ "order.line_items.shipment.shipping_method.reference",
1698
+ "order.line_items.sku_code",
1699
+ "order.line_items.sku.code",
1700
+ "order.line_items.sku.id",
1701
+ "order.line_items.sku.inventory.quantity",
1702
+ "order.line_items.sku.name",
1703
+ "order.line_items.sku.shipping_category.id",
1704
+ "order.line_items.sku.sku_list_items.sku_list.id",
1705
+ "order.line_items.sku.sku_list_items.sku_list.name",
1706
+ "order.line_items.sku.tags.id",
1707
+ "order.line_items.sku.tags.name",
1708
+ "order.line_items.unit_amount_cents",
1709
+ "order.market.code",
1710
+ "order.market.id",
1711
+ "order.shipments_count",
1712
+ "order.shipping_address.country_code",
1713
+ "order.subtotal_amount_cents",
1714
+ "order.tags.name",
1715
+ "order.total_amount_cents",
1716
+ "price.jwt_customer.email",
1717
+ "price.jwt_customer.tags.id",
1718
+ "price.jwt_customer.tags.name",
1719
+ "price.sku.sku_list_items.sku_list.id",
1720
+ "price.sku.sku_list_items.sku_list.name",
1721
+ "price.sku.code",
1722
+ "price.sku.id",
1723
+ "price.sku.tags.id",
1724
+ "price.sku.tags.name",
1725
+ "price.processed_at",
1726
+ "price.amount_cents"
1727
+ ];
1728
+ function Nt({
1729
+ item: e,
1730
+ pathPrefix: s
1731
+ }) {
1732
+ const { setPath: n } = f(), { infos: l } = W(e);
1733
+ let o = l?.field?.type;
1734
+ o == null && (o = fe(e?.value));
1735
+ const a = l?.resource?.id, i = ["tag"], r = [
1736
+ "matches",
1737
+ "does_not_match",
1738
+ "array_match"
1739
+ ], u = me.filter(({ fieldTypes: c, visible: d }) => d !== !1 && c.includes(o)).filter(({ matcher: c }) => a == null || a != null && !i.includes(a) || r.includes(c)).map(({ matcher: c, label: d }) => ({ value: c, label: d }));
1740
+ return /* @__PURE__ */ t.jsx(
1741
+ g,
1742
+ {
1743
+ className: "min-w-[175px]",
1744
+ name: `${s}.matcher`,
1745
+ value: e != null && e.matcher != null ? u.find((c) => c.value === e.matcher) ?? {
1746
+ label: e.matcher != null ? `⚠️   ${e.matcher}` : "",
1747
+ value: e.matcher
1748
+ } : void 0,
1749
+ initialValues: u,
1750
+ onSelect: (c) => {
1751
+ y(c) && (n(`${s}.matcher`, c.value), ie.includes(
1752
+ c.value
1753
+ ) && n(`${s}.value`, null));
1754
+ }
1755
+ }
1756
+ );
1757
+ }
1758
+ const Ce = ({ value: e, pathKey: s, infos: n, onSelect: l }) => {
1759
+ const { sdkClient: o } = De(), { setPath: a } = f(), i = n?.field?.name ?? "id", r = Ze(n?.resource?.id), { data: u } = Y(
1760
+ r,
1761
+ "list",
1762
+ n?.resource?.id == null ? null : [J({ value: "" })]
1763
+ ), { data: c, isLoading: d } = Y(
1764
+ r,
1765
+ "list",
1766
+ n?.resource?.id == null ? null : [
1767
+ {
1768
+ ...J({ value: "" }),
1769
+ filters: {
1770
+ id_in: Array.isArray(e) ? e : [e]
1771
+ }
1772
+ }
1773
+ ]
1774
+ ), m = oe([...c ?? [], ...u ?? []], "id");
1775
+ function h(p) {
1776
+ return {
1777
+ label: m?.find((b) => b.id === p.toString())?.name ?? `${d ? "" : "⚠️ "}${p.toString()}`,
1778
+ value: p.toString()
1779
+ };
1780
+ }
1781
+ return /* @__PURE__ */ t.jsx(
1782
+ g,
1783
+ {
1784
+ placeholder: "Search...",
1785
+ isClearable: !1,
1786
+ isMulti: n?.matcherInfos?.isMulti,
1787
+ defaultValue: Array.isArray(e) ? e.map(h) : e != null ? h(e) : void 0,
1788
+ menuFooterText: u != null && u.meta.recordCount > 25 ? "Type to search for more options." : void 0,
1789
+ initialValues: ee(m ?? [], i),
1790
+ loadAsyncValues: async (p) => {
1791
+ const b = await o[r].list(J({ value: p }));
1792
+ return ee(b, i);
1793
+ },
1794
+ onSelect: (p) => {
1795
+ l?.(p), E(p) ? a(
1796
+ s,
1797
+ p.map((b) => b.value).filter((b) => b != null)
1798
+ ) : y(p) && a(s, p.value);
1799
+ }
1800
+ },
1801
+ `${n?.matcherInfos?.isMulti?.toString()}-${d}-${JSON.stringify(m)}`
1802
+ );
1803
+ };
1804
+ function J({ value: e }) {
1805
+ return {
1806
+ pageSize: 25,
1807
+ sort: {
1808
+ name: "asc"
1809
+ },
1810
+ filters: {
1811
+ name_cont: e
1812
+ }
1813
+ };
1814
+ }
1815
+ function ee(e, s) {
1816
+ return e.map((n) => ({
1817
+ label: n.name,
1818
+ // @ts-expect-error TODO: fix this
1819
+ value: n[s]
1820
+ }));
1821
+ }
1822
+ const R = {
1823
+ in_and: {
1824
+ label: "All of"
1825
+ },
1826
+ in_or: {
1827
+ label: "At least one of"
1828
+ },
1829
+ not_in_and: {
1830
+ label: "Not any of"
1831
+ },
1832
+ not_in_or: {
1833
+ label: "Not at least one of"
1834
+ }
1835
+ };
1836
+ function te({
1837
+ value: e,
1838
+ pathPrefix: s,
1839
+ hasResourceSelector: n = !1,
1840
+ infos: l
1841
+ }) {
1842
+ const { setPath: o } = f(), a = Object.keys(
1843
+ R
1844
+ )[0], i = ce(() => typeof e == "object" && e !== null && !Array.isArray(e) ? e : {
1845
+ [a]: []
1846
+ }, [e]);
1847
+ C(() => {
1848
+ (typeof e != "object" || Array.isArray(e) || e === null) && o(s, {
1849
+ [a]: []
1850
+ });
1851
+ }, [e]);
1852
+ const r = Object.keys(R).filter(
1853
+ (u) => !(u in i)
1854
+ );
1855
+ return /* @__PURE__ */ t.jsxs("div", { className: "flex flex-col gap-2", children: [
1856
+ Object.entries(i).map(([u, c], d) => /* @__PURE__ */ t.jsx(
1857
+ wt,
1858
+ {
1859
+ infos: l,
1860
+ hasResourceSelector: n,
1861
+ pathPrefix: s,
1862
+ defaultValue: c,
1863
+ initialMatcher: u,
1864
+ remainingKeys: r
1865
+ },
1866
+ `${s}.${// biome-ignore lint/suspicious/noArrayIndexKey: Using index as key is acceptable here since items are static
1867
+ d}`
1868
+ )),
1869
+ r.length > 0 && /* @__PURE__ */ t.jsxs(X, { top: "4", children: [
1870
+ /* @__PURE__ */ t.jsx(
1871
+ S,
1872
+ {
1873
+ className: "inline-flex",
1874
+ menuPosition: "bottom-left",
1875
+ dropdownItems: [
1876
+ r.map((u) => /* @__PURE__ */ t.jsx(
1877
+ _,
1878
+ {
1879
+ onClick: () => {
1880
+ o(`${s}.${u}`, []);
1881
+ },
1882
+ label: R[u].label
1883
+ },
1884
+ u
1885
+ ))
1886
+ ],
1887
+ dropdownLabel: /* @__PURE__ */ t.jsx("button", { type: "button", children: /* @__PURE__ */ t.jsxs($, { className: "flex gap-2 items-center", children: [
1888
+ /* @__PURE__ */ t.jsx($, { weight: "bold", size: "small", children: "Add value" }),
1889
+ " ",
1890
+ /* @__PURE__ */ t.jsx(v, { name: "caretDown" })
1891
+ ] }) })
1892
+ }
1893
+ ),
1894
+ /* @__PURE__ */ t.jsx(X, { top: "6", bottom: "2", children: /* @__PURE__ */ t.jsx(qe, { variant: "dashed" }) })
1895
+ ] })
1896
+ ] }, r.join("-"));
1897
+ }
1898
+ function wt({
1899
+ initialMatcher: e,
1900
+ defaultValue: s,
1901
+ pathPrefix: n,
1902
+ hasResourceSelector: l,
1903
+ infos: o,
1904
+ remainingKeys: a
1905
+ }) {
1906
+ const [i, r] = x(s), { setPath: u } = f();
1907
+ return C(() => {
1908
+ u(`${n}.${e}`, i);
1909
+ }, [i]), /* @__PURE__ */ t.jsx(
1910
+ I,
1911
+ {
1912
+ label: /* @__PURE__ */ t.jsx(
1913
+ S,
1914
+ {
1915
+ className: "inline-flex",
1916
+ menuPosition: "bottom-left",
1917
+ dropdownItems: [
1918
+ a.map((c) => /* @__PURE__ */ t.jsx(
1919
+ _,
1920
+ {
1921
+ onClick: () => {
1922
+ u(`${n}.${c}`, i), u(`${n}.${e}`, null);
1923
+ },
1924
+ label: R[c].label
1925
+ },
1926
+ c
1927
+ )),
1928
+ /* @__PURE__ */ t.jsx(
1929
+ z,
1930
+ {
1931
+ hidden: a.length === 0
1932
+ },
1933
+ "divider"
1934
+ ),
1935
+ /* @__PURE__ */ t.jsx(
1936
+ _,
1937
+ {
1938
+ disabled: a.length === Object.keys(R).length - 1,
1939
+ onClick: () => {
1940
+ u(`${n}.${e}`, null);
1941
+ },
1942
+ label: "Remove"
1943
+ },
1944
+ "remove"
1945
+ )
1946
+ ],
1947
+ dropdownLabel: /* @__PURE__ */ t.jsx("button", { type: "button", children: /* @__PURE__ */ t.jsxs(
1948
+ $,
1949
+ {
1950
+ variant: "info",
1951
+ size: "small",
1952
+ className: "flex gap-2 items-center",
1953
+ children: [
1954
+ R[e].label,
1955
+ " ",
1956
+ /* @__PURE__ */ t.jsx(v, { name: "caretDown" })
1957
+ ]
1958
+ }
1959
+ ) })
1960
+ }
1961
+ ),
1962
+ children: l ? /* @__PURE__ */ t.jsx(
1963
+ Ce,
1964
+ {
1965
+ infos: o,
1966
+ value: i,
1967
+ pathKey: `${n}.${e}`,
1968
+ onSelect: (c) => {
1969
+ E(c) && r(
1970
+ c.map(
1971
+ (d) => typeof d.value == "boolean" ? d.value.toString() : d.value
1972
+ )
1973
+ );
1974
+ }
1975
+ }
1976
+ ) : /* @__PURE__ */ t.jsx(
1977
+ g,
1978
+ {
1979
+ isMulti: !0,
1980
+ isCreatable: !0,
1981
+ placeholder: "Enter value",
1982
+ defaultValue: (Array.isArray(i) ? i : []).map((c) => ({
1983
+ value: c,
1984
+ label: c.toString()
1985
+ })),
1986
+ initialValues: [],
1987
+ onSelect: (c) => {
1988
+ E(c) && r(
1989
+ c.map(
1990
+ (d) => typeof d.value == "boolean" ? d.value.toString() : d.value
1991
+ )
1992
+ );
1993
+ }
1994
+ }
1995
+ )
1996
+ }
1997
+ );
1998
+ }
1999
+ function Ct({
2000
+ value: e,
2001
+ onChange: s
2002
+ }) {
2003
+ const [n, l] = x(
2004
+ Array.isArray(e) && typeof e[0] == "number" ? e[0] : null
2005
+ ), [o, a] = x(
2006
+ Array.isArray(e) && typeof e[1] == "number" ? e[1] : null
2007
+ );
2008
+ return /* @__PURE__ */ t.jsxs("div", { className: "flex items-center gap-4", children: [
2009
+ /* @__PURE__ */ t.jsx("div", { className: "grow", children: /* @__PURE__ */ t.jsx(
2010
+ j,
2011
+ {
2012
+ type: "number",
2013
+ placeholder: "Min",
2014
+ value: n ?? "",
2015
+ onChange: (i) => {
2016
+ const r = parseInt(i.currentTarget.value, 10);
2017
+ l(Number.isNaN(r) ? null : r), s([Number.isNaN(r) ? null : r, o]);
2018
+ }
2019
+ }
2020
+ ) }),
2021
+ /* @__PURE__ */ t.jsx("span", { className: "text-gray-300", children: "to" }),
2022
+ /* @__PURE__ */ t.jsx("div", { className: "grow", children: /* @__PURE__ */ t.jsx(
2023
+ j,
2024
+ {
2025
+ type: "number",
2026
+ placeholder: "Max",
2027
+ value: o ?? "",
2028
+ onChange: (i) => {
2029
+ const r = parseInt(i.currentTarget.value, 10);
2030
+ a(Number.isNaN(r) ? null : r), s([n, Number.isNaN(r) ? null : r]);
2031
+ }
2032
+ }
2033
+ ) })
2034
+ ] });
2035
+ }
2036
+ function Tt({
2037
+ value: e,
2038
+ onChange: s
2039
+ }) {
2040
+ const [n, l] = x(
2041
+ Array.isArray(e) && typeof e[0] == "string" ? e[0] : null
2042
+ ), [o, a] = x(
2043
+ Array.isArray(e) && typeof e[1] == "string" ? e[1] : null
2044
+ );
2045
+ return /* @__PURE__ */ t.jsxs("div", { className: "flex items-center gap-4", children: [
2046
+ /* @__PURE__ */ t.jsx("div", { className: "grow", children: /* @__PURE__ */ t.jsx(
2047
+ j,
2048
+ {
2049
+ type: "text",
2050
+ placeholder: "Min",
2051
+ value: n ?? "",
2052
+ onChange: (i) => {
2053
+ const r = i.currentTarget.value;
2054
+ l(r), s([r, o]);
2055
+ }
2056
+ }
2057
+ ) }),
2058
+ /* @__PURE__ */ t.jsx("span", { className: "text-gray-300", children: "to" }),
2059
+ /* @__PURE__ */ t.jsx("div", { className: "grow", children: /* @__PURE__ */ t.jsx(
2060
+ j,
2061
+ {
2062
+ type: "text",
2063
+ placeholder: "Max",
2064
+ value: o ?? "",
2065
+ onChange: (i) => {
2066
+ const r = i.currentTarget.value;
2067
+ a(r), s([n, r]);
2068
+ }
2069
+ }
2070
+ ) })
2071
+ ] });
2072
+ }
2073
+ function St({
2074
+ item: e,
2075
+ pathPrefix: s
2076
+ }) {
2077
+ const { setPath: n } = f(), { componentType: l, fieldType: o } = Vt(e), a = `${s}.value`, [i, r] = x(0), [u, c] = x({
2078
+ componentType: l,
2079
+ matcher: e?.matcher,
2080
+ field: e?.field
2081
+ }), d = e == null || ie.includes(
2082
+ e.matcher
2083
+ );
2084
+ return C(
2085
+ function() {
2086
+ u.componentType !== l && (c((p) => ({
2087
+ ...p,
2088
+ componentType: l
2089
+ })), u.matcher !== e?.matcher && (c((p) => ({
2090
+ ...p,
2091
+ matcher: e?.matcher
2092
+ })), e?.matcher === "array_match" ? n(a, { in_and: [] }) : n(a, null), r((p) => p + 1))), u.field !== e?.field && (c((p) => ({
2093
+ ...p,
2094
+ field: e?.field
2095
+ })), n(a, null), r((p) => p + 1));
2096
+ },
2097
+ [e]
2098
+ ), d ? null : l === "arrayMatch" || l === "resourceSelector" && e?.matcher === "array_match" ? /* @__PURE__ */ t.jsx("div", { children: /* @__PURE__ */ t.jsx(
2099
+ ne,
2100
+ {
2101
+ item: e,
2102
+ fieldType: o,
2103
+ componentType: l,
2104
+ pathKey: a
2105
+ }
2106
+ ) }, i) : /* @__PURE__ */ t.jsx(
2107
+ I,
2108
+ {
2109
+ label: /* @__PURE__ */ t.jsx($, { variant: "info", size: "small", children: "Value" }),
2110
+ children: /* @__PURE__ */ t.jsx(
2111
+ ne,
2112
+ {
2113
+ item: e,
2114
+ fieldType: o,
2115
+ componentType: l,
2116
+ pathKey: a
2117
+ }
2118
+ )
2119
+ },
2120
+ i
2121
+ );
2122
+ }
2123
+ function ne({
2124
+ item: e,
2125
+ fieldType: s,
2126
+ componentType: n,
2127
+ pathKey: l
2128
+ }) {
2129
+ const { setPath: o } = f(), { user: a } = ue(), { infos: i } = W(e), r = Te(e) ? e.value : void 0;
2130
+ switch (n) {
2131
+ case "date": {
2132
+ const u = Z(typeof r == "string" ? r : "");
2133
+ return /* @__PURE__ */ t.jsx(
2134
+ Fe,
2135
+ {
2136
+ value: L(u) ? u : void 0,
2137
+ showTimeSelect: !0,
2138
+ placeholder: "Enter value",
2139
+ onChange: (c) => {
2140
+ o(l, c?.toJSON());
2141
+ },
2142
+ timezone: a?.timezone
2143
+ }
2144
+ );
2145
+ }
2146
+ case "dateRange": {
2147
+ const u = Array.isArray(r) ? r.map((c) => {
2148
+ const d = Z(typeof c == "string" ? c : "");
2149
+ return L(d) ? d : null;
2150
+ }) : [null, null];
2151
+ return /* @__PURE__ */ t.jsx(
2152
+ Le,
2153
+ {
2154
+ value: u,
2155
+ showTimeSelect: !0,
2156
+ onChange: (c) => {
2157
+ o(
2158
+ l,
2159
+ c.map((d) => d?.toJSON() ?? null)
2160
+ );
2161
+ }
2162
+ }
2163
+ );
2164
+ }
2165
+ case "numberRange":
2166
+ return /* @__PURE__ */ t.jsx(
2167
+ Ct,
2168
+ {
2169
+ value: r,
2170
+ onChange: (u) => {
2171
+ o(l, u);
2172
+ }
2173
+ }
2174
+ );
2175
+ case "textRange":
2176
+ return /* @__PURE__ */ t.jsx(
2177
+ Tt,
2178
+ {
2179
+ value: r,
2180
+ onChange: (u) => {
2181
+ o(l, u);
2182
+ }
2183
+ }
2184
+ );
2185
+ case "arrayMatch":
2186
+ return /* @__PURE__ */ t.jsx(te, { infos: i, value: r, pathPrefix: l });
2187
+ case "tag":
2188
+ return /* @__PURE__ */ t.jsx(
2189
+ g,
2190
+ {
2191
+ isMulti: !0,
2192
+ isClearable: !1,
2193
+ isCreatable: !0,
2194
+ defaultValue: Array.isArray(r) ? r.map((u) => ({
2195
+ label: u.toString(),
2196
+ value: u
2197
+ })) : [],
2198
+ initialValues: [],
2199
+ onSelect: (u) => {
2200
+ E(u) && o(
2201
+ l,
2202
+ u.map((c) => {
2203
+ if (s === "integer") {
2204
+ const d = parseInt(c.value.toString(), 10);
2205
+ return Number.isNaN(d) ? null : d;
2206
+ }
2207
+ return c.value;
2208
+ }).filter((c) => c != null)
2209
+ );
2210
+ }
2211
+ }
2212
+ );
2213
+ case "resourceSelector":
2214
+ return e?.matcher === "array_match" ? /* @__PURE__ */ t.jsx(
2215
+ te,
2216
+ {
2217
+ infos: i,
2218
+ value: r,
2219
+ pathPrefix: l,
2220
+ hasResourceSelector: !0
2221
+ }
2222
+ ) : /* @__PURE__ */ t.jsx(Ce, { infos: i, value: r, pathKey: l });
2223
+ case "number":
2224
+ return /* @__PURE__ */ t.jsx(
2225
+ j,
2226
+ {
2227
+ name: l,
2228
+ type: "number",
2229
+ defaultValue: typeof r == "number" ? r : "",
2230
+ placeholder: "Enter value",
2231
+ onChange: (u) => {
2232
+ o(l, parseInt(u.currentTarget.value, 10));
2233
+ }
2234
+ }
2235
+ );
2236
+ case "boolean":
2237
+ return /* @__PURE__ */ t.jsx(
2238
+ g,
2239
+ {
2240
+ name: l,
2241
+ defaultValue: typeof r == "boolean" ? {
2242
+ label: r ? "Yes" : "No",
2243
+ value: r
2244
+ } : void 0,
2245
+ initialValues: [
2246
+ { label: "Yes", value: !0 },
2247
+ { label: "No", value: !1 }
2248
+ ],
2249
+ onSelect: (u) => {
2250
+ y(u) && o(l, u.value);
2251
+ }
2252
+ }
2253
+ );
2254
+ case "text":
2255
+ case null:
2256
+ return /* @__PURE__ */ t.jsx(
2257
+ j,
2258
+ {
2259
+ name: l,
2260
+ type: "text",
2261
+ defaultValue: typeof r == "string" ? r : JSON.stringify(r),
2262
+ placeholder: "Enter value",
2263
+ onChange: (u) => {
2264
+ o(l, u.currentTarget.value);
2265
+ }
2266
+ }
2267
+ );
2268
+ default:
2269
+ return ae();
2270
+ }
2271
+ }
2272
+ function Te(e) {
2273
+ return e != null && "value" in e;
2274
+ }
2275
+ function At(e, s, n) {
2276
+ let l = null;
2277
+ switch (e) {
2278
+ case "datetime": {
2279
+ l = "date";
2280
+ break;
2281
+ }
2282
+ case "boolean": {
2283
+ l = "boolean";
2284
+ break;
2285
+ }
2286
+ case "string": {
2287
+ l = "text";
2288
+ break;
2289
+ }
2290
+ case "integer":
2291
+ case "float": {
2292
+ l = "number";
2293
+ break;
2294
+ }
2295
+ case "array":
2296
+ case "json":
2297
+ case "object":
2298
+ break;
2299
+ default: {
2300
+ l = "text";
2301
+ break;
2302
+ }
2303
+ }
2304
+ switch (s) {
2305
+ case "eq":
2306
+ case "not_eq":
2307
+ case "lt":
2308
+ case "lteq":
2309
+ case "gt":
2310
+ case "gteq":
2311
+ case "multiple":
2312
+ case "start_with":
2313
+ case "not_start_with":
2314
+ case "end_with":
2315
+ case "not_end_with":
2316
+ break;
2317
+ case "matches":
2318
+ case "does_not_match":
2319
+ break;
2320
+ case "gt_lt":
2321
+ case "gteq_lt":
2322
+ case "gt_lteq":
2323
+ case "gteq_lteq": {
2324
+ l === "number" && (l = "numberRange"), l === "text" && (l = "textRange"), l === "date" && (l = "dateRange");
2325
+ break;
2326
+ }
2327
+ case "is_in":
2328
+ case "is_not_in": {
2329
+ l = "tag";
2330
+ break;
2331
+ }
2332
+ case "array_match": {
2333
+ l = "arrayMatch";
2334
+ break;
2335
+ }
2336
+ }
2337
+ return n?.resourceSelectorAvailable && (l = "resourceSelector"), l;
2338
+ }
2339
+ function Vt(e) {
2340
+ const { infos: s } = W(e);
2341
+ let n = s?.field?.type;
2342
+ Te(e) && (n == null && (n = fe(e.value)), (typeof e.value == "string" && /^{{.*}}$/.test(e.value) || Array.isArray(e.value) && e.value.some((o) => typeof o == "string" && /^{{.*}}$/.test(o))) && (n = "string"));
2343
+ const l = At(n, e?.matcher, s);
2344
+ return { fieldType: n, componentType: l };
2345
+ }
2346
+ function kt({
2347
+ item: e,
2348
+ nestingLevel: s,
2349
+ pathPrefix: n,
2350
+ onDelete: l
2351
+ }) {
2352
+ const { setPath: o, setRenderOption: a, optionsConfig: i } = f(), { available: r } = $e(
2353
+ e,
2354
+ i.conditions
2355
+ ), u = [];
2356
+ return s < 2 && (u[0] ??= [], u[0].push(
2357
+ /* @__PURE__ */ t.jsx(
2358
+ _,
2359
+ {
2360
+ label: "Nest conditions",
2361
+ onClick: () => {
2362
+ o(
2363
+ `${n}.nested.conditions.${(e?.nested?.conditions ?? []).length}`,
2364
+ void 0
2365
+ );
2366
+ }
2367
+ }
2368
+ )
2369
+ )), l != null && (u[1] ??= [], u[1].push(
2370
+ /* @__PURE__ */ t.jsx(
2371
+ _,
2372
+ {
2373
+ label: "Delete",
2374
+ onClick: () => {
2375
+ o(`${n}`, null), a(`${n}`, null), l();
2376
+ }
2377
+ }
2378
+ )
2379
+ )), /* @__PURE__ */ t.jsx("div", { children: /* @__PURE__ */ t.jsxs(
2380
+ xe,
2381
+ {
2382
+ pathPrefix: n,
2383
+ dropdownItems: u.map((c, d, m) => (
2384
+ // biome-ignore lint/suspicious/noArrayIndexKey: Using index as key is acceptable here since items are static
2385
+ /* @__PURE__ */ t.jsxs(P.Fragment, { children: [
2386
+ c.map((h, p) => (
2387
+ // biome-ignore lint/suspicious/noArrayIndexKey: Using index as key is acceptable here since items are static
2388
+ /* @__PURE__ */ t.jsx(P.Fragment, { children: h }, p)
2389
+ )),
2390
+ d < m.length - 1 && /* @__PURE__ */ t.jsx(z, {})
2391
+ ] }, d)
2392
+ )),
2393
+ options: !H(e?.field) && !H(e?.matcher) && /* @__PURE__ */ t.jsxs(t.Fragment, { children: [
2394
+ /* @__PURE__ */ t.jsx(St, { item: e, pathPrefix: n }),
2395
+ /* @__PURE__ */ t.jsx(Ne, { item: e, pathPrefix: n }),
2396
+ r.length > 0 && /* @__PURE__ */ t.jsx(
2397
+ S,
2398
+ {
2399
+ className: "inline-flex mt-6",
2400
+ menuPosition: "bottom-left",
2401
+ dropdownItems: r.map((c) => /* @__PURE__ */ t.jsx(
2402
+ _,
2403
+ {
2404
+ onClick: () => {
2405
+ switch (c.name) {
2406
+ case "scope":
2407
+ o(`${n}.scope`, "any");
2408
+ break;
2409
+ case "aggregations":
2410
+ o(`${n}.aggregations`, [{}]);
2411
+ break;
2412
+ case "group":
2413
+ o(`${n}.group`, null, !0);
2414
+ break;
2415
+ }
2416
+ },
2417
+ label: c.label
2418
+ },
2419
+ `option-${c.name}`
2420
+ )),
2421
+ dropdownLabel: /* @__PURE__ */ t.jsx("button", { type: "button", children: /* @__PURE__ */ t.jsxs($, { className: "flex gap-2 items-center", children: [
2422
+ /* @__PURE__ */ t.jsx($, { weight: "bold", size: "small", children: "Add option" }),
2423
+ " ",
2424
+ /* @__PURE__ */ t.jsx(v, { name: "caretDown" })
2425
+ ] }) })
2426
+ }
2427
+ )
2428
+ ] }),
2429
+ children: [
2430
+ /* @__PURE__ */ t.jsx("div", { className: "flex-1", children: /* @__PURE__ */ t.jsx(_t, { value: e?.field, name: `${n}.field` }) }),
2431
+ /* @__PURE__ */ t.jsx("div", { children: /* @__PURE__ */ t.jsx(Nt, { item: e, pathPrefix: n }) })
2432
+ ]
2433
+ }
2434
+ ) });
2435
+ }
2436
+ function Se({
2437
+ item: e,
2438
+ children: s,
2439
+ nestingLevel: n = 0,
2440
+ pathPrefix: l
2441
+ }) {
2442
+ const {
2443
+ state: { selectedRuleIndex: o }
2444
+ } = f(), a = e?.conditions_logic?.toLowerCase() ?? "and", { setPath: i } = f(), [r, u] = x(0), c = n > 0;
2445
+ return /* @__PURE__ */ t.jsxs(
2446
+ "div",
2447
+ {
2448
+ className: A("query-group", {
2449
+ "p-4 border border-gray-200 rounded-md": c
2450
+ }),
2451
+ children: [
2452
+ s,
2453
+ e != null && (e.conditions ?? []).length > 0 && /* @__PURE__ */ t.jsxs(t.Fragment, { children: [
2454
+ c && /* @__PURE__ */ t.jsxs(
2455
+ "select",
2456
+ {
2457
+ onChange: (d) => {
2458
+ i(
2459
+ `${l}.conditions_logic`,
2460
+ d.currentTarget.value
2461
+ );
2462
+ },
2463
+ defaultValue: a,
2464
+ className: "pl-4 pr-8 py-2 font-bold focus:ring-0 focus:outline-hidden appearance-none bg-gray-50 border border-gray-200 rounded-md text-sm leading-4",
2465
+ children: [
2466
+ /* @__PURE__ */ t.jsx("option", { value: "and", children: "Nested in AND" }),
2467
+ /* @__PURE__ */ t.jsx("option", { value: "or", children: "Nested in OR" })
2468
+ ]
2469
+ }
2470
+ ),
2471
+ /* @__PURE__ */ t.jsx(
2472
+ "div",
2473
+ {
2474
+ className: A({
2475
+ "border-l border-gray-200 ml-3 pt-3": c
2476
+ }),
2477
+ children: e?.conditions?.map((d, m, h) => {
2478
+ const p = m === h.length - 1;
2479
+ return /* @__PURE__ */ t.jsxs(
2480
+ "div",
2481
+ {
2482
+ className: "flex items-center mb-4 last:mb-0 relative",
2483
+ children: [
2484
+ c && /* @__PURE__ */ t.jsx(Mt, { rounded: p }),
2485
+ /* @__PURE__ */ t.jsx(
2486
+ "div",
2487
+ {
2488
+ className: A("w-full", {
2489
+ "ml-4": c
2490
+ }),
2491
+ children: /* @__PURE__ */ t.jsx(
2492
+ Se,
2493
+ {
2494
+ item: d?.nested ?? void 0,
2495
+ nestingLevel: d?.nested != null ? n + 1 : 0,
2496
+ pathPrefix: `${l}.conditions.${m}.nested`,
2497
+ children: /* @__PURE__ */ t.jsx(
2498
+ "div",
2499
+ {
2500
+ className: A({
2501
+ "mb-4": d?.nested != null
2502
+ }),
2503
+ children: /* @__PURE__ */ t.jsx(
2504
+ kt,
2505
+ {
2506
+ item: d,
2507
+ nestingLevel: n,
2508
+ pathPrefix: `${l}.conditions.${m}`,
2509
+ onDelete: h.length > 1 || n > 0 ? () => {
2510
+ u((b) => b + 1);
2511
+ } : void 0
2512
+ }
2513
+ )
2514
+ }
2515
+ )
2516
+ }
2517
+ )
2518
+ }
2519
+ )
2520
+ ]
2521
+ },
2522
+ `${o}-${m}-${r}`
2523
+ );
2524
+ })
2525
+ }
2526
+ ),
2527
+ c && /* @__PURE__ */ t.jsx(
2528
+ V,
2529
+ {
2530
+ variant: "link",
2531
+ className: "ml-7 mt-4 text-sm font-bold !no-underline",
2532
+ onClick: () => {
2533
+ i(
2534
+ `${l}.conditions.${e?.conditions?.length ?? 0}`,
2535
+ void 0
2536
+ );
2537
+ },
2538
+ children: /* @__PURE__ */ t.jsxs($, { className: "flex items-center gap-1", children: [
2539
+ /* @__PURE__ */ t.jsx(v, { name: "plus" }),
2540
+ " Add condition"
2541
+ ] })
2542
+ }
2543
+ )
2544
+ ] })
2545
+ ]
2546
+ }
2547
+ );
2548
+ }
2549
+ function Mt({
2550
+ rounded: e = !1
2551
+ }) {
2552
+ return e ? /* @__PURE__ */ t.jsxs(t.Fragment, { children: [
2553
+ /* @__PURE__ */ t.jsx("div", { className: "absolute -left-px top-1/2 w-px h-1/2 bg-white" }),
2554
+ /* @__PURE__ */ t.jsx("div", { className: "absolute -left-px top-1/2 -translate-y-1/2 w-3.5 h-3.5 border-l border-b rounded-es-sm bg-white border-gray-200" })
2555
+ ] }) : /* @__PURE__ */ t.jsx("div", { className: "absolute left-0 top-1/2 -translate-y-1/2 w-3.5 h-px bg-gray-200" });
2556
+ }
2557
+ function Rt() {
2558
+ const {
2559
+ setPath: e,
2560
+ state: { value: s, selectedRuleIndex: n }
2561
+ } = f(), [l, o] = x(
2562
+ s.rules?.[n]?.name ?? ""
2563
+ );
2564
+ return C(() => {
2565
+ o(s.rules?.[n]?.name ?? "");
2566
+ }, [n]), // <Input
2567
+ // value={value.rules?.[selectedRuleIndex]?.name}
2568
+ // onChange={(event) => {
2569
+ // const target = event.currentTarget
2570
+ // const value = target.value.replace(/[\n\s]+/g, " ").trim()
2571
+ // setPath(`rules.${selectedRuleIndex}.name`, value)
2572
+ // }}
2573
+ // className="bg-transparent border-0 shadow-none field-sizing-content"
2574
+ // />
2575
+ // biome-ignore lint/a11y/noStaticElementInteractions: This <div> is used with contentEditable
2576
+ /* @__PURE__ */ t.jsx(
2577
+ "div",
2578
+ {
2579
+ contentEditable: "plaintext-only",
2580
+ suppressContentEditableWarning: !0,
2581
+ onInput: (a) => {
2582
+ const r = a.currentTarget.innerText.replace(/[\n\s]+/g, " ").trim();
2583
+ e(`rules.${n}.name`, r);
2584
+ },
2585
+ onKeyDown: (a) => {
2586
+ a.key === "Enter" && (a.preventDefault(), a.currentTarget.blur());
2587
+ },
2588
+ onBlur: (a) => {
2589
+ const i = a.currentTarget;
2590
+ i.innerText = i.innerText.replace(/[\n\s]+/g, " ").trim();
2591
+ },
2592
+ children: l
2593
+ },
2594
+ n
2595
+ );
2596
+ }
2597
+ const se = {
2598
+ rules: []
2599
+ }, F = (e) => {
2600
+ try {
2601
+ return JSON.parse(e ?? JSON.stringify(se));
2602
+ } catch {
2603
+ return se;
2604
+ }
2605
+ }, Ot = (e) => {
2606
+ try {
2607
+ return JSON.parse(e ?? "{}"), !0;
2608
+ } catch {
2609
+ return !1;
2610
+ }
2611
+ };
2612
+ function Jt(e) {
2613
+ const {
2614
+ settings: { domain: s }
2615
+ } = ue(), [n, l] = x({
2616
+ actions: {},
2617
+ conditions: []
2618
+ }), [o, a] = x(
2619
+ F(e.value ?? e.defaultValue)
2620
+ );
2621
+ return C(
2622
+ function() {
2623
+ o.rules?.length === 0 && a(F(e.value));
2624
+ },
2625
+ [e.value]
2626
+ ), C(
2627
+ function() {
2628
+ ze(e.schemaType, s).then((r) => {
2629
+ const u = tt(
2630
+ r,
2631
+ e.schemaType
2632
+ );
2633
+ l(u);
2634
+ });
2635
+ },
2636
+ [s]
2637
+ ), /* @__PURE__ */ t.jsx(
2638
+ Pe,
2639
+ {
2640
+ initialValue: {
2641
+ value: { rules: o.rules },
2642
+ schemaType: e.schemaType,
2643
+ optionsConfig: n
2644
+ },
2645
+ children: /* @__PURE__ */ t.jsx(Et, { ...e })
2646
+ }
2647
+ );
2648
+ }
2649
+ function Et(e) {
2650
+ const {
2651
+ state: { value: s, selectedRuleIndex: n },
2652
+ setSelectedRuleIndex: l,
2653
+ setValue: o,
2654
+ setPath: a
2655
+ } = f(), [i, r] = x(!1), [u, c] = x(
2656
+ e.defaultCodeEditorVisible ?? !1
2657
+ ), d = s.rules?.[n], m = de(null), [h, p] = x(0);
2658
+ C(
2659
+ function() {
2660
+ !i && !k(F(m.current?.getValue()), s) && (m.current?.setValue(JSON.stringify(s, null, 2)), e.onChange?.(s));
2661
+ },
2662
+ [s]
2663
+ );
2664
+ const b = M(
2665
+ (w) => {
2666
+ const N = F(w);
2667
+ i && Ot(w) && !k(N, s) && (o(N), p((G) => G + 1), e.onChange?.(N));
2668
+ },
2669
+ [s, i]
2670
+ );
2671
+ return /* @__PURE__ */ t.jsx(
2672
+ Ge,
2673
+ {
2674
+ hint: e.hint,
2675
+ feedback: e.feedback,
2676
+ className: "h-full [&>div:first-of-type]:h-full",
2677
+ children: /* @__PURE__ */ t.jsxs("section", { className: "flex h-full", children: [
2678
+ /* @__PURE__ */ t.jsxs(
2679
+ "div",
2680
+ {
2681
+ className: `shrink-0 basis-3/5 overflow-x-auto relative flex flex-col ${u ? "" : "grow"}`,
2682
+ children: [
2683
+ /* @__PURE__ */ t.jsxs("header", { className: "w-full bg-white border-b border-gray-200 px-4 flex text-[13px] gap-4 text-gray-400 font-semibold items-center", children: [
2684
+ /* @__PURE__ */ t.jsxs("div", { className: "flex items-center flex-wrap basis-full", children: [
2685
+ s.rules?.map((w, N, G) => {
2686
+ const Ae = `#${(N + 1).toString().padStart(2, "0")}`;
2687
+ return /* @__PURE__ */ t.jsxs(
2688
+ "div",
2689
+ {
2690
+ className: "flex items-center py-3 pl-4 pr-2 border-r basis-[88px] justify-center",
2691
+ children: [
2692
+ /* @__PURE__ */ t.jsx(
2693
+ "button",
2694
+ {
2695
+ type: "button",
2696
+ className: A("font-bold mr-2", {
2697
+ "text-black": n === N
2698
+ }),
2699
+ onClick: () => {
2700
+ l(N);
2701
+ },
2702
+ children: Ae
2703
+ }
2704
+ ),
2705
+ /* @__PURE__ */ t.jsx(
2706
+ S,
2707
+ {
2708
+ menuPosition: N === 0 ? "bottom-left" : "bottom-right",
2709
+ dropdownLabel: /* @__PURE__ */ t.jsx(V, { variant: "circle", children: /* @__PURE__ */ t.jsx(v, { name: "dotsThreeVertical", size: 16 }) }),
2710
+ dropdownItems: /* @__PURE__ */ t.jsxs(t.Fragment, { children: [
2711
+ /* @__PURE__ */ t.jsx(
2712
+ _,
2713
+ {
2714
+ onClick: () => {
2715
+ const U = s.rules?.length ?? 0;
2716
+ a(`rules.${U}`, {
2717
+ ...w,
2718
+ id: void 0,
2719
+ name: `${w.name} (copy)`
2720
+ }), l(U);
2721
+ },
2722
+ label: "Duplicate"
2723
+ }
2724
+ ),
2725
+ /* @__PURE__ */ t.jsx(z, {}),
2726
+ /* @__PURE__ */ t.jsx(
2727
+ _,
2728
+ {
2729
+ disabled: G.length === 1,
2730
+ onClick: () => {
2731
+ a(`rules.${N}`, null), n >= N && l(n - 1);
2732
+ },
2733
+ label: "Delete"
2734
+ }
2735
+ )
2736
+ ] })
2737
+ }
2738
+ )
2739
+ ]
2740
+ },
2741
+ `${N}-${w.id}`
2742
+ );
2743
+ }),
2744
+ /* @__PURE__ */ t.jsx("div", { className: "min-h-[49px] flex items-center", children: /* @__PURE__ */ t.jsx(
2745
+ V,
2746
+ {
2747
+ variant: "circle",
2748
+ className: "mx-4",
2749
+ onClick: () => {
2750
+ a(`rules.${s.rules?.length ?? 0}`, {
2751
+ name: "Rule name",
2752
+ actions: [null],
2753
+ conditions: [null]
2754
+ }), l(s.rules?.length ?? 0);
2755
+ },
2756
+ children: /* @__PURE__ */ t.jsx(v, { name: "plus", size: 16, className: "shrink-0" })
2757
+ }
2758
+ ) })
2759
+ ] }),
2760
+ /* @__PURE__ */ t.jsx("div", { className: "grow flex justify-end", children: /* @__PURE__ */ t.jsx(
2761
+ V,
2762
+ {
2763
+ variant: "circle",
2764
+ onClick: () => {
2765
+ c(!u);
2766
+ },
2767
+ children: /* @__PURE__ */ t.jsx(v, { name: "sidebarSimple", size: 16 })
2768
+ }
2769
+ ) })
2770
+ ] }),
2771
+ /* @__PURE__ */ t.jsx(Dt, { children: d && /* @__PURE__ */ t.jsxs(t.Fragment, { children: [
2772
+ /* @__PURE__ */ t.jsxs("div", { className: "mb-8 flex items-center gap-2", children: [
2773
+ /* @__PURE__ */ t.jsx(Rt, {}),
2774
+ /* @__PURE__ */ t.jsx(v, { name: "pencilSimple", size: 16, className: "shrink-0" })
2775
+ ] }),
2776
+ /* @__PURE__ */ t.jsxs(
2777
+ le,
2778
+ {
2779
+ title: /* @__PURE__ */ t.jsxs("div", { children: [
2780
+ "When",
2781
+ " ",
2782
+ /* @__PURE__ */ t.jsxs(
2783
+ "select",
2784
+ {
2785
+ onChange: (w) => {
2786
+ a(
2787
+ `rules.${n}.conditions_logic`,
2788
+ w.currentTarget.value
2789
+ );
2790
+ },
2791
+ value: d?.conditions_logic ?? "all",
2792
+ className: A(
2793
+ "pl-4 pr-8 py-2 font-bold focus:ring-0 focus:outline-hidden appearance-none bg-gray-50 border border-gray-200 rounded-md text-sm leading-4",
2794
+ "ml-1 mr-1.5"
2795
+ ),
2796
+ children: [
2797
+ /* @__PURE__ */ t.jsx("option", { value: "and", children: "All" }),
2798
+ /* @__PURE__ */ t.jsx("option", { value: "or", children: "Any" })
2799
+ ]
2800
+ }
2801
+ ),
2802
+ "conditions occur"
2803
+ ] }),
2804
+ icon: "treeView",
2805
+ children: [
2806
+ /* @__PURE__ */ t.jsx(
2807
+ Se,
2808
+ {
2809
+ item: d,
2810
+ pathPrefix: `rules.${n}`
2811
+ }
2812
+ ),
2813
+ /* @__PURE__ */ t.jsx("div", { className: "mt-6", children: /* @__PURE__ */ t.jsxs(
2814
+ V,
2815
+ {
2816
+ size: "small",
2817
+ variant: "secondary",
2818
+ alignItems: "center",
2819
+ onClick: () => {
2820
+ a(
2821
+ `rules.${n}.conditions.${d?.conditions?.length ?? 0}`,
2822
+ void 0
2823
+ );
2824
+ },
2825
+ children: [
2826
+ /* @__PURE__ */ t.jsx(v, { name: "plusCircle" }),
2827
+ " Add condition"
2828
+ ]
2829
+ }
2830
+ ) })
2831
+ ]
2832
+ }
2833
+ ),
2834
+ /* @__PURE__ */ t.jsx(It, { children: "do" }),
2835
+ /* @__PURE__ */ t.jsx(le, { title: "Actions", icon: "lightning", children: /* @__PURE__ */ t.jsx(jt, { actions: d?.actions }) })
2836
+ ] }) })
2837
+ ]
2838
+ },
2839
+ h
2840
+ ),
2841
+ u && /* @__PURE__ */ t.jsx("div", { className: "shrink-0 basis-2/5", children: /* @__PURE__ */ t.jsx(
2842
+ Je,
2843
+ {
2844
+ ref: m,
2845
+ name: e.id ?? e.name,
2846
+ height: "100%",
2847
+ language: "json",
2848
+ jsonSchema: e.schemaType,
2849
+ defaultValue: JSON.stringify(s, null, 2),
2850
+ noRounding: !0,
2851
+ onFocus: () => {
2852
+ r(!0);
2853
+ },
2854
+ onBlur: () => {
2855
+ r(!1);
2856
+ },
2857
+ onChange: b
2858
+ }
2859
+ ) })
2860
+ ] })
2861
+ }
2862
+ );
2863
+ }
2864
+ function It({ children: e }) {
2865
+ return /* @__PURE__ */ t.jsxs("div", { className: "text-gray-500 flex items-center justify-center flex-col", children: [
2866
+ /* @__PURE__ */ t.jsx("div", { className: "h-6 w-[2px] bg-gray-200" }),
2867
+ /* @__PURE__ */ t.jsx("span", { className: "font-bold my-1 bg-gray-200 px-3 relative uppercase rounded h-[25px] items-center flex text-sm", children: e }),
2868
+ /* @__PURE__ */ t.jsx("div", { className: "h-6 w-[2px] bg-gray-200" })
2869
+ ] });
2870
+ }
2871
+ function le({
2872
+ children: e,
2873
+ title: s,
2874
+ icon: n
2875
+ }) {
2876
+ return /* @__PURE__ */ t.jsxs("div", { className: "rounded-md bg-white shadow-xs", children: [
2877
+ /* @__PURE__ */ t.jsxs("div", { className: "flex items-center space-x-4 py-4 border-b border-gray-100", children: [
2878
+ /* @__PURE__ */ t.jsx("div", { className: "w-8 h-8 -ml-4 bg-white rounded-full border border-gray-200 flex items-center justify-center shadow-xs shadow-primary-200", children: /* @__PURE__ */ t.jsx(v, { name: n }) }),
2879
+ /* @__PURE__ */ t.jsx("h2", { className: "font-semibold", children: s })
2880
+ ] }),
2881
+ /* @__PURE__ */ t.jsx("div", { className: "p-6", children: e })
2882
+ ] });
2883
+ }
2884
+ function Dt({
2885
+ children: e
2886
+ }) {
2887
+ return /* @__PURE__ */ t.jsx("div", { className: "h-full w-full bg-gray-50 p-8 bg-[radial-gradient(#d6d6d6_1px,transparent_1px)] bg-size-[16px_16px] overflow-auto", children: /* @__PURE__ */ t.jsx("div", { className: "max-w-[900px] mx-auto", children: e }) });
2888
+ }
2889
+ export {
2890
+ Jt as RuleEngine
2891
+ };