@camstack/ui-library 1.2.190 → 1.2.191

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.cjs CHANGED
@@ -1191,6 +1191,30 @@ var CircleX = createLucideIcon("circle-x", [
1191
1191
  * This source code is licensed under the ISC license.
1192
1192
  * See the LICENSE file in the root directory of this source tree.
1193
1193
  */
1194
+ var Clapperboard = createLucideIcon("clapperboard", [
1195
+ ["path", {
1196
+ d: "m12.296 3.464 3.02 3.956",
1197
+ key: "qash78"
1198
+ }],
1199
+ ["path", {
1200
+ d: "M20.2 6 3 11l-.9-2.4c-.3-1.1.3-2.2 1.3-2.5l13.5-4c1.1-.3 2.2.3 2.5 1.3z",
1201
+ key: "1h7j8b"
1202
+ }],
1203
+ ["path", {
1204
+ d: "M3 11h18v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z",
1205
+ key: "4lm6w1"
1206
+ }],
1207
+ ["path", {
1208
+ d: "m6.18 5.276 3.1 3.899",
1209
+ key: "zjj9t3"
1210
+ }]
1211
+ ]);
1212
+ /**
1213
+ * @license lucide-react v0.576.0 - ISC
1214
+ *
1215
+ * This source code is licensed under the ISC license.
1216
+ * See the LICENSE file in the root directory of this source tree.
1217
+ */
1194
1218
  var Clock = createLucideIcon("clock", [["circle", {
1195
1219
  cx: "12",
1196
1220
  cy: "12",
@@ -17605,360 +17629,1114 @@ function useCapabilityPresence(capabilityName) {
17605
17629
  return classifyCapability(query.data);
17606
17630
  }
17607
17631
  //#endregion
17608
- //#region src/contexts/vod-playback.tsx
17632
+ //#region ../../node_modules/class-variance-authority/dist/index.mjs
17609
17633
  /**
17610
- * VodPlayback — shared context coordinating recorded (VOD) playback between a
17611
- * widget/section (the Recording panel) and the hero StreamPanel.
17634
+ * Copyright 2022 Joe Bell. All rights reserved.
17612
17635
  *
17613
- * A CONTROLLER (the Recording widget) calls `play({ url, label })`; the hero
17614
- * StreamPanel CONSUMES `request` and switches into VOD mode (HLS playback
17615
- * through the hub data-plane) instead of the live WebRTC stream. `clear()`
17616
- * returns the hero to live.
17636
+ * This file is licensed to you under the Apache License, Version 2.0
17637
+ * (the "License"); you may not use this file except in compliance with the
17638
+ * License. You may obtain a copy of the License at
17617
17639
  *
17618
- * Built on `createSharedContext` (NOT a plain `createContext`) so it crosses
17619
- * the Module-Federation boundary: an addon-shipped widget consuming
17620
- * `useVodPlayback()` resolves the SAME provider instance the host mounted —
17621
- * the same mechanism `player-overlays` / `zone-editing` use to let federated
17622
- * widgets (zone-editor, privacy-mask) drive the live player. Consumers used
17623
- * outside a provider get the inert default (no-op), so a StreamPanel mounted
17624
- * on a page without the Recording widget stays live-only without crashing.
17625
- */
17626
- var VodPlaybackContext = createSharedContext("camstack:vod-playback", {
17627
- request: null,
17628
- play: () => {},
17629
- clear: () => {}
17640
+ * http://www.apache.org/licenses/LICENSE-2.0
17641
+ *
17642
+ * Unless required by applicable law or agreed to in writing, software
17643
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17644
+ * WARRANTIES OR REPRESENTATIONS OF ANY KIND, either express or implied. See the
17645
+ * License for the specific language governing permissions and limitations under
17646
+ * the License.
17647
+ */ var falsyToString = (value) => typeof value === "boolean" ? `${value}` : value === 0 ? "0" : value;
17648
+ var cx = clsx;
17649
+ var cva = (base, config) => (props) => {
17650
+ var _config_compoundVariants;
17651
+ if ((config === null || config === void 0 ? void 0 : config.variants) == null) return cx(base, props === null || props === void 0 ? void 0 : props.class, props === null || props === void 0 ? void 0 : props.className);
17652
+ const { variants, defaultVariants } = config;
17653
+ const getVariantClassNames = Object.keys(variants).map((variant) => {
17654
+ const variantProp = props === null || props === void 0 ? void 0 : props[variant];
17655
+ const defaultVariantProp = defaultVariants === null || defaultVariants === void 0 ? void 0 : defaultVariants[variant];
17656
+ if (variantProp === null) return null;
17657
+ const variantKey = falsyToString(variantProp) || falsyToString(defaultVariantProp);
17658
+ return variants[variant][variantKey];
17659
+ });
17660
+ const propsWithoutUndefined = props && Object.entries(props).reduce((acc, param) => {
17661
+ let [key, value] = param;
17662
+ if (value === void 0) return acc;
17663
+ acc[key] = value;
17664
+ return acc;
17665
+ }, {});
17666
+ return cx(base, getVariantClassNames, config === null || config === void 0 ? void 0 : (_config_compoundVariants = config.compoundVariants) === null || _config_compoundVariants === void 0 ? void 0 : _config_compoundVariants.reduce((acc, param) => {
17667
+ let { class: cvClass, className: cvClassName, ...compoundVariantOptions } = param;
17668
+ return Object.entries(compoundVariantOptions).every((param) => {
17669
+ let [key, value] = param;
17670
+ return Array.isArray(value) ? value.includes({
17671
+ ...defaultVariants,
17672
+ ...propsWithoutUndefined
17673
+ }[key]) : {
17674
+ ...defaultVariants,
17675
+ ...propsWithoutUndefined
17676
+ }[key] === value;
17677
+ }) ? [
17678
+ ...acc,
17679
+ cvClass,
17680
+ cvClassName
17681
+ ] : acc;
17682
+ }, []), props === null || props === void 0 ? void 0 : props.class, props === null || props === void 0 ? void 0 : props.className);
17683
+ };
17684
+ //#endregion
17685
+ //#region src/primitives/badge.tsx
17686
+ var badgeVariants = cva("inline-flex items-center rounded-full text-xs font-medium px-2 py-0.5", {
17687
+ variants: {
17688
+ variant: {
17689
+ default: "bg-surface-hover text-foreground",
17690
+ success: "bg-success/15 text-success",
17691
+ warning: "bg-warning/15 text-warning",
17692
+ danger: "bg-danger/15 text-danger",
17693
+ info: "bg-info/15 text-info"
17694
+ },
17695
+ styleVariant: {
17696
+ solid: "",
17697
+ outline: "border bg-transparent"
17698
+ }
17699
+ },
17700
+ defaultVariants: {
17701
+ variant: "default",
17702
+ styleVariant: "solid"
17703
+ }
17630
17704
  });
17631
- function VodPlaybackProvider({ children }) {
17632
- const [request, setRequest] = (0, react$1.useState)(null);
17633
- const value = (0, react$1.useMemo)(() => ({
17634
- request,
17635
- play: (req) => setRequest(req),
17636
- clear: () => setRequest(null)
17637
- }), [request]);
17638
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(VodPlaybackContext.Provider, {
17639
- value,
17640
- children
17705
+ var Badge = (0, react$1.forwardRef)(({ className, variant, style, ...props }, ref) => {
17706
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
17707
+ ref,
17708
+ className: cn(badgeVariants({
17709
+ variant,
17710
+ styleVariant: style
17711
+ }), className),
17712
+ ...props
17641
17713
  });
17642
- }
17643
- /** @returns the VOD playback controller (inert no-op outside a provider). */
17644
- function useVodPlayback() {
17645
- return (0, react$1.useContext)(VodPlaybackContext);
17646
- }
17714
+ });
17715
+ Badge.displayName = "Badge";
17647
17716
  //#endregion
17648
- //#region src/composites/clips/ClipPanel.tsx
17717
+ //#region src/primitives/button.tsx
17718
+ var buttonVariants = cva("inline-flex items-center justify-center rounded-md font-medium transition-colors cursor-pointer disabled:opacity-50 disabled:pointer-events-none", {
17719
+ variants: {
17720
+ variant: {
17721
+ primary: "bg-primary text-primary-foreground hover:bg-primary/90",
17722
+ secondary: "bg-surface text-foreground hover:bg-surface-hover",
17723
+ ghost: "hover:bg-surface-hover text-foreground-muted",
17724
+ danger: "bg-danger text-white hover:bg-danger/90",
17725
+ outline: "border border-border bg-transparent text-foreground hover:bg-surface-hover"
17726
+ },
17727
+ size: {
17728
+ sm: "h-7 px-2.5 text-xs gap-1.5",
17729
+ md: "h-8 px-3 text-sm gap-2",
17730
+ lg: "h-9 px-4 text-sm gap-2"
17731
+ }
17732
+ },
17733
+ defaultVariants: {
17734
+ variant: "primary",
17735
+ size: "sm"
17736
+ }
17737
+ });
17738
+ var Button = (0, react$1.forwardRef)(({ className, variant, size, ...props }, ref) => {
17739
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
17740
+ ref,
17741
+ className: cn(buttonVariants({
17742
+ variant,
17743
+ size
17744
+ }), className),
17745
+ ...props
17746
+ });
17747
+ });
17748
+ Button.displayName = "Button";
17749
+ //#endregion
17750
+ //#region src/primitives/select.tsx
17649
17751
  /**
17650
- * The selected clip — what it is, how it plays, and how it is saved.
17651
- *
17652
- * **No second player.** `getClipPlayback` answers `{ playbackUrl, format,
17653
- * served }` and the panel hands it to the SAME hero the recordings timeline
17654
- * drives: `vod.play({ url, format })` → `StreamPanel playbackUrl/playbackFormat`
17655
- * → `HlsVideo`'s `mp4` branch (`video.src`, no hls.js). Building a clip player
17656
- * here is the thing D549 decision 22 exists to refuse.
17657
- *
17658
- * **`format` travels.** An MP4 handed to hls.js is parsed as a manifest and
17659
- * fails, so the format the provider named is forwarded verbatim and never
17660
- * defaulted here.
17752
+ * A native `<select>` styled to match the rest of the field set.
17661
17753
  *
17662
- * **`served` is shown.** A clip that holds only one twin answers with the one
17663
- * it has, and the surface SAYS so — a missing main twin must never be served
17664
- * silently as if it were the asked-for quality (D549 decision 15). Both ids
17665
- * are already on the row, so changing quality re-asks the hub and never
17666
- * re-searches the camera.
17754
+ * `appearance-none` plus an explicit `bg-surface` / `text-foreground` is what
17755
+ * makes it match — and it is also what USED to make a disabled one a lie. A
17756
+ * browser greys a disabled control by rendering its own background and text
17757
+ * colour; all three of those are overridden here, so a `disabled` dropdown
17758
+ * looked exactly like a live one and simply ignored the click. That is the
17759
+ * whole of the "the language selector does not open" report of 2026-08-15:
17760
+ * the AI section's switch was off, every control under it was correctly inert,
17761
+ * and nothing on screen said so.
17667
17762
  *
17668
- * **Nothing is appended to the URL.** The route is `access:'authenticated'`
17669
- * and the session cookie authenticates it (D549 decision 22); the same URL is
17670
- * the download.
17763
+ * `disabled:` classes belong HERE and not on each call site: there are dozens
17764
+ * of `<Select disabled>` in this app and the one that gets forgotten is the one
17765
+ * that generates the ticket. Guarded by `disabled-affordance.test.tsx`.
17671
17766
  */
17672
- var PROFILES = [
17673
- "low",
17674
- "mid",
17675
- "high"
17676
- ];
17677
- function ClipPanel({ deviceId, clip, profile, onProfileChange }) {
17678
- const vod = useVodPlayback();
17679
- const playback = useVideoclipsGetClipPlayback({
17680
- deviceId,
17681
- clipId: clip.id,
17682
- profile
17683
- });
17684
- const data = playback.data;
17685
- const label = `${new Date(clip.timeRange.startMs).toLocaleString()} · ${clip.source}`;
17686
- (0, react$1.useEffect)(() => {
17687
- if (data === void 0) return;
17688
- vod.play({
17689
- url: hubPath(data.playbackUrl),
17690
- ...data.format === void 0 ? {} : { format: data.format },
17691
- label
17692
- });
17693
- }, [data, label]);
17767
+ var Select = (0, react$1.forwardRef)(({ className, options, disabled, ...props }, ref) => {
17694
17768
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
17695
- className: "space-y-2 rounded-md border border-border p-3 text-sm",
17696
- children: [
17697
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
17698
- className: "font-medium",
17699
- children: label
17700
- }),
17701
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
17702
- className: "flex items-center gap-2",
17703
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
17704
- className: "text-xs text-muted-foreground",
17705
- children: "Quality"
17706
- }), PROFILES.map((option) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
17707
- type: "button",
17708
- "aria-pressed": option === profile,
17709
- onClick: () => onProfileChange(option),
17710
- className: `rounded px-2 py-0.5 text-xs ${option === profile ? "bg-primary text-primary-foreground" : "bg-muted"}`,
17711
- children: option
17712
- }, option))]
17713
- }),
17714
- playback.status === "pending" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
17715
- role: "status",
17716
- children: "Preparing the clip — the file is fetched and muxed once…"
17717
- }) : playback.status === "error" ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
17718
- role: "alert",
17719
- children: ["This clip could not be prepared: ", playback.error?.message ?? "no reason given"]
17720
- }) : data === void 0 ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
17721
- className: "space-y-1",
17722
- children: [data.served === void 0 || data.served === profile ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
17723
- className: "text-xs text-amber-600 dark:text-amber-400",
17724
- children: [
17725
- "Served the ",
17726
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("strong", { children: data.served }),
17727
- " stream — this clip has no ",
17728
- profile,
17729
- " twin."
17730
- ]
17731
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("a", {
17732
- href: hubPath(data.playbackUrl),
17733
- download: true,
17734
- className: "text-xs underline",
17735
- children: "Download this clip"
17736
- })]
17737
- })
17738
- ]
17739
- });
17740
- }
17741
- //#endregion
17742
- //#region src/composites/clips/ClipSilentSources.tsx
17743
- function ClipSilentSources({ silent }) {
17744
- if (silent.length === 0) return null;
17745
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("ul", {
17746
- className: "space-y-1 rounded-md border border-amber-500/40 bg-amber-500/5 p-2 text-xs",
17747
- children: silent.map((notice) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("li", { children: [
17748
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
17749
- className: "font-medium",
17750
- children: notice.label
17751
- }),
17752
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
17753
- className: "text-muted-foreground",
17754
- children: [
17755
- " (",
17756
- notice.source,
17757
- ")"
17758
- ]
17759
- }),
17760
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { children: notice.headline }),
17761
- notice.detail === null ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
17762
- className: "text-muted-foreground break-words",
17763
- children: notice.detail
17764
- })
17765
- ] }, notice.source))
17769
+ className: "relative w-full",
17770
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("select", {
17771
+ ref,
17772
+ disabled,
17773
+ className: cn("h-7 w-full px-2.5 text-xs bg-surface border border-border rounded-md text-foreground appearance-none pr-7 focus:outline-none focus:ring-1 focus:ring-primary", "disabled:opacity-50 disabled:cursor-not-allowed", className),
17774
+ ...props,
17775
+ children: options.map((option) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
17776
+ value: option.value,
17777
+ children: option.label
17778
+ }, option.value))
17779
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
17780
+ className: cn("absolute right-2 top-1/2 -translate-y-1/2 pointer-events-none text-foreground-muted", disabled === true ? "opacity-50" : ""),
17781
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ChevronDown, { className: "h-3.5 w-3.5" })
17782
+ })]
17766
17783
  });
17767
- }
17784
+ });
17785
+ Select.displayName = "Select";
17768
17786
  //#endregion
17769
- //#region src/composites/clips/ClipSourceRow.tsx
17770
- var TONE_CLASS = {
17771
- ok: "text-emerald-600 dark:text-emerald-400",
17772
- warn: "text-amber-600 dark:text-amber-400",
17773
- error: "text-rose-600 dark:text-rose-400"
17774
- };
17775
- function ClipSourceRow({ notice, catalogAge, checked, onToggle }) {
17776
- return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("li", {
17777
- className: "flex items-start gap-2 py-1.5",
17778
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
17779
- type: "checkbox",
17780
- className: "mt-1",
17781
- checked,
17782
- "aria-label": `Show ${notice.label}`,
17783
- onChange: (e) => onToggle(notice.source, e.target.checked)
17784
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
17785
- className: "min-w-0",
17786
- children: [
17787
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
17788
- className: "flex flex-wrap items-baseline gap-x-2",
17789
- children: [
17790
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
17791
- className: "font-medium",
17792
- children: notice.label
17793
- }),
17794
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
17795
- className: "text-xs text-muted-foreground",
17796
- children: notice.source
17797
- }),
17798
- catalogAge === null ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
17799
- className: "text-xs text-muted-foreground",
17800
- children: ["read ", catalogAge]
17801
- })
17802
- ]
17803
- }),
17804
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
17805
- className: `text-xs ${TONE_CLASS[notice.tone]}`,
17806
- children: notice.headline
17807
- }),
17808
- notice.detail === null ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
17809
- className: "text-xs text-muted-foreground break-words",
17810
- children: notice.detail
17811
- })
17812
- ]
17813
- })]
17787
+ //#region src/primitives/skeleton.tsx
17788
+ var Skeleton = (0, react$1.forwardRef)(({ className, ...props }, ref) => {
17789
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
17790
+ ref,
17791
+ className: cn("animate-pulse bg-surface-hover rounded-md h-4 w-full", className),
17792
+ ...props
17814
17793
  });
17815
- }
17794
+ });
17795
+ Skeleton.displayName = "Skeleton";
17816
17796
  //#endregion
17817
- //#region src/composites/clips/clip-tile-media.ts
17797
+ //#region src/hooks/use-is-mobile.ts
17798
+ var MOBILE_QUERY = "(max-width: 767px)";
17818
17799
  /**
17819
- * Why no still exists, in words. Keyed by the provider's own vocabulary so a
17820
- * reason this table does not know still reaches the operator verbatim.
17800
+ * Mid breakpoint — below this width the sidebar collapses to an
17801
+ * icons-only rail to reclaim canvas space. Above it (and outside
17802
+ * mobile) the full sidebar renders. Threshold matches Tailwind `lg`
17803
+ * so sidebar fans out at the same point grids switch to multi-column.
17821
17804
  */
