@actionexec/dashboards 0.15.0 → 0.16.1

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