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