@actionexec/dashboards 0.1.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,658 +1,366 @@
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";
1
+ import { jsxs as _, jsx as l } from "react/jsx-runtime";
2
+ import { useState as N, useRef as M, useEffect as T, useCallback as R, useMemo as G } from "react";
3
+ import { J as z, z as I, G as E, m as D, u as x, H as X, k as L, t as H, r as U, d as q, w as J, v as Q, b as Z } from "./index-BHv7_r-h.js";
4
+ import { PieChart as B, Pie as ee, Cell as te, Tooltip as W, LineChart as ae, Line as re, AreaChart as le, Area as ne, BarChart as ie, Bar as se, CartesianGrid as ce, XAxis as oe, YAxis as de, Legend as he } from "recharts";
5
+ const ue = "https://action-data-api.fly.dev/api", ge = "/external/dashboards";
6
+ class pe extends Error {
7
+ constructor(r, n, t) {
8
+ super(r), this.status = n, this.payload = t, this.name = "ApiError";
8
9
  }
9
10
  }
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
- );
11
+ async function Y(a, r, n) {
12
+ const t = new URL(`${ue}${ge}${a}`);
13
+ if (n)
14
+ for (const [i, s] of Object.entries(n)) t.searchParams.set(i, s);
15
+ const e = await fetch(t.toString(), {
16
+ headers: { Authorization: `Bearer ${r}` }
17
+ });
18
+ if (!e.ok) {
19
+ let i;
20
+ try {
21
+ i = await e.json();
22
+ } catch {
30
23
  }
31
- return await o.json();
24
+ throw new pe(
25
+ `Requisicao falhou (${e.status}) em ${a}`,
26
+ e.status,
27
+ i
28
+ );
32
29
  }
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);
30
+ return await e.json();
31
+ }
32
+ const me = (a) => Y("/layout", a), _e = (a, r) => Y("/render", a, r), fe = 300;
33
+ function be(a) {
34
+ const [r, n] = N(null), [t, e] = N(null), [i, s] = N({}), [c, p] = N({}), [o, d] = N(null), [h, g] = N(!0), [w, u] = N(null), m = M(), $ = M(!1);
35
+ T(() => {
36
+ let v = !1;
37
+ return me(a).then((b) => {
38
+ v || n(b);
39
+ }).catch((b) => {
40
+ v || u(b.message);
47
41
  }), () => {
48
- y = !0;
42
+ v = !0;
49
43
  };
50
- }, []), P(() => {
51
- if (t)
52
- 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), () => {
58
- p.current && clearTimeout(p.current);
44
+ }, [a]), T(() => {
45
+ if (r)
46
+ return m.current && clearTimeout(m.current), m.current = setTimeout(() => {
47
+ const v = ve(i, c);
48
+ g(!0), _e(a, v).then((b) => {
49
+ e(b), !$.current && b.applied && ($.current = !0, s((k) => ({ ...we(b.applied), ...k }))), u(null);
50
+ }).catch((b) => u(b.message)).finally(() => g(!1));
51
+ }, fe), () => {
52
+ m.current && clearTimeout(m.current);
59
53
  };
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);
54
+ }, [a, r, i, c]);
55
+ const f = R((v, b) => {
56
+ s((k) => ({ ...k, [v]: b }));
57
+ }, []), C = R((v, b) => {
58
+ p((k) => ({ ...k, [v]: b }));
59
+ }, []), y = R((v) => {
60
+ d(v);
67
61
  }, []), S = G(
68
- () => u ?? (t == null ? void 0 : t.palette) ?? [],
69
- [u, t]
62
+ () => o ?? (r == null ? void 0 : r.palette) ?? [],
63
+ [o, r]
70
64
  );
71
65
  return {
72
- layout: t,
73
- renderData: r,
74
- loading: d,
75
- error: v,
76
- filters: s,
66
+ layout: r,
67
+ renderData: t,
68
+ loading: h,
69
+ error: w,
70
+ filters: i,
77
71
  variables: c,
78
72
  palette: S,
79
- setFilter: $,
80
- setVariable: b,
81
- setPalette: E
73
+ setFilter: f,
74
+ setVariable: C,
75
+ setPalette: y
82
76
  };
83
77
  }
84
- function pe(e, t) {
78
+ function ve(a, r) {
85
79
  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);
80
+ for (const [t, e] of Object.entries(a))
81
+ if (e.includes("|")) {
82
+ const [i, s] = e.split("|");
83
+ i && (n.f_date_start = i), s && (n.f_date_end = s);
90
84
  } 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]);
85
+ n[`f_${t}`] = e;
86
+ for (const [t, e] of Object.entries(r))
87
+ n[`v_${t}`] = String(e);
231
88
  return n;