17822
- var REFUSAL_TEXT = {
17823
- sleeping: "The camera is asleep — a still would cost a wake",
17824
- "camera-refused": "The camera refused the still request",
17825
- "no-keyframe": "No decodable frame inside this window",
17826
- unsupported: "This source cannot produce stills",
17827
- "queue-full": "The camera is busy — its still queue is full",
17828
- "no-catalog-row": "This clip is no longer in the catalog"
17829
- };
17830
- function refusal(reason) {
17831
- return {
17832
- kind: "unavailable",
17833
- reason,
17834
- text: REFUSAL_TEXT[reason] ?? `Refused: ${reason}`
17835
- };
17805
+ var MID_QUERY = "(min-width: 768px) and (max-width: 1023px)";
17806
+ /**
17807
+ * `matchMedia` is universal in browsers but absent in bare DOM environments.
17808
+ * These hooks are called from shared primitives (`DataTable` picks its narrow
17809
+ * layout with one), so throwing here takes down the whole page that merely
17810
+ * rendered a table. Where the capability is missing, report the desktop
17811
+ * layout — a widescreen rendering is wrong-looking; a crashed page is gone.
17812
+ */
17813
+ function matchQuery(query) {
17814
+ if (typeof window.matchMedia !== "function") return null;
17815
+ return window.matchMedia(query);
17836
17816
  }
17837
- /** What to draw for one clip's tile. */
17838
- function resolveTileMedia(clip) {
17839
- if (clip.thumbnail !== void 0) return {
17840
- kind: "vouched",
17841
- url: clip.thumbnail
17842
- };
17843
- if (clip.thumbnailUnavailable !== void 0) return refusal(clip.thumbnailUnavailable.reason);
17844
- if (clip.thumbnailMint !== void 0) return {
17845
- kind: "mint",
17846
- url: clip.thumbnailMint
17847
- };
17848
- return {
17849
- kind: "none",
17850
- text: "This clip carries no still and offered none"
17817
+ function subscribeQuery(query) {
17818
+ return (callback) => {
17819
+ const mql = matchQuery(query);
17820
+ if (mql === null) return () => {};
17821
+ mql.addEventListener("change", callback);
17822
+ return () => mql.removeEventListener("change", callback);
17851
17823
  };
17852
17824
  }
17825
+ function getSnapshot(query) {
17826
+ return () => matchQuery(query)?.matches ?? false;
17827
+ }
17828
+ function getServerSnapshot() {
17829
+ return false;
17830
+ }
17831
+ function useIsMobile() {
17832
+ return (0, react$1.useSyncExternalStore)(subscribeQuery(MOBILE_QUERY), getSnapshot(MOBILE_QUERY), getServerSnapshot);
17833
+ }
17853
17834
  /**
17854
- * A mint that answered 204 — latch its `x-camstack-reason` to this instant.
17855
- *
17856
- * The refusal is about NOW (a full queue, a sleeping camera), so it replaces
17857
- * the offer for as long as the tile is mounted and is not retried behind the
17858
- * operator's back. An unknown reason is shown raw rather than dropped: a
17859
- * firmware inventing a refusal must not become a blank tile.
17835
+ * True when the viewport is in the medium (`md`) Tailwind range —
17836
+ * 768px ≤ width < 1024px. Use to drive layouts that should pack denser
17837
+ * than full-desktop but more legibly than mobile (e.g. icons-only
17838
+ * sidebar rail, narrower stat tiles).
17860
17839
  */
17861
- function latchMintRefusal(reason) {
17862
- return refusal(reason);
17840
+ function useIsMidWidth() {
17841
+ return (0, react$1.useSyncExternalStore)(subscribeQuery(MID_QUERY), getSnapshot(MID_QUERY), getServerSnapshot);
17863
17842
  }
17864
17843
  //#endregion
17865
- //#region src/composites/clips/clip-thumbnail-fetch.ts
17866
- /**
17867
- * Asking a `thumbnailMint` route for a still — and hearing its refusal.
17868
- *
17869
- * The route answers **200** with a JPEG or **204** with the reason in
17870
- * `x-camstack-reason` (`queue-full`, `sleeping`, `camera-refused`,
17871
- * `no-keyframe`, `no-catalog-row`). An `<img src>` cannot read that header:
17872
- * a 204 fires `onerror` with nothing to say, turning a named refusal into an
17873
- * anonymous broken tile. So a mint goes through `fetch`.
17874
- *
17875
- * **Nothing is appended to the URL.** Both data-plane routes are registered
17876
- * `access: 'authenticated'` and the hub's `/addon/<id>/<prefix>` proxy takes
17877
- * the session cookie the admin UI sets at login, so the URL is never a
17878
- * credential (D549 decision 22) — it may sit in history or a `Referer` and
17879
- * open nothing.
17880
- *
17881
- * The refusal is about NOW and is LATCHED by the caller: a camera that just
17882
- * said "busy" is not asked again behind the operator's back.
17883
- */
17844
+ //#region src/composites/data-table-layout.ts
17884
17845
  /**
17885
- * Ask a mint route for one still.
17886
- *
17887
- * Never rejects: a thrown fetch is a refusal like any other, because a tile
17888
- * that throws is a tile that renders nothing and says nothing — the exact
17889
- * failure this module exists to prevent.
17846
+ * At this many columns and above, `auto` switches a narrow viewport to cards.
17847
+ * Three columns still fit a phone at a readable size; four do not.
17890
17848
  */
17891
- async function fetchMintedThumbnail(url, fetcher) {
17892
- let response;
17893
- try {
17894
- response = await fetcher(url, { credentials: "same-origin" });
17895
- } catch (err) {
17896
- return latchMintRefusal(err instanceof Error ? err.message : String(err));
17897
- }
17898
- if (response.status === 204) return latchMintRefusal(response.headers.get("x-camstack-reason") ?? "no reason given");
17899
- if (!response.ok) return latchMintRefusal(`HTTP ${String(response.status)}`);
17900
- try {
17901
- return {
17902
- kind: "image",
17903
- blob: await response.blob()
17904
- };
17905
- } catch (err) {
17906
- return latchMintRefusal(err instanceof Error ? err.message : String(err));
17907
- }
17849
+ var CARD_MODE_MIN_COLUMNS = 4;
17850
+ function resolveTableLayout({ mode, columnCount, isNarrow }) {
17851
+ if (!isNarrow) return "table";
17852
+ if (mode === "scroll") return "table";
17853
+ if (mode === "cards") return "cards";
17854
+ if (columnCount === 0) return "table";
17855
+ return columnCount >= 4 ? "cards" : "table";
17908
17856
  }
17909
17857
  //#endregion
17910
- //#region src/composites/clips/ClipTile.tsx
17858
+ //#region src/lib/responsive.ts
17911
17859
  /**
17912
- * One clip, as a tile.
17860
+ * Responsive design tokens — three-tier system.
17913
17861
  *
17914
- * The picture is resolved by `resolveTileMedia` — vouched JPEG, an offer, or
17915
- * the reason there is none (D549 decision 5). An offer is fetched rather than
17916
- * dropped into an `<img src>`, because the route's **204 + x-camstack-reason**
17917
- * is invisible to an `<img>`: it fires `onerror` with nothing to say. The
17918
- * refusal is LATCHED for the life of the tile and never retried behind the
17919
- * operator's back.
17862
+ * The admin-ui targets three width tiers; every component should pick
17863
+ * the right token from this file instead of hand-coding breakpoints.
17864
+ * Adopting the tokens uniformly is what makes the app feel consistent
17865
+ * across operator devices (mobile / tablet / desktop) and what unlocks
17866
+ * targeted tuning (e.g. shrink every label by 1px in one place).
17920
17867
  *
17921
- * The row also carries what the camera itself said: its native types, the
17922
- * behaviours beside the class, which storages hold it, and — for a row that
17923
- * is an EVENT sitting inside no file — `playable: false` with its reason
17924
- * (measured: 1 of 29 hub events on 3628). Such a row is SHOWN, never dropped
17925
- * and never offered as playable-then-failing (D549 decision 19).
17926
- */
17927
- function clockOf(ms) {
17928
- return new Date(ms).toLocaleTimeString(void 0, {
17929
- hour: "2-digit",
17930
- minute: "2-digit",
17931
- second: "2-digit"
17932
- });
17933
- }
17934
- /**
17935
- * Ask a mint route once, and LATCH whatever it says.
17868
+ * Tier definitions (Tailwind breakpoints):
17936
17869
  *
17937
- * The offer is memoised on the three fields it is derived from, not rebuilt
17938
- * per render: `resolveTileMedia` returns a fresh object every call, and an
17939
- * effect keyed on that object re-runs on every commit — which, because the
17940
- * effect sets state, is an infinite render loop. It was one here, and it hung
17941
- * the suite rather than failing it.
17870
+ * • **L1 — Compact** (`< 640px`, default = mobile portrait)
17871
+ * Single column, tight padding, smallest text, icon-only buttons
17872
+ * where labels can be inferred. The operator can still see every
17873
+ * stat / action — no horizontal scroll, no clipped text. The user
17874
+ * directive: "molta informazione in poco spazio quando la width è
17875
+ * bassa."
17942
17876
  *
17943
- * The refusal is latched for the life of the tile: a camera that just said
17944
- * "busy" is not asked again behind the operator's back (D549 decision 5).
17877
+ * • **L2 — Standard** (`sm` — `640–1023px`, tablet + small laptop)
17878
+ * 2-column grids, side panels become visible, button labels return.
17879
+ * Targets ~768px–1024px viewports — the most common operator sizes.
17880
+ *
17881
+ * • **L3 — Spacious** (`lg+` — `≥ 1024px`, desktop)
17882
+ * 4-column grids, generous padding, full-width header text,
17883
+ * side-by-side composite layouts. The operator has elbow room.
17884
+ *
17885
+ * Conventions:
17886
+ * - **Always start from L1** — the bare class is always the compact
17887
+ * variant, then `sm:` adds room at 640px, `lg:` at 1024px. No
17888
+ * desktop-first breakpoints; no max-width queries.
17889
+ * - **Token strings are static** — kept as `as const` so callers can
17890
+ * compose them via `cn()` / template literals without running a
17891
+ * class generator at runtime.
17892
+ * - **Pair the token with a comment** — the comment in the file
17893
+ * names every breakpoint it crosses, so a reader can predict the
17894
+ * layout without going to Tailwind docs.
17945
17895
  */
17946
- function useMintedStill(clip) {
17947
- const offered = (0, react$1.useMemo)(() => resolveTileMedia(clip), [
17948
- clip.thumbnail,
17949
- clip.thumbnailMint,
17950
- clip.thumbnailUnavailable?.reason
17951
- ]);
17952
- const [latched, setLatched] = (0, react$1.useState)(null);
17953
- const mintUrl = offered.kind === "mint" ? offered.url : null;
17954
- (0, react$1.useEffect)(() => {
17955
- setLatched(null);
17956
- if (mintUrl === null || typeof fetch !== "function") return void 0;
17957
- let objectUrl = null;
17958
- let cancelled = false;
17959
- (async () => {
17960
- const answer = await fetchMintedThumbnail(hubPath(mintUrl), fetch);
17961
- if (cancelled) return;
17896
+ /** Container padding for a card-style section (header + body). */
17897
+ var SECTION_CARD = "rounded-lg border border-border bg-surface overflow-hidden";
17898
+ /** Header strip inside a card (between border-b lines). */
17899
+ var SECTION_HEADER = "border-b border-border px-3 sm:px-4 py-1.5 sm:py-2";
17900
+ /** Body padding for a card-style section. */
17901
+ var SECTION_BODY = "p-2 sm:p-3 lg:p-4";
17902
+ /** Gap between cards in a vertical stack. */
17903
+ var STACK_GAP = "space-y-3 sm:space-y-4";
17904
+ /** Gap between cards in a grid (4 cells / row at lg). */
17905
+ var GRID_GAP = "gap-2 sm:gap-3";
17906
+ /** Row padding inside a divided list (e.g. InfoRow). */
17907
+ var LIST_ROW = "px-3 sm:px-4 py-1.5 sm:py-2";
17908
+ /** 1-up at L1, 2-up at L2, 4-up at L3 — quick-stat row. */
17909
+ var GRID_QUICK_STATS = "grid grid-cols-2 sm:grid-cols-2 lg:grid-cols-4";
17910
+ /** 1-up at L1, 2-up at L2+ — paired panels (motion + detection rules). */
17911
+ var GRID_PAIRED = "grid grid-cols-1 lg:grid-cols-2";
17912
+ /** Side-by-side layout that stacks below md (canvas + side panel). */
17913
+ var SPLIT_PANEL_OUTER = "flex flex-col-reverse md:flex-row";
17914
+ /** Sidebar narrow lane in a SPLIT_PANEL_OUTER layout. */
17915
+ var SPLIT_PANEL_SIDE = "w-full md:w-44 lg:w-52 md:flex-shrink-0 border-b md:border-b-0 md:border-l border-border";
17916
+ /**
17917
+ * The tier boundary at which a settings label/value row stops stacking.
17918
+ *
17919
+ * Below it (L1 — compact) the row is ONE column: label on its own line, value
17920
+ * on the next at full width. Above it the row is label-left / value-right as
17921
+ * before. The two-column form needs `SETTING_ROW_LABEL`'s lane plus a readable
17922
+ * value beside it; a phone has neither, and the failure mode is not "cramped"
17923
+ * but "the value is the part that gets cut" — the one thing the operator
17924
+ * opened the page to read.
17925
+ */
17926
+ var SETTING_ROW_STACK_BREAKPOINT = "sm";
17927
+ /** Outer row: single column at L1, label/value columns from `sm` up. */
17928
+ var SETTING_ROW = "flex min-w-0 flex-col gap-0.5 py-1.5 sm:flex-row sm:items-center";
17929
+ /** Label lane. Full width (and free to wrap) at L1; a fixed lane from `sm` up. */
17930
+ var SETTING_ROW_LABEL = "min-w-0 text-[11px] leading-tight text-foreground-subtle sm:w-32 sm:shrink-0 sm:pr-2";
17931
+ /**
17932
+ * Value lane — the value text plus its trailing affordances (copy / reveal).
17933
+ * `w-full` at L1 so the value owns the whole row once the label is above it;
17934
+ * `sm:flex-1` makes it share the row again from `sm` up.
17935
+ */
17936
+ var SETTING_ROW_VALUE = "flex w-full min-w-0 items-center gap-1 sm:flex-1";
17937
+ /**
17938
+ * The value text itself. `break-all` lets an opaque token (a key, a URL) wrap
17939
+ * at L1 instead of being cut mid-word; `sm:truncate` restores the single-line
17940
+ * desktop form, where the row is wide enough for truncation to be a choice
17941
+ * rather than data loss.
17942
+ */
17943
+ var SETTING_ROW_VALUE_TEXT = "min-w-0 break-all text-xs text-foreground sm:truncate";
17944
+ /** Section header label (uppercase tracking-wider). */
17945
+ var TEXT_SECTION_LABEL = "text-[10px] sm:text-[11px] font-semibold text-foreground uppercase tracking-wider";
17946
+ /** Field label inside a row. */
17947
+ var TEXT_FIELD_LABEL = "text-[11px] sm:text-xs text-foreground";
17948
+ /** Sub-label / hint text. */
17949
+ var TEXT_HINT = "text-[10px] text-foreground-subtle";
17950
+ /** Primary value (a metric, badge, …). */
17951
+ var TEXT_VALUE = "text-[11px] sm:text-xs font-medium text-foreground";
17952
+ /** Big metric value (StatCard). */
17953
+ var TEXT_METRIC = "text-base sm:text-lg font-semibold leading-tight text-foreground";
17954
+ /** Default compact button. */
17955
+ var BTN_COMPACT = "inline-flex items-center justify-center gap-1 rounded border border-border bg-surface px-1.5 py-0.5 sm:px-2 sm:py-1 text-[10px] sm:text-[11px] font-medium text-foreground hover:bg-surface-hover transition-colors disabled:opacity-40";
17956
+ /** Primary compact button. */
17957
+ var BTN_COMPACT_PRIMARY = "inline-flex items-center justify-center gap-1 rounded border border-primary/40 bg-primary/15 px-1.5 py-0.5 sm:px-2 sm:py-1 text-[10px] sm:text-[11px] font-medium text-primary hover:bg-primary/25 transition-colors disabled:opacity-40";
17958
+ /** Danger compact button. */
17959
+ var BTN_COMPACT_DANGER = "inline-flex items-center justify-center gap-1 rounded border border-danger/40 bg-danger/10 px-1.5 py-0.5 sm:px-2 sm:py-1 text-[10px] sm:text-[11px] font-medium text-danger hover:bg-danger/20 transition-colors disabled:opacity-40";
17960
+ /** Warning compact button (e.g. cancel-drawing). */
17961
+ var BTN_COMPACT_WARNING = "inline-flex items-center justify-center gap-1 rounded border border-warning/40 bg-warning/10 px-1.5 py-0.5 sm:px-2 sm:py-1 text-[10px] sm:text-[11px] font-medium text-warning hover:bg-warning/20 transition-colors disabled:opacity-40";
17962
+ /** Compact text/select/number input. */
17963
+ var INPUT_COMPACT = "w-full rounded border border-border bg-background px-1.5 py-0.5 sm:px-2 sm:py-1 text-[11px] sm:text-xs text-foreground focus:border-primary focus:ring-1 focus:ring-primary/30 outline-none";
17964
+ /** Chip-style toggle (zone / class selectors in ZoneRulesEditor). */
17965
+ var CHIP_BASE = "inline-flex items-center gap-1 rounded-full border px-1.5 py-0.5 text-[10px] font-medium transition-colors";
17966
+ var CHIP_ACTIVE = "border-primary/50 bg-primary/15 text-primary";
17967
+ var CHIP_INACTIVE = "border-border bg-surface text-foreground-subtle hover:bg-surface-hover";
17968
+ //#endregion
17969
+ //#region src/composites/setting-row.tsx
17970
+ function SettingRow({ label, children, actions, elements = "plain", className, valueClassName }) {
17971
+ const LabelTag = elements === "description" ? "dt" : "span";
17972
+ const ValueTag = elements === "description" ? "dd" : "div";
17973
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
17974
+ "data-setting-row": "",
17975
+ className: cn(SETTING_ROW, className),
17976
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(LabelTag, {
17977
+ "data-setting-row-label": "",
17978
+ className: SETTING_ROW_LABEL,
17979
+ children: label
17980
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(ValueTag, {
17981
+ "data-setting-row-value": "",
17982
+ className: SETTING_ROW_VALUE,
17983
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
17984
+ "data-setting-row-value-text": "",
17985
+ className: cn(SETTING_ROW_VALUE_TEXT, valueClassName),
17986
+ children
17987
+ }), actions !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
17988
+ className: "flex shrink-0 items-center gap-0.5",
17989
+ children: actions
17990
+ })]
17991
+ })]
17992
+ });
17993
+ }
17994
+ //#endregion
17995
+ //#region src/composites/sort-header-button.tsx
17996
+ function SortHeaderButton({ label, active, dir, onSort }) {
17997
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
17998
+ type: "button",
17999
+ onClick: onSort,
18000
+ className: "group/sort inline-flex items-center gap-0.5 hover:text-foreground transition-colors",
18001
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: label }), active ? dir === "asc" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ChevronUp, { className: "h-3 w-3 flex-shrink-0" }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ChevronDown, { className: "h-3 w-3 flex-shrink-0" }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ChevronUp, { className: cn("h-3 w-3 flex-shrink-0 opacity-0 transition-opacity", "group-hover/sort:opacity-30") })]
18002
+ });
18003
+ }
18004
+ //#endregion
18005
+ //#region src/composites/table-sort.ts
18006
+ /**
18007
+ * The toggle rule, and the only copy of it.
18008
+ *
18009
+ * none → asc → desc → none, and a click on a DIFFERENT column starts that
18010
+ * column fresh at `asc`. `sameColumn` says whether the clicked column is the
18011
+ * one currently sorted; `currentDir` is its direction (`null` when nothing is
18012
+ * sorted). Returns the next direction, or `null` for "unsorted".
18013
+ *
18014
+ * Split out from {@link nextTableSort} so the device list — whose sort state
18015
+ * keys columns by `columnId`, not `columnKey` — can reuse the rule without a
18016
+ * cast and without a second copy of it.
18017
+ */
18018
+ function nextSortDirection(sameColumn, currentDir) {
18019
+ if (!sameColumn || currentDir === null) return "asc";
18020
+ return currentDir === "asc" ? "desc" : null;
18021
+ }
18022
+ /**
18023
+ * Toggle a column's sort on header click: none → asc → desc → none.
18024
+ * Clicking a DIFFERENT column starts it fresh at `asc`.
18025
+ */
18026
+ function nextTableSort(current, columnKey) {
18027
+ const dir = nextSortDirection(current !== null && current.columnKey === columnKey, current === null ? null : current.dir);
18028
+ return dir === null ? null : {
18029
+ columnKey,
18030
+ dir
18031
+ };
18032
+ }
18033
+ /**
18034
+ * Ascending comparison of two cell values.
18035
+ *
18036
+ * Numbers compare numerically and strings compare with `localeCompare` — a
18037
+ * numeric column must never be ordered as text ("100" before "9"), and a text
18038
+ * column must respect the locale's collation. A mixed column (one row a
18039
+ * number, another a string) falls back to string comparison of both, which is
18040
+ * the only total order available; it is not a shape any caller should build on
18041
+ * purpose.
18042
+ *
18043
+ * `null` is NOT handled here — {@link sortRowsByColumn} pulls it out first,
18044
+ * because its placement is direction-independent and a comparator that is
18045
+ * multiplied by the direction factor cannot express that.
18046
+ */
18047
+ function compareValues(a, b) {
18048
+ if (typeof a === "number" && typeof b === "number") return a - b;
18049
+ return String(a).localeCompare(String(b));
18050
+ }
18051
+ /**
18052
+ * Return a NEW array of `rows` ordered by `sort`.
18053
+ *
18054
+ * `valueOf` is the column's `sortValue` — it is called once per row per
18055
+ * comparison, so it must be cheap (read a field, do not format a string).
18056
+ * `sort === null` ⇒ a fresh shallow copy in the incoming order.
18057
+ */
18058
+ function sortRowsByColumn(rows, sort, valueOf) {
18059
+ if (sort === null) return [...rows];
18060
+ const factor = sort.dir === "asc" ? 1 : -1;
18061
+ return rows.toSorted((a, b) => {
18062
+ const av = valueOf(a);
18063
+ const bv = valueOf(b);
18064
+ if (av === null || bv === null) {
18065
+ if (av === bv) return 0;
18066
+ return av === null ? 1 : -1;
18067
+ }
18068
+ return factor * compareValues(av, bv);
18069
+ });
18070
+ }
18071
+ /** Derive the `<th>` `aria-sort` for `columnKey` from the table's sort state. */
18072
+ function ariaSortForColumn(sort, columnKey) {
18073
+ if (sort === null || sort.columnKey !== columnKey) return "none";
18074
+ return sort.dir === "asc" ? "ascending" : "descending";
18075
+ }
18076
+ //#endregion
18077
+ //#region src/composites/data-table.tsx
18078
+ /**
18079
+ * DataTable — shared responsive table for admin pages.
18080
+ *
18081
+ * Recipes baked in:
18082
+ * - `overflow-x-auto` wrapper so narrow viewports don't clip the
18083
+ * right edge (the rounded border survives the scroll).
18084
+ * - `min-w-[Npx]` on the inner table so columns don't squash below
18085
+ * readable width before the scroll kicks in.
18086
+ * - `whitespace-nowrap` on headers — column titles never wrap to
18087
+ * two lines (`AUTO-KILL` was the regression that triggered this).
18088
+ * - Themed `bg-surface` + `border-border` so contrast works in both
18089
+ * light and dark themes.
18090
+ *
18091
+ * Column model: caller supplies `columns: DataColumn<T>[]` and
18092
+ * `rows: T[]`. Each column declares `header`, optional `align`,
18093
+ * optional `nowrap`, and a `render(row) => ReactNode` that produces
18094
+ * the cell content.
18095
+ *
18096
+ * <DataTable
18097
+ * columns={[
18098
+ * { key: 'username', header: 'Username', render: (u) => u.username },
18099
+ * { key: 'role', header: 'Role', render: (u) => <RoleBadge .../> },
18100
+ * { key: 'actions', header: '', align: 'right', render: (u) => <Actions .../> },
18101
+ * ]}
18102
+ * rows={users}
18103
+ * minWidthPx={560}
18104
+ * />
18105
+ *
18106
+ * If finer header markup is needed, pass `headerRender` instead of
18107
+ * `header` (e.g. for a sortable click affordance).
18108
+ *
18109
+ * ── Narrow viewports ──────────────────────────────────────────────────────
18110
+ * The table stays a table. The wrapper is `overflow-x-auto`, so a phone
18111
+ * scrolls the columns sideways INSIDE the table — the page body never moves
18112
+ * sideways, and the cells stay one line (`whitespace-nowrap`). That is the
18113
+ * default (`mobileMode="scroll"`). Cards are opt-in via `mobileMode="cards"`;
18114
+ * `auto` still applies the old column-count rule for a surface that wants it.
18115
+ * See `resolveTableLayout`.
18116
+ *
18117
+ * ── Scrolling the BODY, not the page ──────────────────────────────────────
18118
+ * `maxBodyHeight` caps the table and scrolls its rows INSIDE the container
18119
+ * with the column header pinned. It is ONE prop, not two, because "this list
18120
+ * scrolls internally" and "its header stays visible" are the same decision: a
18121
+ * capped table whose header scrolls away is a list of unlabelled cells.
18122
+ *
18123
+ * Use it wherever the row count is open-ended (rules, targets, delivery
18124
+ * history) so the page keeps its own header, filters and actions in view while
18125
+ * the operator moves through the rows.
18126
+ */
18127
+ /**
18128
+ * The default cap for an internally-scrolling table.
18129
+ *
18130
+ * `60vh` leaves the page header, its filters and its actions on screen at
18131
+ * every viewport while still showing ~10 rows — and it is a fraction, so it
18132
+ * does not need a breakpoint of its own.
18133
+ */
18134
+ var TABLE_SCROLL_MAX_H = "max-h-[60vh]";
18135
+ var ALIGN_CLASS = {
18136
+ left: "text-left",
18137
+ right: "text-right",
18138
+ center: "text-center"
18139
+ };
18140
+ function DataTable({ columns, rows, rowKey, onRowClick, minWidthPx = 480, emptyMessage, className, bordered = true, rowClassName, mobileMode = "scroll", maxBodyHeight, defaultSort }) {
18141
+ const isNarrow = useIsMobile();
18142
+ const [sort, setSort] = (0, react$1.useState)(defaultSort ?? null);
18143
+ const layout = resolveTableLayout({
18144
+ mode: mobileMode,
18145
+ columnCount: columns.length,
18146
+ isNarrow
18147
+ });
18148
+ const scrolls = maxBodyHeight !== void 0;
18149
+ const sortedColumn = (0, react$1.useMemo)(() => sort === null ? void 0 : columns.find((col) => col.key === sort.columnKey && col.sortValue !== void 0), [columns, sort]);
18150
+ const sortValue = sortedColumn?.sortValue;
18151
+ const displayRows = (0, react$1.useMemo)(() => sortValue === void 0 ? rows : sortRowsByColumn(rows, sort, sortValue), [
18152
+ rows,
18153
+ sort,
18154
+ sortValue
18155
+ ]);
18156
+ const activeSort = sortedColumn === void 0 ? null : sort;
18157
+ if (rows.length === 0 && emptyMessage) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
18158
+ className: `rounded-lg ${bordered ? "border border-border" : ""} bg-surface px-3 py-4 text-xs text-foreground-subtle text-center ${className ?? ""}`,
18159
+ children: emptyMessage
18160
+ });
18161
+ if (rows.length === 0) return null;
18162
+ if (layout === "cards") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
18163
+ className: `space-y-2 ${scrolls ? `${maxBodyHeight} overflow-y-auto` : ""} ${className ?? ""}`,
18164
+ children: displayRows.map((row, rowIndex) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DataTableCard, {
18165
+ row,
18166
+ rowIndex,
18167
+ columns,
18168
+ bordered,
18169
+ onRowClick,
18170
+ rowClassName
18171
+ }, rowKey ? rowKey(row, rowIndex) : rowIndex))
18172
+ });
18173
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
18174
+ className: [
18175
+ "rounded-lg",
18176
+ bordered ? "border border-border" : "",
18177
+ "bg-surface overflow-x-auto",
18178
+ scrolls ? `${maxBodyHeight} overflow-y-auto` : "",
18179
+ className ?? ""
18180
+ ].filter(Boolean).join(" "),
18181
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("table", {
18182
+ className: `w-full text-xs ${scrolls ? "border-separate border-spacing-0" : ""}`,
18183
+ style: { minWidth: `${minWidthPx}px` },
18184
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("thead", {
18185
+ className: "bg-surface",
18186
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("tr", { children: columns.map((col) => {
18187
+ const align = col.align ?? "left";
18188
+ const nowrap = col.nowrap ?? true;
18189
+ const sortable = col.sortValue !== void 0;
18190
+ const isSorted = activeSort !== null && activeSort.columnKey === col.key;
18191
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("th", {
18192
+ "aria-sort": sortable ? ariaSortForColumn(activeSort, col.key) : void 0,
18193
+ title: sortable ? void 0 : col.notSortableReason,
18194
+ className: [
18195
+ "px-3 py-2 text-foreground-subtle font-medium bg-surface border-b border-border",
18196
+ scrolls ? "sticky top-0 z-10" : "",
18197
+ ALIGN_CLASS[align],
18198
+ nowrap ? "whitespace-nowrap" : "",
18199
+ col.width ?? ""
18200
+ ].filter(Boolean).join(" "),
18201
+ children: sortable ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SortHeaderButton, {
18202
+ label: col.headerRender ? col.headerRender() : col.header,
18203
+ active: isSorted,
18204
+ dir: isSorted && activeSort !== null ? activeSort.dir : "asc",
18205
+ onSort: () => setSort((prev) => nextTableSort(prev, col.key))
18206
+ }) : col.headerRender ? col.headerRender() : col.header
18207
+ }, col.key);
18208
+ }) })
18209
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("tbody", { children: displayRows.map((row, rowIndex) => {
18210
+ const key = rowKey ? rowKey(row, rowIndex) : rowIndex;
18211
+ const extra = rowClassName?.(row, rowIndex) ?? "";
18212
+ const interactive = onRowClick !== void 0;
18213
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("tr", {
18214
+ onClick: interactive ? () => onRowClick(row, rowIndex) : void 0,
18215
+ className: [interactive ? "cursor-pointer hover:bg-primary/5" : "hover:bg-primary/5", extra].filter(Boolean).join(" "),
18216
+ children: columns.map((col) => {
18217
+ const align = col.align ?? "left";
18218
+ const nowrap = col.nowrap ?? true;
18219
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", {
18220
+ className: [
18221
+ "px-3 py-2 text-foreground border-b border-border",
18222
+ ALIGN_CLASS[align],
18223
+ nowrap ? "whitespace-nowrap" : ""
18224
+ ].filter(Boolean).join(" "),
18225
+ children: col.render(row, rowIndex)
18226
+ }, col.key);
18227
+ })
18228
+ }, key);
18229
+ }) })]
18230
+ })
18231
+ });
18232
+ }
18233
+ /**
18234
+ * One row as a card. Columns that carry a plain-text `header` become labelled
18235
+ * `SettingRow`s — the label is the column title and the value gets the full
18236
+ * card width. Columns with no text header (an actions column, a
18237
+ * `headerRender`-only column) have no label to show, so they render as a
18238
+ * full-width strip at the foot of the card.
18239
+ */
18240
+ function DataTableCard({ row, rowIndex, columns, bordered, onRowClick, rowClassName }) {
18241
+ const labelled = columns.filter((col) => col.header !== void 0 && col.header !== "");
18242
+ const unlabelled = columns.filter((col) => col.header === void 0 || col.header === "");
18243
+ const interactive = onRowClick !== void 0;
18244
+ const extra = rowClassName?.(row, rowIndex) ?? "";
18245
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
18246
+ "data-data-table-card": "",
18247
+ onClick: interactive ? () => onRowClick(row, rowIndex) : void 0,
18248
+ className: [
18249
+ "rounded-lg bg-surface px-3 py-1.5 divide-y divide-border-subtle",
18250
+ bordered ? "border border-border" : "",
18251
+ interactive ? "cursor-pointer hover:bg-primary/5" : "",
18252
+ extra
18253
+ ].filter(Boolean).join(" "),
18254
+ children: [labelled.map((col) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SettingRow, {
18255
+ label: col.header,
18256
+ children: col.render(row, rowIndex)
18257
+ }, col.key)), unlabelled.length > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
18258
+ className: "flex flex-wrap items-center justify-end gap-2 py-1.5",
18259
+ children: unlabelled.map((col) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { children: col.render(row, rowIndex) }, col.key))
18260
+ })]
18261
+ });
18262
+ }
18263
+ //#endregion
18264
+ //#region src/composites/device-list/pagination.tsx
18265
+ var NEIGHBORS = 2;
18266
+ function computePageButtons(currentPage, totalPages) {
18267
+ if (totalPages <= 1) return [{
18268
+ kind: "page",
18269
+ n: 1
18270
+ }];
18271
+ if (totalPages <= 7) {
18272
+ const all = [];
18273
+ for (let i = 1; i <= totalPages; i++) all.push({
18274
+ kind: "page",
18275
+ n: i
18276
+ });
18277
+ return all;
18278
+ }
18279
+ const result = [];
18280
+ const leftBound = Math.max(2, currentPage - NEIGHBORS);
18281
+ const rightBound = Math.min(totalPages - 1, currentPage + NEIGHBORS);
18282
+ result.push({
18283
+ kind: "page",
18284
+ n: 1
18285
+ });
18286
+ if (leftBound > 2) result.push({
18287
+ kind: "ellipsis",
18288
+ side: "left"
18289
+ });
18290
+ for (let i = leftBound; i <= rightBound; i++) result.push({
18291
+ kind: "page",
18292
+ n: i
18293
+ });
18294
+ if (rightBound < totalPages - 1) result.push({
18295
+ kind: "ellipsis",
18296
+ side: "right"
18297
+ });
18298
+ result.push({
18299
+ kind: "page",
18300
+ n: totalPages
18301
+ });
18302
+ return result;
18303
+ }
18304
+ function Pagination({ currentPage, totalItems, pageSize, onPageChange, itemNoun = "devices" }) {
18305
+ if (totalItems <= pageSize) return null;
18306
+ const totalPages = Math.ceil(totalItems / pageSize);
18307
+ const startIdx = (currentPage - 1) * pageSize + 1;
18308
+ const endIdx = Math.min(currentPage * pageSize, totalItems);
18309
+ const buttons = computePageButtons(currentPage, totalPages);
18310
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
18311
+ className: "flex items-center justify-between gap-4 flex-wrap pt-2 text-[11px] text-foreground-subtle",
18312
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", { children: [
18313
+ "Showing ",
18314
+ startIdx,
18315
+ "–",
18316
+ endIdx,
18317
+ " of ",
18318
+ totalItems,
18319
+ " ",
18320
+ itemNoun
18321
+ ] }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
18322
+ className: "inline-flex items-center gap-1",
18323
+ children: [
18324
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
18325
+ type: "button",
18326
+ "aria-label": "Previous page",
18327
+ disabled: currentPage === 1,
18328
+ onClick: () => onPageChange(currentPage - 1),
18329
+ className: cn("inline-flex items-center justify-center h-7 w-7 rounded border border-border bg-surface text-foreground-subtle", "hover:text-foreground hover:bg-surface-hover transition-colors", "disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-surface"),
18330
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ChevronLeft, { className: "h-3 w-3" })
18331
+ }),
18332
+ buttons.map((b, i) => {
18333
+ if (b.kind === "ellipsis") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
18334
+ className: "px-1 text-foreground-subtle/60 select-none",
18335
+ children: "…"
18336
+ }, `e-${i}`);
18337
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
18338
+ type: "button",
18339
+ onClick: () => onPageChange(b.n),
18340
+ className: cn("inline-flex items-center justify-center h-7 min-w-7 px-1.5 rounded border text-[10.5px] font-medium transition-colors", b.n === currentPage ? "border-primary/40 bg-primary/10 text-primary" : "border-border bg-surface text-foreground-subtle hover:text-foreground hover:bg-surface-hover"),
18341
+ children: b.n
18342
+ }, `p-${b.n}`);
18343
+ }),
18344
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
18345
+ type: "button",
18346
+ "aria-label": "Next page",
18347
+ disabled: currentPage === totalPages,
18348
+ onClick: () => onPageChange(currentPage + 1),
18349
+ className: cn("inline-flex items-center justify-center h-7 w-7 rounded border border-border bg-surface text-foreground-subtle", "hover:text-foreground hover:bg-surface-hover transition-colors", "disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-surface"),
18350
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ChevronRight, { className: "h-3 w-3" })
18351
+ })
18352
+ ]
18353
+ })]
18354
+ });
18355
+ }
18356
+ //#endregion
18357
+ //#region src/composites/empty-state.tsx
18358
+ function EmptyState({ icon: Icon, title, description, action, className }) {
18359
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
18360
+ className: cn("flex flex-col items-center justify-center gap-3 py-12", className),
18361
+ children: [
18362
+ Icon && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Icon, {
18363
+ className: "h-12 w-12 text-foreground-subtle",
18364
+ "aria-hidden": "true"
18365
+ }),
18366
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
18367
+ className: "flex flex-col items-center gap-1 text-center",
18368
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
18369
+ className: "text-foreground-muted text-sm font-medium",
18370
+ children: title
18371
+ }), description && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
18372
+ className: "text-foreground-subtle text-xs max-w-xs",
18373
+ children: description
18374
+ })]
18375
+ }),
18376
+ action && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
18377
+ className: "mt-1",
18378
+ children: action
18379
+ })
18380
+ ]
18381
+ });
18382
+ }
18383
+ //#endregion
18384
+ //#region src/composites/error-box.tsx
18385
+ var VARIANT_STYLES$1 = {
18386
+ danger: {
18387
+ box: "border-danger/40 bg-danger/10",
18388
+ icon: "text-danger",
18389
+ title: "text-danger",
18390
+ message: "text-danger"
18391
+ },
18392
+ warning: {
18393
+ box: "border-amber-500/40 bg-amber-500/10",
18394
+ icon: "text-amber-600 dark:text-amber-400",
18395
+ title: "text-amber-700 dark:text-amber-300",
18396
+ message: "text-amber-700 dark:text-amber-300"
18397
+ }
18398
+ };
18399
+ function ErrorBox({ message, title, onRetry, action, variant = "danger", className }) {
18400
+ const styles = VARIANT_STYLES$1[variant];
18401
+ const Icon = variant === "warning" ? TriangleAlert : CircleAlert;
18402
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
18403
+ role: "alert",
18404
+ className: cn("flex items-start gap-2.5 rounded border px-3 py-2.5", styles.box, className),
18405
+ children: [
18406
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Icon, {
18407
+ className: cn("h-4 w-4 mt-0.5 shrink-0", styles.icon),
18408
+ "aria-hidden": "true"
18409
+ }),
18410
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
18411
+ className: "flex-1 min-w-0",
18412
+ children: [title && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
18413
+ className: cn("text-xs font-semibold", styles.title),
18414
+ children: title
18415
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
18416
+ className: cn("text-xs break-words", styles.message, title ? "mt-0.5" : ""),
18417
+ children: message
18418
+ })]
18419
+ }),
18420
+ action ?? (onRetry && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
18421
+ type: "button",
18422
+ onClick: onRetry,
18423
+ className: cn("shrink-0 inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] font-medium", "border border-current/30 hover:bg-current/10 transition-colors", styles.message),
18424
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(RefreshCw, {
18425
+ className: "h-3 w-3",
18426
+ "aria-hidden": "true"
18427
+ }), "Retry"]
18428
+ }))
18429
+ ]
18430
+ });
18431
+ }
18432
+ //#endregion
18433
+ //#region src/contexts/vod-playback.tsx
18434
+ /**
18435
+ * VodPlayback — shared context coordinating recorded (VOD) playback between a
18436
+ * widget/section (the Recording panel) and the hero StreamPanel.
18437
+ *
18438
+ * A CONTROLLER (the Recording widget) calls `play({ url, label })`; the hero
18439
+ * StreamPanel CONSUMES `request` and switches into VOD mode (HLS playback
18440
+ * through the hub data-plane) instead of the live WebRTC stream. `clear()`
18441
+ * returns the hero to live.
18442
+ *
18443
+ * Built on `createSharedContext` (NOT a plain `createContext`) so it crosses
18444
+ * the Module-Federation boundary: an addon-shipped widget consuming
18445
+ * `useVodPlayback()` resolves the SAME provider instance the host mounted —
18446
+ * the same mechanism `player-overlays` / `zone-editing` use to let federated
18447
+ * widgets (zone-editor, privacy-mask) drive the live player. Consumers used
18448
+ * outside a provider get the inert default (no-op), so a StreamPanel mounted
18449
+ * on a page without the Recording widget stays live-only without crashing.
18450
+ */
18451
+ var VodPlaybackContext = createSharedContext("camstack:vod-playback", {
18452
+ request: null,
18453
+ play: () => {},
18454
+ clear: () => {}
18455
+ });
18456
+ function VodPlaybackProvider({ children }) {
18457
+ const [request, setRequest] = (0, react$1.useState)(null);
18458
+ const value = (0, react$1.useMemo)(() => ({
18459
+ request,
18460
+ play: (req) => setRequest(req),
18461
+ clear: () => setRequest(null)
18462
+ }), [request]);
18463
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(VodPlaybackContext.Provider, {
18464
+ value,
18465
+ children
18466
+ });
18467
+ }
18468
+ /** @returns the VOD playback controller (inert no-op outside a provider). */
18469
+ function useVodPlayback() {
18470
+ return (0, react$1.useContext)(VodPlaybackContext);
18471
+ }
18472
+ //#endregion
18473
+ //#region src/primitives/card.tsx
18474
+ var cardVariants = cva("rounded-lg p-3", {
18475
+ variants: { variant: {
18476
+ flat: "bg-surface",
18477
+ bordered: "bg-surface border border-border"
18478
+ } },
18479
+ defaultVariants: { variant: "bordered" }
18480
+ });
18481
+ var Card = (0, react$1.forwardRef)(({ className, variant, ...props }, ref) => {
18482
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
18483
+ ref,
18484
+ className: cn(cardVariants({ variant }), className),
18485
+ ...props
18486
+ });
18487
+ });
18488
+ Card.displayName = "Card";
18489
+ //#endregion
18490
+ //#region src/composites/clips/ClipPanel.tsx
18491
+ /**
18492
+ * The selected clip — what it is, how it plays, and how it is saved.
18493
+ *
18494
+ * **No second player.** `getClipPlayback` answers `{ playbackUrl, format,
18495
+ * served }` and the panel hands it to the SAME hero the recordings timeline
18496
+ * drives: `vod.play({ url, format })` → `StreamPanel playbackUrl/playbackFormat`
18497
+ * → `HlsVideo`'s `mp4` branch (`video.src`, no hls.js). Building a clip player
18498
+ * here is the thing D549 decision 22 exists to refuse.
18499
+ *
18500
+ * **`format` travels.** An MP4 handed to hls.js is parsed as a manifest and
18501
+ * fails, so the format the provider named is forwarded verbatim and never
18502
+ * defaulted here.
18503
+ *
18504
+ * **`served` is shown.** A clip that holds only one twin answers with the one
18505
+ * it has, and the surface SAYS so — a missing main twin must never be served
18506
+ * silently as if it were the asked-for quality (D549 decision 15). Both ids
18507
+ * are already on the row, so changing quality re-asks the hub and never
18508
+ * re-searches the camera.
18509
+ *
18510
+ * **Nothing is appended to the URL.** The route is `access:'authenticated'`
18511
+ * and the session cookie authenticates it (D549 decision 22); the same URL is
18512
+ * the download.
18513
+ */
18514
+ var PROFILES = [
18515
+ "low",
18516
+ "mid",
18517
+ "high"
18518
+ ];
18519
+ function ClipPanel({ deviceId, clip, profile, onProfileChange }) {
18520
+ const vod = useVodPlayback();
18521
+ const playback = useVideoclipsGetClipPlayback({
18522
+ deviceId,
18523
+ clipId: clip.id,
18524
+ profile
18525
+ });
18526
+ const data = playback.data;
18527
+ const label = `${new Date(clip.timeRange.startMs).toLocaleString()} · ${clip.source}`;
18528
+ (0, react$1.useEffect)(() => {
18529
+ if (data === void 0) return;
18530
+ vod.play({
18531
+ url: hubPath(data.playbackUrl),
18532
+ ...data.format === void 0 ? {} : { format: data.format },
18533
+ label
18534
+ });
18535
+ }, [data, label]);
18536
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(Card, {
18537
+ className: "space-y-2 text-sm",
18538
+ children: [
18539
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
18540
+ className: "font-medium text-foreground",
18541
+ children: label
18542
+ }),
18543
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
18544
+ className: "flex items-center gap-1",
18545
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
18546
+ className: "mr-1 text-[10px] uppercase tracking-wide text-foreground-subtle",
18547
+ children: "Quality"
18548
+ }), PROFILES.map((option) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Button, {
18549
+ variant: option === profile ? "primary" : "secondary",
18550
+ "aria-pressed": option === profile,
18551
+ onClick: () => onProfileChange(option),
18552
+ children: option
18553
+ }, option))]
18554
+ }),
18555
+ playback.status === "pending" ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
18556
+ className: "space-y-1",
18557
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
18558
+ role: "status",
18559
+ className: "text-xs text-foreground-subtle",
18560
+ children: "Preparing the clip — the file is fetched and muxed once…"
18561
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Skeleton, { className: "h-4 w-48" })]
18562
+ }) : playback.status === "error" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ErrorBox, {
18563
+ title: "This clip could not be prepared",
18564
+ message: playback.error?.message ?? "no reason given"
18565
+ }) : data === void 0 ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
18566
+ className: "space-y-2",
18567
+ children: [data.served === void 0 || data.served === profile ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ErrorBox, {
18568
+ variant: "warning",
18569
+ message: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
18570
+ "Served the ",
18571
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("strong", { children: data.served }),
18572
+ " stream — this clip has no ",
18573
+ profile,
18574
+ " ",
18575
+ "twin."
18576
+ ] })
18577
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("a", {
18578
+ href: hubPath(data.playbackUrl),
18579
+ download: true,
18580
+ className: "inline-flex items-center gap-1.5 text-xs font-medium text-primary hover:underline",
18581
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(Download, {
18582
+ className: "h-3.5 w-3.5",
18583
+ "aria-hidden": "true"
18584
+ }), "Download this clip"]
18585
+ })]
18586
+ })
18587
+ ]
18588
+ });
18589
+ }
18590
+ //#endregion
18591
+ //#region src/composites/clips/clip-tile-media.ts
18592
+ /**
18593
+ * Why no still exists, in words. Keyed by the provider's own vocabulary so a
18594
+ * reason this table does not know still reaches the operator verbatim.
18595
+ */
18596
+ var REFUSAL_TEXT = {
18597
+ sleeping: "The camera is asleep — a still would cost a wake",
18598
+ "camera-refused": "The camera refused the still request",
18599
+ "no-keyframe": "No decodable frame inside this window",
18600
+ unsupported: "This source cannot produce stills",
18601
+ "queue-full": "The camera is busy — its still queue is full",
18602
+ "no-catalog-row": "This clip is no longer in the catalog"
18603
+ };
18604
+ function refusal(reason) {
18605
+ return {
18606
+ kind: "unavailable",
18607
+ reason,
18608
+ text: REFUSAL_TEXT[reason] ?? `Refused: ${reason}`
18609
+ };
18610
+ }
18611
+ /** What to draw for one clip's tile. */
18612
+ function resolveTileMedia(clip) {
18613
+ if (clip.thumbnail !== void 0) return {
18614
+ kind: "vouched",
18615
+ url: clip.thumbnail
18616
+ };
18617
+ if (clip.thumbnailUnavailable !== void 0) return refusal(clip.thumbnailUnavailable.reason);
18618
+ if (clip.thumbnailMint !== void 0) return {
18619
+ kind: "mint",
18620
+ url: clip.thumbnailMint
18621
+ };
18622
+ return {
18623
+ kind: "none",
18624
+ text: "This clip carries no still and offered none"
18625
+ };
18626
+ }
18627
+ /**
18628
+ * A mint that answered 204 — latch its `x-camstack-reason` to this instant.
18629
+ *
18630
+ * The refusal is about NOW (a full queue, a sleeping camera), so it replaces
18631
+ * the offer for as long as the tile is mounted and is not retried behind the
18632
+ * operator's back. An unknown reason is shown raw rather than dropped: a
18633
+ * firmware inventing a refusal must not become a blank tile.
18634
+ */
18635
+ function latchMintRefusal(reason) {
18636
+ return refusal(reason);
18637
+ }
18638
+ //#endregion
18639
+ //#region src/composites/clips/clip-thumbnail-fetch.ts
18640
+ /**
18641
+ * Asking a `thumbnailMint` route for a still — and hearing its refusal.
18642
+ *
18643
+ * The route answers **200** with a JPEG or **204** with the reason in
18644
+ * `x-camstack-reason` (`queue-full`, `sleeping`, `camera-refused`,
18645
+ * `no-keyframe`, `no-catalog-row`). An `<img src>` cannot read that header:
18646
+ * a 204 fires `onerror` with nothing to say, turning a named refusal into an
18647
+ * anonymous broken tile. So a mint goes through `fetch`.
18648
+ *
18649
+ * **Nothing is appended to the URL.** Both data-plane routes are registered
18650
+ * `access: 'authenticated'` and the hub's `/addon/<id>/<prefix>` proxy takes
18651
+ * the session cookie the admin UI sets at login, so the URL is never a
18652
+ * credential (D549 decision 22) — it may sit in history or a `Referer` and
18653
+ * open nothing.
18654
+ *
18655
+ * The refusal is about NOW and is LATCHED by the caller: a camera that just
18656
+ * said "busy" is not asked again behind the operator's back.
18657
+ */
18658
+ /**
18659
+ * Ask a mint route for one still.
18660
+ *
18661
+ * Never rejects: a thrown fetch is a refusal like any other, because a tile
18662
+ * that throws is a tile that renders nothing and says nothing — the exact
18663
+ * failure this module exists to prevent.
18664
+ */
18665
+ async function fetchMintedThumbnail(url, fetcher) {
18666
+ let response;
18667
+ try {
18668
+ response = await fetcher(url, { credentials: "same-origin" });
18669
+ } catch (err) {
18670
+ return latchMintRefusal(err instanceof Error ? err.message : String(err));
18671
+ }
18672
+ if (response.status === 204) return latchMintRefusal(response.headers.get("x-camstack-reason") ?? "no reason given");
18673
+ if (!response.ok) return latchMintRefusal(`HTTP ${String(response.status)}`);
18674
+ try {
18675
+ return {
18676
+ kind: "image",
18677
+ blob: await response.blob()
18678
+ };
18679
+ } catch (err) {
18680
+ return latchMintRefusal(err instanceof Error ? err.message : String(err));
18681
+ }
18682
+ }
18683
+ //#endregion
18684
+ //#region src/composites/clips/ClipTile.tsx
18685
+ /**
18686
+ * One clip, as a tile.
18687
+ *
18688
+ * The picture is resolved by `resolveTileMedia` — vouched JPEG, an offer, or
18689
+ * the reason there is none (D549 decision 5). An offer is fetched rather than
18690
+ * dropped into an `<img src>`, because the route's **204 + x-camstack-reason**
18691
+ * is invisible to an `<img>`: it fires `onerror` with nothing to say. The
18692
+ * refusal is LATCHED for the life of the tile and never retried behind the
18693
+ * operator's back.
18694
+ *
18695
+ * The row also carries what the camera itself said: its native types, the
18696
+ * behaviours beside the class, which storages hold it, and — for a row that
18697
+ * is an EVENT sitting inside no file — `playable: false` with its reason
18698
+ * (measured: 1 of 29 hub events on 3628). Such a row is SHOWN, never dropped
18699
+ * and never offered as playable-then-failing (D549 decision 19).
18700
+ *
18701
+ * The CHROME is the library's: a `Card` for the tile, `Badge` for every label
18702
+ * the camera gave it, `Skeleton` while a mint is in flight. Only the ladder
18703
+ * above is this file's own, because only it is a decision.
18704
+ */
18705
+ function clockOf(ms) {
18706
+ return new Date(ms).toLocaleTimeString(void 0, {
18707
+ hour: "2-digit",
18708
+ minute: "2-digit",
18709
+ second: "2-digit"
18710
+ });
18711
+ }
18712
+ /**
18713
+ * Ask a mint route once, and LATCH whatever it says.
18714
+ *
18715
+ * The offer is memoised on the three fields it is derived from, not rebuilt
18716
+ * per render: `resolveTileMedia` returns a fresh object every call, and an
18717
+ * effect keyed on that object re-runs on every commit — which, because the
18718
+ * effect sets state, is an infinite render loop. It was one here, and it hung
18719
+ * the suite rather than failing it.
18720
+ *
18721
+ * The refusal is latched for the life of the tile: a camera that just said
18722
+ * "busy" is not asked again behind the operator's back (D549 decision 5).
18723
+ */
18724
+ function useMintedStill(clip) {
18725
+ const offered = (0, react$1.useMemo)(() => resolveTileMedia(clip), [
18726
+ clip.thumbnail,
18727
+ clip.thumbnailMint,
18728
+ clip.thumbnailUnavailable?.reason
18729
+ ]);
18730
+ const [latched, setLatched] = (0, react$1.useState)(null);
18731
+ const mintUrl = offered.kind === "mint" ? offered.url : null;
18732
+ (0, react$1.useEffect)(() => {
18733
+ setLatched(null);
18734
+ if (mintUrl === null || typeof fetch !== "function") return void 0;
18735
+ let objectUrl = null;
18736
+ let cancelled = false;
18737
+ (async () => {
18738
+ const answer = await fetchMintedThumbnail(hubPath(mintUrl), fetch);
18739
+ if (cancelled) return;
17962
18740
  if (answer.kind === "image") {
17963
18741
  objectUrl = URL.createObjectURL(answer.blob);
17964
18742
  setLatched({
@@ -17980,47 +18758,52 @@ function ClipTile({ clip, selected, onSelect }) {
17980
18758
  const media = useMintedStill(clip);
17981
18759
  const playable = clip.playable !== false;
17982
18760
  const labels = [...clip.labels ?? [], ...clip.behaviours ?? []];
17983
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("li", { children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
18761
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("li", { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
17984
18762
  type: "button",
17985
18763
  onClick: () => onSelect(clip),
17986
18764
  disabled: !playable,
17987
18765
  "aria-current": selected ? "true" : void 0,
17988
- className: `flex w-full gap-3 rounded-md border p-2 text-left ${selected ? "border-primary" : "border-border"} ${playable ? "" : "opacity-70"}`,
17989
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
17990
- className: "flex h-16 w-28 shrink-0 items-center justify-center overflow-hidden rounded bg-muted text-[10px] text-muted-foreground",
17991
- children: media.kind === "vouched" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("img", {
17992
- src: media.url,
17993
- alt: "",
17994
- className: "h-full w-full object-cover"
17995
- }) : media.kind === "mint" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: "minting…" }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
17996
- className: "px-1 text-center",
17997
- children: media.text
17998
- })
17999
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
18000
- className: "min-w-0 flex-1",
18001
- children: [
18002
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
18003
- className: "font-medium",
18004
- children: clockOf(clip.timeRange.startMs)
18005
- }),
18006
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
18007
- className: "text-xs text-muted-foreground",
18008
- children: clip.source
18009
- }),
18010
- labels.length === 0 ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
18011
- className: "text-xs",
18012
- children: labels.join(" · ")
18013
- }),
18014
- clip.nativeTypes === void 0 || clip.nativeTypes.length === 0 ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
18015
- className: "text-[10px] text-muted-foreground",
18016
- children: clip.nativeTypes.join(", ")
18017
- }),
18018
- playable ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
18019
- className: "text-xs text-amber-600 dark:text-amber-400",
18020
- children: ["Not playable — ", clip.unplayableReason ?? "the source gave no reason"]
18766
+ className: "block w-full text-left disabled:cursor-not-allowed",
18767
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(Card, {
18768
+ className: `flex gap-3 transition-colors ${selected ? "border-primary" : ""} ${playable ? "hover:bg-surface-hover" : "opacity-70"}`,
18769
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
18770
+ className: "flex h-16 w-28 shrink-0 items-center justify-center overflow-hidden rounded bg-surface-hover text-[10px] text-foreground-subtle",
18771
+ children: media.kind === "vouched" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("img", {
18772
+ src: media.url,
18773
+ alt: "",
18774
+ className: "h-full w-full object-cover"
18775
+ }) : media.kind === "mint" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Skeleton, { className: "h-full w-full rounded-none" }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
18776
+ className: "px-1 text-center leading-tight",
18777
+ children: media.text
18021
18778
  })
18022
- ]
18023
- })]
18779
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
18780
+ className: "min-w-0 flex-1 space-y-1",
18781
+ children: [
18782
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
18783
+ className: "text-sm font-medium text-foreground",
18784
+ children: clockOf(clip.timeRange.startMs)
18785
+ }),
18786
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
18787
+ className: "text-[10px] text-foreground-subtle",
18788
+ children: clip.source
18789
+ }),
18790
+ labels.length === 0 && clip.nativeTypes === void 0 ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
18791
+ className: "flex flex-wrap gap-1",
18792
+ children: [labels.map((label) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Badge, {
18793
+ variant: "info",
18794
+ children: label
18795
+ }, `label:${label}`)), (clip.nativeTypes ?? []).map((native) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Badge, {
18796
+ style: "outline",
18797
+ children: native
18798
+ }, `native:${native}`))]
18799
+ }),
18800
+ playable ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
18801
+ className: "text-[11px] text-warning",
18802
+ children: ["Not playable — ", clip.unplayableReason ?? "the source gave no reason"]
18803
+ })
18804
+ ]
18805
+ })]
18806
+ })
18024
18807
  }) });
