@actionexec/dashboards 0.6.0 → 0.8.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,639 +1,757 @@
1
- import { jsxs as _, jsx as a } from "react/jsx-runtime";
2
- import { useState as k, useRef as F, useEffect as T, useCallback as R, useMemo as j } from "react";
3
- import { Q as z, R as U, n as L, L as H, G as I, I as D, m as P, w as M, J as X, k as A, q, v as Q, t as J, d as Z, y as B, x as ee, b as te } from "./ColorPaletteSelector-Bsda66uL.js";
4
- import { U as Ue } from "./ColorPaletteSelector-Bsda66uL.js";
5
- import { PieChart as ae, Pie as re, Cell as le, Tooltip as Y, LineChart as ne, Line as ie, AreaChart as se, Area as ce, BarChart as oe, Bar as de, CartesianGrid as ge, XAxis as he, YAxis as ue, Legend as me } from "recharts";
6
- const _e = 300;
7
- function be(t) {
8
- const [l, n] = k(null), [r, e] = k(null), [i, c] = k({}), [s, m] = k({}), [g, o] = k(null), [d, h] = k(!0), [w, u] = k(null), b = F(), y = F(!1);
9
- T(() => {
10
- let v = !1;
11
- return z(t).then((f) => {
12
- v || n(f);
13
- }).catch((f) => {
14
- v || u(f.message);
1
+ import { jsxs as v, jsx as l, Fragment as se } from "react/jsx-runtime";
2
+ import { useState as F, useRef as R, useEffect as P, useCallback as $, useMemo as Z } from "react";
3
+ import { a7 as ie, a8 as ce, s as G, w as V, x as K, z as oe, J as j, a0 as X, K as de, a5 as ue, $ as z, a2 as B, r as ee, U as H, a3 as he, l as U, v as ge, R as me, O as fe, e as pe, Y as _e, X as be, c as ve, y as we, B as ye, o as Se, G as q, C as ke, p as Ne } from "./ColorPaletteSelector-4eS1vsrU.js";
4
+ import { a9 as kt } from "./ColorPaletteSelector-4eS1vsrU.js";
5
+ import { PieChart as Ce, Pie as Re, Cell as $e, Tooltip as te, LineChart as xe, Line as Me, AreaChart as Fe, Area as Te, BarChart as Ae, Bar as Ee, CartesianGrid as We, XAxis as Ie, YAxis as Le, Legend as Oe } from "recharts";
6
+ const Pe = 300;
7
+ function De(t) {
8
+ const [e, a] = F(null), [n, r] = F(null), [s, c] = F({}), [i, f] = F({}), [d, g] = F(null), [o, u] = F(!0), [y, h] = F(null), b = R(), N = R(!1);
9
+ P(() => {
10
+ let k = !1;
11
+ return ie(t).then((w) => {
12
+ k || a(w);
13
+ }).catch((w) => {
14
+ k || h(w.message);
15
15
  }), () => {
16
- v = !0;
16
+ k = !0;
17
17
  };
18
- }, [t]), T(() => {
19
- if (l)
18
+ }, [t]), P(() => {
19
+ if (e)
20
20
  return b.current && clearTimeout(b.current), b.current = setTimeout(() => {
21
- const v = pe(i, s);
22
- h(!0), U(t, v).then((f) => {
23
- e(f), !y.current && f.applied && (y.current = !0, c(($) => ({ ...fe(f.applied), ...$ }))), u(null);
24
- }).catch((f) => u(f.message)).finally(() => h(!1));
25
- }, _e), () => {
21
+ const k = He(s, i);
22
+ u(!0), ce(t, k).then((w) => {
23
+ r(w), !N.current && w.applied && (N.current = !0, c((m) => ({ ...Ye(w.applied), ...m }))), h(null);
24
+ }).catch((w) => h(w.message)).finally(() => u(!1));
25
+ }, Pe), () => {
26
26
  b.current && clearTimeout(b.current);
27
27
  };
28
- }, [t, l, i, s]);
29
- const p = R((v, f) => {
30
- c(($) => ({ ...$, [v]: f }));
31
- }, []), S = R((v, f) => {
32
- m(($) => ({ ...$, [v]: f }));
33
- }, []), N = R((v) => {
34
- o(v);
35
- }, []), C = j(
36
- () => g ?? (l == null ? void 0 : l.palette) ?? [],
37
- [g, l]
28
+ }, [t, e, s, i]);
29
+ const T = $((k, w) => {
30
+ c((m) => ({ ...m, [k]: w }));
31
+ }, []), S = $((k, w) => {
32
+ f((m) => ({ ...m, [k]: w }));
33
+ }, []), O = $((k) => {
34
+ g(k);
35
+ }, []), M = Z(
36
+ () => d ?? (e == null ? void 0 : e.palette) ?? [],
37
+ [d, e]
38
38
  );
39
39
  return {
40
- layout: l,
41
- renderData: r,
42
- loading: d,
43
- error: w,
44
- filters: i,
45
- variables: s,
46
- palette: C,
47
- setFilter: p,
40
+ layout: e,
41
+ renderData: n,
42
+ loading: o,
43
+ error: y,
44
+ filters: s,
45
+ variables: i,
46
+ palette: M,
47
+ setFilter: T,
48
48
  setVariable: S,
49
- setPalette: N
49
+ setPalette: O
50
50
  };
51
51
  }
52
- function pe(t, l) {
53
- const n = {};
54
- for (const [r, e] of Object.entries(t))
55
- if (e.includes("|")) {
56
- const [i, c] = e.split("|");
57
- i && (n.f_date_start = i), c && (n.f_date_end = c);
52
+ function He(t, e) {
53
+ const a = {};
54
+ for (const [n, r] of Object.entries(t))
55
+ if (r.includes("|")) {
56
+ const [s, c] = r.split("|");
57
+ s && (a.f_date_start = s), c && (a.f_date_end = c);
58
58
  } else
59
- n[`f_${r}`] = e;
60
- for (const [r, e] of Object.entries(l))
61
- n[`v_${r}`] = String(e);
62
- return n;
59
+ a[`f_${n}`] = r;
60
+ for (const [n, r] of Object.entries(e))
61
+ a[`v_${n}`] = String(r);
62
+ return a;
63
63
  }
64
- function fe(t) {
65
- const l = {};
66
- for (const [n, r] of Object.entries(t))
67
- if (r && typeof r == "object" && "start" in r) {
68
- const e = r;
69
- l[n] = `${e.start || ""}|${e.end || ""}`;
70
- } else Array.isArray(r) ? l[n] = r.join(L) : typeof r == "string" && (l[n] = r);
71
- return l;
64
+ function Ye(t) {
65
+ const e = {};
66
+ for (const [a, n] of Object.entries(t))
67
+ if (n && typeof n == "object" && "start" in n) {
68
+ const r = n;
69
+ e[a] = `${r.start || ""}|${r.end || ""}`;
70
+ } else Array.isArray(n) ? e[a] = n.join(G) : typeof n == "string" && (e[a] = n);
71
+ return e;
72
72
  }
73
- function we({ data: t, label: l }) {
74
- const n = l || String(t.label || ""), r = String(t.formatted || "-"), e = t.comparison, i = (e == null ? void 0 : e.trend) === "up" ? "widget-kpi__trend--up" : (e == null ? void 0 : e.trend) === "down" ? "widget-kpi__trend--down" : "", c = (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__ */ a("span", { className: "widget-kpi__label", children: n }),
77
- /* @__PURE__ */ a("span", { className: "widget-kpi__value", children: r }),
78
- e && e.variance_pct != null && /* @__PURE__ */ _("div", { className: `widget-kpi__trend ${i}`, children: [
79
- /* @__PURE__ */ _("span", { className: "widget-kpi__variance", children: [
80
- c,
73
+ const Ge = (t) => {
74
+ var e, a;
75
+ return ((a = (e = t.borderBoxSize) == null ? void 0 : e[0]) == null ? void 0 : a.inlineSize) ?? t.target.offsetWidth;
76
+ }, ze = (t) => {
77
+ var e, a;
78
+ return ((a = (e = t.borderBoxSize) == null ? void 0 : e[0]) == null ? void 0 : a.blockSize) ?? t.target.offsetHeight;
79
+ };
80
+ function Ve(t, e, a) {
81
+ return t === void 0 ? 0 : t === "auto" ? oe(e, a) : Math.max(0, t);
82
+ }
83
+ function Ke(t) {
84
+ let e = t.parentElement;
85
+ for (; e && e !== document.body && e !== document.documentElement; ) {
86
+ const { overflowY: a } = getComputedStyle(e);
87
+ if (a !== "visible")
88
+ return a === "hidden" || a === "clip" ? e : null;
89
+ e = e.parentElement;
90
+ }
91
+ return null;
92
+ }
93
+ function je(t) {
94
+ const e = R(t);
95
+ e.current = t;
96
+ const a = R(null), n = R(null), r = R(null), s = R(null), c = R(null), i = R(0), f = R(0), d = R(!1), g = R(!1), o = R(-1), [u, y] = F(!1), h = $((m) => {
97
+ const _ = n.current;
98
+ if (g.current || e.current.silenceWarnings || !_) return;
99
+ const C = Ke(_);
100
+ !C || C.clientHeight >= m.gridHeight || (g.current = !0, console.warn(
101
+ `[@actionexec/dashboards] O dashboard esta sendo cortado: o container precisa de ${Math.ceil(m.gridHeight)}px de altura, mas o ancestral com overflow oculto tem ${C.clientHeight}px. A altura do dashboard varia com a largura — use a prop onGeometryChange para dimensionar o container, ou troque o overflow para auto. Passe silenceWarnings para desligar este aviso.`
102
+ ));
103
+ }, []), b = $(() => {
104
+ var I, E;
105
+ if (!a.current) return;
106
+ const { columns: m, cellAspect: _ } = e.current, C = i.current, W = K(C, m), p = {
107
+ containerWidth: C,
108
+ cellWidth: W,
109
+ cellHeight: V(W, _),
110
+ gridHeight: f.current,
111
+ stacked: d.current
112
+ }, x = c.current;
113
+ x && x.containerWidth === p.containerWidth && x.cellWidth === p.cellWidth && x.cellHeight === p.cellHeight && x.gridHeight === p.gridHeight && x.stacked === p.stacked || (c.current = p, (E = (I = e.current).onGeometryChange) == null || E.call(I, p), h(p));
114
+ }, [h]), N = $((m = !1) => {
115
+ const _ = a.current;
116
+ if (!_) return;
117
+ const C = i.current;
118
+ if (!m && C === o.current) return;
119
+ o.current = C;
120
+ const { columns: W, cellAspect: p, stackBelow: x } = e.current, A = K(C, W);
121
+ _.style.setProperty("--dash-cell-h", `${V(A, p)}px`);
122
+ const I = Ve(x, W, p), E = I > 0 && C > 0 && C < I;
123
+ E !== d.current && (d.current = E, y(E));
124
+ }, []), T = $(() => {
125
+ s.current !== null && (cancelAnimationFrame(s.current), s.current = null);
126
+ }, []), S = $(() => {
127
+ s.current === null && (s.current = requestAnimationFrame(() => {
128
+ s.current = null, N(), b();
129
+ }));
130
+ }, [N, b]), O = $((m) => {
131
+ for (const _ of m)
132
+ _.target === a.current ? i.current = Math.round(Ge(_)) : _.target === n.current && (f.current = ze(_));
133
+ S();
134
+ }, [S]), M = $(() => r.current ? r.current : typeof ResizeObserver > "u" ? null : (r.current = new ResizeObserver(O), r.current), [O]), k = $((m) => {
135
+ const _ = M();
136
+ a.current && (_ == null || _.unobserve(a.current)), a.current = m, m && (_ == null || _.observe(m), i.current = Math.round(m.getBoundingClientRect().width), N(!0), S());
137
+ }, [N, M, S]), w = $((m) => {
138
+ const _ = M();
139
+ if (n.current && (_ == null || _.unobserve(n.current)), n.current = m, !m) {
140
+ f.current = 0;
141
+ return;
142
+ }
143
+ _ == null || _.observe(m), f.current = m.getBoundingClientRect().height, S();
144
+ }, [M, S]);
145
+ return P(() => {
146
+ const m = M();
147
+ return a.current && (m == null || m.observe(a.current)), n.current && (m == null || m.observe(n.current)), () => {
148
+ var _;
149
+ (_ = r.current) == null || _.disconnect(), r.current = null, T();
150
+ };
151
+ }, [M, T]), P(() => {
152
+ a.current && (N(!0), S());
153
+ }, [t.columns, t.cellAspect, t.stackBelow, N, S]), { rootRef: k, gridRef: w, stacked: u };
154
+ }
155
+ const Xe = {
156
+ empty: "Sem dados",
157
+ error: "Não foi possível carregar",
158
+ loading: "Carregando...",
159
+ unconfigured: "Widget não configurado"
160
+ };
161
+ function re({ kind: t, message: e }) {
162
+ return /* @__PURE__ */ l("div", { className: `widget__state widget__state--${t}`, role: t === "error" ? "alert" : void 0, children: e || Xe[t] });
163
+ }
164
+ function L({ name: t, title: e, state: a, stateMessage: n, toolbar: r, children: s }) {
165
+ return /* @__PURE__ */ v("div", { className: `widget widget-${t}`, children: [
166
+ e && /* @__PURE__ */ l("span", { className: "widget__title", children: e }),
167
+ r,
168
+ a ? /* @__PURE__ */ l(re, { kind: a, message: n }) : s
169
+ ] });
170
+ }
171
+ const Ue = { up: "↑", down: "↓" };
172
+ function qe({ data: t, label: e }) {
173
+ const a = e || String(t.label || ""), n = String(t.formatted || "-"), r = t.comparison, s = (r == null ? void 0 : r.trend) ?? "", c = s === "up" || s === "down" ? ` widget-kpi__trend--${s}` : "", i = r == null ? void 0 : r.variance_pct;
174
+ return /* @__PURE__ */ v(L, { name: "kpi", title: a, children: [
175
+ /* @__PURE__ */ l("span", { className: "widget-kpi__value", children: n }),
176
+ i != null && /* @__PURE__ */ v("div", { className: `widget-kpi__trend${c}`, children: [
177
+ /* @__PURE__ */ v("span", { className: "widget-kpi__variance", children: [
178
+ Ue[s] ?? "",
81
179
  " ",
82
- e.variance_pct > 0 ? "+" : "",
83
- e.variance_pct.toFixed(1),
180
+ i > 0 ? "+" : "",
181
+ i.toFixed(1),
84
182
  "%"
85
183
  ] }),
86
- e.label && /* @__PURE__ */ a("span", { className: "widget-kpi__trend-label", children: e.label })
184
+ (r == null ? void 0 : r.label) && /* @__PURE__ */ l("span", { className: "widget-kpi__trend-label", children: r.label })
87
185
  ] })
88
186
  ] });
89
187
  }
90
- const ve = "var(--bg-elevated)";
91
- function E(t, l, n, r) {
92
- if (r <= 0) return "";
93
- if (r >= 1)
94
- return `M ${t - n} ${l} A ${n} ${n} 0 0 1 ${t} ${l - n} A ${n} ${n} 0 0 1 ${t + n} ${l}`;
95
- const e = r * Math.PI, i = t - n * Math.cos(e), c = l - n * Math.sin(e);
96
- return `M ${t - n} ${l} A ${n} ${n} 0 0 1 ${i} ${c}`;
188
+ const Je = "var(--bg-elevated)", Qe = [
189
+ [1, "var(--color-success)"],
190
+ [0.7, ""],
191
+ // vazio = cor da serie 1 (destaque do dashboard)
192
+ [0.4, "var(--color-warning)"],
193
+ [0, "var(--color-error)"]
194
+ ];
195
+ function J(t, e, a, n) {
196
+ if (n <= 0) return "";
197
+ if (n >= 1)
198
+ return `M ${t - a} ${e} A ${a} ${a} 0 0 1 ${t} ${e - a} A ${a} ${a} 0 0 1 ${t + a} ${e}`;
199
+ const r = n * Math.PI;
200
+ return `M ${t - a} ${e} A ${a} ${a} 0 0 1 ${t - a * Math.cos(r)} ${e - a * Math.sin(r)}`;
97
201
  }
98
- function O(t) {
99
- const l = Math.abs(t);
100
- return l >= 1e6 ? `${(t / 1e6).toFixed(1)}M` : l >= 1e3 ? `${(t / 1e3).toFixed(1)}K` : t.toLocaleString("pt-BR");
101
- }
102
- function ye({ data: t, palette: l, label: n }) {
103
- const r = n || String(t.label || ""), e = typeof t.value == "number" ? t.value : null, i = e != null ? O(e) : "-", c = String(t.formatted || "-"), s = typeof t.ratio == "number" ? t.ratio : 0, m = t.target_value, g = t.comparison_label, o = s >= 1, d = Math.min(Math.max(s, 0), 1), h = o ? "var(--action-green)" : s >= 0.7 ? l[0] || "var(--color-info)" : s >= 0.4 ? "var(--color-warning)" : "var(--color-error)", w = m != null ? O(m) : "-", u = 50, b = 50, y = 44, p = 10;
104
- return /* @__PURE__ */ _("div", { className: "widget widget-gauge", children: [
105
- /* @__PURE__ */ a("span", { className: "widget-gauge__label", children: r }),
106
- /* @__PURE__ */ _("div", { className: "widget-gauge__chart", children: [
107
- /* @__PURE__ */ _("svg", { viewBox: "0 0 100 56", preserveAspectRatio: "xMidYMax meet", children: [
108
- /* @__PURE__ */ a("path", { d: E(u, b, y, 1), fill: "none", stroke: ve, strokeWidth: p, strokeLinecap: "butt" }),
109
- d > 0 && /* @__PURE__ */ a("path", { d: E(u, b, y, d), fill: "none", stroke: h, strokeWidth: p, strokeLinecap: "butt" })
202
+ function Ze({ data: t, palette: e, label: a }) {
203
+ const n = a || String(t.label || ""), r = typeof t.ratio == "number" ? t.ratio : 0, s = typeof t.format == "string" ? t.format : void 0, c = String(t.value_formatted || j(t.value, s)), i = String(t.target_formatted || j(t.target_value, s)), f = String(t.formatted || "-"), d = t.comparison_label, g = r >= 1, o = Math.min(Math.max(r, 0), 1), u = Qe.find(([S]) => r >= S), y = (u == null ? void 0 : u[1]) || e[0] || "var(--color-info)", h = 50, b = 50, N = 44, T = 10;
204
+ return /* @__PURE__ */ l(L, { name: "gauge", title: n, children: /* @__PURE__ */ v("div", { className: "widget-gauge__chart", children: [
205
+ /* @__PURE__ */ v("svg", { viewBox: "0 0 100 56", preserveAspectRatio: "xMidYMax meet", role: "img", "aria-label": `${f} da meta`, children: [
206
+ /* @__PURE__ */ l("path", { d: J(h, b, N, 1), fill: "none", stroke: Je, strokeWidth: T, strokeLinecap: "butt" }),
207
+ o > 0 && /* @__PURE__ */ l("path", { d: J(h, b, N, o), fill: "none", stroke: y, strokeWidth: T, strokeLinecap: "butt" })
208
+ ] }),
209
+ /* @__PURE__ */ v("div", { className: "widget-gauge__center", children: [
210
+ /* @__PURE__ */ l("span", { className: "widget-gauge__percent", children: f }),
211
+ /* @__PURE__ */ v("span", { className: "widget-gauge__comparison", children: [
212
+ c,
213
+ " / ",
214
+ i
110
215
  ] }),
111
- /* @__PURE__ */ _("div", { className: "widget-gauge__center", children: [
112
- /* @__PURE__ */ a("span", { className: "widget-gauge__percent", children: c }),
113
- /* @__PURE__ */ _("span", { className: "widget-gauge__comparison", children: [
114
- i,
115
- " / ",
116
- w
117
- ] }),
118
- o && /* @__PURE__ */ a("span", { className: "widget-gauge__badge", children: g || "Meta batida" }),
119
- !o && g && /* @__PURE__ */ a("span", { className: "widget-gauge__comparison", children: g })
120
- ] })
216
+ g && /* @__PURE__ */ l("span", { className: "widget-gauge__badge", children: d || "Meta batida" }),
217
+ !g && d && /* @__PURE__ */ l("span", { className: "widget-gauge__comparison", children: d })
121
218
  ] })
122
- ] });
219
+ ] }) });
123
220
  }
124
- const W = { fontSize: 10, fill: "var(--text-muted)" }, Ne = "var(--bg-elevated)", V = {
221
+ const Q = { fontSize: 10, fill: "var(--text-muted)" }, Be = "var(--bg-elevated)", ae = {
125
222
  backgroundColor: "var(--bg-elevated)",
126
223
  border: "1px solid var(--bg-paper)",
127
224
  borderRadius: "6px",
128
225
  color: "var(--text-primary)"
129
- }, K = {
226
+ }, ne = {
130
227
  color: "var(--text-primary)",
131
228
  fontWeight: 600
132
229
  };
133
- function G(t, l) {
134
- var e;
135
- const n = Array.isArray(l) ? l[0] : void 0, r = (e = n == null ? void 0 : n.payload) == null ? void 0 : e.tooltipLabel;
136
- return typeof r == "string" && r ? r : String(t ?? "");
230
+ function le(t, e) {
231
+ var r;
232
+ const a = Array.isArray(e) ? e[0] : void 0, n = (r = a == null ? void 0 : a.payload) == null ? void 0 : r.tooltipLabel;
233
+ return typeof n == "string" && n ? n : String(t ?? "");
137
234
  }
138
- function ke(t) {
139
- const [l, n] = k({ width: 0, height: 0 });
140
- return T(() => {
141
- const r = t.current;
142
- if (!r) return;
143
- const e = new ResizeObserver(([i]) => {
144
- const { width: c, height: s } = i.contentRect;
145
- n(
146
- (m) => m.width !== Math.floor(c) || m.height !== Math.floor(s) ? { width: Math.floor(c), height: Math.floor(s) } : m
235
+ function et(t) {
236
+ const [e, a] = F({ width: 0, height: 0 });
237
+ return P(() => {
238
+ const n = t.current;
239
+ if (!n) return;
240
+ const r = new ResizeObserver(([s]) => {
241
+ const { width: c, height: i } = s.contentRect;
242
+ a(
243
+ (f) => f.width !== Math.floor(c) || f.height !== Math.floor(i) ? { width: Math.floor(c), height: Math.floor(i) } : f
147
244
  );
148
245
  });
149
- return e.observe(r), () => e.disconnect();
150
- }, [t]), l;
246
+ return r.observe(n), () => r.disconnect();
247
+ }, [t]), e;
151
248
  }
152
- function x({ Chart: t, chartData: l, xKey: n, series: r, palette: e, renderSeries: i, width: c, height: s }) {
153
- return /* @__PURE__ */ _(t, { data: l, width: c, height: s, children: [
154
- /* @__PURE__ */ a(ge, { strokeDasharray: "3 3", stroke: Ne }),
155
- /* @__PURE__ */ a(he, { dataKey: n, tick: W }),
156
- /* @__PURE__ */ a(ue, { tick: W }),
157
- /* @__PURE__ */ a(
158
- Y,
249
+ function Y({ Chart: t, chartData: e, xKey: a, series: n, palette: r, renderSeries: s, width: c, height: i }) {
250
+ return /* @__PURE__ */ v(t, { data: e, width: c, height: i, children: [
251
+ /* @__PURE__ */ l(We, { strokeDasharray: "3 3", stroke: Be }),
252
+ /* @__PURE__ */ l(Ie, { dataKey: a, tick: Q }),
253
+ /* @__PURE__ */ l(Le, { tick: Q }),
254
+ /* @__PURE__ */ l(
255
+ te,
159
256
  {
160
- contentStyle: V,
161
- labelStyle: K,
162
- labelFormatter: G,
257
+ contentStyle: ae,
258
+ labelStyle: ne,
259
+ labelFormatter: le,
163
260
  cursor: { fill: "var(--bg-paper)", opacity: 0.3 }
164
261
  }
165
262
  ),
166
- r.length > 1 && /* @__PURE__ */ a(me, {}),
167
- r.map((m, g) => i(m, e[g % e.length], g))
263
+ n.length > 1 && /* @__PURE__ */ l(Oe, {}),
264
+ n.map((f, d) => s(f, r[d % r.length], d))
168
265
  ] });
169
266
  }
170
- function $e({ data: t, palette: l, label: n }) {
171
- const r = String(t.chartType || "bar"), e = n || String(t.label || ""), i = String(t.xKey || "label"), c = t.series || [], s = t.data || [], m = F(null), { width: g, height: o } = ke(m), d = () => {
172
- var w;
173
- if (g <= 0 || o <= 0) return null;
174
- if (r === "pie")
175
- return /* @__PURE__ */ _(ae, { width: g, height: o, children: [
176
- /* @__PURE__ */ a(
177
- re,
267
+ function tt({ data: t, palette: e, label: a }) {
268
+ const n = String(t.chartType || "bar"), r = a || String(t.label || ""), s = String(t.xKey || "label"), c = t.series || [], i = t.data || [], f = R(null), { width: d, height: g } = et(f), o = () => {
269
+ var y;
270
+ if (d <= 0 || g <= 0) return null;
271
+ if (n === "pie")
272
+ return /* @__PURE__ */ v(Ce, { width: d, height: g, children: [
273
+ /* @__PURE__ */ l(
274
+ Re,
178
275
  {
179
- data: s,
180
- dataKey: ((w = c[0]) == null ? void 0 : w.key) || "s0",
181
- nameKey: i,
276
+ data: i,
277
+ dataKey: ((y = c[0]) == null ? void 0 : y.key) || "s0",
278
+ nameKey: s,
182
279
  cx: "50%",
183
280
  cy: "50%",
184
281
  outerRadius: "75%",
185
- label: ({ name: u, percent: b }) => `${u}: ${(b * 100).toFixed(0)}%`,
282
+ label: ({ name: h, percent: b }) => `${h}: ${(b * 100).toFixed(0)}%`,
186
283
  labelLine: !1,
187
- children: s.map((u, b) => /* @__PURE__ */ a(le, { fill: l[b % l.length] }, b))
284
+ children: i.map((h, b) => /* @__PURE__ */ l($e, { fill: e[b % e.length] }, b))
188
285
  }
189
286
  ),
190
- /* @__PURE__ */ a(
191
- Y,
287
+ /* @__PURE__ */ l(
288
+ te,
192
289
  {
193
- contentStyle: V,
194
- labelStyle: K,
195
- labelFormatter: G
290
+ contentStyle: ae,
291
+ labelStyle: ne,
292
+ labelFormatter: le
196
293
  }
197
294
  )
198
295
  ] });
199
- const h = { chartData: s, xKey: i, series: c, palette: l, width: g, height: o };
200
- return r === "line" ? /* @__PURE__ */ a(x, { ...h, Chart: ne, renderSeries: (u, b) => /* @__PURE__ */ a(
201
- ie,
296
+ const u = { chartData: i, xKey: s, series: c, palette: e, width: d, height: g };
297
+ return n === "line" ? /* @__PURE__ */ l(Y, { ...u, Chart: xe, renderSeries: (h, b) => /* @__PURE__ */ l(
298
+ Me,
202
299
  {
203
300
  type: "monotone",
204
- dataKey: u.key,
205
- name: u.label,
301
+ dataKey: h.key,
302
+ name: h.label,
206
303
  stroke: b,
207
304
  strokeWidth: 2,
208
- dot: s.length <= 31
305
+ dot: i.length <= 31
209
306
  },
210
- u.key
211
- ) }) : r === "area" ? /* @__PURE__ */ a(x, { ...h, Chart: se, renderSeries: (u, b) => /* @__PURE__ */ a(
212
- ce,
307
+ h.key
308
+ ) }) : n === "area" ? /* @__PURE__ */ l(Y, { ...u, Chart: Fe, renderSeries: (h, b) => /* @__PURE__ */ l(
309
+ Te,
213
310
  {
214
311
  type: "monotone",
215
- dataKey: u.key,
216
- name: u.label,
312
+ dataKey: h.key,
313
+ name: h.label,
217
314
  fill: b,
218
315
  stroke: b,
219
316
  fillOpacity: 0.3
220
317
  },
221
- u.key
222
- ) }) : /* @__PURE__ */ a(x, { ...h, Chart: oe, renderSeries: (u, b) => /* @__PURE__ */ a(
223
- de,
318
+ h.key
319
+ ) }) : /* @__PURE__ */ l(Y, { ...u, Chart: Ae, renderSeries: (h, b) => /* @__PURE__ */ l(
320
+ Ee,
224
321
  {
225
- dataKey: u.key,
226
- name: u.label,
322
+ dataKey: h.key,
323
+ name: h.label,
227
324
  fill: b,
228
325
  radius: [3, 3, 0, 0]
229
326
  },
230
- u.key
327
+ h.key
231
328
  ) });
232
329
  };
233
- return /* @__PURE__ */ _("div", { className: "widget widget-chart", children: [
234
- e && /* @__PURE__ */ a("h4", { className: "widget-chart__title", children: e }),
235
- /* @__PURE__ */ a("div", { ref: m, className: "widget-chart__container", children: s.length === 0 ? /* @__PURE__ */ a("div", { className: "widget-chart__empty", children: "Sem dados" }) : d() })
236
- ] });
330
+ return /* @__PURE__ */ l(L, { name: "chart", title: r, children: /* @__PURE__ */ l("div", { ref: f, className: "widget-chart__container", children: i.length === 0 ? /* @__PURE__ */ l(re, { kind: "empty" }) : o() }) });
237
331
  }
238
- function Se(t, l) {
239
- if (t == null || t === "") return "-";
240
- const n = typeof t == "number" ? t : Number(t), r = t !== "" && !Number.isNaN(n);
241
- switch (l) {
242
- case "currency":
243
- return r ? n.toLocaleString("pt-BR", { style: "currency", currency: "BRL" }) : String(t);
244
- case "integer":
245
- return r ? Math.round(n).toLocaleString("pt-BR") : String(t);
246
- case "number":
247
- return r ? n.toLocaleString("pt-BR", { maximumFractionDigits: 1 }) : String(t);
248
- case "percentage":
249
- return r ? `${n > 0 ? "+" : ""}${Math.round(n)}%` : String(t);
250
- default:
251
- return String(t);
252
- }
332
+ function rt(t, e) {
333
+ if (e !== "percentage") return "";
334
+ const a = Number(t);
335
+ return Number.isNaN(a) || a === 0 ? "" : a > 0 ? " widget-table__td--up" : " widget-table__td--down";
253
336
  }
254
- function Ce({ data: t, label: l }) {
337
+ function at({ data: t, label: e }) {
255
338
  var g;
256
- const [n, r] = k(0), e = t.columns || [], i = t.tabs || [], c = i.length > 0, s = c ? ((g = i[Math.min(n, i.length - 1)]) == null ? void 0 : g.rows) || [] : t.rows || [], m = l || String(t.label || "");
257
- return e.length === 0 ? /* @__PURE__ */ _("div", { className: "widget widget-table", children: [
258
- m && /* @__PURE__ */ a("span", { className: "widget-table__label", children: m }),
259
- /* @__PURE__ */ a("span", { className: "widget-table__empty", children: "Configure as colunas da tabela." })
260
- ] }) : /* @__PURE__ */ _("div", { className: "widget widget-table", children: [
261
- m && /* @__PURE__ */ a("span", { className: "widget-table__label", children: m }),
262
- c && /* @__PURE__ */ a("div", { className: "widget-table__tabs", role: "tablist", children: i.map((o, d) => /* @__PURE__ */ a(
263
- "button",
339
+ const [a, n] = F(0), r = t.columns || [], s = t.tabs || [], c = s.length > 0, i = c ? ((g = s[Math.min(a, s.length - 1)]) == null ? void 0 : g.rows) || [] : t.rows || [], f = e || String(t.label || "");
340
+ if (r.length === 0)
341
+ return /* @__PURE__ */ l(
342
+ L,
343
+ {
344
+ name: "table",
345
+ title: f,
346
+ state: "unconfigured",
347
+ stateMessage: "Configure as colunas da tabela."
348
+ }
349
+ );
350
+ const d = c ? /* @__PURE__ */ l("div", { className: "widget-table__tabs", role: "tablist", children: s.map((o, u) => /* @__PURE__ */ l(
351
+ "button",
352
+ {
353
+ type: "button",
354
+ role: "tab",
355
+ "aria-selected": u === a,
356
+ className: `widget-table__tab${u === a ? " widget-table__tab--active" : ""}`,
357
+ onClick: () => n(u),
358
+ children: o.label
359
+ },
360
+ u
361
+ )) }) : void 0;
362
+ return /* @__PURE__ */ l(L, { name: "table", title: f, toolbar: d, children: /* @__PURE__ */ l("div", { className: "widget-table__scroll", children: /* @__PURE__ */ v("table", { className: "widget-table__table", children: [
363
+ /* @__PURE__ */ l("thead", { children: /* @__PURE__ */ l("tr", { children: r.map((o) => /* @__PURE__ */ l(
364
+ "th",
264
365
  {
265
- type: "button",
266
- role: "tab",
267
- "aria-selected": d === n,
268
- className: `widget-table__tab${d === n ? " widget-table__tab--active" : ""}`,
269
- onClick: () => r(d),
270
- children: o.label
366
+ className: `widget-table__th${X(o.format) ? " widget-table__th--num" : ""}`,
367
+ children: o.label || o.key
271
368
  },
272
- d
273
- )) }),
274
- /* @__PURE__ */ a("div", { className: "widget-table__scroll", children: /* @__PURE__ */ _("table", { className: "widget-table__table", children: [
275
- /* @__PURE__ */ a("thead", { children: /* @__PURE__ */ a("tr", { children: e.map((o) => {
276
- const d = !!o.format && o.format !== "text";
277
- return /* @__PURE__ */ a("th", { className: `widget-table__th${d ? " widget-table__th--num" : ""}`, children: o.label || o.key }, o.key);
278
- }) }) }),
279
- /* @__PURE__ */ a("tbody", { children: s.length === 0 ? /* @__PURE__ */ a("tr", { children: /* @__PURE__ */ a("td", { className: "widget-table__td widget-table__empty", colSpan: e.length, children: "Sem dados" }) }) : s.map((o, d) => /* @__PURE__ */ a("tr", { children: e.map((h) => {
280
- const w = o[h.key], u = !!h.format && h.format !== "text";
281
- let b = "";
282
- if (h.format === "percentage") {
283
- const y = Number(w);
284
- Number.isNaN(y) || (b = y > 0 ? " widget-table__td--up" : y < 0 ? " widget-table__td--down" : "");
285
- }
286
- return /* @__PURE__ */ a("td", { className: `widget-table__td${u ? " widget-table__td--num" : ""}${b}`, children: Se(w, h.format) }, h.key);
287
- }) }, d)) })
288
- ] }) })
289
- ] });
369
+ o.key
370
+ )) }) }),
371
+ /* @__PURE__ */ l("tbody", { children: i.length === 0 ? /* @__PURE__ */ l("tr", { children: /* @__PURE__ */ l("td", { className: "widget-table__td widget-table__td--placeholder", colSpan: r.length, children: "Sem dados" }) }) : i.map((o, u) => /* @__PURE__ */ l("tr", { children: r.map((y) => {
372
+ const h = o[y.key], b = X(y.format) ? " widget-table__td--num" : "";
373
+ return /* @__PURE__ */ l("td", { className: `widget-table__td${b}${rt(h, y.format)}`, children: de(h, y.format) }, y.key);
374
+ }) }, u)) })
375
+ ] }) }) });
290
376
  }
291
- function Re({ config: t, value: l, options: n = [], dateBounds: r, onChange: e }) {
292
- const i = t.filterType || "select", c = t.label || "Filtro", s = t.dateFilterMode || "range";
293
- return /* @__PURE__ */ _("div", { className: "widget-filter", children: [
294
- /* @__PURE__ */ a("label", { className: "widget-filter__label", children: c }),
295
- i === "date_range" ? s === "yearly" ? /* @__PURE__ */ a(xe, { value: l, dateBounds: r, onChange: e }) : s === "monthly" ? /* @__PURE__ */ a(Fe, { value: l, dateBounds: r, onChange: e }) : s === "weekly" ? /* @__PURE__ */ a(Te, { value: l, dateBounds: r, onChange: e }) : /* @__PURE__ */ a(Me, { value: l, dateBounds: r, onChange: e }) : /* @__PURE__ */ a(
296
- Le,
377
+ function nt({ config: t, value: e, options: a = [], dateBounds: n, onChange: r }) {
378
+ const s = t.filterType || "select", c = t.label || "Filtro", i = t.dateFilterMode || "range";
379
+ return /* @__PURE__ */ v("div", { className: "widget-filter", children: [
380
+ /* @__PURE__ */ l("label", { className: "widget-filter__label", children: c }),
381
+ s === "date_range" ? i === "yearly" ? /* @__PURE__ */ l(st, { value: e, dateBounds: n, onChange: r }) : i === "monthly" ? /* @__PURE__ */ l(it, { value: e, dateBounds: n, onChange: r }) : i === "weekly" ? /* @__PURE__ */ l(ct, { value: e, dateBounds: n, onChange: r }) : /* @__PURE__ */ l(lt, { value: e, dateBounds: n, onChange: r }) : /* @__PURE__ */ l(
382
+ ot,
297
383
  {
298
- value: l,
299
- options: n,
300
- multi: i === "multi_select",
384
+ value: e,
385
+ options: a,
386
+ multi: s === "multi_select",
301
387
  searchable: t.searchable || !1,
302
- onChange: e
388
+ onChange: r
303
389
  }
304
390
  )
305
391
  ] });
306
392
  }
307
- function Me({ value: t, dateBounds: l, onChange: n }) {
308
- const [r, e] = t ? t.split("|") : ["", ""];
309
- return /* @__PURE__ */ _("div", { className: "widget-filter__date-range widget-filter__date-range--stacked", children: [
310
- /* @__PURE__ */ a(
311
- A,
393
+ function lt({ value: t, dateBounds: e, onChange: a }) {
394
+ const [n, r] = t ? t.split("|") : ["", ""];
395
+ return /* @__PURE__ */ v("div", { className: "widget-filter__date-range widget-filter__date-range--stacked", children: [
396
+ /* @__PURE__ */ l(
397
+ U,
312
398
  {
313
- value: r,
314
- minIso: l == null ? void 0 : l.min,
315
- maxIso: e || (l == null ? void 0 : l.max),
399
+ value: n,
400
+ minIso: e == null ? void 0 : e.min,
401
+ maxIso: r || (e == null ? void 0 : e.max),
316
402
  selectsStart: !0,
317
- startIso: r,
318
- endIso: e,
403
+ startIso: n,
404
+ endIso: r,
319
405
  placeholder: "Data inicial",
320
- onChange: (i) => n(`${i}|${e}`)
406
+ onChange: (s) => a(`${s}|${r}`)
321
407
  }
322
408
  ),
323
- /* @__PURE__ */ a(
324
- A,
409
+ /* @__PURE__ */ l(
410
+ U,
325
411
  {
326
- value: e,
327
- minIso: r || (l == null ? void 0 : l.min),
328
- maxIso: l == null ? void 0 : l.max,
412
+ value: r,
413
+ minIso: n || (e == null ? void 0 : e.min),
414
+ maxIso: e == null ? void 0 : e.max,
329
415
  selectsEnd: !0,
330
- startIso: r,
331
- endIso: e,
416
+ startIso: n,
417
+ endIso: r,
332
418
  placeholder: "Data final",
333
- onChange: (i) => n(`${r}|${i}`)
419
+ onChange: (s) => a(`${n}|${s}`)
334
420
  }
335
421
  )
336
422
  ] });
337
423
  }
338
- function xe({ value: t, dateBounds: l, onChange: n }) {
339
- const [r] = t ? t.split("|") : [""], e = H(r), i = /* @__PURE__ */ new Date(), c = (e == null ? void 0 : e.year) ?? i.getFullYear(), s = I(l), m = (g) => {
340
- const o = J(g);
341
- n(`${o.start}|${o.end}`);
424
+ function st({ value: t, dateBounds: e, onChange: a }) {
425
+ const [n] = t ? t.split("|") : [""], r = ue(n), s = /* @__PURE__ */ new Date(), c = (r == null ? void 0 : r.year) ?? s.getFullYear(), i = z(e), f = (d) => {
426
+ const g = fe(d);
427
+ a(`${g.start}|${g.end}`);
342
428
  };
343
- return /* @__PURE__ */ a("div", { className: "widget-filter__date-range widget-filter__date-range--year", children: /* @__PURE__ */ a(
429
+ return /* @__PURE__ */ l("div", { className: "widget-filter__date-range widget-filter__date-range--year", children: /* @__PURE__ */ l(
344
430
  "select",
345
431
  {
346
432
  className: "widget-filter__select",
347
433
  value: c,
348
- onChange: (g) => m(parseInt(g.target.value)),
349
- children: s.map((g) => /* @__PURE__ */ a("option", { value: g, children: g }, g))
434
+ onChange: (d) => f(parseInt(d.target.value)),
435
+ children: i.map((d) => /* @__PURE__ */ l("option", { value: d, children: d }, d))
350
436
  }
351
437
  ) });
352
438
  }
353
- function Fe({ value: t, dateBounds: l, onChange: n }) {
354
- const [r] = t ? t.split("|") : [""], e = D(r), i = /* @__PURE__ */ new Date(), c = (e == null ? void 0 : e.year) ?? i.getFullYear(), s = (e == null ? void 0 : e.month) ?? i.getMonth() + 1, m = I(l), g = (o, d) => {
355
- const h = Q(o, d);
356
- n(`${h.start}|${h.end}`);
439
+ function it({ value: t, dateBounds: e, onChange: a }) {
440
+ const [n] = t ? t.split("|") : [""], r = B(n), s = /* @__PURE__ */ new Date(), c = (r == null ? void 0 : r.year) ?? s.getFullYear(), i = (r == null ? void 0 : r.month) ?? s.getMonth() + 1, f = z(e), d = (g, o) => {
441
+ const u = me(g, o);
442
+ a(`${u.start}|${u.end}`);
357
443
  };
358
- return /* @__PURE__ */ _("div", { className: "widget-filter__date-range widget-filter__date-range--month", children: [
359
- /* @__PURE__ */ a(
444
+ return /* @__PURE__ */ v("div", { className: "widget-filter__date-range widget-filter__date-range--month", children: [
445
+ /* @__PURE__ */ l(
360
446
  "select",
361
447
  {
362
448
  className: "widget-filter__select",
363
- value: s,
364
- onChange: (o) => g(c, parseInt(o.target.value)),
365
- children: P.map((o, d) => /* @__PURE__ */ a("option", { value: d + 1, children: o }, d + 1))
449
+ value: i,
450
+ onChange: (g) => d(c, parseInt(g.target.value)),
451
+ children: ee.map((g, o) => /* @__PURE__ */ l("option", { value: o + 1, children: g }, o + 1))
366
452
  }
367
453
  ),
368
- /* @__PURE__ */ a(
454
+ /* @__PURE__ */ l(
369
455
  "select",
370
456
  {
371
457
  className: "widget-filter__select",
372
458
  value: c,
373
- onChange: (o) => g(parseInt(o.target.value), s),
374
- children: m.map((o) => /* @__PURE__ */ a("option", { value: o, children: o }, o))
459
+ onChange: (g) => d(parseInt(g.target.value), i),
460
+ children: f.map((g) => /* @__PURE__ */ l("option", { value: g, children: g }, g))
375
461
  }
376
462
  )
377
463
  ] });
378
464
  }
379
- function Te({ value: t, dateBounds: l, onChange: n }) {
380
- const [r] = t ? t.split("|") : [""], e = D(r), i = /* @__PURE__ */ new Date(), c = (e == null ? void 0 : e.year) ?? i.getFullYear(), s = (e == null ? void 0 : e.month) ?? i.getMonth() + 1, m = I(l), g = M(c, s), o = X(r, c, s) || 1;
381
- return /* @__PURE__ */ _("div", { className: "widget-filter__date-range widget-filter__date-range--week", children: [
382
- /* @__PURE__ */ a(
465
+ function ct({ value: t, dateBounds: e, onChange: a }) {
466
+ const [n] = t ? t.split("|") : [""], r = B(n), s = /* @__PURE__ */ new Date(), c = (r == null ? void 0 : r.year) ?? s.getFullYear(), i = (r == null ? void 0 : r.month) ?? s.getMonth() + 1, f = z(e), d = H(c, i), g = he(n, c, i) || 1;
467
+ return /* @__PURE__ */ v("div", { className: "widget-filter__date-range widget-filter__date-range--week", children: [
468
+ /* @__PURE__ */ l(
383
469
  "select",
384
470
  {
385
471
  className: "widget-filter__select",
386
472
  value: c,
387
- onChange: (d) => {
388
- const h = parseInt(d.target.value), u = M(h, s)[0];
389
- u && n(`${u.start}|${u.end}`);
473
+ onChange: (o) => {
474
+ const u = parseInt(o.target.value), h = H(u, i)[0];
475
+ h && a(`${h.start}|${h.end}`);
390
476
  },
391
- children: m.map((d) => /* @__PURE__ */ a("option", { value: d, children: d }, d))
477
+ children: f.map((o) => /* @__PURE__ */ l("option", { value: o, children: o }, o))
392
478
  }
393
479
  ),
394
- /* @__PURE__ */ a(
480
+ /* @__PURE__ */ l(
395
481
  "select",
396
482
  {
397
483
  className: "widget-filter__select",
398
- value: s,
399
- onChange: (d) => {
400
- const h = parseInt(d.target.value), u = M(c, h)[0];
401
- u && n(`${u.start}|${u.end}`);
484
+ value: i,
485
+ onChange: (o) => {
486
+ const u = parseInt(o.target.value), h = H(c, u)[0];
487
+ h && a(`${h.start}|${h.end}`);
402
488
  },
403
- children: P.map((d, h) => /* @__PURE__ */ a("option", { value: h + 1, children: d }, h + 1))
489
+ children: ee.map((o, u) => /* @__PURE__ */ l("option", { value: u + 1, children: o }, u + 1))
404
490
  }
405
491
  ),
406
- /* @__PURE__ */ a(
492
+ /* @__PURE__ */ l(
407
493
  "select",
408
494
  {
409
495
  className: "widget-filter__select",
410
- value: o,
411
- onChange: (d) => {
412
- const h = g[parseInt(d.target.value) - 1];
413
- h && n(`${h.start}|${h.end}`);
496
+ value: g,
497
+ onChange: (o) => {
498
+ const u = d[parseInt(o.target.value) - 1];
499
+ u && a(`${u.start}|${u.end}`);
414
500
  },
415
- children: g.map((d) => /* @__PURE__ */ a("option", { value: d.index, children: d.label }, d.index))
501
+ children: d.map((o) => /* @__PURE__ */ l("option", { value: o.index, children: o.label }, o.index))
416
502
  }
417
503
  )
418
504
  ] });
419
505
  }
420
- function Le({ value: t, options: l, multi: n, searchable: r, onChange: e }) {
421
- if (r)
422
- return /* @__PURE__ */ a(
423
- q,
506
+ function ot({ value: t, options: e, multi: a, searchable: n, onChange: r }) {
507
+ if (n)
508
+ return /* @__PURE__ */ l(
509
+ ge,
424
510
  {
425
511
  value: t,
426
- options: l,
427
- multi: n,
428
- onChange: e
512
+ options: e,
513
+ multi: a,
514
+ onChange: r
429
515
  }
430
516
  );
431
- if (n) {
432
- const i = t ? t.split(L) : [], c = (s) => {
433
- const m = i.includes(s) ? i.filter((g) => g !== s) : [...i, s];
434
- e(m.join(L));
517
+ if (a) {
518
+ const s = t ? t.split(G) : [], c = (i) => {
519
+ const f = s.includes(i) ? s.filter((d) => d !== i) : [...s, i];
520
+ r(f.join(G));
435
521
  };
436
- return /* @__PURE__ */ _("div", { className: "widget-filter__multi", children: [
437
- i.length > 0 && /* @__PURE__ */ a(
522
+ return /* @__PURE__ */ v("div", { className: "widget-filter__multi", children: [
523
+ s.length > 0 && /* @__PURE__ */ l(
438
524
  "button",
439
525
  {
440
526
  type: "button",
441
527
  className: "widget-filter__multi-clear",
442
- onClick: () => e(""),
528
+ onClick: () => r(""),
443
529
  children: "Limpar filtro"
444
530
  }
445
531
  ),
446
- l.map((s) => /* @__PURE__ */ _("label", { className: "widget-filter__multi-option", children: [
447
- /* @__PURE__ */ a(
532
+ e.map((i) => /* @__PURE__ */ v("label", { className: "widget-filter__multi-option", children: [
533
+ /* @__PURE__ */ l(
448
534
  "input",
449
535
  {
450
536
  type: "checkbox",
451
- checked: i.includes(s),
452
- onChange: () => c(s)
537
+ checked: s.includes(i),
538
+ onChange: () => c(i)
453
539
  }
454
540
  ),
455
- s
456
- ] }, s))
541
+ i
542
+ ] }, i))
457
543
  ] });
458
544
  }
459
- return /* @__PURE__ */ _(
545
+ return /* @__PURE__ */ v(
460
546
  "select",
461
547
  {
462
548
  className: "widget-filter__select",
463
549
  value: t,
464
- onChange: (i) => e(i.target.value),
550
+ onChange: (s) => r(s.target.value),
465
551
  children: [
466
- /* @__PURE__ */ a("option", { value: "", children: "Todos" }),
467
- l.map((i) => /* @__PURE__ */ a("option", { value: i, children: i }, i))
552
+ /* @__PURE__ */ l("option", { value: "", children: "Todos" }),
553
+ e.map((s) => /* @__PURE__ */ l("option", { value: s, children: s }, s))
468
554
  ]
469
555
  }
470
556
  );
471
557
  }
472
- const Ie = {
558
+ const dt = {
473
559
  currency: "R$",
474
560
  percentage: "%"
475
561
  };
476
- function Ae({ config: t, value: l, onChange: n }) {
477
- const r = t.label || "Variavel", e = t.locked || !1, i = t.variableFormat || "number", c = Ie[i] || "";
478
- return /* @__PURE__ */ _("div", { className: `widget-variable ${e ? "widget-variable--locked" : ""}`, children: [
479
- /* @__PURE__ */ a("label", { className: "widget-variable__label", children: r }),
480
- /* @__PURE__ */ _("div", { className: "widget-variable__input-wrapper", children: [
481
- /* @__PURE__ */ a(
562
+ function ut({ config: t, value: e, onChange: a }) {
563
+ const n = t.label || "Variavel", r = t.locked || !1, s = t.variableFormat || "number", c = dt[s] || "";
564
+ return /* @__PURE__ */ v("div", { className: `widget-variable ${r ? "widget-variable--locked" : ""}`, children: [
565
+ /* @__PURE__ */ l("label", { className: "widget-variable__label", children: n }),
566
+ /* @__PURE__ */ v("div", { className: "widget-variable__input-wrapper", children: [
567
+ /* @__PURE__ */ l(
482
568
  "input",
483
569
  {
484
570
  className: "widget-variable__input",
485
571
  type: "number",
486
- value: l,
487
- onChange: (s) => n(parseFloat(s.target.value) || 0),
488
- disabled: e,
489
- step: i === "integer" ? 1 : 0.01
572
+ value: e,
573
+ onChange: (i) => a(parseFloat(i.target.value) || 0),
574
+ disabled: r,
575
+ step: s === "integer" ? 1 : 0.01
490
576
  }
491
577
  ),
492
- c && /* @__PURE__ */ a("span", { className: "widget-variable__suffix", children: c })
578
+ c && /* @__PURE__ */ l("span", { className: "widget-variable__suffix", children: c })
493
579
  ] }),
494
- e && /* @__PURE__ */ a("span", { className: "widget-variable__lock-icon", title: "Bloqueado", children: "🔒" })
580
+ r && /* @__PURE__ */ l("span", { className: "widget-variable__lock-icon", title: "Bloqueado", children: "🔒" })
495
581
  ] });
496
582
  }
497
- function Ee({ config: t, palette: l, onChange: n }) {
498
- const r = t.label || "Cores", e = t.locked || !1;
499
- return /* @__PURE__ */ _("div", { className: `widget-palette ${e ? "widget-palette--locked" : ""}`, children: [
500
- /* @__PURE__ */ a("label", { className: "widget-palette__label", children: r }),
501
- /* @__PURE__ */ a(Z, { selected: l, onSelect: n, customMode: !0, disabled: e }),
502
- e && /* @__PURE__ */ a("span", { className: "widget-palette__lock-icon", title: "Bloqueado", children: "🔒" })
583
+ function ht({ config: t, palette: e, onChange: a }) {
584
+ const n = t.label || "Cores", r = t.locked || !1;
585
+ return /* @__PURE__ */ v("div", { className: `widget-palette ${r ? "widget-palette--locked" : ""}`, children: [
586
+ /* @__PURE__ */ l("label", { className: "widget-palette__label", children: n }),
587
+ /* @__PURE__ */ l(pe, { selected: e, onSelect: a, customMode: !0, disabled: r }),
588
+ r && /* @__PURE__ */ l("span", { className: "widget-palette__lock-icon", title: "Bloqueado", children: "🔒" })
503
589
  ] });
504
590
  }
505
- function Oe({
591
+ const gt = {
592
+ failed_to_compute: "Não foi possível calcular este widget"
593
+ };
594
+ function mt({
506
595
  type: t,
507
- computed: l,
508
- palette: n,
509
- config: r,
510
- filterValue: e,
511
- filterOptions: i,
596
+ computed: e,
597
+ palette: a,
598
+ config: n,
599
+ filterValue: r,
600
+ filterOptions: s,
512
601
  dateBounds: c,
513
- onFilterChange: s,
514
- variableValue: m,
515
- onVariableChange: g,
516
- onPaletteChange: o
602
+ onFilterChange: i,
603
+ variableValue: f,
604
+ onVariableChange: d,
605
+ onPaletteChange: g
517
606
  }) {
518
- if (l.error)
519
- return /* @__PURE__ */ a("div", { className: "widget widget--error", children: /* @__PURE__ */ a("span", { className: "widget__error-text", children: String(l.error) }) });
520
- const d = B(n);
607
+ if (e.error)
608
+ return /* @__PURE__ */ l(
609
+ L,
610
+ {
611
+ name: t.replace("_", "-"),
612
+ title: n == null ? void 0 : n.label,
613
+ state: "error",
614
+ stateMessage: gt[String(e.error)]
615
+ }
616
+ );
617
+ const o = _e(a);
521
618
  switch (t) {
522
619
  case "kpi_card":
523
- return /* @__PURE__ */ a(we, { data: l, label: r == null ? void 0 : r.label });
620
+ return /* @__PURE__ */ l(qe, { data: e, label: n == null ? void 0 : n.label });
524
621
  case "gauge":
525
- return /* @__PURE__ */ a(ye, { data: l, palette: d, label: r == null ? void 0 : r.label });
622
+ return /* @__PURE__ */ l(Ze, { data: e, palette: o, label: n == null ? void 0 : n.label });
526
623
  case "chart":
527
- return /* @__PURE__ */ a($e, { data: l, palette: d, label: r == null ? void 0 : r.label });
624
+ return /* @__PURE__ */ l(tt, { data: e, palette: o, label: n == null ? void 0 : n.label });
528
625
  case "table":
529
- return /* @__PURE__ */ a(Ce, { data: l, label: r == null ? void 0 : r.label });
626
+ return /* @__PURE__ */ l(at, { data: e, label: n == null ? void 0 : n.label });
530
627
  case "filter":
531
- return r && s ? /* @__PURE__ */ a(
532
- Re,
628
+ return n && i ? /* @__PURE__ */ l(
629
+ nt,
533
630
  {
534
- config: r,
535
- value: e || "",
536
- options: i,
631
+ config: n,
632
+ value: r || "",
633
+ options: s,
537
634
  dateBounds: c,
538
- onChange: s
635
+ onChange: i
539
636
  }
540
637
  ) : null;
541
638
  case "variable": {
542
- const h = r;
543
- return h && g ? /* @__PURE__ */ a(
544
- Ae,
639
+ const u = n;
640
+ return u && d ? /* @__PURE__ */ l(
641
+ ut,
545
642
  {
546
- config: h,
547
- value: m ?? h.variableValue ?? 0,
548
- onChange: g
643
+ config: u,
644
+ value: f ?? u.variableValue ?? 0,
645
+ onChange: d
549
646
  }
550
647
  ) : null;
551
648
  }
552
649
  case "color_palette":
553
- return r && o ? /* @__PURE__ */ a(
554
- Ee,
650
+ return n && g ? /* @__PURE__ */ l(
651
+ ht,
555
652
  {
556
- config: r,
557
- palette: n,
558
- onChange: o
653
+ config: n,
654
+ palette: a,
655
+ onChange: g
559
656
  }
560
657
  ) : null;
561
658
  default:
562
- return /* @__PURE__ */ _("div", { className: "widget", children: [
563
- "Widget: ",
564
- t
565
- ] });
659
+ return /* @__PURE__ */ l(L, { name: "unknown", state: "unconfigured" });
566
660
  }
567
661
  }
568
- const We = 2.5, De = 0.375;
569
- function Ge({
662
+ const ft = (t, e) => t.grid.y - e.grid.y || t.grid.x - e.grid.x;
663
+ function wt({
570
664
  token: t,
571
- rowHeight: l = We,
572
- gridGap: n = De,
573
- className: r
665
+ cellAspect: e = ke,
666
+ stackBelow: a,
667
+ onGeometryChange: n,
668
+ silenceWarnings: r,
669
+ className: s
574
670
  }) {
575
671
  const {
576
- layout: e,
672
+ layout: c,
577
673
  renderData: i,
578
- loading: c,
579
- error: s,
580
- filters: m,
581
- variables: g,
582
- palette: o,
583
- setFilter: d,
674
+ loading: f,
675
+ error: d,
676
+ filters: g,
677
+ variables: o,
678
+ palette: u,
679
+ setFilter: y,
584
680
  setVariable: h,
585
- setPalette: w
586
- } = be(t);
587
- if (s && !e)
588
- return /* @__PURE__ */ a("div", { className: `preview-tab ${r ?? ""}`, children: /* @__PURE__ */ a("div", { className: "preview-tab__error", children: s }) });
589
- if (!e)
590
- return /* @__PURE__ */ a("div", { className: `preview-tab ${r ?? ""}`, children: /* @__PURE__ */ a("div", { className: "preview-tab__loading", children: "Carregando dashboard..." }) });
591
- if (e.widgets.length === 0)
592
- return /* @__PURE__ */ a("div", { className: `preview-tab ${r ?? ""}`, children: /* @__PURE__ */ a("div", { className: "preview-tab__empty", children: "Este dashboard nao possui widgets." }) });
593
- const u = (i == null ? void 0 : i.widgets) ?? {}, b = (i == null ? void 0 : i.date_bounds) ?? null, y = {
594
- display: "grid",
595
- gridTemplateColumns: `repeat(${e.gridColumns}, 1fr)`,
596
- gridTemplateRows: `repeat(${e.gridRows}, ${l}rem)`,
597
- gap: `${n}rem`,
598
- ...ee(o)
599
- };
600
- return /* @__PURE__ */ _("div", { className: `preview-tab ${r ?? ""}`, children: [
601
- s && !i && /* @__PURE__ */ a("div", { className: "preview-tab__error", children: s }),
602
- i && /* @__PURE__ */ a("div", { className: "preview-tab__grid", style: y, children: e.widgets.map((p) => {
603
- const S = te.has(p.type), N = u[p.id], C = {
604
- gridColumn: `${p.grid.x + 1} / span ${p.grid.w}`,
605
- gridRow: `${p.grid.y + 1} / span ${p.grid.h}`
606
- }, v = p.type === "variable" ? g[p.id] ?? (N == null ? void 0 : N.value) ?? p.config.variableValue ?? 0 : void 0;
607
- return /* @__PURE__ */ a(
608
- "div",
609
- {
610
- className: `preview-tab__widget ${S ? "preview-tab__widget--control" : ""}`,
611
- style: C,
612
- children: S || N ? /* @__PURE__ */ a(
613
- Oe,
614
- {
615
- type: p.type,
616
- computed: N || {},
617
- palette: o,
618
- config: p.config,
619
- filterValue: m[p.id] || "",
620
- filterOptions: (N == null ? void 0 : N.available_values) || [],
621
- dateBounds: b,
622
- onFilterChange: (f) => d(p.id, f),
623
- variableValue: v,
624
- onVariableChange: (f) => h(p.id, f),
625
- onPaletteChange: w
626
- }
627
- ) : /* @__PURE__ */ a("div", { className: "preview-tab__widget-loading", children: c ? "Carregando..." : "Sem dados" })
628
- },
629
- p.id
630
- );
631
- }) }),
632
- c && i && /* @__PURE__ */ a("div", { className: "preview-tab__recalculating", children: "Atualizando..." })
633
- ] });
681
+ setPalette: b
682
+ } = De(t), { rootRef: N, gridRef: T, stacked: S } = je({
683
+ columns: (c == null ? void 0 : c.gridColumns) ?? 0,
684
+ cellAspect: e,
685
+ stackBelow: a,
686
+ onGeometryChange: n,
687
+ silenceWarnings: r
688
+ }), O = Z(() => {
689
+ const m = (c == null ? void 0 : c.widgets) ?? [];
690
+ return S ? [...m].sort(ft) : m;
691
+ }, [c == null ? void 0 : c.widgets, S]), M = {
692
+ "--dash-gap": `${q}px`,
693
+ "--dash-pad": `${Se}px`
694
+ }, k = ["preview-tab", s].filter(Boolean).join(" ");
695
+ let w;
696
+ if (d && !c)
697
+ w = /* @__PURE__ */ l("div", { className: "preview-tab__error", children: d });
698
+ else if (!c)
699
+ w = /* @__PURE__ */ l("div", { className: "preview-tab__loading", children: "Carregando dashboard..." });
700
+ else if (c.widgets.length === 0)
701
+ w = /* @__PURE__ */ l("div", { className: "preview-tab__empty", children: "Este dashboard nao possui widgets." });
702
+ else {
703
+ const m = (i == null ? void 0 : i.widgets) ?? {}, _ = (i == null ? void 0 : i.date_bounds) ?? null, C = {
704
+ "--dash-cols": c.gridColumns,
705
+ "--dash-rows": c.gridRows,
706
+ ...be(u)
707
+ }, W = ["preview-tab__grid", S && "preview-tab__grid--stacked"].filter(Boolean).join(" ");
708
+ w = /* @__PURE__ */ v(se, { children: [
709
+ d && !i && /* @__PURE__ */ l("div", { className: "preview-tab__error", children: d }),
710
+ i && /* @__PURE__ */ l("div", { className: W, style: C, ref: T, children: O.map((p) => {
711
+ const x = ve.has(p.type), A = m[p.id], I = S ? {
712
+ gridColumn: 1,
713
+ aspectRatio: `${ye(p.grid.w, p.grid.h, e)}`,
714
+ minHeight: `${we(p.grid.h, Ne, q, 0)}px`
715
+ } : {
716
+ gridColumn: `${p.grid.x + 1} / span ${p.grid.w}`,
717
+ gridRow: `${p.grid.y + 1} / span ${p.grid.h}`
718
+ }, E = p.type === "variable" ? o[p.id] ?? (A == null ? void 0 : A.value) ?? p.config.variableValue ?? 0 : void 0;
719
+ return /* @__PURE__ */ l(
720
+ "div",
721
+ {
722
+ className: `preview-tab__widget ${x ? "preview-tab__widget--control" : ""}`,
723
+ style: I,
724
+ children: x || A ? /* @__PURE__ */ l(
725
+ mt,
726
+ {
727
+ type: p.type,
728
+ computed: A || {},
729
+ palette: u,
730
+ config: p.config,
731
+ filterValue: g[p.id] || "",
732
+ filterOptions: (
733
+ // Estruturais: vem do /layout (cacheavel), nao do /render —
734
+ // recalcula-los a cada render custaria um DISTINCT por filtro.
735
+ p.type === "filter" ? p.config.availableValues ?? [] : []
736
+ ),
737
+ dateBounds: _,
738
+ onFilterChange: (D) => y(p.id, D),
739
+ variableValue: E,
740
+ onVariableChange: (D) => h(p.id, D),
741
+ onPaletteChange: b
742
+ }
743
+ ) : /* @__PURE__ */ l("div", { className: "preview-tab__widget-loading", children: f ? "Carregando..." : "Sem dados" })
744
+ },
745
+ p.id
746
+ );
747
+ }) }),
748
+ f && i && /* @__PURE__ */ l("div", { className: "preview-tab__recalculating", children: "Atualizando..." })
749
+ ] });
750
+ }
751
+ return /* @__PURE__ */ l("div", { className: k, style: M, ref: N, children: w });
634
752
  }
635
753
  export {
636
- Ue as ApiError,
637
- Ge as Dashboard
754
+ kt as ApiError,
755
+ wt as Dashboard
638
756
  };
639
757
  //# sourceMappingURL=index.js.map