232
89
  }
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
- };
252
- }
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: [
90
+ function we(a) {
91
+ const r = {};
92
+ for (const [n, t] of Object.entries(a))
93
+ if (t && typeof t == "object" && "start" in t) {
94
+ const e = t;
95
+ r[n] = `${e.start || ""}|${e.end || ""}`;
96
+ } else Array.isArray(t) ? r[n] = t.join(",") : typeof t == "string" && (r[n] = t);
97
+ return r;
98
+ }
99
+ function ye({ data: a, label: r }) {
100
+ const n = r || String(a.label || ""), t = String(a.formatted || "-"), e = a.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" ? "↓" : "";
101
+ return /* @__PURE__ */ _("div", { className: "widget widget-kpi", children: [
256
102
  /* @__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,
103
+ /* @__PURE__ */ l("span", { className: "widget-kpi__value", children: t }),
104
+ e && e.variance_pct != null && /* @__PURE__ */ _("div", { className: `widget-kpi__trend ${i}`, children: [
105
+ /* @__PURE__ */ _("span", { className: "widget-kpi__variance", children: [
106
+ s,
261
107
  " ",
262
- a.variance_pct > 0 ? "+" : "",
263
- a.variance_pct.toFixed(1),
108
+ e.variance_pct > 0 ? "+" : "",
109
+ e.variance_pct.toFixed(1),
264
110
  "%"
265
111
  ] }),
266
- a.label && /* @__PURE__ */ l("span", { className: "widget-kpi__trend-label", children: a.label })
112
+ e.label && /* @__PURE__ */ l("span", { className: "widget-kpi__trend-label", children: e.label })
267
113
  ] })
268
114
  ] });
269
115
  }
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" })
116
+ const Ne = "var(--bg-elevated)";
117
+ function P(a, r, n, t) {
118
+ if (t <= 0) return "";
119
+ if (t >= 1)
120
+ return `M ${a - n} ${r} A ${n} ${n} 0 0 1 ${a} ${r - n} A ${n} ${n} 0 0 1 ${a + n} ${r}`;
121
+ const e = t * Math.PI, i = a - n * Math.cos(e), s = r - n * Math.sin(e);
122
+ return `M ${a - n} ${r} A ${n} ${n} 0 0 1 ${i} ${s}`;
123
+ }
124
+ function A(a) {
125
+ const r = Math.abs(a);
126
+ return r >= 1e6 ? `${(a / 1e6).toFixed(1)}M` : r >= 1e3 ? `${(a / 1e3).toFixed(1)}K` : a.toLocaleString("pt-BR");
127
+ }
128
+ function $e({ data: a, palette: r, label: n }) {
129
+ const t = n || String(a.label || ""), e = typeof a.value == "number" ? a.value : null, i = e != null ? A(e) : "-", s = String(a.formatted || "-"), c = typeof a.ratio == "number" ? a.ratio : 0, p = a.target_value, o = a.comparison_label, d = c >= 1, h = Math.min(Math.max(c, 0), 1), g = d ? "var(--action-green)" : c >= 0.7 ? r[0] || "var(--color-info)" : c >= 0.4 ? "var(--color-warning)" : "var(--color-error)", w = p != null ? A(p) : "-", u = 50, m = 50, $ = 44, f = 10;
130
+ return /* @__PURE__ */ _("div", { className: "widget widget-gauge", children: [
131
+ /* @__PURE__ */ l("span", { className: "widget-gauge__label", children: t }),
132
+ /* @__PURE__ */ _("div", { className: "widget-gauge__chart", children: [
133
+ /* @__PURE__ */ _("svg", { viewBox: "0 0 100 56", preserveAspectRatio: "xMidYMax meet", children: [
134
+ /* @__PURE__ */ l("path", { d: P(u, m, $, 1), fill: "none", stroke: Ne, strokeWidth: f, strokeLinecap: "butt" }),
135
+ h > 0 && /* @__PURE__ */ l("path", { d: P(u, m, $, h), fill: "none", stroke: g, strokeWidth: f, strokeLinecap: "butt" })
290
136
  ] }),
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,
137
+ /* @__PURE__ */ _("div", { className: "widget-gauge__center", children: [
138
+ /* @__PURE__ */ l("span", { className: "widget-gauge__percent", children: s }),
139
+ /* @__PURE__ */ _("span", { className: "widget-gauge__comparison", children: [
140
+ i,
295
141
  " / ",
296
- v
142
+ w
297
143
  ] }),
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 })
144
+ d && /* @__PURE__ */ l("span", { className: "widget-gauge__badge", children: o || "Meta batida" }),
145
+ !d && o && /* @__PURE__ */ l("span", { className: "widget-gauge__comparison", children: o })
300
146
  ] })
301
147
  ] })
302
148
  ] });