18025
18808
  }
18026
18809
  //#endregion
@@ -18129,12 +18912,6 @@ function formatCatalogAge(catalogAsOf, now) {
18129
18912
  }
18130
18913
  //#endregion
18131
18914
  //#region src/composites/clips/clip-view-state.ts
18132
- /** Keep only the rows of selected sources; an absent selection keeps them all. */
18133
- function applySelection(clips, selected) {
18134
- if (selected === void 0) return clips;
18135
- const allowed = new Set(selected);
18136
- return clips.filter((clip) => allowed.has(clip.source));
18137
- }
18138
18915
  function resolveClipsView(input) {
18139
18916
  if (input.clipsStatus === "error") return {
18140
18917
  kind: "failed",
@@ -18148,7 +18925,7 @@ function resolveClipsView(input) {
18148
18925
  const notices = input.sources.map(describeSource);
18149
18926
  const answered = notices.filter((notice) => notice.answered);
18150
18927
  const silent = notices.filter((notice) => !notice.answered);
18151
- const clips = applySelection(input.clips, input.selected);
18928
+ const clips = input.clips;
18152
18929
  if (clips.length === 0) return {
18153
18930
  kind: "empty",
18154
18931
  dayId: input.dayId,
@@ -18164,56 +18941,166 @@ function resolveClipsView(input) {
18164
18941
  };
18165
18942
  }
18166
18943
  //#endregion
18167
- //#region src/composites/clips/ClipsBrowser.tsx
18944
+ //#region src/composites/clips/ClipsSection.tsx
18168
18945
  /**
18169
- * `host/clips-browser` — a camera's clips, from EVERY source it has.
18946
+ * `host/clips-browser` — a camera's clips, from EVERY source it has, as the
18947
+ * LAST SECTION of the Recording tab.
18170
18948
  *
18171
18949
  * Mounted by the framework, not by hand: `videoclips.cap.ts` declares
18172
18950
  * `deviceConfig.ui = { kind:'widget', widgetId:'host/clips-browser',
18173
- * tab:'clips', topTab:true }` and `deriveDeviceConfigContribution` emits the
18174
- * section (D14). `DeviceDetail.tsx` is not edited — placement is data, and
18175
- * `device-config-widget-wrapped-binding.spec.ts` pins that the derive works
18176
- * for this cap's WRAPPED binding entry, which no shipped widget cap had
18177
- * exercised before.
18178
- *
18179
- * ## What it shows, and why every part of it exists
18180
- *
18181
- * A camera's clips live in several places at once — the analytics visit log,
18182
- * the camera's own SD card, a hub's storage — and the operator asked for all
18183
- * of them side by side, never one hidden behind another (D549 decision 2). So:
18951
+ * tab:'recording', topTab:true, order:100 }` and
18952
+ * `deriveDeviceConfigContribution` emits the section (D14). `DeviceDetail.tsx`
18953
+ * is not edited — placement is data. Because the admin Recordings page renders
18954
+ * every `location:'top-tab'` + `tab:'recording'` section behind its camera
18955
+ * picker (`CameraRecordingSettingsSection`), the same declaration puts this on
18956
+ * both surfaces with no second wiring.
18957
+ *
18958
+ * ## Built from the library, not from scratch
18959
+ *
18960
+ * It shipped as its own top tab made of five bespoke components, and the
18961
+ * operator rejected both: *"La UI è orribile, non segue la nostra UI affatto …
18962
+ * Io in realtà utilizzerei la stessa tab recordings, lì abbiamo già tutto il
18963
+ * necessario, una nuova sezione alla fine per le clips dove possiamo
18964
+ * selezionare le source con un multiselect common, non componenti nuovi
18965
+ * anonimi."* So every piece of chrome here is a component this repo already
18966
+ * has: `Select`, `DataTable`, `EmptyState`, `ErrorBox`, `Pagination`, `Card`,
18967
+ * `Badge`, `Button`, `Skeleton`. What the chrome CARRIES is unchanged, and it
18968
+ * is the feature:
18184
18969
  *
18185
18970
  * - **The source list is complete, always.** Every source the camera has,
18186
- * with its availability and the age of its catalog. Unticking one hides its
18187
- * ROWS; the source itself never leaves the list.
18971
+ * with its availability and the age of its catalog, whichever provider is
18972
+ * being asked. A source never leaves the table.
18188
18973
  * - **Nothing is deduped.** A clip held in two storages appears twice, once
18189
- * per source, and every row says which. That is stated as a consequence in
18190
- * D549 so it is not "fixed" later.
18974
+ * per source, and every tile says which (D549).
18191
18975
  * - **Four states are tellable apart**: loading, empty-with-a-cause,
18192
18976
  * degraded-per-source, and each silent source in its own words. Every one
18193
- * of them used to render as "no clips", which is the defect this whole
18194
- * line of work is about — a camera with no SD card (640) is not quiet, and
18195
- * a camera whose own index disagrees with its own calendar (618, 6–20
18977
+ * of them used to render as "no clips", which is the defect this whole line
18978
+ * of work is about — a camera with no SD card (640) is not quiet, and a
18979
+ * camera whose own index disagrees with its own calendar (618, 6–20
18196
18980
  * September) is not quiet either.
18197
18981
  *
18198
- * ## What the picker WRITES — nothing
18199
- *
18200
- * The tick boxes are the cap's own `sources` view filter, forwarded to
18201
- * `listClips`, and they persist nothing. The persistent authority for turning
18202
- * a source off for a camera is `deviceManager.setWrapperActive`, whose deny
18203
- * set is keyed by **addon id** (D556 decision 3) — and one addon serves TWO
18204
- * sources of a hub child (`native:reolink:onboard` and `native:reolink:hub`,
18205
- * both `provider-reolink`). Wiring a per-SOURCE tick box to a per-ADDON
18206
- * authority would make "hide the hub's event view" silently mean "turn off
18207
- * both Reolink sources": a switch that does something other than what it says,
18208
- * which is worse than no switch (D62). The gap and its fix are recorded in
18209
- * ADR 557; until a source row names its own provider, this surface offers the
18210
- * filter it can honour and no second store.
18982
+ * ## The picker WRITES nothing, and there is nothing for it to write
18983
+ *
18984
+ * A clip source is not enabled or disabled — it EXISTS, because of a
18985
+ * configuration that lives somewhere else. The operator put it exactly:
18986
+ * *"non è affatto necessario lo stato di abilitato o meno delle sources. Loro
18987
+ * vivono lì, ad esempio hksv c'è se la camera è esportata su homekit, reolink
18988
+ * la dà di suo così come il camstack."* HKSV is there if the camera is
18989
+ * exported to HomeKit; the Reolink source is there because Reolink is that
18990
+ * camera's provider; CamStack's is always there. None of that is a decision to
18991
+ * make in a clips list, so this surface offers no switch and writes no
18992
+ * authority (D557, amended). A directory-wide guard in
18993
+ * `clips-section-sources.test.tsx` keeps it that way.
18994
+ *
18995
+ * ## Why the picker is a SELECT and not a multiselect
18996
+ *
18997
+ * The operator asked for *"un multiselect common"* while `listClips` still
18998
+ * took `sources?: string[]`. It now takes ONE `provider` — *"il get videoclips
18999
+ * prendere un provider opzionale, di default va su camstack … l'utilizzatore è
19000
+ * uno solo"* — and a multi-pick control over a one-at-a-time argument offers a
19001
+ * sum the hub cannot answer. So the control is the shared single-choice one,
19002
+ * `Select`: the same component the Recordings page's own camera picker uses,
19003
+ * which is what *"segue la nostra UI"* means here. Absent means the camera's
19004
+ * BOUND provider, and the option that carries it is labelled with that
19005
+ * provider's own sources rather than the word "default".
19006
+ *
19007
+ * ## One provider is a fleet STATE
19008
+ *
19009
+ * `listSources` derives from `deviceManager.getBindings`, and today nothing
19010
+ * binds `provider-reolink` for `videoclips`, so a real camera answers with one
19011
+ * provider. The selector is then inert and SAYS why. An empty or silently
19012
+ * single-entry control would read as a defect; the binding store learning to
19013
+ * hold several providers for a collection cap is what changes this, and
19014
+ * nothing here needs to change with it.
18211
19015
  */
18212
19016
  /** Newest-first, and bounded: a busy day on 592 lists 546 clips. */
18213
19017
  var CLIP_PAGE_LIMIT = 500;
18214
- function ClipsBrowser({ deviceId }) {
19018
+ /** Tiles per page. The rest are a `Pagination` click away, never dropped. */
19019
+ var TILES_PER_PAGE = 60;
19020
+ var TONE_BADGE = {
19021
+ ok: "success",
19022
+ warn: "warning",
19023
+ error: "danger"
19024
+ };
19025
+ var SOURCE_COLUMNS = [
19026
+ {
19027
+ key: "source",
19028
+ header: "Source",
19029
+ render: (row) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
19030
+ className: "min-w-0",
19031
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
19032
+ className: "font-medium text-foreground",
19033
+ children: row.notice.label
19034
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
19035
+ className: "text-[10px] text-foreground-subtle",
19036
+ children: row.notice.source
19037
+ })]
19038
+ })
19039
+ },
19040
+ {
19041
+ key: "state",
19042
+ header: "State",
19043
+ nowrap: false,
19044
+ render: (row) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Badge, {
19045
+ variant: TONE_BADGE[row.notice.tone],
19046
+ children: row.notice.headline
19047
+ })
19048
+ },
19049
+ {
19050
+ key: "reason",
19051
+ header: "Reason",
19052
+ nowrap: false,
19053
+ render: (row) => row.notice.detail === null ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
19054
+ className: "text-foreground-subtle",
19055
+ children: "—"
19056
+ }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
19057
+ className: "break-words",
19058
+ children: row.notice.detail
19059
+ })
19060
+ },
19061
+ {
19062
+ key: "read",
19063
+ header: "Catalog read",
19064
+ render: (row) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
19065
+ className: "text-foreground-subtle",
19066
+ children: row.catalogAge ?? "live"
19067
+ })
19068
+ }
19069
+ ];
19070
+ /** The sources that contributed NOTHING to what is on screen, and why. */
19071
+ function SilentSources({ silent }) {
19072
+ if (silent.length === 0) return null;
19073
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ErrorBox, {
19074
+ variant: "warning",
19075
+ title: silent.length === 1 ? "One source contributed nothing to this list" : `${String(silent.length)} sources contributed nothing to this list`,
19076
+ message: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
19077
+ className: "space-y-1",
19078
+ children: silent.map((notice) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [
19079
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
19080
+ className: "font-medium",
19081
+ children: notice.label
19082
+ }),
19083
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
19084
+ className: "opacity-70",
19085
+ children: [
19086
+ " (",
19087
+ notice.source,
19088
+ ")"
19089
+ ]
19090
+ }),
19091
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { children: notice.headline }),
19092
+ notice.detail === null ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
19093
+ className: "opacity-80 break-words",
19094
+ children: notice.detail
19095
+ })
19096
+ ] }, notice.source))
19097
+ })
19098
+ });
19099
+ }
19100
+ function ClipsSection({ deviceId }) {
18215
19101
  const [dayId, setDayId] = (0, react$1.useState)(() => toDayId(/* @__PURE__ */ new Date()));
18216
- const [hidden, setHidden] = (0, react$1.useState)([]);
19102
+ const [provider, setProvider] = (0, react$1.useState)("");
19103
+ const [page, setPage] = (0, react$1.useState)(1);
18217
19104
  const [selectedClip, setSelectedClip] = (0, react$1.useState)(null);
18218
19105
  const [profile, setProfile] = (0, react$1.useState)("low");
18219
19106
  const presence = useCapabilityPresence("videoclips");
@@ -18223,115 +19110,186 @@ function ClipsBrowser({ deviceId }) {
18223
19110
  deviceId,
18224
19111
  since: window.since,
18225
19112
  until: window.until,
18226
- limit: CLIP_PAGE_LIMIT
19113
+ limit: CLIP_PAGE_LIMIT,
19114
+ ...provider === "" ? {} : { provider }
18227
19115
  });
