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