303
149
  }
304
- const W = { fontSize: 10, fill: "var(--text-muted)" }, Te = "var(--bg-elevated)", z = {
150
+ const O = { fontSize: 10, fill: "var(--text-muted)" }, ke = "var(--bg-elevated)", V = {
305
151
  backgroundColor: "var(--bg-elevated)",
306
152
  border: "1px solid var(--bg-paper)",
307
153
  borderRadius: "6px",
308
154
  color: "var(--text-primary)"
309
- }, J = {
155
+ }, j = {
310
156
  color: "var(--text-primary)",
311
157
  fontWeight: 600
312
158
  };
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;
159
+ function K(a, r) {
160
+ var e;
161
+ const n = Array.isArray(r) ? r[0] : void 0, t = (e = n == null ? void 0 : n.payload) == null ? void 0 : e.tooltipLabel;
162
+ return typeof t == "string" && t ? t : String(a ?? "");
163
+ }
164
+ function Ce(a) {
165
+ const [r, n] = N({ width: 0, height: 0 });
166
+ return T(() => {
167
+ const t = a.current;
168
+ if (!t) return;
169
+ const e = new ResizeObserver(([i]) => {
170
+ const { width: s, height: c } = i.contentRect;
325
171
  n(
326
- (g) => g.width !== Math.floor(i) || g.height !== Math.floor(c) ? { width: Math.floor(i), height: Math.floor(c) } : g
172
+ (p) => p.width !== Math.floor(s) || p.height !== Math.floor(c) ? { width: Math.floor(s), height: Math.floor(c) } : p
327
173
  );
328
174
  });
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 }),
175
+ return e.observe(t), () => e.disconnect();
176
+ }, [a]), r;
177
+ }
178
+ function F({ Chart: a, chartData: r, xKey: n, series: t, palette: e, renderSeries: i, width: s, height: c }) {
179
+ return /* @__PURE__ */ _(a, { data: r, width: s, height: c, children: [
180
+ /* @__PURE__ */ l(ce, { strokeDasharray: "3 3", stroke: ke }),
181
+ /* @__PURE__ */ l(oe, { dataKey: n, tick: O }),
182
+ /* @__PURE__ */ l(de, { tick: O }),
337
183
  /* @__PURE__ */ l(
338
- j,
184
+ W,
339
185
  {
340
- contentStyle: z,
341
- labelStyle: J,
342
- labelFormatter: H,
186
+ contentStyle: V,
187
+ labelStyle: j,
188
+ labelFormatter: K,
343
189
  cursor: { fill: "var(--bg-paper)", opacity: 0.3 }
344
190
  }
345
191
  ),
346
- r.length > 1 && /* @__PURE__ */ l(de, {}),
347
- r.map((g, u) => s(g, a[u % a.length], u))
192
+ t.length > 1 && /* @__PURE__ */ l(he, {}),
193
+ t.map((p, o) => i(p, e[o % e.length], o))
348
194
  ] });
349
195
  }
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: [
196
+ function Se({ data: a, palette: r, label: n }) {
197
+ const t = String(a.chartType || "bar"), e = n || String(a.label || ""), i = String(a.xKey || "label"), s = a.series || [], c = a.data || [], p = M(null), { width: o, height: d } = Ce(p);
198
+ return c.length ? /* @__PURE__ */ _("div", { className: "widget widget-chart", children: [
199
+ e && /* @__PURE__ */ l("h4", { className: "widget-chart__title", children: e }),
200
+ /* @__PURE__ */ l("div", { ref: p, className: "widget-chart__container", children: (() => {
201
+ var w;
202
+ if (o <= 0 || d <= 0) return null;
203
+ if (t === "pie")
204
+ return /* @__PURE__ */ _(B, { width: o, height: d, children: [
359
205
  /* @__PURE__ */ l(
360
- B,
206
+ ee,
361
207
  {
362
208
  data: c,
363
- dataKey: ((v = i[0]) == null ? void 0 : v.key) || "s0",
364
- nameKey: s,
209
+ dataKey: ((w = s[0]) == null ? void 0 : w.key) || "s0",
210
+ nameKey: i,
365
211
  cx: "50%",
366
212
  cy: "50%",
367
213
  outerRadius: "75%",
368
- label: ({ name: h, percent: p }) => `${h}: ${(p * 100).toFixed(0)}%`,
214
+ label: ({ name: u, percent: m }) => `${u}: ${(m * 100).toFixed(0)}%`,
369
215
  labelLine: !1,
370
- children: c.map((h, p) => /* @__PURE__ */ l(ee, { fill: t[p % t.length] }, p))
216
+ children: c.map((u, m) => /* @__PURE__ */ l(te, { fill: r[m % r.length] }, m))
371
217
  }
372
218
  ),
373
219
  /* @__PURE__ */ l(
374
- j,
220
+ W,
375
221
  {
376
- contentStyle: z,
377
- labelStyle: J,
378
- labelFormatter: H
222
+ contentStyle: V,
223
+ labelStyle: j,
224
+ labelFormatter: K
379
225
  }
380
226
  )
381
227
  ] });
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,
228
+ const g = { chartData: c, xKey: i, series: s, palette: r, width: o, height: d };
229
+ return t === "line" ? /* @__PURE__ */ l(F, { ...g, Chart: ae, renderSeries: (u, m) => /* @__PURE__ */ l(
230
+ re,
385
231
  {
386
232
  type: "monotone",
387
- dataKey: h.key,
388
- name: h.label,
389
- stroke: p,
233
+ dataKey: u.key,
234
+ name: u.label,
235
+ stroke: m,
390
236
  strokeWidth: 2,
391
237
  dot: c.length <= 31
392
238
  },
393
- h.key
394
- ) }) : r === "area" ? /* @__PURE__ */ l(L, { ...f, Chart: re, renderSeries: (h, p) => /* @__PURE__ */ l(
239
+ u.key
240
+ ) }) : t === "area" ? /* @__PURE__ */ l(F, { ...g, Chart: le, renderSeries: (u, m) => /* @__PURE__ */ l(
395
241
  ne,
396
242
  {
397
243
  type: "monotone",
398
- dataKey: h.key,
399
- name: h.label,
400
- fill: p,
401
- stroke: p,
244
+ dataKey: u.key,
245
+ name: u.label,
246
+ fill: m,
247
+ stroke: m,
402
248
  fillOpacity: 0.3
403
249
  },
404
- h.key
405
- ) }) : /* @__PURE__ */ l(L, { ...f, Chart: le, renderSeries: (h, p) => /* @__PURE__ */ l(
250
+ u.key
251
+ ) }) : /* @__PURE__ */ l(F, { ...g, Chart: ie, renderSeries: (u, m) => /* @__PURE__ */ l(
406
252
  se,
407
253
  {
408
- dataKey: h.key,
409
- name: h.label,
410
- fill: p,
254
+ dataKey: u.key,
255
+ name: u.label,
256
+ fill: m,
411
257
  radius: [3, 3, 0, 0]
412
258
  },
413
- h.key
259
+ u.key
414
260
  ) });
415
261
  })() })
416
262
  ] }) : /* @__PURE__ */ l("div", { className: "widget widget-chart widget-chart--empty", children: "Sem dados" });
417
263
  }
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(
264
+ function Re({ config: a, value: r, options: n = [], dateBounds: t, onChange: e }) {
265
+ const i = a.filterType || "select", s = a.label || "Filtro", c = a.dateFilterMode || "range";
266
+ return /* @__PURE__ */ _("div", { className: "widget-filter", children: [
267
+ /* @__PURE__ */ l("label", { className: "widget-filter__label", children: s }),
268
+ i === "date_range" ? c === "yearly" ? /* @__PURE__ */ l(Fe, { value: r, dateBounds: t, onChange: e }) : c === "monthly" ? /* @__PURE__ */ l(Me, { value: r, dateBounds: t, onChange: e }) : c === "weekly" ? /* @__PURE__ */ l(Te, { value: r, dateBounds: t, onChange: e }) : /* @__PURE__ */ l(xe, { value: r, dateBounds: t, onChange: e }) : /* @__PURE__ */ l(
561
269
  Ie,
562
270
  {
563
- value: t,
271
+ value: r,
564
272
  options: n,
565
- multi: s === "multi_select",
566
- onChange: a
273
+ multi: i === "multi_select",
274
+ onChange: e
567
275
  }
568
276
  )
569
277
  ] });
570
278
  }
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: [
279
+ function xe({ value: a, dateBounds: r, onChange: n }) {
280
+ const [t, e] = a ? a.split("|") : ["", ""];
281
+ return /* @__PURE__ */ _("div", { className: "widget-filter__date-range widget-filter__date-range--stacked", children: [
574
282
  /* @__PURE__ */ l(
575
- U,
283
+ L,
576
284
  {
577
- value: r,
578
- minIso: t == null ? void 0 : t.min,
579
- maxIso: a || (t == null ? void 0 : t.max),
285
+ value: t,
286
+ minIso: r == null ? void 0 : r.min,
287
+ maxIso: e || (r == null ? void 0 : r.max),
580
288
  selectsStart: !0,
581
- startIso: r,
582
- endIso: a,
289
+ startIso: t,
290
+ endIso: e,
583
291
  placeholder: "Data inicial",
584
- onChange: (s) => n(`${s}|${a}`)
292
+ onChange: (i) => n(`${i}|${e}`)
585
293
  }
586
294
  ),
587
295
  /* @__PURE__ */ l(
588
- U,
296
+ L,
589
297
  {
590
- value: a,
591
- minIso: r || (t == null ? void 0 : t.min),
592
- maxIso: t == null ? void 0 : t.max,
298
+ value: e,
299
+ minIso: t || (r == null ? void 0 : r.min),
300
+ maxIso: r == null ? void 0 : r.max,
593
301
  selectsEnd: !0,
594
- startIso: r,
595
- endIso: a,
302
+ startIso: t,
303
+ endIso: e,
596
304
  placeholder: "Data final",
597
- onChange: (s) => n(`${r}|${s}`)
305
+ onChange: (i) => n(`${t}|${i}`)
598
306
  }
599
307
  )
600
308
  ] });
601
309
  }
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}`);
310
+ function Fe({ value: a, dateBounds: r, onChange: n }) {
311
+ const [t] = a ? a.split("|") : [""], e = z(t), i = /* @__PURE__ */ new Date(), s = (e == null ? void 0 : e.year) ?? i.getFullYear(), c = I(r), p = (o) => {
312
+ const d = U(o);
313
+ n(`${d.start}|${d.end}`);
606
314
  };
607
315
  return /* @__PURE__ */ l("div", { className: "widget-filter__date-range widget-filter__date-range--year", children: /* @__PURE__ */ l(
608
316
  "select",
609
317
  {
610
318
  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))
319
+ value: s,
320
+ onChange: (o) => p(parseInt(o.target.value)),
321
+ children: c.map((o) => /* @__PURE__ */ l("option", { value: o, children: o }, o))
614
322
  }
615
323
  ) });
616
324
  }
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}`);
325
+ function Me({ value: a, dateBounds: r, onChange: n }) {
326
+ const [t] = a ? a.split("|") : [""], e = E(t), i = /* @__PURE__ */ new Date(), s = (e == null ? void 0 : e.year) ?? i.getFullYear(), c = (e == null ? void 0 : e.month) ?? i.getMonth() + 1, p = I(r), o = (d, h) => {
327
+ const g = H(d, h);
328
+ n(`${g.start}|${g.end}`);
621
329
  };
622
- return /* @__PURE__ */ m("div", { className: "widget-filter__date-range widget-filter__date-range--month", children: [
330
+ return /* @__PURE__ */ _("div", { className: "widget-filter__date-range widget-filter__date-range--month", children: [
623
331
  /* @__PURE__ */ l(
624
332
  "select",
625
333
  {
626
334
  className: "widget-filter__select",
627
335
  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))
336
+ onChange: (d) => o(s, parseInt(d.target.value)),
337
+ children: D.map((d, h) => /* @__PURE__ */ l("option", { value: h + 1, children: d }, h + 1))
630
338
  }
631
339
  ),
632
340
  /* @__PURE__ */ l(
633
341
  "select",
634
342
  {
635
343
  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))
344
+ value: s,
345
+ onChange: (d) => o(parseInt(d.target.value), c),
346
+ children: p.map((d) => /* @__PURE__ */ l("option", { value: d, children: d }, d))
639
347
  }
640
348
  )
641
349
  ] });
642
350
  }
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: [
351
+ function Te({ value: a, dateBounds: r, onChange: n }) {
352
+ const [t] = a ? a.split("|") : [""], e = E(t), i = /* @__PURE__ */ new Date(), s = (e == null ? void 0 : e.year) ?? i.getFullYear(), c = (e == null ? void 0 : e.month) ?? i.getMonth() + 1, p = I(r), o = x(s, c), d = X(t, s, c) || 1;
353
+ return /* @__PURE__ */ _("div", { className: "widget-filter__date-range widget-filter__date-range--week", children: [
646
354
  /* @__PURE__ */ l(
647
355
  "select",
648
356
  {
649
357
  className: "widget-filter__select",
650
- value: i,
651
- onChange: (d) => {
652
- const f = parseInt(d.target.value), h = A(f, c)[0];
653
- h && n(`${h.start}|${h.end}`);
358
+ value: s,
359
+ onChange: (h) => {
360
+ const g = parseInt(h.target.value), u = x(g, c)[0];
361
+ u && n(`${u.start}|${u.end}`);
654
362
  },
655
- children: g.map((d) => /* @__PURE__ */ l("option", { value: d, children: d }, d))
363
+ children: p.map((h) => /* @__PURE__ */ l("option", { value: h, children: h }, h))
656
364
  }
657
365
  ),
658
366
  /* @__PURE__ */ l(
@@ -660,423 +368,221 @@ function Pe({ value: e, dateBounds: t, onChange: n }) {
660
368
  {
661
369
  className: "widget-filter__select",
662
370
  value: c,
663
- onChange: (d) => {
664
- const f = parseInt(d.target.value), h = A(i, f)[0];
665
- h && n(`${h.start}|${h.end}`);
371
+ onChange: (h) => {
372
+ const g = parseInt(h.target.value), u = x(s, g)[0];
373
+ u && n(`${u.start}|${u.end}`);
666
374
  },
667
- children: X.map((d, f) => /* @__PURE__ */ l("option", { value: f + 1, children: d }, f + 1))
375
+ children: D.map((h, g) => /* @__PURE__ */ l("option", { value: g + 1, children: h }, g + 1))
668
376
  }
669
377
  ),
670
378
  /* @__PURE__ */ l(
671
379
  "select",
672
380
  {
673
381
  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}`);
382
+ value: d,
383
+ onChange: (h) => {
384
+ const g = o[parseInt(h.target.value) - 1];
385
+ g && n(`${g.start}|${g.end}`);
678
386
  },
679
- children: u.map((d) => /* @__PURE__ */ l("option", { value: d.index, children: d.label }, d.index))
387
+ children: o.map((h) => /* @__PURE__ */ l("option", { value: h.index, children: h.label }, h.index))
680
388
  }
681
389
  )
682
390
  ] });
683
391
  }
684
- function Ie({ value: e, options: t, multi: n, onChange: r }) {
392
+ function Ie({ value: a, options: r, multi: n, onChange: t }) {
685
393
  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(","));
394
+ const e = a ? a.split(",") : [], i = (s) => {
395
+ const c = e.includes(s) ? e.filter((p) => p !== s) : [...e, s];
396
+ t(c.join(","));
689
397
  };
690
- return /* @__PURE__ */ l("div", { className: "widget-filter__multi", children: t.map((i) => /* @__PURE__ */ m("label", { className: "widget-filter__multi-option", children: [
398
+ return /* @__PURE__ */ l("div", { className: "widget-filter__multi", children: r.map((s) => /* @__PURE__ */ _("label", { className: "widget-filter__multi-option", children: [
691
399
  /* @__PURE__ */ l(
692
400
  "input",
693
401
  {
694
402
  type: "checkbox",
695
- checked: a.includes(i),
696
- onChange: () => s(i)
403
+ checked: e.includes(s),
404
+ onChange: () => i(s)
697
405
  }
698
406
  ),
699
- i
700
- ] }, i)) });
407
+ s
408
+ ] }, s)) });
701
409
  }
702
- return /* @__PURE__ */ m(
410
+ return /* @__PURE__ */ _(
703
411
  "select",
704
412
  {
705
413
  className: "widget-filter__select",
706
- value: e,
707
- onChange: (a) => r(a.target.value),
414
+ value: a,
415
+ onChange: (e) => t(e.target.value),
708
416
  children: [
709
417
  /* @__PURE__ */ l("option", { value: "", children: "Todos" }),
710
- t.map((a) => /* @__PURE__ */ l("option", { value: a, children: a }, a))
418
+ r.map((e) => /* @__PURE__ */ l("option", { value: e, children: e }, e))
711
419
  ]
712
420
  }
713
421
  );
714
422
  }
715
- const Re = {
423
+ const Le = {
716
424
  currency: "R$",
717
425
  percentage: "%"
718
426
  };
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: [
427
+ function Pe({ config: a, value: r, onChange: n }) {
428
+ const t = a.label || "Variavel", e = a.locked || !1, i = a.variableFormat || "number", s = Le[i] || "";
429
+ return /* @__PURE__ */ _("div", { className: `widget-variable ${e ? "widget-variable--locked" : ""}`, children: [
430
+ /* @__PURE__ */ l("label", { className: "widget-variable__label", children: t }),
431
+ /* @__PURE__ */ _("div", { className: "widget-variable__input-wrapper", children: [
724
432
  /* @__PURE__ */ l(
725
433
  "input",
726
434
  {
727
435
  className: "widget-variable__input",
728
436
  type: "number",
729
- value: t,
437
+ value: r,
730
438
  onChange: (c) => n(parseFloat(c.target.value) || 0),
731
- disabled: a,
732
- step: s === "integer" ? 1 : 0.01
439
+ disabled: e,
440
+ step: i === "integer" ? 1 : 0.01
733
441
  }
734
442
  ),
735
- i && /* @__PURE__ */ l("span", { className: "widget-variable__suffix", children: i })
443
+ s && /* @__PURE__ */ l("span", { className: "widget-variable__suffix", children: s })
736
444
  ] }),
737
- a && /* @__PURE__ */ l("span", { className: "widget-variable__lock-icon", title: "Bloqueado", children: "🔒" })
445
+ e && /* @__PURE__ */ l("span", { className: "widget-variable__lock-icon", title: "Bloqueado", children: "🔒" })
738
446
  ] });
739
447
  }
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
- }) })
448
+ function Ae({ config: a, palette: r, onChange: n }) {
449
+ const t = a.label || "Cores", e = a.locked || !1;
450
+ return /* @__PURE__ */ _("div", { className: `widget-palette ${e ? "widget-palette--locked" : ""}`, children: [
451
+ /* @__PURE__ */ l("label", { className: "widget-palette__label", children: t }),
452
+ /* @__PURE__ */ l(q, { selected: r, onSelect: n, customMode: !0, disabled: e }),
453
+ e && /* @__PURE__ */ l("span", { className: "widget-palette__lock-icon", title: "Bloqueado", children: "🔒" })
835
454
  ] });
836
455
  }
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: "🔒" })
843
- ] });
844
- }
845
- function Ke({
846
- type: e,
847
- computed: t,
456
+ function Oe({
457
+ type: a,
458
+ computed: r,
848
459
  palette: n,
849
- config: r,
850
- filterValue: a,
851
- filterOptions: s,
852
- dateBounds: i,
460
+ config: t,
461
+ filterValue: e,
462
+ filterOptions: i,
463
+ dateBounds: s,
853
464
  onFilterChange: c,
854
- variableValue: g,
855
- onVariableChange: u,
856
- onPaletteChange: o
465
+ variableValue: p,
466
+ onVariableChange: o,
467
+ onPaletteChange: d
857
468
  }) {
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) {
469
+ if (r.error)
470
+ return /* @__PURE__ */ l("div", { className: "widget widget--error", children: /* @__PURE__ */ l("span", { className: "widget__error-text", children: String(r.error) }) });
471
+ const h = J(n);
472
+ switch (a) {
862
473
  case "kpi_card":
863
- return /* @__PURE__ */ l(ye, { data: t, label: r == null ? void 0 : r.label });
474
+ return /* @__PURE__ */ l(ye, { data: r, label: t == null ? void 0 : t.label });
864
475
  case "gauge":
865
- return /* @__PURE__ */ l(Ne, { data: t, palette: d, label: r == null ? void 0 : r.label });
476
+ return /* @__PURE__ */ l($e, { data: r, palette: h, label: t == null ? void 0 : t.label });
866
477
  case "chart":
867
- return /* @__PURE__ */ l($e, { data: t, palette: d, label: r == null ? void 0 : r.label });
478
+ return /* @__PURE__ */ l(Se, { data: r, palette: h, label: t == null ? void 0 : t.label });
868
479
  case "filter":
869
- return r && c ? /* @__PURE__ */ l(
870
- Fe,
480
+ return t && c ? /* @__PURE__ */ l(
481
+ Re,
871
482
  {
872
- config: r,
873
- value: a || "",
874
- options: s,
875
- dateBounds: i,
483
+ config: t,
484
+ value: e || "",
485
+ options: i,
486
+ dateBounds: s,
876
487
  onChange: c
877
488
  }
878
489
  ) : null;
879
490
  case "variable": {
880
- const f = r;
881
- return f && u ? /* @__PURE__ */ l(
882
- Ye,
491
+ const g = t;
492
+ return g && o ? /* @__PURE__ */ l(
493
+ Pe,
883
494
  {
884
- config: f,
885
- value: g ?? f.variableValue ?? 0,
886
- onChange: u
495
+ config: g,
496
+ value: p ?? g.variableValue ?? 0,
497
+ onChange: o
887
498
  }
888
499
  ) : null;
889
500
  }
890
501
  case "color_palette":
891
- return r && o ? /* @__PURE__ */ l(
892
- Ve,
502
+ return t && d ? /* @__PURE__ */ l(
503
+ Ae,
893
504
  {
894
- config: r,
505
+ config: t,
895
506
  palette: n,
896
- onChange: o
507
+ onChange: d
897
508
  }
898
509
  ) : null;
899
510
  default:
900
- return /* @__PURE__ */ m("div", { className: "widget", children: [
511
+ return /* @__PURE__ */ _("div", { className: "widget", children: [
901
512
  "Widget: ",
902
- e
513
+ a
903
514
  ] });
904
515
  }
905
516
  }
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,
517
+ const Ee = 40, De = 6;
518
+ function Ke({
519
+ token: a,
520
+ rowHeight: r = Ee,
521
+ gridGap: n = De,
522
+ className: t
523
+ }) {
524
+ const {
525
+ layout: e,
967
526
  renderData: i,
968
- loading: c,
969
- error: g,
970
- filters: u,
527
+ loading: s,
528
+ error: c,
529
+ filters: p,
971
530
  variables: o,
972
531
  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, $ = {
532
+ setFilter: h,
533
+ setVariable: g,
534
+ setPalette: w
535
+ } = be(a);
536
+ if (c && !e)
537
+ return /* @__PURE__ */ l("div", { className: `preview-tab ${t ?? ""}`, children: /* @__PURE__ */ l("div", { className: "preview-tab__error", children: c }) });
538
+ if (!e)
539
+ return /* @__PURE__ */ l("div", { className: `preview-tab ${t ?? ""}`, children: /* @__PURE__ */ l("div", { className: "preview-tab__loading", children: "Carregando dashboard..." }) });
540
+ if (e.widgets.length === 0)
541
+ return /* @__PURE__ */ l("div", { className: `preview-tab ${t ?? ""}`, children: /* @__PURE__ */ l("div", { className: "preview-tab__empty", children: "Este dashboard nao possui widgets." }) });
542
+ const u = (i == null ? void 0 : i.widgets) ?? {}, m = (i == null ? void 0 : i.date_bounds) ?? null, $ = {
984
543
  display: "grid",
985
- gridTemplateColumns: `repeat(${s.gridColumns}, 1fr)`,
986
- gridTemplateRows: `repeat(${s.gridRows}, ${t}px)`,
544
+ gridTemplateColumns: `repeat(${e.gridColumns}, 1fr)`,
545
+ gridTemplateRows: `repeat(${e.gridRows}, ${r}px)`,
987
546
  gap: `${n}px`,
988
- // Aplica CSS vars da paleta no container — widgets descendentes usam var(--bg-*, --text-*, etc)
989
- ...we(d)
547
+ ...Q(d)
990
548
  };
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 = {
995
- gridColumn: `${b.grid.x + 1} / span ${b.grid.w}`,
996
- 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;
549
+ return /* @__PURE__ */ _("div", { className: `preview-tab ${t ?? ""}`, children: [
550
+ c && !i && /* @__PURE__ */ l("div", { className: "preview-tab__error", children: c }),
551
+ i && /* @__PURE__ */ l("div", { className: "preview-tab__grid", style: $, children: e.widgets.map((f) => {
552
+ const C = Z.has(f.type), y = u[f.id], S = {
553
+ gridColumn: `${f.grid.x + 1} / span ${f.grid.w}`,
554
+ gridRow: `${f.grid.y + 1} / span ${f.grid.h}`
555
+ }, v = f.type === "variable" ? o[f.id] ?? (y == null ? void 0 : y.value) ?? f.config.variableValue ?? 0 : void 0;
998
556
  return /* @__PURE__ */ l(
999
557
  "div",
1000
558
  {
1001
- className: `preview-tab__widget ${E ? "preview-tab__widget--control" : ""}`,
1002
- style: y,
1003
- children: E || S ? /* @__PURE__ */ l(
1004
- Ke,
559
+ className: `preview-tab__widget ${C ? "preview-tab__widget--control" : ""}`,
560
+ style: S,
561
+ children: C || y ? /* @__PURE__ */ l(
562
+ Oe,
1005
563
  {
1006
- type: b.type,
1007
- computed: S || {},
564
+ type: f.type,
565
+ computed: y || {},
1008
566
  palette: d,
1009
- 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
567
+ config: f.config,
568
+ filterValue: p[f.id] || "",
569
+ filterOptions: (y == null ? void 0 : y.available_values) || [],
570
+ dateBounds: m,
571
+ onFilterChange: (b) => h(f.id, b),
572
+ variableValue: v,
573
+ onVariableChange: (b) => g(f.id, b),
574
+ onPaletteChange: w
1017
575
  }
1018
- ) : /* @__PURE__ */ l("div", { className: "preview-tab__widget-loading", children: c ? "Carregando..." : "Sem dados" })
576
+ ) : /* @__PURE__ */ l("div", { className: "preview-tab__widget-loading", children: s ? "Carregando..." : "Sem dados" })
1019
577
  },
1020
- b.id
578
+ f.id
1021
579
  );
1022
580
  }) }),
1023
- c && i && /* @__PURE__ */ l("div", { className: "preview-tab__recalculating", children: "Atualizando..." })
581
+ s && i && /* @__PURE__ */ l("div", { className: "preview-tab__recalculating", children: "Atualizando..." })
1024
582
  ] });
1025
583
  }
1026
584
  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
585
+ pe as ApiError,
586
+ Ke as Dashboard
1081
587
  };
1082
588
  //# sourceMappingURL=index.js.map