18228
19116
  const sourceRows = sources.data ?? [];
18229
- const selected = sourceRows.map((row) => row.source).filter((source) => !hidden.includes(source));
18230
19117
  const view = resolveClipsView({
18231
19118
  dayId,
18232
19119
  clipsStatus: clips.status,
18233
19120
  clips: clips.data ?? [],
18234
19121
  sourcesStatus: sources.status,
18235
19122
  sources: sourceRows,
18236
- ...hidden.length === 0 ? {} : { selected },
18237
19123
  ...clips.error ? { clipsError: clips.error.message } : {},
18238
19124
  ...sources.error ? { sourcesError: sources.error.message } : {}
18239
19125
  });
18240
19126
  const now = Date.now();
18241
- const toggle = (source, next) => setHidden((current) => next ? current.filter((id) => id !== source) : current.includes(source) ? current : [...current, source]);
18242
- if (presence === "pending") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
18243
- role: "status",
18244
- children: "Asking the registry whether this cluster serves clips…"
19127
+ const options = (0, react$1.useMemo)(() => {
19128
+ const byAddon = /* @__PURE__ */ new Map();
19129
+ for (const row of sourceRows) {
19130
+ const addonId = row.addonId;
19131
+ if (addonId === void 0) continue;
19132
+ const labels = byAddon.get(addonId);
19133
+ if (labels === void 0) byAddon.set(addonId, [row.label]);
19134
+ else labels.push(row.label);
19135
+ }
19136
+ const rest = [...byAddon].map(([value, labels]) => ({
19137
+ value,
19138
+ label: labels.join(" · ")
19139
+ }));
19140
+ const first = rest[0];
19141
+ return [{
19142
+ value: "",
19143
+ label: first === void 0 ? "The camera’s bound provider" : first.label
19144
+ }, ...rest.slice(1)];
19145
+ }, [sourceRows]);
19146
+ const tableRows = (0, react$1.useMemo)(() => sourceRows.map((row) => ({
19147
+ notice: describeSource(row),
19148
+ catalogAge: formatCatalogAge(row.availability.catalogAsOf, now)
19149
+ })), [sourceRows]);
19150
+ const goToDay = (next) => {
19151
+ setDayId(next);
19152
+ setPage(1);
19153
+ };
19154
+ const pick = (next) => {
19155
+ setProvider(next);
19156
+ setPage(1);
19157
+ };
19158
+ if (presence === "pending") return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
19159
+ className: "space-y-2",
19160
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
19161
+ role: "status",
19162
+ className: "text-xs text-foreground-subtle",
19163
+ children: "Asking the registry whether this cluster serves clips…"
19164
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Skeleton, { className: "h-24 w-full" })]
18245
19165
  });
