@archbase/advanced 3.0.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.
package/dist/index.js ADDED
@@ -0,0 +1,4051 @@
1
+ import { jsx as n, jsxs as p } from "react/jsx-runtime";
2
+ import y, { Component as v, useState as $, Fragment as Ie, useRef as Be, useEffect as ge } from "react";
3
+ import { ArchbaseError as te, getI18nextInstance as m, ltrim as ie, detectDataSourceVersion as Q, useArchbaseTheme as $e, processErrorMessage as he, processDetailErrorMessage as ce, useArchbaseTranslation as it, builder as C, emit as rt } from "@archbase/core";
4
+ import { Modal as st, Group as q, Button as w, Checkbox as W, Switch as qe, MultiSelect as nt, Space as R, Text as x, Grid as O, Card as re, Tooltip as f, ActionIcon as g, ScrollArea as Fe, Accordion as X, Menu as B, Radio as pe, Badge as at, Paper as ke, Box as Me, useMantineColorScheme as We, TextInput as ze, Popover as E, Input as lt, Flex as ot } from "@mantine/core";
5
+ import { DatePickerInput as M, TimeInput as Ge } from "@mantine/dates";
6
+ import { IconSearch as le, IconFilterSearch as Qe, IconChevronUp as dt, IconChevronDown as ht, IconArrowDown as ve, IconArrowUp as Se, IconPlus as ct, IconTrash as Ue, IconDeviceFloppy as ue, IconRefresh as ye, IconDoorExit as pt, IconCalendarEvent as ut, IconCalendarMonth as mt, IconCalendarWeek as ft, IconCalendar as je, IconFilterOff as gt, IconSubtask as Ft, IconFilter as bt, IconDownload as Ct, IconPrinter as vt, IconSortAscendingLetters as St, IconSortDescendingLetters as yt, IconFilterX as wt } from "@tabler/icons-react";
7
+ import { uniqueId as U, cloneDeep as me } from "lodash";
8
+ import xt from "lodash/debounce";
9
+ import oe from "react-addons-shallow-compare";
10
+ import { ArchbaseEdit as It, ArchbaseDialog as N, ArchbaseDateTimePickerRange as Ye, ArchbaseDateTimePickerEdit as He, ArchbaseSelect as be, ArchbaseSelectItem as Ce, ArchbaseList as de, ArchbaseSwitch as kt } from "@archbase/components";
11
+ import { useDebouncedValue as Je } from "@mantine/hooks";
12
+ import { endOfMonth as Tt, formatISO as Te } from "date-fns";
13
+ import Ot from "react-date-object";
14
+ import { v4 as Rt } from "uuid";
15
+ import { ArchbaseForm as Ke } from "@archbase/layout";
16
+ import { AccordionItem as Oe, AccordionItemHeading as Re, AccordionItemButton as Ee, AccordionItemPanel as _e, AccordionItemState as Et, Accordion as _t } from "react-accessible-accordion";
17
+ import { ArchbaseDataSource as j } from "@archbase/data";
18
+ import { Calendar as Dt } from "react-multi-date-picker";
19
+ const S = -2, Z = -1, ee = "normal", T = "quick", se = "advanced", Fi = "null", bi = "notNull", Ci = "contains", vi = "startsWith", Si = "endsWith", yi = "=", wi = "!=", xi = ">", Ii = "<", ki = ">=", Ti = "<=", Oi = "between", Ri = "inList", Ei = "notInList";
20
+ class ne {
21
+ _id;
22
+ _companyId;
23
+ _filter;
24
+ _name;
25
+ _viewName;
26
+ _componentName;
27
+ _userName;
28
+ _shared;
29
+ _code;
30
+ _isNewFilter;
31
+ constructor() {
32
+ }
33
+ // Getters
34
+ get id() {
35
+ return this._id;
36
+ }
37
+ get companyId() {
38
+ return this._companyId;
39
+ }
40
+ get filter() {
41
+ return this._filter;
42
+ }
43
+ get name() {
44
+ return this._name;
45
+ }
46
+ get viewName() {
47
+ return this._viewName;
48
+ }
49
+ get componentName() {
50
+ return this._componentName;
51
+ }
52
+ get userName() {
53
+ return this._userName;
54
+ }
55
+ get isShared() {
56
+ return this._shared;
57
+ }
58
+ get code() {
59
+ return this._code;
60
+ }
61
+ get isNewFilter() {
62
+ return this._isNewFilter;
63
+ }
64
+ setId(e) {
65
+ this._id = e;
66
+ }
67
+ setCompanyId(e) {
68
+ this._companyId = e;
69
+ }
70
+ setFilter(e) {
71
+ this._filter = e;
72
+ }
73
+ setName(e) {
74
+ this._name = e;
75
+ }
76
+ setViewName(e) {
77
+ this._viewName = e;
78
+ }
79
+ setComponentName(e) {
80
+ this._componentName = e;
81
+ }
82
+ setUserName(e) {
83
+ this._userName = e;
84
+ }
85
+ setShared(e) {
86
+ this._shared = e;
87
+ }
88
+ setCode(e) {
89
+ this._code = e;
90
+ }
91
+ setIsNewFilter(e) {
92
+ this._isNewFilter = e;
93
+ }
94
+ static createInstance() {
95
+ return new ne();
96
+ }
97
+ static createInstanceWithValues(e) {
98
+ const t = new ne();
99
+ return e.id !== void 0 && t.setId(e.id), e.companyId !== void 0 && t.setCompanyId(e.companyId), e.filter && t.setFilter(e.filter), typeof e.name == "string" && t.setName(e.name), typeof e.viewName == "string" && t.setViewName(e.viewName), typeof e.componentName == "string" && t.setComponentName(e.componentName), typeof e.userName == "string" && t.setUserName(e.userName), typeof e.shared == "boolean" && t.setShared(e.shared), typeof e.code == "string" && t.setCode(e.code), typeof e.isNewFilter == "boolean" && t.setIsNewFilter(e.isNewFilter), t;
100
+ }
101
+ }
102
+ function Nt({
103
+ sortable: d = !0,
104
+ quickFilter: e = !0,
105
+ quickFilterSort: t = !1,
106
+ ...i
107
+ }) {
108
+ return null;
109
+ }
110
+ class At extends v {
111
+ static get componentName() {
112
+ return "FilterFieldValue";
113
+ }
114
+ render() {
115
+ return null;
116
+ }
117
+ }
118
+ function Pt({ children: d }) {
119
+ return /* @__PURE__ */ n("div", { children: d });
120
+ }
121
+ const Xe = (d) => {
122
+ let e = "", t = !1;
123
+ return d.sort.sortFields.forEach(
124
+ (i) => {
125
+ i.selected && (t && (e += ", "), e += i.label + "(" + (i.asc_desc === "asc" ? "A" : "D") + ")", t = !0);
126
+ }
127
+ ), e;
128
+ }, Ze = (d) => {
129
+ let e = [];
130
+ return y.Children.toArray(d).forEach(function(i) {
131
+ i && i.type && i.type.componentName === "QueryFields" && i.props.children && y.Children.toArray(i.props.children).forEach(function(s, a) {
132
+ let l = [];
133
+ y.Children.toArray(s.props.children).forEach(function(o) {
134
+ l.push(/* @__PURE__ */ n(At, { ...o.props }, "fld" + a));
135
+ }), e.push(
136
+ /* @__PURE__ */ n(Nt, { ...s.props, children: l }, "fld" + a)
137
+ );
138
+ });
139
+ }), /* @__PURE__ */ n(Pt, { children: e });
140
+ }, I = (d) => {
141
+ let e = [], t = Ze(d.children);
142
+ return t && y.Children.toArray(t).forEach((r) => {
143
+ r.type && r.type.componentName === "FilterFields" && r.props.children && y.Children.toArray(r.props.children).forEach((a) => {
144
+ if (a.type && a.type.componentName !== "FilterField")
145
+ throw new te(
146
+ "Somente filhos do tipo FilterField podem ser usados com FilterFields."
147
+ );
148
+ let l = [];
149
+ y.Children.toArray(a.props.children).forEach((o) => {
150
+ if (o.type && o.type.componentName !== "FilterFieldValue")
151
+ throw new te(
152
+ "Somente filhos do tipo FilterFieldValue podem ser usados com FilterFields"
153
+ );
154
+ l.push({ label: o.props.label, value: o.props.value });
155
+ }), e.push({
156
+ name: a.props.name,
157
+ label: a.props.label,
158
+ dataType: a.props.dataType,
159
+ operator: a.props.operator,
160
+ quickFilter: a.props.quickFilter,
161
+ quickFilterSort: a.props.quickFilterSort,
162
+ sortable: a.props.sortable,
163
+ listValues: l,
164
+ searchComponent: a.props.searchComponent,
165
+ searchField: a.props.searchField
166
+ });
167
+ });
168
+ }), e;
169
+ }, _i = (d, e) => {
170
+ for (var t = 0; t < e.length; t++)
171
+ if (e[t].name === d)
172
+ return e[t].nameSql;
173
+ }, Di = (d, e) => {
174
+ for (var t = 0; t < e.length; t++)
175
+ if (e[t].name === d)
176
+ return e[t].listValues;
177
+ }, ae = (d) => {
178
+ let e = [];
179
+ return d && d.forEach((t) => {
180
+ t.quickFilter === !0 && e.push({
181
+ name: t.name,
182
+ label: t.label,
183
+ dataType: "string",
184
+ operator: "",
185
+ quickFilter: !1,
186
+ quickFilterSort: !1,
187
+ sortable: !1,
188
+ listValues: [],
189
+ searchComponent: void 0,
190
+ searchField: void 0
191
+ });
192
+ }), e;
193
+ }, Lt = (d) => {
194
+ let e = [];
195
+ return d && d.forEach((t, i) => {
196
+ t.quickFilterSort === !0 && e.push({
197
+ name: t.name,
198
+ label: t.label,
199
+ selected: !1,
200
+ order: i,
201
+ asc_desc: "asc"
202
+ });
203
+ }), e;
204
+ }, Vt = (d) => {
205
+ let e = "", t = !1;
206
+ return d.forEach(function(i) {
207
+ i.quickFilterSort === !0 && (t && (e += ","), e += i.name, t = !0);
208
+ }), e;
209
+ }, Ni = (d) => {
210
+ let e = "", t = !1;
211
+ return d.forEach((i) => {
212
+ i.selected && t && (e += ","), e += i.name, t = !0;
213
+ }), e;
214
+ }, Bt = (d, e) => {
215
+ let t = [];
216
+ return e && (e.forEach(function(i, r) {
217
+ let s = !1, a = "asc", l = r;
218
+ d && d.forEach(function(h) {
219
+ h.name === i.name && (s = h.selected, a = h.asc_desc, l = h.order);
220
+ }), t.push({
221
+ name: i.name,
222
+ selected: s,
223
+ order: l,
224
+ asc_desc: a || "asc",
225
+ label: i.label
226
+ });
227
+ }), t = t.sort(function(i, r) {
228
+ return i.order - r.order;
229
+ })), t;
230
+ }, A = (d, e) => {
231
+ let t = "", i = !1;
232
+ return d && d.filter && (!d.filter.selectedFields || d.filter.selectedFields.length === 0 ? e.forEach((r) => {
233
+ r.quickFilter === !0 && (i && (t = t + ","), t += r.name), i = !0;
234
+ }) : d.filter.selectedFields.forEach((r) => {
235
+ i && (t += ","), t += r.name, i = !0;
236
+ })), t;
237
+ }, Y = () => ({
238
+ id: 0,
239
+ name: "",
240
+ viewName: "",
241
+ apiVersion: "",
242
+ filter: {
243
+ id: "root",
244
+ selectedFields: [],
245
+ quickFilterText: "",
246
+ rules: [],
247
+ condition: "",
248
+ filterType: "normal",
249
+ quickFilterFieldsText: ""
250
+ },
251
+ sort: {
252
+ quickFilterSort: "",
253
+ sortFields: [],
254
+ activeIndex: -1
255
+ }
256
+ }), $t = [
257
+ {
258
+ name: "null",
259
+ label: "Em branco",
260
+ dataTypes: ["string", "number", "date", "date_time", "time", "boolean"]
261
+ },
262
+ {
263
+ name: "notNull",
264
+ label: "Preenchido",
265
+ dataTypes: ["string", "number", "date", "date_time", "time", "boolean"]
266
+ },
267
+ {
268
+ name: "contains",
269
+ label: "Contém",
270
+ dataTypes: ["string"]
271
+ },
272
+ {
273
+ name: "startsWith",
274
+ label: "Iniciado com",
275
+ dataTypes: ["string"]
276
+ },
277
+ {
278
+ name: "endsWith",
279
+ label: "Terminado com",
280
+ dataTypes: ["string"]
281
+ },
282
+ {
283
+ name: "=",
284
+ label: "Igual",
285
+ dataTypes: ["string", "number", "date", "date_time", "time", "boolean"]
286
+ },
287
+ {
288
+ name: "!=",
289
+ label: "Diferente",
290
+ dataTypes: ["string", "number", "date", "date_time", "time", "boolean"]
291
+ },
292
+ {
293
+ name: "<",
294
+ label: "Menor",
295
+ dataTypes: ["string", "number", "date", "date_time", "time"]
296
+ },
297
+ {
298
+ name: ">",
299
+ label: "Maior",
300
+ dataTypes: ["string", "number", "date", "date_time", "time"]
301
+ },
302
+ {
303
+ name: "<=",
304
+ label: "Menor igual",
305
+ dataTypes: ["string", "number", "date", "date_time", "time"]
306
+ },
307
+ {
308
+ name: ">=",
309
+ label: "Maior igual",
310
+ dataTypes: ["string", "number", "date", "date_time", "time"]
311
+ },
312
+ {
313
+ name: "between",
314
+ label: "Entre",
315
+ dataTypes: ["string", "number", "date", "date_time", "time"]
316
+ },
317
+ {
318
+ name: "inList",
319
+ label: "Na lista",
320
+ dataTypes: ["string", "number", "date", "time"]
321
+ },
322
+ {
323
+ name: "notInList",
324
+ label: "Fora da lista",
325
+ dataTypes: ["string", "number", "date", "time"]
326
+ }
327
+ ], Ai = [
328
+ {
329
+ name: "and",
330
+ label: "E"
331
+ },
332
+ {
333
+ name: "or",
334
+ label: "Ou"
335
+ }
336
+ ], D = (d, e) => {
337
+ let t = I(d), i = {
338
+ id: -1,
339
+ name: "",
340
+ viewName: "",
341
+ apiVersion: "",
342
+ filter: {
343
+ id: "root",
344
+ selectedFields: [],
345
+ quickFilterText: "",
346
+ quickFilterFieldsText: "",
347
+ rules: [],
348
+ condition: "",
349
+ filterType: e
350
+ },
351
+ sort: {
352
+ quickFilterSort: "",
353
+ sortFields: [],
354
+ activeIndex: -1
355
+ }
356
+ };
357
+ return i.filter.selectedFields = ae(t), i.filter.quickFilterFieldsText = A(null, t), i.sort.sortFields = Bt([], t), i.sort.quickFilterSort = Vt(t), i;
358
+ };
359
+ function Pi({ children: d }) {
360
+ return /* @__PURE__ */ n("div", { children: d });
361
+ }
362
+ function Li({
363
+ sortable: d = !0,
364
+ quickFilter: e = !0,
365
+ quickFilterSort: t = !1,
366
+ operator: i = "=",
367
+ mask: r = "",
368
+ ...s
369
+ }) {
370
+ return null;
371
+ }
372
+ class Vi extends v {
373
+ static get componentName() {
374
+ return "QueryFieldValue";
375
+ }
376
+ render() {
377
+ return null;
378
+ }
379
+ }
380
+ const qt = ({
381
+ title: d,
382
+ id: e,
383
+ onClickCancel: t,
384
+ onClickOk: i,
385
+ modalOpen: r,
386
+ placeholder: s,
387
+ variant: a
388
+ }) => {
389
+ const [l, h] = $(), [o, c] = $(!0), u = (b, k) => {
390
+ if (b === "btnOK") {
391
+ if (!l || l === "") {
392
+ N.showWarning("Informe o nome do filtro.");
393
+ return;
394
+ }
395
+ i && i(l, o);
396
+ } else
397
+ b === "btnCancel" && t && t(k);
398
+ };
399
+ return /* @__PURE__ */ p(st, { title: d, id: e, opened: r === e, onClose: () => {
400
+ t && t();
401
+ }, children: [
402
+ /* @__PURE__ */ p(q, { children: [
403
+ /* @__PURE__ */ n(w, { variant: a, onClick: (b) => u("btnOK", b), children: "OK" }),
404
+ " ",
405
+ /* @__PURE__ */ n(w, { variant: a, color: "red", onClick: (b) => u("btnCancel", b), children: "Fechar" })
406
+ ] }),
407
+ /* @__PURE__ */ p(Ke, { children: [
408
+ /* @__PURE__ */ n(
409
+ It,
410
+ {
411
+ placeholder: s,
412
+ style: { width: "100%" },
413
+ onChangeValue: (b) => h(b)
414
+ }
415
+ ),
416
+ /* @__PURE__ */ n(
417
+ W,
418
+ {
419
+ onChange: (b) => c(b.currentTarget.checked),
420
+ label: m().t("archbase:Filtro compartilhado ?")
421
+ }
422
+ )
423
+ ] })
424
+ ] });
425
+ }, De = (() => {
426
+ const d = (i, r) => r++ && [...Array(r - i)].map((s, a) => String.fromCharCode(i + a)), e = {
427
+ num: d(48, 57),
428
+ alphaLower: d(97, 122),
429
+ alphaUpper: d(65, 90),
430
+ special: [...`~!@#$%^&*()_+-=[]{}|;:'",./<>?`]
431
+ };
432
+ function* t(i, r) {
433
+ r.length < 1 && (r = Object.values(e).flat());
434
+ for (let s = 0; s < i; s++)
435
+ yield r[Math.random() * r.length | 0];
436
+ }
437
+ return Object.assign((i, ...r) => [...t(i, r.flat())].join(""), e);
438
+ })();
439
+ class Mt extends v {
440
+ static defaultProps = {
441
+ operators: [
442
+ {
443
+ name: "null",
444
+ label: "Em branco",
445
+ dataTypes: ["string", "number", "date", "date_time", "time", "boolean"]
446
+ },
447
+ {
448
+ name: "notNull",
449
+ label: "Preenchido",
450
+ dataTypes: ["string", "number", "date", "date_time", "time", "boolean"]
451
+ },
452
+ {
453
+ name: "contains",
454
+ label: "Contém",
455
+ dataTypes: ["string"]
456
+ },
457
+ {
458
+ name: "startsWith",
459
+ label: "Iniciado com",
460
+ dataTypes: ["string"]
461
+ },
462
+ {
463
+ name: "endsWith",
464
+ label: "Terminado com",
465
+ dataTypes: ["string"]
466
+ },
467
+ {
468
+ name: "=",
469
+ label: "Igual",
470
+ dataTypes: ["string", "number", "date", "date_time", "time", "boolean"]
471
+ },
472
+ {
473
+ name: "!=",
474
+ label: "Diferente",
475
+ dataTypes: ["string", "number", "date", "date_time", "time", "boolean"]
476
+ },
477
+ {
478
+ name: "<",
479
+ label: "Menor",
480
+ dataTypes: ["string", "number", "date", "date_time", "time"]
481
+ },
482
+ {
483
+ name: ">",
484
+ label: "Maior",
485
+ dataTypes: ["string", "number", "date", "date_time", "time"]
486
+ },
487
+ {
488
+ name: "<=",
489
+ label: "Menor igual",
490
+ dataTypes: ["string", "number", "date", "date_time", "time"]
491
+ },
492
+ {
493
+ name: ">=",
494
+ label: "Maior igual",
495
+ dataTypes: ["string", "number", "date", "date_time", "time"]
496
+ },
497
+ {
498
+ name: "between",
499
+ label: "Entre",
500
+ dataTypes: ["string", "number", "date", "date_time", "time"]
501
+ },
502
+ {
503
+ name: "inList",
504
+ label: "Na lista",
505
+ dataTypes: ["string", "number", "date", "time"]
506
+ },
507
+ {
508
+ name: "notInList",
509
+ label: "Fora da lista",
510
+ dataTypes: ["string", "number", "date", "time"]
511
+ }
512
+ ],
513
+ conditions: [
514
+ {
515
+ name: "and",
516
+ label: "E"
517
+ },
518
+ {
519
+ name: "or",
520
+ label: "Ou"
521
+ }
522
+ ],
523
+ onFilterChanged: null,
524
+ onError: null
525
+ };
526
+ prefixId;
527
+ // declare context: React.ContextType<typeof ArchbaseAppContext>
528
+ constructor(e) {
529
+ super(e), this.prefixId = De(12, De.alphaLower);
530
+ const t = this.createSchema(), i = e.currentFilter ? e.currentFilter : Y(), r = e.currentFilter ? e.activeFilterIndex : 0, s = this.createFilterFields(e, t, i);
531
+ this.state = {
532
+ simpleFields: s,
533
+ currentFilter: i,
534
+ schema: t,
535
+ update: Math.random(),
536
+ activeFilterIndex: r
537
+ };
538
+ }
539
+ shouldComponentUpdate = (e, t) => oe(this, e, t);
540
+ UNSAFE_componentWillReceiveProps = (e) => {
541
+ const t = this.createSchema(), i = e.currentFilter ? e.currentFilter : Y(), r = e.currentFilter ? e.activeFilterIndex : 0, s = this.createFilterFields(e, t, i);
542
+ this.setState({
543
+ ...this.state,
544
+ simpleFields: s,
545
+ currentFilter: i,
546
+ activeFilterIndex: r,
547
+ schema: t,
548
+ update: Math.random()
549
+ });
550
+ };
551
+ createSchema = () => {
552
+ const { operators: e, conditions: t, fields: i } = this.props;
553
+ return {
554
+ fields: i,
555
+ operators: e,
556
+ conditions: t,
557
+ onPropChange: this.notifyQueryChange.bind(this, this.onPropChange),
558
+ getLevel: this.getLevel.bind(this),
559
+ isRuleGroup: this.isRuleGroup.bind(this),
560
+ getOperators: (r) => this.getOperators(r)
561
+ };
562
+ };
563
+ getDataType = (e, t) => {
564
+ for (let i = 0; i < t.length; i++)
565
+ if (t[i].name === e)
566
+ return t[i].dataType;
567
+ };
568
+ getSelectedSort = () => {
569
+ const e = [];
570
+ return this.state.currentFilter.sort.sortFields.forEach(function(t) {
571
+ t.selected && e.push({ name: t.name, asc_desc: t.asc_desc });
572
+ }), e;
573
+ };
574
+ getSortItem = (e) => {
575
+ let t;
576
+ return this.state.currentFilter.sort.sortFields.forEach(function(i) {
577
+ i.name === e && (t = i);
578
+ }), t;
579
+ };
580
+ getSortItemByOrder = (e) => {
581
+ let t;
582
+ return this.state.currentFilter.sort.sortFields.forEach(function(i) {
583
+ i.order === e && (t = i);
584
+ }), t;
585
+ };
586
+ onChangeSortItem = (e, t, i, r) => {
587
+ const s = this.getSortItem(e);
588
+ Object.assign(s, {
589
+ selected: t,
590
+ order: i,
591
+ asc_desc: r,
592
+ label: s.label
593
+ });
594
+ let a = this.state.currentFilter.sort.sortFields;
595
+ a = a.sort(function(h, o) {
596
+ return h.order - o.order;
597
+ });
598
+ const l = this.state.currentFilter;
599
+ l.sort.sortFields = a, this.setState(
600
+ {
601
+ ...this.state,
602
+ update: Math.random(),
603
+ currentFilter: l
604
+ },
605
+ () => {
606
+ this.propagateFilterChanged();
607
+ }
608
+ );
609
+ };
610
+ propagateFilterChanged = () => {
611
+ const { onFilterChanged: e } = this.props;
612
+ e && e(this.state.currentFilter, this.state.activeFilterIndex);
613
+ };
614
+ onSortDown = (e) => {
615
+ let t = this.state.currentFilter.sort.activeIndex;
616
+ if (t >= 0) {
617
+ const i = this.state.currentFilter.sort.sortFields[t];
618
+ if (i.order < this.state.currentFilter.sort.sortFields.length - 1) {
619
+ t = i.order + 1;
620
+ const a = this.getSortItemByOrder(i.order + 1);
621
+ Object.assign(i, {
622
+ order: i.order + 1
623
+ }), Object.assign(a, {
624
+ order: a.order - 1
625
+ });
626
+ }
627
+ let r = this.state.currentFilter.sort.sortFields;
628
+ r = r.sort((a, l) => a.order - l.order);
629
+ const s = this.state.currentFilter;
630
+ s.sort.sortFields = r, s.sort.activeIndex = t, this.setState(
631
+ {
632
+ ...this.state,
633
+ currentFilter: s
634
+ },
635
+ () => {
636
+ this.propagateFilterChanged();
637
+ }
638
+ );
639
+ }
640
+ };
641
+ onSortUp = (e) => {
642
+ const { currentFilter: t } = this.state;
643
+ let i = t.sort.activeIndex;
644
+ if (i >= 0) {
645
+ const r = t.sort.sortFields[i];
646
+ if (r.order > 0) {
647
+ i = r.order - 1;
648
+ const a = this.getSortItemByOrder(r.order - 1);
649
+ Object.assign(r, {
650
+ order: r.order - 1
651
+ }), Object.assign(a, {
652
+ order: a.order + 1
653
+ });
654
+ }
655
+ let s = t.sort.sortFields;
656
+ s = s.sort((a, l) => a.order - l.order), t.sort.sortFields = s, t.sort.activeIndex = i, this.setState(
657
+ {
658
+ ...this.state,
659
+ currentFilter: t
660
+ },
661
+ () => {
662
+ this.propagateFilterChanged();
663
+ }
664
+ );
665
+ }
666
+ };
667
+ isRuleGroup = (e) => !!(e.condition && e.rules);
668
+ getField = (e) => {
669
+ let t;
670
+ return this.props.fields.forEach((i) => {
671
+ i.name === e && (t = i);
672
+ }, this), t;
673
+ };
674
+ getOperators = (e) => {
675
+ const t = this.getField(e), i = [];
676
+ return this.props.operators.forEach((r) => {
677
+ r.dataTypes.indexOf(t.dataType) >= 0 && i.push(r);
678
+ }, this), i;
679
+ };
680
+ onPropChange = (e, t, i) => {
681
+ const r = this.state.currentFilter, s = this.findRule(i, r.filter);
682
+ e === "not" ? (e = "condition", s.condition.indexOf("and") >= 0 ? t = ie(t + " and") : t = ie(t + " or")) : e === "condition" && s.condition.indexOf("not") >= 0 && (t = "not " + t), Object.assign(s, { [e]: t }), this.setState({ ...this.state, currentFilter: r });
683
+ };
684
+ getLevel = (e) => this.getLevel2(e, 0, this.state.currentFilter.filter);
685
+ getLevel2 = (e, t, i) => {
686
+ const { isRuleGroup: r } = this.state.schema;
687
+ var s = -1;
688
+ return i.id === e ? s = t : r(i) && i.rules.forEach((a) => {
689
+ if (s === -1) {
690
+ let l = t;
691
+ r(a) && l++, s = this.getLevel2(e, l, a);
692
+ }
693
+ }), s;
694
+ };
695
+ findRule = (e, t) => {
696
+ if (t.id === e)
697
+ return t;
698
+ for (const i of t.rules)
699
+ if (i.id === e)
700
+ return i;
701
+ };
702
+ notifyQueryChange = (e, ...t) => {
703
+ e && e.call(this, ...t);
704
+ const { onFilterChanged: i } = this.props;
705
+ i && i(this.state.currentFilter, this.state.activeFilterIndex);
706
+ };
707
+ onSelectListItem = (e, t) => {
708
+ const i = this.state.currentFilter;
709
+ i.sort.activeIndex = e, this.setState({ ...this.state, currentFilter: i }), this.props.onFilterChanged && this.props.onFilterChanged(i, this.state.activeFilterIndex);
710
+ };
711
+ onOperatorChanged = (e, t) => {
712
+ this.onElementChanged("operator", t, e.id), this.onElementChanged("value", "", e.id), this.onElementChanged("value2", "", e.id);
713
+ };
714
+ onDisabledChanged = (e, t, i, r) => {
715
+ this.onElementChanged("disabled", !t, i.id), document.getElementById(r);
716
+ };
717
+ onValueChanged = (e, t) => {
718
+ const { field: i, operator: r } = e, {
719
+ schema: { fields: s }
720
+ } = this.state, a = this.getDataType(i, s);
721
+ if (r === "between" && (a === "date" || a === "date_time" || a === "time"))
722
+ t.length > 1 ? (this.onElementChanged("value", t[0].toString(), e.id), this.onElementChanged("value2", t[1].toString(), e.id)) : (this.onElementChanged("value", "", e.id), this.onElementChanged("value2", "", e.id));
723
+ else if ((r === "inList" || r === "notInList") && (a === "date" || a === "date_time" || a === "time"))
724
+ t || (t = ""), this.onElementChanged("value", t, e.id);
725
+ else if (r === "inList" || r === "notInList") {
726
+ t || (t = "");
727
+ const l = t.split(",");
728
+ if (l.length > 0) {
729
+ let h = !1, o = "";
730
+ l.forEach((c) => {
731
+ h && (o += ","), a === "number" || a === "integer" ? o += c : o += "'" + c + "'", h = !0;
732
+ }), this.onElementChanged("value", o, e.id);
733
+ }
734
+ } else
735
+ this.onElementChanged("value", t, e.id);
736
+ };
737
+ onValue2Changed = (e, t) => {
738
+ this.onElementChanged("value2", t, e.id);
739
+ };
740
+ onElementChanged = (e, t, i) => {
741
+ const {
742
+ schema: { onPropChange: r }
743
+ } = this.state;
744
+ r(e, t, i);
745
+ };
746
+ getFieldValues = (e, t) => {
747
+ for (var i = 0; i < t.length; i++)
748
+ if (t[i].name === e)
749
+ return t[i].listValues;
750
+ return [];
751
+ };
752
+ getColor = (e) => this.props.theme.colors[e][this.props.colorScheme === "dark" ? 5 : 7];
753
+ createFilterFields = (e, t, i) => {
754
+ const { operators: r } = t, s = [];
755
+ return e.fields.forEach((l, h) => {
756
+ const o = this.getFieldValues(l.name, e.fields);
757
+ let c = this.findRule(`r-${l.name}`, i.filter);
758
+ c || (c = {
759
+ id: `r-${l.name}`,
760
+ field: l.name,
761
+ fieldSql: l.nameSql,
762
+ dataType: l.dataType,
763
+ expanded: !1,
764
+ value: "",
765
+ value2: "",
766
+ disabled: l.disabled,
767
+ operator: l.operator ? l.operator : r[0].name
768
+ }, i.filter.rules.push(c));
769
+ let u = c.value && c.value !== "" ? c.value : null;
770
+ u = c.value2 && c.value2 !== "" ? `${u} a ${c.value2}` : u, s.push(
771
+ /* @__PURE__ */ p(
772
+ Oe,
773
+ {
774
+ uuid: this.prefixId + "_" + h,
775
+ id: this.prefixId + "_" + h,
776
+ dangerouslySetExpanded: !c.disabled,
777
+ children: [
778
+ /* @__PURE__ */ n(
779
+ Re,
780
+ {
781
+ className: c.disabled === !0 ? "simple-filter-disabled" : "simple-filter-enabled",
782
+ children: /* @__PURE__ */ n(
783
+ Ee,
784
+ {
785
+ className: c.disabled === !0 ? "accordion__button simple-filter-disabled" : "accordion__button simple-filter-enabled",
786
+ children: /* @__PURE__ */ p("div", { style: { display: "flex", alignItems: "center" }, children: [
787
+ /* @__PURE__ */ n(
788
+ W,
789
+ {
790
+ checked: !c.disabled,
791
+ width: "24px",
792
+ style: { margin: 0, cursor: "pointer" },
793
+ onChange: (F) => this.onDisabledChanged(
794
+ F.currentTarget.checked,
795
+ F.currentTarget.checked,
796
+ c,
797
+ this.prefixId + "_" + h
798
+ )
799
+ }
800
+ ),
801
+ /* @__PURE__ */ n(R, { w: "sm" }),
802
+ /* @__PURE__ */ n(x, { c: this.props.colorScheme === "dark" ? "white" : "black", children: m().t(l.label) }),
803
+ /* @__PURE__ */ n(
804
+ Ae,
805
+ {
806
+ field: l.name,
807
+ options: this.getOperators(l.name),
808
+ value: c.operator,
809
+ className: "custom-select-operator",
810
+ style: {
811
+ color: this.props.theme.colors.blue[5],
812
+ backgroundColor: "transparent"
813
+ },
814
+ disabled: !0,
815
+ handleOnChange: (F) => this.onOperatorChanged(c, F),
816
+ level: 0
817
+ }
818
+ ),
819
+ /* @__PURE__ */ n(x, { style: { fontSize: "12px" }, c: "blue", children: u })
820
+ ] })
821
+ }
822
+ )
823
+ }
824
+ ),
825
+ /* @__PURE__ */ n(
826
+ _e,
827
+ {
828
+ className: c.disabled === !0 ? "simple-filter-disabled" : "simple-filter-enabled",
829
+ children: /* @__PURE__ */ p(
830
+ "div",
831
+ {
832
+ style: {
833
+ display: "flex",
834
+ alignItems: "center",
835
+ justifyContent: "space-between"
836
+ },
837
+ children: [
838
+ /* @__PURE__ */ n(
839
+ Ae,
840
+ {
841
+ field: l.name,
842
+ options: this.getOperators(l.name),
843
+ value: c.operator,
844
+ className: "custom-select-operator",
845
+ style: {
846
+ color: this.props.colorScheme === "dark" ? "white" : "black"
847
+ },
848
+ disabled: l.disabled,
849
+ handleOnChange: (F) => this.onOperatorChanged(c, F),
850
+ level: 0
851
+ }
852
+ ),
853
+ /* @__PURE__ */ n(
854
+ Ne,
855
+ {
856
+ field: l.name,
857
+ dataType: l.dataType,
858
+ operator: c.operator,
859
+ value: c.value,
860
+ value2: c.value2,
861
+ listValues: o,
862
+ searchField: l.searchField,
863
+ disabled: c.disabled,
864
+ className: "rule-value",
865
+ handleOnChange: (F) => this.onValueChanged(c, F),
866
+ onSearchButtonClick: e.onSearchButtonClick,
867
+ searchComponent: l.searchComponent,
868
+ level: 0
869
+ },
870
+ "svf1_" + h
871
+ ),
872
+ " ",
873
+ c.operator === "between" && c.dataType !== "date" && c.dataType !== "date_time" && c.dataType !== "time" ? /* @__PURE__ */ n(
874
+ Ne,
875
+ {
876
+ field: l.name,
877
+ dataType: c.dataType,
878
+ operator: c.operator,
879
+ value: c.value2,
880
+ listValues: o,
881
+ searchField: l.searchField,
882
+ disabled: c.disabled,
883
+ className: "rule-value",
884
+ handleOnChange: (F) => this.onValue2Changed(c, F),
885
+ onSearchButtonClick: e.onSearchButtonClick,
886
+ searchComponent: l.searchComponent,
887
+ level: 0
888
+ },
889
+ "svf2_" + h
890
+ ) : ""
891
+ ]
892
+ }
893
+ )
894
+ }
895
+ )
896
+ ]
897
+ },
898
+ "flk" + h
899
+ )
900
+ );
901
+ }), s.sort((l, h) => l.props.disabled && h.props.disabled ? 0 : l.props.disabled ? -1 : 1), this.props.allowSort === !0 && s.push(
902
+ /* @__PURE__ */ p(Oe, { uuid: this.prefixId + "_9999", children: [
903
+ /* @__PURE__ */ n(Re, { children: /* @__PURE__ */ n(Ee, { children: /* @__PURE__ */ p(
904
+ "div",
905
+ {
906
+ style: {
907
+ fontWeight: "bold",
908
+ color: "#3d3d69",
909
+ marginTop: "10px",
910
+ display: "flex",
911
+ padding: "4px"
912
+ },
913
+ children: [
914
+ /* @__PURE__ */ n(Qe, { size: 30, color: this.getColor("green") }),
915
+ /* @__PURE__ */ n(R, { w: "md" }),
916
+ "Ordenação",
917
+ /* @__PURE__ */ n(R, { w: "md" }),
918
+ /* @__PURE__ */ n(
919
+ x,
920
+ {
921
+ truncate: !0,
922
+ c: "blue",
923
+ style: {
924
+ wordBreak: "break-word",
925
+ display: "block",
926
+ wordWrap: "break-word",
927
+ width: "100%",
928
+ whiteSpace: "normal",
929
+ fontSize: "12px"
930
+ },
931
+ children: Xe(i)
932
+ },
933
+ "txto_9999"
934
+ ),
935
+ /* @__PURE__ */ n(Et, { children: ({ expanded: l }) => l ? /* @__PURE__ */ n(dt, {}) : /* @__PURE__ */ n(ht, {}) })
936
+ ]
937
+ }
938
+ ) }) }),
939
+ /* @__PURE__ */ n(_e, { children: /* @__PURE__ */ n(O, { children: /* @__PURE__ */ n(O.Col, { span: 12, style: { padding: 13 }, children: /* @__PURE__ */ n(
940
+ "div",
941
+ {
942
+ style: {
943
+ height: "auto"
944
+ },
945
+ children: /* @__PURE__ */ p(re, { withBorder: !0, shadow: "sm", radius: "md", children: [
946
+ /* @__PURE__ */ n(re.Section, { withBorder: !0, inheritPadding: !0, py: "xs", children: /* @__PURE__ */ p(q, { children: [
947
+ /* @__PURE__ */ n(f, { withinPortal: !0, withArrow: !0, label: "Para baixo", children: /* @__PURE__ */ n(g, { id: "btnFilterSortDown", onClick: this.onSortDown, children: /* @__PURE__ */ n(ve, {}) }) }),
948
+ /* @__PURE__ */ n(f, { withinPortal: !0, withArrow: !0, label: "Para cima", children: /* @__PURE__ */ n(g, { id: "btnFilterSortUp", onClick: this.onSortUp, children: /* @__PURE__ */ n(Se, {}) }) }),
949
+ /* @__PURE__ */ n(x, { children: "Ordenação" })
950
+ ] }) }),
951
+ /* @__PURE__ */ n(
952
+ de,
953
+ {
954
+ height: "100%",
955
+ width: "100%",
956
+ withBorder: !1,
957
+ dataSource: (
958
+ // 🔄 MIGRAÇÃO V1/V2: DataSource com compatibilidade
959
+ (() => {
960
+ const l = new j("dsSortFields", {
961
+ records: i.sort.sortFields,
962
+ grandTotalRecords: i.sort.sortFields.length,
963
+ currentPage: 0,
964
+ totalPages: 0,
965
+ pageSize: 999999
966
+ });
967
+ return Q(l), l;
968
+ })()
969
+ ),
970
+ dataFieldId: "name",
971
+ dataFieldText: "name",
972
+ activeIndex: i.sort.activeIndex,
973
+ component: {
974
+ type: we,
975
+ props: {
976
+ sortFocused: this.props.sortFocused,
977
+ onChangeSortItem: this.onChangeSortItem,
978
+ onSelectListItem: this.onSelectListItem
979
+ }
980
+ }
981
+ }
982
+ )
983
+ ] })
984
+ }
985
+ ) }) }) })
986
+ ] }, "flk9999")
987
+ ), s;
988
+ };
989
+ render = () => {
990
+ const e = [], t = [];
991
+ return this.state.simpleFields.forEach((i) => {
992
+ i.props.dangerouslySetExpanded && i.props.uuid !== this.prefixId + "_9999" && (e.push(i), t.push(i.props.uuid));
993
+ }), this.state.simpleFields.forEach((i) => {
994
+ i.props.uuid === this.prefixId + "_9999" && (e.push(i), t.push(i.props.uuid));
995
+ }), this.state.simpleFields.forEach((i) => {
996
+ !i.props.dangerouslySetExpanded && i.props.uuid !== this.prefixId + "_9999" && e.push(i);
997
+ }), /* @__PURE__ */ n(Ie, { children: /* @__PURE__ */ n(
998
+ _t,
999
+ {
1000
+ allowZeroExpanded: !0,
1001
+ allowMultipleExpanded: !0,
1002
+ preExpanded: t,
1003
+ id: "acc1",
1004
+ children: e.map((i, r) => /* @__PURE__ */ n(Ie, { children: i }, r))
1005
+ }
1006
+ ) });
1007
+ };
1008
+ }
1009
+ class Ne extends y.Component {
1010
+ constructor(e) {
1011
+ super(e);
1012
+ }
1013
+ static get componentName() {
1014
+ return "ValueEditor";
1015
+ }
1016
+ onButtonClick = (e) => {
1017
+ this.props.onSearchButtonClick && this.props.onSearchButtonClick(
1018
+ this.props.field,
1019
+ e,
1020
+ this.props.handleOnChange,
1021
+ this.props.operator,
1022
+ this.props.searchField
1023
+ );
1024
+ };
1025
+ handleRangeChange = (e) => {
1026
+ if (e && e.length === 2) {
1027
+ const [t, i] = e;
1028
+ t && i ? this.props.handleOnChange([t, i]) : this.props.handleOnChange([]);
1029
+ }
1030
+ };
1031
+ convertValueCombobox = (e, t) => {
1032
+ if (!e || e.length === 0)
1033
+ return e;
1034
+ if (t === "string") {
1035
+ const i = e.split(","), r = [];
1036
+ if (i.length > 0)
1037
+ return i.forEach((s) => r.push(s.replaceAll("'", ""))), r;
1038
+ } else
1039
+ return e.split(",");
1040
+ return e;
1041
+ };
1042
+ render = () => {
1043
+ const {
1044
+ disabled: e,
1045
+ dataType: t,
1046
+ operator: i,
1047
+ value: r,
1048
+ value2: s,
1049
+ listValues: a,
1050
+ searchComponent: l,
1051
+ handleOnChange: h
1052
+ } = this.props;
1053
+ let o = r ?? "", c = s === null || r === void 0 ? "" : s;
1054
+ if (i === "null" || i === "notNull")
1055
+ return null;
1056
+ if (t) {
1057
+ if (t === "date")
1058
+ return i === "between" ? (o === "" && c === "" ? o = "" : o = [o, c], /* @__PURE__ */ n(
1059
+ M,
1060
+ {
1061
+ type: "range",
1062
+ disabled: e,
1063
+ value: o,
1064
+ style: { width: "100%" },
1065
+ onChange: (u) => h(u)
1066
+ }
1067
+ )) : i === "notInList" || i === "inList" ? /* @__PURE__ */ n(
1068
+ M,
1069
+ {
1070
+ type: "multiple",
1071
+ disabled: e,
1072
+ value: o,
1073
+ style: { width: "100%" },
1074
+ onChange: (u) => h(u)
1075
+ }
1076
+ ) : /* @__PURE__ */ n(
1077
+ M,
1078
+ {
1079
+ disabled: e,
1080
+ value: o,
1081
+ style: { width: "100%" },
1082
+ onChange: (u) => h(u)
1083
+ }
1084
+ );
1085
+ if (t === "date_time")
1086
+ if (i === "between") {
1087
+ const u = o === "" && c === "" ? [null, null] : [new Date(o), new Date(c)];
1088
+ return /* @__PURE__ */ n(
1089
+ Ye,
1090
+ {
1091
+ disabled: e,
1092
+ value: u,
1093
+ width: "100%",
1094
+ onRangeChange: this.handleRangeChange,
1095
+ withSeconds: !0,
1096
+ valueFormat: "DD/MM/YYYY HH:mm:ss"
1097
+ }
1098
+ );
1099
+ } else
1100
+ return /* @__PURE__ */ n(
1101
+ He,
1102
+ {
1103
+ disabled: e,
1104
+ value: o ? new Date(o) : null,
1105
+ width: "100%",
1106
+ onChange: (u) => h(u),
1107
+ withSeconds: !0,
1108
+ valueFormat: "DD/MM/YYYY HH:mm:ss"
1109
+ }
1110
+ );
1111
+ else {
1112
+ if (t === "time")
1113
+ return o === "" && c === "" ? o = "" : o = o + " - " + c, /* @__PURE__ */ n(
1114
+ Ge,
1115
+ {
1116
+ disabled: e,
1117
+ style: { width: "100%" },
1118
+ value: o,
1119
+ onChange: (u) => h(u)
1120
+ }
1121
+ );
1122
+ if (t === "boolean")
1123
+ return /* @__PURE__ */ n(
1124
+ "div",
1125
+ {
1126
+ style: {
1127
+ display: "flex",
1128
+ width: "100%",
1129
+ alignItems: "center",
1130
+ justifyContent: "center"
1131
+ },
1132
+ children: /* @__PURE__ */ n(
1133
+ qe,
1134
+ {
1135
+ checked: o,
1136
+ onChange: (u) => h(u.currentTarget.checked)
1137
+ }
1138
+ )
1139
+ }
1140
+ );
1141
+ if (a && a.length > 0 && (i === "notInList" || i === "inList")) {
1142
+ const u = this.convertValueCombobox(o, t);
1143
+ return /* @__PURE__ */ n(
1144
+ nt,
1145
+ {
1146
+ disabled: e,
1147
+ style: { width: "100%" },
1148
+ onChange: (F) => h(F),
1149
+ value: u,
1150
+ data: a
1151
+ }
1152
+ );
1153
+ } else
1154
+ return a && a.length > 0 ? /* @__PURE__ */ n(
1155
+ be,
1156
+ {
1157
+ disabled: e,
1158
+ width: "100%",
1159
+ value: o,
1160
+ onSelectValue: (u) => h(u),
1161
+ getOptionLabel: (u) => u,
1162
+ getOptionValue: (u) => u,
1163
+ children: a.map((u) => /* @__PURE__ */ n(
1164
+ Ce,
1165
+ {
1166
+ label: u.label,
1167
+ value: u.value,
1168
+ disabled: !1
1169
+ },
1170
+ u.value
1171
+ ))
1172
+ }
1173
+ ) : /* @__PURE__ */ n(
1174
+ H,
1175
+ {
1176
+ onChange: (u) => h(u),
1177
+ disabled: e,
1178
+ initialValue: o,
1179
+ icon: l || /* @__PURE__ */ n(le, { size: "1rem" }),
1180
+ onActionSearchExecute: () => this.onButtonClick(),
1181
+ style: {
1182
+ height: "36px",
1183
+ width: "100%",
1184
+ paddingLeft: "3px"
1185
+ },
1186
+ label: void 0,
1187
+ error: void 0,
1188
+ keyProp: void 0,
1189
+ readOnly: !1,
1190
+ placeholder: void 0,
1191
+ innerRef: void 0,
1192
+ onFocus: void 0,
1193
+ onKeyDown: void 0
1194
+ }
1195
+ );
1196
+ }
1197
+ } else
1198
+ return /* @__PURE__ */ n(
1199
+ H,
1200
+ {
1201
+ onChange: (u) => h(u),
1202
+ disabled: e,
1203
+ initialValue: o,
1204
+ style: {
1205
+ height: "36px",
1206
+ width: "100%",
1207
+ paddingLeft: "3px"
1208
+ },
1209
+ label: void 0,
1210
+ error: void 0,
1211
+ keyProp: void 0,
1212
+ readOnly: !1,
1213
+ placeholder: void 0,
1214
+ innerRef: void 0,
1215
+ onFocus: void 0,
1216
+ onKeyDown: void 0,
1217
+ onActionSearchExecute: void 0,
1218
+ icon: void 0
1219
+ }
1220
+ );
1221
+ };
1222
+ }
1223
+ class Ae extends y.Component {
1224
+ static get componentName() {
1225
+ return "ValueSelector";
1226
+ }
1227
+ constructor(e) {
1228
+ super(e);
1229
+ const t = e.options && e.options.length > 0 && e.options[0] ? this.getTextWidth(e.options[0].name) : "100px";
1230
+ this.state = { width: t, value: void 0 };
1231
+ }
1232
+ getLabelByName = (e) => this.props.options.map((t) => {
1233
+ if (t.name === e)
1234
+ return t.label;
1235
+ });
1236
+ getTextWidth = (e) => {
1237
+ const t = document.createElement("span");
1238
+ document.body.appendChild(t), t.className = this.props.className, t.innerHTML = this.getLabelByName(e);
1239
+ const r = Math.ceil(t.offsetWidth) + 4 + "px";
1240
+ return document.body.removeChild(t), r;
1241
+ };
1242
+ handleOnChange = (e) => {
1243
+ this.props.handleOnChange && this.props.handleOnChange(e.target.value);
1244
+ const t = this.getTextWidth(e.target.value);
1245
+ this.setState({ ...this.state, value: e.target.value, width: t });
1246
+ };
1247
+ render = () => {
1248
+ const { value: e, options: t, className: i, disabled: r, style: s } = this.props;
1249
+ return /* @__PURE__ */ n(
1250
+ "select",
1251
+ {
1252
+ className: i,
1253
+ disabled: r,
1254
+ value: e,
1255
+ tabIndex: -1,
1256
+ style: { ...s, width: this.state.width },
1257
+ onChange: this.handleOnChange,
1258
+ children: t.map((a) => /* @__PURE__ */ n("option", { value: a.name, children: a.label }, a.name))
1259
+ }
1260
+ );
1261
+ };
1262
+ }
1263
+ class Wt extends v {
1264
+ // declare context: React.ContextType<typeof ArchbaseAppContext>
1265
+ constructor(e) {
1266
+ super(e);
1267
+ const t = new j("dsSortFields", {
1268
+ records: this.props.persistenceDelegator.getFilters(),
1269
+ grandTotalRecords: this.props.persistenceDelegator.getFilters().length,
1270
+ currentPage: 0,
1271
+ totalPages: 0,
1272
+ pageSize: 999999
1273
+ }), i = Q(t) === "V2";
1274
+ this.state = {
1275
+ modalOpen: "",
1276
+ activeFilterIndex: e.activeFilterIndex,
1277
+ fields: I(e),
1278
+ showEditor: !1,
1279
+ expandedFilter: !1,
1280
+ dataSource: t,
1281
+ isDataSourceV2: i,
1282
+ forceUpdateCounter: 0
1283
+ };
1284
+ }
1285
+ shouldComponentUpdate = (e, t) => oe(this, e, t);
1286
+ UNSAFE_componentWillReceiveProps = (e) => {
1287
+ const t = new j("dsSortFields", {
1288
+ records: this.props.persistenceDelegator.getFilters(),
1289
+ grandTotalRecords: this.props.persistenceDelegator.getFilters().length,
1290
+ currentPage: 0,
1291
+ totalPages: 0,
1292
+ pageSize: 999999
1293
+ }), i = Q(t) === "V2";
1294
+ this.setState({
1295
+ ...this.state,
1296
+ fields: I(e),
1297
+ activeFilterIndex: e.activeFilterIndex,
1298
+ dataSource: t,
1299
+ isDataSourceV2: i,
1300
+ // Para V1, incrementar contador para forçar re-render
1301
+ forceUpdateCounter: i ? this.state.forceUpdateCounter : this.state.forceUpdateCounter + 1
1302
+ });
1303
+ };
1304
+ onSelectMenuItem = (e) => {
1305
+ this.props.onSaveFilter && this.props.onSaveFilter(e);
1306
+ };
1307
+ onChangeFilterType = (e) => {
1308
+ this.props.onChangeFilterType && this.props.onChangeFilterType(e);
1309
+ };
1310
+ onSelectItem = (e, t) => {
1311
+ if (this.props.onChangeSelectedFilter && t && t.filter) {
1312
+ const i = JSON.parse(t.filter);
1313
+ this.props.onChangeSelectedFilter(i, e), this.state.isDataSourceV2 || this.setState({
1314
+ ...this.state,
1315
+ forceUpdateCounter: this.state.forceUpdateCounter + 1
1316
+ });
1317
+ }
1318
+ };
1319
+ getColor = (e) => "black";
1320
+ render = () => {
1321
+ let e = "normal";
1322
+ return this.props.currentFilter && (e = this.props.currentFilter.filter.filterType), /* @__PURE__ */ n(Fe, { h: this.props.height, w: this.props.width, children: /* @__PURE__ */ p("div", { style: { width: "98%" }, children: [
1323
+ /* @__PURE__ */ n(X, { variant: "contained", multiple: !1, defaultValue: "filters", children: /* @__PURE__ */ p(X.Item, { value: "filters", children: [
1324
+ /* @__PURE__ */ n(
1325
+ X.Control,
1326
+ {
1327
+ icon: /* @__PURE__ */ n(Qe, { size: 24, color: this.getColor("red") }),
1328
+ children: /* @__PURE__ */ n(x, { style: { fontWeight: "bold" }, children: `${m().t("archbase:Filtros salvos")}` })
1329
+ }
1330
+ ),
1331
+ /* @__PURE__ */ n(X.Panel, { children: /* @__PURE__ */ n(
1332
+ de,
1333
+ {
1334
+ height: "105px",
1335
+ activeIndex: this.state.activeFilterIndex,
1336
+ dataSource: this.state.dataSource,
1337
+ onSelectListItem: this.onSelectItem,
1338
+ style: { borderRadius: "6px", marginBottom: "4px", padding: "10px" },
1339
+ component: { type: Gt, props: {} }
1340
+ }
1341
+ ) })
1342
+ ] }) }),
1343
+ /* @__PURE__ */ p("div", { className: "filter-apply", children: [
1344
+ /* @__PURE__ */ p(q, { gap: "xs", children: [
1345
+ /* @__PURE__ */ n(f, { withinPortal: !0, withArrow: !0, label: `${m().t("archbase:Novo filtro")}`, children: /* @__PURE__ */ n(
1346
+ w,
1347
+ {
1348
+ id: "btnNew",
1349
+ variant: this.props.variant,
1350
+ leftSection: /* @__PURE__ */ n(ct, {}),
1351
+ onClick: (t) => this.props.onActionClick && this.props.onActionClick("new"),
1352
+ children: m().t("archbase:New")
1353
+ }
1354
+ ) }),
1355
+ /* @__PURE__ */ n(f, { withinPortal: !0, withArrow: !0, label: `${m().t("archbase:Remover filtro")}`, children: /* @__PURE__ */ n(
1356
+ w,
1357
+ {
1358
+ id: "btnRemove",
1359
+ color: "red",
1360
+ variant: this.props.variant,
1361
+ disabled: this.props.currentFilter && (!this.props.currentFilter.id || this.props.currentFilter.id <= 0),
1362
+ leftSection: /* @__PURE__ */ n(Ue, {}),
1363
+ onClick: (t) => this.props.onActionClick && this.props.onActionClick("remove"),
1364
+ children: m().t("archbase:Remover")
1365
+ }
1366
+ ) })
1367
+ ] }),
1368
+ /* @__PURE__ */ p(q, { gap: "xs", children: [
1369
+ /* @__PURE__ */ p(
1370
+ B,
1371
+ {
1372
+ shadow: "md",
1373
+ width: 200,
1374
+ withinPortal: !0,
1375
+ disabled: this.props.activeFilterIndex === S,
1376
+ children: [
1377
+ /* @__PURE__ */ n(B.Target, { children: /* @__PURE__ */ n(w, { variant: this.props.variant, leftSection: /* @__PURE__ */ n(ue, {}), children: `${m().t("archbase:Save")}` }) }),
1378
+ /* @__PURE__ */ p(B.Dropdown, { children: [
1379
+ /* @__PURE__ */ n(B.Label, { children: `${m().t("archbase:Filter")}` }),
1380
+ /* @__PURE__ */ n(
1381
+ B.Item,
1382
+ {
1383
+ onClick: () => this.onSelectMenuItem("mnuItemSalvar"),
1384
+ disabled: this.props.activeFilterIndex === S,
1385
+ leftSection: /* @__PURE__ */ n(ue, { size: 14 }),
1386
+ children: `${m().t("archbase:Save")}`
1387
+ }
1388
+ ),
1389
+ /* @__PURE__ */ n(
1390
+ B.Item,
1391
+ {
1392
+ onClick: () => this.onSelectMenuItem("mnuItemSalvarComo"),
1393
+ disabled: this.props.activeFilterIndex === S,
1394
+ leftSection: /* @__PURE__ */ n(ue, { size: 14 }),
1395
+ children: `${m().t("archbase:Salvar como...")}`
1396
+ }
1397
+ )
1398
+ ] })
1399
+ ]
1400
+ }
1401
+ ),
1402
+ /* @__PURE__ */ n(f, { withinPortal: !0, withArrow: !0, label: `${m().t("archbase:Aplicar filtro")}`, children: /* @__PURE__ */ n(
1403
+ w,
1404
+ {
1405
+ id: "btnApply",
1406
+ variant: this.props.variant,
1407
+ leftSection: /* @__PURE__ */ n(ye, {}),
1408
+ disabled: this.props.activeFilterIndex === S,
1409
+ onClick: (t) => {
1410
+ console.log(this.props.activeFilterIndex), this.props.onActionClick && this.props.onActionClick("apply");
1411
+ },
1412
+ children: `${m().t("archbase:Aplicar")}`
1413
+ }
1414
+ ) }),
1415
+ /* @__PURE__ */ n(f, { withinPortal: !0, withArrow: !0, label: `${m().t("archbase:Fechar filtro")}`, children: /* @__PURE__ */ n(
1416
+ w,
1417
+ {
1418
+ id: "btnClose",
1419
+ variant: this.props.variant,
1420
+ color: "green",
1421
+ leftSection: /* @__PURE__ */ n(pt, {}),
1422
+ onClick: (t) => this.props.onActionClick && this.props.onActionClick("close"),
1423
+ children: `${m().t("archbase:Close")}`
1424
+ }
1425
+ ) })
1426
+ ] })
1427
+ ] }),
1428
+ this.props.activeFilterIndex === Z ? /* @__PURE__ */ n(
1429
+ pe.Group,
1430
+ {
1431
+ value: this.props.currentFilter.filter.filterType,
1432
+ name: "filterType",
1433
+ label: `${m().t("archbase:Selecione o tipo do filtro")}`,
1434
+ withAsterisk: !0,
1435
+ onChange: (t) => this.onChangeFilterType(t === "normal" ? 0 : 1),
1436
+ children: /* @__PURE__ */ p(q, { mt: "xs", children: [
1437
+ /* @__PURE__ */ n(pe, { value: "normal", label: `${m().t("archbase:Simples")}` }),
1438
+ /* @__PURE__ */ n(pe, { value: "advanced", label: `${m().t("archbase:Avançado")}` })
1439
+ ] })
1440
+ }
1441
+ ) : null,
1442
+ e === ee ? /* @__PURE__ */ n(
1443
+ Mt,
1444
+ {
1445
+ allowSort: !0,
1446
+ update: this.props.update,
1447
+ operators: $t,
1448
+ currentFilter: this.props.currentFilter,
1449
+ activeFilterIndex: this.props.activeFilterIndex,
1450
+ onFilterChanged: this.props.onFilterChanged,
1451
+ onSearchButtonClick: this.props.onSearchButtonClick,
1452
+ fields: this.state.fields
1453
+ }
1454
+ ) : null,
1455
+ e === se ? /* @__PURE__ */ n(
1456
+ zt,
1457
+ {
1458
+ isOpen: this.state.expandedFilter,
1459
+ update: this.props.update,
1460
+ width: "auto",
1461
+ height: "100%",
1462
+ selectedOptions: ae(this.state.fields),
1463
+ onFilterChanged: this.props.onFilterChanged,
1464
+ onSearchButtonClick: this.props.onSearchButtonClick,
1465
+ currentFilter: this.props.currentFilter,
1466
+ activeFilterIndex: this.props.activeFilterIndex,
1467
+ children: Ze(this.props.children)
1468
+ }
1469
+ ) : null
1470
+ ] }) });
1471
+ };
1472
+ }
1473
+ class zt extends v {
1474
+ static defaultProps = {
1475
+ isOpen: !1
1476
+ };
1477
+ constructor(e) {
1478
+ super(e), this.state = { modalOpen: "", update: Math.random() };
1479
+ }
1480
+ onSelectMenuItem = (e) => {
1481
+ this.props.onSaveFilter && this.props.onSaveFilter(e);
1482
+ };
1483
+ onSelectItem = (e, t) => {
1484
+ if (this.props.onChangeSelectedFilter && t && t.filter) {
1485
+ let i = JSON.parse(t.filter);
1486
+ i.id = t.id, i.name = t.name, i.formName = t.formName, this.props.onChangeSelectedFilter(i, e);
1487
+ }
1488
+ this.setState({ ...this.state, update: Math.random() });
1489
+ };
1490
+ render() {
1491
+ return /* @__PURE__ */ p("div", { style: { padding: "10px", width: this.props.width }, children: [
1492
+ /* @__PURE__ */ n(
1493
+ Ht,
1494
+ {
1495
+ onFilterChanged: this.props.onFilterChanged,
1496
+ width: "100%",
1497
+ horizontal: !1,
1498
+ currentFilter: this.props.currentFilter,
1499
+ activeFilterIndex: this.props.activeFilterIndex,
1500
+ id: `advanced${U()}`,
1501
+ border: "none",
1502
+ variant: this.props.variant,
1503
+ children: this.props.children
1504
+ }
1505
+ ),
1506
+ /* @__PURE__ */ n(
1507
+ qt,
1508
+ {
1509
+ id: "modalSaveFilter",
1510
+ title: `${m().t("archbase:Salvar filtro")}`,
1511
+ modalOpen: this.state.modalOpen,
1512
+ variant: this.props.variant
1513
+ }
1514
+ )
1515
+ ] });
1516
+ }
1517
+ }
1518
+ class Gt extends v {
1519
+ static defaultProps = {
1520
+ disabled: !1,
1521
+ active: !0
1522
+ };
1523
+ constructor(e) {
1524
+ super(e), this.state = { update: Math.random() };
1525
+ }
1526
+ onClick = (e) => {
1527
+ e.preventDefault(), this.props.disabled || (this.props.handleSelectItem && (e.preventDefault(), this.props.handleSelectItem(this.props.index, this.props.recordData), e.preventDefault()), this.props.onSelectListItem && this.props.onSelectListItem(this.props.index, this.props.recordData));
1528
+ };
1529
+ render = () => {
1530
+ let e = "#28C76F", t = `${m().t("archbase:Simples")}`;
1531
+ this.props.recordData.filter && JSON.parse(this.props.recordData.filter).filter.filterType === "advanced" && (e = "#437de0", t = `${m().t("archbase:Avançado")}`);
1532
+ let i = "list-group-item list-group-item-action", r = {
1533
+ maxHeight: "24px",
1534
+ padding: "2px 2px 2px 8px",
1535
+ display: "flex",
1536
+ justifyContent: "space-between",
1537
+ alignItems: "center",
1538
+ cursor: "pointer"
1539
+ };
1540
+ return this.props.active && (i += " active", r = { ...r, border: "1px dashed blue", fontWeight: "bold" }), this.props.recordData.disabled && (i += " disabled"), /* @__PURE__ */ p("div", { className: i, style: r, onClick: this.onClick, children: [
1541
+ /* @__PURE__ */ n(x, { style: { cursor: "pointer" }, children: m().t(this.props.recordData.name) }),
1542
+ /* @__PURE__ */ n(at, { style: { cursor: "pointer", maxWidth: "100px", fontWeight: "bold" }, color: e, children: t })
1543
+ ] });
1544
+ };
1545
+ }
1546
+ class Qt extends v {
1547
+ constructor(e) {
1548
+ super(e), me(ae(e.fields)), me(Lt(e.fields)), this.state = {
1549
+ selectedFields: [...e.selectedOptions],
1550
+ sortFields: [...e.sort],
1551
+ allChecked: !1,
1552
+ activeIndex: e.currentFilter.sort.activeIndex,
1553
+ update: Math.random(),
1554
+ // 🔄 MIGRAÇÃO V1/V2: Inicializar contador de forceUpdate
1555
+ forceUpdateCounter: 0
1556
+ };
1557
+ }
1558
+ // 🔄 MIGRAÇÃO V1/V2: Helper para criar DataSource com compatibilidade
1559
+ createCompatibleDataSource = (e) => {
1560
+ const t = new j("dsSortFields", {
1561
+ records: e,
1562
+ grandTotalRecords: e.length,
1563
+ currentPage: 0,
1564
+ totalPages: 0,
1565
+ pageSize: 999999
1566
+ });
1567
+ return Q(t) !== "V2" && this.setState({
1568
+ ...this.state,
1569
+ forceUpdateCounter: this.state.forceUpdateCounter + 1
1570
+ }), t;
1571
+ };
1572
+ onCheckboxChange = (e, t, i) => {
1573
+ let r = [...this.state.selectedFields];
1574
+ t ? r.push(i) : r = this.state.selectedFields.filter((s) => s.name !== i.name), this.setState({ ...this.state, selectedFields: r });
1575
+ };
1576
+ renderCheckboxFields = () => {
1577
+ if (this.props.fields)
1578
+ return this.props.fields.map((e) => {
1579
+ let t = !1;
1580
+ return this.state.selectedFields.forEach((i) => {
1581
+ e.name === i.name && (t = !0);
1582
+ }), /* @__PURE__ */ n(
1583
+ W,
1584
+ {
1585
+ label: e.label,
1586
+ checked: t,
1587
+ style: { paddingBottom: "8px", cursor: "pointer" },
1588
+ onChange: (i) => this.onCheckboxChange(i.currentTarget.checked, i.currentTarget.checked, e)
1589
+ },
1590
+ e.label
1591
+ );
1592
+ });
1593
+ };
1594
+ getSortItem = (e) => {
1595
+ let t;
1596
+ return this.state.sortFields.forEach(function(i) {
1597
+ i.name === e && (t = i);
1598
+ }), t;
1599
+ };
1600
+ onChangeSortItem = (e, t, i, r) => {
1601
+ const s = this.getSortItem(e);
1602
+ if (s) {
1603
+ Object.assign(s, {
1604
+ selected: t,
1605
+ order: i,
1606
+ asc_desc: r,
1607
+ label: s.label
1608
+ });
1609
+ let a = this.state.sortFields;
1610
+ a = a.sort(function(l, h) {
1611
+ return l.order - h.order;
1612
+ }), this.setState({
1613
+ ...this.state,
1614
+ update: Math.random(),
1615
+ sortFields: a
1616
+ });
1617
+ }
1618
+ };
1619
+ getSortItemByOrder = (e) => {
1620
+ let t;
1621
+ return this.state.sortFields.forEach(function(i) {
1622
+ i.order === e && (t = i);
1623
+ }), t;
1624
+ };
1625
+ onSortDown = (e) => {
1626
+ let t = this.state.activeIndex;
1627
+ if (t >= 0) {
1628
+ const i = this.state.sortFields[t];
1629
+ if (i.order < this.state.sortFields.length - 1) {
1630
+ t = i.order + 1;
1631
+ const s = this.getSortItemByOrder(i.order + 1);
1632
+ s && (Object.assign(i, {
1633
+ order: i.order + 1
1634
+ }), Object.assign(s, {
1635
+ order: s.order - 1
1636
+ }));
1637
+ }
1638
+ let r = this.state.sortFields;
1639
+ r = r.sort(function(s, a) {
1640
+ return s.order - a.order;
1641
+ }), this.setState({
1642
+ ...this.state,
1643
+ sortFields: r,
1644
+ activeIndex: t
1645
+ });
1646
+ }
1647
+ };
1648
+ onSortUp = (e) => {
1649
+ let t = this.state.activeIndex;
1650
+ if (t >= 0) {
1651
+ const i = this.state.sortFields[t];
1652
+ if (i.order > 0) {
1653
+ t = i.order - 1;
1654
+ const s = this.getSortItemByOrder(i.order - 1);
1655
+ s && (Object.assign(i, {
1656
+ order: i.order - 1
1657
+ }), Object.assign(s, {
1658
+ order: s.order + 1
1659
+ }));
1660
+ }
1661
+ let r = this.state.sortFields;
1662
+ r = r.sort(function(s, a) {
1663
+ return s.order - a.order;
1664
+ }), this.setState({
1665
+ ...this.state,
1666
+ sortFields: r,
1667
+ activeIndex: t
1668
+ });
1669
+ }
1670
+ };
1671
+ onSelectListItem = (e, t) => {
1672
+ this.setState({ ...this.state, activeIndex: e });
1673
+ };
1674
+ selectAllFields = (e) => {
1675
+ const t = me(ae(this.props.fields)), i = e ? t : [];
1676
+ this.setState({ ...this.state, selectedFields: i, allChecked: e });
1677
+ };
1678
+ render = () => /* @__PURE__ */ p(
1679
+ "div",
1680
+ {
1681
+ id: this.props.id,
1682
+ style: { width: this.props.width, display: "grid", justifyContent: "center", height: "460px" },
1683
+ children: [
1684
+ /* @__PURE__ */ p(Ke, { children: [
1685
+ /* @__PURE__ */ p(
1686
+ O,
1687
+ {
1688
+ style: {
1689
+ paddingBottom: "10px",
1690
+ overflowY: "auto",
1691
+ display: "block",
1692
+ overflowX: "hidden"
1693
+ },
1694
+ children: [
1695
+ /* @__PURE__ */ p(
1696
+ ke,
1697
+ {
1698
+ style: {
1699
+ padding: "10px",
1700
+ width: "100%"
1701
+ },
1702
+ children: [
1703
+ /* @__PURE__ */ n(x, { style: { fontWeight: "700" }, children: m().t("archbase:Selecione os campos p/ o filtro rápido:") }),
1704
+ /* @__PURE__ */ n(
1705
+ W,
1706
+ {
1707
+ checked: this.state.allChecked,
1708
+ style: { cursor: "pointer" },
1709
+ onChange: (e) => this.selectAllFields(e.currentTarget.checked),
1710
+ label: m().t("archbase:Selecionar todos ?")
1711
+ }
1712
+ )
1713
+ ]
1714
+ }
1715
+ ),
1716
+ /* @__PURE__ */ n(O.Col, { children: /* @__PURE__ */ n(Fe, { h: "128px", children: /* @__PURE__ */ n(Me, { children: this.renderCheckboxFields() }) }) })
1717
+ ]
1718
+ }
1719
+ ),
1720
+ /* @__PURE__ */ n(O, { children: /* @__PURE__ */ n(O.Col, { style: { padding: 13 }, children: /* @__PURE__ */ p(
1721
+ "div",
1722
+ {
1723
+ className: "sort-group-container",
1724
+ style: {
1725
+ height: "200px"
1726
+ },
1727
+ children: [
1728
+ /* @__PURE__ */ p("div", { className: "sort-header", children: [
1729
+ /* @__PURE__ */ p("div", { style: { display: "flex" }, children: [
1730
+ /* @__PURE__ */ n(f, { withinPortal: !0, withArrow: !0, label: "Para baixo", children: /* @__PURE__ */ n(g, { id: "btnFilterSortDown", onClick: this.onSortDown, children: /* @__PURE__ */ n(ve, {}) }) }),
1731
+ /* @__PURE__ */ n(f, { withinPortal: !0, withArrow: !0, label: "Para cima", children: /* @__PURE__ */ n(g, { id: "btnFilterSortUp", onClick: this.onSortUp, children: /* @__PURE__ */ n(Se, {}) }) })
1732
+ ] }),
1733
+ /* @__PURE__ */ n(x, { children: m().t("archbase:Ordenação") })
1734
+ ] }),
1735
+ /* @__PURE__ */ n(Fe, { className: "sort-body", children: /* @__PURE__ */ n(
1736
+ de,
1737
+ {
1738
+ height: "100%",
1739
+ width: "100%",
1740
+ dataSource: (
1741
+ // 🔄 MIGRAÇÃO V1/V2: Usar método de compatibilidade
1742
+ this.createCompatibleDataSource(this.state.sortFields)
1743
+ ),
1744
+ withBorder: !1,
1745
+ dataFieldId: "name",
1746
+ dataFieldText: "name",
1747
+ activeIndex: this.state.activeIndex,
1748
+ component: {
1749
+ type: we,
1750
+ props: {
1751
+ sortFocused: this.props.sortFocused,
1752
+ onChangeSortItem: this.onChangeSortItem,
1753
+ onSelectListItem: this.onSelectListItem
1754
+ }
1755
+ }
1756
+ }
1757
+ ) })
1758
+ ]
1759
+ }
1760
+ ) }) })
1761
+ ] }),
1762
+ /* @__PURE__ */ p(
1763
+ ke,
1764
+ {
1765
+ style: {
1766
+ display: "flex",
1767
+ justifyContent: "end",
1768
+ width: "100%",
1769
+ height: "40px",
1770
+ marginTop: "10px"
1771
+ },
1772
+ children: [
1773
+ /* @__PURE__ */ n(
1774
+ w,
1775
+ {
1776
+ variant: this.props.variant,
1777
+ onClick: () => this.props.onConfirmSelectFields && this.props.onConfirmSelectFields(this.state.selectedFields, this.state.sortFields, this.state.activeIndex),
1778
+ children: "Aplicar"
1779
+ }
1780
+ ),
1781
+ /* @__PURE__ */ n(R, { w: "sm" }),
1782
+ /* @__PURE__ */ n(w, { variant: this.props.variant, color: "red", onClick: this.props.onCancelSelectFields, children: "Cancela" })
1783
+ ]
1784
+ }
1785
+ )
1786
+ ]
1787
+ },
1788
+ this.props.key
1789
+ );
1790
+ }
1791
+ const Ut = ["Dom", "Seg", "Ter", "Qua", "Qui", "Sex", "Sáb"], jt = ["Jan", "Fev", "Mar", "Abr", "Mai", "Jun", "Jul", "Ago", "Set", "Out", "Nov", "Dez"];
1792
+ class Yt extends v {
1793
+ dateRef;
1794
+ constructor(e) {
1795
+ super(e), this.state = { value: void 0, selectRangeType: "range" }, this.dateRef = y.createRef();
1796
+ }
1797
+ UNSAFE_componentWillReceiveProps = (e) => {
1798
+ this.setState({ value: void 0 });
1799
+ };
1800
+ handleDateChange = (e) => {
1801
+ this.setState({ value: e });
1802
+ };
1803
+ render = () => /* @__PURE__ */ p(
1804
+ "div",
1805
+ {
1806
+ id: this.props.id,
1807
+ style: { width: this.props.width, display: "grid", justifyContent: "center", height: "344px" },
1808
+ children: [
1809
+ /* @__PURE__ */ n("div", { style: { display: "flex", justifyContent: "center", alignItems: "center" }, children: /* @__PURE__ */ n(
1810
+ Dt,
1811
+ {
1812
+ ref: this.dateRef,
1813
+ value: this.state.value,
1814
+ shadow: !1,
1815
+ weekDays: Ut,
1816
+ months: jt,
1817
+ weekPicker: this.state.selectRangeType === "week",
1818
+ onlyMonthPicker: this.state.selectRangeType === "month",
1819
+ range: this.state.selectRangeType === "week" || this.state.selectRangeType === "month" || this.state.selectRangeType === "range",
1820
+ multiple: this.state.selectRangeType === "day",
1821
+ format: "DD/MM/YYYY",
1822
+ numberOfMonths: 2,
1823
+ onChange: this.handleDateChange
1824
+ }
1825
+ ) }),
1826
+ /* @__PURE__ */ p(
1827
+ Me,
1828
+ {
1829
+ style: {
1830
+ display: "flex",
1831
+ justifyContent: "space-between",
1832
+ alignItems: "center",
1833
+ width: this.props.width,
1834
+ height: "40px",
1835
+ marginTop: "10px"
1836
+ },
1837
+ children: [
1838
+ /* @__PURE__ */ p("div", { style: { display: "flex", alignItems: "center" }, children: [
1839
+ /* @__PURE__ */ n(f, { withinPortal: !0, withArrow: !0, label: `${m().t("archbase:Intervalo")}`, children: /* @__PURE__ */ n(
1840
+ g,
1841
+ {
1842
+ variant: this.props.variant,
1843
+ size: "lg",
1844
+ color: "var(--mantine-primary-color-filled)",
1845
+ onClick: () => this.setState({ ...this.state, selectRangeType: "range" }),
1846
+ style: { width: "36px", height: "36px", marginRight: 2 },
1847
+ children: /* @__PURE__ */ n(ut, { size: "1.4rem" })
1848
+ }
1849
+ ) }),
1850
+ /* @__PURE__ */ n(f, { withinPortal: !0, withArrow: !0, label: `${m().t("archbase:Mês")}`, children: /* @__PURE__ */ n(
1851
+ g,
1852
+ {
1853
+ variant: this.props.variant,
1854
+ size: "lg",
1855
+ color: "var(--mantine-primary-color-filled)",
1856
+ onClick: () => this.setState({ ...this.state, selectRangeType: "month" }),
1857
+ style: { width: "36px", height: "36px", marginRight: 2 },
1858
+ children: /* @__PURE__ */ n(mt, { size: "1.4rem" })
1859
+ }
1860
+ ) }),
1861
+ /* @__PURE__ */ n(f, { withinPortal: !0, withArrow: !0, label: `${m().t("archbase:Semana")}`, children: /* @__PURE__ */ n(
1862
+ g,
1863
+ {
1864
+ variant: this.props.variant,
1865
+ size: "lg",
1866
+ color: "var(--mantine-primary-color-filled)",
1867
+ onClick: () => this.setState({ ...this.state, selectRangeType: "week" }),
1868
+ style: { width: "36px", height: "36px", marginRight: 2 },
1869
+ children: /* @__PURE__ */ n(ft, { size: "1.4rem" })
1870
+ }
1871
+ ) }),
1872
+ /* @__PURE__ */ n(f, { withinPortal: !0, withArrow: !0, label: `${m().t("archbase:Dia")}`, children: /* @__PURE__ */ n(
1873
+ g,
1874
+ {
1875
+ variant: this.props.variant,
1876
+ size: "lg",
1877
+ color: "var(--mantine-primary-color-filled)",
1878
+ onClick: () => this.setState({ ...this.state, selectRangeType: "day" }),
1879
+ style: { width: "36px", height: "36px", marginRight: 2 },
1880
+ children: /* @__PURE__ */ n(je, { size: "1.4rem" })
1881
+ }
1882
+ ) })
1883
+ ] }),
1884
+ /* @__PURE__ */ p("div", { style: { display: "flex" }, children: [
1885
+ /* @__PURE__ */ n(
1886
+ w,
1887
+ {
1888
+ variant: this.props.variant,
1889
+ onClick: () => this.props.onConfirmSelectRange(this.state.value, this.state.selectRangeType),
1890
+ children: "Aplicar"
1891
+ }
1892
+ ),
1893
+ /* @__PURE__ */ n(R, { w: "sm" }),
1894
+ /* @__PURE__ */ n(w, { variant: this.props.variant, color: "red", onClick: this.props.onCancelSelectRange, children: "Cancela" })
1895
+ ] })
1896
+ ]
1897
+ }
1898
+ )
1899
+ ]
1900
+ },
1901
+ this.props.key
1902
+ );
1903
+ }
1904
+ const H = ({
1905
+ onActionSearchExecute: d,
1906
+ icon: e,
1907
+ disabled: t,
1908
+ label: i,
1909
+ error: r,
1910
+ initialValue: s,
1911
+ onChange: a,
1912
+ style: l,
1913
+ placeholder: h,
1914
+ keyProp: o,
1915
+ readOnly: c,
1916
+ innerRef: u,
1917
+ onFocus: F,
1918
+ onKeyDown: b,
1919
+ tooltipIconSearch: k = "Clique aqui para Localizar",
1920
+ variant: P = "filled"
1921
+ }) => {
1922
+ const [L, J] = $(s), [z] = Je(L, 500), G = Be(!1), V = $e(), { colorScheme: K } = We();
1923
+ return ge(() => {
1924
+ J(s);
1925
+ }, [s]), ge(() => {
1926
+ z !== s && G.current && a(z), G.current = !1;
1927
+ }, [z, s, a]), /* @__PURE__ */ n(
1928
+ ze,
1929
+ {
1930
+ label: i,
1931
+ error: r,
1932
+ value: L,
1933
+ ref: u,
1934
+ w: "100%",
1935
+ readOnly: c,
1936
+ onFocus: F,
1937
+ onKeyDown: b,
1938
+ placeholder: h,
1939
+ style: l,
1940
+ disabled: t,
1941
+ rightSection: d ? /* @__PURE__ */ n(f, { withinPortal: !0, withArrow: !0, label: k, children: /* @__PURE__ */ n(
1942
+ g,
1943
+ {
1944
+ style: {
1945
+ backgroundColor: P === "filled" ? K === "dark" ? V.colors[V.primaryColor][5] : V.colors[V.primaryColor][6] : void 0
1946
+ },
1947
+ tabIndex: -1,
1948
+ variant: P,
1949
+ onClick: d,
1950
+ children: e
1951
+ }
1952
+ ) }) : null,
1953
+ onChange: (_) => {
1954
+ J(_.target.value), G.current = !0;
1955
+ }
1956
+ },
1957
+ o
1958
+ );
1959
+ };
1960
+ class Bi extends v {
1961
+ static defaultProps = {
1962
+ showClearButton: !0,
1963
+ showToggleButton: !0,
1964
+ showPrintButton: !1,
1965
+ showExportButton: !1,
1966
+ expandedFilter: !1,
1967
+ width: "50px",
1968
+ height: "500px",
1969
+ detailsHeight: 580,
1970
+ detailsWidth: 768,
1971
+ detailsAlign: "right"
1972
+ };
1973
+ timeout;
1974
+ divMain;
1975
+ refEdit;
1976
+ toggleFilterButtonRef;
1977
+ inputValue;
1978
+ // declare context: React.ContextType<typeof ArchbaseAppContext>;
1979
+ constructor(e) {
1980
+ super(e), this.refEdit = y.createRef(), this.toggleFilterButtonRef = y.createRef(), this.state = {
1981
+ currentFilter: this.props.currentFilter ? this.props.currentFilter : D(e, T),
1982
+ modalOpen: "",
1983
+ modalSearchField: "",
1984
+ isOpenSelectRange: !1,
1985
+ isOpenSelectFields: !1,
1986
+ expandedFilter: this.props.expandedFilter,
1987
+ update: Math.random(),
1988
+ activeFilterIndex: this.props.currentFilter ? this.props.activeFilterIndex : S
1989
+ };
1990
+ }
1991
+ shouldComponentUpdate = (e, t) => oe(this, e, t);
1992
+ UNSAFE_componentWillReceiveProps = (e) => {
1993
+ let t = e.currentFilter, i = e.activeFilterIndex;
1994
+ t || (e.persistenceDelegator && e.persistenceDelegator.getFilters().length > 0 ? (t = JSON.parse(e.persistenceDelegator.getFirstFilter().filter), i = 0) : (t = D(e, T), i = S)), this.setState({
1995
+ ...this.state,
1996
+ currentFilter: t,
1997
+ modalOpen: "",
1998
+ expandedFilter: e.expandedFilter ? e.expandedFilter : !1,
1999
+ activeFilterIndex: i
2000
+ });
2001
+ };
2002
+ componentDidMount = () => {
2003
+ window.addEventListener("resize", this.onResize);
2004
+ };
2005
+ componentWillUnmount = () => {
2006
+ window.removeEventListener("resize", this.onResize);
2007
+ };
2008
+ toggleExpandedFilter = () => {
2009
+ const e = !this.state.expandedFilter;
2010
+ this.getPosition("filter"), this.setState(
2011
+ {
2012
+ ...this.state,
2013
+ expandedFilter: e,
2014
+ isOpenSelectRange: !1,
2015
+ isOpenSelectFields: !1
2016
+ },
2017
+ () => {
2018
+ if (!this.state.currentFilter || this.state.currentFilter.filter.filterType === T) {
2019
+ const t = this.props.persistenceDelegator.getFirstFilter();
2020
+ if (t) {
2021
+ const i = t.filter ? JSON.parse(t.filter) : Y();
2022
+ this.onChangeSelectedFilter(i, 0);
2023
+ } else
2024
+ this.addNewFilter();
2025
+ }
2026
+ }
2027
+ ), this.props.onToggleExpandedFilter && this.props.onToggleExpandedFilter(e);
2028
+ };
2029
+ clearFilter = () => {
2030
+ this.props.onToggleExpandedFilter && this.props.onToggleExpandedFilter(!1);
2031
+ const e = D(this.props, T);
2032
+ this.setState(
2033
+ {
2034
+ ...this.state,
2035
+ currentFilter: e,
2036
+ expandedFilter: !1,
2037
+ activeFilterIndex: S
2038
+ },
2039
+ () => {
2040
+ this.onFilterChanged(e, S, () => {
2041
+ this.props.onClearFilter && this.props.onClearFilter(this), this.onSearchClick();
2042
+ });
2043
+ }
2044
+ );
2045
+ };
2046
+ onSearchClick = () => {
2047
+ this.props.onSearchByFilter && this.props.onSearchByFilter(), this.onCloseFilterClick();
2048
+ };
2049
+ onChangeQuickFilter = (e) => {
2050
+ this.changeQuickFilter(e);
2051
+ };
2052
+ changeQuickFilter = (e) => {
2053
+ let t = this.state.currentFilter;
2054
+ t && t.filter && t.filter.filterType !== T && (t = D(this.props, T)), t.filter.quickFilterText = e, t.filter.quickFilterFieldsText = A(t, I(this.props)), this.setState({
2055
+ ...this.state,
2056
+ currentFilter: t,
2057
+ expandedFilter: !1,
2058
+ activeFilterIndex: S
2059
+ }), clearTimeout(this.timeout), this.timeout = setTimeout(() => {
2060
+ this.props.onToggleExpandedFilter && this.props.onToggleExpandedFilter(!1), this.props.onFilterChanged && this.props.onFilterChanged(t, S);
2061
+ }, 200);
2062
+ };
2063
+ handleQuickFilter = (e) => {
2064
+ e.keyCode === 13 && this.onSearchClick();
2065
+ };
2066
+ getQuickFilterText = () => this.state.currentFilter.filter.quickFilterText;
2067
+ onFilterChanged = (e, t, i) => {
2068
+ const r = [];
2069
+ if (e.id) {
2070
+ this.convertFilterToListValues("root", e.filter.rules, r);
2071
+ const s = { filter: r, sort: e.sort.sortFields };
2072
+ localStorage.setItem(`filter${e.id}`, JSON.stringify(s));
2073
+ }
2074
+ this.props.onFilterChanged ? this.props.onFilterChanged(e, t, () => {
2075
+ this.setState({ ...this.state, update: Math.random() }, i);
2076
+ }) : this.setState({ ...this.state, update: Math.random() }, i);
2077
+ };
2078
+ loadListValuesToFilter = (e, t, i) => {
2079
+ for (let r = 0; r < t.length; r++) {
2080
+ const s = t[r];
2081
+ if (s.rules)
2082
+ this.loadListValuesToFilter(s.id, s.rules, i);
2083
+ else {
2084
+ const a = this.getItemListById(i, e, s.id);
2085
+ a && (s.value = a.value, s.value2 = a.value2);
2086
+ }
2087
+ }
2088
+ };
2089
+ getItemListById = (e, t, i) => {
2090
+ for (let r = 0; r < e.length; r++)
2091
+ if (e[r].parent === t && e[r].id === i)
2092
+ return e[r];
2093
+ };
2094
+ convertFilterToListValues = (e, t, i) => {
2095
+ for (let r = 0; r < t.length; r++) {
2096
+ const s = t[r];
2097
+ s.rules ? this.convertFilterToListValues(s.id, s.rules, i) : i.push({
2098
+ parent: e,
2099
+ id: s.id,
2100
+ value: s.value,
2101
+ value2: s.value2
2102
+ });
2103
+ }
2104
+ };
2105
+ onSaveFilter = (e) => {
2106
+ e === "mnuItemSalvar" && this.state.currentFilter && this.state.currentFilter.id && this.state.currentFilter.id !== S && this.state.currentFilter.id !== Z ? N.showConfirmDialogYesNo(
2107
+ `${m().t("archbase:Confirme")}`,
2108
+ `${m().t("archbase:Deseja salvar o Filtro ?")}`,
2109
+ () => {
2110
+ const t = this.state.currentFilter;
2111
+ t.filter.quickFilterFieldsText = A(t, I(this.props));
2112
+ const i = this.props.persistenceDelegator.getFilterById(
2113
+ t.id
2114
+ );
2115
+ i && (i.setFilter(t), this.props.persistenceDelegator.saveFilter(i, (r) => {
2116
+ r && N.showErrorWithDetails(
2117
+ `${m().t("archbase:Warning")}`,
2118
+ he(r),
2119
+ ce(r)
2120
+ );
2121
+ }));
2122
+ },
2123
+ () => {
2124
+ }
2125
+ ) : (e === "mnuItemSalvar" || e === "mnuItemSalvarComo") && this.state.currentFilter && (this.inputValue = "", N.showInputDialog(
2126
+ `${m().t("archbase:Salvar como...")}`,
2127
+ `${m().t("archbase:Informe um nome para o fitro...")}`,
2128
+ `${m().t("archbase:Confirme")}`,
2129
+ (t) => this.inputValue = t.target.value,
2130
+ () => {
2131
+ const t = this.state.currentFilter;
2132
+ t.filter.quickFilterFieldsText = A(t, I(this.props));
2133
+ const i = ne.createInstanceWithValues({
2134
+ filter: t,
2135
+ id: Rt(),
2136
+ name: this.inputValue,
2137
+ componentName: this.props.id,
2138
+ userName: this.props.userName,
2139
+ shared: !0,
2140
+ viewName: this.props.viewName,
2141
+ isNewFilter: !0
2142
+ });
2143
+ this.props.persistenceDelegator.addNewFilter(i, (r, s) => {
2144
+ r ? N.showErrorWithDetails(
2145
+ `${m().t("archbase:Warning")}`,
2146
+ he(r),
2147
+ ce(r)
2148
+ ) : (t && t.id === -1 && (t.id = s, t.name = i.name), this.setState({
2149
+ ...this.state,
2150
+ currentFilter: t,
2151
+ modalOpen: "modalSaveFilter"
2152
+ }));
2153
+ });
2154
+ },
2155
+ () => {
2156
+ }
2157
+ ));
2158
+ };
2159
+ onChangeFilterType = (e) => {
2160
+ const t = this.state.currentFilter;
2161
+ t.filter.filterType = e === 0 ? ee : se, t.filter.quickFilterFieldsText = A(t, I(this.props)), this.setState({ ...this.state, currentFilter: t, update: Math.random() }), this.props.onFilterChanged && this.props.onFilterChanged(t, this.state.activeFilterIndex);
2162
+ };
2163
+ onChangeSelectedFilter = (e, t) => {
2164
+ this.props.onSelectedFilter && this.props.onSelectedFilter(e, t);
2165
+ const i = localStorage.getItem(`filter${e.id}`);
2166
+ if (i && i !== null) {
2167
+ const r = JSON.parse(i);
2168
+ this.loadListValuesToFilter("root", e.filter.rules, r.filter);
2169
+ }
2170
+ this.setState({
2171
+ ...this.state,
2172
+ currentFilter: e,
2173
+ activeFilterIndex: t
2174
+ });
2175
+ };
2176
+ addNewFilter = () => {
2177
+ const e = D(this.props, ee);
2178
+ this.setState({
2179
+ ...this.state,
2180
+ currentFilter: e,
2181
+ activeFilterIndex: Z
2182
+ }), this.props.onSelectedFilter && this.props.onSelectedFilter(e, Z);
2183
+ };
2184
+ onActionClick = (e) => {
2185
+ e === "new" ? this.addNewFilter() : e === "remove" ? this.removeFilter() : e === "apply" ? this.onSearchClick() : e === "close" && this.onCloseFilterClick();
2186
+ };
2187
+ removeFilter = () => {
2188
+ N.showConfirmDialogYesNo(
2189
+ `${m().t("archbase:Confirme")}`,
2190
+ `${m().t("archbase:Deseja remover o Filtro ?")}`,
2191
+ () => {
2192
+ const e = this.state.currentFilter, t = this.props.persistenceDelegator.getFilterById(e.id);
2193
+ t && this.props.persistenceDelegator.removeFilterBy(t, (i) => {
2194
+ if (i && i !== null)
2195
+ N.showErrorWithDetails(
2196
+ `${m().t("archbase:Warning")}`,
2197
+ he(i),
2198
+ ce(i)
2199
+ );
2200
+ else {
2201
+ const r = this.props.persistenceDelegator.getFirstFilter();
2202
+ if (r) {
2203
+ const s = Y();
2204
+ s.id = r.id, s.name = r.name, s.viewName = r.viewName, s.filter = JSON.parse(r.filter || ""), this.onChangeSelectedFilter(s, 0);
2205
+ } else
2206
+ this.addNewFilter();
2207
+ }
2208
+ });
2209
+ },
2210
+ () => {
2211
+ }
2212
+ );
2213
+ };
2214
+ onCloseFilterClick = () => {
2215
+ this.setState({
2216
+ ...this.state,
2217
+ isOpenSelectRange: !1,
2218
+ selectRangeType: void 0,
2219
+ expandedFilter: !1,
2220
+ isOpenSelectFields: !1
2221
+ }), this.props.onToggleExpandedFilter && this.props.onToggleExpandedFilter(!1);
2222
+ };
2223
+ getPosition = (e, t) => {
2224
+ if (this.divMain) {
2225
+ let i = this.props.detailsWidth;
2226
+ e === "range" ? t === "month" ? i = 260 : i = 510 : e === "fields" && (i = 480);
2227
+ const r = this.divMain.getBoundingClientRect(), { innerHeight: s } = window;
2228
+ let a = r.left;
2229
+ return (this.state.detailsAlign === "right" && e === "filter" || r.left + i > window.innerWidth - 100) && (a = r.right - i), {
2230
+ left: a,
2231
+ top: r.bottom + 2,
2232
+ height: this.props.detailsHeight ? this.props.detailsHeight : s - r.bottom - 30
2233
+ };
2234
+ }
2235
+ return { left: 0, top: 0, height: 0 };
2236
+ };
2237
+ onResize = () => {
2238
+ let e = "filter", t;
2239
+ this.state.isOpenSelectFields ? e = "fields" : this.state.isOpenSelectRange && (e = "range", t = this.state.selectRangeType), this.getPosition(e, t), this.setState({
2240
+ ...this.state
2241
+ });
2242
+ };
2243
+ onSelectRange = (e) => {
2244
+ this.state.isOpenSelectRange ? this.onCancelSelectRange() : (this.getPosition("range", e), this.setState({
2245
+ ...this.state,
2246
+ isOpenSelectRange: !0,
2247
+ selectRangeType: e,
2248
+ expandedFilter: !1,
2249
+ isOpenSelectFields: !1
2250
+ }));
2251
+ };
2252
+ onCancelSelectRange = () => {
2253
+ this.setState({
2254
+ ...this.state,
2255
+ isOpenSelectRange: !1,
2256
+ selectRangeType: void 0,
2257
+ expandedFilter: !1,
2258
+ modalOpen: "",
2259
+ isOpenSelectFields: !1
2260
+ });
2261
+ };
2262
+ onConfirmSelectRange = (e, t) => {
2263
+ let i = "";
2264
+ if (t === "month") {
2265
+ const s = e[0].toString(), a = new Ot({
2266
+ date: Tt(e[1].toDate()),
2267
+ format: "DD/MM/YYYY"
2268
+ }).toString();
2269
+ i = `${s}:${a}`;
2270
+ } else if (t === "range" || t === "week") {
2271
+ const s = e[0].toString(), a = e[1].toString();
2272
+ i = `${s}:${a}`;
2273
+ } else if (t === "day") {
2274
+ let s = !1;
2275
+ i = "", e.forEach((a) => {
2276
+ s && (i += ","), i += a.toString(), s = !0;
2277
+ });
2278
+ }
2279
+ let r = this.state.currentFilter;
2280
+ r && r.filter && r.filter.filterType !== T && (r = D(this.props, T)), r.filter.quickFilterText = i, r.filter.quickFilterFieldsText = A(r, I(this.props)), this.setState(
2281
+ {
2282
+ ...this.state,
2283
+ currentFilter: r,
2284
+ activeFilterIndex: S,
2285
+ selectRangeType: void 0,
2286
+ isOpenSelectRange: !1,
2287
+ isOpenSelectFields: !1,
2288
+ modalOpen: "",
2289
+ expandedFilter: !1
2290
+ },
2291
+ () => {
2292
+ this.props.onFilterChanged && this.props.onFilterChanged(r, S);
2293
+ }
2294
+ );
2295
+ };
2296
+ selectFields = () => {
2297
+ this.state.isOpenSelectFields ? this.onCancelSelectFields() : (this.getPosition("fields"), this.setState({
2298
+ ...this.state,
2299
+ isOpenSelectFields: !0,
2300
+ isOpenSelectRange: !1,
2301
+ expandedFilter: !1
2302
+ }));
2303
+ };
2304
+ onCancelSelectFields = () => {
2305
+ this.setState({
2306
+ ...this.state,
2307
+ isOpenSelectFields: !1,
2308
+ isOpenSelectRange: !1,
2309
+ expandedFilter: !1
2310
+ });
2311
+ };
2312
+ getSortString = (e) => {
2313
+ let t = "", i = !1;
2314
+ return e.sort.sortFields.forEach((r) => {
2315
+ r.selected && (i && (t += ", "), t += `${r.name}:${r.asc_desc}`, i = !0);
2316
+ }), t;
2317
+ };
2318
+ onConfirmSelectFields = (e, t, i) => {
2319
+ let r = this.state.currentFilter;
2320
+ r && r.filter && r.filter.filterType !== T && (r = D(this.props, T)), r.filter.selectedFields = e, r.filter.quickFilterFieldsText = A(r, I(this.props)), r.sort.sortFields = t, r.sort.activeIndex = i, r.sort.quickFilterSort = this.getSortString(r), this.setState(
2321
+ {
2322
+ ...this.state,
2323
+ isOpenSelectFields: !1,
2324
+ isOpenSelectRange: !1,
2325
+ expandedFilter: !1,
2326
+ currentFilter: r,
2327
+ activeFilterIndex: S
2328
+ },
2329
+ () => {
2330
+ this.props.onFilterChanged && this.props.onFilterChanged(r, S);
2331
+ }
2332
+ );
2333
+ };
2334
+ onFocusEdit = () => {
2335
+ this.state.expandedFilter && this.setState(
2336
+ {
2337
+ ...this.state,
2338
+ isOpenSelectFields: !1,
2339
+ isOpenSelectRange: !1,
2340
+ expandedFilter: !1
2341
+ },
2342
+ () => {
2343
+ this.refEdit.current.focus();
2344
+ }
2345
+ );
2346
+ };
2347
+ onClickOk = (e, t) => {
2348
+ if (t && t.length > 0) {
2349
+ let i = "";
2350
+ if (this.state.modalOperator === "notInList" || this.state.modalOperator === "inList") {
2351
+ let r = !1;
2352
+ t.forEach((s) => {
2353
+ r && (i += ","), i += s[this.state.modalSearchField], r = !0;
2354
+ });
2355
+ } else
2356
+ i = t[0][this.state.modalSearchField];
2357
+ this.state.modalHandleOnChange && this.state.modalHandleOnChange(i);
2358
+ }
2359
+ this.setState({
2360
+ ...this.state,
2361
+ modalOpen: "",
2362
+ modalHandleOnChange: void 0,
2363
+ modalOperator: void 0,
2364
+ modalSearchField: ""
2365
+ });
2366
+ };
2367
+ onClickCancel = (e) => {
2368
+ this.setState({
2369
+ ...this.state,
2370
+ modalOpen: "",
2371
+ modalHandleOnChange: void 0,
2372
+ modalOperator: void 0,
2373
+ modalSearchField: ""
2374
+ });
2375
+ };
2376
+ onSearchButtonClick = (e, t, i, r, s) => {
2377
+ this.setState({
2378
+ ...this.state,
2379
+ modalOpen: `modal${e}`,
2380
+ modalHandleOnChange: i,
2381
+ modalOperator: r,
2382
+ modalSearchField: s
2383
+ });
2384
+ };
2385
+ buildSearchModals = () => {
2386
+ const e = I(this.props), t = [];
2387
+ return e.forEach((i) => {
2388
+ if (i.searchComponent && i.searchField) {
2389
+ const r = i.searchComponent;
2390
+ t.push(
2391
+ /* @__PURE__ */ n(
2392
+ r,
2393
+ {
2394
+ isOpen: this.state.modalOpen && this.state.modalOpen === `modal${i.name}`,
2395
+ user: this.props.userName,
2396
+ onClickOk: this.onClickOk,
2397
+ onClickCancel: this.onClickCancel,
2398
+ selectedRecords: []
2399
+ },
2400
+ `modal${i.name}`
2401
+ )
2402
+ );
2403
+ }
2404
+ }), t;
2405
+ };
2406
+ render = () => {
2407
+ let e = "filter", t;
2408
+ this.state.isOpenSelectFields ? e = "fields" : this.state.isOpenSelectRange && (e = "range", t = this.state.selectRangeType), this.getPosition(e, t);
2409
+ let i = "R", r = "#f0ad4e";
2410
+ return this.state.currentFilter.filter.filterType === ee ? (i = "S", r = "#72ac18") : this.state.currentFilter.filter.filterType === se && (i = "A", r = "#007bff"), /* @__PURE__ */ p(
2411
+ "div",
2412
+ {
2413
+ ref: (s) => {
2414
+ this.divMain = s;
2415
+ },
2416
+ style: {
2417
+ minWidth: this.props.width,
2418
+ maxWidth: this.props.width,
2419
+ height: "50px",
2420
+ // backgroundColor:
2421
+ // this.context.colorScheme === 'dark'
2422
+ // ? this.context.theme!.colors.dark[7]
2423
+ // : this.context.theme!.colors.gray[0],
2424
+ position: "relative",
2425
+ // border: `1px solid ${
2426
+ // this.context.colorScheme === 'dark'
2427
+ // ? this.context.theme!.colors.gray[7]
2428
+ // : this.context.theme!.colors.gray[2]
2429
+ // }`,
2430
+ borderRadius: 4,
2431
+ display: "flex",
2432
+ flexFlow: "column nowrap",
2433
+ paddingRight: "8px"
2434
+ },
2435
+ children: [
2436
+ /* @__PURE__ */ p(
2437
+ "div",
2438
+ {
2439
+ style: {
2440
+ padding: 3,
2441
+ width: "100%",
2442
+ height: 50,
2443
+ display: "flex",
2444
+ flexFlow: "row nowrap",
2445
+ alignItems: "center",
2446
+ justifyContent: "center",
2447
+ backgroundColor: "transparent",
2448
+ position: "relative"
2449
+ },
2450
+ children: [
2451
+ /* @__PURE__ */ p("div", { style: { display: "flex", width: "100%" }, children: [
2452
+ /* @__PURE__ */ n(
2453
+ H,
2454
+ {
2455
+ onChange: (s) => this.onChangeQuickFilter(s),
2456
+ innerRef: this.refEdit,
2457
+ onFocus: this.onFocusEdit,
2458
+ onKeyDown: this.handleQuickFilter,
2459
+ initialValue: this.state.currentFilter.filter.quickFilterText,
2460
+ placeholder: this.props.placeholder,
2461
+ style: {
2462
+ height: "36px",
2463
+ paddingLeft: "3px"
2464
+ },
2465
+ label: void 0,
2466
+ error: void 0,
2467
+ keyProp: void 0,
2468
+ readOnly: !1,
2469
+ onActionSearchExecute: void 0,
2470
+ icon: void 0,
2471
+ disabled: !1
2472
+ }
2473
+ ),
2474
+ /* @__PURE__ */ n(
2475
+ "span",
2476
+ {
2477
+ style: {
2478
+ position: "relative",
2479
+ top: "8px",
2480
+ right: "28px",
2481
+ background: r,
2482
+ color: "white",
2483
+ border: "1px solid silver",
2484
+ width: "20px",
2485
+ height: "20px",
2486
+ textAlign: "center",
2487
+ display: "flex",
2488
+ justifyContent: "center",
2489
+ alignItems: "center",
2490
+ borderRadius: "50px"
2491
+ },
2492
+ children: i
2493
+ }
2494
+ )
2495
+ ] }),
2496
+ /* @__PURE__ */ n(f, { withinPortal: !0, withArrow: !0, label: "Filtrar", children: /* @__PURE__ */ n(
2497
+ g,
2498
+ {
2499
+ variant: this.props.variant,
2500
+ size: "lg",
2501
+ color: "var(--mantine-primary-color-filled)",
2502
+ style: { width: "36px", height: "36px", marginRight: 2 },
2503
+ onClick: () => {
2504
+ this.onSearchClick();
2505
+ },
2506
+ children: /* @__PURE__ */ n(ye, { size: "1.4rem" })
2507
+ }
2508
+ ) }),
2509
+ this.props.showClearButton ? /* @__PURE__ */ n(f, { withinPortal: !0, withArrow: !0, label: "Limpar filtro", children: /* @__PURE__ */ n(
2510
+ g,
2511
+ {
2512
+ variant: this.props.variant,
2513
+ size: "lg",
2514
+ color: "var(--mantine-primary-color-filled)",
2515
+ style: { width: "36px", height: "36px", marginRight: 2 },
2516
+ onClick: () => {
2517
+ this.clearFilter();
2518
+ },
2519
+ children: /* @__PURE__ */ n(gt, { size: "1.4rem" })
2520
+ }
2521
+ ) }) : null,
2522
+ /* @__PURE__ */ p(
2523
+ E,
2524
+ {
2525
+ width: this.props.width,
2526
+ position: "bottom-end",
2527
+ withArrow: !0,
2528
+ shadow: "md",
2529
+ onClose: () => this.setState({ ...this.state, modalOpen: "" }),
2530
+ opened: this.state.modalOpen === "selectDate",
2531
+ withinPortal: !0,
2532
+ children: [
2533
+ /* @__PURE__ */ n(E.Target, { children: /* @__PURE__ */ n(f, { withinPortal: !0, withArrow: !0, label: `${m().t("archbase:Selecionar período")}`, children: /* @__PURE__ */ n(
2534
+ g,
2535
+ {
2536
+ variant: this.props.variant,
2537
+ size: "lg",
2538
+ color: "var(--mantine-primary-color-filled)",
2539
+ onClick: () => this.setState({ ...this.state, modalOpen: "selectDate" }),
2540
+ style: { width: "36px", height: "36px", marginRight: 2 },
2541
+ children: /* @__PURE__ */ n(je, { size: "1.4rem" })
2542
+ }
2543
+ ) }) }),
2544
+ /* @__PURE__ */ n(E.Dropdown, { children: /* @__PURE__ */ n(
2545
+ Yt,
2546
+ {
2547
+ selectRangeType: this.state.selectRangeType,
2548
+ onConfirmSelectRange: this.onConfirmSelectRange,
2549
+ onCancelSelectRange: this.onCancelSelectRange,
2550
+ width: `calc(${this.props.width} - 2rem)`,
2551
+ variant: this.props.variant
2552
+ }
2553
+ ) })
2554
+ ]
2555
+ }
2556
+ ),
2557
+ /* @__PURE__ */ p(
2558
+ E,
2559
+ {
2560
+ width: this.props.width,
2561
+ position: "bottom-end",
2562
+ withArrow: !0,
2563
+ shadow: "md",
2564
+ opened: this.state.isOpenSelectFields,
2565
+ onClose: () => this.setState({ ...this.state, isOpenSelectFields: !1 }),
2566
+ withinPortal: !0,
2567
+ children: [
2568
+ /* @__PURE__ */ n(E.Target, { children: /* @__PURE__ */ n(f, { withinPortal: !0, withArrow: !0, label: `${m().t("archbase:Selecionar campos filtro rápido")}`, children: /* @__PURE__ */ n(
2569
+ g,
2570
+ {
2571
+ variant: this.props.variant,
2572
+ size: "lg",
2573
+ color: "var(--mantine-primary-color-filled)",
2574
+ onClick: () => {
2575
+ this.selectFields();
2576
+ },
2577
+ style: { width: "36px", height: "36px", marginRight: 2 },
2578
+ children: /* @__PURE__ */ n(Ft, { size: "1.4rem" })
2579
+ }
2580
+ ) }) }),
2581
+ /* @__PURE__ */ n(E.Dropdown, { children: /* @__PURE__ */ n(
2582
+ Qt,
2583
+ {
2584
+ id: `filrsep${U()}`,
2585
+ currentFilter: this.state.currentFilter,
2586
+ selectedOptions: this.state.currentFilter.filter.selectedFields || [],
2587
+ sort: this.state.currentFilter.sort.sortFields || [],
2588
+ fields: I(this.props),
2589
+ onConfirmSelectFields: this.onConfirmSelectFields,
2590
+ onCancelSelectFields: this.onCancelSelectFields,
2591
+ width: `calc(${this.props.width} - 2rem)`,
2592
+ variant: this.props.variant
2593
+ },
2594
+ `kfilrsep${U()}`
2595
+ ) })
2596
+ ]
2597
+ }
2598
+ ),
2599
+ this.props.showToggleButton ? /* @__PURE__ */ p(
2600
+ E,
2601
+ {
2602
+ width: this.props.detailsWidth,
2603
+ position: "bottom-end",
2604
+ withArrow: !0,
2605
+ shadow: "md",
2606
+ opened: this.state.expandedFilter,
2607
+ zIndex: 199,
2608
+ withinPortal: !0,
2609
+ children: [
2610
+ /* @__PURE__ */ n(E.Target, { children: /* @__PURE__ */ n(f, { withinPortal: !0, withArrow: !0, label: `${m().t("archbase:Filtro avançado")}`, children: /* @__PURE__ */ n(
2611
+ g,
2612
+ {
2613
+ variant: this.props.variant,
2614
+ ref: this.toggleFilterButtonRef,
2615
+ size: "lg",
2616
+ color: "var(--mantine-primary-color-filled)",
2617
+ onClick: () => {
2618
+ this.toggleExpandedFilter();
2619
+ },
2620
+ style: { width: "36px", height: "36px", marginRight: 2 },
2621
+ children: /* @__PURE__ */ n(bt, { size: "1.4rem" })
2622
+ }
2623
+ ) }) }),
2624
+ /* @__PURE__ */ n(E.Dropdown, { children: /* @__PURE__ */ n(
2625
+ Wt,
2626
+ {
2627
+ update: this.state.update,
2628
+ currentFilter: this.state.currentFilter,
2629
+ activeFilterIndex: this.state.activeFilterIndex,
2630
+ persistenceDelegator: this.props.persistenceDelegator,
2631
+ onFilterChanged: (s, a) => this.onFilterChanged(s, a, () => {
2632
+ }),
2633
+ onSaveFilter: this.onSaveFilter,
2634
+ onActionClick: this.onActionClick,
2635
+ onChangeFilterType: this.onChangeFilterType,
2636
+ onChangeSelectedFilter: this.onChangeSelectedFilter,
2637
+ onSearchButtonClick: this.onSearchButtonClick,
2638
+ width: `calc(${this.props.detailsWidth}px - 2rem)`,
2639
+ height: `calc(${this.props.detailsHeight}px - 2rem)`,
2640
+ toggleFilterButtonRef: this.toggleFilterButtonRef,
2641
+ variant: this.props.variant,
2642
+ children: this.props.children
2643
+ }
2644
+ ) })
2645
+ ]
2646
+ }
2647
+ ) : null,
2648
+ this.props.showExportButton ? /* @__PURE__ */ n(f, { withinPortal: !0, withArrow: !0, label: "Exportar", children: /* @__PURE__ */ n(
2649
+ g,
2650
+ {
2651
+ variant: this.props.variant,
2652
+ size: "lg",
2653
+ color: "var(--mantine-primary-color-filled)",
2654
+ style: { width: "36px", height: "36px", marginRight: 2 },
2655
+ onClick: () => {
2656
+ this.props.onExport && this.props.onExport();
2657
+ },
2658
+ children: /* @__PURE__ */ n(Ct, { size: "1.4rem" })
2659
+ }
2660
+ ) }) : null,
2661
+ this.props.showPrintButton ? /* @__PURE__ */ n(f, { withinPortal: !0, withArrow: !0, label: "Imprimir", children: /* @__PURE__ */ n(
2662
+ g,
2663
+ {
2664
+ variant: this.props.variant,
2665
+ size: "lg",
2666
+ color: "var(--mantine-primary-color-filled)",
2667
+ style: { width: "36px", height: "36px", marginRight: 2 },
2668
+ onClick: () => {
2669
+ this.props.onPrint && this.props.onPrint();
2670
+ },
2671
+ children: /* @__PURE__ */ n(vt, { size: "1.4rem" })
2672
+ }
2673
+ ) }) : null
2674
+ ]
2675
+ }
2676
+ ),
2677
+ this.buildSearchModals()
2678
+ ]
2679
+ }
2680
+ );
2681
+ };
2682
+ }
2683
+ class Ht extends v {
2684
+ static defaultProps = {
2685
+ operators: [
2686
+ {
2687
+ name: "null",
2688
+ label: "Em branco",
2689
+ dataTypes: ["string", "number", "date", "date_time", "time", "boolean"]
2690
+ },
2691
+ {
2692
+ name: "notNull",
2693
+ label: "Preenchido",
2694
+ dataTypes: ["string", "number", "date", "date_time", "time", "boolean"]
2695
+ },
2696
+ {
2697
+ name: "contains",
2698
+ label: "Contém",
2699
+ dataTypes: ["string"]
2700
+ },
2701
+ {
2702
+ name: "startsWith",
2703
+ label: "Iniciado com",
2704
+ dataTypes: ["string"]
2705
+ },
2706
+ {
2707
+ name: "endsWith",
2708
+ label: "Terminado com",
2709
+ dataTypes: ["string"]
2710
+ },
2711
+ {
2712
+ name: "=",
2713
+ label: "Igual",
2714
+ dataTypes: ["string", "number", "date", "date_time", "time", "boolean"]
2715
+ },
2716
+ {
2717
+ name: "!=",
2718
+ label: "Diferente",
2719
+ dataTypes: ["string", "number", "date", "date_time", "time", "boolean"]
2720
+ },
2721
+ {
2722
+ name: "<",
2723
+ label: "Menor",
2724
+ dataTypes: ["string", "number", "date", "date_time", "time"]
2725
+ },
2726
+ {
2727
+ name: ">",
2728
+ label: "Maior",
2729
+ dataTypes: ["string", "number", "date", "date_time", "time"]
2730
+ },
2731
+ {
2732
+ name: "<=",
2733
+ label: "Menor igual",
2734
+ dataTypes: ["string", "number", "date", "date_time", "time"]
2735
+ },
2736
+ {
2737
+ name: ">=",
2738
+ label: "Maior igual",
2739
+ dataTypes: ["string", "number", "date", "date_time", "time"]
2740
+ },
2741
+ {
2742
+ name: "between",
2743
+ label: "Entre",
2744
+ dataTypes: ["string", "number", "date", "date_time", "time"]
2745
+ },
2746
+ {
2747
+ name: "inList",
2748
+ label: "Na lista",
2749
+ dataTypes: ["string", "number", "date", "time"]
2750
+ },
2751
+ {
2752
+ name: "notInList",
2753
+ label: "Fora da lista",
2754
+ dataTypes: ["string", "number", "date", "time"]
2755
+ }
2756
+ ],
2757
+ conditions: [
2758
+ {
2759
+ name: "and",
2760
+ label: "E"
2761
+ },
2762
+ {
2763
+ name: "or",
2764
+ label: "Ou"
2765
+ }
2766
+ ],
2767
+ getOperators: null,
2768
+ onFilterChanged: null,
2769
+ allowSort: !0,
2770
+ disabled: !1,
2771
+ horizontal: !0,
2772
+ sortFocused: "",
2773
+ width: "100%",
2774
+ border: "1px solid silver"
2775
+ };
2776
+ constructor(e) {
2777
+ super(e), this.state = {
2778
+ modalOpen: "",
2779
+ currentFilter: e.currentFilter ? e.currentFilter : Y(),
2780
+ activeFilterIndex: e.currentFilter ? e.activeFilterIndex : -1,
2781
+ schema: this.createSchema(),
2782
+ // 🔄 MIGRAÇÃO V1/V2: Inicializar contador de forceUpdate
2783
+ forceUpdateCounter: 0
2784
+ };
2785
+ }
2786
+ shouldComponentUpdate = (e, t) => oe(this, e, t);
2787
+ // 🔄 MIGRAÇÃO V1/V2: Helper para criar DataSource com compatibilidade
2788
+ createCompatibleDataSource = (e) => {
2789
+ const t = new j("dsSortFields", {
2790
+ records: e,
2791
+ grandTotalRecords: e.length,
2792
+ currentPage: 0,
2793
+ totalPages: 0,
2794
+ pageSize: 999999
2795
+ });
2796
+ return Q(t) !== "V2" && this.setState({
2797
+ ...this.state,
2798
+ forceUpdateCounter: this.state.forceUpdateCounter + 1
2799
+ }), t;
2800
+ };
2801
+ getQuickFields = () => {
2802
+ let e = [];
2803
+ return this.getFields(this.props).forEach(function(t) {
2804
+ t.quickFilter === !0 && e.push({ name: t.name, label: t.label });
2805
+ }, this), e;
2806
+ };
2807
+ getQuickFilterSort = () => {
2808
+ let e = "", t = !1;
2809
+ return this.getFields(this.props).forEach(function(i) {
2810
+ i.quickFilterSort === !0 && (t && (e += ","), e += i.name, t = !0);
2811
+ }, this), e;
2812
+ };
2813
+ UNSAFE_componentWillReceiveProps = (e) => {
2814
+ let t = e.currentFilter, i = e.activeFilterIndex;
2815
+ (!t || !t.hasOwnProperty("filter")) && (t = D(e, se), i = -1), this.setState({
2816
+ ...this.state,
2817
+ currentFilter: t,
2818
+ activeFilterIndex: i
2819
+ });
2820
+ };
2821
+ createRuleGroup = () => ({
2822
+ id: `g-${U()}`,
2823
+ rules: [],
2824
+ condition: this.props.conditions[0].name
2825
+ });
2826
+ createSchema = () => {
2827
+ const { operators: e, conditions: t } = this.props;
2828
+ return {
2829
+ fields: this.getFields(this.props),
2830
+ operators: e,
2831
+ conditions: t,
2832
+ createRule: this.createRule.bind(this),
2833
+ createRuleGroup: this.createRuleGroup.bind(this),
2834
+ onRuleAdd: this._notifyQueryChange.bind(this, this.onRuleAdd),
2835
+ onGroupAdd: this._notifyQueryChange.bind(this, this.onGroupAdd),
2836
+ onRuleRemove: this._notifyQueryChange.bind(this, this.onRuleRemove),
2837
+ onGroupRemove: this._notifyQueryChange.bind(this, this.onGroupRemove),
2838
+ onPropChange: this._notifyQueryChange.bind(this, this.onPropChange),
2839
+ getLevel: this.getLevel.bind(this),
2840
+ isRuleGroup: this.isRuleGroup.bind(this),
2841
+ getOperators: (i) => this.getOperators(i)
2842
+ };
2843
+ };
2844
+ getSelectedSort = () => {
2845
+ let e = [];
2846
+ return this.state.currentFilter && this.state.currentFilter.sort.sortFields.forEach(function(t) {
2847
+ t.selected && e.push({ name: t.name, asc_desc: t.asc_desc });
2848
+ }), e;
2849
+ };
2850
+ getSortItem = (e) => {
2851
+ let t;
2852
+ return this.state.currentFilter && this.state.currentFilter.sort.sortFields.forEach(function(i) {
2853
+ i.name === e && (t = i);
2854
+ }), t;
2855
+ };
2856
+ getSortItemByOrder = (e) => {
2857
+ let t;
2858
+ return this.state.currentFilter && this.state.currentFilter.sort.sortFields.forEach(function(i) {
2859
+ i.order === e && (t = i);
2860
+ }), t;
2861
+ };
2862
+ onChangeSortItem = (e, t, i, r) => {
2863
+ if (this.state.currentFilter) {
2864
+ let s = this.getSortItem(e);
2865
+ if (s) {
2866
+ Object.assign(s, {
2867
+ selected: t,
2868
+ order: i,
2869
+ asc_desc: r,
2870
+ label: s.label
2871
+ });
2872
+ let a = this.state.currentFilter.sort.sortFields;
2873
+ a = a.sort(function(h, o) {
2874
+ return h.order - o.order;
2875
+ });
2876
+ let l = this.state.currentFilter;
2877
+ l.sort.sortFields = a, this.setState({
2878
+ ...this.state,
2879
+ currentFilter: l
2880
+ }), this.propagateFilterChanged();
2881
+ }
2882
+ }
2883
+ };
2884
+ propagateFilterChanged = () => {
2885
+ const { onFilterChanged: e } = this.props;
2886
+ e && e(this.state.currentFilter, this.state.activeFilterIndex);
2887
+ };
2888
+ onSortDown = (e) => {
2889
+ if (this.state.currentFilter) {
2890
+ let t = this.state.currentFilter.sort.activeIndex;
2891
+ if (t >= 0) {
2892
+ let i = this.state.currentFilter.sort.sortFields[t];
2893
+ if (i.order < this.state.currentFilter.sort.sortFields.length - 1) {
2894
+ t = i.order + 1;
2895
+ let a = this.getSortItemByOrder(i.order + 1);
2896
+ a && (Object.assign(i, {
2897
+ order: i.order + 1
2898
+ }), Object.assign(a, {
2899
+ order: a.order - 1
2900
+ }));
2901
+ }
2902
+ let r = this.state.currentFilter.sort.sortFields;
2903
+ r = r.sort((a, l) => a.order - l.order);
2904
+ let s = this.state.currentFilter;
2905
+ s.sort.sortFields = r, s.sort.activeIndex = t, this.setState(
2906
+ {
2907
+ ...this.state,
2908
+ currentFilter: s
2909
+ },
2910
+ () => {
2911
+ this.propagateFilterChanged();
2912
+ }
2913
+ );
2914
+ }
2915
+ }
2916
+ };
2917
+ onSortUp = (e) => {
2918
+ if (this.state.currentFilter) {
2919
+ const { currentFilter: t } = this.state;
2920
+ let i = t.sort.activeIndex;
2921
+ if (i >= 0) {
2922
+ const r = t.sort.sortFields[i];
2923
+ if (r.order > 0) {
2924
+ i = r.order - 1;
2925
+ let a = this.getSortItemByOrder(r.order - 1);
2926
+ a && (Object.assign(r, {
2927
+ order: r.order - 1
2928
+ }), Object.assign(a, {
2929
+ order: a.order + 1
2930
+ }));
2931
+ }
2932
+ let s = t.sort.sortFields;
2933
+ s = s.sort(function(a, l) {
2934
+ return a.order - l.order;
2935
+ }), t.sort.sortFields = s, t.sort.activeIndex = i, this.setState(
2936
+ {
2937
+ ...this.state,
2938
+ currentFilter: t
2939
+ },
2940
+ () => {
2941
+ this.propagateFilterChanged();
2942
+ }
2943
+ );
2944
+ }
2945
+ }
2946
+ };
2947
+ getFields = (e) => {
2948
+ let t = [];
2949
+ return e.children && y.Children.toArray(e.children).forEach((r) => {
2950
+ r.type && r.type.componentName === "FilterFields" && r.props.children && y.Children.toArray(r.props.children).forEach((a) => {
2951
+ if (a.type && a.type.componentName !== "FilterField")
2952
+ throw new te(
2953
+ "Somente filhos do tipo FilterField podem ser usados com FilterFields."
2954
+ );
2955
+ let l = [];
2956
+ y.Children.toArray(a.props.children).forEach((o) => {
2957
+ if (o.type && o.type.componentName !== "FilterFieldValue")
2958
+ throw new te(
2959
+ "Somente filhos do tipo FilterFieldValue podem ser usados com FilterFields"
2960
+ );
2961
+ l.push({ label: o.props.label, value: o.props.value });
2962
+ }), t.push({
2963
+ name: a.props.name,
2964
+ label: a.props.label,
2965
+ dataType: a.props.dataType,
2966
+ quickFilter: a.props.quickFilter,
2967
+ quickFilterSort: a.props.quickFilterSort,
2968
+ sortable: a.props.sortable,
2969
+ listValues: l,
2970
+ operator: "",
2971
+ searchComponent: void 0,
2972
+ searchField: void 0
2973
+ });
2974
+ });
2975
+ }), t;
2976
+ };
2977
+ isRuleGroup = (e) => !!(e.condition && e.rules);
2978
+ createRule = () => {
2979
+ const { operators: e } = this.state.schema, t = this.getFields(this.props);
2980
+ return {
2981
+ id: `r-${U()}`,
2982
+ field: t[0].name,
2983
+ fieldSql: t[0].nameSql,
2984
+ dataType: t[0].dataType,
2985
+ value: "",
2986
+ value2: "",
2987
+ disabled: !1,
2988
+ operator: e[0].name
2989
+ };
2990
+ };
2991
+ getField = (e) => {
2992
+ let t;
2993
+ return this.getFields(this.props).forEach(function(i) {
2994
+ i.name === e && (t = i);
2995
+ }, this), t;
2996
+ };
2997
+ getOperators = (e) => {
2998
+ let t = this.getField(e), i = [];
2999
+ return this.props.operators.forEach((r) => {
3000
+ r.dataTypes.indexOf(t.dataType) >= 0 && i.push(r);
3001
+ }, this), i;
3002
+ };
3003
+ onRuleAdd = (e, t) => {
3004
+ let i = this.state.currentFilter;
3005
+ if (i) {
3006
+ const r = this._findRule(t, i.filter);
3007
+ r && r.rules.push(e), this.setState({ ...this.state, currentFilter: i });
3008
+ }
3009
+ };
3010
+ onGroupAdd = (e, t) => {
3011
+ let i = this.state.currentFilter;
3012
+ if (i) {
3013
+ const r = this._findRule(t, i.filter);
3014
+ r && r.rules.push(e), this.setState({ ...this.state, currentFilter: i });
3015
+ }
3016
+ };
3017
+ onPropChange = (e, t, i) => {
3018
+ let r = this.state.currentFilter;
3019
+ if (r) {
3020
+ const s = this._findRule(i, r.filter);
3021
+ s && (e === "not" ? (e = "condition", s.condition.indexOf("and") >= 0 ? t = ie(t + " and") : t = ie(t + " or")) : e === "condition" && s.condition.indexOf("not") >= 0 && (t = "not " + t), Object.assign(s, { [e]: t }), this.setState({ ...this.state, currentFilter: r }));
3022
+ }
3023
+ };
3024
+ onRuleRemove = (e, t) => {
3025
+ let i = this.state.currentFilter;
3026
+ if (i) {
3027
+ const r = this._findRule(t, i.filter);
3028
+ if (r) {
3029
+ const s = r.rules.findIndex((a) => a.id === e);
3030
+ r.rules.splice(s, 1), this.setState({ ...this.state, currentFilter: i });
3031
+ }
3032
+ }
3033
+ };
3034
+ onGroupRemove = (e, t) => {
3035
+ let i = this.state.currentFilter;
3036
+ if (i) {
3037
+ const r = this._findRule(t, i.filter);
3038
+ if (r) {
3039
+ const s = r.rules.findIndex((a) => a.id === e);
3040
+ r.rules.splice(s, 1);
3041
+ }
3042
+ this.setState({ ...this.state, currentFilter: i });
3043
+ }
3044
+ };
3045
+ getLevel = (e) => this._getLevel(e, 0, this.state.currentFilter.filter);
3046
+ _getLevel = (e, t, i) => {
3047
+ const { isRuleGroup: r } = this.state.schema;
3048
+ var s = -1;
3049
+ return i.id === e ? s = t : r(i) && i.rules.forEach((a) => {
3050
+ if (s === -1) {
3051
+ var l = t;
3052
+ r(a) && l++, s = this._getLevel(e, l, a);
3053
+ }
3054
+ }), s;
3055
+ };
3056
+ _findRule = (e, t) => {
3057
+ const { isRuleGroup: i } = this.state.schema;
3058
+ if (t.id === e)
3059
+ return t;
3060
+ for (const r of t.rules) {
3061
+ if (r.id === e)
3062
+ return r;
3063
+ if (i(r)) {
3064
+ const s = this._findRule(e, r);
3065
+ if (s)
3066
+ return s;
3067
+ }
3068
+ }
3069
+ };
3070
+ _notifyQueryChange = (e, ...t) => {
3071
+ e && e.call(this, ...t);
3072
+ const { onFilterChanged: i } = this.props;
3073
+ i && i(this.state.currentFilter, this.state.activeFilterIndex);
3074
+ };
3075
+ onSelectListItem = (e, t) => {
3076
+ let i = this.state.currentFilter;
3077
+ i && (i.sort.activeIndex = e, this.setState({ ...this.state, currentFilter: i }), this.props.onFilterChanged && this.props.onFilterChanged(i, this.state.activeFilterIndex));
3078
+ };
3079
+ render() {
3080
+ return /* @__PURE__ */ p(
3081
+ "div",
3082
+ {
3083
+ style: {
3084
+ height: this.props.height,
3085
+ overflowY: "hidden",
3086
+ overflowX: "hidden"
3087
+ },
3088
+ children: [
3089
+ /* @__PURE__ */ n("div", { style: { width: this.props.width, overflow: "hidden" }, children: /* @__PURE__ */ n(O, { children: /* @__PURE__ */ n(O.Col, { span: 12, children: /* @__PURE__ */ n(
3090
+ xe,
3091
+ {
3092
+ rules: this.state.currentFilter.filter.rules,
3093
+ condition: this.state.currentFilter.filter.condition,
3094
+ schema: this.state.schema,
3095
+ id: this.state.currentFilter.filter.id,
3096
+ onSearchButtonClick: this.props.onSearchButtonClick,
3097
+ parentId: null,
3098
+ variant: this.props.variant
3099
+ }
3100
+ ) }) }) }),
3101
+ this.props.allowSort === !0 ? /* @__PURE__ */ n(O, { children: /* @__PURE__ */ n(O.Col, { span: 12, style: { padding: 13 }, children: /* @__PURE__ */ n(
3102
+ "div",
3103
+ {
3104
+ style: {
3105
+ height: "auto"
3106
+ },
3107
+ children: /* @__PURE__ */ p(re, { withBorder: !0, shadow: "sm", radius: "md", children: [
3108
+ /* @__PURE__ */ n(re.Section, { withBorder: !0, inheritPadding: !0, py: "xs", children: /* @__PURE__ */ p(q, { children: [
3109
+ /* @__PURE__ */ n(f, { withinPortal: !0, withArrow: !0, label: "Para baixo", children: /* @__PURE__ */ n(g, { id: "btnFilterSortDown", onClick: this.onSortDown, children: /* @__PURE__ */ n(ve, {}) }) }),
3110
+ /* @__PURE__ */ n(f, { withinPortal: !0, withArrow: !0, label: "Para cima", children: /* @__PURE__ */ n(g, { id: "btnFilterSortUp", onClick: this.onSortUp, children: /* @__PURE__ */ n(Se, {}) }) }),
3111
+ /* @__PURE__ */ n(x, { children: "Ordenação" }),
3112
+ /* @__PURE__ */ n(R, { w: "md" }),
3113
+ /* @__PURE__ */ n(
3114
+ x,
3115
+ {
3116
+ truncate: !0,
3117
+ color: "blue",
3118
+ style: {
3119
+ fontWeight: "bold",
3120
+ wordBreak: "break-word",
3121
+ display: "block",
3122
+ wordWrap: "break-word",
3123
+ whiteSpace: "normal",
3124
+ fontSize: "12px"
3125
+ },
3126
+ children: Xe(this.state.currentFilter)
3127
+ },
3128
+ "txto_9899"
3129
+ )
3130
+ ] }) }),
3131
+ /* @__PURE__ */ n(
3132
+ de,
3133
+ {
3134
+ height: "100%",
3135
+ width: "100%",
3136
+ withBorder: !1,
3137
+ dataSource: (
3138
+ // 🔄 MIGRAÇÃO V1/V2: Usar método de compatibilidade
3139
+ this.createCompatibleDataSource(this.state.currentFilter.sort.sortFields)
3140
+ ),
3141
+ dataFieldId: "name",
3142
+ dataFieldText: "name",
3143
+ activeIndex: this.state.currentFilter.sort.activeIndex,
3144
+ component: {
3145
+ type: we,
3146
+ props: {
3147
+ sortFocused: this.state.sortFocused,
3148
+ onChangeSortItem: this.onChangeSortItem,
3149
+ onSelectListItem: this.onSelectListItem
3150
+ }
3151
+ }
3152
+ }
3153
+ )
3154
+ ] })
3155
+ }
3156
+ ) }) }) : null
3157
+ ]
3158
+ }
3159
+ );
3160
+ }
3161
+ }
3162
+ class we extends v {
3163
+ static defaultProps = {
3164
+ disabled: !1,
3165
+ active: !0,
3166
+ selected: !1
3167
+ };
3168
+ // declare context: React.ContextType<typeof ArchbaseListContext>
3169
+ constructor(e) {
3170
+ super(e), this.state = { update: Math.random(), selected: e.recordData.selected };
3171
+ }
3172
+ static get componentName() {
3173
+ return "CustomSortItem";
3174
+ }
3175
+ UNSAFE_componentWillReceiveProps = (e) => {
3176
+ this.setState({
3177
+ update: Math.random(),
3178
+ selected: e.recordData.selected
3179
+ });
3180
+ };
3181
+ onClick = (e) => {
3182
+ e.preventDefault(), this.props.disabled || this.props.onSelectListItem && this.props.onSelectListItem(this.props.index, this);
3183
+ };
3184
+ onCheckboxChange = (e) => {
3185
+ let t = this.props.recordData[this.props.dataFieldId];
3186
+ const i = e.currentTarget.checked;
3187
+ this.setState({ ...this.state, selected: i }, () => {
3188
+ this.props.onChangeSortItem(
3189
+ t,
3190
+ i,
3191
+ this.props.recordData.order,
3192
+ this.isAsc() ? "asc" : "desc"
3193
+ );
3194
+ });
3195
+ };
3196
+ onDoubleClick = (e) => {
3197
+ let t = this.props.recordData[this.props.dataFieldId];
3198
+ this.props.onChangeSortItem(
3199
+ t,
3200
+ this.state.selected,
3201
+ this.props.recordData.order,
3202
+ this.isAsc() ? "desc" : "asc"
3203
+ );
3204
+ };
3205
+ isAsc = () => {
3206
+ let e = this.props.recordData[this.props.dataFieldId], t = !0;
3207
+ return this.props.dataSource.browseRecords().forEach((i) => {
3208
+ i.name === e && (t = !i.asc_desc || i.asc_desc === "asc");
3209
+ }), t;
3210
+ };
3211
+ render = () => {
3212
+ let e = this.props.id;
3213
+ const t = "black", i = "black";
3214
+ return /* @__PURE__ */ p(
3215
+ "li",
3216
+ {
3217
+ style: {
3218
+ height: "30px",
3219
+ padding: "0px 15px",
3220
+ display: "flex",
3221
+ color: i,
3222
+ backgroundColor: t,
3223
+ alignItems: "center"
3224
+ },
3225
+ onClick: this.onClick,
3226
+ children: [
3227
+ /* @__PURE__ */ n(
3228
+ W,
3229
+ {
3230
+ label: /* @__PURE__ */ n(x, { color: i, children: m().t(this.props.recordData.label) }),
3231
+ checked: this.state.selected,
3232
+ style: { cursor: "pointer" },
3233
+ onChange: this.onCheckboxChange
3234
+ }
3235
+ ),
3236
+ /* @__PURE__ */ p("div", { style: { height: "100%", display: "flex", alignItems: "center" }, children: [
3237
+ /* @__PURE__ */ n(R, { w: "md" }),
3238
+ this.isAsc() ? /* @__PURE__ */ n(
3239
+ St,
3240
+ {
3241
+ style: { cursor: "pointer" },
3242
+ onDoubleClick: this.onDoubleClick
3243
+ }
3244
+ ) : /* @__PURE__ */ n(
3245
+ yt,
3246
+ {
3247
+ style: { cursor: "pointer" },
3248
+ onDoubleClick: this.onDoubleClick
3249
+ }
3250
+ )
3251
+ ] })
3252
+ ]
3253
+ },
3254
+ e
3255
+ );
3256
+ };
3257
+ }
3258
+ class xe extends v {
3259
+ static defaultProps = {
3260
+ id: null,
3261
+ parentId: null,
3262
+ rules: [],
3263
+ condition: "and",
3264
+ schema: {}
3265
+ };
3266
+ // static contextType = ArchbaseAppContext
3267
+ // declare context: React.ContextType<typeof ArchbaseAppContext>
3268
+ constructor(e) {
3269
+ super(e), this.hasParentGroup = this.hasParentGroup.bind(this), this.onConditionChange = this.onConditionChange.bind(this), this.onNotConditionChange = this.onNotConditionChange.bind(this), this.addRule = this.addRule.bind(this), this.addGroup = this.addGroup.bind(this), this.removeGroup = this.removeGroup.bind(this);
3270
+ }
3271
+ static get componentName() {
3272
+ return "RuleGroupItem";
3273
+ }
3274
+ getColor = (e) => "black";
3275
+ render = () => {
3276
+ const {
3277
+ height: e,
3278
+ condition: t,
3279
+ rules: i,
3280
+ onSearchButtonClick: r,
3281
+ schema: { isRuleGroup: s, getLevel: a }
3282
+ } = this.props, l = a(this.props.id);
3283
+ return /* @__PURE__ */ p(
3284
+ "dl",
3285
+ {
3286
+ className: "rules-group-container",
3287
+ style: {
3288
+ height: e,
3289
+ overflowX: e !== void 0 ? "auto" : "hidden"
3290
+ },
3291
+ children: [
3292
+ /* @__PURE__ */ n("dt", { className: "rules-group-header", children: /* @__PURE__ */ p(
3293
+ "div",
3294
+ {
3295
+ style: {
3296
+ display: "flex"
3297
+ },
3298
+ children: [
3299
+ /* @__PURE__ */ n(
3300
+ qe,
3301
+ {
3302
+ size: "md",
3303
+ color: "teal",
3304
+ onLabel: /* @__PURE__ */ n(x, { fz: "sm", children: "E" }),
3305
+ offLabel: /* @__PURE__ */ n(x, { fz: "sm", children: "OU" }),
3306
+ onChange: (h) => this.onConditionChange(h.currentTarget.checked ? 0 : 1),
3307
+ checked: t === "and"
3308
+ }
3309
+ ),
3310
+ /* @__PURE__ */ n(R, { w: "md" }),
3311
+ /* @__PURE__ */ p(w.Group, { children: [
3312
+ /* @__PURE__ */ n(
3313
+ fe,
3314
+ {
3315
+ label: "Condição",
3316
+ style: {},
3317
+ handleOnClick: this.addRule,
3318
+ rules: i,
3319
+ level: l,
3320
+ variant: this.props.variant
3321
+ }
3322
+ ),
3323
+ /* @__PURE__ */ n(
3324
+ fe,
3325
+ {
3326
+ label: "Grupo",
3327
+ handleOnClick: this.addGroup,
3328
+ rules: i,
3329
+ level: l,
3330
+ variant: this.props.variant
3331
+ }
3332
+ ),
3333
+ " ",
3334
+ this.hasParentGroup() ? /* @__PURE__ */ n(
3335
+ fe,
3336
+ {
3337
+ label: "Remover",
3338
+ color: "red",
3339
+ handleOnClick: this.removeGroup,
3340
+ rules: i,
3341
+ level: l,
3342
+ variant: this.props.variant
3343
+ }
3344
+ ) : null
3345
+ ] })
3346
+ ]
3347
+ }
3348
+ ) }),
3349
+ /* @__PURE__ */ n("dd", { className: "rules-group-body", children: /* @__PURE__ */ n("ul", { className: "rules-list", children: i && i.map((h) => s(h) ? /* @__PURE__ */ n(
3350
+ xe,
3351
+ {
3352
+ id: h.id,
3353
+ schema: this.props.schema,
3354
+ parentId: this.props.id,
3355
+ condition: h.condition,
3356
+ onSearchButtonClick: r,
3357
+ rules: h.rules
3358
+ },
3359
+ h.id
3360
+ ) : /* @__PURE__ */ n(
3361
+ Jt,
3362
+ {
3363
+ id: h.id,
3364
+ field: h.field,
3365
+ value: h.value,
3366
+ value2: h.value2,
3367
+ operator: h.operator,
3368
+ disabled: h.disabled,
3369
+ schema: this.props.schema,
3370
+ onSearchButtonClick: r,
3371
+ parentId: this.props.id
3372
+ },
3373
+ h.id
3374
+ )) }) })
3375
+ ]
3376
+ }
3377
+ );
3378
+ };
3379
+ hasParentGroup() {
3380
+ return this.props.parentId;
3381
+ }
3382
+ onConditionChange(e) {
3383
+ const { onPropChange: t } = this.props.schema;
3384
+ t("condition", e === 0 ? "and" : "or", this.props.id);
3385
+ }
3386
+ onNotConditionChange(e, t) {
3387
+ const { onPropChange: i } = this.props.schema;
3388
+ i("not", e === !0 ? "not" : "", this.props.id);
3389
+ }
3390
+ addRule(e) {
3391
+ e.preventDefault(), e.stopPropagation();
3392
+ const { createRule: t, onRuleAdd: i } = this.props.schema, r = t();
3393
+ i(r, this.props.id);
3394
+ }
3395
+ addGroup(e) {
3396
+ e.preventDefault(), e.stopPropagation();
3397
+ const { createRuleGroup: t, onGroupAdd: i } = this.props.schema, r = t();
3398
+ i(r, this.props.id);
3399
+ }
3400
+ removeGroup(e) {
3401
+ e.preventDefault(), e.stopPropagation(), this.props.schema.onGroupRemove(this.props.id, this.props.parentId);
3402
+ }
3403
+ }
3404
+ class Jt extends v {
3405
+ static defaultProps = {
3406
+ id: null,
3407
+ parentId: null,
3408
+ field: null,
3409
+ operator: null,
3410
+ value: null,
3411
+ value2: null,
3412
+ disabled: !1
3413
+ };
3414
+ // static contextType = ArchbaseAppContext
3415
+ // declare context: React.ContextType<typeof ArchbaseAppContext>
3416
+ constructor(e) {
3417
+ super(e);
3418
+ }
3419
+ static get componentName() {
3420
+ return "Rule";
3421
+ }
3422
+ getDataType = (e, t) => {
3423
+ for (var i = 0; i < t.length; i++)
3424
+ if (t[i].name === e)
3425
+ return t[i].dataType;
3426
+ };
3427
+ getSearchField = (e, t) => {
3428
+ for (var i = 0; i < t.length; i++)
3429
+ if (t[i].name === e)
3430
+ return t[i].dataType;
3431
+ };
3432
+ getFieldSql = (e, t) => {
3433
+ for (var i = 0; i < t.length; i++)
3434
+ if (t[i].name === e)
3435
+ return t[i].nameSql;
3436
+ };
3437
+ getFieldValues = (e, t) => {
3438
+ for (var i = 0; i < t.length; i++)
3439
+ if (t[i].name === e)
3440
+ return t[i].listValues;
3441
+ };
3442
+ render = () => {
3443
+ const {
3444
+ field: e,
3445
+ disabled: t,
3446
+ operator: i,
3447
+ value: r,
3448
+ value2: s,
3449
+ onSearchButtonClick: a,
3450
+ schema: { fields: l, getOperators: h, getLevel: o }
3451
+ } = this.props;
3452
+ let c = this.getDataType(e, l), u = this.getSearchField(e, l), F = i === "between" && c !== "date" && c !== "date_time" && c !== "time";
3453
+ var b = o(this.props.id);
3454
+ let k = this.getFieldValues(e, l);
3455
+ const { colorScheme: P } = We();
3456
+ return /* @__PURE__ */ p("li", { className: "rule-container", children: [
3457
+ /* @__PURE__ */ n(
3458
+ W,
3459
+ {
3460
+ label: "",
3461
+ checked: !t,
3462
+ style: { cursor: "pointer" },
3463
+ onChange: (L) => this.onDisabledChanged(L.currentTarget.checked)
3464
+ }
3465
+ ),
3466
+ /* @__PURE__ */ n(
3467
+ Le,
3468
+ {
3469
+ options: l,
3470
+ value: e,
3471
+ className: "custom-select-field",
3472
+ disabled: t,
3473
+ handleOnChange: this.onFieldChanged,
3474
+ level: b,
3475
+ field: ""
3476
+ }
3477
+ ),
3478
+ /* @__PURE__ */ n(
3479
+ Le,
3480
+ {
3481
+ field: e,
3482
+ options: h(e),
3483
+ value: i,
3484
+ className: "custom-select-operator",
3485
+ disabled: t,
3486
+ handleOnChange: this.onOperatorChanged,
3487
+ level: b
3488
+ }
3489
+ ),
3490
+ /* @__PURE__ */ n(
3491
+ Pe,
3492
+ {
3493
+ field: e,
3494
+ dataType: c,
3495
+ operator: i,
3496
+ value: r,
3497
+ value2: s,
3498
+ listValues: k,
3499
+ disabled: t,
3500
+ searchField: u,
3501
+ className: "rule-value",
3502
+ handleOnChange: this.onValueChanged,
3503
+ onSearchButtonClick: a,
3504
+ level: b,
3505
+ twoFields: F
3506
+ }
3507
+ ),
3508
+ " ",
3509
+ i === "between" && c !== "date" && c !== "date_time" && c !== "time" ? /* @__PURE__ */ n(
3510
+ Pe,
3511
+ {
3512
+ field: e,
3513
+ dataType: c,
3514
+ operator: i,
3515
+ value: s,
3516
+ listValues: k,
3517
+ disabled: t,
3518
+ searchField: u,
3519
+ className: "rule-value",
3520
+ handleOnChange: this.onValue2Changed,
3521
+ onSearchButtonClick: a,
3522
+ level: b,
3523
+ twoFields: F
3524
+ }
3525
+ ) : "",
3526
+ /* @__PURE__ */ n(g, { id: `btnRemoveRule_${e}`, onClick: this.removeRule, children: /* @__PURE__ */ n(Ue, { color: "blue" }) })
3527
+ ] });
3528
+ };
3529
+ onDisabledChanged = (e) => {
3530
+ this.onElementChanged("disabled", !e);
3531
+ };
3532
+ onFieldChanged = (e) => {
3533
+ this.onElementChanged("field", e), this.onElementChanged("fieldSql", this.getFieldSql(e, this.props.schema.fields)), this.onElementChanged("dataType", this.getDataType(e, this.props.schema.fields)), this.onElementChanged("value", ""), this.onElementChanged("value2", "");
3534
+ };
3535
+ onOperatorChanged = (e) => {
3536
+ this.onElementChanged("operator", e), this.onElementChanged("value", ""), this.onElementChanged("value2", "");
3537
+ };
3538
+ onValueChanged = (e) => {
3539
+ const {
3540
+ field: t,
3541
+ operator: i,
3542
+ schema: { fields: r }
3543
+ } = this.props;
3544
+ let s = this.getDataType(t, r);
3545
+ if (i === "between" && (s === "date" || s === "date_time" || s === "time"))
3546
+ e && e.length > 1 ? (this.onElementChanged("value", e[0].toString()), this.onElementChanged("value2", e[1].toString())) : (this.onElementChanged("value", ""), this.onElementChanged("value2", ""));
3547
+ else if ((i === "inList" || i === "notInList") && (s === "date" || s === "date_time" || s === "time"))
3548
+ e || (e = ""), this.onElementChanged("value", e);
3549
+ else if (i === "inList" || i === "notInList") {
3550
+ e || (e = "");
3551
+ let a = e.split(",");
3552
+ if (a.length > 0) {
3553
+ let l = !1, h = "";
3554
+ a.forEach(function(o) {
3555
+ l && (h += ","), s === "number" || s === "integer" ? h += o : h += "'" + o + "'", l = !0;
3556
+ }), this.onElementChanged("value", h);
3557
+ }
3558
+ } else
3559
+ this.onElementChanged("value", e);
3560
+ };
3561
+ onValue2Changed = (e) => {
3562
+ this.onElementChanged("value2", e);
3563
+ };
3564
+ onElementChanged = (e, t) => {
3565
+ const { id: i, schema: r } = this.props;
3566
+ r && r.onPropChange && r.onPropChange(e, t, i);
3567
+ };
3568
+ removeRule = (e) => {
3569
+ e.preventDefault(), e.stopPropagation(), this.props.schema && this.props.schema.onRuleRemove(this.props.id, this.props.parentId);
3570
+ };
3571
+ }
3572
+ class fe extends v {
3573
+ static get componentName() {
3574
+ return "ActionElement";
3575
+ }
3576
+ render = () => {
3577
+ const { label: e, handleOnClick: t, style: i, color: r } = this.props;
3578
+ return /* @__PURE__ */ n(
3579
+ w,
3580
+ {
3581
+ variant: this.props.variant,
3582
+ style: i,
3583
+ size: "xs",
3584
+ color: r,
3585
+ onClick: (s) => t(s),
3586
+ children: e
3587
+ }
3588
+ );
3589
+ };
3590
+ }
3591
+ class Pe extends v {
3592
+ onInput;
3593
+ constructor(e) {
3594
+ super(e), this.onInput = xt(e.handleOnChange, 300);
3595
+ }
3596
+ static get componentName() {
3597
+ return "ValueEditor";
3598
+ }
3599
+ onActionSearchExecute = () => {
3600
+ this.props.onSearchButtonClick && this.props.onSearchButtonClick(
3601
+ this.props.field,
3602
+ event,
3603
+ this.props.handleOnChange,
3604
+ this.props.operator,
3605
+ this.props.searchField
3606
+ );
3607
+ };
3608
+ convertValueCombobox = (e, t) => {
3609
+ if (!e || e.length === 0)
3610
+ return e;
3611
+ if (t === "string") {
3612
+ let i = e.split(","), r = [];
3613
+ if (i.length > 0)
3614
+ return i.forEach((s) => {
3615
+ r.push(s.replaceAll("'", ""));
3616
+ }), r;
3617
+ } else
3618
+ return e.split(",");
3619
+ return e;
3620
+ };
3621
+ handleRangeChange = (e) => {
3622
+ e && e.length === 2 ? this.onInput(e) : this.onInput([null, null]);
3623
+ };
3624
+ render = () => {
3625
+ const { disabled: e, dataType: t, operator: i, value: r, value2: s, listValues: a } = this.props;
3626
+ let l = r ?? "", h = s === null || r === void 0 ? "" : s;
3627
+ if (i === "null" || i === "notNull")
3628
+ return null;
3629
+ if (t) {
3630
+ if (t === "date")
3631
+ return i === "between" ? (l === "" && h === "" ? l = "" : l = [l, h], /* @__PURE__ */ n(
3632
+ M,
3633
+ {
3634
+ type: "range",
3635
+ disabled: e,
3636
+ value: l,
3637
+ style: { width: this.props.twoFields ? "128px" : "260px" },
3638
+ onChange: (o) => this.onInput(o)
3639
+ }
3640
+ )) : i === "notInList" || i === "inList" ? /* @__PURE__ */ n(
3641
+ M,
3642
+ {
3643
+ type: "multiple",
3644
+ disabled: e,
3645
+ value: l,
3646
+ style: { width: this.props.twoFields ? "128px" : "260px" },
3647
+ onChange: (o) => this.onInput(o)
3648
+ }
3649
+ ) : /* @__PURE__ */ n(
3650
+ M,
3651
+ {
3652
+ disabled: e,
3653
+ value: l,
3654
+ style: { width: this.props.twoFields ? "128px" : "260px" },
3655
+ onChange: (o) => this.onInput(o)
3656
+ }
3657
+ );
3658
+ if (t === "date_time")
3659
+ if (i === "between") {
3660
+ const o = l === "" && h === "" ? [null, null] : [new Date(l), new Date(h)];
3661
+ return /* @__PURE__ */ n(
3662
+ Ye,
3663
+ {
3664
+ disabled: e,
3665
+ value: o,
3666
+ width: this.props.twoFields ? "128px" : "260px",
3667
+ onRangeChange: this.handleRangeChange,
3668
+ withSeconds: !0,
3669
+ valueFormat: "DD/MM/YYYY HH:mm:ss"
3670
+ }
3671
+ );
3672
+ } else
3673
+ return /* @__PURE__ */ n(
3674
+ He,
3675
+ {
3676
+ disabled: e,
3677
+ value: l ? new Date(l) : null,
3678
+ width: this.props.twoFields ? "128px" : "260px",
3679
+ onChange: (o) => this.onInput(o),
3680
+ withSeconds: !0,
3681
+ valueFormat: "DD/MM/YYYY HH:mm:ss"
3682
+ }
3683
+ );
3684
+ else {
3685
+ if (t === "time")
3686
+ return l === "" && h === "" ? l = "" : l = l + " - " + h, /* @__PURE__ */ n(
3687
+ Ge,
3688
+ {
3689
+ disabled: e,
3690
+ width: this.props.twoFields ? "128px" : "260px",
3691
+ value: l,
3692
+ onChange: (o) => this.onInput(o)
3693
+ }
3694
+ );
3695
+ if (t === "boolean")
3696
+ return /* @__PURE__ */ n(
3697
+ kt,
3698
+ {
3699
+ isChecked: l,
3700
+ onChangeValue: (o, c) => this.onInput(o === !0)
3701
+ }
3702
+ );
3703
+ if (a && a.length > 0 && (i === "notInList" || i === "inList")) {
3704
+ let o = this.convertValueCombobox(l, t);
3705
+ return /* @__PURE__ */ n(
3706
+ be,
3707
+ {
3708
+ disabled: e,
3709
+ width: this.props.twoFields ? "128px" : "260px",
3710
+ onSelectValue: (c) => this.onInput(c),
3711
+ value: o,
3712
+ getOptionLabel: (c) => c.label,
3713
+ getOptionValue: (c) => c.value,
3714
+ children: a.map((c) => /* @__PURE__ */ n(
3715
+ Ce,
3716
+ {
3717
+ label: c.label,
3718
+ value: c.value,
3719
+ disabled: !1
3720
+ },
3721
+ c.value
3722
+ ))
3723
+ }
3724
+ );
3725
+ } else
3726
+ return a && a.length > 0 ? /* @__PURE__ */ n(
3727
+ be,
3728
+ {
3729
+ disabled: e,
3730
+ value: l,
3731
+ width: this.props.twoFields ? "128px" : "260px",
3732
+ getOptionLabel: (o) => o.label,
3733
+ getOptionValue: (o) => o.value,
3734
+ onSelectValue: (o) => this.onInput(o),
3735
+ children: a.map((o) => /* @__PURE__ */ n(
3736
+ Ce,
3737
+ {
3738
+ label: o.label,
3739
+ value: o.value,
3740
+ disabled: !1
3741
+ },
3742
+ o.value
3743
+ ))
3744
+ }
3745
+ ) : /* @__PURE__ */ n(
3746
+ H,
3747
+ {
3748
+ onChange: (o) => this.onInput(o),
3749
+ disabled: e,
3750
+ initialValue: l,
3751
+ icon: /* @__PURE__ */ n(le, { size: "1rem" }),
3752
+ onActionSearchExecute: this.onActionSearchExecute,
3753
+ style: {
3754
+ height: "36px",
3755
+ width: this.props.twoFields ? "128px" : "260px",
3756
+ paddingLeft: "3px"
3757
+ },
3758
+ label: void 0,
3759
+ error: void 0,
3760
+ keyProp: void 0,
3761
+ readOnly: !1,
3762
+ placeholder: void 0,
3763
+ innerRef: void 0,
3764
+ onFocus: void 0,
3765
+ onKeyDown: void 0
3766
+ }
3767
+ );
3768
+ }
3769
+ } else
3770
+ return /* @__PURE__ */ n(
3771
+ H,
3772
+ {
3773
+ onChange: (o) => this.onInput(o),
3774
+ disabled: e,
3775
+ initialValue: l,
3776
+ style: {
3777
+ height: "36px",
3778
+ width: this.props.twoFields ? "128px" : "260px",
3779
+ paddingLeft: "3px"
3780
+ },
3781
+ label: void 0,
3782
+ error: void 0,
3783
+ keyProp: void 0,
3784
+ readOnly: !1,
3785
+ placeholder: void 0,
3786
+ innerRef: void 0,
3787
+ onFocus: void 0,
3788
+ onKeyDown: void 0,
3789
+ onActionSearchExecute: void 0,
3790
+ icon: void 0
3791
+ }
3792
+ );
3793
+ };
3794
+ }
3795
+ class Le extends v {
3796
+ static get componentName() {
3797
+ return "ValueSelector";
3798
+ }
3799
+ static defaultProps = {
3800
+ disabled: !1
3801
+ };
3802
+ constructor(e) {
3803
+ super(e);
3804
+ let t = this.getTextWidth(e.options[0].name);
3805
+ this.state = { width: t, value: void 0 };
3806
+ }
3807
+ getLabelByName = (e) => {
3808
+ let t;
3809
+ return this.props.options.map((i) => {
3810
+ i.name === e && (t = i.label);
3811
+ }), t;
3812
+ };
3813
+ getTextWidth = (e) => {
3814
+ let t = document.createElement("span");
3815
+ document.body.appendChild(t);
3816
+ const i = this.getLabelByName(e);
3817
+ t.className = this.props.className, t.innerHTML = i;
3818
+ let s = Math.ceil(t.offsetWidth) + 4 + "px";
3819
+ return document.body.removeChild(t), s;
3820
+ };
3821
+ handleOnChange = (e) => {
3822
+ this.props.handleOnChange && this.props.handleOnChange(e.target.value);
3823
+ let t = this.getTextWidth(e.target.value);
3824
+ this.setState({ ...this.state, value: e.target.value, width: t });
3825
+ };
3826
+ render = () => {
3827
+ const { value: e, options: t, className: i, disabled: r, style: s } = this.props;
3828
+ return /* @__PURE__ */ n(
3829
+ "select",
3830
+ {
3831
+ className: i,
3832
+ style: s,
3833
+ disabled: r,
3834
+ value: e,
3835
+ tabIndex: -1,
3836
+ onChange: this.handleOnChange,
3837
+ children: t.map((a) => /* @__PURE__ */ n("option", { value: a.name, children: a.label }, a.name))
3838
+ }
3839
+ );
3840
+ };
3841
+ }
3842
+ class $i extends v {
3843
+ render = () => {
3844
+ const { style: e, when: t, inputValue: i, children: r, classNameFeedback: s } = this.props;
3845
+ return t && i && t(i) === !0 ? /* @__PURE__ */ n("div", { style: e, className: s, children: r }) : null;
3846
+ };
3847
+ }
3848
+ class qi extends v {
3849
+ render = () => {
3850
+ const { theme: e, colorScheme: t, onSearchClick: i, variant: r } = this.props;
3851
+ return /* @__PURE__ */ n(
3852
+ lt,
3853
+ {
3854
+ placeholder: this.props.placeholder,
3855
+ style: { width: "100%" },
3856
+ rightSection: /* @__PURE__ */ n(f, { withinPortal: !0, withArrow: !0, label: "Localizar", children: /* @__PURE__ */ n(
3857
+ g,
3858
+ {
3859
+ style: {
3860
+ backgroundColor: t === "dark" ? e.colors[e.primaryColor][5] : e.colors[e.primaryColor][6]
3861
+ },
3862
+ tabIndex: -1,
3863
+ variant: r,
3864
+ onClick: i,
3865
+ children: /* @__PURE__ */ n(le, { size: "1rem" })
3866
+ }
3867
+ ) })
3868
+ }
3869
+ );
3870
+ };
3871
+ }
3872
+ function Kt(d, e) {
3873
+ const t = [];
3874
+ return d.forEach((i) => {
3875
+ t.push(C.eq(i, `^*${e}*`));
3876
+ }), rt(C.or(...t));
3877
+ }
3878
+ function Mi({
3879
+ searchableFields: d,
3880
+ onFilter: e,
3881
+ minFilterValueLength: t,
3882
+ options: i
3883
+ }) {
3884
+ const { t: r } = it(), [s, a] = $(""), [l, h] = Je(s, 500), [o, c] = $(""), [u, F] = $(""), b = $e(), k = Be(!1);
3885
+ ge(() => {
3886
+ if (l.length < t && !k.current && (e("", ""), c(""), F(""), k.current = !0), l.length >= t && l !== u) {
3887
+ const _ = Kt(d, l);
3888
+ c(_), k.current = !1, F(l), h(), e(_, l);
3889
+ }
3890
+ }, [l, t, e, d]);
3891
+ function P(_, tt) {
3892
+ e(_, tt);
3893
+ }
3894
+ const L = i && i.inputProps ? i.inputProps : { miw: 240 }, J = i && i.buttonRefreshProps ? i.buttonRefreshProps : { color: b.primaryColor, variant: "filled" }, z = i && i.buttonClearProps ? i.buttonClearProps : { color: b.primaryColor, variant: "filled" }, G = i && i.iconRefreshProps ? i.iconRefreshProps : { size: "1.5rem", color: "white" }, V = i && i.iconRefreshProps ? i.iconRefreshProps : { size: "1.5rem", color: "white" }, K = i && i.spacing ? i.spacing : 5;
3895
+ return /* @__PURE__ */ p(ot, { justify: "space-between", align: "center", children: [
3896
+ /* @__PURE__ */ n(
3897
+ ze,
3898
+ {
3899
+ rightSection: /* @__PURE__ */ n(le, {}),
3900
+ variant: "filled",
3901
+ defaultValue: s,
3902
+ onChange: (_) => a(_.currentTarget.value),
3903
+ ...L
3904
+ }
3905
+ ),
3906
+ /* @__PURE__ */ n(R, { w: K }),
3907
+ /* @__PURE__ */ n(f, { withinPortal: !0, withArrow: !0, label: `${r("archbase:Refresh")}`, children: /* @__PURE__ */ n(
3908
+ g,
3909
+ {
3910
+ color: "var(--mantine-primary-color-filled)",
3911
+ onClick: () => P(o, u),
3912
+ style: { height: "36px", width: "36px" },
3913
+ ...J,
3914
+ children: /* @__PURE__ */ n(ye, { ...G })
3915
+ }
3916
+ ) }),
3917
+ /* @__PURE__ */ n(R, { w: K }),
3918
+ /* @__PURE__ */ n(f, { withinPortal: !0, withArrow: !0, label: `${r("archbase:ClearFilter")}`, children: /* @__PURE__ */ n(
3919
+ g,
3920
+ {
3921
+ color: "var(--mantine-primary-color-filled)",
3922
+ onClick: () => P("", ""),
3923
+ style: { height: "36px", width: "36px" },
3924
+ ...z,
3925
+ children: /* @__PURE__ */ n(wt, { ...V })
3926
+ }
3927
+ ) })
3928
+ ] });
3929
+ }
3930
+ function Wi(d) {
3931
+ const e = [];
3932
+ if (d.filter.rules) {
3933
+ const t = et(d.filter.condition, d.filter.rules);
3934
+ return d.sort && d.sort.sortFields && d.sort.sortFields.forEach((i) => {
3935
+ i.selected && e.push(i.name + ":" + i.asc_desc);
3936
+ }), {
3937
+ expressionNode: t,
3938
+ sortStrings: e
3939
+ };
3940
+ }
3941
+ return null;
3942
+ }
3943
+ function et(d, e) {
3944
+ let t = C.and;
3945
+ d === "or" && (t = C.or);
3946
+ const i = [];
3947
+ return e.forEach((r) => {
3948
+ if (r.field && !r.disabled) {
3949
+ let s = r.value, a = r.value2;
3950
+ s && s !== "" && (typeof s == "number" || s instanceof Date) && (r.dataType === "date" || r.dataType === "date_time") && (s = Ve(r, s)), a && a !== "" && (typeof a == "number" || a instanceof Date) && (r.dataType === "date" || r.dataType === "date_time") && (a = Ve(r, a)), r.operator === "null" ? i.push(C.eq(r.field, "null")) : r.operator === "notNull" ? i.push(C.neq(r.field, "null")) : r.operator === "contains" && s && s !== "" ? i.push(C.eq(r.field, `^*${s}*`)) : r.operator === "startsWith" && s && s !== "" ? i.push(C.eq(r.field, `^${s}*`)) : r.operator === "endsWith" && s && s !== "" && (typeof s == "string" || typeof s == "number") ? i.push(C.eq(r.field, `^*${s}`)) : r.operator === "=" && s && s !== "" && (typeof s == "string" || typeof s == "number") ? i.push(C.eq(r.field, s)) : r.operator === "!=" && s && s !== "" && (typeof s == "string" || typeof s == "number") ? i.push(C.neq(r.field, s)) : r.operator === "<" && s && s !== "" && (typeof s == "string" || typeof s == "number") ? i.push(C.lt(r.field, s)) : r.operator === ">" && s && s !== "" && (typeof s == "string" || typeof s == "number") ? i.push(C.gt(r.field, s)) : r.operator === "<=" && s && s !== "" && (typeof s == "string" || typeof s == "number") ? i.push(C.le(r.field, s)) : r.operator === ">=" && s && s !== "" && (typeof s == "string" || typeof s == "number") ? i.push(C.ge(r.field, s)) : r.operator === "between" && s && s !== "" && a && a !== "" && (typeof s == "string" || typeof s == "number") && (typeof a == "string" || typeof a == "number") ? i.push(C.bt(r.field, s, a)) : r.operator === "notBetween" && s && s !== "" && a && a !== "" && (typeof s == "string" || typeof s == "number") && (typeof a == "string" || typeof a == "number") ? i.push(C.nb(r.field, s, a)) : r.operator === "inList" && s && s !== "" && Array.isArray(s) ? i.push(C.in(r.field, s)) : r.operator === "notInList" && s && s !== "" && Array.isArray(s) && i.push(C.out(r.field, s));
3951
+ }
3952
+ r.rules && !r.disabled && i.push(et(r.condition, r.rules));
3953
+ }), t(...i);
3954
+ }
3955
+ function Ve(d, e) {
3956
+ if (d.dataType === "date")
3957
+ return Te(e, { representation: "date" });
3958
+ if (d.dataType === "date_time")
3959
+ return Te(e, { representation: "complete" });
3960
+ }
3961
+ class Xt {
3962
+ query;
3963
+ constructor() {
3964
+ this.query = "";
3965
+ }
3966
+ buildFrom(e) {
3967
+ return this.query = "", e.filter.rules && this.buildGraphQLQuery(e.filter.condition, e.filter.rules), this.query;
3968
+ }
3969
+ buildGraphQLQuery(e, t) {
3970
+ e === "or" && (this.query += "("), t.forEach((i, r) => {
3971
+ if (r > 0 && (e === "or" ? this.query += ", " : this.query += " E "), i.field && !i.disabled) {
3972
+ const s = this.getFieldName(i.field), a = this.getOperator(i.operator), l = this.formatValue(i.value, i.dataType);
3973
+ this.query += `${s}: { ${a}: ${l} }`;
3974
+ }
3975
+ i.rules && !i.disabled && this.buildGraphQLQuery(i.condition, i.rules);
3976
+ }), e === "or" && (this.query += ")");
3977
+ }
3978
+ getFieldName(e) {
3979
+ return e;
3980
+ }
3981
+ getOperator(e) {
3982
+ return e;
3983
+ }
3984
+ formatValue(e, t) {
3985
+ return t === "date" || t === "date_time" ? `"${e}"` : t === "number" ? e : `"${e}"`;
3986
+ }
3987
+ }
3988
+ const zi = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
3989
+ __proto__: null,
3990
+ default: Xt
3991
+ }, Symbol.toStringTag, { value: "Module" })), Gi = "3.0.0", Qi = "3.0.0";
3992
+ export {
3993
+ se as ADVANCED,
3994
+ Ht as ArchbaseAdvancedFilter,
3995
+ Qi as ArchbaseAdvancedVersion,
3996
+ Wt as ArchbaseCompositeFilter,
3997
+ zt as ArchbaseDetailedFilter,
3998
+ $i as ArchbaseFeedback,
3999
+ Qt as ArchbaseFilterSelectFields,
4000
+ Yt as ArchbaseFilterSelectRange,
4001
+ Mi as ArchbaseGlobalFilter,
4002
+ qi as ArchbaseInputSearch,
4003
+ Gi as ArchbaseKanbanVersion,
4004
+ Bi as ArchbaseQueryBuilder,
4005
+ qt as ArchbaseSaveFilter,
4006
+ Mt as ArchbaseSimpleFilter,
4007
+ we as CustomSortItem,
4008
+ Nt as FilterField,
4009
+ At as FilterFieldValue,
4010
+ Pt as FilterFields,
4011
+ zi as GraphQLQueryBuilder,
4012
+ Z as NEW_FILTER_INDEX,
4013
+ ee as NORMAL,
4014
+ Oi as OP_BETWEEN,
4015
+ Ci as OP_CONTAINS,
4016
+ Si as OP_ENDSWITH,
4017
+ yi as OP_EQUALS,
4018
+ xi as OP_GREATER,
4019
+ ki as OP_GREATER_OR_EQUAL,
4020
+ Ri as OP_IN_LIST,
4021
+ Ii as OP_LESS,
4022
+ Ti as OP_LESS_OR_EQUAL,
4023
+ wi as OP_NOT_EQUALS,
4024
+ Ei as OP_NOT_IN_LIST,
4025
+ bi as OP_NOT_NULL,
4026
+ Fi as OP_NULL,
4027
+ vi as OP_STARTSWITH,
4028
+ T as QUICK,
4029
+ S as QUICK_FILTER_INDEX,
4030
+ Li as QueryField,
4031
+ Vi as QueryFieldValue,
4032
+ Pi as QueryFields,
4033
+ ne as QueryFilterEntity,
4034
+ Pe as ValueEditor,
4035
+ Wi as buildFrom,
4036
+ Ze as convertQueryFields,
4037
+ Ai as defaultConditions,
4038
+ $t as defaultOperators,
4039
+ Y as getDefaultEmptyFilter,
4040
+ D as getDefaultFilter,
4041
+ _i as getFieldSql,
4042
+ Di as getFieldValues,
4043
+ I as getFields,
4044
+ ae as getQuickFields,
4045
+ Lt as getQuickFieldsSort,
4046
+ A as getQuickFilterFields,
4047
+ Vt as getQuickFilterSort,
4048
+ Ni as getQuickFilterSortBySelectedFields,
4049
+ Xe as getSortString,
4050
+ Bt as mergeSortWithFields
4051
+ };