@nivaro/react 0.3.45 → 0.3.46

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.
Files changed (40) hide show
  1. package/dist/full.css +1 -1
  2. package/dist/hooks/useSessionRecorder.js +1 -1
  3. package/dist/index.d.ts +42 -7
  4. package/dist/shared/components/BaseMap.js +149 -103
  5. package/dist/shared/components/command-center/CommandCenterView.js +313 -69
  6. package/dist/shared/components/command-center/Customize.js +353 -0
  7. package/dist/shared/components/command-center/Header.js +279 -53
  8. package/dist/shared/components/command-center/KioskLinks.js +198 -0
  9. package/dist/shared/components/command-center/PeekPanel.js +143 -3
  10. package/dist/shared/components/command-center/announce.js +13 -0
  11. package/dist/shared/components/command-center/board-prefs.js +99 -0
  12. package/dist/shared/components/command-center/freshness.js +29 -0
  13. package/dist/shared/components/command-center/layout.js +56 -0
  14. package/dist/shared/components/command-center/panels/AttentionPanel.js +132 -3
  15. package/dist/shared/components/command-center/panels/Banner.js +75 -0
  16. package/dist/shared/components/command-center/panels/BoardSettings.js +223 -0
  17. package/dist/shared/components/command-center/panels/FeedPanel.js +145 -29
  18. package/dist/shared/components/command-center/panels/FlowPanel.js +154 -56
  19. package/dist/shared/components/command-center/panels/ForecastPanel.js +244 -3
  20. package/dist/shared/components/command-center/panels/MapLegend.js +266 -0
  21. package/dist/shared/components/command-center/panels/MapPanel.js +216 -66
  22. package/dist/shared/components/command-center/panels/PartnersPanel.js +49 -3
  23. package/dist/shared/components/command-center/panels/PeoplePanel.js +257 -40
  24. package/dist/shared/components/command-center/panels/RegionPicker.js +88 -3
  25. package/dist/shared/components/command-center/panels/SystemPanel.js +158 -38
  26. package/dist/shared/components/command-center/panels/ThroughputPanel.js +307 -3
  27. package/dist/shared/components/command-center/panels/TimeBar.js +227 -6
  28. package/dist/shared/components/command-center/panels/TrafficPanel.js +12 -8
  29. package/dist/shared/components/command-center/panels/WorkloadPanel.js +82 -3
  30. package/dist/shared/components/command-center/panels/attention-actions.js +267 -0
  31. package/dist/shared/components/command-center/panels/map-shared.js +95 -0
  32. package/dist/shared/components/command-center/panels/registry.js +87 -19
  33. package/dist/shared/components/command-center/shell-hooks.js +118 -0
  34. package/dist/shared/components/command-center/shortcuts.js +37 -0
  35. package/dist/shared/components/command-center/theme.js +39 -21
  36. package/dist/shared/components/command-center/time.js +52 -0
  37. package/dist/shared/components/command-center/url-state.js +54 -0
  38. package/dist/shared/components/command-center/work-links.js +32 -0
  39. package/dist/shared/components/monitoring/TrafficMiniMap.js +111 -70
  40. package/package.json +1 -1
