@actionexec/dashboards 0.12.0 → 0.13.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,574 +1,575 @@
1
- import { jsxs as v, jsx as a, Fragment as ge } from "react/jsx-runtime";
2
- import { useState as E, useRef as N, useEffect as P, useCallback as x, useMemo as ae } from "react";
3
- import { f as me, a as fe, M as G, c as q, b as U, d as pe, e as le, i as Q, g as _e, p as be, h as V, j as ie, k as se, l as H, m as ve, D as J, S as we, n as ye, o as ke, C as Se, q as Ne, r as Ce, s as Re, t as $e, u as xe, G as Me, v as Z, w as Ae, x as Te } from "./ColorPaletteSelector-DJge9VhO.js";
4
- import { A as Et } from "./ColorPaletteSelector-DJge9VhO.js";
5
- import { LineChart as Ee, Line as Fe, AreaChart as Ie, Area as We, BarChart as ce, Bar as z, CartesianGrid as oe, XAxis as de, YAxis as ue, Tooltip as K, Legend as Le, Cell as B, PieChart as Oe, Pie as Pe } from "recharts";
6
- const De = 300;
7
- function He(e) {
8
- const [t, n] = E(null), [r, l] = E(null), [i, c] = E({}), [s, h] = E({}), [o, f] = E(null), [u, d] = E(!0), [g, b] = E(null), k = N(), C = N(!1);
9
- P(() => {
10
- let y = !1;
11
- return me(e).then((w) => {
12
- y || n(w);
13
- }).catch((w) => {
14
- y || b(w.message);
1
+ import { jsxs as _, jsx as r, Fragment as oe } from "react/jsx-runtime";
2
+ import { useState as I, useRef as R, useEffect as W, useCallback as T, useMemo as ce } from "react";
3
+ import { M as Y, f as Ne, a as Se, c as Q, b as Z, d as ke, e as de, i as J, g as j, p as Ce, h as X, j as ue, k as me, l as z, m as Re, D, S as he, n as $e, o as xe, C as Ie, q as Ae, r as ge, s as Te, t as Fe, u as Ee, G as Me, v as ee, w as Le, x as Oe, y as Pe, z as We, A as De } from "./ColorPaletteSelector-CZP3HDNJ.js";
4
+ import { B as qt } from "./ColorPaletteSelector-CZP3HDNJ.js";
5
+ import { LineChart as He, Line as ze, AreaChart as Ge, Area as Ye, BarChart as fe, Bar as V, CartesianGrid as _e, XAxis as pe, YAxis as be, Tooltip as K, Legend as je, Cell as te, PieChart as Ve, Pie as Ke } from "recharts";
6
+ const re = "__window";
7
+ function U(e, t = {}) {
8
+ const a = {};
9
+ for (const [n, l] of Object.entries(e))
10
+ if (l.includes("|")) {
11
+ const [s, o] = l.split("|");
12
+ s && (a.f_date_start = s), o && (a.f_date_end = o);
13
+ } else
14
+ a[`f_${n}`] = l;
15
+ for (const [n, l] of Object.entries(t))
16
+ a[`v_${n}`] = String(l);
17
+ return a;
18
+ }
19
+ function ve(e) {
20
+ const t = {};
21
+ for (const [a, n] of Object.entries(e))
22
+ if (n && typeof n == "object" && "start" in n) {
23
+ const l = n;
24
+ t[a] = `${l.start || ""}|${l.end || ""}`;
25
+ } else Array.isArray(n) ? t[a] = n.join(Y) : typeof n == "string" && (t[a] = n);
26
+ return t;
27
+ }
28
+ const Ue = 300;
29
+ function Xe(e) {
30
+ const [t, a] = I(null), [n, l] = I(null), [s, o] = I({}), [i, m] = I({}), [d, f] = I(null), [h, u] = I(!0), [g, p] = I(null), N = R(), C = R(!1);
31
+ W(() => {
32
+ let k = !1;
33
+ return Ne(e).then((S) => {
34
+ k || a(S);
35
+ }).catch((S) => {
36
+ k || p(S.message);
15
37
  }), () => {
16
- y = !0;
38
+ k = !0;
17
39
  };
18
- }, [e]), P(() => {
40
+ }, [e]), W(() => {
19
41
  if (t)
20
- return k.current && clearTimeout(k.current), k.current = setTimeout(() => {
21
- const y = Ye(i, s);
22
- d(!0), fe(e, y).then((w) => {
23
- l(w), !C.current && w.applied && (C.current = !0, c((m) => ({ ...Ge(w.applied), ...m }))), b(null);
24
- }).catch((w) => b(w.message)).finally(() => d(!1));
25
- }, De), () => {
26
- k.current && clearTimeout(k.current);
42
+ return N.current && clearTimeout(N.current), N.current = setTimeout(() => {
43
+ const k = U(s, i);
44
+ u(!0), Se(e, k).then((S) => {
45
+ l(S), !C.current && S.applied && (C.current = !0, o((c) => ({ ...ve(S.applied), ...c }))), p(null);
46
+ }).catch((S) => p(S.message)).finally(() => u(!1));
47
+ }, Ue), () => {
48
+ N.current && clearTimeout(N.current);
27
49
  };
28
- }, [e, t, i, s]);
29
- const M = x((y, w) => {
30
- c((m) => ({ ...m, [y]: w }));
31
- }, []), S = x((y, w) => {
32
- h((m) => ({ ...m, [y]: w }));
33
- }, []), T = x((y) => {
34
- f(y);
35
- }, []), $ = ae(
36
- () => o ?? (t == null ? void 0 : t.palette) ?? [],
37
- [o, t]
50
+ }, [e, t, s, i]);
51
+ const y = T((k, S) => {
52
+ o((c) => ({ ...c, [k]: S }));
53
+ }, []), w = T((k, S) => {
54
+ m((c) => ({ ...c, [k]: S }));
55
+ }, []), $ = T((k) => {
56
+ f(k);
57
+ }, []), x = ce(
58
+ () => d ?? (t == null ? void 0 : t.palette) ?? [],
59
+ [d, t]
38
60
  );
39
61
  return {
40
62
  layout: t,
41
- renderData: r,
42
- loading: u,
63
+ renderData: n,
64
+ loading: h,
43
65
  error: g,
44
- filters: i,
45
- variables: s,
46
- palette: $,
47
- setFilter: M,
48
- setVariable: S,
49
- setPalette: T
66
+ filters: s,
67
+ variables: i,
68
+ palette: x,
69
+ setFilter: y,
70
+ setVariable: w,
71
+ setPalette: $
50
72
  };
51
73
  }
52
- function Ye(e, t) {
53
- const n = {};
54
- for (const [r, l] of Object.entries(e))
55
- if (l.includes("|")) {
56
- const [i, c] = l.split("|");
57
- i && (n.f_date_start = i), c && (n.f_date_end = c);
58
- } else
59
- n[`f_${r}`] = l;
60
- for (const [r, l] of Object.entries(t))
61
- n[`v_${r}`] = String(l);
62
- return n;
63
- }
64
- function Ge(e) {
65
- const t = {};
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
- return t;
72
- }
73
- const ze = (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
- }, Ke = (e) => {
77
- var t, n;
78
- return ((n = (t = e.borderBoxSize) == null ? void 0 : t[0]) == null ? void 0 : n.blockSize) ?? e.target.offsetHeight;
74
+ const Be = (e) => {
75
+ var t, a;
76
+ return ((a = (t = e.borderBoxSize) == null ? void 0 : t[0]) == null ? void 0 : a.inlineSize) ?? e.target.offsetWidth;
77
+ }, qe = (e) => {
78
+ var t, a;
79
+ return ((a = (t = e.borderBoxSize) == null ? void 0 : t[0]) == null ? void 0 : a.blockSize) ?? e.target.offsetHeight;
79
80
  };
80
- function Ve(e, t, n) {
81
- return e === void 0 ? 0 : e === "auto" ? pe(t, n) : Math.max(0, e);
81
+ function Qe(e, t, a) {
82
+ return e === void 0 ? 0 : e === "auto" ? ke(t, a) : Math.max(0, e);
82
83
  }
83
- function je(e) {
84
+ function Ze(e) {
84
85
  let t = e.parentElement;
85
86
  for (; t && t !== document.body && t !== document.documentElement; ) {
86
- const { overflowY: n } = getComputedStyle(t);
87
- if (n !== "visible")
88
- return n === "hidden" || n === "clip" ? t : null;
87
+ const { overflowY: a } = getComputedStyle(t);
88
+ if (a !== "visible")
89
+ return a === "hidden" || a === "clip" ? t : null;
89
90
  t = t.parentElement;
90
91
  }
91
92
  return null;
92
93
  }
93
- function Xe(e) {
94
- const t = N(e);
94
+ function Je(e) {
95
+ const t = R(e);
95
96
  t.current = e;
96
- const n = N(null), r = N(null), l = N(null), i = N(null), c = N(null), s = N(0), h = N(0), o = N(!1), f = N(!1), u = N(-1), [d, g] = E(!1), b = x((m) => {
97
- const _ = r.current;
98
- if (f.current || t.current.silenceWarnings || !_) return;
99
- const R = je(_);
100
- !R || R.clientHeight >= m.gridHeight || (f.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 ${R.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.`
97
+ const a = R(null), n = R(null), l = R(null), s = R(null), o = R(null), i = R(0), m = R(0), d = R(!1), f = R(!1), h = R(-1), [u, g] = I(!1), p = T((c) => {
98
+ const b = n.current;
99
+ if (f.current || t.current.silenceWarnings || !b) return;
100
+ const A = Ze(b);
101
+ !A || A.clientHeight >= c.gridHeight || (f.current = !0, console.warn(
102
+ `[@actionexec/dashboards] O dashboard esta sendo cortado: o container precisa de ${Math.ceil(c.gridHeight)}px de altura, mas o ancestral com overflow oculto tem ${A.clientHeight}px. A altura do dashboard varia com a largura — use a prop onGeometryChange para dimensionar o container, ou troque o overflow para auto. Passe silenceWarnings para desligar este aviso.`
102
103
  ));
103
- }, []), k = x(() => {
104
- var O, I;
105
- if (!n.current) return;
106
- const { columns: m, cellAspect: _ } = t.current, R = s.current, L = U(R, m), p = {
107
- containerWidth: R,
108
- cellWidth: L,
109
- cellHeight: q(L, _),
110
- gridHeight: h.current,
111
- stacked: o.current
112
- }, A = c.current;
113
- A && A.containerWidth === p.containerWidth && A.cellWidth === p.cellWidth && A.cellHeight === p.cellHeight && A.gridHeight === p.gridHeight && A.stacked === p.stacked || (c.current = p, (I = (O = t.current).onGeometryChange) == null || I.call(O, p), b(p));
114
- }, [b]), C = x((m = !1) => {
115
- const _ = n.current;
116
- if (!_) return;
117
- const R = s.current;
118
- if (!m && R === u.current) return;
119
- u.current = R;
120
- const { columns: L, cellAspect: p, stackBelow: A } = t.current, F = U(R, L);
121
- _.style.setProperty("--dash-cell-h", `${q(F, p)}px`);
122
- const O = Ve(A, L, p), I = O > 0 && R > 0 && R < O;
123
- I !== o.current && (o.current = I, g(I));
124
- }, []), M = x(() => {
125
- i.current !== null && (cancelAnimationFrame(i.current), i.current = null);
126
- }, []), S = x(() => {
127
- i.current === null && (i.current = requestAnimationFrame(() => {
128
- i.current = null, C(), k();
104
+ }, []), N = T(() => {
105
+ var P, M;
106
+ if (!a.current) return;
107
+ const { columns: c, cellAspect: b } = t.current, A = i.current, O = Z(A, c), v = {
108
+ containerWidth: A,
109
+ cellWidth: O,
110
+ cellHeight: Q(O, b),
111
+ gridHeight: m.current,
112
+ stacked: d.current
113
+ }, F = o.current;
114
+ F && F.containerWidth === v.containerWidth && F.cellWidth === v.cellWidth && F.cellHeight === v.cellHeight && F.gridHeight === v.gridHeight && F.stacked === v.stacked || (o.current = v, (M = (P = t.current).onGeometryChange) == null || M.call(P, v), p(v));
115
+ }, [p]), C = T((c = !1) => {
116
+ const b = a.current;
117
+ if (!b) return;
118
+ const A = i.current;
119
+ if (!c && A === h.current) return;
120
+ h.current = A;
121
+ const { columns: O, cellAspect: v, stackBelow: F } = t.current, E = Z(A, O);
122
+ b.style.setProperty("--dash-cell-h", `${Q(E, v)}px`);
123
+ const P = Qe(F, O, v), M = P > 0 && A > 0 && A < P;
124
+ M !== d.current && (d.current = M, g(M));
125
+ }, []), y = T(() => {
126
+ s.current !== null && (cancelAnimationFrame(s.current), s.current = null);
127
+ }, []), w = T(() => {
128
+ s.current === null && (s.current = requestAnimationFrame(() => {
129
+ s.current = null, C(), N();
129
130
  }));
130
- }, [C, k]), T = x((m) => {
131
- for (const _ of m)
132
- _.target === n.current ? s.current = Math.round(ze(_)) : _.target === r.current && (h.current = Ke(_));
133
- S();
134
- }, [S]), $ = x(() => l.current ? l.current : typeof ResizeObserver > "u" ? null : (l.current = new ResizeObserver(T), l.current), [T]), y = x((m) => {
135
- const _ = $();
136
- n.current && (_ == null || _.unobserve(n.current)), n.current = m, m && (_ == null || _.observe(m), s.current = Math.round(m.getBoundingClientRect().width), C(!0), S());
137
- }, [C, $, S]), w = x((m) => {
138
- const _ = $();
139
- if (r.current && (_ == null || _.unobserve(r.current)), r.current = m, !m) {
140
- h.current = 0;
131
+ }, [C, N]), $ = T((c) => {
132
+ for (const b of c)
133
+ b.target === a.current ? i.current = Math.round(Be(b)) : b.target === n.current && (m.current = qe(b));
134
+ w();
135
+ }, [w]), x = T(() => l.current ? l.current : typeof ResizeObserver > "u" ? null : (l.current = new ResizeObserver($), l.current), [$]), k = T((c) => {
136
+ const b = x();
137
+ a.current && (b == null || b.unobserve(a.current)), a.current = c, c && (b == null || b.observe(c), i.current = Math.round(c.getBoundingClientRect().width), C(!0), w());
138
+ }, [C, x, w]), S = T((c) => {
139
+ const b = x();
140
+ if (n.current && (b == null || b.unobserve(n.current)), n.current = c, !c) {
141
+ m.current = 0;
141
142
  return;
142
143
  }
143
- _ == null || _.observe(m), h.current = m.getBoundingClientRect().height, S();
144
- }, [$, S]);
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 _;
149
- (_ = l.current) == null || _.disconnect(), l.current = null, M();
144
+ b == null || b.observe(c), m.current = c.getBoundingClientRect().height, w();
145
+ }, [x, w]);
146
+ return W(() => {
147
+ const c = x();
148
+ return a.current && (c == null || c.observe(a.current)), n.current && (c == null || c.observe(n.current)), () => {
149
+ var b;
150
+ (b = l.current) == null || b.disconnect(), l.current = null, y();
150
151
  };
151
- }, [$, M]), P(() => {
152
- n.current && (C(!0), S());
153
- }, [e.columns, e.cellAspect, e.stackBelow, C, S]), { rootRef: y, gridRef: w, stacked: d };
152
+ }, [x, y]), W(() => {
153
+ a.current && (C(!0), w());
154
+ }, [e.columns, e.cellAspect, e.stackBelow, C, w]), { rootRef: k, gridRef: S, stacked: u };
154
155
  }
155
- const qe = {
156
+ const et = {
156
157
  empty: "Sem dados",
157
158
  error: "Não foi possível carregar",
158
159
  loading: "Carregando...",
159
160
  unconfigured: "Widget não configurado"
160
161
  };
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] });
162
+ function B({ kind: e, message: t }) {
163
+ return /* @__PURE__ */ r("div", { className: `widget__state widget__state--${e}`, role: e === "error" ? "alert" : void 0, children: t || et[e] });
163
164
  }
164
- function W({ 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 }),
165
+ function L({ name: e, title: t, state: a, stateMessage: n, toolbar: l, children: s }) {
166
+ return /* @__PURE__ */ _("div", { className: `widget widget-${e}`, children: [
167
+ t && /* @__PURE__ */ r("span", { className: "widget__title", children: t }),
167
168
  l,
168
- n ? /* @__PURE__ */ a(j, { kind: n, message: r }) : i
169
+ a ? /* @__PURE__ */ r(B, { kind: a, message: n }) : s
169
170
  ] });
170
171
  }
171
- const Ue = { up: "↑", down: "↓" };
172
- function he(e) {
172
+ const tt = { up: "↑", down: "↓" };
173
+ function we(e) {
173
174
  return Array.isArray(e) ? e.filter(
174
175
  (t) => t && t.status === "ok" && t.formatted && t.formatted !== "-"
175
176
  ) : [];
176
177
  }
177
- function Qe({ comparison: e, primary: t }) {
178
- const n = e.sentiment ?? "neutral", r = Ue[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,
178
+ function rt({ comparison: e, primary: t }) {
179
+ const a = e.sentiment ?? "neutral", n = tt[e.trend ?? ""] ?? "";
180
+ return /* @__PURE__ */ _("div", { className: `widget-kpi__trend widget-kpi__trend--${a}${t ? "" : " widget-kpi__trend--muted"}`, children: [
181
+ /* @__PURE__ */ _("span", { className: "widget-kpi__variance", children: [
182
+ n,
182
183
  " ",
183
184
  e.formatted
184
185
  ] }),
185
- e.label && /* @__PURE__ */ a("span", { className: "widget-kpi__trend-label", children: e.label })
186
+ e.label && /* @__PURE__ */ r("span", { className: "widget-kpi__trend-label", children: e.label })
186
187
  ] });
187
188
  }
188
- function Je({ data: e, label: t }) {
189
- const n = t || String(e.label || ""), r = String(e.formatted || "-"), l = he(e.comparisons);
190
- return /* @__PURE__ */ v(W, { name: "kpi", title: n, children: [
191
- /* @__PURE__ */ a("span", { className: "widget-kpi__value", children: r }),
192
- l.map((i, c) => /* @__PURE__ */ a(Qe, { comparison: i, primary: c === 0 }, i.id || c))
189
+ function at({ data: e, label: t }) {
190
+ const a = t || String(e.label || ""), n = String(e.formatted || "-"), l = we(e.comparisons);
191
+ return /* @__PURE__ */ _(L, { name: "kpi", title: a, children: [
192
+ /* @__PURE__ */ r("span", { className: "widget-kpi__value", children: n }),
193
+ l.map((s, o) => /* @__PURE__ */ r(rt, { comparison: s, primary: o === 0 }, s.id || o))
193
194
  ] });
194
195
  }
195
- const Ze = "var(--bg-elevated)", Be = [
196
+ const nt = "var(--bg-elevated)", lt = [
196
197
  [1, "var(--color-success)"],
197
198
  [0.7, ""],
198
199
  // vazio = cor da serie 1 (destaque do dashboard)
199
200
  [0.4, "var(--color-warning)"],
200
201
  [0, "var(--color-error)"]
201
202
  ];
202
- function ee(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 et({ 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, c = String(e.value_formatted || le(e.value, i)), s = String(e.formatted || "-"), h = he(e.comparisons), [o, ...f] = h, u = String((o == null ? void 0 : o.baseline_formatted) || "-"), d = (o == null ? void 0 : o.label) ?? null, g = l >= 1, b = Math.min(Math.max(l, 0), 1), k = Be.find(([y]) => l >= y), C = (k == null ? void 0 : k[1]) || t[0] || "var(--color-info)", M = 50, S = 50, T = 44, $ = 10;
211
- return /* @__PURE__ */ a(W, { 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: ee(M, S, T, 1), fill: "none", stroke: Ze, strokeWidth: $, strokeLinecap: "butt" }),
214
- b > 0 && /* @__PURE__ */ a("path", { d: ee(M, S, T, b), fill: "none", stroke: C, strokeWidth: $, strokeLinecap: "butt" })
203
+ function ae(e, t, a, n) {
204
+ if (n <= 0) return "";
205
+ if (n >= 1)
206
+ return `M ${e - a} ${t} A ${a} ${a} 0 0 1 ${e} ${t - a} A ${a} ${a} 0 0 1 ${e + a} ${t}`;
207
+ const l = n * Math.PI;
208
+ return `M ${e - a} ${t} A ${a} ${a} 0 0 1 ${e - a * Math.cos(l)} ${t - a * Math.sin(l)}`;
209
+ }
210
+ function st({ data: e, palette: t, label: a }) {
211
+ const n = a || String(e.label || ""), l = typeof e.ratio == "number" ? e.ratio : 0, s = typeof e.format == "string" ? e.format : void 0, o = String(e.value_formatted || de(e.value, s)), i = String(e.formatted || "-"), m = we(e.comparisons), [d, ...f] = m, h = String((d == null ? void 0 : d.baseline_formatted) || "-"), u = (d == null ? void 0 : d.label) ?? null, g = l >= 1, p = Math.min(Math.max(l, 0), 1), N = lt.find(([k]) => l >= k), C = (N == null ? void 0 : N[1]) || t[0] || "var(--color-info)", y = 50, w = 50, $ = 44, x = 10;
212
+ return /* @__PURE__ */ r(L, { name: "gauge", title: n, children: /* @__PURE__ */ _("div", { className: "widget-gauge__chart", children: [
213
+ /* @__PURE__ */ _("svg", { viewBox: "0 0 100 56", preserveAspectRatio: "xMidYMax meet", role: "img", "aria-label": `${i} da meta`, children: [
214
+ /* @__PURE__ */ r("path", { d: ae(y, w, $, 1), fill: "none", stroke: nt, strokeWidth: x, strokeLinecap: "butt" }),
215
+ p > 0 && /* @__PURE__ */ r("path", { d: ae(y, w, $, p), fill: "none", stroke: C, strokeWidth: x, strokeLinecap: "butt" })
215
216
  ] }),
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
- c,
217
+ /* @__PURE__ */ _("div", { className: "widget-gauge__center", children: [
218
+ /* @__PURE__ */ r("span", { className: "widget-gauge__percent", children: i }),
219
+ /* @__PURE__ */ _("span", { className: "widget-gauge__comparison", children: [
220
+ o,
220
221
  " / ",
221
- u
222
+ h
222
223
  ] }),
223
- g && /* @__PURE__ */ a("span", { className: "widget-gauge__badge", children: d || "Meta batida" }),
224
- !g && d && /* @__PURE__ */ a("span", { className: "widget-gauge__comparison", children: d }),
225
- f.map((y, w) => /* @__PURE__ */ v("span", { className: "widget-gauge__comparison", children: [
226
- y.formatted,
224
+ g && /* @__PURE__ */ r("span", { className: "widget-gauge__badge", children: u || "Meta batida" }),
225
+ !g && u && /* @__PURE__ */ r("span", { className: "widget-gauge__comparison", children: u }),
226
+ f.map((k, S) => /* @__PURE__ */ _("span", { className: "widget-gauge__comparison", children: [
227
+ k.formatted,
227
228
  " ",
228
- y.label
229
- ] }, y.id || w))
229
+ k.label
230
+ ] }, k.id || S))
230
231
  ] })
231
232
  ] }) });
232
233
  }
233
- function X(e) {
234
- const [t, n] = E({ 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: c, height: s } = i.contentRect;
240
- n(
241
- (h) => h.width !== Math.floor(c) || h.height !== Math.floor(s) ? { width: Math.floor(c), height: Math.floor(s) } : h
234
+ function q(e) {
235
+ const [t, a] = I({ width: 0, height: 0 });
236
+ return W(() => {
237
+ const n = e.current;
238
+ if (!n) return;
239
+ const l = new ResizeObserver(([s]) => {
240
+ const { width: o, height: i } = s.contentRect;
241
+ a(
242
+ (m) => m.width !== Math.floor(o) || m.height !== Math.floor(i) ? { width: Math.floor(o), height: Math.floor(i) } : m
242
243
  );
243
244
  });
244
- return l.observe(r), () => l.disconnect();
245
+ return l.observe(n), () => l.disconnect();
245
246
  }, [e]), t;
246
247
  }
247
- const te = { fontSize: 10, fill: "var(--text-muted)" }, tt = "var(--bg-elevated)", rt = {
248
+ const ne = { fontSize: 10, fill: "var(--text-muted)" }, it = "var(--bg-elevated)", ot = {
248
249
  backgroundColor: "var(--bg-elevated)",
249
250
  border: "1px solid var(--bg-paper)",
250
251
  borderRadius: "6px",
251
252
  color: "var(--text-primary)"
252
- }, nt = {
253
+ }, ct = {
253
254
  color: "var(--text-primary)",
254
255
  fontWeight: 600
255
256
  };
256
- function at(e, t) {
257
+ function dt(e, t) {
257
258
  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 ?? "");
260
- }
261
- function Y({ Chart: e, chartData: t, xKey: n, series: r, palette: l, renderSeries: i, width: c, height: s }) {
262
- return /* @__PURE__ */ v(e, { data: t, width: c, height: s, children: [
263
- /* @__PURE__ */ a(oe, { strokeDasharray: "3 3", stroke: tt }),
264
- /* @__PURE__ */ a(de, { dataKey: n, tick: te }),
265
- /* @__PURE__ */ a(ue, { tick: te }),
266
- /* @__PURE__ */ a(
259
+ const a = Array.isArray(t) ? t[0] : void 0, n = (l = a == null ? void 0 : a.payload) == null ? void 0 : l.tooltipLabel;
260
+ return typeof n == "string" && n ? n : String(e ?? "");
261
+ }
262
+ function G({ Chart: e, chartData: t, xKey: a, series: n, palette: l, renderSeries: s, width: o, height: i }) {
263
+ return /* @__PURE__ */ _(e, { data: t, width: o, height: i, children: [
264
+ /* @__PURE__ */ r(_e, { strokeDasharray: "3 3", stroke: it }),
265
+ /* @__PURE__ */ r(pe, { dataKey: a, tick: ne }),
266
+ /* @__PURE__ */ r(be, { tick: ne }),
267
+ /* @__PURE__ */ r(
267
268
  K,
268
269
  {
269
- contentStyle: rt,
270
- labelStyle: nt,
271
- labelFormatter: at,
270
+ contentStyle: ot,
271
+ labelStyle: ct,
272
+ labelFormatter: dt,
272
273
  cursor: { fill: "var(--bg-paper)", opacity: 0.3 }
273
274
  }
274
275
  ),
275
- r.length > 1 && /* @__PURE__ */ a(Le, {}),
276
- r.map((h, o) => i(h, l[o % l.length], o))
276
+ n.length > 1 && /* @__PURE__ */ r(je, {}),
277
+ n.map((m, d) => s(m, l[d % l.length], d))
277
278
  ] });
278
279
  }
279
- function lt({ data: e, palette: t, label: n }) {
280
- const r = String(e.chartType || "bar"), l = n || String(e.label || ""), i = String(e.xKey || "label"), c = e.series || [], s = e.data || [], h = N(null), { width: o, height: f } = X(h), u = () => {
281
- if (o <= 0 || f <= 0) return null;
282
- const d = { chartData: s, xKey: i, series: c, palette: t, width: o, height: f };
283
- return r === "line" ? /* @__PURE__ */ a(Y, { ...d, Chart: Ee, renderSeries: (g, b) => /* @__PURE__ */ a(
284
- Fe,
280
+ function ut({ data: e, palette: t, label: a }) {
281
+ const n = String(e.chartType || "bar"), l = a || String(e.label || ""), s = String(e.xKey || "label"), o = e.series || [], i = e.data || [], m = R(null), { width: d, height: f } = q(m), h = () => {
282
+ if (d <= 0 || f <= 0) return null;
283
+ const u = { chartData: i, xKey: s, series: o, palette: t, width: d, height: f };
284
+ return n === "line" ? /* @__PURE__ */ r(G, { ...u, Chart: He, renderSeries: (g, p) => /* @__PURE__ */ r(
285
+ ze,
285
286
  {
286
287
  type: "monotone",
287
288
  dataKey: g.key,
288
289
  name: g.label,
289
- stroke: b,
290
+ stroke: p,
290
291
  strokeWidth: 2,
291
- dot: s.length <= 31
292
+ dot: i.length <= 31
292
293
  },
293
294
  g.key
294
- ) }) : r === "area" ? /* @__PURE__ */ a(Y, { ...d, Chart: Ie, renderSeries: (g, b) => /* @__PURE__ */ a(
295
- We,
295
+ ) }) : n === "area" ? /* @__PURE__ */ r(G, { ...u, Chart: Ge, renderSeries: (g, p) => /* @__PURE__ */ r(
296
+ Ye,
296
297
  {
297
298
  type: "monotone",
298
299
  dataKey: g.key,
299
300
  name: g.label,
300
- fill: b,
301
- stroke: b,
301
+ fill: p,
302
+ stroke: p,
302
303
  fillOpacity: 0.3
303
304
  },
304
305
  g.key
305
- ) }) : /* @__PURE__ */ a(Y, { ...d, Chart: ce, renderSeries: (g, b) => /* @__PURE__ */ a(
306
- z,
306
+ ) }) : /* @__PURE__ */ r(G, { ...u, Chart: fe, renderSeries: (g, p) => /* @__PURE__ */ r(
307
+ V,
307
308
  {
308
309
  dataKey: g.key,
309
310
  name: g.label,
310
- fill: b,
311
+ fill: p,
311
312
  radius: [3, 3, 0, 0]
312
313
  },
313
314
  g.key
314
315
  ) });
315
316
  };
316
- return /* @__PURE__ */ a(W, { 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
+ return /* @__PURE__ */ r(L, { name: "chart", title: l, children: /* @__PURE__ */ r("div", { ref: m, className: "widget-chart__container", children: i.length === 0 ? /* @__PURE__ */ r(B, { kind: "empty" }) : h() }) });
317
318
  }
318
- const re = { fontSize: 10, fill: "var(--text-muted)" }, it = "var(--bg-elevated)", st = { fill: "var(--bg-paper)", opacity: 0.3 };
319
- function ct(e) {
319
+ const le = { fontSize: 10, fill: "var(--text-muted)" }, mt = "var(--bg-elevated)", ht = { fill: "var(--bg-paper)", opacity: 0.3 };
320
+ function gt(e) {
320
321
  return e.kind === "anchor" ? "var(--color-accent)" : e.kind === "residual" ? "var(--color-warning)" : e.value < 0 ? "var(--color-error)" : "var(--color-success)";
321
322
  }
322
- function ne({ active: e, payload: t }) {
323
- var r;
324
- const n = e ? (r = t == null ? void 0 : t[0]) == null ? void 0 : r.payload : void 0;
325
- return n ? /* @__PURE__ */ v("div", { className: "widget-composition__tooltip", children: [
326
- /* @__PURE__ */ a("span", { className: "widget-composition__tooltip-label", children: n.label }),
327
- /* @__PURE__ */ a("span", { className: "widget-composition__tooltip-value", children: n.formatted })
323
+ function se({ active: e, payload: t }) {
324
+ var n;
325
+ const a = e ? (n = t == null ? void 0 : t[0]) == null ? void 0 : n.payload : void 0;
326
+ return a ? /* @__PURE__ */ _("div", { className: "widget-composition__tooltip", children: [
327
+ /* @__PURE__ */ r("span", { className: "widget-composition__tooltip-label", children: a.label }),
328
+ /* @__PURE__ */ r("span", { className: "widget-composition__tooltip-value", children: a.formatted })
328
329
  ] }) : null;
329
330
  }
330
- function ot({ data: e, palette: t, label: n }) {
331
- const r = n || String(e.label || ""), l = String(e.display || "pie"), i = e.data || [], c = typeof e.format == "string" ? e.format : void 0, s = N(null), { width: h, height: o } = X(s), f = () => /* @__PURE__ */ v(ce, { data: i, width: h, height: o, children: [
332
- /* @__PURE__ */ a(oe, { strokeDasharray: "3 3", stroke: it }),
333
- /* @__PURE__ */ a(de, { dataKey: "label", tick: re, interval: 0 }),
334
- /* @__PURE__ */ a(ue, { tick: re, tickFormatter: (d) => le(d, c) }),
335
- /* @__PURE__ */ a(K, { content: /* @__PURE__ */ a(ne, {}), cursor: st }),
336
- /* @__PURE__ */ a(z, { dataKey: "base", stackId: "bridge", fill: "none", fillOpacity: 0, isAnimationActive: !1 }),
337
- /* @__PURE__ */ a(z, { dataKey: "span", stackId: "bridge", radius: [3, 3, 0, 0], children: i.map((d, g) => /* @__PURE__ */ a(B, { fill: ct(d) }, g)) })
338
- ] }), u = () => /* @__PURE__ */ v(Oe, { width: h, height: o, children: [
339
- /* @__PURE__ */ a(
340
- Pe,
331
+ function ft({ data: e, palette: t, label: a }) {
332
+ const n = a || String(e.label || ""), l = String(e.display || "pie"), s = e.data || [], o = typeof e.format == "string" ? e.format : void 0, i = R(null), { width: m, height: d } = q(i), f = () => /* @__PURE__ */ _(fe, { data: s, width: m, height: d, children: [
333
+ /* @__PURE__ */ r(_e, { strokeDasharray: "3 3", stroke: mt }),
334
+ /* @__PURE__ */ r(pe, { dataKey: "label", tick: le, interval: 0 }),
335
+ /* @__PURE__ */ r(be, { tick: le, tickFormatter: (u) => de(u, o) }),
336
+ /* @__PURE__ */ r(K, { content: /* @__PURE__ */ r(se, {}), cursor: ht }),
337
+ /* @__PURE__ */ r(V, { dataKey: "base", stackId: "bridge", fill: "none", fillOpacity: 0, isAnimationActive: !1 }),
338
+ /* @__PURE__ */ r(V, { dataKey: "span", stackId: "bridge", radius: [3, 3, 0, 0], children: s.map((u, g) => /* @__PURE__ */ r(te, { fill: gt(u) }, g)) })
339
+ ] }), h = () => /* @__PURE__ */ _(Ve, { width: m, height: d, children: [
340
+ /* @__PURE__ */ r(
341
+ Ke,
341
342
  {
342
- data: i,
343
+ data: s,
343
344
  dataKey: "value",
344
345
  nameKey: "label",
345
346
  cx: "50%",
346
347
  cy: "50%",
347
348
  outerRadius: "75%",
348
- label: ({ name: d, percent: g }) => `${d}: ${(g * 100).toFixed(0)}%`,
349
+ label: ({ name: u, percent: g }) => `${u}: ${(g * 100).toFixed(0)}%`,
349
350
  labelLine: !1,
350
- children: i.map((d, g) => /* @__PURE__ */ a(B, { fill: t[g % t.length] }, g))
351
+ children: s.map((u, g) => /* @__PURE__ */ r(te, { fill: t[g % t.length] }, g))
351
352
  }
352
353
  ),
353
- /* @__PURE__ */ a(K, { content: /* @__PURE__ */ a(ne, {}) })
354
+ /* @__PURE__ */ r(K, { content: /* @__PURE__ */ r(se, {}) })
354
355
  ] });
355
- return /* @__PURE__ */ a(W, { name: "composition", title: r, children: /* @__PURE__ */ a("div", { ref: s, className: "widget-composition__container", children: i.length === 0 || h <= 0 || o <= 0 ? /* @__PURE__ */ a(j, { kind: "empty" }) : l === "bridge" ? f() : u() }) });
356
+ return /* @__PURE__ */ r(L, { name: "composition", title: n, children: /* @__PURE__ */ r("div", { ref: i, className: "widget-composition__container", children: s.length === 0 || m <= 0 || d <= 0 ? /* @__PURE__ */ r(B, { kind: "empty" }) : l === "bridge" ? f() : h() }) });
356
357
  }
357
- function dt(e, t) {
358
+ function _t(e, t) {
358
359
  if (t !== "percentage") return "";
359
- const n = Number(e);
360
- return Number.isNaN(n) || n === 0 ? "" : n > 0 ? " widget-table__td--up" : " widget-table__td--down";
360
+ const a = Number(e);
361
+ return Number.isNaN(a) || a === 0 ? "" : a > 0 ? " widget-table__td--up" : " widget-table__td--down";
361
362
  }
362
- function ut(e, t, n, r) {
363
- const l = (r == null ? void 0 : r.offsetHeight) ?? 0;
363
+ function pt(e, t, a, n) {
364
+ const l = (n == null ? void 0 : n.offsetHeight) ?? 0;
364
365
  if (e === 0 || t <= 0 || l <= 0) return e;
365
- const i = Math.floor((t - ((n == null ? void 0 : n.offsetHeight) ?? 0)) / l);
366
- return Math.max(0, Math.min(e, i));
366
+ const s = Math.floor((t - ((a == null ? void 0 : a.offsetHeight) ?? 0)) / l);
367
+ return Math.max(0, Math.min(e, s));
367
368
  }
368
- function ht({ data: e, label: t }) {
369
- var d;
370
- const n = e.columns || [], r = e.rows || [], l = e.overflow === "clip", i = e.indexColumn === !0, c = t || String(e.label || ""), s = N(null), h = N(null), o = N(null), { height: f } = X(s), u = l ? r.slice(0, ut(
371
- r.length,
369
+ function bt({ data: e, label: t }) {
370
+ var u;
371
+ const a = e.columns || [], n = e.rows || [], l = e.overflow === "clip", s = e.indexColumn === !0, o = t || String(e.label || ""), i = R(null), m = R(null), d = R(null), { height: f } = q(i), h = l ? n.slice(0, pt(
372
+ n.length,
372
373
  f,
373
- h.current,
374
- ((d = o.current) == null ? void 0 : d.firstElementChild) ?? null
375
- )) : r;
376
- return n.length === 0 ? /* @__PURE__ */ a(
377
- W,
374
+ m.current,
375
+ ((u = d.current) == null ? void 0 : u.firstElementChild) ?? null
376
+ )) : n;
377
+ return a.length === 0 ? /* @__PURE__ */ r(
378
+ L,
378
379
  {
379
380
  name: "table",
380
- title: c,
381
+ title: o,
381
382
  state: "unconfigured",
382
383
  stateMessage: "Configure as colunas da tabela."
383
384
  }
384
- ) : /* @__PURE__ */ a(W, { name: "table", title: c, children: /* @__PURE__ */ a(
385
+ ) : /* @__PURE__ */ r(L, { name: "table", title: o, children: /* @__PURE__ */ r(
385
386
  "div",
386
387
  {
387
- ref: s,
388
+ ref: i,
388
389
  className: `widget-table__scroll${l ? " widget-table__scroll--clip" : ""}`,
389
- children: /* @__PURE__ */ v(
390
+ children: /* @__PURE__ */ _(
390
391
  "table",
391
392
  {
392
- className: `widget-table__table${l && u.length < r.length ? "" : " widget-table__table--fill"}`,
393
+ className: `widget-table__table${l && h.length < n.length ? "" : " widget-table__table--fill"}`,
393
394
  children: [
394
- /* @__PURE__ */ a("thead", { ref: h, children: /* @__PURE__ */ v("tr", { children: [
395
- i && /* @__PURE__ */ a("th", { className: "widget-table__th widget-table__th--index", children: "#" }),
396
- n.map((g) => /* @__PURE__ */ a(
395
+ /* @__PURE__ */ r("thead", { ref: m, children: /* @__PURE__ */ _("tr", { children: [
396
+ s && /* @__PURE__ */ r("th", { className: "widget-table__th widget-table__th--index", children: "#" }),
397
+ a.map((g) => /* @__PURE__ */ r(
397
398
  "th",
398
399
  {
399
- className: `widget-table__th${Q(g.format) ? " widget-table__th--num" : ""}`,
400
+ className: `widget-table__th${J(g.format) ? " widget-table__th--num" : ""}`,
400
401
  children: g.label || g.key
401
402
  },
402
403
  g.key
403
404
  ))
404
405
  ] }) }),
405
- /* @__PURE__ */ a("tbody", { ref: o, children: u.length === 0 ? /* @__PURE__ */ a("tr", { children: /* @__PURE__ */ a(
406
+ /* @__PURE__ */ r("tbody", { ref: d, children: h.length === 0 ? /* @__PURE__ */ r("tr", { children: /* @__PURE__ */ r(
406
407
  "td",
407
408
  {
408
409
  className: "widget-table__td widget-table__td--placeholder",
409
- colSpan: n.length + (i ? 1 : 0),
410
+ colSpan: a.length + (s ? 1 : 0),
410
411
  children: "Sem dados"
411
412
  }
412
- ) }) : u.map((g, b) => /* @__PURE__ */ v("tr", { children: [
413
- i && /* @__PURE__ */ a("td", { className: "widget-table__td widget-table__td--index", children: b + 1 }),
414
- n.map((k) => {
415
- const C = g[k.key], M = Q(k.format) ? " widget-table__td--num" : "";
416
- return /* @__PURE__ */ a("td", { className: `widget-table__td${M}${dt(C, k.format)}`, children: _e(C, k.format) }, k.key);
413
+ ) }) : h.map((g, p) => /* @__PURE__ */ _("tr", { children: [
414
+ s && /* @__PURE__ */ r("td", { className: "widget-table__td widget-table__td--index", children: p + 1 }),
415
+ a.map((N) => {
416
+ const C = g[N.key], y = J(N.format) ? " widget-table__td--num" : "";
417
+ return /* @__PURE__ */ r("td", { className: `widget-table__td${y}${_t(C, N.format)}`, children: j(C, N.format) }, N.key);
417
418
  })
418
- ] }, b)) })
419
+ ] }, p)) })
419
420
  ]
420
421
  }
421
422
  )
422
423
  }
423
424
  ) });
424
425
  }
425
- function gt({ config: e, value: t, options: n = [], dateBounds: r, onChange: l }) {
426
- const i = e.filterType || "select", c = e.label || "Filtro", s = e.dateFilterMode || "range";
427
- return /* @__PURE__ */ v("div", { className: "widget-filter", children: [
428
- /* @__PURE__ */ a("label", { className: "widget-filter__label", children: c }),
429
- 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(_t, { value: t, dateBounds: r, onChange: l }) : /* @__PURE__ */ a(mt, { value: t, dateBounds: r, onChange: l }) : /* @__PURE__ */ a(
430
- bt,
426
+ function vt({ config: e, value: t, options: a = [], dateBounds: n, onChange: l }) {
427
+ const s = e.filterType || "select", o = e.label || "Filtro", i = e.dateFilterMode || "range";
428
+ return /* @__PURE__ */ _("div", { className: "widget-filter", children: [
429
+ /* @__PURE__ */ r("label", { className: "widget-filter__label", children: o }),
430
+ s === "date_range" ? i === "yearly" ? /* @__PURE__ */ r(yt, { value: t, dateBounds: n, onChange: l }) : i === "monthly" ? /* @__PURE__ */ r(Nt, { value: t, dateBounds: n, onChange: l }) : i === "weekly" ? /* @__PURE__ */ r(St, { value: t, dateBounds: n, onChange: l }) : /* @__PURE__ */ r(wt, { value: t, dateBounds: n, onChange: l }) : /* @__PURE__ */ r(
431
+ kt,
431
432
  {
432
433
  value: t,
433
- options: n,
434
- multi: i === "multi_select",
434
+ options: a,
435
+ multi: s === "multi_select",
435
436
  searchable: e.searchable || !1,
436
437
  onChange: l
437
438
  }
438
439
  )
439
440
  ] });
440
441
  }
441
- function mt({ value: e, dateBounds: t, onChange: n }) {
442
- const [r, l] = e ? e.split("|") : ["", ""];
443
- return /* @__PURE__ */ v("div", { className: "widget-filter__date-range widget-filter__date-range--stacked", children: [
444
- /* @__PURE__ */ a(
445
- J,
442
+ function wt({ value: e, dateBounds: t, onChange: a }) {
443
+ const [n, l] = e ? e.split("|") : ["", ""];
444
+ return /* @__PURE__ */ _("div", { className: "widget-filter__date-range widget-filter__date-range--stacked", children: [
445
+ /* @__PURE__ */ r(
446
+ D,
446
447
  {
447
- value: r,
448
+ value: n,
448
449
  minIso: t == null ? void 0 : t.min,
449
450
  maxIso: l || (t == null ? void 0 : t.max),
450
451
  selectsStart: !0,
451
- startIso: r,
452
+ startIso: n,
452
453
  endIso: l,
453
454
  placeholder: "Data inicial",
454
- onChange: (i) => n(`${i}|${l}`)
455
+ onChange: (s) => a(`${s}|${l}`)
455
456
  }
456
457
  ),
457
- /* @__PURE__ */ a(
458
- J,
458
+ /* @__PURE__ */ r(
459
+ D,
459
460
  {
460
461
  value: l,
461
- minIso: r || (t == null ? void 0 : t.min),
462
+ minIso: n || (t == null ? void 0 : t.min),
462
463
  maxIso: t == null ? void 0 : t.max,
463
464
  selectsEnd: !0,
464
- startIso: r,
465
+ startIso: n,
465
466
  endIso: l,
466
467
  placeholder: "Data final",
467
- onChange: (i) => n(`${r}|${i}`)
468
+ onChange: (s) => a(`${n}|${s}`)
468
469
  }
469
470
  )
470
471
  ] });
471
472
  }
472
- function ft({ value: e, dateBounds: t, onChange: n }) {
473
- const [r] = e ? e.split("|") : [""], l = be(r), i = /* @__PURE__ */ new Date(), c = (l == null ? void 0 : l.year) ?? i.getFullYear(), s = V(t), h = (o) => {
474
- const f = ke(o);
475
- n(`${f.start}|${f.end}`);
473
+ function yt({ value: e, dateBounds: t, onChange: a }) {
474
+ const [n] = e ? e.split("|") : [""], l = Ce(n), s = /* @__PURE__ */ new Date(), o = (l == null ? void 0 : l.year) ?? s.getFullYear(), i = X(t), m = (d) => {
475
+ const f = xe(d);
476
+ a(`${f.start}|${f.end}`);
476
477
  };
477
- return /* @__PURE__ */ a("div", { className: "widget-filter__date-range widget-filter__date-range--year", children: /* @__PURE__ */ a(
478
+ return /* @__PURE__ */ r("div", { className: "widget-filter__date-range widget-filter__date-range--year", children: /* @__PURE__ */ r(
478
479
  "select",
479
480
  {
480
481
  className: "widget-filter__select",
481
- value: c,
482
- onChange: (o) => h(parseInt(o.target.value)),
483
- children: s.map((o) => /* @__PURE__ */ a("option", { value: o, children: o }, o))
482
+ value: o,
483
+ onChange: (d) => m(parseInt(d.target.value)),
484
+ children: i.map((d) => /* @__PURE__ */ r("option", { value: d, children: d }, d))
484
485
  }
485
486
  ) });
486
487
  }
487
- function pt({ value: e, dateBounds: t, onChange: n }) {
488
- const [r] = e ? e.split("|") : [""], l = ie(r), i = /* @__PURE__ */ new Date(), c = (l == null ? void 0 : l.year) ?? i.getFullYear(), s = (l == null ? void 0 : l.month) ?? i.getMonth() + 1, h = V(t), o = (f, u) => {
489
- const d = ye(f, u);
490
- n(`${d.start}|${d.end}`);
488
+ function Nt({ value: e, dateBounds: t, onChange: a }) {
489
+ const [n] = e ? e.split("|") : [""], l = ue(n), s = /* @__PURE__ */ new Date(), o = (l == null ? void 0 : l.year) ?? s.getFullYear(), i = (l == null ? void 0 : l.month) ?? s.getMonth() + 1, m = X(t), d = (f, h) => {
490
+ const u = $e(f, h);
491
+ a(`${u.start}|${u.end}`);
491
492
  };
492
- return /* @__PURE__ */ v("div", { className: "widget-filter__date-range widget-filter__date-range--month", children: [
493
- /* @__PURE__ */ a(
493
+ return /* @__PURE__ */ _("div", { className: "widget-filter__date-range widget-filter__date-range--month", children: [
494
+ /* @__PURE__ */ r(
494
495
  "select",
495
496
  {
496
497
  className: "widget-filter__select",
497
- value: s,
498
- onChange: (f) => o(c, parseInt(f.target.value)),
499
- children: se.map((f, u) => /* @__PURE__ */ a("option", { value: u + 1, children: f }, u + 1))
498
+ value: i,
499
+ onChange: (f) => d(o, parseInt(f.target.value)),
500
+ children: me.map((f, h) => /* @__PURE__ */ r("option", { value: h + 1, children: f }, h + 1))
500
501
  }
501
502
  ),
502
- /* @__PURE__ */ a(
503
+ /* @__PURE__ */ r(
503
504
  "select",
504
505
  {
505
506
  className: "widget-filter__select",
506
- value: c,
507
- onChange: (f) => o(parseInt(f.target.value), s),
508
- children: h.map((f) => /* @__PURE__ */ a("option", { value: f, children: f }, f))
507
+ value: o,
508
+ onChange: (f) => d(parseInt(f.target.value), i),
509
+ children: m.map((f) => /* @__PURE__ */ r("option", { value: f, children: f }, f))
509
510
  }
510
511
  )
511
512
  ] });
512
513
  }
513
- function _t({ value: e, dateBounds: t, onChange: n }) {
514
- const [r] = e ? e.split("|") : [""], l = ie(r), i = /* @__PURE__ */ new Date(), c = (l == null ? void 0 : l.year) ?? i.getFullYear(), s = (l == null ? void 0 : l.month) ?? i.getMonth() + 1, h = V(t), o = H(c, s), f = ve(r, c, s) || 1;
515
- return /* @__PURE__ */ v("div", { className: "widget-filter__date-range widget-filter__date-range--week", children: [
516
- /* @__PURE__ */ a(
514
+ function St({ value: e, dateBounds: t, onChange: a }) {
515
+ const [n] = e ? e.split("|") : [""], l = ue(n), s = /* @__PURE__ */ new Date(), o = (l == null ? void 0 : l.year) ?? s.getFullYear(), i = (l == null ? void 0 : l.month) ?? s.getMonth() + 1, m = X(t), d = z(o, i), f = Re(n, o, i) || 1;
516
+ return /* @__PURE__ */ _("div", { className: "widget-filter__date-range widget-filter__date-range--week", children: [
517
+ /* @__PURE__ */ r(
517
518
  "select",
518
519
  {
519
520
  className: "widget-filter__select",
520
- value: c,
521
- onChange: (u) => {
522
- const d = parseInt(u.target.value), b = H(d, s)[0];
523
- b && n(`${b.start}|${b.end}`);
521
+ value: o,
522
+ onChange: (h) => {
523
+ const u = parseInt(h.target.value), p = z(u, i)[0];
524
+ p && a(`${p.start}|${p.end}`);
524
525
  },
525
- children: h.map((u) => /* @__PURE__ */ a("option", { value: u, children: u }, u))
526
+ children: m.map((h) => /* @__PURE__ */ r("option", { value: h, children: h }, h))
526
527
  }
527
528
  ),
528
- /* @__PURE__ */ a(
529
+ /* @__PURE__ */ r(
529
530
  "select",
530
531
  {
531
532
  className: "widget-filter__select",
532
- value: s,
533
- onChange: (u) => {
534
- const d = parseInt(u.target.value), b = H(c, d)[0];
535
- b && n(`${b.start}|${b.end}`);
533
+ value: i,
534
+ onChange: (h) => {
535
+ const u = parseInt(h.target.value), p = z(o, u)[0];
536
+ p && a(`${p.start}|${p.end}`);
536
537
  },
537
- children: se.map((u, d) => /* @__PURE__ */ a("option", { value: d + 1, children: u }, d + 1))
538
+ children: me.map((h, u) => /* @__PURE__ */ r("option", { value: u + 1, children: h }, u + 1))
538
539
  }
539
540
  ),
540
- /* @__PURE__ */ a(
541
+ /* @__PURE__ */ r(
541
542
  "select",
542
543
  {
543
544
  className: "widget-filter__select",
544
545
  value: f,
545
- onChange: (u) => {
546
- const d = o[parseInt(u.target.value) - 1];
547
- d && n(`${d.start}|${d.end}`);
546
+ onChange: (h) => {
547
+ const u = d[parseInt(h.target.value) - 1];
548
+ u && a(`${u.start}|${u.end}`);
548
549
  },
549
- children: o.map((u) => /* @__PURE__ */ a("option", { value: u.index, children: u.label }, u.index))
550
+ children: d.map((h) => /* @__PURE__ */ r("option", { value: h.index, children: h.label }, h.index))
550
551
  }
551
552
  )
552
553
  ] });
553
554
  }
554
- function bt({ value: e, options: t, multi: n, searchable: r, onChange: l }) {
555
- if (r)
556
- return /* @__PURE__ */ a(
557
- we,
555
+ function kt({ value: e, options: t, multi: a, searchable: n, onChange: l }) {
556
+ if (n)
557
+ return /* @__PURE__ */ r(
558
+ he,
558
559
  {
559
560
  value: e,
560
561
  options: t,
561
- multi: n,
562
+ multi: a,
562
563
  onChange: l
563
564
  }
564
565
  );
565
- if (n) {
566
- const i = e ? e.split(G) : [], c = (s) => {
567
- const h = i.includes(s) ? i.filter((o) => o !== s) : [...i, s];
568
- l(h.join(G));
566
+ if (a) {
567
+ const s = e ? e.split(Y) : [], o = (i) => {
568
+ const m = s.includes(i) ? s.filter((d) => d !== i) : [...s, i];
569
+ l(m.join(Y));
569
570
  };
570
- return /* @__PURE__ */ v("div", { className: "widget-filter__multi", children: [
571
- i.length > 0 && /* @__PURE__ */ a(
571
+ return /* @__PURE__ */ _("div", { className: "widget-filter__multi", children: [
572
+ s.length > 0 && /* @__PURE__ */ r(
572
573
  "button",
573
574
  {
574
575
  type: "button",
@@ -577,231 +578,463 @@ function bt({ value: e, options: t, multi: n, searchable: r, onChange: l }) {
577
578
  children: "Limpar filtro"
578
579
  }
579
580
  ),
580
- t.map((s) => /* @__PURE__ */ v("label", { className: "widget-filter__multi-option", children: [
581
- /* @__PURE__ */ a(
581
+ t.map((i) => /* @__PURE__ */ _("label", { className: "widget-filter__multi-option", children: [
582
+ /* @__PURE__ */ r(
582
583
  "input",
583
584
  {
584
585
  type: "checkbox",
585
- checked: i.includes(s),
586
- onChange: () => c(s)
586
+ checked: s.includes(i),
587
+ onChange: () => o(i)
587
588
  }
588
589
  ),
589
- s
590
- ] }, s))
590
+ i
591
+ ] }, i))
591
592
  ] });
592
593
  }
593
- return /* @__PURE__ */ v(
594
+ return /* @__PURE__ */ _(
594
595
  "select",
595
596
  {
596
597
  className: "widget-filter__select",
597
598
  value: e,
598
- onChange: (i) => l(i.target.value),
599
+ onChange: (s) => l(s.target.value),
599
600
  children: [
600
- /* @__PURE__ */ a("option", { value: "", children: "Todos" }),
601
- t.map((i) => /* @__PURE__ */ a("option", { value: i, children: i }, i))
601
+ /* @__PURE__ */ r("option", { value: "", children: "Todos" }),
602
+ t.map((s) => /* @__PURE__ */ r("option", { value: s, children: s }, s))
602
603
  ]
603
604
  }
604
605
  );
605
606
  }
606
- const vt = {
607
+ const Ct = {
607
608
  currency: "R$",
608
609
  percentage: "%"
609
610
  };
610
- function wt({ config: e, value: t, onChange: n }) {
611
- const r = e.label || "Variavel", l = e.locked || !1, i = e.variableFormat || "number", c = vt[i] || "";
612
- return /* @__PURE__ */ v("div", { className: `widget-variable ${l ? "widget-variable--locked" : ""}`, children: [
613
- /* @__PURE__ */ a("label", { className: "widget-variable__label", children: r }),
614
- /* @__PURE__ */ v("div", { className: "widget-variable__input-wrapper", children: [
615
- /* @__PURE__ */ a(
611
+ function Rt({ config: e, value: t, onChange: a }) {
612
+ const n = e.label || "Variavel", l = e.locked || !1, s = e.variableFormat || "number", o = Ct[s] || "";
613
+ return /* @__PURE__ */ _("div", { className: `widget-variable ${l ? "widget-variable--locked" : ""}`, children: [
614
+ /* @__PURE__ */ r("label", { className: "widget-variable__label", children: n }),
615
+ /* @__PURE__ */ _("div", { className: "widget-variable__input-wrapper", children: [
616
+ /* @__PURE__ */ r(
616
617
  "input",
617
618
  {
618
619
  className: "widget-variable__input",
619
620
  type: "number",
620
621
  value: t,
621
- onChange: (s) => n(parseFloat(s.target.value) || 0),
622
+ onChange: (i) => a(parseFloat(i.target.value) || 0),
622
623
  disabled: l,
623
- step: i === "integer" ? 1 : 0.01
624
+ step: s === "integer" ? 1 : 0.01
624
625
  }
625
626
  ),
626
- c && /* @__PURE__ */ a("span", { className: "widget-variable__suffix", children: c })
627
+ o && /* @__PURE__ */ r("span", { className: "widget-variable__suffix", children: o })
627
628
  ] }),
628
- l && /* @__PURE__ */ a("span", { className: "widget-variable__lock-icon", title: "Bloqueado", children: "🔒" })
629
+ l && /* @__PURE__ */ r("span", { className: "widget-variable__lock-icon", title: "Bloqueado", children: "🔒" })
629
630
  ] });
630
631
  }
631
- function yt({ config: e, palette: t, onChange: n }) {
632
- const r = e.label || "Cores", l = e.locked || !1;
633
- return /* @__PURE__ */ v("div", { className: `widget-palette ${l ? "widget-palette--locked" : ""}`, children: [
634
- /* @__PURE__ */ a("label", { className: "widget-palette__label", children: r }),
635
- /* @__PURE__ */ a(Se, { selected: t, onSelect: n, customMode: !0, disabled: l }),
636
- l && /* @__PURE__ */ a("span", { className: "widget-palette__lock-icon", title: "Bloqueado", children: "🔒" })
632
+ function $t({ config: e, palette: t, onChange: a }) {
633
+ const n = e.label || "Cores", l = e.locked || !1;
634
+ return /* @__PURE__ */ _("div", { className: `widget-palette ${l ? "widget-palette--locked" : ""}`, children: [
635
+ /* @__PURE__ */ r("label", { className: "widget-palette__label", children: n }),
636
+ /* @__PURE__ */ r(Ie, { selected: t, onSelect: a, customMode: !0, disabled: l }),
637
+ l && /* @__PURE__ */ r("span", { className: "widget-palette__lock-icon", title: "Bloqueado", children: "🔒" })
637
638
  ] });
638
639
  }
639
- const kt = {
640
+ const xt = {
640
641
  failed_to_compute: "Não foi possível calcular este widget"
641
642
  };
642
- function St({
643
+ function It({
643
644
  type: e,
644
645
  computed: t,
645
- palette: n,
646
- config: r,
646
+ palette: a,
647
+ config: n,
647
648
  filterValue: l,
648
- filterOptions: i,
649
- dateBounds: c,
650
- onFilterChange: s,
651
- variableValue: h,
652
- onVariableChange: o,
649
+ filterOptions: s,
650
+ dateBounds: o,
651
+ onFilterChange: i,
652
+ variableValue: m,
653
+ onVariableChange: d,
653
654
  onPaletteChange: f
654
655
  }) {
655
656
  if (t.error)
656
- return /* @__PURE__ */ a(
657
- W,
657
+ return /* @__PURE__ */ r(
658
+ L,
658
659
  {
659
660
  name: e.replace("_", "-"),
660
- title: r == null ? void 0 : r.label,
661
+ title: n == null ? void 0 : n.label,
661
662
  state: "error",
662
- stateMessage: kt[String(t.error)]
663
+ stateMessage: xt[String(t.error)]
663
664
  }
664
665
  );
665
- const u = Ne(n);
666
+ const h = Ae(a);
666
667
  switch (e) {
667
668
  case "kpi_card":
668
- return /* @__PURE__ */ a(Je, { data: t, label: r == null ? void 0 : r.label });
669
+ return /* @__PURE__ */ r(at, { data: t, label: n == null ? void 0 : n.label });
669
670
  case "gauge":
670
- return /* @__PURE__ */ a(et, { data: t, palette: u, label: r == null ? void 0 : r.label });
671
+ return /* @__PURE__ */ r(st, { data: t, palette: h, label: n == null ? void 0 : n.label });
671
672
  case "chart":
672
- return /* @__PURE__ */ a(lt, { data: t, palette: u, label: r == null ? void 0 : r.label });
673
+ return /* @__PURE__ */ r(ut, { data: t, palette: h, label: n == null ? void 0 : n.label });
673
674
  case "composition":
674
- return /* @__PURE__ */ a(ot, { data: t, palette: u, label: r == null ? void 0 : r.label });
675
+ return /* @__PURE__ */ r(ft, { data: t, palette: h, label: n == null ? void 0 : n.label });
675
676
  case "table":
676
- return /* @__PURE__ */ a(ht, { data: t, label: r == null ? void 0 : r.label });
677
+ return /* @__PURE__ */ r(bt, { data: t, label: n == null ? void 0 : n.label });
677
678
  case "filter":
678
- return r && s ? /* @__PURE__ */ a(
679
- gt,
679
+ return n && i ? /* @__PURE__ */ r(
680
+ vt,
680
681
  {
681
- config: r,
682
+ config: n,
682
683
  value: l || "",
683
- options: i,
684
- dateBounds: c,
685
- onChange: s
684
+ options: s,
685
+ dateBounds: o,
686
+ onChange: i
686
687
  }
687
688
  ) : null;
688
689
  case "variable": {
689
- const d = r;
690
- return d && o ? /* @__PURE__ */ a(
691
- wt,
690
+ const u = n;
691
+ return u && d ? /* @__PURE__ */ r(
692
+ Rt,
692
693
  {
693
- config: d,
694
- value: h ?? d.variableValue ?? 0,
695
- onChange: o
694
+ config: u,
695
+ value: m ?? u.variableValue ?? 0,
696
+ onChange: d
696
697
  }
697
698
  ) : null;
698
699
  }
699
700
  case "color_palette":
700
- return r && f ? /* @__PURE__ */ a(
701
- yt,
701
+ return n && f ? /* @__PURE__ */ r(
702
+ $t,
702
703
  {
703
- config: r,
704
- palette: n,
704
+ config: n,
705
+ palette: a,
705
706
  onChange: f
706
707
  }
707
708
  ) : null;
708
709
  default:
709
- return /* @__PURE__ */ a(W, { name: "unknown", state: "unconfigured" });
710
+ return /* @__PURE__ */ r(L, { name: "unknown", state: "unconfigured" });
710
711
  }
711
712
  }
712
- const Nt = (e, t) => e.grid.y - t.grid.y || e.grid.x - t.grid.x;
713
- function Mt({
713
+ const At = (e, t) => e.grid.y - t.grid.y || e.grid.x - t.grid.x;
714
+ function Kt({
714
715
  token: e,
715
- cellAspect: t = Ae,
716
- stackBelow: n,
717
- onGeometryChange: r,
716
+ cellAspect: t = Le,
717
+ stackBelow: a,
718
+ onGeometryChange: n,
718
719
  silenceWarnings: l,
719
- className: i
720
+ className: s
720
721
  }) {
721
722
  const {
722
- layout: c,
723
- renderData: s,
724
- loading: h,
725
- error: o,
723
+ layout: o,
724
+ renderData: i,
725
+ loading: m,
726
+ error: d,
726
727
  filters: f,
727
- variables: u,
728
- palette: d,
728
+ variables: h,
729
+ palette: u,
729
730
  setFilter: g,
730
- setVariable: b,
731
- setPalette: k
732
- } = He(e), { rootRef: C, gridRef: M, stacked: S } = Xe({
733
- columns: (c == null ? void 0 : c.gridColumns) ?? 0,
731
+ setVariable: p,
732
+ setPalette: N
733
+ } = Xe(e), { rootRef: C, gridRef: y, stacked: w } = Je({
734
+ columns: (o == null ? void 0 : o.gridColumns) ?? 0,
734
735
  cellAspect: t,
735
- stackBelow: n,
736
- onGeometryChange: r,
736
+ stackBelow: a,
737
+ onGeometryChange: n,
737
738
  silenceWarnings: l
738
- }), T = ae(() => {
739
- const m = (c == null ? void 0 : c.widgets) ?? [];
740
- return S ? [...m].sort(Nt) : m;
741
- }, [c == null ? void 0 : c.widgets, S]), $ = {
742
- "--dash-gap": `${Z}px`,
739
+ }), $ = ce(() => {
740
+ const c = (o == null ? void 0 : o.widgets) ?? [];
741
+ return w ? [...c].sort(At) : c;
742
+ }, [o == null ? void 0 : o.widgets, w]), x = {
743
+ "--dash-gap": `${ee}px`,
743
744
  "--dash-pad": `${Me}px`
744
- }, y = ["preview-tab", i].filter(Boolean).join(" ");
745
- let w;
746
- if (o && !c)
747
- w = /* @__PURE__ */ a("div", { className: "preview-tab__error", children: o });
748
- else if (!c)
749
- w = /* @__PURE__ */ a("div", { className: "preview-tab__loading", children: "Carregando dashboard..." });
750
- else if (c.widgets.length === 0)
751
- w = /* @__PURE__ */ a("div", { className: "preview-tab__empty", children: "Este dashboard nao possui widgets." });
745
+ }, k = ["preview-tab", s].filter(Boolean).join(" ");
746
+ let S;
747
+ if (d && !o)
748
+ S = /* @__PURE__ */ r("div", { className: "preview-tab__error", children: d });
749
+ else if (!o)
750
+ S = /* @__PURE__ */ r("div", { className: "preview-tab__loading", children: "Carregando dashboard..." });
751
+ else if (o.widgets.length === 0)
752
+ S = /* @__PURE__ */ r("div", { className: "preview-tab__empty", children: "Este dashboard nao possui widgets." });
752
753
  else {
753
- const m = (s == null ? void 0 : s.widgets) ?? {}, _ = (s == null ? void 0 : s.date_bounds) ?? null, R = {
754
- "--dash-cols": c.gridColumns,
755
- "--dash-rows": c.gridRows,
756
- ...Ce(d)
757
- }, L = ["preview-tab__grid", S && "preview-tab__grid--stacked"].filter(Boolean).join(" ");
758
- w = /* @__PURE__ */ v(ge, { children: [
759
- o && !s && /* @__PURE__ */ a("div", { className: "preview-tab__error", children: o }),
760
- s && /* @__PURE__ */ a("div", { className: L, style: R, ref: M, children: T.map((p) => {
761
- const A = Re.has(p.type), F = m[p.id], O = S ? {
754
+ const c = (i == null ? void 0 : i.widgets) ?? {}, b = (i == null ? void 0 : i.date_bounds) ?? null, A = {
755
+ "--dash-cols": o.gridColumns,
756
+ "--dash-rows": o.gridRows,
757
+ ...ge(u)
758
+ }, O = ["preview-tab__grid", w && "preview-tab__grid--stacked"].filter(Boolean).join(" ");
759
+ S = /* @__PURE__ */ _(oe, { children: [
760
+ d && !i && /* @__PURE__ */ r("div", { className: "preview-tab__error", children: d }),
761
+ i && /* @__PURE__ */ r("div", { className: O, style: A, ref: y, children: $.map((v) => {
762
+ const F = Te.has(v.type), E = c[v.id], P = w ? {
762
763
  gridColumn: 1,
763
- aspectRatio: `${xe(p.grid.w, p.grid.h, t)}`,
764
- minHeight: `${$e(p.grid.h, Te, Z, 0)}px`
764
+ aspectRatio: `${Ee(v.grid.w, v.grid.h, t)}`,
765
+ minHeight: `${Fe(v.grid.h, Oe, ee, 0)}px`
765
766
  } : {
766
- gridColumn: `${p.grid.x + 1} / span ${p.grid.w}`,
767
- gridRow: `${p.grid.y + 1} / span ${p.grid.h}`
768
- }, I = p.type === "variable" ? u[p.id] ?? (F == null ? void 0 : F.value) ?? p.config.variableValue ?? 0 : void 0;
769
- return /* @__PURE__ */ a(
767
+ gridColumn: `${v.grid.x + 1} / span ${v.grid.w}`,
768
+ gridRow: `${v.grid.y + 1} / span ${v.grid.h}`
769
+ }, M = v.type === "variable" ? h[v.id] ?? (E == null ? void 0 : E.value) ?? v.config.variableValue ?? 0 : void 0;
770
+ return /* @__PURE__ */ r(
770
771
  "div",
771
772
  {
772
- className: `preview-tab__widget ${A ? "preview-tab__widget--control" : ""}`,
773
- style: O,
774
- children: A || F ? /* @__PURE__ */ a(
775
- St,
773
+ className: `preview-tab__widget ${F ? "preview-tab__widget--control" : ""}`,
774
+ style: P,
775
+ children: F || E ? /* @__PURE__ */ r(
776
+ It,
776
777
  {
777
- type: p.type,
778
- computed: F || {},
779
- palette: d,
780
- config: p.config,
781
- filterValue: f[p.id] || "",
778
+ type: v.type,
779
+ computed: E || {},
780
+ palette: u,
781
+ config: v.config,
782
+ filterValue: f[v.id] || "",
782
783
  filterOptions: (
783
784
  // Estruturais: vem do /layout (cacheavel), nao do /render —
784
785
  // recalcula-los a cada render custaria um DISTINCT por filtro.
785
- p.type === "filter" ? p.config.availableValues ?? [] : []
786
+ v.type === "filter" ? v.config.availableValues ?? [] : []
786
787
  ),
787
- dateBounds: _,
788
- onFilterChange: (D) => g(p.id, D),
789
- variableValue: I,
790
- onVariableChange: (D) => b(p.id, D),
791
- onPaletteChange: k
788
+ dateBounds: b,
789
+ onFilterChange: (H) => g(v.id, H),
790
+ variableValue: M,
791
+ onVariableChange: (H) => p(v.id, H),
792
+ onPaletteChange: N
792
793
  }
793
- ) : /* @__PURE__ */ a("div", { className: "preview-tab__widget-loading", children: h ? "Carregando..." : "Sem dados" })
794
+ ) : /* @__PURE__ */ r("div", { className: "preview-tab__widget-loading", children: m ? "Carregando..." : "Sem dados" })
794
795
  },
795
- p.id
796
+ v.id
796
797
  );
797
798
  }) }),
798
- h && s && /* @__PURE__ */ a("div", { className: "preview-tab__recalculating", children: "Atualizando..." })
799
+ m && i && /* @__PURE__ */ r("div", { className: "preview-tab__recalculating", children: "Atualizando..." })
800
+ ] });
801
+ }
802
+ return /* @__PURE__ */ r("div", { className: k, style: x, ref: C, children: S });
803
+ }
804
+ function Tt(e, t) {
805
+ const a = URL.createObjectURL(e), n = document.createElement("a");
806
+ n.href = a, n.download = t, document.body.appendChild(n), n.click(), n.remove(), setTimeout(() => URL.revokeObjectURL(a), 0);
807
+ }
808
+ const Ft = 768, Et = 879;
809
+ function Mt(e) {
810
+ return Array.from(e.normalize("NFD")).filter((t) => {
811
+ const a = t.codePointAt(0) ?? 0;
812
+ return a < Ft || a > Et;
813
+ }).join("");
814
+ }
815
+ function Lt(e, t) {
816
+ return `${Mt(e).replace(/[^a-zA-Z0-9]+/g, "-").replace(/^-+|-+$/g, "").toLowerCase() || "documento"}.${t}`;
817
+ }
818
+ const Ot = 300;
819
+ function Pt(e) {
820
+ const [t, a] = I(null), [n, l] = I(null), [s, o] = I({}), [i, m] = I(!0), [d, f] = I(null), [h, u] = I(!1), g = R(), p = R(!1);
821
+ W(() => {
822
+ let y = !1;
823
+ return Pe(e).then((w) => {
824
+ y || a(w);
825
+ }).catch((w) => {
826
+ y || f(w.message);
827
+ }), () => {
828
+ y = !0;
829
+ };
830
+ }, [e]), W(() => {
831
+ if (t)
832
+ return g.current && clearTimeout(g.current), g.current = setTimeout(() => {
833
+ m(!0), We(e, U(s)).then((y) => {
834
+ l(y), !p.current && y.applied && (p.current = !0, o((w) => ({ ...ve(y.applied), ...w }))), f(null);
835
+ }).catch((y) => f(y.message)).finally(() => m(!1));
836
+ }, Ot), () => {
837
+ g.current && clearTimeout(g.current);
838
+ };
839
+ }, [e, t, s]);
840
+ const N = T((y, w) => {
841
+ o(($) => ({ ...$, [y]: w }));
842
+ }, []), C = T(() => {
843
+ u(!0), De(e, U(s)).then((y) => {
844
+ Tt(y, Lt((t == null ? void 0 : t.name) ?? "demonstrativo", "pdf")), f(null);
845
+ }).catch((y) => f(y.message)).finally(() => u(!1));
846
+ }, [e, s, t == null ? void 0 : t.name]);
847
+ return {
848
+ layout: t,
849
+ renderData: n,
850
+ loading: i,
851
+ error: d,
852
+ filters: s,
853
+ setFilter: N,
854
+ downloadPdf: C,
855
+ downloading: h
856
+ };
857
+ }
858
+ const Wt = 8, Dt = 14;
859
+ function ie(e) {
860
+ return { paddingLeft: `${Wt + e * Dt}px` };
861
+ }
862
+ function ye({ label: e, value: t, bounds: a, onChange: n }) {
863
+ const [l, s] = t ? t.split("|") : ["", ""];
864
+ return /* @__PURE__ */ _("div", { className: "stmt__filter stmt__filter--range", children: [
865
+ /* @__PURE__ */ r("span", { className: "stmt__filter-label", children: e }),
866
+ /* @__PURE__ */ _("div", { className: "stmt__filter-range", children: [
867
+ /* @__PURE__ */ r(
868
+ D,
869
+ {
870
+ value: l,
871
+ minIso: a.min,
872
+ maxIso: s || a.max,
873
+ selectsStart: !0,
874
+ startIso: l,
875
+ endIso: s,
876
+ placeholder: "Início",
877
+ onChange: (o) => n(`${o}|${s}`)
878
+ }
879
+ ),
880
+ /* @__PURE__ */ r(
881
+ D,
882
+ {
883
+ value: s,
884
+ minIso: l || a.min,
885
+ maxIso: a.max,
886
+ selectsEnd: !0,
887
+ startIso: l,
888
+ endIso: s,
889
+ placeholder: "Fim",
890
+ onChange: (o) => n(`${l}|${o}`)
891
+ }
892
+ )
893
+ ] })
894
+ ] });
895
+ }
896
+ function Ht({ definition: e, value: t, options: a, bounds: n, onChange: l }) {
897
+ return e.type === "date_range" ? /* @__PURE__ */ r(
898
+ ye,
899
+ {
900
+ label: e.label,
901
+ value: t,
902
+ bounds: n,
903
+ onChange: l
904
+ }
905
+ ) : /* @__PURE__ */ _("div", { className: "stmt__filter", children: [
906
+ /* @__PURE__ */ r("span", { className: "stmt__filter-label", children: e.label }),
907
+ /* @__PURE__ */ r(
908
+ he,
909
+ {
910
+ value: t,
911
+ options: a,
912
+ multi: e.type === "multi_select",
913
+ onChange: l
914
+ }
915
+ )
916
+ ] });
917
+ }
918
+ function zt({ line: e, columnCount: t, showTotal: a, showVertical: n, showHorizontal: l }) {
919
+ if (e.type === "separator")
920
+ return /* @__PURE__ */ r("tr", { className: "stmt__row stmt__row--separator", children: /* @__PURE__ */ r("td", { colSpan: t }) });
921
+ if (e.type === "header")
922
+ return /* @__PURE__ */ _("tr", { className: "stmt__row stmt__row--header", children: [
923
+ /* @__PURE__ */ r("th", { scope: "row", style: ie(e.style.indent), children: e.label }),
924
+ /* @__PURE__ */ r("td", { colSpan: t - 1 })
925
+ ] });
926
+ const s = [
927
+ "stmt__row",
928
+ `stmt__row--${e.type}`,
929
+ e.style.bold && "stmt__row--bold"
930
+ ].filter(Boolean).join(" ");
931
+ return /* @__PURE__ */ _("tr", { className: s, children: [
932
+ /* @__PURE__ */ r("th", { scope: "row", style: ie(e.style.indent), children: e.label }),
933
+ e.formatted.map((o, i) => {
934
+ const m = e.horizontalAnalysis[i];
935
+ return /* @__PURE__ */ _("td", { className: "stmt__value", children: [
936
+ /* @__PURE__ */ r("span", { className: "stmt__number", children: o }),
937
+ n && e.verticalAnalysis[i] != null && /* @__PURE__ */ r("span", { className: "stmt__aux", title: "Análise vertical", children: j(e.verticalAnalysis[i], "percentage") }),
938
+ l && m != null && /* @__PURE__ */ r(
939
+ "span",
940
+ {
941
+ className: `stmt__aux stmt__aux--${m < 0 ? "down" : "up"}`,
942
+ title: "Variação sobre o período anterior",
943
+ children: j(m, "percentage")
944
+ }
945
+ )
946
+ ] }, i);
947
+ }),
948
+ a && /* @__PURE__ */ r("td", { className: "stmt__value stmt__value--total", children: /* @__PURE__ */ r("span", { className: "stmt__number", children: e.totalFormatted ?? "-" }) })
949
+ ] });
950
+ }
951
+ function Ut({ token: e, palette: t, showDownload: a = !0, className: n }) {
952
+ const {
953
+ layout: l,
954
+ renderData: s,
955
+ loading: o,
956
+ error: i,
957
+ filters: m,
958
+ setFilter: d,
959
+ downloadPdf: f,
960
+ downloading: h
961
+ } = Pt(e), u = ["stmt", n].filter(Boolean).join(" "), g = ge(t);
962
+ let p;
963
+ if (i && !l)
964
+ p = /* @__PURE__ */ r("div", { className: "stmt__error", children: i });
965
+ else if (!l)
966
+ p = /* @__PURE__ */ r("div", { className: "stmt__state", children: "Carregando demonstrativo..." });
967
+ else {
968
+ const N = (s == null ? void 0 : s.dateBounds) ?? l.dateBounds, C = l.periods.showTotal, y = l.filters.some((c) => c.type === "date_range"), w = (s == null ? void 0 : s.columns) ?? [], $ = (s == null ? void 0 : s.lines) ?? [], x = 1 + w.length + (C ? 1 : 0), k = $.some((c) => c.verticalAnalysis.length > 0), S = $.some((c) => c.horizontalAnalysis.length > 0);
969
+ p = /* @__PURE__ */ _(oe, { children: [
970
+ /* @__PURE__ */ _("div", { className: "stmt__toolbar", children: [
971
+ !y && /* @__PURE__ */ r(
972
+ ye,
973
+ {
974
+ label: "Período",
975
+ value: m[re] ?? "",
976
+ bounds: N,
977
+ onChange: (c) => d(re, c)
978
+ }
979
+ ),
980
+ l.filters.map((c) => /* @__PURE__ */ r(
981
+ Ht,
982
+ {
983
+ definition: c,
984
+ value: m[c.id] ?? "",
985
+ options: l.filterOptions[c.id] ?? [],
986
+ bounds: N,
987
+ onChange: (b) => d(c.id, b)
988
+ },
989
+ c.id
990
+ )),
991
+ /* @__PURE__ */ _("div", { className: "stmt__toolbar-end", children: [
992
+ /* @__PURE__ */ _("span", { className: "stmt__bounds", children: [
993
+ "Base: ",
994
+ N.min,
995
+ " a ",
996
+ N.max
997
+ ] }),
998
+ a && /* @__PURE__ */ r(
999
+ "button",
1000
+ {
1001
+ type: "button",
1002
+ className: "stmt__download",
1003
+ onClick: f,
1004
+ disabled: h || !s,
1005
+ title: "Baixar o documento em PDF",
1006
+ children: h ? "Gerando..." : "Baixar PDF"
1007
+ }
1008
+ )
1009
+ ] })
1010
+ ] }),
1011
+ i && /* @__PURE__ */ r("div", { className: "stmt__error", children: i }),
1012
+ s ? w.length === 0 ? /* @__PURE__ */ r("div", { className: "stmt__state", children: "Nenhum período na janela selecionada." }) : $.length === 0 ? /* @__PURE__ */ r("div", { className: "stmt__state", children: "Este demonstrativo não possui linhas." }) : /* @__PURE__ */ r("div", { className: "stmt__scroll", children: /* @__PURE__ */ _("table", { className: "stmt__table", children: [
1013
+ /* @__PURE__ */ r("thead", { children: /* @__PURE__ */ _("tr", { children: [
1014
+ /* @__PURE__ */ r("th", { className: "stmt__corner", scope: "col", children: s.name }),
1015
+ w.map((c) => /* @__PURE__ */ r("th", { scope: "col", title: `${c.start} a ${c.end}`, children: c.label }, c.key)),
1016
+ C && /* @__PURE__ */ r("th", { scope: "col", className: "stmt__total-head", children: l.periods.totalLabel })
1017
+ ] }) }),
1018
+ /* @__PURE__ */ r("tbody", { children: $.map((c) => /* @__PURE__ */ r(
1019
+ zt,
1020
+ {
1021
+ line: c,
1022
+ columnCount: x,
1023
+ showTotal: C,
1024
+ showVertical: k,
1025
+ showHorizontal: S
1026
+ },
1027
+ c.id
1028
+ )) })
1029
+ ] }) }) : /* @__PURE__ */ r("div", { className: "stmt__state", children: "Calculando..." }),
1030
+ o && s && /* @__PURE__ */ r("div", { className: "stmt__recalculating", children: "Atualizando..." })
799
1031
  ] });
800
1032
  }
801
- return /* @__PURE__ */ a("div", { className: y, style: $, ref: C, children: w });
1033
+ return /* @__PURE__ */ r("div", { className: u, style: g, children: p });
802
1034
  }
803
1035
  export {
804
- Et as ApiError,
805
- Mt as Dashboard
1036
+ qt as ApiError,
1037
+ Kt as Dashboard,
1038
+ Ut as Statement
806
1039
  };
807
1040
  //# sourceMappingURL=index.js.map