18246
- if (presence === "unknown") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
18247
- role: "alert",
18248
- children: "The capability registry could not be reached, so whether this camera has clip sources is unknown — not absent."
19166
+ if (presence === "unknown") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ErrorBox, {
19167
+ variant: "warning",
19168
+ title: "Clip sources unknown",
19169
+ message: "The capability registry could not be reached, so whether this camera has clip sources is unknown — not absent."
18249
19170
  });
18250
- if (presence === "absent") return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
19171
+ if (presence === "absent") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
18251
19172
  role: "status",
18252
- children: [
18253
- "No provider of ",
18254
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("code", { children: "videoclips" }),
18255
- " is installed in this cluster."
18256
- ]
19173
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(EmptyState, {
19174
+ icon: Clapperboard,
19175
+ title: "No provider of videoclips in this cluster",
19176
+ description: "Nothing is installed that could list a camera's stored clips."
19177
+ })
18257
19178
  });
19179
+ const visible = view.kind === "listed" ? view.clips : [];
19180
+ const pageClips = visible.slice((page - 1) * TILES_PER_PAGE, page * TILES_PER_PAGE);
18258
19181
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
18259
- className: "space-y-4",
19182
+ className: "space-y-3",
18260
19183
  children: [
18261
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
18262
- "aria-label": "Clip sources",
18263
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h3", {
18264
- className: "text-sm font-semibold",
18265
- children: "Sources"
18266
- }), sources.status === "pending" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
18267
- role: "status",
18268
- children: "Loading this camera's clip sources…"
18269
- }) : sourceRows.length === 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
18270
- role: "status",
18271
- children: "No provider answered for this camera — nothing claims to hold clips for it."
18272
- }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("ul", { children: sourceRows.map((row) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ClipSourceRow, {
18273
- notice: describeSource(row),
18274
- catalogAge: formatCatalogAge(row.availability.catalogAsOf, now),
18275
- checked: !hidden.includes(row.source),
18276
- onToggle: toggle
18277
- }, row.source)) })]
18278
- }),
18279
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
18280
- "aria-label": "Day",
18281
- className: "flex items-center gap-2",
19184
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h3", {
19185
+ className: "text-sm font-semibold text-foreground",
19186
+ children: "Clips"
19187
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
19188
+ className: "mt-1 text-[11px] text-foreground-subtle",
19189
+ children: "Every source this camera has, side by side — CamStack's own recordings and whatever the camera or an export keeps of its own. A source is listed because it exists, not because it was switched on here; pick sources to narrow the view."
19190
+ })] }),
19191
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
19192
+ className: "flex flex-wrap items-center gap-2",
18282
19193
  children: [
18283
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
18284
- type: "button",
18285
- "aria-label": "Previous day",
18286
- onClick: () => setDayId(shiftDay(dayId, -1)),
18287
- children: "‹"
18288
- }),
18289
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
18290
- className: "font-medium",
18291
- children: formatDayLabel(dayId)
19194
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("label", {
19195
+ htmlFor: "clips-provider",
19196
+ className: "text-[10px] uppercase tracking-wide text-foreground-subtle",
19197
+ children: "Source"
18292
19198
  }),
18293
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
18294
- type: "button",
18295
- "aria-label": "Next day",
18296
- onClick: () => setDayId(shiftDay(dayId, 1)),
18297
- children: "›"
19199
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
19200
+ className: "w-60",
19201
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Select, {
19202
+ id: "clips-provider",
19203
+ options,
19204
+ value: provider,
19205
+ disabled: options.length < 2,
19206
+ onChange: (e) => pick(e.target.value)
19207
+ })
18298
19208
  }),
18299
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
18300
- type: "button",
18301
- onClick: () => setDayId(toDayId(/* @__PURE__ */ new Date())),
18302
- children: "Today"
19209
+ options.length < 2 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
19210
+ className: "text-[11px] text-foreground-subtle",
19211
+ children: "This camera is bound to one clip provider today."
19212
+ }) : null,
19213
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
19214
+ className: "ml-auto flex items-center gap-1",
19215
+ children: [
19216
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Button, {
19217
+ variant: "ghost",
19218
+ "aria-label": "Previous day",
19219
+ onClick: () => goToDay(shiftDay(dayId, -1)),
19220
+ children: "‹"
19221
+ }),
19222
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
19223
+ className: "px-1 text-xs font-medium text-foreground",
19224
+ children: formatDayLabel(dayId)
19225
+ }),
19226
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Button, {
19227
+ variant: "ghost",
19228
+ "aria-label": "Next day",
19229
+ onClick: () => goToDay(shiftDay(dayId, 1)),
19230
+ children: "›"
19231
+ }),
19232
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Button, {
19233
+ variant: "outline",
19234
+ onClick: () => goToDay(toDayId(/* @__PURE__ */ new Date())),
19235
+ children: "Today"
19236
+ })
19237
+ ]
18303
19238
  })
18304
19239
  ]
18305
19240
  }),
19241
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("section", {
19242
+ "aria-label": "Clip sources",
19243
+ className: "space-y-1",
19244
+ children: sources.status === "pending" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Skeleton, { className: "h-16 w-full" }) : tableRows.length === 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(EmptyState, {
19245
+ icon: Film,
19246
+ title: "No provider answered for this camera",
19247
+ description: "Nothing claims to hold clips for it."
19248
+ }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DataTable, {
19249
+ columns: SOURCE_COLUMNS,
19250
+ rows: [...tableRows],
19251
+ minWidthPx: 520
19252
+ })
19253
+ }),
18306
19254
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("section", {
18307
19255
  "aria-label": "Clips",
18308
- children: view.kind === "loading" ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
19256
+ className: "space-y-2",
19257
+ children: view.kind === "loading" ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
18309
19258
  role: "status",
19259
+ className: "text-xs text-foreground-subtle",
18310
19260
  children: [
18311
19261
  "Loading clips for ",
18312
19262
  formatDayLabel(dayId),
18313
19263
  "…"
18314
19264
  ]
18315
- }) : view.kind === "failed" ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
18316
- role: "alert",
18317
- children: ["The clip list could not be read: ", view.message]
18318
- }) : view.kind === "empty" ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
18319
- className: "space-y-2",
18320
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
18321
- role: "status",
18322
- children: view.nobodyAnswered ? `No source could answer for ${formatDayLabel(dayId)}.` : `No clips on ${formatDayLabel(dayId)} from ${view.answered.map((notice) => notice.label).join(", ")}.`
18323
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ClipSilentSources, { silent: view.silent })]
18324
- }) : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
18325
- className: "space-y-2",
18326
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(ClipSilentSources, { silent: view.silent }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("ul", {
18327
- className: "space-y-2",
18328
- children: view.clips.map((clip) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ClipTile, {
19265
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Skeleton, { className: "h-24 w-full" })] }) : view.kind === "failed" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ErrorBox, {
19266
+ title: "The clip list could not be read",
19267
+ message: view.message
19268
+ }) : view.kind === "empty" ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
19269
+ role: "status",
19270
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(EmptyState, {
19271
+ icon: Film,
19272
+ title: view.nobodyAnswered ? `No source could answer for ${formatDayLabel(dayId)}` : `No clips on ${formatDayLabel(dayId)}`,
19273
+ ...view.nobodyAnswered ? {} : { description: `Asked ${view.answered.map((notice) => notice.label).join(", ")}.` }
19274
+ })
19275
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SilentSources, { silent: view.silent })] }) : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
19276
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SilentSources, { silent: view.silent }),
19277
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("ul", {
19278
+ className: "grid grid-cols-1 gap-2 sm:grid-cols-2 xl:grid-cols-3",
19279
+ children: pageClips.map((clip) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ClipTile, {
18329
19280
  clip,
18330
19281
  selected: selectedClip?.id === clip.id,
18331
19282
  onSelect: setSelectedClip
18332
19283
  }, `${clip.source}:${clip.id}`))
18333
- })]
18334
- })
19284
+ }),
19285
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Pagination, {
19286
+ currentPage: page,
19287
+ totalItems: visible.length,
19288
+ pageSize: TILES_PER_PAGE,
19289
+ onPageChange: setPage,
19290
+ itemNoun: "clips"
19291
+ })
19292
+ ] })
18335
19293
  }),
18336
19294
  selectedClip === null ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ClipPanel, {
18337
19295
  deviceId,
@@ -20462,82 +21420,6 @@ function useScrubController(sink, isPlayerLive = () => false) {
20462
21420
  };
20463
21421
  }
20464
21422
  //#endregion
20465
- //#region src/composites/empty-state.tsx
20466
- function EmptyState({ icon: Icon, title, description, action, className }) {
20467
- return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
20468
- className: cn("flex flex-col items-center justify-center gap-3 py-12", className),
20469
- children: [
20470
- Icon && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Icon, {
20471
- className: "h-12 w-12 text-foreground-subtle",
20472
- "aria-hidden": "true"
20473
- }),
20474
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
20475
- className: "flex flex-col items-center gap-1 text-center",
20476
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
20477
- className: "text-foreground-muted text-sm font-medium",
20478
- children: title
20479
- }), description && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
20480
- className: "text-foreground-subtle text-xs max-w-xs",
20481
- children: description
20482
- })]
20483
- }),
20484
- action && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
20485
- className: "mt-1",
20486
- children: action
20487
- })
20488
- ]
20489
- });
20490
- }
20491
- //#endregion
20492
- //#region src/composites/error-box.tsx
20493
- var VARIANT_STYLES$1 = {
20494
- danger: {
20495
- box: "border-danger/40 bg-danger/10",
20496
- icon: "text-danger",
20497
- title: "text-danger",
20498
- message: "text-danger"
20499
- },
20500
- warning: {
20501
- box: "border-amber-500/40 bg-amber-500/10",
20502
- icon: "text-amber-600 dark:text-amber-400",
20503
- title: "text-amber-700 dark:text-amber-300",
20504
- message: "text-amber-700 dark:text-amber-300"
20505
- }
20506
- };
20507
- function ErrorBox({ message, title, onRetry, action, variant = "danger", className }) {
20508
- const styles = VARIANT_STYLES$1[variant];
20509
- const Icon = variant === "warning" ? TriangleAlert : CircleAlert;
20510
- return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
20511
- role: "alert",
20512
- className: cn("flex items-start gap-2.5 rounded border px-3 py-2.5", styles.box, className),
20513
- children: [
20514
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Icon, {
20515
- className: cn("h-4 w-4 mt-0.5 shrink-0", styles.icon),
20516
- "aria-hidden": "true"
20517
- }),
20518
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
20519
- className: "flex-1 min-w-0",
20520
- children: [title && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
20521
- className: cn("text-xs font-semibold", styles.title),
20522
- children: title
20523
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
20524
- className: cn("text-xs break-words", styles.message, title ? "mt-0.5" : ""),
20525
- children: message
20526
- })]
20527
- }),
20528
- action ?? (onRetry && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
20529
- type: "button",
20530
- onClick: onRetry,
20531
- className: cn("shrink-0 inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] font-medium", "border border-current/30 hover:bg-current/10 transition-colors", styles.message),
20532
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(RefreshCw, {
20533
- className: "h-3 w-3",
20534
- "aria-hidden": "true"
20535
- }), "Retry"]
20536
- }))
20537
- ]
20538
- });
20539
- }
20540
- //#endregion
20541
21423
  //#region src/composites/cap-settings/recording-spans.ts