@@ -1,74 +1,224 @@
1
- import { jsxs as f, jsx as o } from "react/jsx-runtime";
2
- import { useMemo as u } from "react";
3
- import { titleCase as y } from "../../../lib/utils.js";
4
- import { BaseMap as k } from "../../BaseMap.js";
5
- import { useCcQuery as b } from "../api.js";
6
- import { useCc as N } from "../state.js";
7
- import { PANEL as w, PANEL_HEAD as C, TITLE as L } from "../theme.js";
8
- function T() {
9
- var g;
10
- const s = N(), { snapshot: n, config: c, mapCollection: $ } = s, m = (c == null ? void 0 : c.geo_collections) ?? [], l = $ ?? ((g = m[0]) == null ? void 0 : g.key) ?? null, i = !!l, { data: a } = b(
11
- "/geo",
12
- { collection: l },
13
- { enabled: !!l, refetchInterval: 6e4 }
14
- ), { data: d = [] } = b("/people-geo", void 0, { staleTime: 10 * 6e4, lenses: !1 }), p = u(
15
- () => (i ? a ?? [] : []).map((e) => ({
16
- id: e.id,
17
- lat: e.lat,
18
- lng: e.lng,
19
- label: `${e.label}${e.state ? ` — ${e.state}` : ""}${e.sla === "breached" ? " · SLA breached" : e.sla === "warning" ? " · SLA warning" : ""}`,
20
- color: e.sla === "breached" ? "#ef4444" : e.sla === "warning" ? "#f59e0b" : e.state_color ?? "#00a5cc",
21
- pulse: e.sla === "breached"
22
- })),
23
- [a, i]
24
- ), r = u(() => {
25
- const e = ((n == null ? void 0 : n.people.offices) ?? []).map((t, v) => ({
26
- id: `office-${v}`,
27
- lat: t.lat,
28
- lng: t.lng,
29
- count: t.count,
30
- label: `${t.label}${t.names.length ? ` — ${t.names.slice(0, 5).join(", ")}${t.names.length > 5 ? ` +${t.names.length - 5}` : ""}` : ""}`,
31
- color: "#10b981"
32
- })), h = new Map(
33
- ((n == null ? void 0 : n.people.by_region) ?? []).map((t) => [String(t.region_id), t.count])
34
- ), x = d.filter((t) => (h.get(String(t.id)) ?? 0) > 0).map((t) => ({
35
- id: String(t.id),
36
- lat: t.lat,
37
- lng: t.lng,
38
- count: h.get(String(t.id)) ?? 0,
39
- label: t.label,
40
- color: "#10b981"
41
- }));
42
- return [...e, ...x];
43
- }, [d, n]);
44
- return /* @__PURE__ */ f("div", { className: `${w} flex min-h-[420px] flex-col overflow-hidden`, "data-cc-panel": "map", children: [
45
- /* @__PURE__ */ f("div", { className: C, children: [
46
- /* @__PURE__ */ o("h2", { className: L, children: "Live map" }),
47
- /* @__PURE__ */ o("div", { className: "flex items-center gap-2", children: m.map((e) => /* @__PURE__ */ o(
1
+ import { jsx as o, jsxs as p } from "react/jsx-runtime";
2
+ import { Settings2 as V, MapPinned as X, KeyRound as Z } from "lucide-react";
3
+ import { useState as N, useMemo as g } from "react";
4
+ import { titleCase as j, cn as h } from "../../../lib/utils.js";
5
+ import { BaseMap as ee } from "../../BaseMap.js";
6
+ import { useCcQuery as y } from "../api.js";
7
+ import { useCc as te } from "../state.js";
8
+ import { FOCUS as b, PANEL as E, PANEL_HEAD as R, TITLE as I, MUTED as ae, BUTTON as ne, FAINT as oe } from "../theme.js";
9
+ import { BoardSettings as F } from "./BoardSettings.js";
10
+ import { MapFilters as le, MapLegend as se } from "./MapLegend.js";
11
+ import { slaWords as ie, pinColor as W, MAP_COLORS as m, slaRank as D } from "./map-shared.js";
12
+ const re = [
13
+ { kind: "sla_heat", label: "SLA heat" },
14
+ { kind: "activity", label: "Recent changes" },
15
+ { kind: "out_today", label: "Out today" }
16
+ ];
17
+ function ce(l, c) {
18
+ const i = {};
19
+ return l && (i.collection = l), c.states.length && (i.states = c.states.join(",")), c.sla.length && (i.sla = c.sla.join(",")), c.owner && (i.owner = c.owner), i;
20
+ }
21
+ function we() {
22
+ var B, T;
23
+ const l = te(), { snapshot: c, config: i, mapCollection: K } = l, u = (i == null ? void 0 : i.geo_collections) ?? [], r = K ?? ((B = u[0]) == null ? void 0 : B.key) ?? null, _ = !l.kiosk && (l.isAdmin || !!(i != null && i.can_configure)), [v, Q] = N([]), [x, U] = N(!1), [$, k] = N(!1), n = y("/geo", ce(r, l.filters), {
24
+ enabled: !!r,
25
+ refetchInterval: 6e4
26
+ }).data, w = (e) => [
27
+ { kind: e, ...e !== "out_today" && r ? { collection: r } : {} },
28
+ {
29
+ enabled: v.includes(e) && (e === "out_today" || !!r),
30
+ refetchInterval: 6e4
31
+ }
32
+ ], C = y("/layers", ...w("sla_heat")), L = y("/layers", ...w("activity")), M = y("/layers", ...w("out_today")), z = g(() => new Map(((n == null ? void 0 : n.pins) ?? []).map((e) => [e.id, e])), [n]), A = g(
33
+ () => ((n == null ? void 0 : n.pins) ?? []).map((e) => {
34
+ const t = [e.state, ie(e.sla), e.owner ? `owner ${e.owner}` : null].filter(
35
+ Boolean
36
+ );
37
+ return {
38
+ id: e.id,
39
+ lat: e.lat,
40
+ lng: e.lng,
41
+ label: `${e.label}${t.length ? ` — ${t.join(" · ")}` : ""}`,
42
+ color: W(e),
43
+ pulse: e.sla === "breached"
44
+ };
45
+ }),
46
+ [n]
47
+ ), H = (e) => {
48
+ let t;
49
+ for (const a of e) {
50
+ const d = z.get(a.id);
51
+ d && (!t || D(d.sla) > D(t.sla)) && (t = d);
52
+ }
53
+ return t ? W(t) : e[0].color ?? m.ok;
54
+ }, O = g(() => {
55
+ const e = /* @__PURE__ */ new Map();
56
+ for (const t of (n == null ? void 0 : n.pins) ?? [])
57
+ t.state_key && !e.has(t.state_key) && e.set(t.state_key, {
58
+ key: t.state_key,
59
+ label: t.state ?? t.state_key,
60
+ color: t.state_color
61
+ });
62
+ return [...e.values()];
63
+ }, [n]), f = g(() => {
64
+ const e = [];
65
+ for (const [t, a] of ((c == null ? void 0 : c.people.regions) ?? []).entries())
66
+ a.lat == null || a.lng == null || a.count === 0 || e.push({
67
+ id: a.region_id != null ? `region:${a.region_id}` : `office:${t}`,
68
+ lat: a.lat,
69
+ lng: a.lng,
70
+ count: a.count,
71
+ label: `${a.label}${a.names.length ? ` — ${a.names.slice(0, 5).join(", ")}${a.names.length > 5 ? ` and ${a.names.length - 5} more` : ""}` : ""}`,
72
+ color: m.people
73
+ });
74
+ return e;
75
+ }, [c]), G = g(() => {
76
+ var t, a, d;
77
+ const e = [];
78
+ for (const s of ((t = C.data) == null ? void 0 : t.points) ?? [])
79
+ e.push({
80
+ id: `sla_heat:${s.id}`,
81
+ lat: s.lat,
82
+ lng: s.lng,
83
+ label: s.label,
84
+ weight: s.weight,
85
+ color: (s.weight ?? 0) >= 1 ? m.breached : m.warning
86
+ });
87
+ for (const s of ((a = L.data) == null ? void 0 : a.points) ?? [])
88
+ e.push({
89
+ id: `activity:${s.id}`,
90
+ lat: s.lat,
91
+ lng: s.lng,
92
+ label: s.label,
93
+ weight: s.weight,
94
+ color: m.activity
95
+ });
96
+ for (const s of ((d = M.data) == null ? void 0 : d.points) ?? [])
97
+ e.push({
98
+ id: `out_today:${s.id}`,
99
+ lat: s.lat,
100
+ lng: s.lng,
101
+ label: s.label,
102
+ weight: 0.5,
103
+ color: m.out
104
+ });
105
+ return e;
106
+ }, [C.data, L.data, M.data]), S = !!i, Y = S && u.length === 0, q = l.region && n && !n.region_applies ? " · region focus does not apply here" : "", J = ((T = u.find((e) => e.key === r)) == null ? void 0 : T.label) || j((r ?? "").replace(/_/g, " ")), P = _ && /* @__PURE__ */ o(
107
+ "button",
108
+ {
109
+ type: "button",
110
+ onClick: () => k(!0),
111
+ "aria-label": "Board settings",
112
+ "data-tip": "Board settings — map collections, regions, stuck days",
113
+ className: h("rounded-md p-1 text-[var(--cc-muted)] hover:bg-[var(--cc-chip)]", b),
114
+ children: /* @__PURE__ */ o(V, { className: "h-4 w-4" })
115
+ }
116
+ );
117
+ return Y ? /* @__PURE__ */ p("div", { className: `${E} flex flex-col overflow-hidden`, "data-cc-panel": "map", children: [
118
+ /* @__PURE__ */ p("div", { className: R, children: [
119
+ /* @__PURE__ */ o("h2", { className: I, children: "Live map" }),
120
+ P
121
+ ] }),
122
+ /* @__PURE__ */ p("div", { className: "flex flex-1 flex-col items-center justify-center gap-2 px-6 py-10 text-center", children: [
123
+ /* @__PURE__ */ o(X, { className: "h-7 w-7 text-[var(--cc-faint)]", "aria-hidden": "true" }),
124
+ /* @__PURE__ */ o("p", { className: "text-[13px] font-semibold text-[var(--cc-strong)]", children: "Nothing to put on the map yet" }),
125
+ /* @__PURE__ */ o("p", { className: `max-w-[440px] text-[12px] leading-relaxed ${ae}`, children: "The map shows records from any collection that has a latitude and a longitude field — sites, offices, stores. Add those two number fields to a collection and fill them in, and its records appear here with their step and SLA. The rest of the board works without a map." }),
126
+ _ ? /* @__PURE__ */ o(
48
127
  "button",
49
128
  {
50
129
  type: "button",
51
- "aria-pressed": l === e.key,
52
- onClick: () => s.setMapCollection(e.key),
53
- className: `rounded px-2 py-0.5 text-[11px] ${l === e.key ? "bg-nvr-cyan font-medium text-[#172940]" : "text-[var(--cc-muted)] hover:bg-[var(--cc-chip)]"}`,
54
- children: e.label || y(e.key.replace(/_/g, " "))
55
- },
56
- e.key
57
- )) })
130
+ onClick: () => l.navigate("/collections"),
131
+ className: h(ne, b, "mt-1"),
132
+ children: "Open the data model"
133
+ }
134
+ ) : /* @__PURE__ */ o("p", { className: `text-[11.5px] ${oe}`, children: "An administrator can add them." })
135
+ ] }),
136
+ $ && /* @__PURE__ */ o(F, { onClose: () => k(!1) })
137
+ ] }) : /* @__PURE__ */ p("div", { className: `${E} flex min-h-[420px] flex-col overflow-hidden`, "data-cc-panel": "map", children: [
138
+ /* @__PURE__ */ p("div", { className: h(R, "flex-wrap"), children: [
139
+ /* @__PURE__ */ o("h2", { className: I, children: "Live map" }),
140
+ /* @__PURE__ */ p("div", { className: "flex flex-wrap items-center gap-1.5", children: [
141
+ u.length > 1 && u.map((e) => /* @__PURE__ */ o(
142
+ "button",
143
+ {
144
+ type: "button",
145
+ "aria-pressed": r === e.key,
146
+ onClick: () => l.setMapCollection(e.key),
147
+ className: h(
148
+ "rounded px-2 py-0.5 text-[11px]",
149
+ b,
150
+ r === e.key ? "bg-nvr-cyan font-medium text-[#172940]" : "text-[var(--cc-muted)] hover:bg-[var(--cc-chip)]"
151
+ ),
152
+ children: e.label || j(e.key.replace(/_/g, " "))
153
+ },
154
+ e.key
155
+ )),
156
+ /* @__PURE__ */ o("span", { className: "mx-1 h-4 w-px bg-[var(--cc-border)]", "aria-hidden": "true" }),
157
+ re.filter((e) => !(l.kiosk && e.kind === "out_today")).map((e) => {
158
+ const t = v.includes(e.kind);
159
+ return /* @__PURE__ */ o(
160
+ "button",
161
+ {
162
+ type: "button",
163
+ "aria-pressed": t,
164
+ onClick: () => Q((a) => t ? a.filter((d) => d !== e.kind) : [...a, e.kind]),
165
+ className: h(
166
+ "rounded-full border px-2 py-0.5 text-[11px]",
167
+ b,
168
+ t ? "border-nvr-cyan bg-nvr-cyan/15 font-medium text-[var(--cc-strong)]" : "border-[var(--cc-border)] text-[var(--cc-muted)] hover:bg-[var(--cc-chip)]"
169
+ ),
170
+ children: e.label
171
+ },
172
+ e.kind
173
+ );
174
+ }),
175
+ /* @__PURE__ */ o(
176
+ "button",
177
+ {
178
+ type: "button",
179
+ "aria-pressed": x,
180
+ "aria-label": "Map key",
181
+ "data-tip": "What the colours mean",
182
+ onClick: () => U((e) => !e),
183
+ className: h(
184
+ "rounded-md p-1 text-[var(--cc-muted)] hover:bg-[var(--cc-chip)]",
185
+ b,
186
+ x && "bg-[var(--cc-chip)]"
187
+ ),
188
+ children: /* @__PURE__ */ o(Z, { className: "h-4 w-4" })
189
+ }
190
+ ),
191
+ P
192
+ ] })
193
+ ] }),
194
+ /* @__PURE__ */ o(le, { states: O, pins: (n == null ? void 0 : n.pins) ?? [] }),
195
+ /* @__PURE__ */ p("div", { className: "relative min-h-0 flex-1", children: [
196
+ /* @__PURE__ */ o(
197
+ ee,
198
+ {
199
+ pins: A,
200
+ bubbles: f,
201
+ dots: G,
202
+ focus: l.mapFocus,
203
+ clusterColor: H,
204
+ onPinClick: (e) => r && l.setPeek({ collection: r, id: e }),
205
+ onDotClick: (e) => {
206
+ const [t, a] = [e.slice(0, e.indexOf(":")), e.slice(e.indexOf(":") + 1)];
207
+ t !== "out_today" && r && l.setPeek({ collection: r, id: a });
208
+ },
209
+ onBubbleClick: (e) => {
210
+ const t = f.find((a) => a.id === e);
211
+ e.startsWith("region:") && !l.kiosk && l.setRegion(e.slice(7)), t && l.focusMap({ lat: t.lat, lng: t.lng, zoom: e.startsWith("region:") ? 8 : 12 });
212
+ },
213
+ statusLine: `${S ? `${A.length} ${J.toLowerCase()}${n != null && n.truncated ? " (the first ones only)" : ""}` : "Loading…"}${f.length > 0 ? ` · ${f.length} groups with people on` : ""}${q}${n != null && n.live_only ? " · live (the map does not rewind)" : ""} · © OpenStreetMap`,
214
+ minHeight: 380
215
+ }
216
+ ),
217
+ x && /* @__PURE__ */ o("div", { className: "absolute bottom-8 right-3 z-[4]", children: /* @__PURE__ */ o(se, { states: O, layers: v, showPeople: f.length > 0 }) })
58
218
  ] }),
59
- /* @__PURE__ */ o("div", { className: "min-h-0 flex-1", children: /* @__PURE__ */ o(
60
- k,
61
- {
62
- pins: p,
63
- bubbles: r,
64
- focus: s.mapFocus,
65
- onPinClick: (e) => l && s.setPeek({ collection: l, id: e }),
66
- statusLine: `${i ? `${p.length} ${(l ?? "").replace(/_/g, " ")}${a != null && a.truncated ? " (first 500)" : ""}` : "No map collection"}${r.length > 0 ? ` · ${r.length} groups with people on` : ""} · © OpenStreetMap`,
67
- minHeight: 380
68
- }
69
- ) })
219
+ $ && /* @__PURE__ */ o(F, { onClose: () => k(!1) })
70
220
  ] });
71
221
  }
72
222
  export {
73
- T as MapPanel
223
+ we as MapPanel
74
224
  };
@@ -1,6 +1,52 @@
1
- function n() {
2
- return null;
1
+ import { jsxs as n, jsx as t } from "react/jsx-runtime";
2
+ import { useCcQuery as i } from "../api.js";
3
+ import { useCc as h } from "../state.js";
4
+ import { PANEL as p, PANEL_HEAD as m, TITLE as x, FAINT as u, FOCUS as g } from "../theme.js";
5
+ import { LiveOnlyBadge as b } from "./TimeBar.js";
6
+ const f = {
7
+ ok: { glyph: "●", cls: "text-[var(--cc-good-text)]", word: "healthy" },
8
+ degraded: { glyph: "▲", cls: "text-[var(--cc-warn-text)]", word: "degraded" },
9
+ down: { glyph: "■", cls: "text-[var(--cc-bad-text)]", word: "failing" },
10
+ unknown: { glyph: "○", cls: "text-[var(--cc-faint)]", word: "no calls today" }
11
+ };
12
+ function $() {
13
+ var o;
14
+ const r = h(), s = r.isAdmin || !!((o = r.snapshot) != null && o.health), { data: l } = i("/partners", void 0, {
15
+ enabled: s,
16
+ refetchInterval: 6e4,
17
+ staleTime: 3e4
18
+ });
19
+ if (!s || !l || l.length === 0) return null;
20
+ const c = l.filter((e) => e.status === "down" || e.status === "degraded").length, d = (e) => r.navigate(e ?? "/integration-health?tab=partners");
21
+ return /* @__PURE__ */ n("section", { className: p, "data-cc-panel": "partners", "aria-label": "Partners", children: [
22
+ /* @__PURE__ */ n("div", { className: m, children: [
23
+ /* @__PURE__ */ t("h2", { className: x, children: "Partners" }),
24
+ /* @__PURE__ */ n("span", { className: "flex items-center gap-2", children: [
25
+ r.at != null && /* @__PURE__ */ t(b, {}),
26
+ /* @__PURE__ */ t("span", { className: `text-[11.5px] ${u}`, children: c === 0 ? "All healthy" : `${c} not healthy` })
27
+ ] })
28
+ ] }),
29
+ /* @__PURE__ */ t("ul", { className: "flex flex-wrap gap-1.5 p-2.5", children: l.map((e) => {
30
+ const a = f[e.status];
31
+ return /* @__PURE__ */ t("li", { children: /* @__PURE__ */ n(
32
+ "button",
33
+ {
34
+ type: "button",
35
+ onClick: () => d(e.href),
36
+ className: `flex items-center gap-1.5 rounded-full bg-[var(--cc-chip)] px-2 py-0.5 text-[11.5px] text-[var(--cc-text)] hover:bg-[var(--cc-chip-hover)] ${g}`,
37
+ "aria-label": `${e.label}: ${a.word}${e.open_problems ? `, ${e.open_problems} open problems` : ""}`,
38
+ "data-tip": e.last_ok_at ? `${a.word} · last worked ${new Date(e.last_ok_at).toLocaleString([], { month: "short", day: "numeric", hour: "numeric", minute: "2-digit" })}` : a.word,
39
+ children: [
40
+ /* @__PURE__ */ t("span", { "aria-hidden": !0, className: `text-[10px] ${a.cls}`, children: a.glyph }),
41
+ /* @__PURE__ */ t("span", { className: "max-w-[140px] truncate", children: e.label }),
42
+ e.open_problems > 0 && /* @__PURE__ */ t("span", { className: "rounded-full bg-red-500/15 px-1.5 text-[10.5px] font-semibold tabular-nums text-[var(--cc-bad-text)]", children: e.open_problems })
43
+ ]
44
+ }
45
+ ) }, e.key);
46
+ }) })
47
+ ] });
3
48
  }
4
49
  export {
5
- n as PartnersPanel
50
+ f as PARTNER_STATUS,
51
+ $ as PartnersPanel
6
52
  };
@@ -1,47 +1,264 @@
1
- import { jsxs as o, jsx as l } from "react/jsx-runtime";
2
- import { useCcQuery as d } from "../api.js";
3
- import { useCc as u } from "../state.js";
4
- import { PANEL as m, PANEL_HEAD as h, TITLE as x, FAINT as c } from "../theme.js";
5
- function v() {
6
- const r = u(), n = r.snapshot, { data: i = [] } = d("/people-geo", void 0, { staleTime: 10 * 6e4, lenses: !1 }), p = (n == null ? void 0 : n.people.regions) ?? [];
7
- return /* @__PURE__ */ o("section", { className: m, "data-cc-panel": "people", children: [
8
- /* @__PURE__ */ o("div", { className: h, children: [
9
- /* @__PURE__ */ l("h2", { className: x, children: "People on now" }),
10
- /* @__PURE__ */ l("span", { className: `text-[11px] tabular-nums ${c}`, children: (n == null ? void 0 : n.people.online_count) ?? 0 })
1
+ import { jsxs as l, jsx as n, Fragment as y } from "react/jsx-runtime";
2
+ import { useMutation as C } from "@tanstack/react-query";
3
+ import { ChevronRight as k, LocateFixed as S, MessageSquare as M, Footprints as P } from "lucide-react";
4
+ import { useState as v } from "react";
5
+ import { toast as $ } from "sonner";
6
+ import { useNivaroClient as A } from "../../../context.js";
7
+ import { post as T } from "../../../lib/commands.js";
8
+ import { cn as i } from "../../../lib/utils.js";
9
+ import { UserChip as F } from "../../item-edit/UserChip.js";
10
+ import { useCc as N } from "../state.js";
11
+ import { PANEL as E, PANEL_HEAD as O, TITLE as I, FAINT as f, FOCUS as m, BUTTON as _, MUTED as L } from "../theme.js";
12
+ const z = 50;
13
+ function X() {
14
+ const e = N(), t = e.snapshot, o = (t == null ? void 0 : t.people.regions) ?? [], [s, b] = v(/* @__PURE__ */ new Set()), u = (a) => `${a.region_id ?? "x"}:${a.label}`, d = (a) => b((c) => {
15
+ const p = new Set(c);
16
+ return p.has(a) ? p.delete(a) : p.add(a), p;
17
+ }), h = e.region && (t == null ? void 0 : t.people.region_applies) === !1;
18
+ return /* @__PURE__ */ l("section", { className: E, "data-cc-panel": "people", "aria-labelledby": "cc-people-title", children: [
19
+ /* @__PURE__ */ l("div", { className: O, children: [
20
+ /* @__PURE__ */ n("h2", { id: "cc-people-title", className: I, children: "People on now" }),
21
+ /* @__PURE__ */ l("span", { className: `text-[11px] tabular-nums ${f}`, children: [
22
+ (t == null ? void 0 : t.people.online_count) ?? 0,
23
+ " online",
24
+ t && t.people.idle_count > 0 ? ` · ${t.people.idle_count} idle` : ""
25
+ ] })
11
26
  ] }),
12
- /* @__PURE__ */ o("div", { className: "space-y-2.5 p-3", children: [
13
- p.map((e) => {
14
- const s = e.region_id != null ? i.find((a) => String(a.id) === String(e.region_id)) : null, t = e.lat != null && e.lng != null ? { lat: e.lat, lng: e.lng, zoom: 12 } : s ? { lat: s.lat, lng: s.lng, zoom: 8 } : null;
15
- return /* @__PURE__ */ o("div", { children: [
16
- /* @__PURE__ */ o(
17
- "button",
18
- {
19
- type: "button",
20
- disabled: !t,
21
- onClick: () => t && r.focusMap(t),
22
- className: `flex w-full items-center gap-1.5 text-left ${t ? "group cursor-pointer" : "cursor-default"}`,
23
- "data-tip": t ? "Show this group on the map" : "No map placement for this group",
24
- children: [
25
- /* @__PURE__ */ l("span", { className: "h-2.5 w-2.5 rounded-full bg-[var(--cc-people)]" }),
26
- /* @__PURE__ */ l("span", { className: "text-[12px] font-semibold text-[var(--cc-people-text)] group-hover:underline", children: e.label }),
27
- /* @__PURE__ */ l("span", { className: `text-[11px] tabular-nums ${c}`, children: e.count })
28
- ]
29
- }
30
- ),
31
- /* @__PURE__ */ l("div", { className: "mt-1 flex flex-wrap gap-1.5 pl-4", children: e.names.map((a) => /* @__PURE__ */ l(
32
- "span",
33
- {
34
- className: "rounded-full bg-[var(--cc-chip)] px-2 py-0.5 text-[11.5px] text-[var(--cc-text)]",
35
- children: a
36
- },
37
- a
38
- )) })
39
- ] }, `${e.region_id ?? "x"}:${e.label}`);
27
+ /* @__PURE__ */ l("div", { className: "space-y-1 p-2", children: [
28
+ h && /* @__PURE__ */ n("p", { className: `px-1 pb-1 text-[11px] ${f}`, children: "People are not placed in regions here — showing everyone." }),
29
+ o.map((a) => {
30
+ const c = u(a);
31
+ return /* @__PURE__ */ n(U, { group: a, expanded: s.has(c), onToggle: () => d(c) }, c);
40
32
  }),
41
- p.length === 0 && /* @__PURE__ */ l("p", { className: `text-[12px] ${c}`, children: "Nobody online right now." })
33
+ t && o.length === 0 && /* @__PURE__ */ n("p", { className: `px-1 text-[12px] ${f}`, children: "Nobody online right now." }),
34
+ !t && /* @__PURE__ */ n("p", { className: `px-1 text-[12px] ${f}`, children: "Loading…" })
35
+ ] })
36
+ ] });
37
+ }
38
+ function U({
39
+ group: e,
40
+ expanded: t,
41
+ onToggle: o
42
+ }) {
43
+ var x, g;
44
+ const s = N(), [b, u] = v(!1), d = e.region_id != null ? (x = s.config) == null ? void 0 : x.regions.find((r) => String(r.id) === String(e.region_id)) : null, h = e.lat != null && e.lng != null ? { lat: e.lat, lng: e.lng, zoom: e.region_id != null ? 8 : 12 } : (d == null ? void 0 : d.lat) != null && d.lng != null ? { lat: d.lat, lng: d.lng, zoom: 8 } : null, a = e.people ?? e.names.map((r, w) => ({
45
+ user_id: `${w}`,
46
+ name: r,
47
+ idle: !1,
48
+ page_label: null,
49
+ record: null
50
+ })), c = s.isAdmin && !s.kiosk && !!((g = e.people) != null && g.length), p = `cc-people-${(e.region_id ?? e.label).toString().replace(/[^A-Za-z0-9_-]/g, "_")}`;
51
+ return /* @__PURE__ */ l("div", { className: "rounded-md", children: [
52
+ /* @__PURE__ */ l("div", { className: "flex items-center gap-1", children: [
53
+ /* @__PURE__ */ l(
54
+ "button",
55
+ {
56
+ type: "button",
57
+ "aria-expanded": t,
58
+ "aria-controls": p,
59
+ onClick: o,
60
+ className: i(
61
+ "flex min-w-0 flex-1 items-center gap-1.5 rounded-md px-1 py-1 text-left hover:bg-[var(--cc-chip)]",
62
+ m
63
+ ),
64
+ children: [
65
+ /* @__PURE__ */ n(
66
+ k,
67
+ {
68
+ className: i(
69
+ "h-3.5 w-3.5 shrink-0 text-[var(--cc-faint)] motion-safe:transition-transform",
70
+ t && "rotate-90"
71
+ ),
72
+ "aria-hidden": "true"
73
+ }
74
+ ),
75
+ /* @__PURE__ */ n(
76
+ "span",
77
+ {
78
+ className: "h-2.5 w-2.5 shrink-0 rounded-full bg-[var(--cc-people)]",
79
+ "aria-hidden": "true"
80
+ }
81
+ ),
82
+ /* @__PURE__ */ n("span", { className: "truncate text-[12px] font-semibold text-[var(--cc-people-text)]", children: e.label }),
83
+ /* @__PURE__ */ n("span", { className: `text-[11px] tabular-nums ${f}`, children: e.count })
84
+ ]
85
+ }
86
+ ),
87
+ h && /* @__PURE__ */ n(
88
+ "button",
89
+ {
90
+ type: "button",
91
+ onClick: () => s.focusMap(h),
92
+ "aria-label": `Show ${e.label} on the map`,
93
+ "data-tip": "Show on the map",
94
+ className: i(
95
+ "rounded p-1 text-[var(--cc-faint)] hover:bg-[var(--cc-chip)] hover:text-[var(--cc-text)]",
96
+ m
97
+ ),
98
+ children: /* @__PURE__ */ n(S, { className: "h-3.5 w-3.5" })
99
+ }
100
+ ),
101
+ c && /* @__PURE__ */ n(
102
+ "button",
103
+ {
104
+ type: "button",
105
+ onClick: () => u((r) => !r),
106
+ "aria-label": `Message the people in ${e.label}`,
107
+ "data-tip": "Message these people",
108
+ className: i(
109
+ "rounded p-1 text-[var(--cc-faint)] hover:bg-[var(--cc-chip)] hover:text-[var(--cc-text)]",
110
+ m
111
+ ),
112
+ children: /* @__PURE__ */ n(M, { className: "h-3.5 w-3.5" })
113
+ }
114
+ )
115
+ ] }),
116
+ b && c && /* @__PURE__ */ n(
117
+ R,
118
+ {
119
+ label: e.label,
120
+ ids: (e.people ?? []).map((r) => r.user_id).slice(0, z),
121
+ total: e.count,
122
+ onDone: () => u(!1)
123
+ }
124
+ ),
125
+ t && /* @__PURE__ */ l("ul", { id: p, className: "mb-1 ml-5 mt-0.5 space-y-0.5", children: [
126
+ a.map((r) => /* @__PURE__ */ n(j, { p: r, real: !!e.people }, r.user_id)),
127
+ e.count > a.length && /* @__PURE__ */ l("li", { className: `px-1 text-[11px] ${f}`, children: [
128
+ "and ",
129
+ e.count - a.length,
130
+ " more"
131
+ ] })
132
+ ] })
133
+ ] });
134
+ }
135
+ function j({ p: e, real: t }) {
136
+ const o = N(), s = /* @__PURE__ */ n(
137
+ "button",
138
+ {
139
+ type: "button",
140
+ className: i(
141
+ "truncate rounded text-left text-[12px] font-medium text-[var(--cc-text)] hover:underline",
142
+ m
143
+ ),
144
+ "aria-label": `${e.name} — open their card`,
145
+ children: e.name
146
+ }
147
+ );
148
+ return /* @__PURE__ */ l("li", { className: "flex items-start gap-1.5 rounded px-1 py-0.5", children: [
149
+ /* @__PURE__ */ n(
150
+ "span",
151
+ {
152
+ className: i(
153
+ "mt-[5px] h-2 w-2 shrink-0 rounded-full",
154
+ e.idle ? "bg-[var(--cc-faint)]" : "bg-[var(--cc-people)]"
155
+ ),
156
+ "aria-hidden": "true"
157
+ }
158
+ ),
159
+ /* @__PURE__ */ l("div", { className: "min-w-0 flex-1", children: [
160
+ /* @__PURE__ */ l("div", { className: "flex items-center gap-1.5", children: [
161
+ t && !o.kiosk ? /* @__PURE__ */ n(F, { userId: e.user_id, children: s }) : /* @__PURE__ */ n("span", { className: "truncate text-[12px] font-medium", children: e.name }),
162
+ /* @__PURE__ */ n("span", { className: `text-[10.5px] ${f}`, children: e.idle ? "idle" : "active" }),
163
+ t && o.isAdmin && !o.kiosk && /* @__PURE__ */ n(
164
+ "button",
165
+ {
166
+ type: "button",
167
+ onClick: () => o.navigate(`/traffic-map?follow=${encodeURIComponent(e.user_id)}`),
168
+ "aria-label": `Follow ${e.name} in the Traffic Map`,
169
+ "data-tip": "Follow in Traffic Map",
170
+ className: i(
171
+ "ml-auto rounded p-0.5 text-[var(--cc-faint)] hover:bg-[var(--cc-chip)] hover:text-[var(--cc-text)]",
172
+ m
173
+ ),
174
+ children: /* @__PURE__ */ n(P, { className: "h-3 w-3" })
175
+ }
176
+ )
177
+ ] }),
178
+ (e.record || e.page_label) && /* @__PURE__ */ n("p", { className: `truncate text-[11px] ${L}`, children: e.record ? /* @__PURE__ */ l(
179
+ "button",
180
+ {
181
+ type: "button",
182
+ onClick: () => e.record && o.setPeek({ collection: e.record.collection, id: e.record.id }),
183
+ className: i("truncate rounded text-left hover:underline", m),
184
+ "aria-label": `On ${e.record.label} — preview it`,
185
+ children: [
186
+ "On ",
187
+ e.record.label
188
+ ]
189
+ }
190
+ ) : /* @__PURE__ */ l(y, { children: [
191
+ "On ",
192
+ e.page_label
193
+ ] }) })
194
+ ] })
195
+ ] });
196
+ }
197
+ function R({
198
+ label: e,
199
+ ids: t,
200
+ total: o,
201
+ onDone: s
202
+ }) {
203
+ const b = A(), [u, d] = v(""), [h, a] = v(!1), c = C({
204
+ mutationFn: () => b.request(
205
+ T("/command-center/people/message", { user_ids: t, message: u.trim() })
206
+ ),
207
+ onSuccess: (x) => {
208
+ var r;
209
+ const g = ((r = x.data) == null ? void 0 : r.sent) ?? t.length;
210
+ $.success(`Sent to ${g} ${g === 1 ? "person" : "people"}`), s();
211
+ },
212
+ onError: (x) => {
213
+ a(!1), $.error(x.message || "Message not sent");
214
+ }
215
+ }), p = `cc-msg-${e.replace(/[^A-Za-z0-9_-]/g, "_")}`;
216
+ return /* @__PURE__ */ l("div", { className: "mb-1.5 ml-5 mt-1 space-y-1.5 rounded-md border border-[var(--cc-border)] p-2", children: [
217
+ /* @__PURE__ */ l("label", { htmlFor: p, className: `block text-[11px] ${f}`, children: [
218
+ "One in-app message to each of ",
219
+ t.length,
220
+ " ",
221
+ t.length === 1 ? "person" : "people",
222
+ " in",
223
+ " ",
224
+ e,
225
+ o > t.length ? ` (the first ${t.length} of ${o})` : ""
226
+ ] }),
227
+ /* @__PURE__ */ n(
228
+ "textarea",
229
+ {
230
+ id: p,
231
+ value: u,
232
+ maxLength: 1e3,
233
+ rows: 3,
234
+ onChange: (x) => {
235
+ d(x.target.value), a(!1);
236
+ },
237
+ className: i(
238
+ "w-full resize-y rounded-md border border-[var(--cc-border)] bg-[var(--cc-panel)] px-2 py-1 text-[12px] text-[var(--cc-text)]",
239
+ m
240
+ )
241
+ }
242
+ ),
243
+ /* @__PURE__ */ l("div", { className: "flex items-center justify-end gap-1.5", children: [
244
+ /* @__PURE__ */ n("button", { type: "button", onClick: s, className: i(_, m), children: "Cancel" }),
245
+ /* @__PURE__ */ n(
246
+ "button",
247
+ {
248
+ type: "button",
249
+ disabled: !u.trim() || c.isPending,
250
+ onClick: () => h ? c.mutate() : a(!0),
251
+ className: i(
252
+ _,
253
+ m,
254
+ h && "border-nvr-cyan bg-nvr-cyan text-white hover:bg-nvr-cyan"
255
+ ),
256
+ children: c.isPending ? "Sending…" : h ? `Confirm — send to ${t.length}` : "Send"
257
+ }
258
+ )
42
259
  ] })
43
260
  ] });
44
261
  }
45
262
  export {
46
- v as PeoplePanel
263
+ X as PeoplePanel
47
264
  };