@actionexec/dashboards 0.1.0 → 0.5.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 CHANGED
@@ -1,387 +1,207 @@
1
- import { jsxs as m, jsx as l } from "react/jsx-runtime";
2
- import { useState as T, useRef as O, useEffect as P, useCallback as F, useMemo as G } from "react";
3
- import { PieChart as Z, Pie as B, Cell as ee, Tooltip as j, LineChart as te, Line as ae, AreaChart as re, Area as ne, BarChart as le, Bar as se, CartesianGrid as ie, XAxis as ce, YAxis as oe, Legend as de } from "recharts";
4
- import ue from "react-datepicker";
5
- class ge extends Error {
6
- constructor(t, n, r) {
7
- super(t), this.status = n, this.payload = r, this.name = "ApiError";
8
- }
9
- }
10
- function fe(e) {
11
- const { apiUrl: t, token: n, fetch: r = globalThis.fetch } = e, a = e.endpointPrefix ?? "/external/dashboards", s = t.replace(/\/$/, "");
12
- async function i(c, g) {
13
- const u = new URL(`${s}${a}${c}`);
14
- if (g)
15
- for (const [d, f] of Object.entries(g)) u.searchParams.set(d, f);
16
- const o = await r(u.toString(), {
17
- headers: { Authorization: `Bearer ${n}` }
18
- });
19
- if (!o.ok) {
20
- let d;
21
- try {
22
- d = await o.json();
23
- } catch {
24
- }
25
- throw new ge(
26
- `Requisicao falhou (${o.status}) em ${c}`,
27
- o.status,
28
- d
29
- );
30
- }
31
- return await o.json();
32
- }
33
- return {
34
- layout: () => i("/layout"),
35
- render: (c) => i("/render", c)
36
- };
37
- }
38
- const he = 300;
39
- function me(e) {
40
- const [t, n] = T(null), [r, a] = T(null), [s, i] = T({}), [c, g] = T({}), [u, o] = T(null), [d, f] = T(!0), [v, h] = T(null), p = O(), k = O(!1);
41
- P(() => {
42
- let y = !1;
43
- return e.layout().then((w) => {
44
- y || n(w);
45
- }).catch((w) => {
46
- y || h(w.message);
1
+ import { jsxs as _, jsx as r } from "react/jsx-runtime";
2
+ import { useState as N, useRef as x, useEffect as T, useCallback as M, useMemo as G } from "react";
3
+ import { L as j, O as z, J as H, z as I, G as W, m as D, u as R, H as X, k as L, t as q, r as Q, d as U, w as J, v as Z, b as B } from "./index-C3jiurhg.js";
4
+ import { Q as Ke } from "./index-C3jiurhg.js";
5
+ import { PieChart as ee, Pie as te, Cell as ae, Tooltip as P, LineChart as re, Line as le, AreaChart as ne, Area as ie, BarChart as se, Bar as ce, CartesianGrid as oe, XAxis as de, YAxis as ge, Legend as he } from "recharts";
6
+ const ue = 300;
7
+ function me(l) {
8
+ const [a, n] = N(null), [t, e] = N(null), [i, s] = N({}), [c, m] = N({}), [o, d] = N(null), [g, u] = N(!0), [w, h] = N(null), p = x(), k = x(!1);
9
+ T(() => {
10
+ let v = !1;
11
+ return j(l).then((f) => {
12
+ v || n(f);
13
+ }).catch((f) => {
14
+ v || h(f.message);
47
15
  }), () => {
48
- y = !0;
16
+ v = !0;
49
17
  };
50
- }, []), P(() => {
51
- if (t)
18
+ }, [l]), T(() => {
19
+ if (a)
52
20
  return p.current && clearTimeout(p.current), p.current = setTimeout(() => {
53
- const y = pe(s, c);
54
- f(!0), e.render(y).then((w) => {
55
- a(w), !k.current && w.applied && (k.current = !0, i((N) => ({ ..._e(w.applied), ...N }))), h(null);
56
- }).catch((w) => h(w.message)).finally(() => f(!1));
57
- }, he), () => {
21
+ const v = pe(i, c);
22
+ u(!0), z(l, v).then((f) => {
23
+ e(f), !k.current && f.applied && (k.current = !0, s(($) => ({ ..._e(f.applied), ...$ }))), h(null);
24
+ }).catch((f) => h(f.message)).finally(() => u(!1));
25
+ }, ue), () => {
58
26
  p.current && clearTimeout(p.current);
59
27
  };
60
- }, [t, s, c, e]);
61
- const $ = F((y, w) => {
62
- i((N) => ({ ...N, [y]: w }));
63
- }, []), b = F((y, w) => {
64
- g((N) => ({ ...N, [y]: w }));
65
- }, []), E = F((y) => {
66
- o(y);
28
+ }, [l, a, i, c]);
29
+ const b = M((v, f) => {
30
+ s(($) => ({ ...$, [v]: f }));
31
+ }, []), C = M((v, f) => {
32
+ m(($) => ({ ...$, [v]: f }));
33
+ }, []), y = M((v) => {
34
+ d(v);
67
35
  }, []), S = G(
68
- () => u ?? (t == null ? void 0 : t.palette) ?? [],
69
- [u, t]
36
+ () => o ?? (a == null ? void 0 : a.palette) ?? [],
37
+ [o, a]
70
38
  );
71
39
  return {
72
- layout: t,
73
- renderData: r,
74
- loading: d,
75
- error: v,
76
- filters: s,
40
+ layout: a,
41
+ renderData: t,
42
+ loading: g,
43
+ error: w,
44
+ filters: i,
77
45
  variables: c,
78
46
  palette: S,
79
- setFilter: $,
80
- setVariable: b,
81
- setPalette: E
47
+ setFilter: b,
48
+ setVariable: C,
49
+ setPalette: y
82
50
  };
83
51
  }
84
- function pe(e, t) {
52
+ function pe(l, a) {
85
53
  const n = {};
86
- for (const [r, a] of Object.entries(e))
87
- if (a.includes("|")) {
88
- const [s, i] = a.split("|");
89
- s && (n.f_date_start = s), i && (n.f_date_end = i);
54
+ for (const [t, e] of Object.entries(l))
55
+ if (e.includes("|")) {
56
+ const [i, s] = e.split("|");
57
+ i && (n.f_date_start = i), s && (n.f_date_end = s);
90
58
  } else
91
- n[`f_${r}`] = a;
92
- for (const [r, a] of Object.entries(t))
93
- n[`v_${r}`] = String(a);
94
- return n;
95
- }
96
- function _e(e) {
97
- const t = {};
98
- for (const [n, r] of Object.entries(e))
99
- if (r && typeof r == "object" && "start" in r) {
100
- const a = r;
101
- t[n] = `${a.start || ""}|${a.end || ""}`;
102
- } else Array.isArray(r) ? t[n] = r.join(",") : typeof r == "string" && (t[n] = r);
103
- return t;
104
- }
105
- const _ = {
106
- series0: 0,
107
- series1: 1,
108
- series2: 2,
109
- series3: 3,
110
- series4: 4,
111
- bgDark: 5,
112
- bgPaper: 6,
113
- bgElevated: 7,
114
- textPrimary: 8,
115
- textMuted: 9,
116
- accent: 10,
117
- success: 11,
118
- error: 12
119
- }, be = 5, x = 13, ve = {
120
- series0: "Série 1",
121
- series1: "Série 2",
122
- series2: "Série 3",
123
- series3: "Série 4",
124
- series4: "Série 5",
125
- bgDark: "Fundo Escuro",
126
- bgPaper: "Fundo Cartão",
127
- bgElevated: "Fundo Elevado",
128
- textPrimary: "Texto Primário",
129
- textMuted: "Texto Secundário",
130
- accent: "Destaque",
131
- success: "Sucesso",
132
- error: "Erro"
133
- }, M = {
134
- action: {
135
- label: "Action",
136
- colors: [
137
- "#ff6b00",
138
- "#a3e635",
139
- "#e3f544",
140
- "#65ffd1",
141
- "#ff0404",
142
- "#1a1a1a",
143
- "#262626",
144
- "#333333",
145
- "#f5f5f5",
146
- "#999999",
147
- "#ff6b00",
148
- "#a3e635",
149
- "#ef4444"
150
- ]
151
- },
152
- westCoast: {
153
- label: "West Coast",
154
- colors: [
155
- "#a3b86c",
156
- "#c89b3c",
157
- "#8b6f47",
158
- "#6b8e23",
159
- "#d2691e",
160
- "#1f1a14",
161
- "#2a241b",
162
- "#3a3225",
163
- "#e8dcc4",
164
- "#a89878",
165
- "#c89b3c",
166
- "#a3b86c",
167
- "#c44536"
168
- ]
169
- },
170
- mono: {
171
- label: "Monocromático",
172
- colors: [
173
- "#f8fafc",
174
- "#cbd5e1",
175
- "#94a3b8",
176
- "#64748b",
177
- "#475569",
178
- "#0a0a0a",
179
- "#171717",
180
- "#262626",
181
- "#fafafa",
182
- "#a3a3a3",
183
- "#e5e5e5",
184
- "#cbd5e1",
185
- "#ef4444"
186
- ]
187
- },
188
- ocean: {
189
- label: "Ocean",
190
- colors: [
191
- "#0ea5e9",
192
- "#06b6d4",
193
- "#0891b2",
194
- "#3b82f6",
195
- "#22d3ee",
196
- "#0a1929",
197
- "#0f2740",
198
- "#173554",
199
- "#e0f2fe",
200
- "#7dd3fc",
201
- "#22d3ee",
202
- "#10b981",
203
- "#f43f5e"
204
- ]
205
- },
206
- princess: {
207
- label: "Cute Pink",
208
- colors: [
209
- "#ff79bc",
210
- "#a855f7",
211
- "#f472b6",
212
- "#d946ef",
213
- "#fb7185",
214
- "#fff0f6",
215
- "#ffe4ec",
216
- "#ffffff",
217
- "#ff4099",
218
- "#ffadd5",
219
- "#ec4899",
220
- "#10b981",
221
- "#e11d48"
222
- ]
223
- }
224
- }, rt = "action", V = M.action.colors;
225
- function C(e) {
226
- const t = V;
227
- if (!e || e.length === 0) return [...t];
228
- if (e.length >= x) return e.slice(0, x);
229
- const n = [...e];
230
- for (let r = e.length; r < x; r++) n.push(t[r]);
59
+ n[`f_${t}`] = e;
60
+ for (const [t, e] of Object.entries(a))
61
+ n[`v_${t}`] = String(e);
231
62
  return n;
232
63
  }
233
- function K(e) {
234
- return C(e).slice(0, be);
235
- }
236
- function we(e) {
237
- const t = C(e);
238
- return {
239
- "--bg-dark": t[_.bgDark],
240
- "--bg-paper": t[_.bgPaper],
241
- "--bg-elevated": t[_.bgElevated],
242
- "--text-primary": t[_.textPrimary],
243
- "--text-secondary": t[_.textMuted],
244
- "--text-muted": t[_.textMuted],
245
- "--action-orange": t[_.accent],
246
- "--action-green": t[_.success],
247
- "--color-success": t[_.success],
248
- "--color-error": t[_.error],
249
- "--color-info": t[_.series2],
250
- "--color-warning": t[_.series3]
251
- };
64
+ function _e(l) {
65
+ const a = {};
66
+ for (const [n, t] of Object.entries(l))
67
+ if (t && typeof t == "object" && "start" in t) {
68
+ const e = t;
69
+ a[n] = `${e.start || ""}|${e.end || ""}`;
70
+ } else Array.isArray(t) ? a[n] = t.join(",") : typeof t == "string" && (a[n] = t);
71
+ return a;
252
72
  }
253
- function ye({ data: e, label: t }) {
254
- const n = t || String(e.label || ""), r = String(e.formatted || "-"), a = e.comparison, s = (a == null ? void 0 : a.trend) === "up" ? "widget-kpi__trend--up" : (a == null ? void 0 : a.trend) === "down" ? "widget-kpi__trend--down" : "", i = (a == null ? void 0 : a.trend) === "up" ? "↑" : (a == null ? void 0 : a.trend) === "down" ? "↓" : "";
255
- return /* @__PURE__ */ m("div", { className: "widget widget-kpi", children: [
256
- /* @__PURE__ */ l("span", { className: "widget-kpi__label", children: n }),
257
- /* @__PURE__ */ l("span", { className: "widget-kpi__value", children: r }),
258
- a && a.variance_pct != null && /* @__PURE__ */ m("div", { className: `widget-kpi__trend ${s}`, children: [
259
- /* @__PURE__ */ m("span", { className: "widget-kpi__variance", children: [
260
- i,
73
+ function be({ data: l, label: a }) {
74
+ const n = a || String(l.label || ""), t = String(l.formatted || "-"), e = l.comparison, i = (e == null ? void 0 : e.trend) === "up" ? "widget-kpi__trend--up" : (e == null ? void 0 : e.trend) === "down" ? "widget-kpi__trend--down" : "", s = (e == null ? void 0 : e.trend) === "up" ? "↑" : (e == null ? void 0 : e.trend) === "down" ? "↓" : "";
75
+ return /* @__PURE__ */ _("div", { className: "widget widget-kpi", children: [
76
+ /* @__PURE__ */ r("span", { className: "widget-kpi__label", children: n }),
77
+ /* @__PURE__ */ r("span", { className: "widget-kpi__value", children: t }),
78
+ e && e.variance_pct != null && /* @__PURE__ */ _("div", { className: `widget-kpi__trend ${i}`, children: [
79
+ /* @__PURE__ */ _("span", { className: "widget-kpi__variance", children: [
80
+ s,
261
81
  " ",
262
- a.variance_pct > 0 ? "+" : "",
263
- a.variance_pct.toFixed(1),
82
+ e.variance_pct > 0 ? "+" : "",
83
+ e.variance_pct.toFixed(1),
264
84
  "%"
265
85
  ] }),
266
- a.label && /* @__PURE__ */ l("span", { className: "widget-kpi__trend-label", children: a.label })
86
+ e.label && /* @__PURE__ */ r("span", { className: "widget-kpi__trend-label", children: e.label })
267
87
  ] })
268
88
  ] });
269
89
  }
270
- const Se = "var(--bg-elevated)";
271
- function R(e, t, n, r) {
272
- if (r <= 0) return "";
273
- if (r >= 1)
274
- return `M ${e - n} ${t} A ${n} ${n} 0 0 1 ${e} ${t - n} A ${n} ${n} 0 0 1 ${e + n} ${t}`;
275
- const a = r * Math.PI, s = e - n * Math.cos(a), i = t - n * Math.sin(a);
276
- return `M ${e - n} ${t} A ${n} ${n} 0 0 1 ${s} ${i}`;
277
- }
278
- function Y(e) {
279
- const t = Math.abs(e);
280
- return t >= 1e6 ? `${(e / 1e6).toFixed(1)}M` : t >= 1e3 ? `${(e / 1e3).toFixed(1)}K` : e.toLocaleString("pt-BR");
281
- }
282
- function Ne({ data: e, palette: t, label: n }) {
283
- const r = n || String(e.label || ""), a = typeof e.value == "number" ? e.value : null, s = a != null ? Y(a) : "-", i = String(e.formatted || "-"), c = typeof e.ratio == "number" ? e.ratio : 0, g = e.target_value, u = e.comparison_label, o = c >= 1, d = Math.min(Math.max(c, 0), 1), f = o ? "var(--action-green)" : c >= 0.7 ? t[0] || "var(--color-info)" : c >= 0.4 ? "var(--color-warning)" : "var(--color-error)", v = g != null ? Y(g) : "-", h = 50, p = 50, k = 44, $ = 10;
284
- return /* @__PURE__ */ m("div", { className: "widget widget-gauge", children: [
285
- /* @__PURE__ */ l("span", { className: "widget-gauge__label", children: r }),
286
- /* @__PURE__ */ m("div", { className: "widget-gauge__chart", children: [
287
- /* @__PURE__ */ m("svg", { viewBox: "0 0 100 56", preserveAspectRatio: "xMidYMax meet", children: [
288
- /* @__PURE__ */ l("path", { d: R(h, p, k, 1), fill: "none", stroke: Se, strokeWidth: $, strokeLinecap: "butt" }),
289
- d > 0 && /* @__PURE__ */ l("path", { d: R(h, p, k, d), fill: "none", stroke: f, strokeWidth: $, strokeLinecap: "butt" })
90
+ const fe = "var(--bg-elevated)";
91
+ function O(l, a, n, t) {
92
+ if (t <= 0) return "";
93
+ if (t >= 1)
94
+ return `M ${l - n} ${a} A ${n} ${n} 0 0 1 ${l} ${a - n} A ${n} ${n} 0 0 1 ${l + n} ${a}`;
95
+ const e = t * Math.PI, i = l - n * Math.cos(e), s = a - n * Math.sin(e);
96
+ return `M ${l - n} ${a} A ${n} ${n} 0 0 1 ${i} ${s}`;
97
+ }
98
+ function A(l) {
99
+ const a = Math.abs(l);
100
+ return a >= 1e6 ? `${(l / 1e6).toFixed(1)}M` : a >= 1e3 ? `${(l / 1e3).toFixed(1)}K` : l.toLocaleString("pt-BR");
101
+ }
102
+ function ve({ data: l, palette: a, label: n }) {
103
+ const t = n || String(l.label || ""), e = typeof l.value == "number" ? l.value : null, i = e != null ? A(e) : "-", s = String(l.formatted || "-"), c = typeof l.ratio == "number" ? l.ratio : 0, m = l.target_value, o = l.comparison_label, d = c >= 1, g = Math.min(Math.max(c, 0), 1), u = d ? "var(--action-green)" : c >= 0.7 ? a[0] || "var(--color-info)" : c >= 0.4 ? "var(--color-warning)" : "var(--color-error)", w = m != null ? A(m) : "-", h = 50, p = 50, k = 44, b = 10;
104
+ return /* @__PURE__ */ _("div", { className: "widget widget-gauge", children: [
105
+ /* @__PURE__ */ r("span", { className: "widget-gauge__label", children: t }),
106
+ /* @__PURE__ */ _("div", { className: "widget-gauge__chart", children: [
107
+ /* @__PURE__ */ _("svg", { viewBox: "0 0 100 56", preserveAspectRatio: "xMidYMax meet", children: [
108
+ /* @__PURE__ */ r("path", { d: O(h, p, k, 1), fill: "none", stroke: fe, strokeWidth: b, strokeLinecap: "butt" }),
109
+ g > 0 && /* @__PURE__ */ r("path", { d: O(h, p, k, g), fill: "none", stroke: u, strokeWidth: b, strokeLinecap: "butt" })
290
110
  ] }),
291
- /* @__PURE__ */ m("div", { className: "widget-gauge__center", children: [
292
- /* @__PURE__ */ l("span", { className: "widget-gauge__percent", children: i }),
293
- /* @__PURE__ */ m("span", { className: "widget-gauge__comparison", children: [
294
- s,
111
+ /* @__PURE__ */ _("div", { className: "widget-gauge__center", children: [
112
+ /* @__PURE__ */ r("span", { className: "widget-gauge__percent", children: s }),
113
+ /* @__PURE__ */ _("span", { className: "widget-gauge__comparison", children: [
114
+ i,
295
115
  " / ",
296
- v
116
+ w
297
117
  ] }),
298
- o && /* @__PURE__ */ l("span", { className: "widget-gauge__badge", children: u || "Meta batida" }),
299
- !o && u && /* @__PURE__ */ l("span", { className: "widget-gauge__comparison", children: u })
118
+ d && /* @__PURE__ */ r("span", { className: "widget-gauge__badge", children: o || "Meta batida" }),
119
+ !d && o && /* @__PURE__ */ r("span", { className: "widget-gauge__comparison", children: o })
300
120
  ] })
301
121
  ] })
302
122
  ] });
303
123
  }
304
- const W = { fontSize: 10, fill: "var(--text-muted)" }, Te = "var(--bg-elevated)", z = {
124
+ const E = { fontSize: 10, fill: "var(--text-muted)" }, we = "var(--bg-elevated)", Y = {
305
125
  backgroundColor: "var(--bg-elevated)",
306
126
  border: "1px solid var(--bg-paper)",
307
127
  borderRadius: "6px",
308
128
  color: "var(--text-primary)"
309
- }, J = {
129
+ }, V = {
310
130
  color: "var(--text-primary)",
311
131
  fontWeight: 600
312
132
  };
313
- function H(e, t) {
314
- var a;
315
- const n = Array.isArray(t) ? t[0] : void 0, r = (a = n == null ? void 0 : n.payload) == null ? void 0 : a.tooltipLabel;
316
- return typeof r == "string" && r ? r : String(e ?? "");
317
- }
318
- function ke(e) {
319
- const [t, n] = T({ width: 0, height: 0 });
320
- return P(() => {
321
- const r = e.current;
322
- if (!r) return;
323
- const a = new ResizeObserver(([s]) => {
324
- const { width: i, height: c } = s.contentRect;
133
+ function K(l, a) {
134
+ var e;
135
+ const n = Array.isArray(a) ? a[0] : void 0, t = (e = n == null ? void 0 : n.payload) == null ? void 0 : e.tooltipLabel;
136
+ return typeof t == "string" && t ? t : String(l ?? "");
137
+ }
138
+ function ye(l) {
139
+ const [a, n] = N({ width: 0, height: 0 });
140
+ return T(() => {
141
+ const t = l.current;
142
+ if (!t) return;
143
+ const e = new ResizeObserver(([i]) => {
144
+ const { width: s, height: c } = i.contentRect;
325
145
  n(
326
- (g) => g.width !== Math.floor(i) || g.height !== Math.floor(c) ? { width: Math.floor(i), height: Math.floor(c) } : g
146
+ (m) => m.width !== Math.floor(s) || m.height !== Math.floor(c) ? { width: Math.floor(s), height: Math.floor(c) } : m
327
147
  );
328
148
  });
329
- return a.observe(r), () => a.disconnect();
330
- }, [e]), t;
331
- }
332
- function L({ Chart: e, chartData: t, xKey: n, series: r, palette: a, renderSeries: s, width: i, height: c }) {
333
- return /* @__PURE__ */ m(e, { data: t, width: i, height: c, children: [
334
- /* @__PURE__ */ l(ie, { strokeDasharray: "3 3", stroke: Te }),
335
- /* @__PURE__ */ l(ce, { dataKey: n, tick: W }),
336
- /* @__PURE__ */ l(oe, { tick: W }),
337
- /* @__PURE__ */ l(
338
- j,
149
+ return e.observe(t), () => e.disconnect();
150
+ }, [l]), a;
151
+ }
152
+ function F({ Chart: l, chartData: a, xKey: n, series: t, palette: e, renderSeries: i, width: s, height: c }) {
153
+ return /* @__PURE__ */ _(l, { data: a, width: s, height: c, children: [
154
+ /* @__PURE__ */ r(oe, { strokeDasharray: "3 3", stroke: we }),
155
+ /* @__PURE__ */ r(de, { dataKey: n, tick: E }),
156
+ /* @__PURE__ */ r(ge, { tick: E }),
157
+ /* @__PURE__ */ r(
158
+ P,
339
159
  {
340
- contentStyle: z,
341
- labelStyle: J,
342
- labelFormatter: H,
160
+ contentStyle: Y,
161
+ labelStyle: V,
162
+ labelFormatter: K,
343
163
  cursor: { fill: "var(--bg-paper)", opacity: 0.3 }
344
164
  }
345
165
  ),
346
- r.length > 1 && /* @__PURE__ */ l(de, {}),
347
- r.map((g, u) => s(g, a[u % a.length], u))
166
+ t.length > 1 && /* @__PURE__ */ r(he, {}),
167
+ t.map((m, o) => i(m, e[o % e.length], o))
348
168
  ] });
349
169
  }
350
- function $e({ data: e, palette: t, label: n }) {
351
- const r = String(e.chartType || "bar"), a = n || String(e.label || ""), s = String(e.xKey || "label"), i = e.series || [], c = e.data || [], g = O(null), { width: u, height: o } = ke(g);
352
- return c.length ? /* @__PURE__ */ m("div", { className: "widget widget-chart", children: [
353
- a && /* @__PURE__ */ l("h4", { className: "widget-chart__title", children: a }),
354
- /* @__PURE__ */ l("div", { ref: g, className: "widget-chart__container", children: (() => {
355
- var v;
356
- if (u <= 0 || o <= 0) return null;
357
- if (r === "pie")
358
- return /* @__PURE__ */ m(Z, { width: u, height: o, children: [
359
- /* @__PURE__ */ l(
360
- B,
170
+ function Ne({ data: l, palette: a, label: n }) {
171
+ const t = String(l.chartType || "bar"), e = n || String(l.label || ""), i = String(l.xKey || "label"), s = l.series || [], c = l.data || [], m = x(null), { width: o, height: d } = ye(m);
172
+ return c.length ? /* @__PURE__ */ _("div", { className: "widget widget-chart", children: [
173
+ e && /* @__PURE__ */ r("h4", { className: "widget-chart__title", children: e }),
174
+ /* @__PURE__ */ r("div", { ref: m, className: "widget-chart__container", children: (() => {
175
+ var w;
176
+ if (o <= 0 || d <= 0) return null;
177
+ if (t === "pie")
178
+ return /* @__PURE__ */ _(ee, { width: o, height: d, children: [
179
+ /* @__PURE__ */ r(
180
+ te,
361
181
  {
362
182
  data: c,
363
- dataKey: ((v = i[0]) == null ? void 0 : v.key) || "s0",
364
- nameKey: s,
183
+ dataKey: ((w = s[0]) == null ? void 0 : w.key) || "s0",
184
+ nameKey: i,
365
185
  cx: "50%",
366
186
  cy: "50%",
367
187
  outerRadius: "75%",
368
188
  label: ({ name: h, percent: p }) => `${h}: ${(p * 100).toFixed(0)}%`,
369
189
  labelLine: !1,
370
- children: c.map((h, p) => /* @__PURE__ */ l(ee, { fill: t[p % t.length] }, p))
190
+ children: c.map((h, p) => /* @__PURE__ */ r(ae, { fill: a[p % a.length] }, p))
371
191
  }
372
192
  ),
373
- /* @__PURE__ */ l(
374
- j,
193
+ /* @__PURE__ */ r(
194
+ P,
375
195
  {
376
- contentStyle: z,
377
- labelStyle: J,
378
- labelFormatter: H
196
+ contentStyle: Y,
197
+ labelStyle: V,
198
+ labelFormatter: K
379
199
  }
380
200
  )
381
201
  ] });
382
- const f = { chartData: c, xKey: s, series: i, palette: t, width: u, height: o };
383
- return r === "line" ? /* @__PURE__ */ l(L, { ...f, Chart: te, renderSeries: (h, p) => /* @__PURE__ */ l(
384
- ae,
202
+ const u = { chartData: c, xKey: i, series: s, palette: a, width: o, height: d };
203
+ return t === "line" ? /* @__PURE__ */ r(F, { ...u, Chart: re, renderSeries: (h, p) => /* @__PURE__ */ r(
204
+ le,
385
205
  {
386
206
  type: "monotone",
387
207
  dataKey: h.key,
@@ -391,8 +211,8 @@ function $e({ data: e, palette: t, label: n }) {
391
211
  dot: c.length <= 31
392
212
  },
393
213
  h.key
394
- ) }) : r === "area" ? /* @__PURE__ */ l(L, { ...f, Chart: re, renderSeries: (h, p) => /* @__PURE__ */ l(
395
- ne,
214
+ ) }) : t === "area" ? /* @__PURE__ */ r(F, { ...u, Chart: ne, renderSeries: (h, p) => /* @__PURE__ */ r(
215
+ ie,
396
216
  {
397
217
  type: "monotone",
398
218
  dataKey: h.key,
@@ -402,8 +222,8 @@ function $e({ data: e, palette: t, label: n }) {
402
222
  fillOpacity: 0.3
403
223
  },
404
224
  h.key
405
- ) }) : /* @__PURE__ */ l(L, { ...f, Chart: le, renderSeries: (h, p) => /* @__PURE__ */ l(
406
- se,
225
+ ) }) : /* @__PURE__ */ r(F, { ...u, Chart: se, renderSeries: (h, p) => /* @__PURE__ */ r(
226
+ ce,
407
227
  {
408
228
  dataKey: h.key,
409
229
  name: h.label,
@@ -413,670 +233,330 @@ function $e({ data: e, palette: t, label: n }) {
413
233
  h.key
414
234
  ) });
415
235
  })() })
416
- ] }) : /* @__PURE__ */ l("div", { className: "widget widget-chart widget-chart--empty", children: "Sem dados" });
417
- }
418
- const X = [
419
- "Jan",
420
- "Fev",
421
- "Mar",
422
- "Abr",
423
- "Mai",
424
- "Jun",
425
- "Jul",
426
- "Ago",
427
- "Set",
428
- "Out",
429
- "Nov",
430
- "Dez"
431
- ], nt = [
432
- "Janeiro",
433
- "Fevereiro",
434
- "Marco",
435
- "Abril",
436
- "Maio",
437
- "Junho",
438
- "Julho",
439
- "Agosto",
440
- "Setembro",
441
- "Outubro",
442
- "Novembro",
443
- "Dezembro"
444
- ];
445
- function De(e) {
446
- return { start: `${e}-01-01`, end: `${e}-12-31` };
447
- }
448
- function Ce(e) {
449
- if (!e) return null;
450
- const t = e.match(/^(\d{4})/);
451
- return t ? { year: parseInt(t[1]) } : null;
452
- }
453
- function Ee(e, t) {
454
- const n = new Date(e, t, 0).getDate(), r = (a) => String(a).padStart(2, "0");
455
- return {
456
- start: `${e}-${r(t)}-01`,
457
- end: `${e}-${r(t)}-${r(n)}`
458
- };
459
- }
460
- function q(e) {
461
- const t = new Date(Date.UTC(e.getFullYear(), e.getMonth(), e.getDate()));
462
- t.setUTCDate(t.getUTCDate() + 4 - (t.getUTCDay() || 7));
463
- const n = new Date(Date.UTC(t.getUTCFullYear(), 0, 1));
464
- return Math.ceil(((t.getTime() - n.getTime()) / 864e5 + 1) / 7);
465
- }
466
- function lt(e, t) {
467
- const n = new Date(e, 0, 4), r = (n.getDay() + 6) % 7, a = new Date(n.getTime() - r * 864e5), s = new Date(a.getTime() + (t - 1) * 7 * 864e5), i = new Date(s.getTime() + 6 * 864e5), c = (u) => String(u).padStart(2, "0"), g = (u) => `${u.getFullYear()}-${c(u.getMonth() + 1)}-${c(u.getDate())}`;
468
- return { start: g(s), end: g(i) };
469
- }
470
- function st(e, t) {
471
- const n = /* @__PURE__ */ new Set(), r = new Date(e, t, 0).getDate();
472
- for (let a = 1; a <= r; a++)
473
- n.add(q(new Date(e, t - 1, a)));
474
- return Array.from(n).sort((a, s) => a - s);
475
- }
476
- function A(e, t) {
477
- const n = new Date(e, t, 0).getDate(), r = (c) => String(c).padStart(2, "0"), a = [];
478
- let s = 1, i = 1;
479
- for (; s <= n; ) {
480
- const c = s, g = Math.min(s + 6, n), u = `${e}-${r(t)}-${r(c)}`, o = `${e}-${r(t)}-${r(g)}`, d = `${i}° Semana (${r(c)}/${r(t)} - ${r(g)}/${r(t)})`;
481
- a.push({ index: i, startDay: c, endDay: g, start: u, end: o, label: d }), s = g + 1, i++;
482
- }
483
- return a;
484
- }
485
- function xe(e, t, n) {
486
- if (!e) return 1;
487
- const r = (i) => String(i).padStart(2, "0"), a = e.match(new RegExp(`^${t}-${r(n)}-(\\d{2})`));
488
- if (!a) return 1;
489
- const s = parseInt(a[1]);
490
- return Math.ceil(s / 7);
491
- }
492
- function Q(e) {
493
- if (!e) return null;
494
- const t = e.match(/^(\d{4})-(\d{2})/);
495
- return t ? { year: parseInt(t[1]), month: parseInt(t[2]) } : null;
496
- }
497
- function it(e) {
498
- if (!e) return null;
499
- const t = /* @__PURE__ */ new Date(e + "T00:00:00");
500
- return isNaN(t.getTime()) ? null : { year: t.getFullYear(), week: q(t) };
501
- }
502
- function I(e) {
503
- const t = /* @__PURE__ */ new Date(), n = e != null && e.min ? parseInt(e.min.slice(0, 4)) : t.getFullYear() - 2, r = e != null && e.max ? parseInt(e.max.slice(0, 4)) : t.getFullYear(), a = [];
504
- for (let s = r; s >= n; s--) a.push(s);
505
- return a;
506
- }
507
- function D(e) {
508
- if (!e) return null;
509
- const [t, n, r] = e.split("-").map(Number);
510
- return !t || !n || !r ? null : new Date(t, n - 1, r);
511
- }
512
- function Me(e) {
513
- if (!e) return "";
514
- const t = e.getFullYear(), n = String(e.getMonth() + 1).padStart(2, "0"), r = String(e.getDate()).padStart(2, "0");
515
- return `${t}-${n}-${r}`;
516
- }
517
- function U({
518
- value: e,
519
- onChange: t,
520
- minIso: n,
521
- maxIso: r,
522
- placeholder: a,
523
- selectsStart: s,
524
- selectsEnd: i,
525
- startIso: c,
526
- endIso: g,
527
- className: u,
528
- disabled: o
529
- }) {
530
- return /* @__PURE__ */ l("div", { className: `ddp-field ${u ?? ""}`, children: /* @__PURE__ */ l(
531
- ue,
532
- {
533
- selected: D(e),
534
- onChange: (d) => t(Me(d)),
535
- selectsStart: s,
536
- selectsEnd: i,
537
- startDate: D(c) ?? void 0,
538
- endDate: D(g) ?? void 0,
539
- minDate: D(n) ?? void 0,
540
- maxDate: D(r) ?? void 0,
541
- dateFormat: "dd/MM/yyyy",
542
- placeholderText: a ?? "Selecione...",
543
- disabled: o,
544
- portalId: "ddp-portal",
545
- popperPlacement: "bottom-start",
546
- popperModifiers: [
547
- {
548
- name: "flip",
549
- options: { fallbackPlacements: ["bottom-end", "top-start", "top-end"] },
550
- fn: (d) => d
551
- }
552
- ]
553
- }
554
- ) });
555
- }
556
- function Fe({ config: e, value: t, options: n = [], dateBounds: r, onChange: a }) {
557
- const s = e.filterType || "select", i = e.label || "Filtro", c = e.dateFilterMode || "range";
558
- return /* @__PURE__ */ m("div", { className: "widget-filter", children: [
559
- /* @__PURE__ */ l("label", { className: "widget-filter__label", children: i }),
560
- s === "date_range" ? c === "yearly" ? /* @__PURE__ */ l(Ae, { value: t, dateBounds: r, onChange: a }) : c === "monthly" ? /* @__PURE__ */ l(Oe, { value: t, dateBounds: r, onChange: a }) : c === "weekly" ? /* @__PURE__ */ l(Pe, { value: t, dateBounds: r, onChange: a }) : /* @__PURE__ */ l(Le, { value: t, dateBounds: r, onChange: a }) : /* @__PURE__ */ l(
561
- Ie,
236
+ ] }) : /* @__PURE__ */ r("div", { className: "widget widget-chart widget-chart--empty", children: "Sem dados" });
237
+ }
238
+ function ke({ config: l, value: a, options: n = [], dateBounds: t, onChange: e }) {
239
+ const i = l.filterType || "select", s = l.label || "Filtro", c = l.dateFilterMode || "range";
240
+ return /* @__PURE__ */ _("div", { className: "widget-filter", children: [
241
+ /* @__PURE__ */ r("label", { className: "widget-filter__label", children: s }),
242
+ i === "date_range" ? c === "yearly" ? /* @__PURE__ */ r(Ce, { value: a, dateBounds: t, onChange: e }) : c === "monthly" ? /* @__PURE__ */ r(Se, { value: a, dateBounds: t, onChange: e }) : c === "weekly" ? /* @__PURE__ */ r(Me, { value: a, dateBounds: t, onChange: e }) : /* @__PURE__ */ r($e, { value: a, dateBounds: t, onChange: e }) : /* @__PURE__ */ r(
243
+ Re,
562
244
  {
563
- value: t,
245
+ value: a,
564
246
  options: n,
565
- multi: s === "multi_select",
566
- onChange: a
247
+ multi: i === "multi_select",
248
+ onChange: e
567
249
  }
568
250
  )
569
251
  ] });
570
252
  }
571
- function Le({ value: e, dateBounds: t, onChange: n }) {
572
- const [r, a] = e ? e.split("|") : ["", ""];
573
- return /* @__PURE__ */ m("div", { className: "widget-filter__date-range widget-filter__date-range--stacked", children: [
574
- /* @__PURE__ */ l(
575
- U,
253
+ function $e({ value: l, dateBounds: a, onChange: n }) {
254
+ const [t, e] = l ? l.split("|") : ["", ""];
255
+ return /* @__PURE__ */ _("div", { className: "widget-filter__date-range widget-filter__date-range--stacked", children: [
256
+ /* @__PURE__ */ r(
257
+ L,
576
258
  {
577
- value: r,
578
- minIso: t == null ? void 0 : t.min,
579
- maxIso: a || (t == null ? void 0 : t.max),
259
+ value: t,
260
+ minIso: a == null ? void 0 : a.min,
261
+ maxIso: e || (a == null ? void 0 : a.max),
580
262
  selectsStart: !0,
581
- startIso: r,
582
- endIso: a,
263
+ startIso: t,
264
+ endIso: e,
583
265
  placeholder: "Data inicial",
584
- onChange: (s) => n(`${s}|${a}`)
266
+ onChange: (i) => n(`${i}|${e}`)
585
267
  }
586
268
  ),
587
- /* @__PURE__ */ l(
588
- U,
269
+ /* @__PURE__ */ r(
270
+ L,
589
271
  {
590
- value: a,
591
- minIso: r || (t == null ? void 0 : t.min),
592
- maxIso: t == null ? void 0 : t.max,
272
+ value: e,
273
+ minIso: t || (a == null ? void 0 : a.min),
274
+ maxIso: a == null ? void 0 : a.max,
593
275
  selectsEnd: !0,
594
- startIso: r,
595
- endIso: a,
276
+ startIso: t,
277
+ endIso: e,
596
278
  placeholder: "Data final",
597
- onChange: (s) => n(`${r}|${s}`)
279
+ onChange: (i) => n(`${t}|${i}`)
598
280
  }
599
281
  )
600
282
  ] });
601
283
  }
602
- function Ae({ value: e, dateBounds: t, onChange: n }) {
603
- const [r] = e ? e.split("|") : [""], a = Ce(r), s = /* @__PURE__ */ new Date(), i = (a == null ? void 0 : a.year) ?? s.getFullYear(), c = I(t), g = (u) => {
604
- const o = De(u);
605
- n(`${o.start}|${o.end}`);
284
+ function Ce({ value: l, dateBounds: a, onChange: n }) {
285
+ const [t] = l ? l.split("|") : [""], e = H(t), i = /* @__PURE__ */ new Date(), s = (e == null ? void 0 : e.year) ?? i.getFullYear(), c = I(a), m = (o) => {
286
+ const d = Q(o);
287
+ n(`${d.start}|${d.end}`);
606
288
  };
607
- return /* @__PURE__ */ l("div", { className: "widget-filter__date-range widget-filter__date-range--year", children: /* @__PURE__ */ l(
289
+ return /* @__PURE__ */ r("div", { className: "widget-filter__date-range widget-filter__date-range--year", children: /* @__PURE__ */ r(
608
290
  "select",
609
291
  {
610
292
  className: "widget-filter__select",
611
- value: i,
612
- onChange: (u) => g(parseInt(u.target.value)),
613
- children: c.map((u) => /* @__PURE__ */ l("option", { value: u, children: u }, u))
293
+ value: s,
294
+ onChange: (o) => m(parseInt(o.target.value)),
295
+ children: c.map((o) => /* @__PURE__ */ r("option", { value: o, children: o }, o))
614
296
  }
615
297
  ) });
616
298
  }
617
- function Oe({ value: e, dateBounds: t, onChange: n }) {
618
- const [r] = e ? e.split("|") : [""], a = Q(r), s = /* @__PURE__ */ new Date(), i = (a == null ? void 0 : a.year) ?? s.getFullYear(), c = (a == null ? void 0 : a.month) ?? s.getMonth() + 1, g = I(t), u = (o, d) => {
619
- const f = Ee(o, d);
620
- n(`${f.start}|${f.end}`);
299
+ function Se({ value: l, dateBounds: a, onChange: n }) {
300
+ const [t] = l ? l.split("|") : [""], e = W(t), i = /* @__PURE__ */ new Date(), s = (e == null ? void 0 : e.year) ?? i.getFullYear(), c = (e == null ? void 0 : e.month) ?? i.getMonth() + 1, m = I(a), o = (d, g) => {
301
+ const u = q(d, g);
302
+ n(`${u.start}|${u.end}`);
621
303
  };
622
- return /* @__PURE__ */ m("div", { className: "widget-filter__date-range widget-filter__date-range--month", children: [
623
- /* @__PURE__ */ l(
304
+ return /* @__PURE__ */ _("div", { className: "widget-filter__date-range widget-filter__date-range--month", children: [
305
+ /* @__PURE__ */ r(
624
306
  "select",
625
307
  {
626
308
  className: "widget-filter__select",
627
309
  value: c,
628
- onChange: (o) => u(i, parseInt(o.target.value)),
629
- children: X.map((o, d) => /* @__PURE__ */ l("option", { value: d + 1, children: o }, d + 1))
310
+ onChange: (d) => o(s, parseInt(d.target.value)),
311
+ children: D.map((d, g) => /* @__PURE__ */ r("option", { value: g + 1, children: d }, g + 1))
630
312
  }
631
313
  ),
632
- /* @__PURE__ */ l(
314
+ /* @__PURE__ */ r(
633
315
  "select",
634
316
  {
635
317
  className: "widget-filter__select",
636
- value: i,
637
- onChange: (o) => u(parseInt(o.target.value), c),
638
- children: g.map((o) => /* @__PURE__ */ l("option", { value: o, children: o }, o))
318
+ value: s,
319
+ onChange: (d) => o(parseInt(d.target.value), c),
320
+ children: m.map((d) => /* @__PURE__ */ r("option", { value: d, children: d }, d))
639
321
  }
640
322
  )
641
323
  ] });
642
324
  }
643
- function Pe({ value: e, dateBounds: t, onChange: n }) {
644
- const [r] = e ? e.split("|") : [""], a = Q(r), s = /* @__PURE__ */ new Date(), i = (a == null ? void 0 : a.year) ?? s.getFullYear(), c = (a == null ? void 0 : a.month) ?? s.getMonth() + 1, g = I(t), u = A(i, c), o = xe(r, i, c) || 1;
645
- return /* @__PURE__ */ m("div", { className: "widget-filter__date-range widget-filter__date-range--week", children: [
646
- /* @__PURE__ */ l(
325
+ function Me({ value: l, dateBounds: a, onChange: n }) {
326
+ const [t] = l ? l.split("|") : [""], e = W(t), i = /* @__PURE__ */ new Date(), s = (e == null ? void 0 : e.year) ?? i.getFullYear(), c = (e == null ? void 0 : e.month) ?? i.getMonth() + 1, m = I(a), o = R(s, c), d = X(t, s, c) || 1;
327
+ return /* @__PURE__ */ _("div", { className: "widget-filter__date-range widget-filter__date-range--week", children: [
328
+ /* @__PURE__ */ r(
647
329
  "select",
648
330
  {
649
331
  className: "widget-filter__select",
650
- value: i,
651
- onChange: (d) => {
652
- const f = parseInt(d.target.value), h = A(f, c)[0];
332
+ value: s,
333
+ onChange: (g) => {
334
+ const u = parseInt(g.target.value), h = R(u, c)[0];
653
335
  h && n(`${h.start}|${h.end}`);
654
336
  },
655
- children: g.map((d) => /* @__PURE__ */ l("option", { value: d, children: d }, d))
337
+ children: m.map((g) => /* @__PURE__ */ r("option", { value: g, children: g }, g))
656
338
  }
657
339
  ),
658
- /* @__PURE__ */ l(
340
+ /* @__PURE__ */ r(
659
341
  "select",
660
342
  {
661
343
  className: "widget-filter__select",
662
344
  value: c,
663
- onChange: (d) => {
664
- const f = parseInt(d.target.value), h = A(i, f)[0];
345
+ onChange: (g) => {
346
+ const u = parseInt(g.target.value), h = R(s, u)[0];
665
347
  h && n(`${h.start}|${h.end}`);
666
348
  },
667
- children: X.map((d, f) => /* @__PURE__ */ l("option", { value: f + 1, children: d }, f + 1))
349
+ children: D.map((g, u) => /* @__PURE__ */ r("option", { value: u + 1, children: g }, u + 1))
668
350
  }
669
351
  ),
670
- /* @__PURE__ */ l(
352
+ /* @__PURE__ */ r(
671
353
  "select",
672
354
  {
673
355
  className: "widget-filter__select",
674
- value: o,
675
- onChange: (d) => {
676
- const f = u[parseInt(d.target.value) - 1];
677
- f && n(`${f.start}|${f.end}`);
356
+ value: d,
357
+ onChange: (g) => {
358
+ const u = o[parseInt(g.target.value) - 1];
359
+ u && n(`${u.start}|${u.end}`);
678
360
  },
679
- children: u.map((d) => /* @__PURE__ */ l("option", { value: d.index, children: d.label }, d.index))
361
+ children: o.map((g) => /* @__PURE__ */ r("option", { value: g.index, children: g.label }, g.index))
680
362
  }
681
363
  )
682
364
  ] });
683
365
  }
684
- function Ie({ value: e, options: t, multi: n, onChange: r }) {
366
+ function Re({ value: l, options: a, multi: n, onChange: t }) {
685
367
  if (n) {
686
- const a = e ? e.split(",") : [], s = (i) => {
687
- const c = a.includes(i) ? a.filter((g) => g !== i) : [...a, i];
688
- r(c.join(","));
368
+ const e = l ? l.split(",") : [], i = (s) => {
369
+ const c = e.includes(s) ? e.filter((m) => m !== s) : [...e, s];
370
+ t(c.join(","));
689
371
  };
690
- return /* @__PURE__ */ l("div", { className: "widget-filter__multi", children: t.map((i) => /* @__PURE__ */ m("label", { className: "widget-filter__multi-option", children: [
691
- /* @__PURE__ */ l(
372
+ return /* @__PURE__ */ r("div", { className: "widget-filter__multi", children: a.map((s) => /* @__PURE__ */ _("label", { className: "widget-filter__multi-option", children: [
373
+ /* @__PURE__ */ r(
692
374
  "input",
693
375
  {
694
376
  type: "checkbox",
695
- checked: a.includes(i),
696
- onChange: () => s(i)
377
+ checked: e.includes(s),
378
+ onChange: () => i(s)
697
379
  }
698
380
  ),
699
- i
700
- ] }, i)) });
381
+ s
382
+ ] }, s)) });
701
383
  }
702
- return /* @__PURE__ */ m(
384
+ return /* @__PURE__ */ _(
703
385
  "select",
704
386
  {
705
387
  className: "widget-filter__select",
706
- value: e,
707
- onChange: (a) => r(a.target.value),
388
+ value: l,
389
+ onChange: (e) => t(e.target.value),
708
390
  children: [
709
- /* @__PURE__ */ l("option", { value: "", children: "Todos" }),
710
- t.map((a) => /* @__PURE__ */ l("option", { value: a, children: a }, a))
391
+ /* @__PURE__ */ r("option", { value: "", children: "Todos" }),
392
+ a.map((e) => /* @__PURE__ */ r("option", { value: e, children: e }, e))
711
393
  ]
712
394
  }
713
395
  );
714
396
  }
715
- const Re = {
397
+ const Fe = {
716
398
  currency: "R$",
717
399
  percentage: "%"
718
400
  };
719
- function Ye({ config: e, value: t, onChange: n }) {
720
- const r = e.label || "Variavel", a = e.locked || !1, s = e.variableFormat || "number", i = Re[s] || "";
721
- return /* @__PURE__ */ m("div", { className: `widget-variable ${a ? "widget-variable--locked" : ""}`, children: [
722
- /* @__PURE__ */ l("label", { className: "widget-variable__label", children: r }),
723
- /* @__PURE__ */ m("div", { className: "widget-variable__input-wrapper", children: [
724
- /* @__PURE__ */ l(
401
+ function xe({ config: l, value: a, onChange: n }) {
402
+ const t = l.label || "Variavel", e = l.locked || !1, i = l.variableFormat || "number", s = Fe[i] || "";
403
+ return /* @__PURE__ */ _("div", { className: `widget-variable ${e ? "widget-variable--locked" : ""}`, children: [
404
+ /* @__PURE__ */ r("label", { className: "widget-variable__label", children: t }),
405
+ /* @__PURE__ */ _("div", { className: "widget-variable__input-wrapper", children: [
406
+ /* @__PURE__ */ r(
725
407
  "input",
726
408
  {
727
409
  className: "widget-variable__input",
728
410
  type: "number",
729
- value: t,
411
+ value: a,
730
412
  onChange: (c) => n(parseFloat(c.target.value) || 0),
731
- disabled: a,
732
- step: s === "integer" ? 1 : 0.01
413
+ disabled: e,
414
+ step: i === "integer" ? 1 : 0.01
733
415
  }
734
416
  ),
735
- i && /* @__PURE__ */ l("span", { className: "widget-variable__suffix", children: i })
417
+ s && /* @__PURE__ */ r("span", { className: "widget-variable__suffix", children: s })
736
418
  ] }),
737
- a && /* @__PURE__ */ l("span", { className: "widget-variable__lock-icon", title: "Bloqueado", children: "🔒" })
419
+ e && /* @__PURE__ */ r("span", { className: "widget-variable__lock-icon", title: "Bloqueado", children: "🔒" })
738
420
  ] });
739
421
  }
740
- const We = [
741
- _.bgDark,
742
- _.bgPaper,
743
- _.bgElevated,
744
- _.accent,
745
- _.success
746
- ];
747
- function Ue(e) {
748
- if (!e) return !0;
749
- const t = C(e);
750
- return Object.values(M).some(
751
- (n) => JSON.stringify(n.colors) === JSON.stringify(t)
752
- );
753
- }
754
- const Ge = [
755
- { label: "Series", slots: ["series0", "series1", "series2", "series3", "series4"] },
756
- { label: "Tema", slots: ["bgDark", "bgPaper", "bgElevated", "textPrimary", "textMuted"] },
757
- { label: "Estados", slots: ["accent", "success", "error"] }
758
- ];
759
- function je({
760
- selected: e,
761
- onSelect: t,
762
- customMode: n,
763
- onCustomModeChange: r,
764
- disabled: a
765
- }) {
766
- var u;
767
- const s = n ?? !Ue(e), i = C(e), c = s || (u = Object.entries(M).find(
768
- ([, o]) => JSON.stringify(o.colors) === JSON.stringify(i)
769
- )) == null ? void 0 : u[0], g = (o, d) => {
770
- const f = [...i];
771
- for (; f.length < x; ) f.push("#000000");
772
- f[o] = d, t(f);
773
- };
774
- return /* @__PURE__ */ m("div", { className: `palette-selector ${a ? "palette-selector--disabled" : ""}`, children: [
775
- r && /* @__PURE__ */ m("label", { className: "config-panel__checkbox", children: [
776
- /* @__PURE__ */ l(
777
- "input",
778
- {
779
- type: "checkbox",
780
- checked: s,
781
- onChange: (o) => r(o.target.checked),
782
- disabled: a
783
- }
784
- ),
785
- "Customizar"
786
- ] }),
787
- s ? /* @__PURE__ */ l("div", { className: "palette-selector__custom", children: Ge.map((o) => /* @__PURE__ */ m("div", { className: "palette-selector__row", children: [
788
- /* @__PURE__ */ l("span", { className: "palette-selector__row-label", children: o.label }),
789
- /* @__PURE__ */ l("div", { className: "palette-selector__row-slots", children: o.slots.map((d) => {
790
- const f = _[d];
791
- return /* @__PURE__ */ l(
792
- "input",
793
- {
794
- type: "color",
795
- className: "palette-selector__color-input",
796
- value: i[f] || "#000000",
797
- onChange: (v) => g(f, v.target.value),
798
- disabled: a,
799
- title: ve[d]
800
- },
801
- d
802
- );
803
- }) })
804
- ] }, o.label)) }) : /* @__PURE__ */ l("div", { className: "palette-selector__options", children: Object.entries(M).map(([o, d]) => {
805
- const f = C(d.colors);
806
- return /* @__PURE__ */ m(
807
- "button",
808
- {
809
- className: `palette-selector__option ${c === o ? "palette-selector__option--active" : ""}`,
810
- onClick: () => t(d.colors),
811
- disabled: a,
812
- children: [
813
- /* @__PURE__ */ l("div", { className: "palette-selector__bar", children: K(d.colors).map((v, h) => /* @__PURE__ */ l(
814
- "span",
815
- {
816
- className: "palette-selector__swatch",
817
- style: { backgroundColor: v }
818
- },
819
- h
820
- )) }),
821
- /* @__PURE__ */ l("div", { className: "palette-selector__bar palette-selector__bar--theme", children: We.map((v, h) => /* @__PURE__ */ l(
822
- "span",
823
- {
824
- className: "palette-selector__swatch",
825
- style: { backgroundColor: f[v] }
826
- },
827
- h
828
- )) }),
829
- /* @__PURE__ */ l("span", { className: "palette-selector__label", children: d.label })
830
- ]
831
- },
832
- o
833
- );
834
- }) })
835
- ] });
836
- }
837
- function Ve({ config: e, palette: t, onChange: n }) {
838
- const r = e.label || "Cores", a = e.locked || !1;
839
- return /* @__PURE__ */ m("div", { className: `widget-palette ${a ? "widget-palette--locked" : ""}`, children: [
840
- /* @__PURE__ */ l("label", { className: "widget-palette__label", children: r }),
841
- /* @__PURE__ */ l(je, { selected: t, onSelect: n, customMode: !0, disabled: a }),
842
- a && /* @__PURE__ */ l("span", { className: "widget-palette__lock-icon", title: "Bloqueado", children: "🔒" })
422
+ function Te({ config: l, palette: a, onChange: n }) {
423
+ const t = l.label || "Cores", e = l.locked || !1;
424
+ return /* @__PURE__ */ _("div", { className: `widget-palette ${e ? "widget-palette--locked" : ""}`, children: [
425
+ /* @__PURE__ */ r("label", { className: "widget-palette__label", children: t }),
426
+ /* @__PURE__ */ r(U, { selected: a, onSelect: n, customMode: !0, disabled: e }),
427
+ e && /* @__PURE__ */ r("span", { className: "widget-palette__lock-icon", title: "Bloqueado", children: "🔒" })
843
428
  ] });
844
429
  }
845
- function Ke({
846
- type: e,
847
- computed: t,
430
+ function Ie({
431
+ type: l,
432
+ computed: a,
848
433
  palette: n,
849
- config: r,
850
- filterValue: a,
851
- filterOptions: s,
852
- dateBounds: i,
434
+ config: t,
435
+ filterValue: e,
436
+ filterOptions: i,
437
+ dateBounds: s,
853
438
  onFilterChange: c,
854
- variableValue: g,
855
- onVariableChange: u,
856
- onPaletteChange: o
439
+ variableValue: m,
440
+ onVariableChange: o,
441
+ onPaletteChange: d
857
442
  }) {
858
- if (t.error)
859
- return /* @__PURE__ */ l("div", { className: "widget widget--error", children: /* @__PURE__ */ l("span", { className: "widget__error-text", children: String(t.error) }) });
860
- const d = K(n);
861
- switch (e) {
443
+ if (a.error)
444
+ return /* @__PURE__ */ r("div", { className: "widget widget--error", children: /* @__PURE__ */ r("span", { className: "widget__error-text", children: String(a.error) }) });
445
+ const g = J(n);
446
+ switch (l) {
862
447
  case "kpi_card":
863
- return /* @__PURE__ */ l(ye, { data: t, label: r == null ? void 0 : r.label });
448
+ return /* @__PURE__ */ r(be, { data: a, label: t == null ? void 0 : t.label });
864
449
  case "gauge":
865
- return /* @__PURE__ */ l(Ne, { data: t, palette: d, label: r == null ? void 0 : r.label });
450
+ return /* @__PURE__ */ r(ve, { data: a, palette: g, label: t == null ? void 0 : t.label });
866
451
  case "chart":
867
- return /* @__PURE__ */ l($e, { data: t, palette: d, label: r == null ? void 0 : r.label });
452
+ return /* @__PURE__ */ r(Ne, { data: a, palette: g, label: t == null ? void 0 : t.label });
868
453
  case "filter":
869
- return r && c ? /* @__PURE__ */ l(
870
- Fe,
454
+ return t && c ? /* @__PURE__ */ r(
455
+ ke,
871
456
  {
872
- config: r,
873
- value: a || "",
874
- options: s,
875
- dateBounds: i,
457
+ config: t,
458
+ value: e || "",
459
+ options: i,
460
+ dateBounds: s,
876
461
  onChange: c
877
462
  }
878
463
  ) : null;
879
464
  case "variable": {
880
- const f = r;
881
- return f && u ? /* @__PURE__ */ l(
882
- Ye,
465
+ const u = t;
466
+ return u && o ? /* @__PURE__ */ r(
467
+ xe,
883
468
  {
884
- config: f,
885
- value: g ?? f.variableValue ?? 0,
886
- onChange: u
469
+ config: u,
470
+ value: m ?? u.variableValue ?? 0,
471
+ onChange: o
887
472
  }
888
473
  ) : null;
889
474
  }
890
475
  case "color_palette":
891
- return r && o ? /* @__PURE__ */ l(
892
- Ve,
476
+ return t && d ? /* @__PURE__ */ r(
477
+ Te,
893
478
  {
894
- config: r,
479
+ config: t,
895
480
  palette: n,
896
- onChange: o
481
+ onChange: d
897
482
  }
898
483
  ) : null;
899
484
  default:
900
- return /* @__PURE__ */ m("div", { className: "widget", children: [
485
+ return /* @__PURE__ */ _("div", { className: "widget", children: [
901
486
  "Widget: ",
902
- e
487
+ l
903
488
  ] });
904
489
  }
905
490
  }
906
- const ze = V, Je = 30, He = 10, ct = {
907
- gridColumns: Je,
908
- gridRows: He,
909
- widgets: []
910
- }, ot = {
911
- kpi_card: "KPI Card",
912
- gauge: "Gauge",
913
- chart: "Gráfico",
914
- filter: "Filtro",
915
- variable: "Variável",
916
- color_palette: "Paleta de Cores"
917
- }, dt = ["kpi_card", "gauge", "chart"], ut = ["filter", "variable", "color_palette"], Xe = /* @__PURE__ */ new Set(["filter", "variable", "color_palette"]), gt = {
918
- sum: "Soma",
919
- avg: "Média",
920
- count: "Contagem",
921
- min: "Mínimo",
922
- max: "Máximo",
923
- count_distinct: "Contagem Distinta"
924
- }, qe = {
925
- currency: "Moeda (R$)",
926
- number: "Número",
927
- integer: "Inteiro",
928
- percentage: "Porcentagem",
929
- date: "Data",
930
- text: "Texto"
931
- }, ft = Object.entries(qe).filter(([e]) => e !== "date" && e !== "text"), ht = {
932
- yoy: "vs Ano Anterior",
933
- mom: "vs Mês Anterior",
934
- target: "vs Meta",
935
- none: "Nenhuma"
936
- }, mt = {
937
- bar: "Barras",
938
- line: "Linhas",
939
- area: "Área",
940
- pie: "Pizza"
941
- }, pt = {
942
- date_range: "Periodo",
943
- select: "Seleção Única",
944
- multi_select: "Seleção Múltipla"
945
- }, _t = {
946
- kpi_card: { x: 0, y: 0, w: 6, h: 3 },
947
- gauge: { x: 0, y: 0, w: 6, h: 5 },
948
- chart: { x: 0, y: 0, w: 6, h: 6 },
949
- filter: { x: 0, y: 0, w: 4, h: 2 },
950
- variable: { x: 0, y: 0, w: 4, h: 2 },
951
- color_palette: { x: 0, y: 0, w: 4, h: 2 }
952
- }, bt = {
953
- kpi_card: { label: "Novo KPI", aggregation: "sum", format: "number" },
954
- gauge: { label: "Novo Gauge", aggregation: "sum" },
955
- chart: { label: "Novo Grafico", chartType: "bar", xAxis: { column: "", granularity: "day" }, series: [] },
956
- filter: { label: "Novo Filtro", filterType: "select" },
957
- variable: { label: "Nova Variavel", variableValue: 0, variableFormat: "number", locked: !1 },
958
- color_palette: { label: "Paleta de Cores", paletteColors: ze, locked: !1 }
959
- }, Qe = 40, Ze = 6;
960
- function vt(e) {
961
- const { rowHeight: t = Qe, gridGap: n = Ze, className: r } = e, a = G(() => "fetcher" in e && e.fetcher ? e.fetcher : fe({ apiUrl: e.apiUrl, token: e.token }), [
962
- "fetcher" in e ? e.fetcher : null,
963
- "apiUrl" in e ? e.apiUrl : null,
964
- "token" in e ? e.token : null
965
- ]), {
966
- layout: s,
491
+ const Le = 2.5, Oe = 0.375;
492
+ function Pe({
493
+ token: l,
494
+ rowHeight: a = Le,
495
+ gridGap: n = Oe,
496
+ className: t
497
+ }) {
498
+ const {
499
+ layout: e,
967
500
  renderData: i,
968
- loading: c,
969
- error: g,
970
- filters: u,
501
+ loading: s,
502
+ error: c,
503
+ filters: m,
971
504
  variables: o,
972
505
  palette: d,
973
- setFilter: f,
974
- setVariable: v,
975
- setPalette: h
976
- } = me(a);
977
- if (g && !s)
978
- return /* @__PURE__ */ l("div", { className: `preview-tab ${r ?? ""}`, children: /* @__PURE__ */ l("div", { className: "preview-tab__error", children: g }) });
979
- if (!s)
980
- return /* @__PURE__ */ l("div", { className: `preview-tab ${r ?? ""}`, children: /* @__PURE__ */ l("div", { className: "preview-tab__loading", children: "Carregando dashboard..." }) });
981
- if (s.widgets.length === 0)
982
- return /* @__PURE__ */ l("div", { className: `preview-tab ${r ?? ""}`, children: /* @__PURE__ */ l("div", { className: "preview-tab__empty", children: "Este dashboard nao possui widgets." }) });
983
- const p = (i == null ? void 0 : i.widgets) ?? {}, k = (i == null ? void 0 : i.date_bounds) ?? null, $ = {
506
+ setFilter: g,
507
+ setVariable: u,
508
+ setPalette: w
509
+ } = me(l);
510
+ if (c && !e)
511
+ return /* @__PURE__ */ r("div", { className: `preview-tab ${t ?? ""}`, children: /* @__PURE__ */ r("div", { className: "preview-tab__error", children: c }) });
512
+ if (!e)
513
+ return /* @__PURE__ */ r("div", { className: `preview-tab ${t ?? ""}`, children: /* @__PURE__ */ r("div", { className: "preview-tab__loading", children: "Carregando dashboard..." }) });
514
+ if (e.widgets.length === 0)
515
+ return /* @__PURE__ */ r("div", { className: `preview-tab ${t ?? ""}`, children: /* @__PURE__ */ r("div", { className: "preview-tab__empty", children: "Este dashboard nao possui widgets." }) });
516
+ const h = (i == null ? void 0 : i.widgets) ?? {}, p = (i == null ? void 0 : i.date_bounds) ?? null, k = {
984
517
  display: "grid",
985
- gridTemplateColumns: `repeat(${s.gridColumns}, 1fr)`,
986
- gridTemplateRows: `repeat(${s.gridRows}, ${t}px)`,
987
- gap: `${n}px`,
988
- // Aplica CSS vars da paleta no container — widgets descendentes usam var(--bg-*, --text-*, etc)
989
- ...we(d)
518
+ gridTemplateColumns: `repeat(${e.gridColumns}, 1fr)`,
519
+ gridTemplateRows: `repeat(${e.gridRows}, ${a}rem)`,
520
+ gap: `${n}rem`,
521
+ ...Z(d)
990
522
  };
991
- return /* @__PURE__ */ m("div", { className: `preview-tab ${r ?? ""}`, children: [
992
- g && !i && /* @__PURE__ */ l("div", { className: "preview-tab__error", children: g }),
993
- i && /* @__PURE__ */ l("div", { className: "preview-tab__grid", style: $, children: s.widgets.map((b) => {
994
- const E = Xe.has(b.type), S = p[b.id], y = {
523
+ return /* @__PURE__ */ _("div", { className: `preview-tab ${t ?? ""}`, children: [
524
+ c && !i && /* @__PURE__ */ r("div", { className: "preview-tab__error", children: c }),
525
+ i && /* @__PURE__ */ r("div", { className: "preview-tab__grid", style: k, children: e.widgets.map((b) => {
526
+ const C = B.has(b.type), y = h[b.id], S = {
995
527
  gridColumn: `${b.grid.x + 1} / span ${b.grid.w}`,
996
528
  gridRow: `${b.grid.y + 1} / span ${b.grid.h}`
997
- }, w = b.type === "variable" ? o[b.id] ?? (S == null ? void 0 : S.value) ?? b.config.variableValue ?? 0 : void 0;
998
- return /* @__PURE__ */ l(
529
+ }, v = b.type === "variable" ? o[b.id] ?? (y == null ? void 0 : y.value) ?? b.config.variableValue ?? 0 : void 0;
530
+ return /* @__PURE__ */ r(
999
531
  "div",
1000
532
  {
1001
- className: `preview-tab__widget ${E ? "preview-tab__widget--control" : ""}`,
1002
- style: y,
1003
- children: E || S ? /* @__PURE__ */ l(
1004
- Ke,
533
+ className: `preview-tab__widget ${C ? "preview-tab__widget--control" : ""}`,
534
+ style: S,
535
+ children: C || y ? /* @__PURE__ */ r(
536
+ Ie,
1005
537
  {
1006
538
  type: b.type,
1007
- computed: S || {},
539
+ computed: y || {},
1008
540
  palette: d,
1009
541
  config: b.config,
1010
- filterValue: u[b.id] || "",
1011
- filterOptions: (S == null ? void 0 : S.available_values) || [],
1012
- dateBounds: k,
1013
- onFilterChange: (N) => f(b.id, N),
1014
- variableValue: w,
1015
- onVariableChange: (N) => v(b.id, N),
1016
- onPaletteChange: h
542
+ filterValue: m[b.id] || "",
543
+ filterOptions: (y == null ? void 0 : y.available_values) || [],
544
+ dateBounds: p,
545
+ onFilterChange: (f) => g(b.id, f),
546
+ variableValue: v,
547
+ onVariableChange: (f) => u(b.id, f),
548
+ onPaletteChange: w
1017
549
  }
1018
- ) : /* @__PURE__ */ l("div", { className: "preview-tab__widget-loading", children: c ? "Carregando..." : "Sem dados" })
550
+ ) : /* @__PURE__ */ r("div", { className: "preview-tab__widget-loading", children: s ? "Carregando..." : "Sem dados" })
1019
551
  },
1020
552
  b.id
1021
553
  );
1022
554
  }) }),
1023
- c && i && /* @__PURE__ */ l("div", { className: "preview-tab__recalculating", children: "Atualizando..." })
555
+ s && i && /* @__PURE__ */ r("div", { className: "preview-tab__recalculating", children: "Atualizando..." })
1024
556
  ] });
1025
557
  }
1026
558
  export {
1027
- gt as AGGREGATION_LABELS,
1028
- ge as ApiError,
1029
- mt as CHART_TYPE_LABELS,
1030
- ht as COMPARISON_LABELS,
1031
- Xe as CONTROL_WIDGET_SET,
1032
- ut as CONTROL_WIDGET_TYPES,
1033
- $e as ChartWidget,
1034
- je as ColorPaletteSelector,
1035
- Ve as ColorPaletteWidget,
1036
- dt as DATA_WIDGET_TYPES,
1037
- bt as DEFAULT_CONFIG,
1038
- _t as DEFAULT_GRID,
1039
- Je as DEFAULT_GRID_COLUMNS,
1040
- He as DEFAULT_GRID_ROWS,
1041
- ze as DEFAULT_PALETTE,
1042
- V as DEFAULT_PALETTE_COLORS,
1043
- rt as DEFAULT_PALETTE_KEY,
1044
- vt as Dashboard,
1045
- U as DashboardDatePicker,
1046
- ct as EMPTY_LAYOUT,
1047
- pt as FILTER_TYPE_LABELS,
1048
- qe as FORMAT_LABELS,
1049
- Fe as FilterWidget,
1050
- Ne as GaugeWidget,
1051
- ye as KPIWidget,
1052
- nt as MONTH_NAMES_FULL,
1053
- X as MONTH_NAMES_SHORT,
1054
- ft as NUMERIC_FORMAT_OPTIONS,
1055
- M as PALETTES,
1056
- be as SERIES_COUNT,
1057
- _ as SLOT_INDEX,
1058
- ve as SLOT_LABELS,
1059
- x as TOTAL_SLOTS,
1060
- Ye as VariableWidget,
1061
- ot as WIDGET_TYPE_LABELS,
1062
- Ke as WidgetRenderer,
1063
- fe as createTokenFetcher,
1064
- Me as dateToIso,
1065
- C as ensurePaletteShape,
1066
- De as getFullYearRange,
1067
- q as getISOWeek,
1068
- Ee as getMonthRange,
1069
- A as getMonthWeeks,
1070
- we as getPaletteCssVars,
1071
- K as getSeries,
1072
- lt as getWeekRange,
1073
- st as getWeeksInMonth,
1074
- I as getYearRange,
1075
- D as isoToDate,
1076
- Q as parseMonthFromRange,
1077
- xe as parseMonthWeekFromRange,
1078
- it as parseWeekFromRange,
1079
- Ce as parseYearFromRange,
1080
- me as useDashboardData
559
+ Ke as ApiError,
560
+ Pe as Dashboard
1081
561
  };
1082
562
  //# sourceMappingURL=index.js.map