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