20542
21424
  /**
20543
21425
  * Merge availability ranges (across every profile) into the union of distinct
@@ -21721,7 +22603,7 @@ var HOST_WIDGETS = {
21721
22603
  "host/ptz-autotrack": AutotrackSection,
21722
22604
  "host/recording-panel": RecordingPanel,
21723
22605
  "host/camera-grid-layout": CameraGridLayoutEditor,
21724
- "host/clips-browser": ClipsBrowser
22606
+ "host/clips-browser": ClipsSection
21725
22607
  };
21726
22608
  //#endregion
21727
22609
  //#region src/composites/widget-slot.tsx
@@ -26028,92 +26910,6 @@ function AgentStepEditor(props) {
26028
26910
  });
26029
26911
  }
26030
26912
  //#endregion
26031
- //#region ../../node_modules/class-variance-authority/dist/index.mjs
26032
- /**
26033
- * Copyright 2022 Joe Bell. All rights reserved.
26034
- *
26035
- * This file is licensed to you under the Apache License, Version 2.0
26036
- * (the "License"); you may not use this file except in compliance with the
26037
- * License. You may obtain a copy of the License at
26038
- *
26039
- * http://www.apache.org/licenses/LICENSE-2.0
26040
- *
26041
- * Unless required by applicable law or agreed to in writing, software
26042
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
26043
- * WARRANTIES OR REPRESENTATIONS OF ANY KIND, either express or implied. See the
26044
- * License for the specific language governing permissions and limitations under
26045
- * the License.
26046
- */ var falsyToString = (value) => typeof value === "boolean" ? `${value}` : value === 0 ? "0" : value;
26047
- var cx = clsx;
26048
- var cva = (base, config) => (props) => {
26049
- var _config_compoundVariants;
26050
- if ((config === null || config === void 0 ? void 0 : config.variants) == null) return cx(base, props === null || props === void 0 ? void 0 : props.class, props === null || props === void 0 ? void 0 : props.className);
26051
- const { variants, defaultVariants } = config;
26052
- const getVariantClassNames = Object.keys(variants).map((variant) => {
26053
- const variantProp = props === null || props === void 0 ? void 0 : props[variant];
26054
- const defaultVariantProp = defaultVariants === null || defaultVariants === void 0 ? void 0 : defaultVariants[variant];
26055
- if (variantProp === null) return null;
26056
- const variantKey = falsyToString(variantProp) || falsyToString(defaultVariantProp);
26057
- return variants[variant][variantKey];
26058
- });
26059
- const propsWithoutUndefined = props && Object.entries(props).reduce((acc, param) => {
26060
- let [key, value] = param;
26061
- if (value === void 0) return acc;
26062
- acc[key] = value;
26063
- return acc;
26064
- }, {});
26065
- return cx(base, getVariantClassNames, config === null || config === void 0 ? void 0 : (_config_compoundVariants = config.compoundVariants) === null || _config_compoundVariants === void 0 ? void 0 : _config_compoundVariants.reduce((acc, param) => {
26066
- let { class: cvClass, className: cvClassName, ...compoundVariantOptions } = param;
26067
- return Object.entries(compoundVariantOptions).every((param) => {
26068
- let [key, value] = param;
26069
- return Array.isArray(value) ? value.includes({
26070
- ...defaultVariants,
26071
- ...propsWithoutUndefined
26072
- }[key]) : {
26073
- ...defaultVariants,
26074
- ...propsWithoutUndefined
26075
- }[key] === value;
26076
- }) ? [
26077
- ...acc,
26078
- cvClass,
26079
- cvClassName
26080
- ] : acc;
26081
- }, []), props === null || props === void 0 ? void 0 : props.class, props === null || props === void 0 ? void 0 : props.className);
26082
- };
26083
- //#endregion
26084
- //#region src/primitives/button.tsx
26085
- var buttonVariants = cva("inline-flex items-center justify-center rounded-md font-medium transition-colors cursor-pointer disabled:opacity-50 disabled:pointer-events-none", {
26086
- variants: {
26087
- variant: {
26088
- primary: "bg-primary text-primary-foreground hover:bg-primary/90",
26089
- secondary: "bg-surface text-foreground hover:bg-surface-hover",
26090
- ghost: "hover:bg-surface-hover text-foreground-muted",
26091
- danger: "bg-danger text-white hover:bg-danger/90",
26092
- outline: "border border-border bg-transparent text-foreground hover:bg-surface-hover"
26093
- },
26094
- size: {
26095
- sm: "h-7 px-2.5 text-xs gap-1.5",
26096
- md: "h-8 px-3 text-sm gap-2",
26097
- lg: "h-9 px-4 text-sm gap-2"
26098
- }
26099
- },
26100
- defaultVariants: {
26101
- variant: "primary",
26102
- size: "sm"
26103
- }
26104
- });
26105
- var Button = (0, react$1.forwardRef)(({ className, variant, size, ...props }, ref) => {
26106
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
26107
- ref,
26108
- className: cn(buttonVariants({
26109
- variant,
26110
- size
26111
- }), className),
26112
- ...props
26113
- });
26114
- });
26115
- Button.displayName = "Button";
26116
- //#endregion
26117
26913
  //#region src/primitives/icon-button.tsx
26118
26914
  var iconButtonVariants = cva("inline-flex items-center justify-center rounded-md font-medium transition-colors cursor-pointer disabled:opacity-50 disabled:pointer-events-none", {
26119
26915
  variants: {
@@ -26148,55 +26944,6 @@ var IconButton = (0, react$1.forwardRef)(({ className, variant, size, icon: Icon
26148
26944
  });
26149
26945
  IconButton.displayName = "IconButton";
26150
26946
  //#endregion
26151
- //#region src/primitives/badge.tsx
26152
- var badgeVariants = cva("inline-flex items-center rounded-full text-xs font-medium px-2 py-0.5", {
26153
- variants: {
26154
- variant: {
26155
- default: "bg-surface-hover text-foreground",
26156
- success: "bg-success/15 text-success",
26157
- warning: "bg-warning/15 text-warning",
26158
- danger: "bg-danger/15 text-danger",
26159
- info: "bg-info/15 text-info"
26160
- },
26161
- styleVariant: {
26162
- solid: "",
26163
- outline: "border bg-transparent"
26164
- }
26165
- },
26166
- defaultVariants: {
26167
- variant: "default",
26168
- styleVariant: "solid"
26169
- }
26170
- });
26171
- var Badge = (0, react$1.forwardRef)(({ className, variant, style, ...props }, ref) => {
26172
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
26173
- ref,
26174
- className: cn(badgeVariants({
26175
- variant,
26176
- styleVariant: style
26177
- }), className),
26178
- ...props
26179
- });
26180
- });
26181
- Badge.displayName = "Badge";
26182
- //#endregion
26183
- //#region src/primitives/card.tsx
26184
- var cardVariants = cva("rounded-lg p-3", {
26185
- variants: { variant: {
26186
- flat: "bg-surface",
26187
- bordered: "bg-surface border border-border"
26188
- } },
26189
- defaultVariants: { variant: "bordered" }
26190
- });
26191
- var Card = (0, react$1.forwardRef)(({ className, variant, ...props }, ref) => {
26192
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
26193
- ref,
26194
- className: cn(cardVariants({ variant }), className),
26195
- ...props
26196
- });
26197
- });
26198
- Card.displayName = "Card";
26199
- //#endregion
26200
26947
  //#region src/primitives/label.tsx
26201
26948
  var Label = (0, react$1.forwardRef)(({ className, ...props }, ref) => {
26202
26949
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("label", {
@@ -26225,16 +26972,6 @@ var Separator = (0, react$1.forwardRef)(({ className, orientation, ...props }, r
26225
26972
  });
26226
26973
  Separator.displayName = "Separator";
26227
26974
  //#endregion
26228
- //#region src/primitives/skeleton.tsx
26229
- var Skeleton = (0, react$1.forwardRef)(({ className, ...props }, ref) => {
26230
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
26231
- ref,
26232
- className: cn("animate-pulse bg-surface-hover rounded-md h-4 w-full", className),
26233
- ...props
26234
- });
26235
- });
26236
- Skeleton.displayName = "Skeleton";
26237
- //#endregion
26238
26975
  //#region src/primitives/input.tsx
26239
26976
  /**
26240
26977
  * `disabled:opacity-50 disabled:cursor-not-allowed` for the same reason as
@@ -26276,43 +27013,6 @@ var Input = (0, react$1.forwardRef)(({ className, state, leftSlot, rightSlot, ..
26276
27013
  });
26277
27014
  Input.displayName = "Input";
26278
27015
  //#endregion
26279
- //#region src/primitives/select.tsx
26280
- /**
26281
- * A native `<select>` styled to match the rest of the field set.
26282
- *
26283
- * `appearance-none` plus an explicit `bg-surface` / `text-foreground` is what
26284
- * makes it match — and it is also what USED to make a disabled one a lie. A
26285
- * browser greys a disabled control by rendering its own background and text
26286
- * colour; all three of those are overridden here, so a `disabled` dropdown
26287
- * looked exactly like a live one and simply ignored the click. That is the
26288
- * whole of the "the language selector does not open" report of 2026-08-15:
26289
- * the AI section's switch was off, every control under it was correctly inert,
26290
- * and nothing on screen said so.
26291
- *
26292
- * `disabled:` classes belong HERE and not on each call site: there are dozens
26293
- * of `<Select disabled>` in this app and the one that gets forgotten is the one
26294
- * that generates the ticket. Guarded by `disabled-affordance.test.tsx`.
26295
- */
26296
- var Select = (0, react$1.forwardRef)(({ className, options, disabled, ...props }, ref) => {
26297
- return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
26298
- className: "relative w-full",
26299
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("select", {
26300
- ref,
26301
- disabled,
26302
- className: cn("h-7 w-full px-2.5 text-xs bg-surface border border-border rounded-md text-foreground appearance-none pr-7 focus:outline-none focus:ring-1 focus:ring-primary", "disabled:opacity-50 disabled:cursor-not-allowed", className),
26303
- ...props,
26304
- children: options.map((option) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
26305
- value: option.value,
26306
- children: option.label
26307
- }, option.value))
26308
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
26309
- className: cn("absolute right-2 top-1/2 -translate-y-1/2 pointer-events-none text-foreground-muted", disabled === true ? "opacity-50" : ""),
26310
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ChevronDown, { className: "h-3.5 w-3.5" })
26311
- })]
26312
- });
26313
- });
26314
- Select.displayName = "Select";
26315
- //#endregion
26316
27016
  //#region src/primitives/checkbox.tsx
26317
27017
  var Checkbox = (0, react$1.forwardRef)(({ className, ...props }, ref) => {
26318
27018
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
@@ -26601,53 +27301,6 @@ function TooltipContent({ className, children, ...props }) {
26601
27301
  });
26602
27302
  }
26603
27303
  //#endregion
26604
- //#region src/hooks/use-is-mobile.ts
26605
- var MOBILE_QUERY = "(max-width: 767px)";
26606
- /**
26607
- * Mid breakpoint — below this width the sidebar collapses to an
26608
- * icons-only rail to reclaim canvas space. Above it (and outside
26609
- * mobile) the full sidebar renders. Threshold matches Tailwind `lg`
26610
- * so sidebar fans out at the same point grids switch to multi-column.
26611
- */
26612
- var MID_QUERY = "(min-width: 768px) and (max-width: 1023px)";
26613
- /**
26614
- * `matchMedia` is universal in browsers but absent in bare DOM environments.
26615
- * These hooks are called from shared primitives (`DataTable` picks its narrow
26616
- * layout with one), so throwing here takes down the whole page that merely
26617
- * rendered a table. Where the capability is missing, report the desktop
26618
- * layout — a widescreen rendering is wrong-looking; a crashed page is gone.
26619
- */
26620
- function matchQuery(query) {
26621
- if (typeof window.matchMedia !== "function") return null;
26622
- return window.matchMedia(query);
26623
- }
26624
- function subscribeQuery(query) {
26625
- return (callback) => {
26626
- const mql = matchQuery(query);
26627
- if (mql === null) return () => {};
26628
- mql.addEventListener("change", callback);
26629
- return () => mql.removeEventListener("change", callback);
26630
- };
26631
- }
26632
- function getSnapshot(query) {
26633
- return () => matchQuery(query)?.matches ?? false;
26634
- }
26635
- function getServerSnapshot() {
26636
- return false;
26637
- }
26638
- function useIsMobile() {
26639
- return (0, react$1.useSyncExternalStore)(subscribeQuery(MOBILE_QUERY), getSnapshot(MOBILE_QUERY), getServerSnapshot);
26640
- }
26641
- /**
26642
- * True when the viewport is in the medium (`md`) Tailwind range —
26643
- * 768px ≤ width < 1024px. Use to drive layouts that should pack denser
26644
- * than full-desktop but more legibly than mobile (e.g. icons-only
26645
- * sidebar rail, narrower stat tiles).
26646
- */
26647
- function useIsMidWidth() {
26648
- return (0, react$1.useSyncExternalStore)(subscribeQuery(MID_QUERY), getSnapshot(MID_QUERY), getServerSnapshot);
26649
- }
26650
- //#endregion
26651
27304
  //#region src/primitives/bottom-sheet.tsx
