@commercelayer/app-elements 6.2.2 → 6.4.0

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.
@@ -0,0 +1,2168 @@
1
+ "use client";
2
+ import { t as F, B as _e, D as Te, E as Ne, I as we, N as Me, O as Ce, P as Se, Z, b as $e, d as ke, e as Ee, f as Ae, g as Ve, h as Re, i as Ie, j as Ze, k as De, l as G, n as Oe, o as qe, p as Pe, q as Le, r as ze, s as Fe, u as Ge, v as Ue, w as Je, x as We, y as Be, z as Ye, A as Xe, C as He, F as Qe, G as Ke, H as et, J as tt, K as at, L as st, M as nt, Q as rt, R as lt, S as it, T as ot, U as ct, V as ut, W as dt, X as mt, Y as pt, _ as ht, $ as ft, a0 as xt, a1 as gt, a2 as bt, a3 as yt, a4 as vt, a5 as jt, a6 as _t, a7 as Tt, a8 as Nt, a9 as U, aa as wt, ab as Mt, ac as Ct, ad as St, ae as $t, af as kt, ag as Et, ah as At, ai as Vt, aj as Rt, ak as It, al as Zt, am as Dt, an as Ot, ao as qt, ap as Pt, aq as Lt, ar as zt, as as Ft, at as Gt, au as Ut, av as Jt, aw as Wt, ax as Bt, ay as Yt, az as Xt, aA as Ht, aB as Qt, aC as Kt, aD as ea, aE as ta, aF as aa, aG as sa, aH as na, aI as ra, aJ as la, aK as ia, aL as oa, aM as ca, aN as ua, aO as da, aP as ma, aQ as pa, aR as ha, aS as fa, aT as xa, aU as t, aV as q, aW as J, aX as E, aY as ga, aZ as ba, a_ as ya, a$ as y, b0 as V, b1 as M, b2 as ne, b3 as b, b4 as v, b5 as w, b6 as N, b7 as R, b8 as T, b9 as re, ba as S, bb as le, bc as va, bd as ie, be as ja, bf as W, bg as B, bh as _a, bi as P, bj as oe, bk as Ta, bl as Na, bm as wa, bn as Ma, bo as Ca } from "./main-0A5qZYJU.js";
3
+ import Y, { useReducer as Sa, useCallback as k, useMemo as ce, createContext as $a, useContext as ka, useState as x, useEffect as _, useRef as ue } from "react";
4
+ import "react-hook-form";
5
+ import "wouter";
6
+ import { p as X } from "./parseISO-DoHEiqUT.js";
7
+ function H(e, a) {
8
+ const s = 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 s ? F(
12
+ Date.UTC(
13
+ +s[1],
14
+ +s[2] - 1,
15
+ +s[3],
16
+ +s[4] - (+s[9] || 0) * (s[8] == "-" ? -1 : 1),
17
+ +s[5] - (+s[10] || 0) * (s[8] == "-" ? -1 : 1),
18
+ +s[6],
19
+ +((s[7] || "0") + "00").substring(0, 3)
20
+ ),
21
+ a?.in
22
+ ) : F(NaN, a?.in);
23
+ }
24
+ const g = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
25
+ __proto__: null,
26
+ BRAND: _e,
27
+ DIRTY: Te,
28
+ EMPTY_PATH: Ne,
29
+ INVALID: we,
30
+ NEVER: Me,
31
+ OK: Ce,
32
+ ParseStatus: Se,
33
+ Schema: Z,
34
+ ZodAny: $e,
35
+ ZodArray: ke,
36
+ ZodBigInt: Ee,
37
+ ZodBoolean: Ae,
38
+ ZodBranded: Ve,
39
+ ZodCatch: Re,
40
+ ZodDate: Ie,
41
+ ZodDefault: Ze,
42
+ ZodDiscriminatedUnion: De,
43
+ ZodEffects: G,
44
+ ZodEnum: Oe,
45
+ ZodError: qe,
46
+ get ZodFirstPartyTypeKind() {
47
+ return Pe;
48
+ },
49
+ ZodFunction: Le,
50
+ ZodIntersection: ze,
51
+ ZodIssueCode: Fe,
52
+ ZodLazy: Ge,
53
+ ZodLiteral: Ue,
54
+ ZodMap: Je,
55
+ ZodNaN: We,
56
+ ZodNativeEnum: Be,
57
+ ZodNever: Ye,
58
+ ZodNull: Xe,
59
+ ZodNullable: He,
60
+ ZodNumber: Qe,
61
+ ZodObject: Ke,
62
+ ZodOptional: et,
63
+ ZodParsedType: tt,
64
+ ZodPipeline: at,
65
+ ZodPromise: st,
66
+ ZodReadonly: nt,
67
+ ZodRecord: rt,
68
+ ZodSchema: Z,
69
+ ZodSet: lt,
70
+ ZodString: it,
71
+ ZodSymbol: ot,
72
+ ZodTransformer: G,
73
+ ZodTuple: ct,
74
+ ZodType: Z,
75
+ ZodUndefined: ut,
76
+ ZodUnion: dt,
77
+ ZodUnknown: mt,
78
+ ZodVoid: pt,
79
+ addIssueToContext: ht,
80
+ any: ft,
81
+ array: xt,
82
+ bigint: gt,
83
+ boolean: bt,
84
+ coerce: yt,
85
+ custom: vt,
86
+ date: jt,
87
+ datetimeRegex: _t,
88
+ defaultErrorMap: Tt,
89
+ discriminatedUnion: Nt,
90
+ effect: U,
91
+ enum: wt,
92
+ function: Mt,
93
+ getErrorMap: Ct,
94
+ getParsedType: St,
95
+ instanceof: $t,
96
+ intersection: kt,
97
+ isAborted: Et,
98
+ isAsync: At,
99
+ isDirty: Vt,
100
+ isValid: Rt,
101
+ late: It,
102
+ lazy: Zt,
103
+ literal: Dt,
104
+ makeIssue: Ot,
105
+ map: qt,
106
+ nan: Pt,
107
+ nativeEnum: Lt,
108
+ never: zt,
109
+ null: Ft,
110
+ nullable: Gt,
111
+ number: Ut,
112
+ object: Jt,
113
+ get objectUtil() {
114
+ return Wt;
115
+ },
116
+ oboolean: Bt,
117
+ onumber: Yt,
118
+ optional: Xt,
119
+ ostring: Ht,
120
+ pipeline: Qt,
121
+ preprocess: Kt,
122
+ promise: ea,
123
+ quotelessJson: ta,
124
+ record: aa,
125
+ set: sa,
126
+ setErrorMap: na,
127
+ strictObject: ra,
128
+ string: la,
129
+ symbol: ia,
130
+ transformer: U,
131
+ tuple: oa,
132
+ undefined: ca,
133
+ union: ua,
134
+ unknown: da,
135
+ get util() {
136
+ return ma;
137
+ },
138
+ void: pa
139
+ }, Symbol.toStringTag, { value: "Module" }));
140
+ var Ea = 1, Aa = 4;
141
+ function Va(e) {
142
+ return ha(e, Ea | Aa);
143
+ }
144
+ function D(e, a, s) {
145
+ return e == null ? e : fa(e, a, s);
146
+ }
147
+ function Q(e, a) {
148
+ return e == null ? !0 : xa(e, a);
149
+ }
150
+ const de = $a(
151
+ void 0
152
+ );
153
+ function Ra(e, a) {
154
+ switch (a.type) {
155
+ case "SET_PATH": {
156
+ const s = Va(e.value);
157
+ if (/actions\.\d\.[\w_]+$/.test(a.path)) {
158
+ const n = a.path.replace(/\.[\w_]+$/, "");
159
+ J(s, n)?.groups == null && D(s, `${n}.groups`, []);
160
+ }
161
+ if (a.value === null)
162
+ if (/\.\d+$/.test(a.path)) {
163
+ const n = a.path.replace(/\.\d+$/, ""), i = parseInt(a.path.match(/\d+$/)?.[0] ?? "0", 10), o = J(s, n);
164
+ Array.isArray(o) && (o.splice(i, 1), D(s, n, o), o.length === 0 && n.endsWith(".nested.conditions") && Q(s, n.replace(/\.conditions$/, "")));
165
+ } else
166
+ Q(s, a.path);
167
+ else
168
+ D(s, a.path, a.value);
169
+ return {
170
+ ...e,
171
+ value: s
172
+ };
173
+ }
174
+ case "SET_SELECTED_RULE_INDEX":
175
+ return {
176
+ ...e,
177
+ selectedRuleIndex: a.index
178
+ };
179
+ case "SET_VALUE":
180
+ return q(e.value, a.value) ? e : (a.value.rules?.length ?? 0) === 0 ? {
181
+ selectedRuleIndex: 0,
182
+ value: {
183
+ rules: [
184
+ {
185
+ name: "Rule name",
186
+ // @ts-expect-error Setting `null` is intentional for rendering an empty action
187
+ actions: [null],
188
+ // @ts-expect-error Setting `null` is intentional for rendering an empty condition
189
+ conditions: [null]
190
+ }
191
+ ]
192
+ }
193
+ } : {
194
+ ...e,
195
+ value: a.value
196
+ };
197
+ default:
198
+ return e;
199
+ }
200
+ }
201
+ function Ia({
202
+ children: e,
203
+ initialValue: a
204
+ }) {
205
+ const [s, n] = Sa(Ra, {
206
+ value: a.value,
207
+ selectedRuleIndex: 0
208
+ }), i = k((r, u) => {
209
+ n({ type: "SET_PATH", path: r, value: u });
210
+ }, []), o = k((r) => {
211
+ n({ type: "SET_SELECTED_RULE_INDEX", index: r }), r < 0 && setTimeout(() => {
212
+ n({ type: "SET_SELECTED_RULE_INDEX", index: 0 });
213
+ }, 50);
214
+ }, []), c = k((r) => {
215
+ n({ type: "SET_VALUE", value: r });
216
+ }, []), l = ce(
217
+ () => ({
218
+ state: s,
219
+ setPath: i,
220
+ setSelectedRuleIndex: o,
221
+ setValue: c,
222
+ availableActionTypes: a.availableActionTypes,
223
+ schemaType: a.schemaType
224
+ }),
225
+ [
226
+ s,
227
+ i,
228
+ o,
229
+ c,
230
+ a.availableActionTypes,
231
+ a.schemaType
232
+ ]
233
+ );
234
+ return /* @__PURE__ */ t.jsx(de.Provider, { value: l, children: e });
235
+ }
236
+ function f() {
237
+ const e = ka(de);
238
+ if (e === void 0)
239
+ throw new Error("useRuleEngine must be used within a RuleEngineProvider");
240
+ return e;
241
+ }
242
+ const me = [
243
+ {
244
+ /** Matches if field value equals provided value
245
+ * @field Integer, String, Datetime, Boolean
246
+ * @value Integer, String, Datetime, Boolean
247
+ */
248
+ matcher: "eq",
249
+ label: "equals",
250
+ fieldTypes: ["integer", "string", "datetime", "boolean"],
251
+ isMulti: !1,
252
+ exactMatch: !0
253
+ },
254
+ {
255
+ /** Matches if field value is not equal to provided value
256
+ * @field Integer, String, Datetime, Boolean
257
+ * @value Integer, String, Datetime, Boolean
258
+ */
259
+ matcher: "not_eq",
260
+ label: "not equals",
261
+ fieldTypes: ["integer", "string", "datetime", "boolean"],
262
+ isMulti: !1,
263
+ exactMatch: !0
264
+ },
265
+ {
266
+ /** Matches if field value is less than provided value
267
+ * @field Integer, Datetime
268
+ * @value Integer, Datetime
269
+ */
270
+ matcher: "lt",
271
+ label: "<",
272
+ fieldTypes: ["integer", "datetime"],
273
+ isMulti: !1,
274
+ exactMatch: !0
275
+ },
276
+ {
277
+ /** Matches if field value is less than or equal to provided value
278
+ * @field Integer, Datetime
279
+ * @value Integer, Datetime
280
+ */
281
+ matcher: "lteq",
282
+ label: "≤",
283
+ fieldTypes: ["integer", "datetime"],
284
+ isMulti: !1,
285
+ exactMatch: !0
286
+ },
287
+ {
288
+ /** Matches if field value is greater than provided value
289
+ * @field Integer, Datetime
290
+ * @value Integer, Datetime
291
+ */
292
+ matcher: "gt",
293
+ label: ">",
294
+ fieldTypes: ["integer", "datetime"],
295
+ isMulti: !1,
296
+ exactMatch: !0
297
+ },
298
+ {
299
+ /** Matches if field value is greater than or equal to provided value
300
+ * @field Integer, Datetime
301
+ * @value Integer, Datetime
302
+ */
303
+ matcher: "gteq",
304
+ label: "≥",
305
+ fieldTypes: ["integer", "datetime"],
306
+ isMulti: !1,
307
+ exactMatch: !0
308
+ },
309
+ {
310
+ /** Matches if field value is a multiple of provided value
311
+ * @field Integer
312
+ * @value Integer
313
+ */
314
+ matcher: "multiple",
315
+ label: "is a multiple of",
316
+ fieldTypes: ["integer"],
317
+ isMulti: !1,
318
+ exactMatch: !0
319
+ },
320
+ {
321
+ /** Matches if field value matches regex pattern
322
+ * @field String
323
+ * @value String
324
+ */
325
+ matcher: "matches",
326
+ label: "matches regex",
327
+ fieldTypes: ["string"],
328
+ isMulti: !1,
329
+ exactMatch: !1
330
+ },
331
+ {
332
+ /** Matches if field value does not match regex pattern
333
+ * @field String
334
+ * @value String
335
+ */
336
+ matcher: "does_not_match",
337
+ label: "doesn't match regex",
338
+ fieldTypes: ["string"],
339
+ isMulti: !1,
340
+ exactMatch: !1
341
+ },
342
+ {
343
+ /** Matches if field value starts with provided string
344
+ * @field String
345
+ * @value String
346
+ */
347
+ matcher: "start_with",
348
+ label: "starts with",
349
+ fieldTypes: ["string"],
350
+ isMulti: !1,
351
+ exactMatch: !1
352
+ },
353
+ {
354
+ /** Matches if field value does not start with provided string
355
+ * @field String
356
+ * @value String
357
+ */
358
+ matcher: "not_start_with",
359
+ label: "doesn't start with",
360
+ fieldTypes: ["string"],
361
+ isMulti: !1,
362
+ exactMatch: !1
363
+ },
364
+ {
365
+ /** Matches if field value ends with provided string
366
+ * @field String
367
+ * @value String
368
+ */
369
+ matcher: "end_with",
370
+ label: "ends with",
371
+ fieldTypes: ["string"],
372
+ isMulti: !1,
373
+ exactMatch: !1
374
+ },
375
+ {
376
+ /** Matches if field value does not end with provided string
377
+ * @field String
378
+ * @value String
379
+ */
380
+ matcher: "not_end_with",
381
+ label: "doesn't end with",
382
+ fieldTypes: ["string"],
383
+ isMulti: !1,
384
+ exactMatch: !1
385
+ },
386
+ {
387
+ /** Matches if field value is between two values (exclusive)
388
+ * @field Integer, Datetime
389
+ * @value Array
390
+ */
391
+ matcher: "gt_lt",
392
+ label: "> and <",
393
+ fieldTypes: ["integer"],
394
+ isMulti: !1,
395
+ exactMatch: !0
396
+ },
397
+ {
398
+ /** Matches if field value is between two values (inclusive start, exclusive end)
399
+ * @field Integer, Datetime
400
+ * @value Array
401
+ */
402
+ matcher: "gteq_lt",
403
+ label: "≥ and <",
404
+ fieldTypes: ["integer"],
405
+ isMulti: !1,
406
+ exactMatch: !0
407
+ },
408
+ {
409
+ /** Matches if field value is greater than first and less than or equal to second
410
+ * @field Integer, Datetime
411
+ * @value Array
412
+ */
413
+ matcher: "gt_lteq",
414
+ label: "> and ≤",
415
+ fieldTypes: ["integer"],
416
+ isMulti: !1,
417
+ exactMatch: !0
418
+ },
419
+ {
420
+ /** Matches if field value is between two values (inclusive)
421
+ * @field Integer, Datetime
422
+ * @value Array
423
+ */
424
+ matcher: "gteq_lteq",
425
+ label: "≥ and ≤",
426
+ fieldTypes: ["integer"],
427
+ isMulti: !1,
428
+ exactMatch: !0
429
+ },
430
+ {
431
+ /** Matches if field value is between two values (exclusive)
432
+ * @field Integer, Datetime
433
+ * @value Array
434
+ */
435
+ matcher: "gt_lt",
436
+ label: "date range",
437
+ visible: !1,
438
+ fieldTypes: ["datetime"],
439
+ isMulti: !1,
440
+ exactMatch: !0
441
+ },
442
+ {
443
+ /** Matches if field value is between two values (inclusive start, exclusive end)
444
+ * @field Integer, Datetime
445
+ * @value Array
446
+ */
447
+ matcher: "gteq_lt",
448
+ label: "date range",
449
+ visible: !1,
450
+ fieldTypes: ["datetime"],
451
+ isMulti: !1,
452
+ exactMatch: !0
453
+ },
454
+ {
455
+ /** Matches if field value is greater than first and less than or equal to second
456
+ * @field Integer, Datetime
457
+ * @value Array
458
+ */
459
+ matcher: "gt_lteq",
460
+ label: "date range",
461
+ visible: !1,
462
+ fieldTypes: ["datetime"],
463
+ isMulti: !1,
464
+ exactMatch: !0
465
+ },
466
+ {
467
+ /** Matches if field value is between two values (inclusive)
468
+ * @field Integer, Datetime
469
+ * @value Array
470
+ */
471
+ matcher: "gteq_lteq",
472
+ label: "date range",
473
+ visible: !0,
474
+ fieldTypes: ["datetime"],
475
+ isMulti: !1,
476
+ exactMatch: !0
477
+ },
478
+ {
479
+ /** Matches if field value is in provided array
480
+ * @field Integer, String, Datetime
481
+ * @value Array
482
+ */
483
+ matcher: "is_in",
484
+ label: "is one of",
485
+ fieldTypes: ["integer", "string", "datetime"],
486
+ isMulti: !0,
487
+ exactMatch: !0
488
+ },
489
+ {
490
+ /** Matches if field value is not in provided array
491
+ * @field Integer, String, Datetime
492
+ * @value Array
493
+ */
494
+ matcher: "is_not_in",
495
+ label: "is not one of",
496
+ fieldTypes: ["integer", "string", "datetime"],
497
+ isMulti: !0,
498
+ exactMatch: !0
499
+ },
500
+ {
501
+ /** Matches objects within arrays that meet specified requirements
502
+ * @field Array
503
+ * @value Object
504
+ */
505
+ matcher: "array_match",
506
+ label: "is",
507
+ fieldTypes: ["integer", "string", "datetime"],
508
+ isMulti: !0,
509
+ exactMatch: !0
510
+ },
511
+ {
512
+ /** Matches if field value is null or empty string */
513
+ matcher: "blank",
514
+ label: "is blank",
515
+ fieldTypes: ["integer", "string", "datetime", "boolean"],
516
+ isMulti: !1,
517
+ exactMatch: !0
518
+ },
519
+ {
520
+ /** Matches if field value is null */
521
+ matcher: "null",
522
+ label: "is null",
523
+ fieldTypes: ["integer", "string", "datetime", "boolean"],
524
+ isMulti: !1,
525
+ exactMatch: !0
526
+ },
527
+ {
528
+ /** Matches if field value is not null */
529
+ matcher: "not_null",
530
+ label: "is not null",
531
+ fieldTypes: ["integer", "string", "datetime", "boolean"],
532
+ isMulti: !1,
533
+ exactMatch: !0
534
+ },
535
+ {
536
+ /** Matches if field value is not null */
537
+ matcher: "present",
538
+ label: "is present",
539
+ fieldTypes: ["integer", "string", "datetime", "boolean"],
540
+ isMulti: !1,
541
+ exactMatch: !0
542
+ }
543
+ ];
544
+ function pe(e) {
545
+ if (typeof e == "string")
546
+ return E(H(e)) ? "datetime" : "string";
547
+ if (typeof e == "number")
548
+ return "integer";
549
+ if (typeof e == "boolean")
550
+ return "boolean";
551
+ if (Array.isArray(e)) {
552
+ if (typeof e[0] == "string")
553
+ return E(H(e[0])) ? "datetime" : "string";
554
+ if (typeof e[0] == "number")
555
+ return "integer";
556
+ }
557
+ return "string";
558
+ }
559
+ const he = {
560
+ market: "markets",
561
+ tag: "tags",
562
+ sku: "skus",
563
+ sku_list: "sku_lists"
564
+ };
565
+ function Za(e) {
566
+ return he[e];
567
+ }
568
+ function L(e) {
569
+ const [a, s] = x(void 0);
570
+ return _(() => {
571
+ e?.field != null && ga(e.field).then((n) => {
572
+ const i = me.find(
573
+ (o) => o.matcher === e.matcher
574
+ );
575
+ s({
576
+ ...n,
577
+ matcherInfos: i,
578
+ resourceSelectorAvailable: n?.resource?.id != null && Object.keys(he).includes(n.resource.id) && n.path.endsWith(".id") && i?.exactMatch === !0
579
+ });
580
+ }).catch((n) => {
581
+ console.error("Error fetching field info:", n);
582
+ });
583
+ }, [e?.field, e?.matcher]), { infos: a };
584
+ }
585
+ function fe(e) {
586
+ return e == null || e.length === 0 ? [] : ba(
587
+ ya(
588
+ e.flatMap((a) => [
589
+ a?.group,
590
+ ...fe(a?.nested?.conditions)
591
+ ])
592
+ )
593
+ );
594
+ }
595
+ function xe() {
596
+ const {
597
+ state: { selectedRuleIndex: e, value: a }
598
+ } = f();
599
+ return fe(
600
+ a.rules?.[e]?.conditions
601
+ );
602
+ }
603
+ const Da = ({ children: e }) => /* @__PURE__ */ t.jsx("div", { className: "bg-white rounded-md p-4 shadow-xs flex flex-col gap-2", children: e }), ge = ({ children: e, dropdownItems: a, options: s }) => {
604
+ const [n, i] = x(!0);
605
+ 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: [
606
+ /* @__PURE__ */ t.jsxs("div", { className: "flex items-center justify-between gap-2", children: [
607
+ e,
608
+ /* @__PURE__ */ t.jsxs("div", { className: "border border-gray-200 rounded self-stretch flex", children: [
609
+ /* @__PURE__ */ t.jsx(
610
+ "button",
611
+ {
612
+ type: "button",
613
+ onClick: () => {
614
+ i((o) => !o);
615
+ },
616
+ className: "w-11 flex self-stretch justify-center items-center",
617
+ children: /* @__PURE__ */ t.jsx(
618
+ y,
619
+ {
620
+ name: n ? "caretUp" : "caretDown",
621
+ size: 16
622
+ }
623
+ )
624
+ }
625
+ ),
626
+ a != null && /* @__PURE__ */ t.jsx(
627
+ V,
628
+ {
629
+ className: "flex self-stretch border-gray-100 border-l",
630
+ dropdownLabel: /* @__PURE__ */ t.jsx(
631
+ "button",
632
+ {
633
+ type: "button",
634
+ className: "w-11 flex self-stretch justify-center items-center",
635
+ children: /* @__PURE__ */ t.jsx(y, { name: "dotsThreeVertical", size: 16, weight: "bold" })
636
+ }
637
+ ),
638
+ dropdownItems: a
639
+ }
640
+ )
641
+ ] })
642
+ ] }),
643
+ n && /* @__PURE__ */ t.jsx(Da, { children: s })
644
+ ] }) }) });
645
+ }, $ = ({ children: e, label: a, className: s }) => /* @__PURE__ */ t.jsxs(
646
+ "div",
647
+ {
648
+ className: M(
649
+ "flex items-center gap-4 mt-2 first-of-type:mt-0",
650
+ s
651
+ ),
652
+ children: [
653
+ /* @__PURE__ */ t.jsx("div", { className: "basis-[180px] shrink-0", children: a }),
654
+ /* @__PURE__ */ t.jsx("div", { className: "grow", children: e })
655
+ ]
656
+ }
657
+ );
658
+ function Oa({
659
+ item: e,
660
+ pathPrefix: a
661
+ }) {
662
+ const { setPath: s } = f();
663
+ if (e == null)
664
+ return null;
665
+ switch (e.type) {
666
+ case "buy_x_pay_y":
667
+ return /* @__PURE__ */ t.jsxs("div", { className: "w-36 flex items-center gap-0.5", children: [
668
+ /* @__PURE__ */ t.jsx(
669
+ b,
670
+ {
671
+ name: `${a}.value.x`,
672
+ type: "number",
673
+ suffix: "X",
674
+ defaultValue: e.value?.x,
675
+ onChange: (n) => {
676
+ s(
677
+ `${a}.value.x`,
678
+ parseInt(n.currentTarget.value, 10)
679
+ );
680
+ }
681
+ }
682
+ ),
683
+ /* @__PURE__ */ t.jsx(
684
+ b,
685
+ {
686
+ name: `${a}.value.y`,
687
+ type: "number",
688
+ suffix: "Y",
689
+ defaultValue: e.value?.y,
690
+ onChange: (n) => {
691
+ s(
692
+ `${a}.value.y`,
693
+ parseInt(n.currentTarget.value, 10)
694
+ );
695
+ }
696
+ }
697
+ )
698
+ ] });
699
+ case "every_x_discount_y":
700
+ return /* @__PURE__ */ t.jsxs("div", { className: "w-36 flex items-center gap-0.5", children: [
701
+ /* @__PURE__ */ t.jsx(
702
+ b,
703
+ {
704
+ name: `${a}.value.x`,
705
+ type: "number",
706
+ suffix: "X",
707
+ defaultValue: e.value?.x,
708
+ onChange: (n) => {
709
+ s(
710
+ `${a}.value.x`,
711
+ parseInt(n.currentTarget.value, 10)
712
+ );
713
+ }
714
+ }
715
+ ),
716
+ /* @__PURE__ */ t.jsx(
717
+ b,
718
+ {
719
+ name: `${a}.value.y`,
720
+ type: "number",
721
+ suffix: "Y",
722
+ defaultValue: e.value?.y,
723
+ onChange: (n) => {
724
+ s(
725
+ `${a}.value.y`,
726
+ parseInt(n.currentTarget.value, 10)
727
+ );
728
+ }
729
+ }
730
+ )
731
+ ] });
732
+ case "fixed_amount":
733
+ case "fixed_price":
734
+ return /* @__PURE__ */ t.jsx("div", { className: "w-36", children: /* @__PURE__ */ t.jsx(
735
+ b,
736
+ {
737
+ name: `${a}.value`,
738
+ type: "number",
739
+ defaultValue: e.value,
740
+ min: 0,
741
+ suffix: "cents",
742
+ onChange: (n) => {
743
+ s(
744
+ `${a}.value`,
745
+ parseInt(n.currentTarget.value, 10)
746
+ );
747
+ }
748
+ }
749
+ ) });
750
+ case "percentage": {
751
+ const n = (e.value * 100).toFixed(2);
752
+ return /* @__PURE__ */ t.jsx("div", { className: "w-24", children: /* @__PURE__ */ t.jsx(
753
+ b,
754
+ {
755
+ name: `${a}.value`,
756
+ type: "number",
757
+ defaultValue: n.endsWith(".00") ? n.slice(0, -3) : n,
758
+ min: 0,
759
+ max: 100,
760
+ suffix: "%",
761
+ onChange: (i) => {
762
+ s(
763
+ `${a}.value`,
764
+ parseFloat(i.currentTarget.value) / 100
765
+ );
766
+ }
767
+ }
768
+ ) });
769
+ }
770
+ default:
771
+ return ne();
772
+ }
773
+ }
774
+ function qa({
775
+ item: e,
776
+ index: a,
777
+ onDelete: s
778
+ }) {
779
+ const {
780
+ setPath: n,
781
+ schemaType: i,
782
+ state: { selectedRuleIndex: o },
783
+ availableActionTypes: c
784
+ } = f(), l = xe(), r = {
785
+ percentage: "Percentage discount",
786
+ fixed_amount: "Fixed amount",
787
+ fixed_price: "Fixed price",
788
+ buy_x_pay_y: "Buy X, Pay Y",
789
+ every_x_discount_y: "Every X, Discount Y"
790
+ }, u = `rules.${o}.actions.${a}`;
791
+ return _(() => {
792
+ l.length === 0 && (e?.groups ?? []).length > 0 && n(`${u}.groups`, []);
793
+ }, [l]), /* @__PURE__ */ t.jsx("div", { className: "mb-4 last:mb-0", children: /* @__PURE__ */ t.jsxs(
794
+ ge,
795
+ {
796
+ dropdownItems: s != null ? /* @__PURE__ */ t.jsx(
797
+ T,
798
+ {
799
+ label: "Delete",
800
+ onClick: () => {
801
+ n(`${u}`, null), s();
802
+ }
803
+ }
804
+ ) : void 0,
805
+ options: /* @__PURE__ */ t.jsxs(t.Fragment, { children: [
806
+ /* @__PURE__ */ t.jsx(
807
+ $,
808
+ {
809
+ label: /* @__PURE__ */ t.jsx(N, { variant: "info", size: "small", children: "Apply to" }),
810
+ children: /* @__PURE__ */ t.jsx(
811
+ Pa,
812
+ {
813
+ value: e?.selector,
814
+ name: `${u}.selector`
815
+ }
816
+ )
817
+ }
818
+ ),
819
+ (l.length > 0 || (e?.groups ?? []).length > 0) && /* @__PURE__ */ t.jsx(
820
+ $,
821
+ {
822
+ label: /* @__PURE__ */ t.jsx(N, { variant: "info", size: "small", children: "Groups" }),
823
+ children: /* @__PURE__ */ t.jsx(
824
+ v,
825
+ {
826
+ name: `${u}.groups`,
827
+ isMulti: !0,
828
+ value: e?.groups?.map((d) => ({
829
+ label: l.includes(d) ? d : `⚠️   ${d}`,
830
+ value: d
831
+ })),
832
+ initialValues: l.map((d) => ({
833
+ value: d,
834
+ label: d
835
+ })),
836
+ onSelect: (d) => {
837
+ R(d) && (n(
838
+ `${u}.groups`,
839
+ d.map((h) => h.value)
840
+ ), i === "order-rules" && d.length > 0 && n(`${u}.selector`, "order.line_items"));
841
+ }
842
+ }
843
+ )
844
+ }
845
+ )
846
+ ] }),
847
+ children: [
848
+ /* @__PURE__ */ t.jsx("div", { className: "flex-1", children: /* @__PURE__ */ t.jsx(
849
+ v,
850
+ {
851
+ name: `${u}.type`,
852
+ defaultValue: e != null ? {
853
+ label: r[e.type],
854
+ value: e.type
855
+ } : void 0,
856
+ initialValues: c.map((d) => ({
857
+ value: d,
858
+ label: r[d]
859
+ })),
860
+ onSelect: (d) => {
861
+ w(d) && n(`${u}.type`, d.value);
862
+ }
863
+ }
864
+ ) }),
865
+ /* @__PURE__ */ t.jsx(Oa, { item: e, pathPrefix: u })
866
+ ]
867
+ }
868
+ ) });
869
+ }
870
+ function Pa({
871
+ value: e,
872
+ name: a
873
+ }) {
874
+ const { setPath: s, schemaType: n } = f(), { t: i } = re(), o = La[n].map((c) => ({
875
+ value: c,
876
+ label: i(`resource_paths.${c}`).replace(
877
+ "resource_paths.",
878
+ ""
879
+ )
880
+ }));
881
+ return /* @__PURE__ */ t.jsx(
882
+ v,
883
+ {
884
+ name: a,
885
+ isSearchable: !1,
886
+ initialValues: o,
887
+ value: o.find((c) => c.value === e),
888
+ onSelect: async (c) => {
889
+ w(c) && s(a, c.value);
890
+ }
891
+ }
892
+ );
893
+ }
894
+ const La = {
895
+ "order-rules": [
896
+ "order",
897
+ "order.line_items",
898
+ "order.line_items.line_item_options",
899
+ "order.line_items.sku",
900
+ "order.line_items.bundle",
901
+ "order.line_items.shipment",
902
+ "order.line_items.payment_method",
903
+ "order.line_items.adjustment",
904
+ "order.line_items.gift_card"
905
+ ],
906
+ "price-rules": ["price"]
907
+ };
908
+ function za({
909
+ actions: e
910
+ }) {
911
+ const [a, s] = x(0), {
912
+ setPath: n,
913
+ state: { selectedRuleIndex: i }
914
+ } = f();
915
+ return /* @__PURE__ */ t.jsxs(t.Fragment, { children: [
916
+ /* @__PURE__ */ t.jsx("div", { children: e?.map((o, c, l) => /* @__PURE__ */ t.jsx(
917
+ qa,
918
+ {
919
+ item: o,
920
+ index: c,
921
+ onDelete: l.length > 1 ? () => {
922
+ s((r) => r + 1);
923
+ } : void 0
924
+ },
925
+ `${i}-${c}-${a}`
926
+ )) }),
927
+ /* @__PURE__ */ t.jsx("div", { className: "mt-6", children: /* @__PURE__ */ t.jsxs(
928
+ S,
929
+ {
930
+ size: "small",
931
+ variant: "secondary",
932
+ alignItems: "center",
933
+ onClick: () => {
934
+ n(
935
+ `rules.${i}.actions.${e?.length ?? 0}`,
936
+ void 0
937
+ );
938
+ },
939
+ children: [
940
+ /* @__PURE__ */ t.jsx(y, { name: "plusCircle" }),
941
+ " Add action"
942
+ ]
943
+ }
944
+ ) })
945
+ ] });
946
+ }
947
+ function Fa({
948
+ value: e,
949
+ name: a
950
+ }) {
951
+ const { setPath: s, schemaType: n } = f(), { t: i } = re(), o = ue(null), c = n === "order-rules" ? "order" : n === "price-rules" ? "price" : void 0, l = le(
952
+ Ga.filter(
953
+ (r) => c != null && r.startsWith(c)
954
+ ).map((r) => ({
955
+ value: r,
956
+ label: i(`resource_paths.${r}`).replace(
957
+ "resource_paths.",
958
+ ""
959
+ )
960
+ })),
961
+ "label"
962
+ );
963
+ return /* @__PURE__ */ t.jsx(
964
+ v,
965
+ {
966
+ ref: o,
967
+ name: a,
968
+ initialValues: l,
969
+ defaultValue: e != null ? l.find((r) => r.value === e) ?? {
970
+ value: e,
971
+ label: e
972
+ } : void 0,
973
+ asTextSearch: !0,
974
+ isCreatable: !0,
975
+ loadAsyncValues: async (r) => {
976
+ if (c == null)
977
+ return [];
978
+ const u = l.filter(
979
+ (m) => m.label.includes(r)
980
+ ), d = (await va([c], r)).filter((m) => m.value.startsWith(r)).map((m) => {
981
+ const p = m.type === "relationship" || m.value.endsWith(".metadata") ? `${m.value}.` : m.value;
982
+ return {
983
+ value: p,
984
+ label: p
985
+ };
986
+ }), h = r.includes(".metadata") ? [{ label: r, value: r }] : [];
987
+ return [...u, ...d, ...h];
988
+ },
989
+ onSelect: async (r) => {
990
+ w(r) && (s(a, r.value), r.value.toString().endsWith(".") && o.current?.openMenu("first"));
991
+ }
992
+ }
993
+ );
994
+ }
995
+ const Ga = [
996
+ "order.billing_address.country_code",
997
+ "order.country_code",
998
+ "order.currency_code",
999
+ "order.customer_email",
1000
+ "order.customer.email",
1001
+ "order.customer.customer_group.id",
1002
+ "order.customer.customer_group.name",
1003
+ "order.customer.tags.id",
1004
+ "order.customer.tags.name",
1005
+ "order.line_items.item_type",
1006
+ "order.line_items.line_item_options.sku_option.tags.name",
1007
+ "order.line_items.options_amount_cents",
1008
+ "order.line_items.quantity",
1009
+ "order.line_items.reference",
1010
+ "order.line_items.shipment.id",
1011
+ "order.line_items.shipment.shipping_method.id",
1012
+ "order.line_items.shipment.shipping_method.name",
1013
+ "order.line_items.shipment.shipping_method.reference",
1014
+ "order.line_items.sku_code",
1015
+ "order.line_items.sku.code",
1016
+ "order.line_items.sku.id",
1017
+ "order.line_items.sku.inventory.quantity",
1018
+ "order.line_items.sku.name",
1019
+ "order.line_items.sku.shipping_category.id",
1020
+ "order.line_items.sku.sku_lists.id",
1021
+ "order.line_items.sku.sku_lists.name",
1022
+ "order.line_items.sku.tags.id",
1023
+ "order.line_items.sku.tags.name",
1024
+ "order.line_items.unit_amount_cents",
1025
+ "order.market.code",
1026
+ "order.market.id",
1027
+ "order.shipments_count",
1028
+ "order.shipping_address.country_code",
1029
+ "order.subtotal_amount_cents",
1030
+ "order.tags.name",
1031
+ "order.total_amount_cents",
1032
+ "price.jwt_customer.email",
1033
+ "price.jwt_customer.tags.id",
1034
+ "price.jwt_customer.tags.name",
1035
+ "price.sku.sku_list_items.sku_list.id",
1036
+ "price.sku.sku_list_items.sku_list.name",
1037
+ "price.sku.code",
1038
+ "price.sku.id",
1039
+ "price.sku.tags.id",
1040
+ "price.sku.tags.name",
1041
+ "price.processed_at",
1042
+ "price.amount_cents"
1043
+ ];
1044
+ function Ua({
1045
+ item: e,
1046
+ pathPrefix: a
1047
+ }) {
1048
+ const { setPath: s } = f(), { infos: n } = L(e);
1049
+ let i = n?.field?.type;
1050
+ i == null && (i = pe(e?.value));
1051
+ const o = n?.resource?.id, c = ["tag"], l = [
1052
+ "matches",
1053
+ "does_not_match",
1054
+ "array_match"
1055
+ ], r = me.filter(({ fieldTypes: u, visible: d }) => d !== !1 && u.includes(i)).filter(({ matcher: u }) => o == null || o != null && !c.includes(o) || l.includes(u)).map(({ matcher: u, label: d }) => ({ value: u, label: d }));
1056
+ return /* @__PURE__ */ t.jsx(
1057
+ v,
1058
+ {
1059
+ className: "min-w-[175px]",
1060
+ name: `${a}.matcher`,
1061
+ value: e != null ? r.find((u) => u.value === e.matcher) ?? {
1062
+ label: e.matcher != null ? `⚠️   ${e.matcher}` : "",
1063
+ value: e.matcher
1064
+ } : void 0,
1065
+ initialValues: r,
1066
+ onSelect: (u) => {
1067
+ w(u) && (s(`${a}.matcher`, u.value), ie.includes(
1068
+ u.value
1069
+ ) && s(`${a}.value`, null));
1070
+ }
1071
+ }
1072
+ );
1073
+ }
1074
+ const be = ({ value: e, pathKey: a, infos: s }) => {
1075
+ const { sdkClient: n } = ja(), { setPath: i } = f(), o = s?.field?.name ?? "id", c = Za(s?.resource?.id), { data: l, isLoading: r } = W(
1076
+ c,
1077
+ "list",
1078
+ s?.resource?.id == null ? null : [O({ value: "" })]
1079
+ ), { data: u, isLoading: d } = W(
1080
+ c,
1081
+ "list",
1082
+ s?.resource?.id == null ? null : [
1083
+ {
1084
+ ...O({ value: "" }),
1085
+ filters: {
1086
+ id_in: Array.isArray(e) ? e : [e]
1087
+ }
1088
+ }
1089
+ ]
1090
+ ), h = le([...u ?? [], ...l ?? []], "id");
1091
+ function j(m) {
1092
+ return {
1093
+ label: h?.find((p) => p.id === m.toString())?.name ?? m.toString(),
1094
+ value: m.toString()
1095
+ };
1096
+ }
1097
+ return /* @__PURE__ */ t.jsx(
1098
+ v,
1099
+ {
1100
+ placeholder: "Search...",
1101
+ isClearable: !1,
1102
+ isMulti: s?.matcherInfos?.isMulti,
1103
+ defaultValue: Array.isArray(e) ? e.map(j) : e != null ? j(e) : void 0,
1104
+ menuFooterText: l != null && l.meta.recordCount > 25 ? "Type to search for more options." : void 0,
1105
+ initialValues: K(h ?? [], o),
1106
+ loadAsyncValues: async (m) => {
1107
+ const p = await n[c].list(O({ value: m }));
1108
+ return K(p, o);
1109
+ },
1110
+ onSelect: (m) => {
1111
+ R(m) ? i(
1112
+ a,
1113
+ m.map((p) => p.value).filter((p) => p != null)
1114
+ ) : w(m) && i(a, m.value);
1115
+ }
1116
+ },
1117
+ `${s?.matcherInfos?.isMulti?.toString()}-${r}-${d}`
1118
+ );
1119
+ };
1120
+ function O({ value: e }) {
1121
+ return {
1122
+ pageSize: 25,
1123
+ sort: {
1124
+ name: "asc"
1125
+ },
1126
+ filters: {
1127
+ name_cont: e
1128
+ }
1129
+ };
1130
+ }
1131
+ function K(e, a) {
1132
+ return e.map((s) => ({
1133
+ label: s.name,
1134
+ // @ts-expect-error TODO: fix this
1135
+ value: s[a]
1136
+ }));
1137
+ }
1138
+ const C = {
1139
+ in_and: {
1140
+ label: "All of"
1141
+ },
1142
+ in_or: {
1143
+ label: "At least one of"
1144
+ },
1145
+ not_in_and: {
1146
+ label: "Not any of"
1147
+ },
1148
+ not_in_or: {
1149
+ label: "Not at least one of"
1150
+ }
1151
+ };
1152
+ function ee({
1153
+ value: e,
1154
+ pathPrefix: a,
1155
+ hasResourceSelector: s = !1,
1156
+ infos: n
1157
+ }) {
1158
+ const { setPath: i } = f(), o = Object.keys(
1159
+ C
1160
+ )[0], c = ce(() => typeof e == "object" && e !== null && !Array.isArray(e) ? e : {
1161
+ [o]: []
1162
+ }, [e]);
1163
+ _(() => {
1164
+ (typeof e != "object" || Array.isArray(e) || e === null) && i(a, {
1165
+ [o]: []
1166
+ });
1167
+ }, [e]);
1168
+ const l = Object.keys(C).filter(
1169
+ (r) => !(r in c)
1170
+ );
1171
+ return /* @__PURE__ */ t.jsxs("div", { className: "flex flex-col", children: [
1172
+ Object.entries(c).map(([r, u], d) => /* @__PURE__ */ t.jsx(
1173
+ Ja,
1174
+ {
1175
+ infos: n,
1176
+ hasResourceSelector: s,
1177
+ pathPrefix: a,
1178
+ defaultValue: u,
1179
+ initialMatcher: r,
1180
+ remainingKeys: l
1181
+ },
1182
+ `${a}.${// biome-ignore lint/suspicious/noArrayIndexKey: Using index as key is acceptable here since items are static
1183
+ d}`
1184
+ )),
1185
+ l.length > 0 && /* @__PURE__ */ t.jsxs(B, { top: "4", children: [
1186
+ /* @__PURE__ */ t.jsx(
1187
+ V,
1188
+ {
1189
+ className: "inline-flex",
1190
+ menuPosition: "bottom-left",
1191
+ dropdownItems: [
1192
+ l.map((r) => /* @__PURE__ */ t.jsx(
1193
+ T,
1194
+ {
1195
+ onClick: () => {
1196
+ i(`${a}.${r}`, []);
1197
+ },
1198
+ label: C[r].label
1199
+ },
1200
+ r
1201
+ ))
1202
+ ],
1203
+ dropdownLabel: /* @__PURE__ */ t.jsx("button", { type: "button", children: /* @__PURE__ */ t.jsxs(N, { className: "flex gap-2 items-center", children: [
1204
+ /* @__PURE__ */ t.jsx(N, { weight: "bold", size: "small", children: "Add value" }),
1205
+ " ",
1206
+ /* @__PURE__ */ t.jsx(y, { name: "caretDown" })
1207
+ ] }) })
1208
+ }
1209
+ ),
1210
+ /* @__PURE__ */ t.jsx(B, { top: "6", bottom: "2", children: /* @__PURE__ */ t.jsx(_a, { variant: "dashed" }) })
1211
+ ] })
1212
+ ] }, l.join("-"));
1213
+ }
1214
+ function Ja({
1215
+ initialMatcher: e,
1216
+ defaultValue: a,
1217
+ pathPrefix: s,
1218
+ hasResourceSelector: n,
1219
+ infos: i,
1220
+ remainingKeys: o
1221
+ }) {
1222
+ const [c, l] = x(a), { setPath: r } = f();
1223
+ return /* @__PURE__ */ t.jsx(
1224
+ $,
1225
+ {
1226
+ label: /* @__PURE__ */ t.jsx(
1227
+ V,
1228
+ {
1229
+ className: "inline-flex",
1230
+ menuPosition: "bottom-left",
1231
+ dropdownItems: [
1232
+ o.map((u) => /* @__PURE__ */ t.jsx(
1233
+ T,
1234
+ {
1235
+ onClick: () => {
1236
+ r(`${s}.${u}`, c), r(`${s}.${e}`, null);
1237
+ },
1238
+ label: C[u].label
1239
+ },
1240
+ u
1241
+ )),
1242
+ /* @__PURE__ */ t.jsx(
1243
+ P,
1244
+ {
1245
+ hidden: o.length === 0
1246
+ },
1247
+ "divider"
1248
+ ),
1249
+ /* @__PURE__ */ t.jsx(
1250
+ T,
1251
+ {
1252
+ disabled: o.length === Object.keys(C).length - 1,
1253
+ onClick: () => {
1254
+ r(`${s}.${e}`, null);
1255
+ },
1256
+ label: "Remove"
1257
+ },
1258
+ "remove"
1259
+ )
1260
+ ],
1261
+ dropdownLabel: /* @__PURE__ */ t.jsx("button", { type: "button", children: /* @__PURE__ */ t.jsxs(
1262
+ N,
1263
+ {
1264
+ variant: "info",
1265
+ size: "small",
1266
+ className: "flex gap-2 items-center",
1267
+ children: [
1268
+ C[e].label,
1269
+ " ",
1270
+ /* @__PURE__ */ t.jsx(y, { name: "caretDown" })
1271
+ ]
1272
+ }
1273
+ ) })
1274
+ }
1275
+ ),
1276
+ children: n ? /* @__PURE__ */ t.jsx(
1277
+ be,
1278
+ {
1279
+ infos: i,
1280
+ value: c,
1281
+ pathKey: `${s}.${e}`
1282
+ }
1283
+ ) : /* @__PURE__ */ t.jsx(
1284
+ v,
1285
+ {
1286
+ isMulti: !0,
1287
+ isCreatable: !0,
1288
+ placeholder: "Enter value",
1289
+ defaultValue: (Array.isArray(c) ? c : []).map((u) => ({
1290
+ value: u,
1291
+ label: u.toString()
1292
+ })),
1293
+ initialValues: [],
1294
+ onSelect: (u) => {
1295
+ R(u) && l(
1296
+ u.map(
1297
+ (d) => typeof d.value == "boolean" ? d.value.toString() : d.value
1298
+ )
1299
+ );
1300
+ }
1301
+ }
1302
+ )
1303
+ }
1304
+ );
1305
+ }
1306
+ function Wa({
1307
+ value: e,
1308
+ onChange: a
1309
+ }) {
1310
+ const [s, n] = x(
1311
+ Array.isArray(e) && typeof e[0] == "number" ? e[0] : null
1312
+ ), [i, o] = x(
1313
+ Array.isArray(e) && typeof e[1] == "number" ? e[1] : null
1314
+ );
1315
+ return /* @__PURE__ */ t.jsxs("div", { className: "flex items-center gap-4", children: [
1316
+ /* @__PURE__ */ t.jsx("div", { className: "grow", children: /* @__PURE__ */ t.jsx(
1317
+ b,
1318
+ {
1319
+ type: "number",
1320
+ placeholder: "Min",
1321
+ value: s ?? "",
1322
+ onChange: (c) => {
1323
+ const l = parseInt(c.currentTarget.value, 10);
1324
+ n(Number.isNaN(l) ? null : l), a([Number.isNaN(l) ? null : l, i]);
1325
+ }
1326
+ }
1327
+ ) }),
1328
+ /* @__PURE__ */ t.jsx("span", { className: "text-gray-300", children: "to" }),
1329
+ /* @__PURE__ */ t.jsx("div", { className: "grow", children: /* @__PURE__ */ t.jsx(
1330
+ b,
1331
+ {
1332
+ type: "number",
1333
+ placeholder: "Max",
1334
+ value: i ?? "",
1335
+ onChange: (c) => {
1336
+ const l = parseInt(c.currentTarget.value, 10);
1337
+ o(Number.isNaN(l) ? null : l), a([s, Number.isNaN(l) ? null : l]);
1338
+ }
1339
+ }
1340
+ ) })
1341
+ ] });
1342
+ }
1343
+ function Ba({
1344
+ value: e,
1345
+ onChange: a
1346
+ }) {
1347
+ const [s, n] = x(
1348
+ Array.isArray(e) && typeof e[0] == "string" ? e[0] : null
1349
+ ), [i, o] = x(
1350
+ Array.isArray(e) && typeof e[1] == "string" ? e[1] : null
1351
+ );
1352
+ return /* @__PURE__ */ t.jsxs("div", { className: "flex items-center gap-4", children: [
1353
+ /* @__PURE__ */ t.jsx("div", { className: "grow", children: /* @__PURE__ */ t.jsx(
1354
+ b,
1355
+ {
1356
+ type: "text",
1357
+ placeholder: "Min",
1358
+ value: s ?? "",
1359
+ onChange: (c) => {
1360
+ const l = c.currentTarget.value;
1361
+ n(l), a([l, i]);
1362
+ }
1363
+ }
1364
+ ) }),
1365
+ /* @__PURE__ */ t.jsx("span", { className: "text-gray-300", children: "to" }),
1366
+ /* @__PURE__ */ t.jsx("div", { className: "grow", children: /* @__PURE__ */ t.jsx(
1367
+ b,
1368
+ {
1369
+ type: "text",
1370
+ placeholder: "Max",
1371
+ value: i ?? "",
1372
+ onChange: (c) => {
1373
+ const l = c.currentTarget.value;
1374
+ o(l), a([s, l]);
1375
+ }
1376
+ }
1377
+ ) })
1378
+ ] });
1379
+ }
1380
+ function Ya({
1381
+ item: e,
1382
+ pathPrefix: a
1383
+ }) {
1384
+ const { setPath: s } = f(), { infos: n } = L(e), i = `${a}.value`, [o, c] = x(0), [l, r] = x(e?.matcher), u = e == null || ie.includes(
1385
+ e.matcher
1386
+ );
1387
+ let d = n?.field?.type;
1388
+ ye(e) && (d == null && (d = pe(e.value)), (typeof e.value == "string" && /^{{.*}}$/.test(e.value) || Array.isArray(e.value) && e.value.some((m) => typeof m == "string" && /^{{.*}}$/.test(m))) && (d = "string"));
1389
+ const h = Xa(d, e?.matcher, n);
1390
+ return _(
1391
+ function() {
1392
+ l !== e?.matcher && (r(e?.matcher), e?.matcher === "array_match" ? s(i, { in_and: [] }) : s(i, null), c((p) => p + 1));
1393
+ },
1394
+ [h]
1395
+ ), u ? null : h === "arrayMatch" || h === "resourceSelector" && e?.matcher === "array_match" ? /* @__PURE__ */ t.jsx("div", { children: /* @__PURE__ */ t.jsx(
1396
+ te,
1397
+ {
1398
+ item: e,
1399
+ fieldType: d,
1400
+ componentType: h,
1401
+ pathKey: i
1402
+ }
1403
+ ) }, o) : /* @__PURE__ */ t.jsx(
1404
+ $,
1405
+ {
1406
+ label: /* @__PURE__ */ t.jsx(N, { variant: "info", size: "small", children: "Value" }),
1407
+ children: /* @__PURE__ */ t.jsx(
1408
+ te,
1409
+ {
1410
+ item: e,
1411
+ fieldType: d,
1412
+ componentType: h,
1413
+ pathKey: i
1414
+ }
1415
+ )
1416
+ },
1417
+ o
1418
+ );
1419
+ }
1420
+ function te({
1421
+ item: e,
1422
+ fieldType: a,
1423
+ componentType: s,
1424
+ pathKey: n
1425
+ }) {
1426
+ const { setPath: i } = f(), { user: o } = oe(), { infos: c } = L(e), l = ye(e) ? e.value : void 0;
1427
+ switch (s) {
1428
+ case "date": {
1429
+ const r = X(typeof l == "string" ? l : "");
1430
+ return /* @__PURE__ */ t.jsx(
1431
+ Na,
1432
+ {
1433
+ value: E(r) ? r : void 0,
1434
+ showTimeSelect: !0,
1435
+ placeholder: "Enter value",
1436
+ onChange: (u) => {
1437
+ i(n, u?.toJSON());
1438
+ },
1439
+ timezone: o?.timezone
1440
+ }
1441
+ );
1442
+ }
1443
+ case "dateRange": {
1444
+ const r = Array.isArray(l) ? l.map((u) => {
1445
+ const d = X(typeof u == "string" ? u : "");
1446
+ return E(d) ? d : null;
1447
+ }) : [null, null];
1448
+ return /* @__PURE__ */ t.jsx(
1449
+ Ta,
1450
+ {
1451
+ value: r,
1452
+ showTimeSelect: !0,
1453
+ onChange: (u) => {
1454
+ i(
1455
+ n,
1456
+ u.map((d) => d?.toJSON() ?? null)
1457
+ );
1458
+ }
1459
+ }
1460
+ );
1461
+ }
1462
+ case "numberRange":
1463
+ return /* @__PURE__ */ t.jsx(
1464
+ Wa,
1465
+ {
1466
+ value: l,
1467
+ onChange: (r) => {
1468
+ i(n, r);
1469
+ }
1470
+ }
1471
+ );
1472
+ case "textRange":
1473
+ return /* @__PURE__ */ t.jsx(
1474
+ Ba,
1475
+ {
1476
+ value: l,
1477
+ onChange: (r) => {
1478
+ i(n, r);
1479
+ }
1480
+ }
1481
+ );
1482
+ case "arrayMatch":
1483
+ return /* @__PURE__ */ t.jsx(ee, { infos: c, value: l, pathPrefix: n });
1484
+ case "tag":
1485
+ return /* @__PURE__ */ t.jsx(
1486
+ v,
1487
+ {
1488
+ isMulti: !0,
1489
+ isClearable: !1,
1490
+ isCreatable: !0,
1491
+ defaultValue: Array.isArray(l) ? l.map((r) => ({
1492
+ label: r.toString(),
1493
+ value: r
1494
+ })) : [],
1495
+ initialValues: [],
1496
+ onSelect: (r) => {
1497
+ R(r) && i(
1498
+ n,
1499
+ r.map((u) => {
1500
+ if (a === "integer") {
1501
+ const d = parseInt(u.value.toString(), 10);
1502
+ return Number.isNaN(d) ? null : d;
1503
+ }
1504
+ return u.value;
1505
+ }).filter((u) => u != null)
1506
+ );
1507
+ }
1508
+ }
1509
+ );
1510
+ case "resourceSelector":
1511
+ return e?.matcher === "array_match" ? /* @__PURE__ */ t.jsx(
1512
+ ee,
1513
+ {
1514
+ infos: c,
1515
+ value: l,
1516
+ pathPrefix: n,
1517
+ hasResourceSelector: !0
1518
+ }
1519
+ ) : /* @__PURE__ */ t.jsx(be, { infos: c, value: l, pathKey: n });
1520
+ case "number":
1521
+ return /* @__PURE__ */ t.jsx(
1522
+ b,
1523
+ {
1524
+ name: n,
1525
+ type: "number",
1526
+ defaultValue: typeof l == "number" ? l : "",
1527
+ placeholder: "Enter value",
1528
+ onChange: (r) => {
1529
+ i(n, parseInt(r.currentTarget.value, 10));
1530
+ }
1531
+ }
1532
+ );
1533
+ case "boolean":
1534
+ return /* @__PURE__ */ t.jsx(
1535
+ v,
1536
+ {
1537
+ name: n,
1538
+ defaultValue: typeof l == "boolean" ? {
1539
+ label: l ? "Yes" : "No",
1540
+ value: l
1541
+ } : void 0,
1542
+ initialValues: [
1543
+ { label: "Yes", value: !0 },
1544
+ { label: "No", value: !1 }
1545
+ ],
1546
+ onSelect: (r) => {
1547
+ w(r) && i(n, r.value);
1548
+ }
1549
+ }
1550
+ );
1551
+ case "text":
1552
+ case null:
1553
+ return /* @__PURE__ */ t.jsx(
1554
+ b,
1555
+ {
1556
+ name: n,
1557
+ type: "text",
1558
+ defaultValue: typeof l == "string" ? l : JSON.stringify(l),
1559
+ placeholder: "Enter value",
1560
+ onChange: (r) => {
1561
+ i(n, r.currentTarget.value);
1562
+ }
1563
+ }
1564
+ );
1565
+ default:
1566
+ return ne();
1567
+ }
1568
+ }
1569
+ function ye(e) {
1570
+ return e != null && "value" in e;
1571
+ }
1572
+ function Xa(e, a, s) {
1573
+ let n = null;
1574
+ switch (e) {
1575
+ case "datetime": {
1576
+ n = "date";
1577
+ break;
1578
+ }
1579
+ case "boolean": {
1580
+ n = "boolean";
1581
+ break;
1582
+ }
1583
+ case "string": {
1584
+ n = "text";
1585
+ break;
1586
+ }
1587
+ case "integer":
1588
+ case "float": {
1589
+ n = "number";
1590
+ break;
1591
+ }
1592
+ case "array":
1593
+ case "json":
1594
+ case "object":
1595
+ break;
1596
+ default: {
1597
+ n = "text";
1598
+ break;
1599
+ }
1600
+ }
1601
+ switch (a) {
1602
+ case "eq":
1603
+ case "not_eq":
1604
+ case "lt":
1605
+ case "lteq":
1606
+ case "gt":
1607
+ case "gteq":
1608
+ case "multiple":
1609
+ case "start_with":
1610
+ case "not_start_with":
1611
+ case "end_with":
1612
+ case "not_end_with":
1613
+ break;
1614
+ case "matches":
1615
+ case "does_not_match":
1616
+ break;
1617
+ case "gt_lt":
1618
+ case "gteq_lt":
1619
+ case "gt_lteq":
1620
+ case "gteq_lteq": {
1621
+ n === "number" && (n = "numberRange"), n === "text" && (n = "textRange"), n === "date" && (n = "dateRange");
1622
+ break;
1623
+ }
1624
+ case "is_in":
1625
+ case "is_not_in": {
1626
+ n = "tag";
1627
+ break;
1628
+ }
1629
+ case "array_match": {
1630
+ n = "arrayMatch";
1631
+ break;
1632
+ }
1633
+ }
1634
+ return s?.resourceSelectorAvailable && (n = "resourceSelector"), n;
1635
+ }
1636
+ function Ha({
1637
+ item: e,
1638
+ nestingLevel: a,
1639
+ pathPrefix: s,
1640
+ onDelete: n
1641
+ }) {
1642
+ const { setPath: i } = f(), o = [];
1643
+ return a < 2 && (o[0] ??= [], o[0].push(
1644
+ /* @__PURE__ */ t.jsx(
1645
+ T,
1646
+ {
1647
+ label: "Nest conditions",
1648
+ onClick: () => {
1649
+ i(
1650
+ `${s}.nested.conditions.${(e?.nested?.conditions ?? []).length}`,
1651
+ void 0
1652
+ );
1653
+ }
1654
+ }
1655
+ )
1656
+ )), n != null && (o[1] ??= [], o[1].push(
1657
+ /* @__PURE__ */ t.jsx(
1658
+ T,
1659
+ {
1660
+ label: "Delete",
1661
+ onClick: () => {
1662
+ i(`${s}`, null), n();
1663
+ }
1664
+ }
1665
+ )
1666
+ )), /* @__PURE__ */ t.jsx("div", { children: /* @__PURE__ */ t.jsxs(
1667
+ ge,
1668
+ {
1669
+ dropdownItems: o.map((c, l, r) => (
1670
+ // biome-ignore lint/suspicious/noArrayIndexKey: Using index as key is acceptable here since items are static
1671
+ /* @__PURE__ */ t.jsxs(Y.Fragment, { children: [
1672
+ c.map((u, d) => (
1673
+ // biome-ignore lint/suspicious/noArrayIndexKey: Using index as key is acceptable here since items are static
1674
+ /* @__PURE__ */ t.jsx(Y.Fragment, { children: u }, d)
1675
+ )),
1676
+ l < r.length - 1 && /* @__PURE__ */ t.jsx(P, {})
1677
+ ] }, l)
1678
+ )),
1679
+ options: /* @__PURE__ */ t.jsxs(t.Fragment, { children: [
1680
+ /* @__PURE__ */ t.jsx(Ya, { item: e, pathPrefix: s }),
1681
+ /* @__PURE__ */ t.jsx(Qa, { item: e, pathPrefix: s })
1682
+ ] }),
1683
+ children: [
1684
+ /* @__PURE__ */ t.jsx("div", { className: "flex-1", children: /* @__PURE__ */ t.jsx(Fa, { value: e?.field, name: `${s}.field` }) }),
1685
+ /* @__PURE__ */ t.jsx("div", { children: /* @__PURE__ */ t.jsx(Ua, { item: e, pathPrefix: s }) })
1686
+ ]
1687
+ }
1688
+ ) });
1689
+ }
1690
+ const Qa = ({ item: e, pathPrefix: a }) => {
1691
+ const { setPath: s } = f(), n = xe(), [i, o] = x(e?.group);
1692
+ return _(() => {
1693
+ s(`${a}.group`, i);
1694
+ }, [i]), /* @__PURE__ */ t.jsx(
1695
+ $,
1696
+ {
1697
+ label: /* @__PURE__ */ t.jsx(N, { variant: "info", size: "small", children: "Groups" }),
1698
+ children: /* @__PURE__ */ t.jsx(
1699
+ v,
1700
+ {
1701
+ name: `${a}.group`,
1702
+ isCreatable: !0,
1703
+ isClearable: !0,
1704
+ initialValues: n.map((c) => ({
1705
+ value: c,
1706
+ label: c
1707
+ })),
1708
+ value: i != null ? {
1709
+ value: i,
1710
+ label: i
1711
+ } : void 0,
1712
+ onSelect: (c) => {
1713
+ (c == null || w(c)) && o(c?.value.toString());
1714
+ },
1715
+ placeholder: "Select or create group…"
1716
+ }
1717
+ )
1718
+ }
1719
+ );
1720
+ };
1721
+ function ve({
1722
+ item: e,
1723
+ children: a,
1724
+ nestingLevel: s = 0,
1725
+ pathPrefix: n
1726
+ }) {
1727
+ const {
1728
+ state: { selectedRuleIndex: i }
1729
+ } = f(), o = e?.conditions_logic?.toLowerCase() ?? "and", { setPath: c } = f(), [l, r] = x(0), u = s > 0;
1730
+ return /* @__PURE__ */ t.jsxs(
1731
+ "div",
1732
+ {
1733
+ className: M("query-group", {
1734
+ "p-4 border border-gray-200 rounded-md": u
1735
+ }),
1736
+ children: [
1737
+ a,
1738
+ e != null && (e.conditions ?? []).length > 0 && /* @__PURE__ */ t.jsxs(t.Fragment, { children: [
1739
+ u && /* @__PURE__ */ t.jsxs(
1740
+ "select",
1741
+ {
1742
+ onChange: (d) => {
1743
+ c(
1744
+ `${n}.conditions_logic`,
1745
+ d.currentTarget.value
1746
+ );
1747
+ },
1748
+ defaultValue: o,
1749
+ 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",
1750
+ children: [
1751
+ /* @__PURE__ */ t.jsx("option", { value: "and", children: "Nested in AND" }),
1752
+ /* @__PURE__ */ t.jsx("option", { value: "or", children: "Nested in OR" })
1753
+ ]
1754
+ }
1755
+ ),
1756
+ /* @__PURE__ */ t.jsx(
1757
+ "div",
1758
+ {
1759
+ className: M({
1760
+ "border-l border-gray-200 ml-3 pt-3": u
1761
+ }),
1762
+ children: e?.conditions?.map((d, h, j) => {
1763
+ const m = h === j.length - 1;
1764
+ return /* @__PURE__ */ t.jsxs(
1765
+ "div",
1766
+ {
1767
+ className: "flex items-center mb-4 last:mb-0 relative",
1768
+ children: [
1769
+ u && /* @__PURE__ */ t.jsx(Ka, { rounded: m }),
1770
+ /* @__PURE__ */ t.jsx(
1771
+ "div",
1772
+ {
1773
+ className: M("w-full", {
1774
+ "ml-4": u
1775
+ }),
1776
+ children: /* @__PURE__ */ t.jsx(
1777
+ ve,
1778
+ {
1779
+ item: d?.nested ?? void 0,
1780
+ nestingLevel: d?.nested != null ? s + 1 : 0,
1781
+ pathPrefix: `${n}.conditions.${h}.nested`,
1782
+ children: /* @__PURE__ */ t.jsx(
1783
+ "div",
1784
+ {
1785
+ className: M({
1786
+ "mb-4": d?.nested != null
1787
+ }),
1788
+ children: /* @__PURE__ */ t.jsx(
1789
+ Ha,
1790
+ {
1791
+ item: d,
1792
+ nestingLevel: s,
1793
+ pathPrefix: `${n}.conditions.${h}`,
1794
+ onDelete: j.length > 1 || s > 0 ? () => {
1795
+ r((p) => p + 1);
1796
+ } : void 0
1797
+ }
1798
+ )
1799
+ }
1800
+ )
1801
+ }
1802
+ )
1803
+ }
1804
+ )
1805
+ ]
1806
+ },
1807
+ `${i}-${h}-${l}`
1808
+ );
1809
+ })
1810
+ }
1811
+ )
1812
+ ] })
1813
+ ]
1814
+ }
1815
+ );
1816
+ }
1817
+ function Ka({
1818
+ rounded: e = !1
1819
+ }) {
1820
+ return e ? /* @__PURE__ */ t.jsxs(t.Fragment, { children: [
1821
+ /* @__PURE__ */ t.jsx("div", { className: "absolute -left-px top-1/2 w-px h-1/2 bg-white" }),
1822
+ /* @__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" })
1823
+ ] }) : /* @__PURE__ */ t.jsx("div", { className: "absolute left-0 top-1/2 -translate-y-1/2 w-3.5 h-px bg-gray-200" });
1824
+ }
1825
+ function es() {
1826
+ const {
1827
+ setPath: e,
1828
+ state: { value: a, selectedRuleIndex: s }
1829
+ } = f(), [n, i] = x(
1830
+ a.rules?.[s]?.name ?? ""
1831
+ );
1832
+ return _(() => {
1833
+ i(a.rules?.[s]?.name ?? "");
1834
+ }, [s]), // <Input
1835
+ // value={value.rules?.[selectedRuleIndex]?.name}
1836
+ // onChange={(event) => {
1837
+ // const target = event.currentTarget
1838
+ // const value = target.value.replace(/[\n\s]+/g, " ").trim()
1839
+ // setPath(`rules.${selectedRuleIndex}.name`, value)
1840
+ // }}
1841
+ // className="bg-transparent border-0 shadow-none field-sizing-content"
1842
+ // />
1843
+ // biome-ignore lint/a11y/noStaticElementInteractions: This <div> is used with contentEditable
1844
+ /* @__PURE__ */ t.jsx(
1845
+ "div",
1846
+ {
1847
+ contentEditable: "plaintext-only",
1848
+ suppressContentEditableWarning: !0,
1849
+ onInput: (o) => {
1850
+ const l = o.currentTarget.innerText.replace(/[\n\s]+/g, " ").trim();
1851
+ e(`rules.${s}.name`, l);
1852
+ },
1853
+ onKeyDown: (o) => {
1854
+ o.key === "Enter" && (o.preventDefault(), o.currentTarget.blur());
1855
+ },
1856
+ onBlur: (o) => {
1857
+ const c = o.currentTarget;
1858
+ c.innerText = c.innerText.replace(/[\n\s]+/g, " ").trim();
1859
+ },
1860
+ children: n
1861
+ },
1862
+ s
1863
+ );
1864
+ }
1865
+ const ae = {
1866
+ rules: []
1867
+ }, A = (e) => {
1868
+ try {
1869
+ return JSON.parse(e ?? JSON.stringify(ae));
1870
+ } catch {
1871
+ return ae;
1872
+ }
1873
+ }, ts = (e) => {
1874
+ try {
1875
+ return JSON.parse(e ?? "{}"), !0;
1876
+ } catch {
1877
+ return !1;
1878
+ }
1879
+ };
1880
+ function us(e) {
1881
+ const {
1882
+ settings: { domain: a }
1883
+ } = oe(), [s, n] = x([]), [i, o] = x(
1884
+ A(e.value ?? e.defaultValue)
1885
+ );
1886
+ return _(
1887
+ function() {
1888
+ i.rules?.length === 0 && o(A(e.value));
1889
+ },
1890
+ [e.value]
1891
+ ), _(
1892
+ function() {
1893
+ wa(e.schemaType, a).then((l) => {
1894
+ const u = g.object({
1895
+ properties: g.object({
1896
+ rules: g.object({
1897
+ items: g.object({
1898
+ properties: g.object({
1899
+ actions: g.object({
1900
+ items: g.object({
1901
+ anyOf: g.array(
1902
+ g.object({
1903
+ properties: g.object({
1904
+ type: g.object({
1905
+ enum: g.string().array()
1906
+ })
1907
+ })
1908
+ })
1909
+ )
1910
+ })
1911
+ })
1912
+ })
1913
+ })
1914
+ })
1915
+ })
1916
+ }).parse(l).properties.rules.items.properties.actions.items.anyOf.flatMap(
1917
+ (d) => d.properties.type.enum
1918
+ );
1919
+ n([...new Set(u)]);
1920
+ });
1921
+ },
1922
+ [a]
1923
+ ), /* @__PURE__ */ t.jsx(
1924
+ Ia,
1925
+ {
1926
+ initialValue: {
1927
+ value: { rules: i.rules },
1928
+ availableActionTypes: s,
1929
+ schemaType: e.schemaType
1930
+ },
1931
+ children: /* @__PURE__ */ t.jsx(as, { ...e })
1932
+ }
1933
+ );
1934
+ }
1935
+ function as(e) {
1936
+ const {
1937
+ state: { value: a, selectedRuleIndex: s },
1938
+ setSelectedRuleIndex: n,
1939
+ setValue: i,
1940
+ setPath: o
1941
+ } = f(), [c, l] = x(
1942
+ e.defaultCodeEditorVisible ?? !1
1943
+ ), r = a.rules?.[s], u = ue(null), [d, h] = x(0);
1944
+ _(
1945
+ function() {
1946
+ q(A(u.current?.getValue()), a) || u.current?.setValue(JSON.stringify(a, null, 2)), e.onChange?.(a);
1947
+ },
1948
+ [a]
1949
+ );
1950
+ const j = k(
1951
+ (m) => {
1952
+ const p = A(m);
1953
+ u.current?.hasTextFocus() && ts(m) && !q(p, a) && (i(p), h((I) => I + 1));
1954
+ },
1955
+ [a]
1956
+ );
1957
+ return /* @__PURE__ */ t.jsx(
1958
+ Ma,
1959
+ {
1960
+ hint: e.hint,
1961
+ feedback: e.feedback,
1962
+ className: "h-full [&>div:first-of-type]:h-full",
1963
+ children: /* @__PURE__ */ t.jsxs("section", { className: "flex h-full", children: [
1964
+ /* @__PURE__ */ t.jsxs(
1965
+ "div",
1966
+ {
1967
+ className: `shrink-0 basis-3/5 overflow-x-auto relative flex flex-col ${c ? "" : "grow"}`,
1968
+ children: [
1969
+ /* @__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: [
1970
+ /* @__PURE__ */ t.jsxs("div", { className: "flex items-center flex-wrap basis-full", children: [
1971
+ a.rules?.map((m, p, I) => {
1972
+ const je = `#${(p + 1).toString().padStart(2, "0")}`;
1973
+ return /* @__PURE__ */ t.jsxs(
1974
+ "div",
1975
+ {
1976
+ className: "flex items-center py-3 pl-4 pr-2 border-r basis-[88px] justify-center",
1977
+ children: [
1978
+ /* @__PURE__ */ t.jsx(
1979
+ "button",
1980
+ {
1981
+ type: "button",
1982
+ className: M("font-bold mr-2", {
1983
+ "text-black": s === p
1984
+ }),
1985
+ onClick: () => {
1986
+ n(p);
1987
+ },
1988
+ children: je
1989
+ }
1990
+ ),
1991
+ /* @__PURE__ */ t.jsx(
1992
+ V,
1993
+ {
1994
+ menuPosition: p === 0 ? "bottom-left" : "bottom-right",
1995
+ dropdownLabel: /* @__PURE__ */ t.jsx(S, { variant: "circle", children: /* @__PURE__ */ t.jsx(y, { name: "dotsThreeVertical", size: 16 }) }),
1996
+ dropdownItems: /* @__PURE__ */ t.jsxs(t.Fragment, { children: [
1997
+ /* @__PURE__ */ t.jsx(
1998
+ T,
1999
+ {
2000
+ onClick: () => {
2001
+ const z = a.rules?.length ?? 0;
2002
+ o(`rules.${z}`, {
2003
+ ...m,
2004
+ id: void 0,
2005
+ name: `${m.name} (copy)`
2006
+ }), n(z);
2007
+ },
2008
+ label: "Duplicate"
2009
+ }
2010
+ ),
2011
+ /* @__PURE__ */ t.jsx(P, {}),
2012
+ /* @__PURE__ */ t.jsx(
2013
+ T,
2014
+ {
2015
+ disabled: I.length === 1,
2016
+ onClick: () => {
2017
+ o(`rules.${p}`, null), s >= p && n(s - 1);
2018
+ },
2019
+ label: "Delete"
2020
+ }
2021
+ )
2022
+ ] })
2023
+ }
2024
+ )
2025
+ ]
2026
+ },
2027
+ `${p}-${m.id}`
2028
+ );
2029
+ }),
2030
+ /* @__PURE__ */ t.jsx("div", { className: "min-h-[49px] flex items-center", children: /* @__PURE__ */ t.jsx(
2031
+ S,
2032
+ {
2033
+ variant: "circle",
2034
+ className: "mx-4",
2035
+ onClick: () => {
2036
+ o(`rules.${a.rules?.length ?? 0}`, {
2037
+ name: "Rule name",
2038
+ actions: [null],
2039
+ conditions: [null]
2040
+ }), n(a.rules?.length ?? 0);
2041
+ },
2042
+ children: /* @__PURE__ */ t.jsx(y, { name: "plus", size: 16, className: "shrink-0" })
2043
+ }
2044
+ ) })
2045
+ ] }),
2046
+ /* @__PURE__ */ t.jsx("div", { className: "grow flex justify-end", children: /* @__PURE__ */ t.jsx(
2047
+ S,
2048
+ {
2049
+ variant: "circle",
2050
+ onClick: () => {
2051
+ l(!c);
2052
+ },
2053
+ children: /* @__PURE__ */ t.jsx(y, { name: "sidebarSimple", size: 16 })
2054
+ }
2055
+ ) })
2056
+ ] }),
2057
+ /* @__PURE__ */ t.jsx(ns, { children: r && /* @__PURE__ */ t.jsxs(t.Fragment, { children: [
2058
+ /* @__PURE__ */ t.jsxs("div", { className: "mb-8 flex items-center gap-2", children: [
2059
+ /* @__PURE__ */ t.jsx(es, {}),
2060
+ /* @__PURE__ */ t.jsx(y, { name: "pencilSimple", size: 16, className: "shrink-0" })
2061
+ ] }),
2062
+ /* @__PURE__ */ t.jsxs(
2063
+ se,
2064
+ {
2065
+ title: /* @__PURE__ */ t.jsxs("div", { children: [
2066
+ "If",
2067
+ " ",
2068
+ /* @__PURE__ */ t.jsxs(
2069
+ "select",
2070
+ {
2071
+ onChange: (m) => {
2072
+ o(
2073
+ `rules.${s}.conditions_logic`,
2074
+ m.currentTarget.value
2075
+ );
2076
+ },
2077
+ value: r?.conditions_logic ?? "all",
2078
+ className: "font-bold py-1 pl-2 pr-6 bg-position-[right_center] focus:ring-0 focus:outline-hidden appearance-none border-0 rounded-md leading-4 ml-1 mr-1.5",
2079
+ children: [
2080
+ /* @__PURE__ */ t.jsx("option", { value: "and", children: "all" }),
2081
+ /* @__PURE__ */ t.jsx("option", { value: "or", children: "any" })
2082
+ ]
2083
+ }
2084
+ ),
2085
+ "conditions occur"
2086
+ ] }),
2087
+ icon: "treeView",
2088
+ children: [
2089
+ /* @__PURE__ */ t.jsx(
2090
+ ve,
2091
+ {
2092
+ item: r,
2093
+ pathPrefix: `rules.${s}`
2094
+ }
2095
+ ),
2096
+ /* @__PURE__ */ t.jsx("div", { className: "mt-6", children: /* @__PURE__ */ t.jsxs(
2097
+ S,
2098
+ {
2099
+ size: "small",
2100
+ variant: "secondary",
2101
+ alignItems: "center",
2102
+ onClick: () => {
2103
+ o(
2104
+ `rules.${s}.conditions.${r?.conditions?.length ?? 0}`,
2105
+ void 0
2106
+ );
2107
+ },
2108
+ children: [
2109
+ /* @__PURE__ */ t.jsx(y, { name: "plusCircle" }),
2110
+ " Add condition"
2111
+ ]
2112
+ }
2113
+ ) })
2114
+ ]
2115
+ }
2116
+ ),
2117
+ /* @__PURE__ */ t.jsx(ss, { children: "do" }),
2118
+ /* @__PURE__ */ t.jsx(se, { title: "Actions", icon: "lightning", children: /* @__PURE__ */ t.jsx(za, { actions: r?.actions }) })
2119
+ ] }) })
2120
+ ]
2121
+ },
2122
+ d
2123
+ ),
2124
+ c && /* @__PURE__ */ t.jsx("div", { className: "shrink-0 basis-2/5", children: /* @__PURE__ */ t.jsx(
2125
+ Ca,
2126
+ {
2127
+ ref: u,
2128
+ name: e.id ?? e.name,
2129
+ height: "100%",
2130
+ language: "json",
2131
+ jsonSchema: e.schemaType,
2132
+ defaultValue: JSON.stringify(a, null, 2),
2133
+ noRounding: !0,
2134
+ onChange: j
2135
+ }
2136
+ ) })
2137
+ ] })
2138
+ }
2139
+ );
2140
+ }
2141
+ function ss({ children: e }) {
2142
+ return /* @__PURE__ */ t.jsxs("div", { className: "text-gray-500 flex items-center justify-center flex-col", children: [
2143
+ /* @__PURE__ */ t.jsx("div", { className: "h-6 w-[2px] bg-gray-200" }),
2144
+ /* @__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 }),
2145
+ /* @__PURE__ */ t.jsx("div", { className: "h-6 w-[2px] bg-gray-200" })
2146
+ ] });
2147
+ }
2148
+ function se({
2149
+ children: e,
2150
+ title: a,
2151
+ icon: s
2152
+ }) {
2153
+ return /* @__PURE__ */ t.jsxs("div", { className: "rounded-md bg-white shadow-xs", children: [
2154
+ /* @__PURE__ */ t.jsxs("div", { className: "flex items-center space-x-4 py-4 border-b border-gray-100", children: [
2155
+ /* @__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(y, { name: s }) }),
2156
+ /* @__PURE__ */ t.jsx("h2", { className: "font-semibold", children: a })
2157
+ ] }),
2158
+ /* @__PURE__ */ t.jsx("div", { className: "p-6", children: e })
2159
+ ] });
2160
+ }
2161
+ function ns({
2162
+ children: e
2163
+ }) {
2164
+ 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 }) });
2165
+ }
2166
+ export {
2167
+ us as RuleEngine
2168
+ };