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