26652
27305
  function BottomSheet({ open, onClose, title, children, className }) {
26653
27306
  (0, react$1.useEffect)(() => {
@@ -29855,650 +30508,230 @@ function coverageLine(monitor) {
29855
30508
  const extra = [...covered].filter((c) => !SCENE_CAPTURE_VARIANTS.some((v) => v === c));
29856
30509
  for (const c of extra) parts.push(`${variantLabel(c)} ✓`);
29857
30510
  const missing = SCENE_CAPTURE_VARIANTS.filter((v) => !covered.has(v));
29858
- if (missing.length === 0) return parts.join(" · ");
29859
- if (covered.size === 0) return `${parts.join(" · ")} — nothing captured yet, so this scene is not watching.`;
29860
- const names = missing.map((v) => variantLabel(v).toLowerCase()).join(" and ");
29861
- return monitor.onUncoveredCondition === "judge-anyway" ? `${parts.join(" · ")} — ${names} judged against the references you do have.` : `${parts.join(" · ")} — optional; checks in ${names} are skipped.`;
29862
- }
29863
- /**
29864
- * The calm sentence for a scene that is sitting the current light out — `null`
29865
- * whenever it is checking normally.
29866
- *
29867
- * Separate from {@link statusLine} because it is not a verdict and must not
29868
- * read like one. A paused scene has not failed, has not lost its flag, and
29869
- * needs nothing from the operator; the only thing worth saying is which light
29870
- * it is waiting out and that it will pick itself back up.
29871
- */
29872
- function suspensionLine(monitor) {
29873
- if (monitor.suspendedCondition === null) return null;
29874
- const light = variantLabel(monitor.suspendedCondition).toLowerCase();
29875
- return `Paused — nothing was captured in ${light}, so checks are on hold until the light changes back. Capture ${light} if you want it watched around the clock.`;
29876
- }
29877
- var UNAVAILABLE_SENTENCE = {
29878
- "no-reference-for-condition": "can’t tell — nothing has been captured for this scene yet. Press “Capture daylight” to photograph what normal looks like.",
29879
- "view-shifted": "can’t tell — the camera view has moved since the reference was captured. Re-capture it.",
29880
- "no-vision-profile": "can’t tell — the vision model is unreachable, so the change is on hold.",
29881
- "encoder-model-changed": "can’t tell — the embedding model changed, so the stored references are unreadable. Re-capture them.",
29882
- "no-snapshot": "can’t tell — this camera did not return a frame."
29883
- };
29884
- /**
29885
- * The one line under a scene's name. It answers, in order: can it judge, what
29886
- * does it say, and how long has it said it.
29887
- */
29888
- function statusLine(monitor, now) {
29889
- if (monitor.states.length === 0) return "Not armed yet — capture the initial state to start watching.";
29890
- if (monitor.verdict === "unknown") return monitor.unavailable !== null ? UNAVAILABLE_SENTENCE[monitor.unavailable] : "can’t tell right now.";
29891
- const since = monitor.verdict === "diverged" ? monitor.divergedAt : monitor.armedAt;
29892
- const held = since !== null ? ` for ${humanDuration(Math.max(0, now - since))}` : "";
29893
- if (monitor.latched) return monitor.verdict === "diverged" ? `CHANGED${held} — press Reset when you have dealt with it.` : `Back to normal, but still flagged as changed${held}. Press Reset to clear it.`;
29894
- const paused = suspensionLine(monitor);
29895
- if (paused !== null) return paused;
29896
- return monitor.verdict === "diverged" ? `CHANGED${held}` : `Normal${held}`;
29897
- }
29898
- /** The badge word. `latched` wins over `verdict`, because the latch is the
29899
- * thing the operator asked to be told and it outlives the live state.
29900
- *
29901
- * A scene sitting out an uncovered light reads `Paused`, in the NEUTRAL tone —
29902
- * never `alarm`, and never the `danger` variant the page maps that to. A
29903
- * missing IR reference must not be able to paint a red badge on a scene that
29904
- * is doing exactly what it was configured to do. */
29905
- function badgeFor(monitor) {
29906
- if (monitor.states.length === 0) return {
29907
- text: "Not armed",
29908
- tone: "unknown"
29909
- };
29910
- if (monitor.latched) return {
29911
- text: "Changed",
29912
- tone: "alarm"
29913
- };
29914
- if (monitor.suspendedCondition !== null) return {
29915
- text: "Paused",
29916
- tone: "unknown"
29917
- };
29918
- if (monitor.verdict === "unknown") return {
29919
- text: "Can’t tell",
29920
- tone: "unknown"
29921
- };
29922
- return monitor.verdict === "diverged" ? {
29923
- text: "Changed",
29924
- tone: "alarm"
29925
- } : {
29926
- text: "Normal",
29927
- tone: "ok"
29928
- };
29929
- }
29930
- /** A rect covering most of the frame is dominated by weather, sky and parked
29931
- * cars: the bin is 2 % of the pixels and CLIP will not notice it leaving. The
29932
- * failure is silent INSENSITIVITY, which is the worst kind — hence a warning
29933
- * rather than a refusal. */
29934
- var ROI_AREA_WARN_FRACTION = .4;
29935
- function roiTooLarge(roi) {
29936
- return roi.width * roi.height > ROI_AREA_WARN_FRACTION;
29937
- }
29938
- function humanDuration(ms) {
29939
- const s = Math.floor(ms / 1e3);
29940
- if (s < 60) return `${s}s`;
29941
- const m = Math.floor(s / 60);
29942
- if (m < 60) return `${m}m`;
29943
- const h = Math.floor(m / 60);
29944
- if (h < 48) return `${h}h`;
29945
- return `${Math.floor(h / 24)}d`;
29946
- }
29947
- //#endregion
29948
- //#region src/composites/code-block.tsx
29949
- function CodeBlock({ children, maxHeight = 300, className }) {
29950
- const [copied, setCopied] = (0, react$1.useState)(false);
29951
- const handleCopy = (0, react$1.useCallback)(() => {
29952
- navigator.clipboard.writeText(children).then(() => {
29953
- setCopied(true);
29954
- setTimeout(() => setCopied(false), 2e3);
29955
- });
29956
- }, [children]);
29957
- return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
29958
- className: cn("relative group", className),
29959
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(ScrollArea, {
29960
- style: { maxHeight },
29961
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("pre", {
29962
- className: "font-mono text-xs bg-surface p-3 rounded-md border border-border-subtle",
29963
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("code", { children })
29964
- })
29965
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
29966
- className: "absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity",
29967
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(IconButton, {
29968
- icon: copied ? Check : Copy,
29969
- "aria-label": "Copy code",
29970
- variant: "ghost",
29971
- size: "sm",
29972
- onClick: handleCopy
29973
- })
29974
- })]
29975
- });
29976
- }
29977
- //#endregion
29978
- //#region src/composites/confirm-action-button.tsx
29979
- /**
29980
- * ConfirmActionButton — destructive-action button with a modal confirm.
29981
- *
29982
- * Two-step UX for any operation operators shouldn't trigger by accident:
29983
- * reboot device, restart addon, regenerate token, etc. The trigger is a
29984
- * normal Button that opens a Dialog; confirming runs the async action,
29985
- * the trigger spinner-disables itself for the duration, and the dialog
29986
- * closes on success. Errors surface inline at the dialog's bottom.
29987
- *
29988
- * Generic on `TResult` so callers don't have to discard the return
29989
- * value. Pass an `icon` to render it inside the trigger (e.g. RotateCw
29990
- * for reboot, RefreshCw for restart).
29991
- */
29992
- function ConfirmActionButton({ label, icon: Icon, title = "Confirm action", description, confirmLabel, triggerVariant = "outline", confirmVariant = "danger", size = "sm", disabled, className, action, onSuccess }) {
29993
- const [open, setOpen] = (0, react$1.useState)(false);
29994
- const [running, setRunning] = (0, react$1.useState)(false);
29995
- const [error, setError] = (0, react$1.useState)(null);
29996
- const handleConfirm = async () => {
29997
- setError(null);
29998
- setRunning(true);
29999
- try {
30000
- const result = await action();
30001
- onSuccess?.(result);
30002
- setOpen(false);
30003
- } catch (err) {
30004
- setError(err instanceof Error ? err.message : String(err));
30005
- } finally {
30006
- setRunning(false);
30007
- }
30008
- };
30009
- return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(Button, {
30010
- type: "button",
30011
- variant: triggerVariant,
30012
- size,
30013
- disabled,
30014
- onClick: () => {
30015
- setError(null);
30016
- setOpen(true);
30017
- },
30018
- className,
30019
- children: [Icon && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Icon, { className: "h-3.5 w-3.5" }), label]
30020
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Dialog, {
30021
- open,
30022
- onOpenChange: (next) => !running && setOpen(next),
30023
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(DialogContent, { children: [
30024
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(DialogHeader, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(DialogTitle, {
30025
- className: "flex items-center gap-2",
30026
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(TriangleAlert, { className: "h-4 w-4 text-amber-400" }), title]
30027
- }), typeof description === "string" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DialogDescription, { children: description }) : description] }),
30028
- error && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
30029
- className: cn("mt-2 px-3 py-2 rounded border border-danger/40 bg-danger/10", "text-xs text-danger"),
30030
- children: error
30031
- }),
30032
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(DialogFooter, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(Button, {
30033
- type: "button",
30034
- variant: "ghost",
30035
- size,
30036
- disabled: running,
30037
- onClick: () => setOpen(false),
30038
- children: "Cancel"
30039
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(Button, {
30040
- type: "button",
30041
- variant: confirmVariant,
30042
- size,
30043
- disabled: running,
30044
- onClick: () => {
30045
- handleConfirm();
30046
- },
30047
- children: [running && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LoaderCircle, { className: "h-3.5 w-3.5 animate-spin" }), confirmLabel ?? label]
30048
- })] })
30049
- ] })
30050
- })] });
30051
- }
30052
- //#endregion
30053
- //#region src/composites/copy-button.tsx
30054
- /**
30055
- * `CopyButton` — a compact button that copies a string `value` to the
30056
- * clipboard via `navigator.clipboard.writeText`, showing a brief
30057
- * "copied" check state. Addon-agnostic; used wherever a secret / URL
30058
- * needs a one-click copy affordance (export setup panels, etc.).
30059
- */
30060
- var COPIED_RESET_MS = 2e3;
30061
- function CopyButton({ value, label, srLabel, className, disabled }) {
30062
- const [copied, setCopied] = (0, react$1.useState)(false);
30063
- const handleCopy = (0, react$1.useCallback)(() => {
30064
- if (!value) return;
30065
- navigator.clipboard.writeText(value).then(() => {
30066
- setCopied(true);
30067
- setTimeout(() => setCopied(false), COPIED_RESET_MS);
30068
- });
30069
- }, [value]);
30070
- return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(Button, {
30071
- size: "sm",
30072
- variant: "ghost",
30073
- type: "button",
30074
- disabled: disabled || value.length === 0,
30075
- onClick: handleCopy,
30076
- className: cn(className),
30077
- "aria-label": copied ? "Copied" : `Copy ${srLabel ?? label ?? "value"}`,
30078
- children: [copied ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Check, { className: "h-3.5 w-3.5 text-success" }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Copy, { className: "h-3.5 w-3.5" }), label ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
30079
- className: "ml-1",
30080
- children: copied ? "Copied" : label
30081
- }) : null]
30082
- });
30083
- }
30084
- //#endregion
30085
- //#region src/composites/data-table-layout.ts
30086
- /**
30087
- * At this many columns and above, `auto` switches a narrow viewport to cards.
30088
- * Three columns still fit a phone at a readable size; four do not.
30089
- */
30090
- var CARD_MODE_MIN_COLUMNS = 4;
30091
- function resolveTableLayout({ mode, columnCount, isNarrow }) {
30092
- if (!isNarrow) return "table";
30093
- if (mode === "scroll") return "table";
30094
- if (mode === "cards") return "cards";
30095
- if (columnCount === 0) return "table";
30096
- return columnCount >= 4 ? "cards" : "table";
30097
- }
30098
- //#endregion
30099
- //#region src/lib/responsive.ts
30100
- /**
30101
- * Responsive design tokens — three-tier system.
30102
- *
30103
- * The admin-ui targets three width tiers; every component should pick
30104
- * the right token from this file instead of hand-coding breakpoints.
30105
- * Adopting the tokens uniformly is what makes the app feel consistent
30106
- * across operator devices (mobile / tablet / desktop) and what unlocks
30107
- * targeted tuning (e.g. shrink every label by 1px in one place).
30108
- *
30109
- * Tier definitions (Tailwind breakpoints):
30110
- *
30111
- * • **L1 — Compact** (`< 640px`, default = mobile portrait)
30112
- * Single column, tight padding, smallest text, icon-only buttons
30113
- * where labels can be inferred. The operator can still see every
30114
- * stat / action — no horizontal scroll, no clipped text. The user
30115
- * directive: "molta informazione in poco spazio quando la width è
30116
- * bassa."
30117
- *
30118
- * • **L2 — Standard** (`sm` — `640–1023px`, tablet + small laptop)
30119
- * 2-column grids, side panels become visible, button labels return.
30120
- * Targets ~768px–1024px viewports — the most common operator sizes.
30121
- *
30122
- * • **L3 — Spacious** (`lg+` — `≥ 1024px`, desktop)
30123
- * 4-column grids, generous padding, full-width header text,
30124
- * side-by-side composite layouts. The operator has elbow room.
30125
- *
30126
- * Conventions:
30127
- * - **Always start from L1** — the bare class is always the compact
30128
- * variant, then `sm:` adds room at 640px, `lg:` at 1024px. No
30129
- * desktop-first breakpoints; no max-width queries.
30130
- * - **Token strings are static** — kept as `as const` so callers can
30131
- * compose them via `cn()` / template literals without running a
30132
- * class generator at runtime.
30133
- * - **Pair the token with a comment** — the comment in the file
30134
- * names every breakpoint it crosses, so a reader can predict the
30135
- * layout without going to Tailwind docs.
30136
- */
30137
- /** Container padding for a card-style section (header + body). */
30138
- var SECTION_CARD = "rounded-lg border border-border bg-surface overflow-hidden";
30139
- /** Header strip inside a card (between border-b lines). */
30140
- var SECTION_HEADER = "border-b border-border px-3 sm:px-4 py-1.5 sm:py-2";
30141
- /** Body padding for a card-style section. */
30142
- var SECTION_BODY = "p-2 sm:p-3 lg:p-4";
30143
- /** Gap between cards in a vertical stack. */
30144
- var STACK_GAP = "space-y-3 sm:space-y-4";
30145
- /** Gap between cards in a grid (4 cells / row at lg). */
30146
- var GRID_GAP = "gap-2 sm:gap-3";
30147
- /** Row padding inside a divided list (e.g. InfoRow). */
30148
- var LIST_ROW = "px-3 sm:px-4 py-1.5 sm:py-2";
30149
- /** 1-up at L1, 2-up at L2, 4-up at L3 — quick-stat row. */
30150
- var GRID_QUICK_STATS = "grid grid-cols-2 sm:grid-cols-2 lg:grid-cols-4";
30151
- /** 1-up at L1, 2-up at L2+ — paired panels (motion + detection rules). */
30152
- var GRID_PAIRED = "grid grid-cols-1 lg:grid-cols-2";
30153
- /** Side-by-side layout that stacks below md (canvas + side panel). */
30154
- var SPLIT_PANEL_OUTER = "flex flex-col-reverse md:flex-row";
30155
- /** Sidebar narrow lane in a SPLIT_PANEL_OUTER layout. */
30156
- var SPLIT_PANEL_SIDE = "w-full md:w-44 lg:w-52 md:flex-shrink-0 border-b md:border-b-0 md:border-l border-border";
30157
- /**
30158
- * The tier boundary at which a settings label/value row stops stacking.
30159
- *
30160
- * Below it (L1 — compact) the row is ONE column: label on its own line, value
30161
- * on the next at full width. Above it the row is label-left / value-right as
30162
- * before. The two-column form needs `SETTING_ROW_LABEL`'s lane plus a readable
30163
- * value beside it; a phone has neither, and the failure mode is not "cramped"
30164
- * but "the value is the part that gets cut" — the one thing the operator
30165
- * opened the page to read.
30166
- */
30167
- var SETTING_ROW_STACK_BREAKPOINT = "sm";
30168
- /** Outer row: single column at L1, label/value columns from `sm` up. */
30169
- var SETTING_ROW = "flex min-w-0 flex-col gap-0.5 py-1.5 sm:flex-row sm:items-center";
30170
- /** Label lane. Full width (and free to wrap) at L1; a fixed lane from `sm` up. */
30171
- var SETTING_ROW_LABEL = "min-w-0 text-[11px] leading-tight text-foreground-subtle sm:w-32 sm:shrink-0 sm:pr-2";
30172
- /**
30173
- * Value lane — the value text plus its trailing affordances (copy / reveal).
30174
- * `w-full` at L1 so the value owns the whole row once the label is above it;
30175
- * `sm:flex-1` makes it share the row again from `sm` up.
30176
- */
30177
- var SETTING_ROW_VALUE = "flex w-full min-w-0 items-center gap-1 sm:flex-1";
30178
- /**
30179
- * The value text itself. `break-all` lets an opaque token (a key, a URL) wrap
30180
- * at L1 instead of being cut mid-word; `sm:truncate` restores the single-line
30181
- * desktop form, where the row is wide enough for truncation to be a choice
30182
- * rather than data loss.
30183
- */
30184
- var SETTING_ROW_VALUE_TEXT = "min-w-0 break-all text-xs text-foreground sm:truncate";
30185
- /** Section header label (uppercase tracking-wider). */
30186
- var TEXT_SECTION_LABEL = "text-[10px] sm:text-[11px] font-semibold text-foreground uppercase tracking-wider";
30187
- /** Field label inside a row. */
30188
- var TEXT_FIELD_LABEL = "text-[11px] sm:text-xs text-foreground";
30189
- /** Sub-label / hint text. */
30190
- var TEXT_HINT = "text-[10px] text-foreground-subtle";
30191
- /** Primary value (a metric, badge, …). */
30192
- var TEXT_VALUE = "text-[11px] sm:text-xs font-medium text-foreground";
30193
- /** Big metric value (StatCard). */
30194
- var TEXT_METRIC = "text-base sm:text-lg font-semibold leading-tight text-foreground";
30195
- /** Default compact button. */
30196
- var BTN_COMPACT = "inline-flex items-center justify-center gap-1 rounded border border-border bg-surface px-1.5 py-0.5 sm:px-2 sm:py-1 text-[10px] sm:text-[11px] font-medium text-foreground hover:bg-surface-hover transition-colors disabled:opacity-40";
30197
- /** Primary compact button. */
30198
- var BTN_COMPACT_PRIMARY = "inline-flex items-center justify-center gap-1 rounded border border-primary/40 bg-primary/15 px-1.5 py-0.5 sm:px-2 sm:py-1 text-[10px] sm:text-[11px] font-medium text-primary hover:bg-primary/25 transition-colors disabled:opacity-40";
30199
- /** Danger compact button. */
30200
- var BTN_COMPACT_DANGER = "inline-flex items-center justify-center gap-1 rounded border border-danger/40 bg-danger/10 px-1.5 py-0.5 sm:px-2 sm:py-1 text-[10px] sm:text-[11px] font-medium text-danger hover:bg-danger/20 transition-colors disabled:opacity-40";
30201
- /** Warning compact button (e.g. cancel-drawing). */
30202
- var BTN_COMPACT_WARNING = "inline-flex items-center justify-center gap-1 rounded border border-warning/40 bg-warning/10 px-1.5 py-0.5 sm:px-2 sm:py-1 text-[10px] sm:text-[11px] font-medium text-warning hover:bg-warning/20 transition-colors disabled:opacity-40";
30203
- /** Compact text/select/number input. */
30204
- var INPUT_COMPACT = "w-full rounded border border-border bg-background px-1.5 py-0.5 sm:px-2 sm:py-1 text-[11px] sm:text-xs text-foreground focus:border-primary focus:ring-1 focus:ring-primary/30 outline-none";
30205
- /** Chip-style toggle (zone / class selectors in ZoneRulesEditor). */
30206
- var CHIP_BASE = "inline-flex items-center gap-1 rounded-full border px-1.5 py-0.5 text-[10px] font-medium transition-colors";
30207
- var CHIP_ACTIVE = "border-primary/50 bg-primary/15 text-primary";
30208
- var CHIP_INACTIVE = "border-border bg-surface text-foreground-subtle hover:bg-surface-hover";
30209
- //#endregion
30210
- //#region src/composites/setting-row.tsx
30211
- function SettingRow({ label, children, actions, elements = "plain", className, valueClassName }) {
30212
- const LabelTag = elements === "description" ? "dt" : "span";
30213
- const ValueTag = elements === "description" ? "dd" : "div";
30214
- return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
30215
- "data-setting-row": "",
30216
- className: cn(SETTING_ROW, className),
30217
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(LabelTag, {
30218
- "data-setting-row-label": "",
30219
- className: SETTING_ROW_LABEL,
30220
- children: label
30221
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(ValueTag, {
30222
- "data-setting-row-value": "",
30223
- className: SETTING_ROW_VALUE,
30224
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
30225
- "data-setting-row-value-text": "",
30226
- className: cn(SETTING_ROW_VALUE_TEXT, valueClassName),
30227
- children
30228
- }), actions !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
30229
- className: "flex shrink-0 items-center gap-0.5",
30230
- children: actions
30231
- })]
30232
- })]
30233
- });
30234
- }
30235
- //#endregion
30236
- //#region src/composites/sort-header-button.tsx
30237
- function SortHeaderButton({ label, active, dir, onSort }) {
30238
- return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
30239
- type: "button",
30240
- onClick: onSort,
30241
- className: "group/sort inline-flex items-center gap-0.5 hover:text-foreground transition-colors",
30242
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: label }), active ? dir === "asc" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ChevronUp, { className: "h-3 w-3 flex-shrink-0" }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ChevronDown, { className: "h-3 w-3 flex-shrink-0" }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ChevronUp, { className: cn("h-3 w-3 flex-shrink-0 opacity-0 transition-opacity", "group-hover/sort:opacity-30") })]
30243
- });
30244
- }
30245
- //#endregion
30246
- //#region src/composites/table-sort.ts
30247
- /**
30248
- * The toggle rule, and the only copy of it.
30249
- *
30250
- * none → asc → desc → none, and a click on a DIFFERENT column starts that
30251
- * column fresh at `asc`. `sameColumn` says whether the clicked column is the
30252
- * one currently sorted; `currentDir` is its direction (`null` when nothing is
30253
- * sorted). Returns the next direction, or `null` for "unsorted".
30254
- *
30255
- * Split out from {@link nextTableSort} so the device list — whose sort state
30256
- * keys columns by `columnId`, not `columnKey` — can reuse the rule without a
30257
- * cast and without a second copy of it.
30258
- */
30259
- function nextSortDirection(sameColumn, currentDir) {
30260
- if (!sameColumn || currentDir === null) return "asc";
30261
- return currentDir === "asc" ? "desc" : null;
30262
- }
30263
- /**
30264
- * Toggle a column's sort on header click: none → asc → desc → none.
30265
- * Clicking a DIFFERENT column starts it fresh at `asc`.
30266
- */
30267
- function nextTableSort(current, columnKey) {
30268
- const dir = nextSortDirection(current !== null && current.columnKey === columnKey, current === null ? null : current.dir);
30269
- return dir === null ? null : {
30270
- columnKey,
30271
- dir
30272
- };
30511
+ if (missing.length === 0) return parts.join(" · ");
30512
+ if (covered.size === 0) return `${parts.join(" · ")} — nothing captured yet, so this scene is not watching.`;
30513
+ const names = missing.map((v) => variantLabel(v).toLowerCase()).join(" and ");
30514
+ return monitor.onUncoveredCondition === "judge-anyway" ? `${parts.join(" · ")} — ${names} judged against the references you do have.` : `${parts.join(" · ")} — optional; checks in ${names} are skipped.`;
30273
30515
  }
30274
30516
  /**
30275
- * Ascending comparison of two cell values.
30276
- *
30277
- * Numbers compare numerically and strings compare with `localeCompare` — a
30278
- * numeric column must never be ordered as text ("100" before "9"), and a text
30279
- * column must respect the locale's collation. A mixed column (one row a
30280
- * number, another a string) falls back to string comparison of both, which is
30281
- * the only total order available; it is not a shape any caller should build on
30282
- * purpose.
30517
+ * The calm sentence for a scene that is sitting the current light out — `null`
30518
+ * whenever it is checking normally.
30283
30519
  *
30284
- * `null` is NOT handled here — {@link sortRowsByColumn} pulls it out first,
30285
- * because its placement is direction-independent and a comparator that is
30286
- * multiplied by the direction factor cannot express that.
30520
+ * Separate from {@link statusLine} because it is not a verdict and must not
30521
+ * read like one. A paused scene has not failed, has not lost its flag, and
30522
+ * needs nothing from the operator; the only thing worth saying is which light
30523
+ * it is waiting out and that it will pick itself back up.
30287
30524
  */
