teraprox-core-sdk 0.2.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.mjs ADDED
@@ -0,0 +1,961 @@
1
+ // src/context/CoreServiceContext.ts
2
+ import { createContext } from "react";
3
+ var CoreServiceContext = createContext(null);
4
+
5
+ // src/hooks/useCoreService.ts
6
+ import { useContext } from "react";
7
+ function useCoreService() {
8
+ const ctx = useContext(CoreServiceContext);
9
+ if (!ctx) {
10
+ throw new Error(
11
+ "useCoreService must be used within a CoreServiceProvider. Are you running outside Core (standalone mode)?"
12
+ );
13
+ }
14
+ return ctx;
15
+ }
16
+
17
+ // src/hooks/useHttpController.ts
18
+ import { useMemo } from "react";
19
+ function useHttpController(context, baseEndPoint) {
20
+ const { createController } = useCoreService();
21
+ return useMemo(
22
+ () => createController(context, baseEndPoint),
23
+ [createController, context, baseEndPoint]
24
+ );
25
+ }
26
+
27
+ // src/hooks/useToast.ts
28
+ function useToast() {
29
+ return useCoreService().toast;
30
+ }
31
+
32
+ // src/hooks/useMatchingObject.ts
33
+ import { useEffect } from "react";
34
+ function useMatchingObject(context, location, refresher, deps = []) {
35
+ const { subscribe, unsubscribe } = useCoreService();
36
+ useEffect(() => {
37
+ const mo = { context, location, refresher };
38
+ subscribe(mo);
39
+ return () => unsubscribe(mo);
40
+ }, [context, location, subscribe, unsubscribe, ...deps]);
41
+ }
42
+
43
+ // src/hooks/useNotifications.ts
44
+ import { useSelector } from "react-redux";
45
+ function useNotifications() {
46
+ return useSelector((state) => state.notification);
47
+ }
48
+
49
+ // src/hooks/useNavigator.ts
50
+ import { useCallback } from "react";
51
+ import { useNavigate } from "react-router-dom";
52
+ import { useDispatch, useSelector as useSelector2 } from "react-redux";
53
+ var defaultPermissionsSelector = (state) => {
54
+ var _a, _b, _c, _d;
55
+ return (_d = (_c = (_b = (_a = state.global) == null ? void 0 : _a.role) == null ? void 0 : _b.permissao) == null ? void 0 : _c[0]) == null ? void 0 : _d.frontEndPerms;
56
+ };
57
+ var defaultPageLocationSelector = (state) => {
58
+ var _a;
59
+ return (_a = state.global) == null ? void 0 : _a.pageLocation;
60
+ };
61
+ var defaultPrevPageSelector = (state) => {
62
+ var _a;
63
+ return (_a = state.global) == null ? void 0 : _a.prevPage;
64
+ };
65
+ function useNavigator(config) {
66
+ const dispatch = useDispatch();
67
+ const navigate = useNavigate();
68
+ const {
69
+ pageTracking,
70
+ paths,
71
+ permissionsSelector = defaultPermissionsSelector,
72
+ pageLocationSelector = defaultPageLocationSelector,
73
+ prevPageSelector = defaultPrevPageSelector
74
+ } = config;
75
+ const frontEndPerms = useSelector2(permissionsSelector);
76
+ const pageLocation = useSelector2(pageLocationSelector);
77
+ const prevPage = useSelector2(prevPageSelector);
78
+ return useCallback(
79
+ (path, navConfig, pageName) => {
80
+ const allowedPaths = [paths.loginForm];
81
+ if (typeof path === "string" && allowedPaths.includes(path)) {
82
+ return navigate(path);
83
+ }
84
+ if (!path) path = -1;
85
+ if (path === -1) {
86
+ dispatch(pageTracking.setPrevPage(pageLocation));
87
+ dispatch(pageTracking.setPageLocation(prevPage));
88
+ return navigate(-1);
89
+ }
90
+ if (frontEndPerms && frontEndPerms.length > 0) {
91
+ for (const perm of frontEndPerms) {
92
+ const locationBloqueado = `/${perm.locationBloqueado}`;
93
+ if (locationBloqueado === "*") {
94
+ dispatch(pageTracking.setPrevPage(pageLocation));
95
+ return navigate(paths.inativeUser || "/inativeUser");
96
+ }
97
+ if (locationBloqueado === path) {
98
+ return navigate(paths.acessoNaoPermitido);
99
+ }
100
+ dispatch(pageTracking.setPrevPage(pageLocation));
101
+ dispatch(pageTracking.setPageLocation(pageName || ""));
102
+ return navigate(path, { ...navConfig, replace: false });
103
+ }
104
+ }
105
+ dispatch(pageTracking.setPrevPage(pageLocation));
106
+ dispatch(pageTracking.setPageLocation(pageName || ""));
107
+ return navigate(path, { ...navConfig, replace: false });
108
+ },
109
+ [dispatch, navigate, frontEndPerms, pageLocation, prevPage, pageTracking, paths]
110
+ );
111
+ }
112
+
113
+ // src/components/recurso/RecursoDisplayer.tsx
114
+ import { useEffect as useEffect5, useState as useState6 } from "react";
115
+ import { Button } from "react-bootstrap";
116
+ import { useDispatch as useDispatch2 } from "react-redux";
117
+
118
+ // src/reducers/branchLevelReducer.ts
119
+ import { createSlice } from "@reduxjs/toolkit";
120
+ var initialState = {
121
+ form: {
122
+ nome: "",
123
+ level: 0,
124
+ color: "",
125
+ hasComponents: false,
126
+ excludeLevels: 0
127
+ },
128
+ levels: []
129
+ };
130
+ var branchLevelSlice = createSlice({
131
+ name: "branchLevelReducer",
132
+ initialState,
133
+ reducers: {
134
+ setNome(state, action) {
135
+ state.form.nome = action.payload;
136
+ },
137
+ setLevel(state, action) {
138
+ state.form.level = action.payload;
139
+ },
140
+ setColor(state, action) {
141
+ state.form.color = action.payload;
142
+ },
143
+ setHaveComponente(state, action) {
144
+ state.form.hasComponents = action.payload;
145
+ },
146
+ setExcludeLevels(state, action) {
147
+ state.form.excludeLevels = action.payload;
148
+ },
149
+ setLevels(state, action) {
150
+ state.levels = action.payload;
151
+ },
152
+ populateToEdit(state, action) {
153
+ state.form = action.payload;
154
+ },
155
+ clear(state) {
156
+ state.form = initialState.form;
157
+ }
158
+ }
159
+ });
160
+ var {
161
+ setNome,
162
+ setLevel,
163
+ populateToEdit,
164
+ setColor,
165
+ setHaveComponente,
166
+ clear: clearBranchLevelForm,
167
+ setExcludeLevels,
168
+ setLevels
169
+ } = branchLevelSlice.actions;
170
+ var branchLevelReducer_default = branchLevelSlice.reducer;
171
+
172
+ // src/components/recurso/BranchDropDisplay.tsx
173
+ import { useEffect as useEffect2, useRef, useState } from "react";
174
+ import { FaCheck, FaCheckSquare, FaSearch, FaChevronDown } from "react-icons/fa";
175
+ import { MdClose } from "react-icons/md";
176
+
177
+ // src/utils/colorUtils.ts
178
+ function pickTextColorBasedOnBgColorAdvanced(bgColor, lightColor, darkColor) {
179
+ const color = bgColor.charAt(0) === "#" ? bgColor.substring(1, 7) : bgColor;
180
+ const r = parseInt(color.substring(0, 2), 16);
181
+ const g = parseInt(color.substring(2, 4), 16);
182
+ const b = parseInt(color.substring(4, 6), 16);
183
+ const uicolors = [r / 255, g / 255, b / 255];
184
+ const c = uicolors.map(
185
+ (col) => col <= 0.03928 ? col / 12.92 : Math.pow((col + 0.055) / 1.055, 2.4)
186
+ );
187
+ const L = 0.2126 * c[0] + 0.7152 * c[1] + 0.0722 * c[2];
188
+ return L > 0.179 ? darkColor : lightColor;
189
+ }
190
+
191
+ // src/components/recurso/BranchDropDisplay.tsx
192
+ import { jsx, jsxs } from "react/jsx-runtime";
193
+ var BranchDropDisplay = ({
194
+ branch,
195
+ addBranch,
196
+ multiMode,
197
+ setMultiMode,
198
+ onSaveRecurso,
199
+ backOnBranch,
200
+ branches,
201
+ singleReturn
202
+ }) => {
203
+ const [fontColor, setFontColor] = useState("#000");
204
+ const [searchTerm, setSearchTerm] = useState("");
205
+ const [show, setShow] = useState(false);
206
+ const [multiSelected, setMultiSelected] = useState([]);
207
+ const dropdownRef = useRef(null);
208
+ useEffect2(() => {
209
+ setFontColor(
210
+ pickTextColorBasedOnBgColorAdvanced(branch.branchLevel.color, "#FFFFFF", "#000000")
211
+ );
212
+ }, [branch.branchLevel.color]);
213
+ useEffect2(() => {
214
+ const handleClickOutside = (event) => {
215
+ if (dropdownRef.current && !dropdownRef.current.contains(event.target)) {
216
+ setShow(false);
217
+ }
218
+ };
219
+ document.addEventListener("mousedown", handleClickOutside);
220
+ return () => document.removeEventListener("mousedown", handleClickOutside);
221
+ }, [backOnBranch, branch]);
222
+ const handleItemClick = (bn) => {
223
+ const rec = bn.recurso;
224
+ if (multiMode) {
225
+ setMultiSelected(
226
+ (prev) => prev.some((r) => r.id === rec.id) ? prev.filter((r) => r.id !== rec.id) : [...prev, rec]
227
+ );
228
+ } else {
229
+ onSaveRecurso([rec]);
230
+ addBranch(bn);
231
+ setShow(false);
232
+ }
233
+ };
234
+ const startMulti = () => {
235
+ setMultiSelected([]);
236
+ setMultiMode(true);
237
+ setShow(true);
238
+ };
239
+ const handleConfirm = () => {
240
+ setMultiMode(false);
241
+ onSaveRecurso(multiSelected);
242
+ setMultiSelected([]);
243
+ setShow(false);
244
+ };
245
+ const cancelMulti = () => {
246
+ setMultiMode(false);
247
+ setMultiSelected([]);
248
+ };
249
+ const isLastBranchClicked = () => branches.length > 0 && branches[branches.length - 1].id === branch.id;
250
+ const visibleNodes = branch.branchNodes.filter(
251
+ (bn) => bn.recurso.nome.toLowerCase().includes(searchTerm.toLowerCase())
252
+ );
253
+ return /* @__PURE__ */ jsxs(
254
+ "div",
255
+ {
256
+ ref: dropdownRef,
257
+ style: {
258
+ position: "relative",
259
+ marginBottom: "0.5rem",
260
+ width: "100%",
261
+ fontFamily: "Arial, sans-serif"
262
+ },
263
+ children: [
264
+ /* @__PURE__ */ jsxs(
265
+ "button",
266
+ {
267
+ onClick: () => setShow((s) => !s),
268
+ style: {
269
+ width: "100%",
270
+ display: "flex",
271
+ alignItems: "center",
272
+ justifyContent: "space-between",
273
+ padding: "0.5rem 1rem",
274
+ borderRadius: "9999px",
275
+ boxShadow: "0 1px 3px rgba(0, 0, 0, 0.1)",
276
+ border: `1px solid ${branch.branchLevel.color}`,
277
+ background: branch.branchLevel.color,
278
+ color: fontColor,
279
+ cursor: "pointer",
280
+ outline: "none",
281
+ textAlign: "left",
282
+ fontSize: "1rem"
283
+ },
284
+ children: [
285
+ /* @__PURE__ */ jsxs("span", { style: { overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" }, children: [
286
+ branch.nomeRecurso || branch.branchLevel.nome,
287
+ branch.nomeRecurso && !multiMode && isLastBranchClicked() && /* @__PURE__ */ jsx("em", { style: { fontStyle: "italic", opacity: 0.8, marginLeft: "0.5rem" }, children: "(Selecionado)" })
288
+ ] }),
289
+ /* @__PURE__ */ jsx(FaChevronDown, {})
290
+ ]
291
+ }
292
+ ),
293
+ show && /* @__PURE__ */ jsxs(
294
+ "div",
295
+ {
296
+ style: {
297
+ position: "absolute",
298
+ top: "100%",
299
+ left: 0,
300
+ width: "100%",
301
+ background: "#f0f0f0",
302
+ borderRadius: "8px",
303
+ boxShadow: "0 2px 6px rgba(0, 0, 0, 0.15)",
304
+ marginTop: "0.25rem",
305
+ zIndex: 100,
306
+ maxHeight: "300px",
307
+ overflow: "auto"
308
+ },
309
+ children: [
310
+ /* @__PURE__ */ jsxs(
311
+ "div",
312
+ {
313
+ style: {
314
+ display: "flex",
315
+ alignItems: "center",
316
+ padding: "0.5rem",
317
+ borderBottom: "1px solid #ddd"
318
+ },
319
+ children: [
320
+ /* @__PURE__ */ jsx(FaSearch, { style: { marginRight: "0.5rem", color: "#555" } }),
321
+ /* @__PURE__ */ jsx(
322
+ "input",
323
+ {
324
+ type: "text",
325
+ placeholder: "Pesquisar recurso...",
326
+ value: searchTerm,
327
+ onChange: (e) => setSearchTerm(e.target.value),
328
+ style: {
329
+ flex: 1,
330
+ padding: "0.5rem",
331
+ border: "1px solid #ccc",
332
+ borderRadius: "9999px",
333
+ outline: "none",
334
+ fontSize: "0.95rem"
335
+ }
336
+ }
337
+ )
338
+ ]
339
+ }
340
+ ),
341
+ !multiMode && !singleReturn ? /* @__PURE__ */ jsxs(
342
+ "button",
343
+ {
344
+ onClick: startMulti,
345
+ style: {
346
+ display: "flex",
347
+ alignItems: "center",
348
+ justifyContent: "center",
349
+ width: "100%",
350
+ padding: "0.5rem",
351
+ borderRadius: "9999px",
352
+ border: "none",
353
+ background: "#ffc107",
354
+ color: "#000",
355
+ fontSize: "0.95rem",
356
+ cursor: "pointer",
357
+ margin: "0.5rem 0"
358
+ },
359
+ children: [
360
+ /* @__PURE__ */ jsx(FaCheckSquare, { style: { marginRight: "0.5rem" } }),
361
+ "Selecionar m\xFAltiplos"
362
+ ]
363
+ }
364
+ ) : /* @__PURE__ */ jsxs("div", { style: { display: "flex", gap: "0.5rem", margin: "0.5rem 0" }, children: [
365
+ /* @__PURE__ */ jsxs(
366
+ "button",
367
+ {
368
+ onClick: handleConfirm,
369
+ style: {
370
+ flex: 1,
371
+ display: "flex",
372
+ alignItems: "center",
373
+ justifyContent: "center",
374
+ padding: "0.5rem",
375
+ borderRadius: "9999px",
376
+ border: "none",
377
+ background: "#28a745",
378
+ color: "#fff",
379
+ fontSize: "0.95rem",
380
+ cursor: "pointer"
381
+ },
382
+ children: [
383
+ /* @__PURE__ */ jsx(FaCheck, { style: { marginRight: "0.5rem" } }),
384
+ "Confirmar sele\xE7\xE3o"
385
+ ]
386
+ }
387
+ ),
388
+ /* @__PURE__ */ jsxs(
389
+ "button",
390
+ {
391
+ onClick: cancelMulti,
392
+ style: {
393
+ flex: 1,
394
+ display: "flex",
395
+ alignItems: "center",
396
+ justifyContent: "center",
397
+ padding: "0.5rem",
398
+ borderRadius: "9999px",
399
+ border: "none",
400
+ background: "#6c757d",
401
+ color: "#fff",
402
+ fontSize: "0.95rem",
403
+ cursor: "pointer"
404
+ },
405
+ children: [
406
+ /* @__PURE__ */ jsx(MdClose, { style: { marginRight: "0.5rem" } }),
407
+ "Cancelar"
408
+ ]
409
+ }
410
+ )
411
+ ] }),
412
+ /* @__PURE__ */ jsx("div", { style: { padding: "0.5rem" }, children: visibleNodes.map((bn) => {
413
+ const selected = multiMode ? multiSelected.some((r) => r.id === bn.recurso.id) : false;
414
+ return /* @__PURE__ */ jsxs(
415
+ "div",
416
+ {
417
+ onClick: () => handleItemClick(bn),
418
+ style: {
419
+ display: "flex",
420
+ justifyContent: "space-between",
421
+ alignItems: "center",
422
+ padding: "0.5rem",
423
+ borderBottom: "1px solid #ddd",
424
+ background: selected ? "#e9ecef" : "transparent",
425
+ cursor: "pointer",
426
+ transition: "background 0.1s"
427
+ },
428
+ onMouseEnter: (e) => {
429
+ if (!selected) e.currentTarget.style.background = "#e2e6ea";
430
+ },
431
+ onMouseLeave: (e) => {
432
+ e.currentTarget.style.background = selected ? "#e9ecef" : "transparent";
433
+ },
434
+ children: [
435
+ /* @__PURE__ */ jsx("span", { children: bn.recurso.nome }),
436
+ selected && /* @__PURE__ */ jsx(FaCheck, {})
437
+ ]
438
+ },
439
+ bn.recurso.id
440
+ );
441
+ }) })
442
+ ]
443
+ }
444
+ )
445
+ ]
446
+ }
447
+ );
448
+ };
449
+ var BranchDropDisplay_default = BranchDropDisplay;
450
+
451
+ // src/components/recurso/FindRecursoByTagField.tsx
452
+ import { useState as useState5 } from "react";
453
+ import { GrCheckmark } from "react-icons/gr";
454
+
455
+ // src/components/recurso/AutoComplete.tsx
456
+ import { useEffect as useEffect3, useState as useState2 } from "react";
457
+ import { FloatingLabel, Form, InputGroup, ListGroup } from "react-bootstrap";
458
+ import { Fragment, jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
459
+ var AutoComplete = ({
460
+ className,
461
+ ops,
462
+ sortKey,
463
+ displayKey,
464
+ displayKeys,
465
+ onValueChanged,
466
+ selectedKey,
467
+ onSelectedClick,
468
+ value,
469
+ actionButton,
470
+ actionButton2,
471
+ placeH,
472
+ title,
473
+ filter,
474
+ filterField,
475
+ loadFunc,
476
+ loadCondition,
477
+ isBold,
478
+ onBlurEvent,
479
+ formatationFunc,
480
+ onEscKeyDown,
481
+ margT,
482
+ hideComponent,
483
+ disableComponent = false,
484
+ disableSelect = false,
485
+ margB,
486
+ autoFocusConfig,
487
+ onLoad,
488
+ onMouseLv,
489
+ useStandardLabel = false,
490
+ isRequired = false,
491
+ ty = "text"
492
+ }) => {
493
+ const [liItem, setListItem] = useState2([]);
494
+ const [options, setOptions] = useState2([]);
495
+ const [input, setInput] = useState2("");
496
+ const [hide, setHide] = useState2(true);
497
+ const [onLoaded, setOnLoaded] = useState2(false);
498
+ const sortOptions = (opts, key) => {
499
+ if (!key || !Array.isArray(opts)) return opts != null ? opts : [];
500
+ return [...opts].sort((a, b) => String(a[key]).localeCompare(String(b[key])));
501
+ };
502
+ useEffect3(() => {
503
+ if (value) setInput(value);
504
+ else setInput("");
505
+ }, [value]);
506
+ useEffect3(() => {
507
+ const sortedOptions = sortOptions(ops, sortKey);
508
+ setListItem(sortedOptions);
509
+ setOptions(sortedOptions);
510
+ }, [ops, sortKey]);
511
+ useEffect3(() => {
512
+ const loadFunction = async () => {
513
+ if (loadCondition && loadFunc) {
514
+ try {
515
+ const res = await loadFunc();
516
+ let newOps = res.content ? res.content : res;
517
+ newOps = newOps.filter((c) => c != null);
518
+ if (Array.isArray(newOps)) {
519
+ if (filter) {
520
+ newOps = newOps.filter((op) => op[filterField] === filter);
521
+ }
522
+ const sortedOptions = sortOptions(newOps, sortKey);
523
+ setListItem(sortedOptions);
524
+ setOptions(sortedOptions);
525
+ }
526
+ if (onLoad) {
527
+ if (onLoaded) return;
528
+ setOnLoaded(true);
529
+ onLoad(newOps);
530
+ }
531
+ } catch (e) {
532
+ setListItem([]);
533
+ }
534
+ }
535
+ };
536
+ loadFunction();
537
+ }, [loadCondition, filter, filterField, sortKey, onLoad]);
538
+ const onFieldUpdate = (val) => {
539
+ let newListItem;
540
+ if (val && val.length > 0) {
541
+ const regex = new RegExp(`${val}`, "i");
542
+ newListItem = options.filter((liI) => {
543
+ let textToTest;
544
+ if (formatationFunc) {
545
+ textToTest = formatationFunc(liI);
546
+ } else if (displayKey) {
547
+ textToTest = liI[displayKey];
548
+ } else if (displayKeys) {
549
+ textToTest = keysJoinner(liI);
550
+ } else {
551
+ textToTest = liI;
552
+ }
553
+ return regex.test(textToTest);
554
+ });
555
+ setListItem(newListItem);
556
+ } else {
557
+ setListItem(options);
558
+ }
559
+ onValueChanged && onValueChanged(val);
560
+ setInput(val);
561
+ setHide(false);
562
+ };
563
+ const clear = () => {
564
+ setInput("");
565
+ };
566
+ const onOpSelected = (li, index, lItem) => {
567
+ if (formatationFunc) {
568
+ setInput(formatationFunc(li));
569
+ } else if (displayKey) {
570
+ setInput(li[displayKey]);
571
+ } else if (displayKeys) {
572
+ setInput(keysJoinner(li));
573
+ } else {
574
+ setInput(li);
575
+ }
576
+ onSelectedClick(li, index, lItem);
577
+ setHide(true);
578
+ };
579
+ const keysJoinner = (li) => {
580
+ if (!displayKeys || !Array.isArray(displayKeys)) return "";
581
+ const textToRender = displayKeys.map((key) => `${li[key]} `);
582
+ return textToRender.join("").trim();
583
+ };
584
+ const renderMoreThanOneKey = (li, index) => {
585
+ const buildedString = keysJoinner(li);
586
+ return /* @__PURE__ */ jsx2("li", { children: buildedString }, index);
587
+ };
588
+ const boldedPart = (text, key) => {
589
+ return /* @__PURE__ */ jsx2("li", { children: text }, key);
590
+ };
591
+ const displayListItens = (li, index) => {
592
+ if (formatationFunc) {
593
+ return boldedPart(formatationFunc(li), index);
594
+ }
595
+ if (displayKey) {
596
+ return boldedPart(li[displayKey], index);
597
+ }
598
+ if (displayKeys) {
599
+ return renderMoreThanOneKey(li, index);
600
+ }
601
+ return boldedPart(li, index);
602
+ };
603
+ const onKeyDownHandler = (event) => {
604
+ if (event.key === "Escape") {
605
+ setHide(true);
606
+ onEscKeyDown && onEscKeyDown();
607
+ }
608
+ };
609
+ return /* @__PURE__ */ jsxs2(
610
+ "div",
611
+ {
612
+ className: `${className}`,
613
+ style: { marginTop: margT || 4, marginBottom: margB || 4, position: "relative" },
614
+ onBlur: (e) => {
615
+ setTimeout(() => {
616
+ if (onBlurEvent) onBlurEvent(e, input);
617
+ setHide(true);
618
+ }, 200);
619
+ },
620
+ onKeyDown: (event) => onKeyDownHandler(event),
621
+ onMouseLeave: () => {
622
+ setHide(true);
623
+ },
624
+ children: [
625
+ !hideComponent && /* @__PURE__ */ jsxs2(Fragment, { children: [
626
+ useStandardLabel && title && /* @__PURE__ */ jsxs2(Form.Label, { children: [
627
+ title,
628
+ isRequired && " *"
629
+ ] }),
630
+ /* @__PURE__ */ jsxs2(InputGroup, { children: [
631
+ useStandardLabel ? /* @__PURE__ */ jsx2(
632
+ Form.Control,
633
+ {
634
+ autoFocus: autoFocusConfig,
635
+ disabled: disableComponent || disableSelect,
636
+ placeholder: placeH,
637
+ autoComplete: "off",
638
+ value: input,
639
+ onClickCapture: () => {
640
+ setHide(false);
641
+ if (!input) {
642
+ onFieldUpdate("");
643
+ }
644
+ },
645
+ onChange: (event) => onFieldUpdate(event.currentTarget.value),
646
+ type: "text"
647
+ }
648
+ ) : /* @__PURE__ */ jsx2(FloatingLabel, { style: { zIndex: 0 }, label: title, controlId: "floatingInput", children: /* @__PURE__ */ jsx2(
649
+ Form.Control,
650
+ {
651
+ autoFocus: autoFocusConfig,
652
+ disabled: disableComponent || disableSelect,
653
+ placeholder: placeH,
654
+ autoComplete: "off",
655
+ value: input,
656
+ onClickCapture: () => {
657
+ setHide(false);
658
+ if (!input) {
659
+ onFieldUpdate("");
660
+ }
661
+ },
662
+ onChange: (event) => onFieldUpdate(event.currentTarget.value),
663
+ type: "text"
664
+ }
665
+ ) }),
666
+ !disableComponent && actionButton && actionButton(clear),
667
+ !disableComponent && actionButton2 && actionButton2(input)
668
+ ] })
669
+ ] }),
670
+ liItem && /* @__PURE__ */ jsx2(ListGroup, { className: "listgroup-autocomplete", hidden: hide, children: liItem.map((li, index) => /* @__PURE__ */ jsx2(ListGroup.Item, { action: true, onClick: () => onOpSelected(li, index, liItem), children: displayListItens(li, index) }, index)) })
671
+ ]
672
+ }
673
+ );
674
+ };
675
+ var AutoComplete_default = AutoComplete;
676
+
677
+ // src/components/recurso/QrCodeScanButton.tsx
678
+ import { useState as useState4 } from "react";
679
+ import { BsQrCode } from "react-icons/bs";
680
+
681
+ // src/components/recurso/QrReader.tsx
682
+ import QrScanner from "qr-scanner";
683
+ import { useEffect as useEffect4, useRef as useRef2, useState as useState3 } from "react";
684
+ import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
685
+ var QrReader = ({ callback }) => {
686
+ const scanner = useRef2(null);
687
+ const videoEl = useRef2(null);
688
+ const qrBoxEl = useRef2(null);
689
+ const [qrOn, setQrOn] = useState3(true);
690
+ const [scannedResult, setScannedResult] = useState3("");
691
+ const onScanSuccess = (result) => {
692
+ setScannedResult(result == null ? void 0 : result.data);
693
+ callback(result == null ? void 0 : result.data);
694
+ };
695
+ const onScanFail = (err) => {
696
+ console.error(err);
697
+ };
698
+ useEffect4(() => {
699
+ if ((videoEl == null ? void 0 : videoEl.current) && !scanner.current) {
700
+ scanner.current = new QrScanner(videoEl.current, onScanSuccess, {
701
+ onDecodeError: onScanFail,
702
+ preferredCamera: "environment",
703
+ highlightScanRegion: true,
704
+ highlightCodeOutline: true,
705
+ overlay: (qrBoxEl == null ? void 0 : qrBoxEl.current) || void 0
706
+ });
707
+ scanner.current.start().then(() => setQrOn(true)).catch((err) => {
708
+ if (err) setQrOn(false);
709
+ });
710
+ }
711
+ return () => {
712
+ var _a;
713
+ if (!(videoEl == null ? void 0 : videoEl.current)) {
714
+ (_a = scanner == null ? void 0 : scanner.current) == null ? void 0 : _a.stop();
715
+ }
716
+ };
717
+ }, []);
718
+ useEffect4(() => {
719
+ if (!qrOn)
720
+ alert(
721
+ "Camera est\xE1 bloqueada ou inacess\xEDvel. Por Favor habilite a camera nas permiss\xF5es do seu navegador e recarregue a p\xE1gina."
722
+ );
723
+ }, [qrOn]);
724
+ return /* @__PURE__ */ jsxs3("div", { className: "qr-reader", children: [
725
+ /* @__PURE__ */ jsx3("video", { ref: videoEl }),
726
+ /* @__PURE__ */ jsx3("div", { ref: qrBoxEl, className: "qr-box" }),
727
+ scannedResult && /* @__PURE__ */ jsxs3(
728
+ "p",
729
+ {
730
+ style: {
731
+ position: "absolute",
732
+ top: 0,
733
+ left: 0,
734
+ zIndex: 99999,
735
+ color: "white"
736
+ },
737
+ children: [
738
+ "Scanned Result: ",
739
+ scannedResult
740
+ ]
741
+ }
742
+ )
743
+ ] });
744
+ };
745
+ var QrReader_default = QrReader;
746
+
747
+ // src/components/recurso/QrCodeScanButton.tsx
748
+ import { jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
749
+ var QrCodeScanButton = ({ callback }) => {
750
+ const [showQr, setShowQr] = useState4(false);
751
+ const qrShowHandler = () => {
752
+ setShowQr((prev) => !prev);
753
+ };
754
+ return /* @__PURE__ */ jsxs4(
755
+ "div",
756
+ {
757
+ className: "hoverable-div",
758
+ style: {
759
+ border: "solid",
760
+ borderTopRightRadius: "3px",
761
+ borderBottomRightRadius: "3px",
762
+ padding: "8px",
763
+ borderLeft: "none",
764
+ borderColor: "#ccc",
765
+ borderWidth: "1px"
766
+ },
767
+ children: [
768
+ showQr && /* @__PURE__ */ jsx4(
769
+ QrReader_default,
770
+ {
771
+ callback: (v) => {
772
+ qrShowHandler();
773
+ callback(v);
774
+ }
775
+ }
776
+ ),
777
+ /* @__PURE__ */ jsx4(
778
+ BsQrCode,
779
+ {
780
+ size: 25,
781
+ onClick: () => {
782
+ qrShowHandler();
783
+ }
784
+ }
785
+ )
786
+ ]
787
+ }
788
+ );
789
+ };
790
+ var QrCodeScanButton_default = QrCodeScanButton;
791
+
792
+ // src/components/recurso/FindRecursoByTagField.tsx
793
+ import { jsx as jsx5 } from "react/jsx-runtime";
794
+ var FindRecursoByTagField = ({ callback }) => {
795
+ const recursoController = useHttpController("recurso");
796
+ const [selectedTag, setSelectedTag] = useState5(null);
797
+ const [reachedRecurso, setReachedRecurso] = useState5(null);
798
+ const findRecursoByTagIdHandler = async (tagId) => {
799
+ const r = await recursoController.read("findRecursoByTagId", tagId);
800
+ setReachedRecurso(r);
801
+ };
802
+ const findRecursoByTagDescriptionHandler = async (description) => {
803
+ const recurso = await recursoController.read(
804
+ "recurso/findByTagDescription",
805
+ description.replace(" ", "")
806
+ );
807
+ if (!callback) {
808
+ console.log(recurso);
809
+ } else {
810
+ callback(recurso, true);
811
+ }
812
+ };
813
+ const confirmRecursoSelectionButton = () => /* @__PURE__ */ jsx5(
814
+ "div",
815
+ {
816
+ className: "hoverable-div",
817
+ style: {
818
+ border: "solid",
819
+ borderTopRightRadius: "3px",
820
+ borderBottomRightRadius: "3px",
821
+ padding: "8px",
822
+ borderLeft: "none",
823
+ borderColor: "#ccc",
824
+ borderWidth: "1px"
825
+ },
826
+ children: /* @__PURE__ */ jsx5(GrCheckmark, { size: 25, onClick: () => callback(reachedRecurso, true) })
827
+ }
828
+ );
829
+ return /* @__PURE__ */ jsx5("div", { children: /* @__PURE__ */ jsx5(
830
+ AutoComplete_default,
831
+ {
832
+ sortKey: "id",
833
+ loadCondition: true,
834
+ loadFunc: () => recursoController.get("findActiveRecursosTags"),
835
+ displayKey: "descricao",
836
+ title: "Selecione ou Digite a TAG",
837
+ isBold: true,
838
+ actionButton: confirmRecursoSelectionButton,
839
+ actionButton2: () => /* @__PURE__ */ jsx5(
840
+ QrCodeScanButton_default,
841
+ {
842
+ callback: (description) => findRecursoByTagDescriptionHandler(description)
843
+ }
844
+ ),
845
+ onSelectedClick: (v) => {
846
+ setSelectedTag(v);
847
+ findRecursoByTagIdHandler(v.id);
848
+ },
849
+ value: selectedTag == null ? void 0 : selectedTag.descricao
850
+ }
851
+ ) });
852
+ };
853
+ var FindRecursoByTagField_default = FindRecursoByTagField;
854
+
855
+ // src/components/recurso/RecursoDisplayer.tsx
856
+ import { jsx as jsx6, jsxs as jsxs5 } from "react/jsx-runtime";
857
+ var RecursoDisplayer = ({
858
+ selectedList = [],
859
+ onSaveRecurso,
860
+ singleReturn = false
861
+ }) => {
862
+ const arvoreEstruturalController = useHttpController("arvoreEstrutural");
863
+ const branchLevelController = useHttpController("branchLevel");
864
+ const [branches, setBranches] = useState6([]);
865
+ const dispatch = useDispatch2();
866
+ const [localSelected, setLocalSelected] = useState6(selectedList);
867
+ const [selectorDisplay, setSelectorDisplay] = useState6("");
868
+ const [multiMode, setMultiMode] = useState6(false);
869
+ useEffect5(() => {
870
+ const init = async () => {
871
+ const b = await arvoreEstruturalController.get("branchByBranchLevel/1");
872
+ setBranches(b);
873
+ const lv = await branchLevelController.readAll();
874
+ dispatch(setLevels(lv));
875
+ };
876
+ init();
877
+ }, []);
878
+ const branchSetter = async (bn) => {
879
+ const copy = [...branches];
880
+ const branch = await arvoreEstruturalController.read("branch", bn.recurso.branch.id);
881
+ copy[bn.recurso.branch.branchLevel.level - 1] = {
882
+ ...branch,
883
+ nomeRecurso: bn.recurso.nome
884
+ };
885
+ setBranches(copy);
886
+ };
887
+ const backOnBranch = (branch) => {
888
+ const branchsToStay = branches.filter(
889
+ (bArray) => bArray.branchLevel.level <= branch.branchLevel.level
890
+ );
891
+ setBranches(branchsToStay);
892
+ };
893
+ return /* @__PURE__ */ jsxs5("div", { style: { width: "100%", padding: 0 }, children: [
894
+ /* @__PURE__ */ jsx6("div", { className: "d-flex justify-content-between align-items-center mb-3", children: /* @__PURE__ */ jsxs5("div", { children: [
895
+ /* @__PURE__ */ jsx6("label", { className: "me-2", children: "Selecionar Recurso Por:" }),
896
+ /* @__PURE__ */ jsx6(
897
+ Button,
898
+ {
899
+ size: "sm",
900
+ onClick: () => setSelectorDisplay("branch"),
901
+ variant: selectorDisplay === "branch" ? "primary" : "outline-primary",
902
+ className: "me-1",
903
+ children: "\xC1rvore"
904
+ }
905
+ ),
906
+ /* @__PURE__ */ jsx6(
907
+ Button,
908
+ {
909
+ size: "sm",
910
+ onClick: () => setSelectorDisplay("TAG"),
911
+ variant: selectorDisplay === "TAG" ? "primary" : "outline-primary",
912
+ children: "TAG"
913
+ }
914
+ )
915
+ ] }) }),
916
+ selectorDisplay === "branch" && branches.map((branch, i) => /* @__PURE__ */ jsx6(
917
+ BranchDropDisplay_default,
918
+ {
919
+ branch,
920
+ addBranch: branchSetter,
921
+ multiMode,
922
+ setMultiMode,
923
+ onSaveRecurso,
924
+ backOnBranch,
925
+ branches,
926
+ singleReturn
927
+ },
928
+ branch.id || i
929
+ )),
930
+ selectorDisplay === "TAG" && /* @__PURE__ */ jsx6(
931
+ FindRecursoByTagField_default,
932
+ {
933
+ callback: (rec, checked) => {
934
+ setLocalSelected([rec]);
935
+ onSaveRecurso([rec], checked);
936
+ }
937
+ }
938
+ )
939
+ ] });
940
+ };
941
+ var RecursoDisplayer_default = RecursoDisplayer;
942
+ export {
943
+ CoreServiceContext,
944
+ RecursoDisplayer_default as RecursoDisplayer,
945
+ branchLevelReducer_default as branchLevelReducer,
946
+ clearBranchLevelForm,
947
+ pickTextColorBasedOnBgColorAdvanced,
948
+ populateToEdit,
949
+ setColor,
950
+ setExcludeLevels,
951
+ setHaveComponente,
952
+ setLevel,
953
+ setLevels,
954
+ setNome,
955
+ useCoreService,
956
+ useHttpController,
957
+ useMatchingObject,
958
+ useNavigator,
959
+ useNotifications,
960
+ useToast
961
+ };