30288
- function compareValues(a, b) {
30289
- if (typeof a === "number" && typeof b === "number") return a - b;
30290
- return String(a).localeCompare(String(b));
30525
+ function suspensionLine(monitor) {
30526
+ if (monitor.suspendedCondition === null) return null;
30527
+ const light = variantLabel(monitor.suspendedCondition).toLowerCase();
30528
+ return `Paused — nothing was captured in ${light}, so checks are on hold until the light changes back. Capture ${light} if you want it watched around the clock.`;
30291
30529
  }
30530
+ var UNAVAILABLE_SENTENCE = {
30531
+ "no-reference-for-condition": "can’t tell — nothing has been captured for this scene yet. Press “Capture daylight” to photograph what normal looks like.",
30532
+ "view-shifted": "can’t tell — the camera view has moved since the reference was captured. Re-capture it.",
30533
+ "no-vision-profile": "can’t tell — the vision model is unreachable, so the change is on hold.",
30534
+ "encoder-model-changed": "can’t tell — the embedding model changed, so the stored references are unreadable. Re-capture them.",
30535
+ "no-snapshot": "can’t tell — this camera did not return a frame."
30536
+ };
30292
30537
  /**
30293
- * Return a NEW array of `rows` ordered by `sort`.
30294
- *
30295
- * `valueOf` is the column's `sortValue` — it is called once per row per
30296
- * comparison, so it must be cheap (read a field, do not format a string).
30297
- * `sort === null` ⇒ a fresh shallow copy in the incoming order.
30538
+ * The one line under a scene's name. It answers, in order: can it judge, what
30539
+ * does it say, and how long has it said it.
30298
30540
  */
30299
- function sortRowsByColumn(rows, sort, valueOf) {
30300
- if (sort === null) return [...rows];
30301
- const factor = sort.dir === "asc" ? 1 : -1;
30302
- return rows.toSorted((a, b) => {
30303
- const av = valueOf(a);
30304
- const bv = valueOf(b);
30305
- if (av === null || bv === null) {
30306
- if (av === bv) return 0;
30307
- return av === null ? 1 : -1;
30308
- }
30309
- return factor * compareValues(av, bv);
30310
- });
30541
+ function statusLine(monitor, now) {
30542
+ if (monitor.states.length === 0) return "Not armed yet — capture the initial state to start watching.";
30543
+ if (monitor.verdict === "unknown") return monitor.unavailable !== null ? UNAVAILABLE_SENTENCE[monitor.unavailable] : "can’t tell right now.";
30544
+ const since = monitor.verdict === "diverged" ? monitor.divergedAt : monitor.armedAt;
30545
+ const held = since !== null ? ` for ${humanDuration(Math.max(0, now - since))}` : "";
30546
+ if (monitor.latched) return monitor.verdict === "diverged" ? `CHANGED${held} — press Reset when you have dealt with it.` : `Back to normal, but still flagged as changed${held}. Press Reset to clear it.`;
30547
+ const paused = suspensionLine(monitor);
30548
+ if (paused !== null) return paused;
30549
+ return monitor.verdict === "diverged" ? `CHANGED${held}` : `Normal${held}`;
30311
30550
  }
30312
- /** Derive the `<th>` `aria-sort` for `columnKey` from the table's sort state. */
30313
- function ariaSortForColumn(sort, columnKey) {
30314
- if (sort === null || sort.columnKey !== columnKey) return "none";
30315
- return sort.dir === "asc" ? "ascending" : "descending";
30551
+ /** The badge word. `latched` wins over `verdict`, because the latch is the
30552
+ * thing the operator asked to be told and it outlives the live state.
30553
+ *
30554
+ * A scene sitting out an uncovered light reads `Paused`, in the NEUTRAL tone —
30555
+ * never `alarm`, and never the `danger` variant the page maps that to. A
30556
+ * missing IR reference must not be able to paint a red badge on a scene that
30557
+ * is doing exactly what it was configured to do. */
30558
+ function badgeFor(monitor) {
30559
+ if (monitor.states.length === 0) return {
30560
+ text: "Not armed",
30561
+ tone: "unknown"
30562
+ };
30563
+ if (monitor.latched) return {
30564
+ text: "Changed",
30565
+ tone: "alarm"
30566
+ };
30567
+ if (monitor.suspendedCondition !== null) return {
30568
+ text: "Paused",
30569
+ tone: "unknown"
30570
+ };
30571
+ if (monitor.verdict === "unknown") return {
30572
+ text: "Can’t tell",
30573
+ tone: "unknown"
30574
+ };
30575
+ return monitor.verdict === "diverged" ? {
30576
+ text: "Changed",
30577
+ tone: "alarm"
30578
+ } : {
30579
+ text: "Normal",
30580
+ tone: "ok"
30581
+ };
30582
+ }
30583
+ /** A rect covering most of the frame is dominated by weather, sky and parked
30584
+ * cars: the bin is 2 % of the pixels and CLIP will not notice it leaving. The
30585
+ * failure is silent INSENSITIVITY, which is the worst kind — hence a warning
30586
+ * rather than a refusal. */
30587
+ var ROI_AREA_WARN_FRACTION = .4;
30588
+ function roiTooLarge(roi) {
30589
+ return roi.width * roi.height > ROI_AREA_WARN_FRACTION;
30590
+ }
30591
+ function humanDuration(ms) {
30592
+ const s = Math.floor(ms / 1e3);
30593
+ if (s < 60) return `${s}s`;
30594
+ const m = Math.floor(s / 60);
30595
+ if (m < 60) return `${m}m`;
30596
+ const h = Math.floor(m / 60);
30597
+ if (h < 48) return `${h}h`;
30598
+ return `${Math.floor(h / 24)}d`;
30316
30599
  }
30317
30600
  //#endregion
30318
- //#region src/composites/data-table.tsx
30601
+ //#region src/composites/code-block.tsx
30602
+ function CodeBlock({ children, maxHeight = 300, className }) {
30603
+ const [copied, setCopied] = (0, react$1.useState)(false);
30604
+ const handleCopy = (0, react$1.useCallback)(() => {
30605
+ navigator.clipboard.writeText(children).then(() => {
30606
+ setCopied(true);
30607
+ setTimeout(() => setCopied(false), 2e3);
30608
+ });
30609
+ }, [children]);
30610
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
30611
+ className: cn("relative group", className),
30612
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(ScrollArea, {
30613
+ style: { maxHeight },
30614
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("pre", {
30615
+ className: "font-mono text-xs bg-surface p-3 rounded-md border border-border-subtle",
30616
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("code", { children })
30617
+ })
30618
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
30619
+ className: "absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity",
30620
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(IconButton, {
30621
+ icon: copied ? Check : Copy,
30622
+ "aria-label": "Copy code",
30623
+ variant: "ghost",
30624
+ size: "sm",
30625
+ onClick: handleCopy
30626
+ })
30627
+ })]
30628
+ });
30629
+ }
30630
+ //#endregion
30631
+ //#region src/composites/confirm-action-button.tsx
30319
30632
  /**
30320
- * DataTable — shared responsive table for admin pages.
30321
- *
30322
- * Recipes baked in:
30323
- * - `overflow-x-auto` wrapper so narrow viewports don't clip the
30324
- * right edge (the rounded border survives the scroll).
30325
- * - `min-w-[Npx]` on the inner table so columns don't squash below
30326
- * readable width before the scroll kicks in.
30327
- * - `whitespace-nowrap` on headers — column titles never wrap to
30328
- * two lines (`AUTO-KILL` was the regression that triggered this).
30329
- * - Themed `bg-surface` + `border-border` so contrast works in both
30330
- * light and dark themes.
30331
- *
30332
- * Column model: caller supplies `columns: DataColumn<T>[]` and
30333
- * `rows: T[]`. Each column declares `header`, optional `align`,
30334
- * optional `nowrap`, and a `render(row) => ReactNode` that produces
30335
- * the cell content.
30336
- *
30337
- * <DataTable
30338
- * columns={[
30339
- * { key: 'username', header: 'Username', render: (u) => u.username },
30340
- * { key: 'role', header: 'Role', render: (u) => <RoleBadge .../> },
30341
- * { key: 'actions', header: '', align: 'right', render: (u) => <Actions .../> },
30342
- * ]}
30343
- * rows={users}
30344
- * minWidthPx={560}
30345
- * />
30346
- *
30347
- * If finer header markup is needed, pass `headerRender` instead of
30348
- * `header` (e.g. for a sortable click affordance).
30349
- *
30350
- * ── Narrow viewports ──────────────────────────────────────────────────────
30351
- * The table stays a table. The wrapper is `overflow-x-auto`, so a phone
30352
- * scrolls the columns sideways INSIDE the table — the page body never moves
30353
- * sideways, and the cells stay one line (`whitespace-nowrap`). That is the
30354
- * default (`mobileMode="scroll"`). Cards are opt-in via `mobileMode="cards"`;
30355
- * `auto` still applies the old column-count rule for a surface that wants it.
30356
- * See `resolveTableLayout`.
30357
- *
30358
- * ── Scrolling the BODY, not the page ──────────────────────────────────────
30359
- * `maxBodyHeight` caps the table and scrolls its rows INSIDE the container
30360
- * with the column header pinned. It is ONE prop, not two, because "this list
30361
- * scrolls internally" and "its header stays visible" are the same decision: a
30362
- * capped table whose header scrolls away is a list of unlabelled cells.
30633
+ * ConfirmActionButton — destructive-action button with a modal confirm.
30363
30634
  *
30364
- * Use it wherever the row count is open-ended (rules, targets, delivery
30365
- * history) so the page keeps its own header, filters and actions in view while
30366
- * the operator moves through the rows.
30367
- */
30368
- /**
30369
- * The default cap for an internally-scrolling table.
30635
+ * Two-step UX for any operation operators shouldn't trigger by accident:
30636
+ * reboot device, restart addon, regenerate token, etc. The trigger is a
30637
+ * normal Button that opens a Dialog; confirming runs the async action,
30638
+ * the trigger spinner-disables itself for the duration, and the dialog
30639
+ * closes on success. Errors surface inline at the dialog's bottom.
30370
30640
  *
30371
- * `60vh` leaves the page header, its filters and its actions on screen at
30372
- * every viewport while still showing ~10 rows — and it is a fraction, so it
30373
- * does not need a breakpoint of its own.
30641
+ * Generic on `TResult` so callers don't have to discard the return
30642
+ * value. Pass an `icon` to render it inside the trigger (e.g. RotateCw
30643
+ * for reboot, RefreshCw for restart).
30374
30644
  */
30375
- var TABLE_SCROLL_MAX_H = "max-h-[60vh]";
30376
- var ALIGN_CLASS = {
30377
- left: "text-left",
30378
- right: "text-right",
30379
- center: "text-center"
30380
- };
30381
- function DataTable({ columns, rows, rowKey, onRowClick, minWidthPx = 480, emptyMessage, className, bordered = true, rowClassName, mobileMode = "scroll", maxBodyHeight, defaultSort }) {
30382
- const isNarrow = useIsMobile();
30383
- const [sort, setSort] = (0, react$1.useState)(defaultSort ?? null);
30384
- const layout = resolveTableLayout({
30385
- mode: mobileMode,
30386
- columnCount: columns.length,
30387
- isNarrow
30388
- });
30389
- const scrolls = maxBodyHeight !== void 0;
30390
- const sortedColumn = (0, react$1.useMemo)(() => sort === null ? void 0 : columns.find((col) => col.key === sort.columnKey && col.sortValue !== void 0), [columns, sort]);
30391
- const sortValue = sortedColumn?.sortValue;
30392
- const displayRows = (0, react$1.useMemo)(() => sortValue === void 0 ? rows : sortRowsByColumn(rows, sort, sortValue), [
30393
- rows,
30394
- sort,
30395
- sortValue
30396
- ]);
30397
- const activeSort = sortedColumn === void 0 ? null : sort;
30398
- if (rows.length === 0 && emptyMessage) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
30399
- className: `rounded-lg ${bordered ? "border border-border" : ""} bg-surface px-3 py-4 text-xs text-foreground-subtle text-center ${className ?? ""}`,
30400
- children: emptyMessage
30401
- });
30402
- if (rows.length === 0) return null;
30403
- if (layout === "cards") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
30404
- className: `space-y-2 ${scrolls ? `${maxBodyHeight} overflow-y-auto` : ""} ${className ?? ""}`,
30405
- children: displayRows.map((row, rowIndex) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DataTableCard, {
30406
- row,
30407
- rowIndex,
30408
- columns,
30409
- bordered,
30410
- onRowClick,
30411
- rowClassName
30412
- }, rowKey ? rowKey(row, rowIndex) : rowIndex))
30413
- });
30414
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
30415
- className: [
30416
- "rounded-lg",
30417
- bordered ? "border border-border" : "",
30418
- "bg-surface overflow-x-auto",
30419
- scrolls ? `${maxBodyHeight} overflow-y-auto` : "",
30420
- className ?? ""
30421
- ].filter(Boolean).join(" "),
30422
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("table", {
30423
- className: `w-full text-xs ${scrolls ? "border-separate border-spacing-0" : ""}`,
30424
- style: { minWidth: `${minWidthPx}px` },
30425
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("thead", {
30426
- className: "bg-surface",
30427
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("tr", { children: columns.map((col) => {
30428
- const align = col.align ?? "left";
30429
- const nowrap = col.nowrap ?? true;
30430
- const sortable = col.sortValue !== void 0;
30431
- const isSorted = activeSort !== null && activeSort.columnKey === col.key;
30432
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("th", {
30433
- "aria-sort": sortable ? ariaSortForColumn(activeSort, col.key) : void 0,
30434
- title: sortable ? void 0 : col.notSortableReason,
30435
- className: [
30436
- "px-3 py-2 text-foreground-subtle font-medium bg-surface border-b border-border",
30437
- scrolls ? "sticky top-0 z-10" : "",
30438
- ALIGN_CLASS[align],
30439
- nowrap ? "whitespace-nowrap" : "",
30440
- col.width ?? ""
30441
- ].filter(Boolean).join(" "),
30442
- children: sortable ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SortHeaderButton, {
30443
- label: col.headerRender ? col.headerRender() : col.header,
30444
- active: isSorted,
30445
- dir: isSorted && activeSort !== null ? activeSort.dir : "asc",
30446
- onSort: () => setSort((prev) => nextTableSort(prev, col.key))
30447
- }) : col.headerRender ? col.headerRender() : col.header
30448
- }, col.key);
30449
- }) })
30450
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("tbody", { children: displayRows.map((row, rowIndex) => {
30451
- const key = rowKey ? rowKey(row, rowIndex) : rowIndex;
30452
- const extra = rowClassName?.(row, rowIndex) ?? "";
30453
- const interactive = onRowClick !== void 0;
30454
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("tr", {
30455
- onClick: interactive ? () => onRowClick(row, rowIndex) : void 0,
30456
- className: [interactive ? "cursor-pointer hover:bg-primary/5" : "hover:bg-primary/5", extra].filter(Boolean).join(" "),
30457
- children: columns.map((col) => {
30458
- const align = col.align ?? "left";
30459
- const nowrap = col.nowrap ?? true;
30460
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", {
30461
- className: [
30462
- "px-3 py-2 text-foreground border-b border-border",
30463
- ALIGN_CLASS[align],
30464
- nowrap ? "whitespace-nowrap" : ""
30465
- ].filter(Boolean).join(" "),
30466
- children: col.render(row, rowIndex)
30467
- }, col.key);
30468
- })
30469
- }, key);
30470
- }) })]
30471
- })
30472
- });
30645
+ function ConfirmActionButton({ label, icon: Icon, title = "Confirm action", description, confirmLabel, triggerVariant = "outline", confirmVariant = "danger", size = "sm", disabled, className, action, onSuccess }) {
30646
+ const [open, setOpen] = (0, react$1.useState)(false);
30647
+ const [running, setRunning] = (0, react$1.useState)(false);
30648
+ const [error, setError] = (0, react$1.useState)(null);
30649
+ const handleConfirm = async () => {
30650
+ setError(null);
30651
+ setRunning(true);
30652
+ try {
30653
+ const result = await action();
30654
+ onSuccess?.(result);
30655
+ setOpen(false);
30656
+ } catch (err) {
30657
+ setError(err instanceof Error ? err.message : String(err));
30658
+ } finally {
30659
+ setRunning(false);
30660
+ }
30661
+ };
30662
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(Button, {
30663
+ type: "button",
30664
+ variant: triggerVariant,
30665
+ size,
30666
+ disabled,
30667
+ onClick: () => {
30668
+ setError(null);
30669
+ setOpen(true);
30670
+ },
30671
+ className,
30672
+ children: [Icon && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Icon, { className: "h-3.5 w-3.5" }), label]
30673
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Dialog, {
30674
+ open,
30675
+ onOpenChange: (next) => !running && setOpen(next),
30676
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(DialogContent, { children: [
30677
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(DialogHeader, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(DialogTitle, {
30678
+ className: "flex items-center gap-2",
30679
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(TriangleAlert, { className: "h-4 w-4 text-amber-400" }), title]
30680
+ }), typeof description === "string" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DialogDescription, { children: description }) : description] }),
30681
+ error && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
30682
+ className: cn("mt-2 px-3 py-2 rounded border border-danger/40 bg-danger/10", "text-xs text-danger"),
30683
+ children: error
30684
+ }),
30685
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(DialogFooter, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(Button, {
30686
+ type: "button",
30687
+ variant: "ghost",
30688
+ size,
30689
+ disabled: running,
30690
+ onClick: () => setOpen(false),
30691
+ children: "Cancel"
30692
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(Button, {
30693
+ type: "button",
30694
+ variant: confirmVariant,
30695
+ size,
30696
+ disabled: running,
30697
+ onClick: () => {
30698
+ handleConfirm();
30699
+ },
30700
+ children: [running && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LoaderCircle, { className: "h-3.5 w-3.5 animate-spin" }), confirmLabel ?? label]
30701
+ })] })
30702
+ ] })
30703
+ })] });
30473
30704
  }
30705
+ //#endregion
30706
+ //#region src/composites/copy-button.tsx
30474
30707
  /**
30475
- * One row as a card. Columns that carry a plain-text `header` become labelled
30476
- * `SettingRow`s — the label is the column title and the value gets the full
30477
- * card width. Columns with no text header (an actions column, a
30478
- * `headerRender`-only column) have no label to show, so they render as a
30479
- * full-width strip at the foot of the card.
30708
+ * `CopyButton` — a compact button that copies a string `value` to the
30709
+ * clipboard via `navigator.clipboard.writeText`, showing a brief
30710
+ * "copied" check state. Addon-agnostic; used wherever a secret / URL
30711
+ * needs a one-click copy affordance (export setup panels, etc.).
30480
30712
  */
30481
- function DataTableCard({ row, rowIndex, columns, bordered, onRowClick, rowClassName }) {
30482
- const labelled = columns.filter((col) => col.header !== void 0 && col.header !== "");
30483
- const unlabelled = columns.filter((col) => col.header === void 0 || col.header === "");
30484
- const interactive = onRowClick !== void 0;
30485
- const extra = rowClassName?.(row, rowIndex) ?? "";
30486
- return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
30487
- "data-data-table-card": "",
30488
- onClick: interactive ? () => onRowClick(row, rowIndex) : void 0,
30489
- className: [
30490
- "rounded-lg bg-surface px-3 py-1.5 divide-y divide-border-subtle",
30491
- bordered ? "border border-border" : "",
30492
- interactive ? "cursor-pointer hover:bg-primary/5" : "",
30493
- extra
30494
- ].filter(Boolean).join(" "),
30495
- children: [labelled.map((col) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SettingRow, {
30496
- label: col.header,
30497
- children: col.render(row, rowIndex)
30498
- }, col.key)), unlabelled.length > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
30499
- className: "flex flex-wrap items-center justify-end gap-2 py-1.5",
30500
- children: unlabelled.map((col) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { children: col.render(row, rowIndex) }, col.key))
30501
- })]
30713
+ var COPIED_RESET_MS = 2e3;
30714
+ function CopyButton({ value, label, srLabel, className, disabled }) {
30715
+ const [copied, setCopied] = (0, react$1.useState)(false);
30716
+ const handleCopy = (0, react$1.useCallback)(() => {
30717
+ if (!value) return;
30718
+ navigator.clipboard.writeText(value).then(() => {
30719
+ setCopied(true);
30720
+ setTimeout(() => setCopied(false), COPIED_RESET_MS);
30721
+ });
30722
+ }, [value]);
30723
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(Button, {
30724
+ size: "sm",
30725
+ variant: "ghost",
30726
+ type: "button",
30727
+ disabled: disabled || value.length === 0,
30728
+ onClick: handleCopy,
30729
+ className: cn(className),
30730
+ "aria-label": copied ? "Copied" : `Copy ${srLabel ?? label ?? "value"}`,
30731
+ children: [copied ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Check, { className: "h-3.5 w-3.5 text-success" }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Copy, { className: "h-3.5 w-3.5" }), label ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
30732
+ className: "ml-1",
30733
+ children: copied ? "Copied" : label
30734
+ }) : null]
30502
30735
  });
30503
30736
  }
30504
30737
  //#endregion
@@ -46556,99 +46789,6 @@ function fuzzyMatch(query, target) {
46556
46789
  return normalizeForSearch(target).includes(nq);
46557
46790
  }
46558
46791
  //#endregion
46559
- //#region src/composites/device-list/pagination.tsx
46560
- var NEIGHBORS = 2;
46561
- function computePageButtons(currentPage, totalPages) {
46562
- if (totalPages <= 1) return [{
46563
- kind: "page",
46564
- n: 1
46565
- }];
46566
- if (totalPages <= 7) {
46567
- const all = [];
46568
- for (let i = 1; i <= totalPages; i++) all.push({
46569
- kind: "page",
46570
- n: i
46571
- });
46572
- return all;
46573
- }
46574
- const result = [];
46575
- const leftBound = Math.max(2, currentPage - NEIGHBORS);
46576
- const rightBound = Math.min(totalPages - 1, currentPage + NEIGHBORS);
46577
- result.push({
46578
- kind: "page",
46579
- n: 1
46580
- });
46581
- if (leftBound > 2) result.push({
46582
- kind: "ellipsis",
46583
- side: "left"
46584
- });
46585
- for (let i = leftBound; i <= rightBound; i++) result.push({
46586
- kind: "page",
46587
- n: i
46588
- });
46589
- if (rightBound < totalPages - 1) result.push({
46590
- kind: "ellipsis",
46591
- side: "right"
46592
- });
46593
- result.push({
46594
- kind: "page",
46595
- n: totalPages
46596
- });
46597
- return result;
46598
- }
46599
- function Pagination({ currentPage, totalItems, pageSize, onPageChange, itemNoun = "devices" }) {
46600
- if (totalItems <= pageSize) return null;
46601
- const totalPages = Math.ceil(totalItems / pageSize);
46602
- const startIdx = (currentPage - 1) * pageSize + 1;
46603
- const endIdx = Math.min(currentPage * pageSize, totalItems);
46604
- const buttons = computePageButtons(currentPage, totalPages);
46605
- return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
46606
- className: "flex items-center justify-between gap-4 flex-wrap pt-2 text-[11px] text-foreground-subtle",
46607
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", { children: [
46608
- "Showing ",
46609
- startIdx,
46610
- "–",
46611
- endIdx,
46612
- " of ",
46613
- totalItems,
46614
- " ",
46615
- itemNoun
46616
- ] }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
46617
- className: "inline-flex items-center gap-1",
46618
- children: [
46619
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
46620
- type: "button",
46621
- "aria-label": "Previous page",
46622
- disabled: currentPage === 1,
46623
- onClick: () => onPageChange(currentPage - 1),
46624
- className: cn("inline-flex items-center justify-center h-7 w-7 rounded border border-border bg-surface text-foreground-subtle", "hover:text-foreground hover:bg-surface-hover transition-colors", "disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-surface"),
46625
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ChevronLeft, { className: "h-3 w-3" })
46626
- }),
46627
- buttons.map((b, i) => {
46628
- if (b.kind === "ellipsis") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
46629
- className: "px-1 text-foreground-subtle/60 select-none",
46630
- children: "…"
46631
- }, `e-${i}`);
46632
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
46633
- type: "button",
46634
- onClick: () => onPageChange(b.n),
46635
- className: cn("inline-flex items-center justify-center h-7 min-w-7 px-1.5 rounded border text-[10.5px] font-medium transition-colors", b.n === currentPage ? "border-primary/40 bg-primary/10 text-primary" : "border-border bg-surface text-foreground-subtle hover:text-foreground hover:bg-surface-hover"),
46636
- children: b.n
46637
- }, `p-${b.n}`);
46638
- }),
46639
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
46640
- type: "button",
46641
- "aria-label": "Next page",
46642
- disabled: currentPage === totalPages,
46643
- onClick: () => onPageChange(currentPage + 1),
46644
- className: cn("inline-flex items-center justify-center h-7 w-7 rounded border border-border bg-surface text-foreground-subtle", "hover:text-foreground hover:bg-surface-hover transition-colors", "disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-surface"),
46645
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ChevronRight, { className: "h-3 w-3" })
46646
- })
46647
- ]
46648
- })]
46649
- });
46650
- }
46651
- //#endregion
46652
46792
  //#region src/composites/device-list/multi-select.tsx
46653
46793
  /**
46654
46794
  * Compact multi-select dropdown — a single chip-sized trigger ("Label · N")