@camstack/addon-agent-ui 1.2.307 → 1.2.309

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/addon.js CHANGED
@@ -11214,7 +11214,7 @@ object({
11214
11214
  params: record(string(), union([string(), number()])).optional()
11215
11215
  });
11216
11216
  //#endregion
11217
- //#region ../types/dist/composition-BBzVf2xd.mjs
11217
+ //#region ../types/dist/composition-BiKWlUCc.mjs
11218
11218
  /**
11219
11219
  * The ffmpeg build every CamStack node downloads, per platform and arch.
11220
11220
  *
@@ -12147,7 +12147,15 @@ var HelperSpecSchema = discriminatedUnion("kind", [
12147
12147
  thresholdWatts: number().positive(),
12148
12148
  startDwellMs: number().int().nonnegative(),
12149
12149
  stopDwellMs: number().int().nonnegative(),
12150
- member: HelperMemberSchema
12150
+ member: HelperMemberSchema,
12151
+ /**
12152
+ * The plug that powers the appliance (`switch.on`). Optional: when set, the
12153
+ * composition carries a `power-source` feature, so the hub can cut and restore
12154
+ * that plug (power-source link of a NEW-target composition).
12155
+ */
12156
+ powerSwitch: HelperMemberSchema.optional(),
12157
+ /** How long a forced restart keeps the plug off; the cap's default when unset. */
12158
+ offSeconds: number().optional()
12151
12159
  }),
12152
12160
  object({
12153
12161
  kind: literal("statistic"),
@@ -13545,7 +13553,13 @@ var MigrationLedgerEntrySchema = object({
13545
13553
  /** Why it is `blocked` or `held` (`dependency-failed`, `snapshot-refused`, …). */
13546
13554
  reason: string().nullable(),
13547
13555
  nodeId: string().nullable(),
13548
- bootId: string().nullable()
13556
+ bootId: string().nullable(),
13557
+ /**
13558
+ * The catalogued meta of this id (description, body kind, store, `dependsOn`…),
13559
+ * joined by the engine from the catalogues it knows this boot. Absent when no
13560
+ * catalogue lists the id (a newer database).
13561
+ */
13562
+ meta: MigrationMetaSchema.optional()
13549
13563
  });
13550
13564
  /** A catalogued migration that is not applied, with where it stands. */
13551
13565
  var MigrationPendingEntrySchema = object({
@@ -45768,6 +45782,49 @@ function actuator(input) {
45768
45782
  };
45769
45783
  }
45770
45784
  new Map(GROUP_TEMPLATES.map((template) => [template.id, template]));
45785
+ var PowerSourceRefusalReasonSchema = _enum([
45786
+ "no-power-source",
45787
+ "switch-missing",
45788
+ "switch-offline",
45789
+ "switch-unknown",
45790
+ "restart-in-progress",
45791
+ "switch-call-failed"
45792
+ ]);
45793
+ var PowerSourceActionResultSchema = discriminatedUnion("accepted", [object({ accepted: literal(true) }), object({
45794
+ accepted: literal(false),
45795
+ reason: PowerSourceRefusalReasonSchema,
45796
+ /** One line for the operator, naming the switch. */
45797
+ message: string()
45798
+ })]);
45799
+ var PowerSourceInfoSchema = object({
45800
+ /** False when the device has no power source linked; the rest is then empty. */
45801
+ linked: boolean(),
45802
+ switchDeviceId: number().nullable(),
45803
+ switchName: string().nullable(),
45804
+ /** The switch's on/off state, or null when it is unknown. Never false for unknown (D393). */
45805
+ switchOn: boolean().nullable(),
45806
+ switchOnline: boolean().nullable(),
45807
+ restartInProgress: boolean(),
45808
+ offSeconds: number().int()
45809
+ });
45810
+ object({
45811
+ /** Null while the switch has not reported: unknown is never `false` (D393). */
45812
+ switchOn: boolean().nullable(),
45813
+ offSeconds: number().int(),
45814
+ lastFetchedAt: number()
45815
+ });
45816
+ DeviceType.Gateway, DeviceType.Hub, DeviceType.Camera, DeviceType.Sensor, DeviceType.MediaPlayer, DeviceType.Vacuum, DeviceType.Generic, DeviceType.Washer, DeviceType.Dryer, DeviceType.Dishwasher, DeviceType.PetFountain, DeviceType.Fan, DeviceType.Humidifier, DeviceType.Climate, DeviceType.WaterHeater;
45817
+ var deviceInput$1 = object({ deviceId: number().int().nonnegative() });
45818
+ systemMethod(deviceInput$1, PowerSourceInfoSchema, { auth: "admin" }), systemMethod(deviceInput$1, PowerSourceActionResultSchema, {
45819
+ kind: "mutation",
45820
+ auth: "admin"
45821
+ }), systemMethod(deviceInput$1, PowerSourceActionResultSchema, {
45822
+ kind: "mutation",
45823
+ auth: "admin"
45824
+ }), systemMethod(deviceInput$1, PowerSourceActionResultSchema, {
45825
+ kind: "mutation",
45826
+ auth: "admin"
45827
+ });
45771
45828
  DeviceFeature.LightColorRgb, DeviceFeature.LightColorHsv, DeviceFeature.LightColorMired;
45772
45829
  DeviceType.Camera;
45773
45830
  `${COMPOSED_DEVICE_STABLE_ID_PREFIX}`;
@@ -51551,7 +51608,8 @@ var PALETTE_ENTRY_IDS = [
51551
51608
  "switch",
51552
51609
  "siren",
51553
51610
  "button",
51554
- "doorbell"
51611
+ "doorbell",
51612
+ "appliance-cycle"
51555
51613
  ];
51556
51614
  var AUDIO_ENTRY_ID = "audio";
51557
51615
  /** Six rungs, quiet → loud. The opaque end is the entry's hex. */
@@ -51622,7 +51680,8 @@ var CAMSTACK_HEX = {
51622
51680
  switch: "#7a812a",
51623
51681
  siren: "#ac5d7f",
51624
51682
  button: "#b276cd",
51625
- doorbell: "#0087ab"
51683
+ doorbell: "#0087ab",
51684
+ "appliance-cycle": "#2a8c8c"
51626
51685
  };
51627
51686
  var CAMSTACK_FALLBACK = [
51628
51687
  "#b34dc7",
@@ -51687,7 +51746,8 @@ var HIGH_CONTRAST_HEX = {
51687
51746
  switch: "#d05259",
51688
51747
  siren: "#cd67b3",
51689
51748
  button: "#c9746a",
51690
- doorbell: "#338eeb"
51749
+ doorbell: "#338eeb",
51750
+ "appliance-cycle": "#00848a"
51691
51751
  };
51692
51752
  var HIGH_CONTRAST_FALLBACK = [
51693
51753
  "#817f3b",
@@ -51752,7 +51812,8 @@ var OKABE_ITO_HEX = {
51752
51812
  switch: "#ad2c4e",
51753
51813
  siren: "#348e08",
51754
51814
  button: "#d27303",
51755
- doorbell: "#55770f"
51815
+ doorbell: "#55770f",
51816
+ "appliance-cycle": "#00737d"
51756
51817
  };
51757
51818
  var OKABE_ITO_FALLBACK = [
51758
51819
  "#9a3784",
@@ -51961,6 +52022,7 @@ sub("switch", "control", "control", "switch", "Switch");
51961
52022
  sub("siren", "control", "control", "siren", "Siren");
51962
52023
  sub("button", "control", "control", "button", "Button");
51963
52024
  sub("doorbell", "control", "control", "doorbell", "Doorbell");
52025
+ sub("appliance-cycle", "control", "control", "switch", "Appliance cycle");
51964
52026
  for (const l of AUDIO_MACRO_LABELS) {
51965
52027
  const kind = `audio-${l.id}`;
51966
52028
  if (entries.has(kind)) continue;
@@ -60504,7 +60566,8 @@ var CAP_TO_KIND = {
60504
60566
  cover: "cover",
60505
60567
  switch: "switch",
60506
60568
  button: "button",
60507
- doorbell: "doorbell"
60569
+ doorbell: "doorbell",
60570
+ "running-state": "appliance-cycle"
60508
60571
  };
60509
60572
  function buildDescriptor(capName, kind) {
60510
60573
  const t = EVENT_TAXONOMY[kind];
@@ -64453,19 +64516,19 @@ var RemoteSetConfigResultSchema = discriminatedUnion("status", [object({ status:
64453
64516
  reason: _enum(["unknown-template", "not-a-media-player"]),
64454
64517
  detail: string()
64455
64518
  })]);
64456
- var deviceInput$1 = object({ deviceId: number().int().nonnegative() });
64519
+ var deviceInput = object({ deviceId: number().int().nonnegative() });
64457
64520
  DeviceType.MediaPlayer;
64458
- method(deviceInput$1, RemoteConfigSchema, { auth: "admin" }), method(deviceInput$1.extend({ config: RemoteConfigSchema }), RemoteSetConfigResultSchema, {
64521
+ method(deviceInput, RemoteConfigSchema, { auth: "admin" }), method(deviceInput.extend({ config: RemoteConfigSchema }), RemoteSetConfigResultSchema, {
64459
64522
  kind: "mutation",
64460
64523
  auth: "admin"
64461
- }), method(deviceInput$1, RemoteCommandListSchema, { auth: "protected" }), method(deviceInput$1.extend({
64524
+ }), method(deviceInput, RemoteCommandListSchema, { auth: "protected" }), method(deviceInput.extend({
64462
64525
  role: RemoteRoleSchema,
64463
64526
  /** Sends in a row (volume steps). */
64464
64527
  repeat: number().int().min(1).max(50).default(1)
64465
64528
  }), RemoteSendResultSchema, {
64466
64529
  kind: "mutation",
64467
64530
  auth: "protected"
64468
- }), method(deviceInput$1.extend({
64531
+ }), method(deviceInput.extend({
64469
64532
  command: RemoteMediaCommandSchema,
64470
64533
  muted: boolean().optional(),
64471
64534
  source: string().optional(),
@@ -67377,49 +67440,6 @@ DeviceType.Lock, method(object({
67377
67440
  kind: "mutation",
67378
67441
  auth: "protected"
67379
67442
  });
67380
- var PowerSourceRefusalReasonSchema = _enum([
67381
- "no-power-source",
67382
- "switch-missing",
67383
- "switch-offline",
67384
- "switch-unknown",
67385
- "restart-in-progress",
67386
- "switch-call-failed"
67387
- ]);
67388
- var PowerSourceActionResultSchema = discriminatedUnion("accepted", [object({ accepted: literal(true) }), object({
67389
- accepted: literal(false),
67390
- reason: PowerSourceRefusalReasonSchema,
67391
- /** One line for the operator, naming the switch. */
67392
- message: string()
67393
- })]);
67394
- var PowerSourceInfoSchema = object({
67395
- /** False when the device has no power source linked; the rest is then empty. */
67396
- linked: boolean(),
67397
- switchDeviceId: number().nullable(),
67398
- switchName: string().nullable(),
67399
- /** The switch's on/off state, or null when it is unknown. Never false for unknown (D393). */
67400
- switchOn: boolean().nullable(),
67401
- switchOnline: boolean().nullable(),
67402
- restartInProgress: boolean(),
67403
- offSeconds: number().int()
67404
- });
67405
- object({
67406
- /** Null while the switch has not reported: unknown is never `false` (D393). */
67407
- switchOn: boolean().nullable(),
67408
- offSeconds: number().int(),
67409
- lastFetchedAt: number()
67410
- });
67411
- DeviceType.Gateway, DeviceType.Hub, DeviceType.Camera, DeviceType.Sensor, DeviceType.MediaPlayer, DeviceType.Vacuum, DeviceType.Generic, DeviceType.Washer, DeviceType.Dryer, DeviceType.Dishwasher, DeviceType.PetFountain, DeviceType.Fan, DeviceType.Humidifier, DeviceType.Climate, DeviceType.WaterHeater;
67412
- var deviceInput = object({ deviceId: number().int().nonnegative() });
67413
- systemMethod(deviceInput, PowerSourceInfoSchema, { auth: "admin" }), systemMethod(deviceInput, PowerSourceActionResultSchema, {
67414
- kind: "mutation",
67415
- auth: "admin"
67416
- }), systemMethod(deviceInput, PowerSourceActionResultSchema, {
67417
- kind: "mutation",
67418
- auth: "admin"
67419
- }), systemMethod(deviceInput, PowerSourceActionResultSchema, {
67420
- kind: "mutation",
67421
- auth: "admin"
67422
- });
67423
67443
  object({
67424
67444
  value: number().nullable().meta(readingMeta("device", { label: "Total" })),
67425
67445
  lastFetchedAt: number()
@@ -72657,7 +72677,7 @@ var ExternalIdentityKeySchema = object({
72657
72677
  provider: string().min(1),
72658
72678
  subject: string().min(1)
72659
72679
  });
72660
- method(_void(), array(UserSummarySchema), { auth: "admin" }), method(CreateUserInputSchema, UserSummarySchema, {
72680
+ method(_void(), array(UserSummarySchema), { auth: "admin" }), method(_void(), object({ defaultPasswordInUse: boolean() }), { auth: "admin" }), method(CreateUserInputSchema, UserSummarySchema, {
72661
72681
  kind: "mutation",
72662
72682
  auth: "admin",
72663
72683
  access: "create"
@@ -83513,6 +83533,13 @@ Object.freeze({
83513
83533
  access: "view",
83514
83534
  role: "admin"
83515
83535
  },
83536
+ "userManagement.getAdminBootstrapStatus": {
83537
+ capName: "user-management",
83538
+ capScope: "system",
83539
+ addonId: null,
83540
+ access: "view",
83541
+ role: "admin"
83542
+ },
83516
83543
  "userManagement.getTotpStatus": {
83517
83544
  capName: "user-management",
83518
83545
  capScope: "system",
@@ -87480,13 +87507,114 @@ NC_AUDIO_DEFAULTS.hitPercent, NC_AUDIO_DEFAULTS.samplingSeconds;
87480
87507
  *
87481
87508
  * Pure, RN-safe: the viewer imports the support rule from here.
87482
87509
  */
87510
+ /**
87511
+ * Control caps that still have a raise and a clear an operator names: an
87512
+ * appliance cycle raises when it STARTS and clears when it FINISHES. Kept out
87513
+ * of `SOURCE_CAP_ACTIVE_FIELD` on purpose — that table also makes a device a
87514
+ * camera-sensor / recorder-trigger source, and a dishwasher is neither.
87515
+ */
87516
+ var CYCLE_RAISED_FIELD_BY_CAP = { "running-state": "running" };
87483
87517
  /** Event kind → the boolean field of its cap slice that means "raised". */
87484
87518
  var NC_SENSOR_RAISED_FIELD_BY_KIND = Object.freeze(Object.fromEntries(Object.entries(EVENT_KIND_BY_CAP).flatMap(([capName, descriptor]) => {
87519
+ const cycleField = CYCLE_RAISED_FIELD_BY_CAP[capName];
87520
+ if (cycleField !== void 0) return [[descriptor.kind, cycleField]];
87485
87521
  const field = SOURCE_CAP_ACTIVE_FIELD[capName];
87486
87522
  if (field === void 0 || descriptor.category !== "sensor") return [];
87487
87523
  return [[descriptor.kind, field]];
87488
87524
  })));
87489
87525
  Object.freeze(Object.keys(NC_SENSOR_RAISED_FIELD_BY_KIND));
87526
+ Object.freeze({
87527
+ contact: {
87528
+ starts: {
87529
+ en: "opened",
87530
+ it: "si apre"
87531
+ },
87532
+ finishes: {
87533
+ en: "closed",
87534
+ it: "si chiude"
87535
+ }
87536
+ },
87537
+ "motion-sensor": {
87538
+ starts: {
87539
+ en: "motion detected",
87540
+ it: "movimento rilevato"
87541
+ },
87542
+ finishes: {
87543
+ en: "motion stopped",
87544
+ it: "movimento terminato"
87545
+ }
87546
+ },
87547
+ smoke: {
87548
+ starts: {
87549
+ en: "smoke detected",
87550
+ it: "fumo rilevato"
87551
+ },
87552
+ finishes: {
87553
+ en: "smoke gone",
87554
+ it: "fumo scomparso"
87555
+ }
87556
+ },
87557
+ flood: {
87558
+ starts: {
87559
+ en: "water detected",
87560
+ it: "acqua rilevata"
87561
+ },
87562
+ finishes: {
87563
+ en: "dry again",
87564
+ it: "di nuovo asciutto"
87565
+ }
87566
+ },
87567
+ gas: {
87568
+ starts: {
87569
+ en: "gas detected",
87570
+ it: "gas rilevato"
87571
+ },
87572
+ finishes: {
87573
+ en: "gas gone",
87574
+ it: "gas scomparso"
87575
+ }
87576
+ },
87577
+ "carbon-monoxide": {
87578
+ starts: {
87579
+ en: "carbon monoxide detected",
87580
+ it: "monossido rilevato"
87581
+ },
87582
+ finishes: {
87583
+ en: "carbon monoxide gone",
87584
+ it: "monossido scomparso"
87585
+ }
87586
+ },
87587
+ vibration: {
87588
+ starts: {
87589
+ en: "vibration detected",
87590
+ it: "vibrazione rilevata"
87591
+ },
87592
+ finishes: {
87593
+ en: "vibration stopped",
87594
+ it: "vibrazione terminata"
87595
+ }
87596
+ },
87597
+ tamper: {
87598
+ starts: {
87599
+ en: "tampered with",
87600
+ it: "manomesso"
87601
+ },
87602
+ finishes: {
87603
+ en: "tamper cleared",
87604
+ it: "manomissione rientrata"
87605
+ }
87606
+ },
87607
+ "appliance-cycle": {
87608
+ starts: {
87609
+ en: "the cycle started",
87610
+ it: "il ciclo parte"
87611
+ },
87612
+ finishes: {
87613
+ en: "the cycle finished",
87614
+ it: "il ciclo è terminato"
87615
+ }
87616
+ }
87617
+ });
87490
87618
  object({
87491
87619
  phase: _enum(["raised", "resolved"]),
87492
87620
  episodeId: string().min(1),
@@ -87710,6 +87838,7 @@ var STATE_SUMMARY_VARS = [
87710
87838
  [...RULE_TEXT],
87711
87839
  [...RULE_TEXT],
87712
87840
  [...RULE_TEXT],
87841
+ [...RULE_TEXT],
87713
87842
  ([...RULE_TEXT], [...DEVICE_ATTENTION, ...ALERT_EPISODE]),
87714
87843
  [...RULE_TEXT],
87715
87844
  [...RULE_TEXT],
@@ -87954,6 +88083,7 @@ new Set([
87954
88083
  "siren",
87955
88084
  "button",
87956
88085
  "doorbell",
88086
+ "appliance-cycle",
87957
88087
  "audio-speech",
87958
88088
  "audio-scream",
87959
88089
  "audio-crying",
@@ -88430,7 +88560,7 @@ var AgentUIAddon = class extends BaseAddon {
88430
88560
  capability: adminUiCapability,
88431
88561
  provider: {
88432
88562
  getStaticDir: async () => ({ staticDir: path.resolve(__dirname) }),
88433
- getVersion: async () => ({ version: "1.2.307" })
88563
+ getVersion: async () => ({ version: "1.2.309" })
88434
88564
  }
88435
88565
  }];
88436
88566
  }
@@ -1 +1 @@
1
- import{a as e,i as t,l as n,n as r,o as i}from"./scheduler-0XZJE03d.js";import{c as a,d as o,g as s,l as c,p as l,t as u,w as d}from"./index-DWH0ZLxX.js";import{MaskShapeCanvas as f}from"./MaskShapeCanvas-BTvl6Rin.js";var p=d(`grid-2x2`,[[`path`,{d:`M12 3v18`,key:`108xh3`}],[`path`,{d:`M3 12h18`,key:`1i2n21`}],[`rect`,{x:`3`,y:`3`,width:`18`,height:`18`,rx:`2`,key:`h1oib`}]]),m=n(i(),1),h=n(e(),1),g=110,_=`motion-zones`,v=0,y=[1,2,3],b=1,x=`rounded-md border border-border bg-surface px-2 py-1 text-[11px] font-medium text-foreground-subtle hover:bg-surface-hover disabled:opacity-40 transition-colors`,S=`rounded-md border border-primary/50 bg-primary/15 px-2.5 py-1 text-[11px] font-medium text-primary hover:bg-primary/25 disabled:opacity-40 transition-colors`;function C(e,t,n){let r=t*n,i=Array.from({length:r});for(let t=0;t<r;t+=1)i[t]=e[t]===!0;return i}function w(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1)if(e[n]!==t[n])return!1;return!0}function T(e,t){return Math.ceil(e/t)}function E(e,t,n){return Math.min(n-1,Math.floor((e+.5)/t*n))}function D(e,t,n,r){let i=T(t,r),a=T(n,r),o=Array.from({length:i*a},()=>!1);for(let r=0;r<n;r+=1){let s=E(r,n,a);for(let n=0;n<t;n+=1)e[r*t+n]===!0&&(o[s*i+E(n,t,i)]=!0)}return o}function O(e,t,n,r){let i=T(t,r),a=T(n,r),o=Array.from({length:t*n},()=>!1);for(let r=0;r<n;r+=1){let s=E(r,n,a);for(let n=0;n<t;n+=1)o[r*t+n]=e[s*i+E(n,t,i)]===!0}return o}function k({deviceId:e}){let n=t(),i=o(s().trpcClient,e),[d,E]=(0,m.useState)(null),[k,A]=(0,m.useState)(!1),[j,M]=(0,m.useState)(null),[N,P]=(0,m.useState)(null),[F,I]=(0,m.useState)(b),[L,R]=(0,m.useState)(!1),[z,B]=(0,m.useState)(!1),V=(0,m.useRef)(!1);(0,m.useEffect)(()=>{if(!i)return;let e=!1;return V.current=!1,E(null),A(!1),M(null),P(null),I(b),B(!1),(async()=>{try{let t=await i.motionZones?.getOptions({});if(e)return;if(!t)throw Error(`device proxy not ready`);if(E(t),V.current)return;let n=await i.motionZones?.getStatus({});if(e)return;if(!n)throw Error(`device proxy not ready`);V.current=!0;let r=n.regions.find(e=>e.shape.kind===`grid`),a=C(r?r.shape.cells:[],t.grid.width,t.grid.height);P(a),M(D(a,t.grid.width,t.grid.height,b))}catch(t){if(e)return;c(t)?A(!0):console.error(`Motion Zones load failed`,t)}})(),()=>{e=!0}},[i]);let H=d?d.grid.width:0,U=d?d.grid.height:0,W=T(H,F),G=T(U,F),K=(0,m.useMemo)(()=>j&&d?O(j,H,U,F):null,[j,d,H,U,F]),q=(0,m.useMemo)(()=>K!==null&&N!==null&&!w(K,N),[K,N]),J=(0,m.useMemo)(()=>K?K.reduce((e,t)=>t?e+1:e,0):0,[K]),Y=H*U,X=W*G,Z=(0,m.useCallback)(e=>{X>0&&M(Array.from({length:X},()=>e))},[X]),ee=(0,m.useCallback)(()=>{M(e=>e&&e.map(e=>!e))},[]),te=(0,m.useCallback)(()=>{N&&d&&M(D(N,H,U,F))},[N,d,H,U,F]),ne=(0,m.useCallback)(e=>{e===F||!d||M(t=>{if(!t)return I(e),t;let n=D(O(t,H,U,F),H,U,e);return I(e),n})},[F,d,H,U]),Q=(0,m.useMemo)(()=>d&&j?[{id:v,shape:{kind:`grid`,gridWidth:W,gridHeight:G,cells:[...j]}}]:[],[d,j,W,G]),$=(0,m.useCallback)((e,t)=>{t.kind===`grid`&&M(t.cells)},[]),re=(0,m.useCallback)(async()=>{if(!(!i||!j||!d)){R(!0);try{let e=O(j,d.grid.width,d.grid.height,F),t={kind:`grid`,gridWidth:d.grid.width,gridHeight:d.grid.height,cells:e};await i.motionZones?.setZone({patch:{regions:[{id:v,enabled:!0,shape:t}]}});let n=await i.motionZones?.getStatus({});if(n){let e=n.regions.find(e=>e.shape.kind===`grid`),t=C(e?e.shape.cells:[],d.grid.width,d.grid.height);P(t),M(D(t,d.grid.width,d.grid.height,F))}}catch(e){console.error(`Motion Zones save failed`,e)}finally{R(!1)}}},[i,j,d,F]);u((0,m.useMemo)(()=>z&&!k&&d&&j?{id:_,order:g,node:(0,h.jsx)(f,{transparent:!0,items:Q,supportedShapes:[`grid`],grid:{width:W,height:G},selectedId:v,onSelect:()=>{},onShapeChange:$,onDrawComplete:()=>{},drawingKind:null})}:null,[z,k,d,j,Q,$,W,G]));let ie=!k&&d!==null&&j!==null;return i?(0,h.jsx)(l,{title:n(`uiLibrary.motionZones.title`,`Motion Zones`),icon:(0,h.jsx)(p,{className:`h-3.5 w-3.5 text-foreground-subtle`}),children:(0,h.jsx)(`div`,{className:`flex flex-col gap-3`,children:k?(0,h.jsx)(`p`,{className:`${a} leading-relaxed`,children:n(`uiLibrary.motionZones.unsupported`,`This camera doesn't expose an on-board motion zones grid.`)}):ie?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`p`,{className:`${a} leading-relaxed`,children:(0,h.jsx)(r,{uiKey:`uiLibrary.motionZones.intro`,fallback:`Toggle <0>Edit grid</0> to paint the region directly on the live frame, then <1>Save</1> to push the mask to the camera. Pick a bigger <2>Cell size</2> for quicker, broad-stroke painting — it's resampled to the camera's native {{width}}×{{height}} grid on save (×1 is the finest).`,components:[(0,h.jsx)(`strong`,{className:`text-foreground`},`e`),(0,h.jsx)(`strong`,{className:`text-foreground`},`s`),(0,h.jsx)(`strong`,{className:`text-foreground`},`c`)],values:{width:d.grid.width,height:d.grid.height}})}),(0,h.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,h.jsx)(`button`,{type:`button`,onClick:()=>B(e=>!e),disabled:L,"aria-pressed":z,className:z?S:x,children:z?n(`uiLibrary.motionZones.doneEditing`,`Done editing`):n(`uiLibrary.motionZones.editGrid`,`Edit grid`)}),(0,h.jsx)(`button`,{type:`button`,onClick:()=>Z(!0),disabled:L,className:x,children:n(`uiLibrary.motionZones.allOn`,`All on`)}),(0,h.jsx)(`button`,{type:`button`,onClick:()=>Z(!1),disabled:L,className:x,children:n(`uiLibrary.motionZones.allOff`,`All off`)}),(0,h.jsx)(`button`,{type:`button`,onClick:ee,disabled:L,className:x,children:n(`uiLibrary.motionZones.invert`,`Invert`)}),(0,h.jsxs)(`div`,{className:`flex items-center gap-1 ml-1`,role:`group`,"aria-label":n(`uiLibrary.motionZones.cellSize`,`Cell size`),children:[(0,h.jsx)(`span`,{className:`${a} mr-0.5`,children:n(`uiLibrary.motionZones.cellSize`,`Cell size`)}),y.map(e=>(0,h.jsxs)(`button`,{type:`button`,onClick:()=>ne(e),disabled:L,"aria-pressed":F===e,title:e===1?n(`uiLibrary.motionZones.cameraGrid`,`Camera grid {{width}}×{{height}} (finest)`,{width:H,height:U}):n(`uiLibrary.motionZones.paintingGrid`,`{{width}}×{{height}} painting grid · cells ×{{factor}} bigger`,{width:T(H,e),height:T(U,e),factor:e}),className:F===e?S:x,children:[`×`,e]},e))]}),(0,h.jsxs)(`span`,{className:`${a} ml-1 tabular-nums`,children:[n(`uiLibrary.motionZones.cells`,`{{active}} / {{total}} cells · {{width}}×{{height}}`,{active:J,total:Y,width:d.grid.width,height:d.grid.height}),F===1?``:n(`uiLibrary.motionZones.paintSuffix`,` · paint {{width}}×{{height}}`,{width:W,height:G})]}),(0,h.jsx)(`span`,{className:`flex-1`}),(0,h.jsx)(`button`,{type:`button`,onClick:te,disabled:L||!q,className:`rounded-md border border-border bg-surface px-2 py-1 text-[11px] text-foreground-subtle hover:bg-surface-hover disabled:opacity-40 transition-colors`,children:n(`uiLibrary.motionZones.revert`,`Revert`)}),(0,h.jsx)(`button`,{type:`button`,onClick:()=>void re(),disabled:L||!q,className:S,children:L?n(`uiLibrary.motionZones.saving`,`Saving…`):n(`uiLibrary.motionZones.save`,`Save`)})]})]}):(0,h.jsx)(`p`,{className:`${a} leading-relaxed`,children:n(`uiLibrary.motionZones.loading`,`Loading the camera's grid…`)})})}):null}export{k as MotionZonesSettings};
1
+ import{a as e,i as t,l as n,n as r,o as i}from"./scheduler-0XZJE03d.js";import{c as a,d as o,g as s,l as c,p as l,t as u,w as d}from"./index-KdTdngTk.js";import{MaskShapeCanvas as f}from"./MaskShapeCanvas-BTvl6Rin.js";var p=d(`grid-2x2`,[[`path`,{d:`M12 3v18`,key:`108xh3`}],[`path`,{d:`M3 12h18`,key:`1i2n21`}],[`rect`,{x:`3`,y:`3`,width:`18`,height:`18`,rx:`2`,key:`h1oib`}]]),m=n(i(),1),h=n(e(),1),g=110,_=`motion-zones`,v=0,y=[1,2,3],b=1,x=`rounded-md border border-border bg-surface px-2 py-1 text-[11px] font-medium text-foreground-subtle hover:bg-surface-hover disabled:opacity-40 transition-colors`,S=`rounded-md border border-primary/50 bg-primary/15 px-2.5 py-1 text-[11px] font-medium text-primary hover:bg-primary/25 disabled:opacity-40 transition-colors`;function C(e,t,n){let r=t*n,i=Array.from({length:r});for(let t=0;t<r;t+=1)i[t]=e[t]===!0;return i}function w(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1)if(e[n]!==t[n])return!1;return!0}function T(e,t){return Math.ceil(e/t)}function E(e,t,n){return Math.min(n-1,Math.floor((e+.5)/t*n))}function D(e,t,n,r){let i=T(t,r),a=T(n,r),o=Array.from({length:i*a},()=>!1);for(let r=0;r<n;r+=1){let s=E(r,n,a);for(let n=0;n<t;n+=1)e[r*t+n]===!0&&(o[s*i+E(n,t,i)]=!0)}return o}function O(e,t,n,r){let i=T(t,r),a=T(n,r),o=Array.from({length:t*n},()=>!1);for(let r=0;r<n;r+=1){let s=E(r,n,a);for(let n=0;n<t;n+=1)o[r*t+n]=e[s*i+E(n,t,i)]===!0}return o}function k({deviceId:e}){let n=t(),i=o(s().trpcClient,e),[d,E]=(0,m.useState)(null),[k,A]=(0,m.useState)(!1),[j,M]=(0,m.useState)(null),[N,P]=(0,m.useState)(null),[F,I]=(0,m.useState)(b),[L,R]=(0,m.useState)(!1),[z,B]=(0,m.useState)(!1),V=(0,m.useRef)(!1);(0,m.useEffect)(()=>{if(!i)return;let e=!1;return V.current=!1,E(null),A(!1),M(null),P(null),I(b),B(!1),(async()=>{try{let t=await i.motionZones?.getOptions({});if(e)return;if(!t)throw Error(`device proxy not ready`);if(E(t),V.current)return;let n=await i.motionZones?.getStatus({});if(e)return;if(!n)throw Error(`device proxy not ready`);V.current=!0;let r=n.regions.find(e=>e.shape.kind===`grid`),a=C(r?r.shape.cells:[],t.grid.width,t.grid.height);P(a),M(D(a,t.grid.width,t.grid.height,b))}catch(t){if(e)return;c(t)?A(!0):console.error(`Motion Zones load failed`,t)}})(),()=>{e=!0}},[i]);let H=d?d.grid.width:0,U=d?d.grid.height:0,W=T(H,F),G=T(U,F),K=(0,m.useMemo)(()=>j&&d?O(j,H,U,F):null,[j,d,H,U,F]),q=(0,m.useMemo)(()=>K!==null&&N!==null&&!w(K,N),[K,N]),J=(0,m.useMemo)(()=>K?K.reduce((e,t)=>t?e+1:e,0):0,[K]),Y=H*U,X=W*G,Z=(0,m.useCallback)(e=>{X>0&&M(Array.from({length:X},()=>e))},[X]),ee=(0,m.useCallback)(()=>{M(e=>e&&e.map(e=>!e))},[]),te=(0,m.useCallback)(()=>{N&&d&&M(D(N,H,U,F))},[N,d,H,U,F]),ne=(0,m.useCallback)(e=>{e===F||!d||M(t=>{if(!t)return I(e),t;let n=D(O(t,H,U,F),H,U,e);return I(e),n})},[F,d,H,U]),Q=(0,m.useMemo)(()=>d&&j?[{id:v,shape:{kind:`grid`,gridWidth:W,gridHeight:G,cells:[...j]}}]:[],[d,j,W,G]),$=(0,m.useCallback)((e,t)=>{t.kind===`grid`&&M(t.cells)},[]),re=(0,m.useCallback)(async()=>{if(!(!i||!j||!d)){R(!0);try{let e=O(j,d.grid.width,d.grid.height,F),t={kind:`grid`,gridWidth:d.grid.width,gridHeight:d.grid.height,cells:e};await i.motionZones?.setZone({patch:{regions:[{id:v,enabled:!0,shape:t}]}});let n=await i.motionZones?.getStatus({});if(n){let e=n.regions.find(e=>e.shape.kind===`grid`),t=C(e?e.shape.cells:[],d.grid.width,d.grid.height);P(t),M(D(t,d.grid.width,d.grid.height,F))}}catch(e){console.error(`Motion Zones save failed`,e)}finally{R(!1)}}},[i,j,d,F]);u((0,m.useMemo)(()=>z&&!k&&d&&j?{id:_,order:g,node:(0,h.jsx)(f,{transparent:!0,items:Q,supportedShapes:[`grid`],grid:{width:W,height:G},selectedId:v,onSelect:()=>{},onShapeChange:$,onDrawComplete:()=>{},drawingKind:null})}:null,[z,k,d,j,Q,$,W,G]));let ie=!k&&d!==null&&j!==null;return i?(0,h.jsx)(l,{title:n(`uiLibrary.motionZones.title`,`Motion Zones`),icon:(0,h.jsx)(p,{className:`h-3.5 w-3.5 text-foreground-subtle`}),children:(0,h.jsx)(`div`,{className:`flex flex-col gap-3`,children:k?(0,h.jsx)(`p`,{className:`${a} leading-relaxed`,children:n(`uiLibrary.motionZones.unsupported`,`This camera doesn't expose an on-board motion zones grid.`)}):ie?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`p`,{className:`${a} leading-relaxed`,children:(0,h.jsx)(r,{uiKey:`uiLibrary.motionZones.intro`,fallback:`Toggle <0>Edit grid</0> to paint the region directly on the live frame, then <1>Save</1> to push the mask to the camera. Pick a bigger <2>Cell size</2> for quicker, broad-stroke painting — it's resampled to the camera's native {{width}}×{{height}} grid on save (×1 is the finest).`,components:[(0,h.jsx)(`strong`,{className:`text-foreground`},`e`),(0,h.jsx)(`strong`,{className:`text-foreground`},`s`),(0,h.jsx)(`strong`,{className:`text-foreground`},`c`)],values:{width:d.grid.width,height:d.grid.height}})}),(0,h.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,h.jsx)(`button`,{type:`button`,onClick:()=>B(e=>!e),disabled:L,"aria-pressed":z,className:z?S:x,children:z?n(`uiLibrary.motionZones.doneEditing`,`Done editing`):n(`uiLibrary.motionZones.editGrid`,`Edit grid`)}),(0,h.jsx)(`button`,{type:`button`,onClick:()=>Z(!0),disabled:L,className:x,children:n(`uiLibrary.motionZones.allOn`,`All on`)}),(0,h.jsx)(`button`,{type:`button`,onClick:()=>Z(!1),disabled:L,className:x,children:n(`uiLibrary.motionZones.allOff`,`All off`)}),(0,h.jsx)(`button`,{type:`button`,onClick:ee,disabled:L,className:x,children:n(`uiLibrary.motionZones.invert`,`Invert`)}),(0,h.jsxs)(`div`,{className:`flex items-center gap-1 ml-1`,role:`group`,"aria-label":n(`uiLibrary.motionZones.cellSize`,`Cell size`),children:[(0,h.jsx)(`span`,{className:`${a} mr-0.5`,children:n(`uiLibrary.motionZones.cellSize`,`Cell size`)}),y.map(e=>(0,h.jsxs)(`button`,{type:`button`,onClick:()=>ne(e),disabled:L,"aria-pressed":F===e,title:e===1?n(`uiLibrary.motionZones.cameraGrid`,`Camera grid {{width}}×{{height}} (finest)`,{width:H,height:U}):n(`uiLibrary.motionZones.paintingGrid`,`{{width}}×{{height}} painting grid · cells ×{{factor}} bigger`,{width:T(H,e),height:T(U,e),factor:e}),className:F===e?S:x,children:[`×`,e]},e))]}),(0,h.jsxs)(`span`,{className:`${a} ml-1 tabular-nums`,children:[n(`uiLibrary.motionZones.cells`,`{{active}} / {{total}} cells · {{width}}×{{height}}`,{active:J,total:Y,width:d.grid.width,height:d.grid.height}),F===1?``:n(`uiLibrary.motionZones.paintSuffix`,` · paint {{width}}×{{height}}`,{width:W,height:G})]}),(0,h.jsx)(`span`,{className:`flex-1`}),(0,h.jsx)(`button`,{type:`button`,onClick:te,disabled:L||!q,className:`rounded-md border border-border bg-surface px-2 py-1 text-[11px] text-foreground-subtle hover:bg-surface-hover disabled:opacity-40 transition-colors`,children:n(`uiLibrary.motionZones.revert`,`Revert`)}),(0,h.jsx)(`button`,{type:`button`,onClick:()=>void re(),disabled:L||!q,className:S,children:L?n(`uiLibrary.motionZones.saving`,`Saving…`):n(`uiLibrary.motionZones.save`,`Save`)})]})]}):(0,h.jsx)(`p`,{className:`${a} leading-relaxed`,children:n(`uiLibrary.motionZones.loading`,`Loading the camera's grid…`)})})}):null}export{k as MotionZonesSettings};
@@ -1 +1 @@
1
- import{a as e,i as t,l as n,n as r,o as i}from"./scheduler-0XZJE03d.js";import{S as ee,_ as a,b as te,c as o,d as ne,g as s,l as c,p as re,t as l,v as u,w as d}from"./index-DWH0ZLxX.js";import{MaskShapeCanvas as ie}from"./MaskShapeCanvas-BTvl6Rin.js";var ae=d(`hexagon`,[[`path`,{d:`M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z`,key:`yt0hxn`}]]),oe=d(`mic-off`,[[`path`,{d:`M12 19v3`,key:`npa21l`}],[`path`,{d:`M15 9.34V5a3 3 0 0 0-5.68-1.33`,key:`1gzdoj`}],[`path`,{d:`M16.95 16.95A7 7 0 0 1 5 12v-2`,key:`cqa7eg`}],[`path`,{d:`M18.89 13.23A7 7 0 0 0 19 12v-2`,key:`16hl24`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M9 9v3a3 3 0 0 0 5.12 2.12`,key:`r2i35w`}]]),f=n(i(),1),p=`Microphone`,m=`The camera encodes no audio at all — live view, recordings, exports and the audio analyzer are all silent.`;function se(e){let t=e.supportsAudioMute===!0,n=t?e.audioEnabled:null,r=e.pendingOn??null;return{label:p,supported:t,on:n===null?null:r??n,available:t&&n!==null,costWhenOff:m}}function ce(e){return!e.available||e.on===null?null:{enabled:!e.on}}var h=n(e(),1),le=120,ue=`privacy-mask`,g=`rounded-md border border-border bg-surface px-2 py-1 text-[11px] font-medium text-foreground-subtle hover:bg-surface-hover disabled:opacity-40 transition-colors`,_=`rounded-md border border-primary/50 bg-primary/15 px-2.5 py-1 text-[11px] font-medium text-primary hover:bg-primary/25 disabled:opacity-40 transition-colors`;function v(e){return e.kind===`rect`||e.kind===`polygon`?e:null}function de(e){let t=new Set(e.map(e=>e.id)),n=0;for(;t.has(n);)n+=1;return n}function fe(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1)if(JSON.stringify(e[n])!==JSON.stringify(t[n]))return!1;return!0}function y({deviceId:e}){let n=t(),i=ne(s().trpcClient,e),[d,p]=(0,f.useState)(null),[m,y]=(0,f.useState)(!1),[b,x]=(0,f.useState)(!1),[S,C]=(0,f.useState)(null),[w,T]=(0,f.useState)(null),[E,D]=(0,f.useState)(!1),[O,k]=(0,f.useState)(!1),[A,j]=(0,f.useState)(null),[M,N]=(0,f.useState)(null),[pe,P]=(0,f.useState)(null),[F,I]=(0,f.useState)(null),[L,R]=(0,f.useState)(null),z=(0,f.useRef)(!1);(0,f.useEffect)(()=>{if(!i)return;let e=!1;return z.current=!1,p(null),y(!1),x(!1),C(null),T(null),k(!1),j(null),N(null),P(null),I(null),R(null),(async()=>{try{let t=await i.privacyMask?.getOptions({});if(e)return;if(!t)throw Error(`device proxy not ready`);if(p(t),z.current)return;let n=await i.privacyMask?.getStatus({});if(e)return;if(!n)throw Error(`device proxy not ready`);if(n.regions===null){x(!0),P(n.audioEnabled);return}z.current=!0;let r={enabled:n.enabled,regions:n.regions};T(r),C(r),P(n.audioEnabled)}catch(t){if(e)return;c(t)?y(!0):console.error(`Privacy Mask load failed`,t)}})(),()=>{e=!0}},[i]);let B=(0,f.useMemo)(()=>S!==null&&w!==null&&(S.enabled!==w.enabled||!fe(S.regions,w.regions)),[S,w]),V=S?S.regions.length:0,H=d?d.maxRegions:0,U=(0,f.useRef)(0);(0,f.useEffect)(()=>{U.current=H},[H]);let W=H>0&&V>=H,me=(0,f.useCallback)(()=>{C(e=>e&&{...e,enabled:!e.enabled})},[]),G=(0,f.useCallback)(e=>{j(typeof e==`number`?e:null)},[]),K=(0,f.useMemo)(()=>S?S.regions.map(e=>({id:e.id,shape:e.shape,enabled:e.enabled,label:n(`uiLibrary.privacyMaskSettings.zoneN`,`Zone {{id}}`,{id:e.id})})):[],[S,n]),q=(0,f.useCallback)((e,t)=>{let n=v(t);n&&C(t=>t&&{...t,regions:t.regions.map(t=>t.id===e?{...t,shape:n}:t)})},[]),J=(0,f.useCallback)(e=>{let t=v(e);t&&(N(null),C(e=>{if(!e)return e;let n=U.current;if(n>0&&e.regions.length>=n)return e;let r=de(e.regions),i={id:r,enabled:!0,shape:t};return j(r),{...e,regions:[...e.regions,i]}}))},[]),Y=(0,f.useCallback)(e=>{k(!0),j(null),N(e)},[]),he=(0,f.useCallback)(e=>{k(!0),N(null),j(e)},[]),ge=(0,f.useCallback)(e=>{j(t=>t===e?null:t),C(t=>t&&{...t,regions:t.regions.filter(t=>t.id!==e)})},[]),_e=(0,f.useCallback)(()=>{N(null),j(null),w&&C({enabled:w.enabled,regions:w.regions})},[w]),X=(0,f.useCallback)(async()=>{if(!(!i||!S)){D(!0);try{await i.privacyMask?.setMask({patch:{enabled:S.enabled,regions:[...S.regions]}});let e=await i.privacyMask?.getStatus({});if(e&&e.regions!==null){let t={enabled:e.enabled,regions:e.regions};T(t),C(t)}}catch(e){console.error(`Privacy Mask save failed`,e)}finally{D(!1)}}},[i,S]),Z=se({supportsAudioMute:d===null?null:d.supportsAudioMute,audioEnabled:pe,pendingOn:F}),ve=(0,f.useCallback)(async()=>{let e=ce(Z);if(!(!i||e===null)){I(e.enabled),R(null);try{await i.privacyMask?.setAudioEnabled(e);let t=await i.privacyMask?.getStatus({});t&&P(t.audioEnabled)}catch(e){console.error(`Privacy microphone write failed — reverting`,e),R(e instanceof Error?e.message:String(e))}finally{I(null)}}},[i,Z]),ye=(0,f.useCallback)(()=>{k(e=>(e&&(N(null),j(null)),!e))},[]),Q=d?.supportedShapes??[];l((0,f.useMemo)(()=>O&&!m&&d&&S?{id:ue,order:le,node:(0,h.jsx)(ie,{transparent:!0,items:K,supportedShapes:Q,polygonVertices:d.polygonVertices,selectedId:A,onSelect:G,onShapeChange:q,onDrawComplete:J,drawingKind:M})}:null,[O,m,d,S,K,Q,A,G,q,J,M]));let be=d?.supportedShapes.includes(`rect`)??!1,xe=d?.supportedShapes.includes(`polygon`)??!1,$=d!==null&&(d.maxRegions<=0||d.supportedShapes.length===0),Se=!m&&!$&&!b&&d!==null&&S!==null;return i?(0,h.jsx)(re,{title:n(`uiLibrary.privacyMaskSettings.title`,`Privacy Mask`),icon:(0,h.jsx)(ee,{className:`h-3.5 w-3.5 text-foreground-subtle`}),children:(0,h.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[m||$?(0,h.jsx)(`p`,{className:`${o} leading-relaxed`,children:n(`uiLibrary.privacyMaskSettings.unsupported`,`This camera doesn't support an on-board privacy mask.`)}):b?(0,h.jsx)(`p`,{className:`${o} leading-relaxed`,children:n(`uiLibrary.privacyMaskSettings.unreadable`,`This camera hasn't answered, so what it currently masks is unknown — the editor stays closed rather than showing an empty frame you could save over. A battery camera answers once it wakes; otherwise check that it is reachable.`)}):Se?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`p`,{className:`${o} leading-relaxed`,children:(0,h.jsx)(r,{uiKey:`uiLibrary.privacyMaskSettings.help`,fallback:`Toggle <0>Edit mask</0> to draw blanked-out zones on the live frame, then <1>Save</1> to push them to the camera. Drag a rectangle to move, its corner to resize; drag polygon vertices, click an edge midpoint to add one, or right-click a vertex to remove it.`,components:[(0,h.jsx)(`strong`,{className:`text-foreground`},`edit`),(0,h.jsx)(`strong`,{className:`text-foreground`},`save`)]})}),(0,h.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,h.jsx)(`button`,{type:`button`,onClick:ye,disabled:E,"aria-pressed":O,className:O?_:g,children:O?n(`uiLibrary.privacyMaskSettings.doneEditing`,`Done editing`):n(`uiLibrary.privacyMaskSettings.editMask`,`Edit mask`)}),(0,h.jsx)(`button`,{type:`button`,onClick:me,disabled:E,"aria-pressed":S.enabled,className:S.enabled?_:g,children:S.enabled?n(`uiLibrary.privacyMaskSettings.maskOn`,`Mask on`):n(`uiLibrary.privacyMaskSettings.maskOff`,`Mask off`)}),be&&(0,h.jsx)(`button`,{type:`button`,onClick:()=>Y(`rect`),disabled:E||W,"aria-pressed":M===`rect`,className:M===`rect`?_:g,title:W?n(`uiLibrary.privacyMaskSettings.maxZones`,`Maximum zones reached`):n(`uiLibrary.privacyMaskSettings.addRect`,`Add a rectangle zone`),children:n(`uiLibrary.privacyMaskSettings.rectButton`,`+ Rect`)}),xe&&(0,h.jsx)(`button`,{type:`button`,onClick:()=>Y(`polygon`),disabled:E||W,"aria-pressed":M===`polygon`,className:M===`polygon`?_:g,title:W?n(`uiLibrary.privacyMaskSettings.maxZones`,`Maximum zones reached`):n(`uiLibrary.privacyMaskSettings.addPolygon`,`Add a polygon zone`),children:n(`uiLibrary.privacyMaskSettings.polygonButton`,`+ Polygon`)}),(0,h.jsx)(`span`,{className:`${o} ml-1 tabular-nums`,children:n(`uiLibrary.privacyMaskSettings.zoneCount`,`{{active}} / {{max}} zones`,{active:V,max:H})}),(0,h.jsx)(`span`,{className:`flex-1`}),(0,h.jsx)(`button`,{type:`button`,onClick:_e,disabled:E||!B,className:`rounded-md border border-border bg-surface px-2 py-1 text-[11px] text-foreground-subtle hover:bg-surface-hover disabled:opacity-40 transition-colors`,children:n(`uiLibrary.privacyMaskSettings.revert`,`Revert`)}),(0,h.jsx)(`button`,{type:`button`,onClick:()=>void X(),disabled:E||!B,className:_,children:E?n(`uiLibrary.privacyMaskSettings.saving`,`Saving…`):n(`uiLibrary.privacyMaskSettings.save`,`Save`)})]}),V>0?(0,h.jsx)(`div`,{className:`flex flex-col gap-1`,children:S.regions.map(e=>{let t=A===e.id,r=e.shape.kind===`polygon`?ae:u;return(0,h.jsxs)(`div`,{className:`flex items-center gap-2 rounded-md border px-2 py-1 transition-colors ${t?`border-primary/50 bg-primary/10`:`border-border bg-surface`}`,children:[(0,h.jsxs)(`button`,{type:`button`,onClick:()=>he(e.id),disabled:E,className:`flex flex-1 items-center gap-2 text-left text-[11px] font-medium text-foreground-subtle hover:text-foreground disabled:opacity-40 transition-colors`,children:[(0,h.jsx)(r,{className:`h-3.5 w-3.5 shrink-0`}),(0,h.jsx)(`span`,{children:n(`uiLibrary.privacyMaskSettings.zoneN`,`Zone {{id}}`,{id:e.id})}),(0,h.jsx)(`span`,{className:`text-foreground-faint capitalize`,children:e.shape.kind})]}),(0,h.jsx)(`button`,{type:`button`,onClick:()=>ge(e.id),disabled:E,"aria-label":n(`uiLibrary.privacyMaskSettings.deleteZoneN`,`Delete zone {{id}}`,{id:e.id}),title:n(`uiLibrary.privacyMaskSettings.deleteZone`,`Delete zone`),className:`inline-flex h-6 w-6 items-center justify-center rounded border border-border bg-surface text-foreground-subtle hover:border-red-400/40 hover:bg-red-500/10 hover:text-red-400 disabled:opacity-40 transition-colors`,children:(0,h.jsx)(a,{className:`h-3.5 w-3.5`})})]},e.id)})}):null]}):(0,h.jsx)(`p`,{className:`${o} leading-relaxed`,children:n(`uiLibrary.privacyMaskSettings.loading`,`Loading the camera's privacy mask…`)}),Z.supported&&(0,h.jsxs)(`div`,{className:`flex items-start gap-3 rounded-md border border-border bg-surface px-2 py-2`,children:[(0,h.jsx)(`button`,{type:`button`,role:`switch`,"aria-label":Z.label,"aria-checked":Z.on===!0,disabled:!Z.available||F!==null,onClick:()=>void ve(),title:Z.on===null?n(`uiLibrary.privacyMaskSettings.micTitleUnknown`,`Microphone — state unknown; the camera did not answer.`):Z.on?n(`uiLibrary.privacyMaskSettings.micTitleOn`,`The camera is capturing sound. Turning it off: {{cost}}`,{cost:Z.costWhenOff}):n(`uiLibrary.privacyMaskSettings.micTitleOff`,`The camera is silent. {{cost}}`,{cost:Z.costWhenOff}),className:Z.on===!1||Z.on===null?g:_,children:(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[Z.on===!1?(0,h.jsx)(oe,{className:`h-3.5 w-3.5`}):(0,h.jsx)(te,{className:`h-3.5 w-3.5`}),Z.on===null?n(`uiLibrary.privacyMaskSettings.micUnknown`,`Microphone unknown`):Z.on?n(`uiLibrary.privacyMaskSettings.micOn`,`Microphone on`):n(`uiLibrary.privacyMaskSettings.micOff`,`Microphone off`)]})}),(0,h.jsx)(`p`,{className:`text-[10px] text-foreground-subtle flex-1 leading-relaxed`,children:L===null?Z.on===null?n(`uiLibrary.privacyMaskSettings.micNotReported`,`The camera did not report its microphone, so this state is unknown.`):Z.costWhenOff:n(`uiLibrary.privacyMaskSettings.writeFailed`,`Write failed: {{reason}}`,{reason:L})})]})]})}):null}export{y as PrivacyMaskSettings};
1
+ import{a as e,i as t,l as n,n as r,o as i}from"./scheduler-0XZJE03d.js";import{S as ee,_ as a,b as te,c as o,d as ne,g as s,l as c,p as re,t as l,v as u,w as d}from"./index-KdTdngTk.js";import{MaskShapeCanvas as ie}from"./MaskShapeCanvas-BTvl6Rin.js";var ae=d(`hexagon`,[[`path`,{d:`M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z`,key:`yt0hxn`}]]),oe=d(`mic-off`,[[`path`,{d:`M12 19v3`,key:`npa21l`}],[`path`,{d:`M15 9.34V5a3 3 0 0 0-5.68-1.33`,key:`1gzdoj`}],[`path`,{d:`M16.95 16.95A7 7 0 0 1 5 12v-2`,key:`cqa7eg`}],[`path`,{d:`M18.89 13.23A7 7 0 0 0 19 12v-2`,key:`16hl24`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M9 9v3a3 3 0 0 0 5.12 2.12`,key:`r2i35w`}]]),f=n(i(),1),p=`Microphone`,m=`The camera encodes no audio at all — live view, recordings, exports and the audio analyzer are all silent.`;function se(e){let t=e.supportsAudioMute===!0,n=t?e.audioEnabled:null,r=e.pendingOn??null;return{label:p,supported:t,on:n===null?null:r??n,available:t&&n!==null,costWhenOff:m}}function ce(e){return!e.available||e.on===null?null:{enabled:!e.on}}var h=n(e(),1),le=120,ue=`privacy-mask`,g=`rounded-md border border-border bg-surface px-2 py-1 text-[11px] font-medium text-foreground-subtle hover:bg-surface-hover disabled:opacity-40 transition-colors`,_=`rounded-md border border-primary/50 bg-primary/15 px-2.5 py-1 text-[11px] font-medium text-primary hover:bg-primary/25 disabled:opacity-40 transition-colors`;function v(e){return e.kind===`rect`||e.kind===`polygon`?e:null}function de(e){let t=new Set(e.map(e=>e.id)),n=0;for(;t.has(n);)n+=1;return n}function fe(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1)if(JSON.stringify(e[n])!==JSON.stringify(t[n]))return!1;return!0}function y({deviceId:e}){let n=t(),i=ne(s().trpcClient,e),[d,p]=(0,f.useState)(null),[m,y]=(0,f.useState)(!1),[b,x]=(0,f.useState)(!1),[S,C]=(0,f.useState)(null),[w,T]=(0,f.useState)(null),[E,D]=(0,f.useState)(!1),[O,k]=(0,f.useState)(!1),[A,j]=(0,f.useState)(null),[M,N]=(0,f.useState)(null),[pe,P]=(0,f.useState)(null),[F,I]=(0,f.useState)(null),[L,R]=(0,f.useState)(null),z=(0,f.useRef)(!1);(0,f.useEffect)(()=>{if(!i)return;let e=!1;return z.current=!1,p(null),y(!1),x(!1),C(null),T(null),k(!1),j(null),N(null),P(null),I(null),R(null),(async()=>{try{let t=await i.privacyMask?.getOptions({});if(e)return;if(!t)throw Error(`device proxy not ready`);if(p(t),z.current)return;let n=await i.privacyMask?.getStatus({});if(e)return;if(!n)throw Error(`device proxy not ready`);if(n.regions===null){x(!0),P(n.audioEnabled);return}z.current=!0;let r={enabled:n.enabled,regions:n.regions};T(r),C(r),P(n.audioEnabled)}catch(t){if(e)return;c(t)?y(!0):console.error(`Privacy Mask load failed`,t)}})(),()=>{e=!0}},[i]);let B=(0,f.useMemo)(()=>S!==null&&w!==null&&(S.enabled!==w.enabled||!fe(S.regions,w.regions)),[S,w]),V=S?S.regions.length:0,H=d?d.maxRegions:0,U=(0,f.useRef)(0);(0,f.useEffect)(()=>{U.current=H},[H]);let W=H>0&&V>=H,me=(0,f.useCallback)(()=>{C(e=>e&&{...e,enabled:!e.enabled})},[]),G=(0,f.useCallback)(e=>{j(typeof e==`number`?e:null)},[]),K=(0,f.useMemo)(()=>S?S.regions.map(e=>({id:e.id,shape:e.shape,enabled:e.enabled,label:n(`uiLibrary.privacyMaskSettings.zoneN`,`Zone {{id}}`,{id:e.id})})):[],[S,n]),q=(0,f.useCallback)((e,t)=>{let n=v(t);n&&C(t=>t&&{...t,regions:t.regions.map(t=>t.id===e?{...t,shape:n}:t)})},[]),J=(0,f.useCallback)(e=>{let t=v(e);t&&(N(null),C(e=>{if(!e)return e;let n=U.current;if(n>0&&e.regions.length>=n)return e;let r=de(e.regions),i={id:r,enabled:!0,shape:t};return j(r),{...e,regions:[...e.regions,i]}}))},[]),Y=(0,f.useCallback)(e=>{k(!0),j(null),N(e)},[]),he=(0,f.useCallback)(e=>{k(!0),N(null),j(e)},[]),ge=(0,f.useCallback)(e=>{j(t=>t===e?null:t),C(t=>t&&{...t,regions:t.regions.filter(t=>t.id!==e)})},[]),_e=(0,f.useCallback)(()=>{N(null),j(null),w&&C({enabled:w.enabled,regions:w.regions})},[w]),X=(0,f.useCallback)(async()=>{if(!(!i||!S)){D(!0);try{await i.privacyMask?.setMask({patch:{enabled:S.enabled,regions:[...S.regions]}});let e=await i.privacyMask?.getStatus({});if(e&&e.regions!==null){let t={enabled:e.enabled,regions:e.regions};T(t),C(t)}}catch(e){console.error(`Privacy Mask save failed`,e)}finally{D(!1)}}},[i,S]),Z=se({supportsAudioMute:d===null?null:d.supportsAudioMute,audioEnabled:pe,pendingOn:F}),ve=(0,f.useCallback)(async()=>{let e=ce(Z);if(!(!i||e===null)){I(e.enabled),R(null);try{await i.privacyMask?.setAudioEnabled(e);let t=await i.privacyMask?.getStatus({});t&&P(t.audioEnabled)}catch(e){console.error(`Privacy microphone write failed — reverting`,e),R(e instanceof Error?e.message:String(e))}finally{I(null)}}},[i,Z]),ye=(0,f.useCallback)(()=>{k(e=>(e&&(N(null),j(null)),!e))},[]),Q=d?.supportedShapes??[];l((0,f.useMemo)(()=>O&&!m&&d&&S?{id:ue,order:le,node:(0,h.jsx)(ie,{transparent:!0,items:K,supportedShapes:Q,polygonVertices:d.polygonVertices,selectedId:A,onSelect:G,onShapeChange:q,onDrawComplete:J,drawingKind:M})}:null,[O,m,d,S,K,Q,A,G,q,J,M]));let be=d?.supportedShapes.includes(`rect`)??!1,xe=d?.supportedShapes.includes(`polygon`)??!1,$=d!==null&&(d.maxRegions<=0||d.supportedShapes.length===0),Se=!m&&!$&&!b&&d!==null&&S!==null;return i?(0,h.jsx)(re,{title:n(`uiLibrary.privacyMaskSettings.title`,`Privacy Mask`),icon:(0,h.jsx)(ee,{className:`h-3.5 w-3.5 text-foreground-subtle`}),children:(0,h.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[m||$?(0,h.jsx)(`p`,{className:`${o} leading-relaxed`,children:n(`uiLibrary.privacyMaskSettings.unsupported`,`This camera doesn't support an on-board privacy mask.`)}):b?(0,h.jsx)(`p`,{className:`${o} leading-relaxed`,children:n(`uiLibrary.privacyMaskSettings.unreadable`,`This camera hasn't answered, so what it currently masks is unknown — the editor stays closed rather than showing an empty frame you could save over. A battery camera answers once it wakes; otherwise check that it is reachable.`)}):Se?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`p`,{className:`${o} leading-relaxed`,children:(0,h.jsx)(r,{uiKey:`uiLibrary.privacyMaskSettings.help`,fallback:`Toggle <0>Edit mask</0> to draw blanked-out zones on the live frame, then <1>Save</1> to push them to the camera. Drag a rectangle to move, its corner to resize; drag polygon vertices, click an edge midpoint to add one, or right-click a vertex to remove it.`,components:[(0,h.jsx)(`strong`,{className:`text-foreground`},`edit`),(0,h.jsx)(`strong`,{className:`text-foreground`},`save`)]})}),(0,h.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,h.jsx)(`button`,{type:`button`,onClick:ye,disabled:E,"aria-pressed":O,className:O?_:g,children:O?n(`uiLibrary.privacyMaskSettings.doneEditing`,`Done editing`):n(`uiLibrary.privacyMaskSettings.editMask`,`Edit mask`)}),(0,h.jsx)(`button`,{type:`button`,onClick:me,disabled:E,"aria-pressed":S.enabled,className:S.enabled?_:g,children:S.enabled?n(`uiLibrary.privacyMaskSettings.maskOn`,`Mask on`):n(`uiLibrary.privacyMaskSettings.maskOff`,`Mask off`)}),be&&(0,h.jsx)(`button`,{type:`button`,onClick:()=>Y(`rect`),disabled:E||W,"aria-pressed":M===`rect`,className:M===`rect`?_:g,title:W?n(`uiLibrary.privacyMaskSettings.maxZones`,`Maximum zones reached`):n(`uiLibrary.privacyMaskSettings.addRect`,`Add a rectangle zone`),children:n(`uiLibrary.privacyMaskSettings.rectButton`,`+ Rect`)}),xe&&(0,h.jsx)(`button`,{type:`button`,onClick:()=>Y(`polygon`),disabled:E||W,"aria-pressed":M===`polygon`,className:M===`polygon`?_:g,title:W?n(`uiLibrary.privacyMaskSettings.maxZones`,`Maximum zones reached`):n(`uiLibrary.privacyMaskSettings.addPolygon`,`Add a polygon zone`),children:n(`uiLibrary.privacyMaskSettings.polygonButton`,`+ Polygon`)}),(0,h.jsx)(`span`,{className:`${o} ml-1 tabular-nums`,children:n(`uiLibrary.privacyMaskSettings.zoneCount`,`{{active}} / {{max}} zones`,{active:V,max:H})}),(0,h.jsx)(`span`,{className:`flex-1`}),(0,h.jsx)(`button`,{type:`button`,onClick:_e,disabled:E||!B,className:`rounded-md border border-border bg-surface px-2 py-1 text-[11px] text-foreground-subtle hover:bg-surface-hover disabled:opacity-40 transition-colors`,children:n(`uiLibrary.privacyMaskSettings.revert`,`Revert`)}),(0,h.jsx)(`button`,{type:`button`,onClick:()=>void X(),disabled:E||!B,className:_,children:E?n(`uiLibrary.privacyMaskSettings.saving`,`Saving…`):n(`uiLibrary.privacyMaskSettings.save`,`Save`)})]}),V>0?(0,h.jsx)(`div`,{className:`flex flex-col gap-1`,children:S.regions.map(e=>{let t=A===e.id,r=e.shape.kind===`polygon`?ae:u;return(0,h.jsxs)(`div`,{className:`flex items-center gap-2 rounded-md border px-2 py-1 transition-colors ${t?`border-primary/50 bg-primary/10`:`border-border bg-surface`}`,children:[(0,h.jsxs)(`button`,{type:`button`,onClick:()=>he(e.id),disabled:E,className:`flex flex-1 items-center gap-2 text-left text-[11px] font-medium text-foreground-subtle hover:text-foreground disabled:opacity-40 transition-colors`,children:[(0,h.jsx)(r,{className:`h-3.5 w-3.5 shrink-0`}),(0,h.jsx)(`span`,{children:n(`uiLibrary.privacyMaskSettings.zoneN`,`Zone {{id}}`,{id:e.id})}),(0,h.jsx)(`span`,{className:`text-foreground-faint capitalize`,children:e.shape.kind})]}),(0,h.jsx)(`button`,{type:`button`,onClick:()=>ge(e.id),disabled:E,"aria-label":n(`uiLibrary.privacyMaskSettings.deleteZoneN`,`Delete zone {{id}}`,{id:e.id}),title:n(`uiLibrary.privacyMaskSettings.deleteZone`,`Delete zone`),className:`inline-flex h-6 w-6 items-center justify-center rounded border border-border bg-surface text-foreground-subtle hover:border-red-400/40 hover:bg-red-500/10 hover:text-red-400 disabled:opacity-40 transition-colors`,children:(0,h.jsx)(a,{className:`h-3.5 w-3.5`})})]},e.id)})}):null]}):(0,h.jsx)(`p`,{className:`${o} leading-relaxed`,children:n(`uiLibrary.privacyMaskSettings.loading`,`Loading the camera's privacy mask…`)}),Z.supported&&(0,h.jsxs)(`div`,{className:`flex items-start gap-3 rounded-md border border-border bg-surface px-2 py-2`,children:[(0,h.jsx)(`button`,{type:`button`,role:`switch`,"aria-label":Z.label,"aria-checked":Z.on===!0,disabled:!Z.available||F!==null,onClick:()=>void ve(),title:Z.on===null?n(`uiLibrary.privacyMaskSettings.micTitleUnknown`,`Microphone — state unknown; the camera did not answer.`):Z.on?n(`uiLibrary.privacyMaskSettings.micTitleOn`,`The camera is capturing sound. Turning it off: {{cost}}`,{cost:Z.costWhenOff}):n(`uiLibrary.privacyMaskSettings.micTitleOff`,`The camera is silent. {{cost}}`,{cost:Z.costWhenOff}),className:Z.on===!1||Z.on===null?g:_,children:(0,h.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[Z.on===!1?(0,h.jsx)(oe,{className:`h-3.5 w-3.5`}):(0,h.jsx)(te,{className:`h-3.5 w-3.5`}),Z.on===null?n(`uiLibrary.privacyMaskSettings.micUnknown`,`Microphone unknown`):Z.on?n(`uiLibrary.privacyMaskSettings.micOn`,`Microphone on`):n(`uiLibrary.privacyMaskSettings.micOff`,`Microphone off`)]})}),(0,h.jsx)(`p`,{className:`text-[10px] text-foreground-subtle flex-1 leading-relaxed`,children:L===null?Z.on===null?n(`uiLibrary.privacyMaskSettings.micNotReported`,`The camera did not report its microphone, so this state is unknown.`):Z.costWhenOff:n(`uiLibrary.privacyMaskSettings.writeFailed`,`Write failed: {{reason}}`,{reason:L})})]})]})}):null}export{y as PrivacyMaskSettings};
@@ -1 +1 @@
1
- import{a as e,i as t,l as n,n as r,o as i}from"./scheduler-0XZJE03d.js";import{C as a,_ as o,a as s,c,d as l,f as u,g as d,h as f,i as p,l as m,m as h,n as g,o as _,r as v,s as y,u as b,w as x,x as S,y as C}from"./index-DWH0ZLxX.js";import{MaskShapeCanvas as w}from"./MaskShapeCanvas-BTvl6Rin.js";var T=x(`settings-2`,[[`path`,{d:`M14 17H5`,key:`gfn3mx`}],[`path`,{d:`M19 7h-9`,key:`6i9tg`}],[`circle`,{cx:`17`,cy:`17`,r:`3`,key:`18b49y`}],[`circle`,{cx:`7`,cy:`7`,r:`3`,key:`dfmy0x`}]]),E=n(i(),1),D=n(e(),1),O=h(`/addon/pipeline-analytics/event-media`);function k(e){return`${O}/m/${e}`}function A(e){let t=new Map;for(let n of e.states)n.references.forEach((e,r)=>{let i=t.get(e.condition)??[];i.push({stateId:n.id,index:r,reference:e}),t.set(e.condition,i)});return[...t.entries()].map(([e,t])=>({condition:e,tiles:[...t].sort((e,t)=>t.reference.capturedAt-e.reference.capturedAt)})).sort((e,t)=>e.condition.localeCompare(t.condition))}function j(e){return e.states.reduce((e,t)=>e+t.references.length,0)}var M=`rounded border border-danger/50 bg-danger/10 px-1 py-0.5 text-[10px] font-medium text-danger hover:bg-danger/20 disabled:opacity-40 transition-colors`;function N({monitor:e,disabled:n,onDelete:r}){let i=t(),a=A(e),s=j(e),l=f();return a.length===0?(0,D.jsx)(`p`,{className:`${c} leading-relaxed`,children:i(`uiLibrary.sceneReferenceGallery.empty`,`No photographs captured yet. Press “Capture daylight” to take the one this scene will judge everything against.`)}):(0,D.jsx)(`div`,{className:`flex flex-col gap-2`,children:a.map(e=>(0,D.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,D.jsxs)(`p`,{className:`text-[10px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:[y(e.condition,i),` · `,e.tiles.length]}),(0,D.jsx)(`ul`,{className:`flex flex-wrap gap-1.5`,children:e.tiles.map(t=>{let a=`${t.stateId}:${String(t.index)}`,u=s===1;return(0,D.jsxs)(`li`,{className:`flex w-24 flex-col gap-1 rounded-md border border-border p-1`,children:[(0,D.jsx)(P,{reference:t.reference}),(0,D.jsx)(`span`,{className:`${c} tabular-nums`,children:F(t.reference.capturedAt)}),(0,D.jsxs)(`button`,{type:`button`,className:M,disabled:n,"aria-label":i(`uiLibrary.sceneReferenceGallery.deleteLabel`,`Delete the {{variant}} photograph from {{date}}`,{variant:y(e.condition,i).toLowerCase(),date:F(t.reference.capturedAt)}),onClick:()=>{(async()=>{u&&!await l({title:i(`uiLibrary.sceneReferenceGallery.deleteTitle`,`Delete the only photograph?`),message:i(`uiLibrary.sceneReferenceGallery.lastWarning`,`This is the only photograph this scene has. Delete it and the scene no longer knows what normal looks like — it stops judging until you capture again.`),confirmLabel:i(`uiLibrary.sceneReferenceGallery.delete`,`Delete`),variant:`danger`})||r({stateId:t.stateId,index:t.index})})()},children:[(0,D.jsx)(o,{className:`mr-1 inline h-3 w-3`}),i(`uiLibrary.sceneReferenceGallery.delete`,`Delete`)]})]},a)})})]},e.condition))})}function P({reference:e}){let n=t(),[r,i]=(0,E.useState)(!1),a=e.thumbnailMediaId;return a===void 0||r?(0,D.jsxs)(`div`,{className:`flex h-16 w-full flex-col items-center justify-center gap-0.5 rounded bg-surface text-foreground-subtle`,title:n(`uiLibrary.sceneReferenceGallery.missingPicture`,`The picture for this reference is no longer stored. The reference itself is intact and still being scored against.`),children:[(0,D.jsx)(S,{className:`h-4 w-4`}),(0,D.jsx)(`span`,{className:`text-[9px]`,children:n(`uiLibrary.sceneReferenceGallery.noPicture`,`no picture`)})]}):(0,D.jsx)(`img`,{src:k(a),alt:``,loading:`lazy`,className:`h-16 w-full rounded object-cover`,onError:()=>i(!0)})}function F(e){let t=new Date(e);return`${t.toLocaleDateString()} ${t.toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`})}`}var I=`rounded-md border border-border bg-surface px-2 py-1 text-[11px] text-foreground focus:border-primary focus:outline-none disabled:opacity-50`,L=`text-[10px] font-medium text-foreground-subtle`,R=`flex flex-col gap-2 rounded-md border border-border bg-surface/40 p-2`,z=`text-[10px] font-semibold uppercase tracking-wide text-foreground-subtle`,B=5,V=3600;function H(e,t){switch(e){case`periodic`:return t(`uiLibrary.sceneSettingsForm.triggerHintPeriodic`,`Only on the clock. Predictable, and it notices a change even on a camera nothing ever moves in front of.`);case`on-motion`:return t(`uiLibrary.sceneSettingsForm.triggerHintOnMotion`,`Only after the camera has been still again for the quiet window below. Cheapest, but a change nobody walks past is never seen.`);case`both`:return t(`uiLibrary.sceneSettingsForm.triggerHintBoth`,`Both — the clock is the safety net that lets the motion path miss. This is the right answer for almost every scene.`)}}function U(e,t){switch(e){case`skip`:return t(`uiLibrary.sceneSettingsForm.uncoveredHintSkip`,`Sit that light out. No verdict, no alarm, no flag touched — it picks itself back up when a light it knows returns. This is why the night capture is optional.`);case`judge-anyway`:return t(`uiLibrary.sceneSettingsForm.uncoveredHintJudge`,`Compare against the references you do have. Only correct when the two lights genuinely look alike (a floodlit driveway, an indoor lamp) — against a real infrared frame it will report a change that did not happen.`)}}function W(e){return{label:e.label,checkIntervalSec:e.checkIntervalSec??60,threshold:e.check.mode===`similarity`?e.check.threshold:.8,hysteresisCount:e.check.hysteresisCount,quietSeconds:e.quietSeconds,minObservationSpacingSec:e.minObservationSpacingSec,confirmPrompt:e.confirm?.prompt??``}}function G({monitor:e,disabled:n,onPatch:i}){let a=t(),[o,s]=(0,E.useState)(()=>W(e)),[l,u]=(0,E.useState)(!1);(0,E.useEffect)(()=>{l||s(W(e))},[e,l]);let d=e=>{u(!1),i(e)},f=t=>e.check.mode===`similarity`?{mode:`similarity`,threshold:t.threshold??e.check.threshold,hysteresisCount:t.hysteresisCount??e.check.hysteresisCount}:{...e.check,hysteresisCount:t.hysteresisCount??e.check.hysteresisCount},p=e.confirm?.enabled===!0,m=e.check.mode===`similarity`?e.check.threshold:null;return(0,D.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,D.jsxs)(`div`,{className:R,children:[(0,D.jsx)(`p`,{className:z,children:a(`uiLibrary.sceneSettingsForm.whatItWatches`,`What it watches`)}),(0,D.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,D.jsx)(`span`,{className:L,children:a(`uiLibrary.sceneSettingsForm.name`,`Name`)}),(0,D.jsx)(`input`,{type:`text`,value:o.label,disabled:n,className:I,onFocus:()=>u(!0),onChange:e=>s(t=>({...t,label:e.target.value})),onBlur:()=>{let t=o.label.trim();t.length>0&&t!==e.label?d({label:t}):u(!1)}})]}),(0,D.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,D.jsx)(`input`,{type:`checkbox`,checked:e.enabled,disabled:n,onChange:e=>d({enabled:e.target.checked})}),(0,D.jsx)(`span`,{className:L,children:a(`uiLibrary.sceneSettingsForm.watching`,`Watching`)})]}),(0,D.jsx)(`p`,{className:c,children:a(`uiLibrary.sceneSettingsForm.watchingHint`,`Turned off, the scene keeps its region, its references and its flag — it simply stops checking. Nothing is lost by pausing one for a while.`)}),(0,D.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,D.jsx)(`span`,{className:L,children:a(`uiLibrary.sceneSettingsForm.whenToLook`,`When to look`)}),(0,D.jsxs)(`select`,{value:e.triggerMode,disabled:n,className:I,onChange:e=>{let t=e.target.value;(t===`periodic`||t===`on-motion`||t===`both`)&&d({triggerMode:t})},children:[(0,D.jsx)(`option`,{value:`both`,children:a(`uiLibrary.sceneSettingsForm.triggerBoth`,`On the clock and after motion settles`)}),(0,D.jsx)(`option`,{value:`periodic`,children:a(`uiLibrary.sceneSettingsForm.triggerPeriodic`,`On the clock only`)}),(0,D.jsx)(`option`,{value:`on-motion`,children:a(`uiLibrary.sceneSettingsForm.triggerOnMotion`,`After motion settles only`)})]})]}),(0,D.jsx)(`p`,{className:c,children:H(e.triggerMode,a)}),(0,D.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,D.jsx)(`span`,{className:L,children:a(`uiLibrary.sceneSettingsForm.checkEvery`,`Check every (seconds)`)}),(0,D.jsx)(`input`,{type:`number`,min:B,max:V,value:o.checkIntervalSec,disabled:n,className:I,onFocus:()=>u(!0),onChange:e=>s(t=>({...t,checkIntervalSec:Number(e.target.value)||0})),onBlur:()=>{let t=K(o.checkIntervalSec,B,V);t===e.checkIntervalSec?u(!1):d({checkIntervalSec:t})}})]}),(0,D.jsx)(`p`,{className:c,children:a(`uiLibrary.sceneSettingsForm.intervalHint`,`60 s suits “is the bin still out”. Every check costs one photograph and one encode, so going below about 30 s buys latency you almost never need and multiplies the cost by the number of scenes you own.`)})]}),(0,D.jsxs)(`div`,{className:R,children:[(0,D.jsx)(`p`,{className:z,children:a(`uiLibrary.sceneSettingsForm.howSure`,`How sure it has to be`)}),e.check.mode===`similarity`&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,D.jsx)(`span`,{className:L,children:(0,D.jsx)(r,{uiKey:`uiLibrary.sceneSettingsForm.matchThreshold`,fallback:`Match threshold — <0>{{value}}</0>`,components:[(0,D.jsx)(`span`,{className:`tabular-nums`},`value`)],values:{value:o.threshold.toFixed(2)}})}),(0,D.jsx)(`input`,{type:`range`,min:.3,max:.99,step:.01,value:o.threshold,disabled:n,onFocus:()=>u(!0),onChange:e=>s(t=>({...t,threshold:Number(e.target.value)})),onMouseUp:()=>{o.threshold===m?u(!1):d({check:f({threshold:o.threshold})})},onBlur:()=>{o.threshold===m?u(!1):d({check:f({threshold:o.threshold})})}})]}),(0,D.jsx)(`p`,{className:`text-[10px] text-foreground-subtle`,children:a(`uiLibrary.sceneSettingsForm.thresholdHint`,`How closely the region still has to resemble the photograph to count as unchanged. Higher means fussier: at 0.95 a passing cloud can read as a change; at 0.60 the bin can be taken and the scene will shrug. 0.80 is a sensible start — if it cries wolf, lower it; if it misses the thing you care about, raise it.`)})]}),(0,D.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,D.jsx)(`span`,{className:L,children:a(`uiLibrary.sceneSettingsForm.agreeingChecks`,`Agreeing checks before it changes its mind`)}),(0,D.jsx)(`input`,{type:`number`,min:1,max:10,value:o.hysteresisCount,disabled:n,className:I,onFocus:()=>u(!0),onChange:e=>s(t=>({...t,hysteresisCount:Number(e.target.value)||1})),onBlur:()=>{let t=K(o.hysteresisCount,1,10);t===e.check.hysteresisCount?u(!1):d({check:f({hysteresisCount:t})})}})]}),(0,D.jsx)(`p`,{className:c,children:a(`uiLibrary.sceneSettingsForm.agreeingHint`,`One bad photograph must never be able to flip a scene. 3 agreeing checks at 60 s is about four minutes of latency and is what makes the answer trustworthy — leaving a state costs exactly the same as entering one.`)}),(0,D.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,D.jsx)(`span`,{className:L,children:a(`uiLibrary.sceneSettingsForm.quietFor`,`Quiet for (seconds) before a check counts`)}),(0,D.jsx)(`input`,{type:`number`,min:0,max:3600,value:o.quietSeconds,disabled:n,className:I,onFocus:()=>u(!0),onChange:e=>s(t=>({...t,quietSeconds:Number(e.target.value)||0})),onBlur:()=>{let t=K(o.quietSeconds,0,3600);t===e.quietSeconds?u(!1):d({quietSeconds:t})}})]}),(0,D.jsx)(`p`,{className:c,children:a(`uiLibrary.sceneSettingsForm.quietHint`,`A check taken while something is moving is a photograph of the van parked in front of the bin, so it is discarded rather than merely delayed. 0 disables the gate.`)}),(0,D.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,D.jsx)(`span`,{className:L,children:a(`uiLibrary.sceneSettingsForm.minGap`,`Minimum gap between counted checks (seconds)`)}),(0,D.jsx)(`input`,{type:`number`,min:0,max:3600,value:o.minObservationSpacingSec,disabled:n,className:I,onFocus:()=>u(!0),onChange:e=>s(t=>({...t,minObservationSpacingSec:Number(e.target.value)||0})),onBlur:()=>{let t=K(o.minObservationSpacingSec,0,3600);t===e.minObservationSpacingSec?u(!1):d({minObservationSpacingSec:t})}})]}),(0,D.jsx)(`p`,{className:c,children:a(`uiLibrary.sceneSettingsForm.minGapHint`,`Spreads the agreeing checks over real time instead of letting three adjacent polls inside one long occlusion be mistaken for three independent opinions.`)})]}),(0,D.jsxs)(`div`,{className:R,children:[(0,D.jsx)(`p`,{className:z,children:a(`uiLibrary.sceneSettingsForm.lighting`,`Lighting`)}),(0,D.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,D.jsx)(`span`,{className:L,children:a(`uiLibrary.sceneSettingsForm.noReference`,`When a light has no reference of its own`)}),(0,D.jsxs)(`select`,{value:e.onUncoveredCondition,disabled:n,className:I,onChange:e=>{let t=e.target.value;(t===`skip`||t===`judge-anyway`)&&d({onUncoveredCondition:t})},children:[(0,D.jsx)(`option`,{value:`skip`,children:a(`uiLibrary.sceneSettingsForm.uncoveredSkip`,`Skip the check (recommended)`)}),(0,D.jsx)(`option`,{value:`judge-anyway`,children:a(`uiLibrary.sceneSettingsForm.uncoveredJudge`,`Judge against the other light anyway`)})]})]}),(0,D.jsx)(`p`,{className:c,children:U(e.onUncoveredCondition,a)})]}),(0,D.jsxs)(`div`,{className:R,children:[(0,D.jsx)(`p`,{className:z,children:a(`uiLibrary.sceneSettingsForm.whatYouGetTold`,`What you get told`)}),(0,D.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,D.jsx)(`span`,{className:L,children:a(`uiLibrary.sceneSettingsForm.notificationsFollow`,`Notifications follow`)}),(0,D.jsxs)(`select`,{value:e.emit,disabled:n,className:I,onChange:e=>{let t=e.target.value;(t===`latched`||t===`live`)&&d({emit:t})},children:[(0,D.jsx)(`option`,{value:`latched`,children:a(`uiLibrary.sceneSettingsForm.emitLatched`,`The flag — told once, still visible at breakfast`)}),(0,D.jsx)(`option`,{value:`live`,children:a(`uiLibrary.sceneSettingsForm.emitLive`,`The live state — follows the region as it changes`)})]})]}),(0,D.jsx)(`p`,{className:c,children:a(`uiLibrary.sceneSettingsForm.emitHint`,`“Is the bin gone” is a flag: you want to be told once and still see it later. “Is the gate open” is a live state.`)}),(0,D.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,D.jsx)(`input`,{type:`checkbox`,checked:e.autoRestore,disabled:n,onChange:e=>d({autoRestore:e.target.checked})}),(0,D.jsx)(`span`,{className:L,children:a(`uiLibrary.sceneSettingsForm.autoRestore`,`Clear the flag by itself when things look normal again`)})]}),(0,D.jsx)(`p`,{className:c,children:a(`uiLibrary.sceneSettingsForm.autoRestoreHint`,`Off by default, so an alarm never silently clears itself. The “back to normal” moment is recorded either way, so an automation can still react to it.`)})]}),(0,D.jsxs)(`div`,{className:R,children:[(0,D.jsx)(`p`,{className:z,children:a(`uiLibrary.sceneSettingsForm.aiDoubleCheck`,`AI double-check`)}),(0,D.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,D.jsx)(`input`,{type:`checkbox`,checked:p,disabled:n||o.confirmPrompt.trim().length===0,onChange:e=>d(e.target.checked?{confirm:{...q(o.confirmPrompt.trim()),enabled:!0}}:{confirm:null})}),(0,D.jsx)(`span`,{className:L,children:a(`uiLibrary.sceneSettingsForm.askVision`,`Ask a vision model before changing the answer`)})]}),(0,D.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,D.jsx)(`span`,{className:L,children:a(`uiLibrary.sceneSettingsForm.question`,`The question to ask`)}),(0,D.jsx)(`input`,{type:`text`,value:o.confirmPrompt,placeholder:a(`uiLibrary.sceneSettingsForm.questionPlaceholder`,`e.g. Is the wheelie bin still there?`),disabled:n,className:I,onFocus:()=>u(!0),onChange:e=>s(t=>({...t,confirmPrompt:e.target.value})),onBlur:()=>{let t=o.confirmPrompt.trim();t.length>0&&t!==e.confirm?.prompt?d({confirm:{...q(t),enabled:p}}):u(!1)}})]}),(0,D.jsx)(`p`,{className:c,children:(0,D.jsx)(r,{uiKey:`uiLibrary.sceneSettingsForm.confirmHint`,fallback:`The model is asked <0>only</0> when the region has already changed enough to flip the answer — roughly twice a week for a bin, not once a minute. It reasons about the object rather than the pixels, so rain, shadows and a repositioned bin stop counting as the thing being taken. If it cannot be reached, the change is held rather than announced.`,components:[(0,D.jsx)(`strong`,{},`only`)]})})]})]})}function K(e,t,n){return Math.min(n,Math.max(t,e))}function q(e){return{enabled:!1,prompt:e,timeoutMs:8e3,maxImagePx:448,onTimeout:`hold`}}var J=`rounded-md border border-border bg-surface px-2 py-1 text-[11px] font-medium text-foreground-subtle hover:bg-surface-hover disabled:opacity-40 transition-colors`,Y=`rounded-md border border-primary/50 bg-primary/15 px-2.5 py-1 text-[11px] font-medium text-primary hover:bg-primary/25 disabled:opacity-40 transition-colors`,X=`rounded-md border border-danger/50 bg-danger/10 px-2 py-1 text-[11px] font-medium text-danger hover:bg-danger/20 disabled:opacity-40 transition-colors`,Z={alarm:`border-danger/50 bg-danger/15 text-danger`,ok:`border-success/50 bg-success/15 text-success`,unknown:`border-border bg-surface text-foreground-subtle`},ee=.8,te=3;function Q({deviceId:e}){let n=t(),r=l(d().trpcClient,e),i=u(r?.state.sceneMonitor),f=b(e,{width:640}),[h,x]=(0,E.useState)(null),[S,O]=(0,E.useState)(!1),[k,A]=(0,E.useState)(null),[j,M]=(0,E.useState)(null),[P,F]=(0,E.useState)(null),[I,L]=(0,E.useState)(null),[R,z]=(0,E.useState)(!1),[B,V]=(0,E.useState)(null),[H,U]=(0,E.useState)(``),W=(0,E.useRef)(!0);(0,E.useEffect)(()=>(W.current=!0,()=>{W.current=!1}),[]);let K=(0,E.useCallback)(async()=>{if(r)try{let e=await r.sceneMonitor?.listScenes({});if(!W.current)return;e&&x(e)}catch(e){if(!W.current)return;m(e)?O(!0):M(e instanceof Error?e.message:String(e))}},[r]);(0,E.useEffect)(()=>{x(null),O(!1),M(null),K()},[K]);let q=i?.monitors??h?.monitors??[],Q=Date.now(),$=(0,E.useCallback)(async(e,t)=>{A(e),M(null);try{await t(),await K()}catch(e){W.current&&M(e instanceof Error?e.message:String(e))}finally{W.current&&A(null)}},[K]),ne=(0,E.useMemo)(()=>{let e=q.map(e=>({id:e.id,shape:e.roi,label:e.label,enabled:e.enabled}));return B===null?e:[...e,{id:`__draft__`,shape:B,label:n(`uiLibrary.sceneMonitor.newSceneLabel`,`New scene`)}]},[q,B,n]),re=(0,E.useCallback)((e,t)=>{if(t.kind===`rect`){if(e===`__draft__`){V(t);return}$(`roi-${String(e)}`,async()=>r?.sceneMonitor?.updateScene({monitorId:String(e),patch:{roi:t}}))}},[r,$]),ie=(0,E.useCallback)(e=>{e.kind===`rect`&&V(e)},[]),ae=(0,E.useCallback)(async()=>{B===null||H.trim().length===0||(await $(`create`,async()=>{await r?.sceneMonitor?.createScene({label:H.trim(),roi:B,check:{mode:`similarity`,threshold:ee,hysteresisCount:te}})}),V(null),U(``),z(!1))},[r,B,H,$]);return r?(0,D.jsx)(`div`,{className:`flex flex-col gap-3`,children:S?(0,D.jsx)(`p`,{className:`${c} leading-relaxed`,children:n(`uiLibrary.sceneMonitor.unsupported`,`Scene monitoring is not available for this camera.`)}):(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`p`,{className:`${c} leading-relaxed`,children:n(`uiLibrary.sceneMonitor.intro`,`A scene watches one region of this camera and tells you when it stops looking like the picture you captured. Draw a box around the thing you care about — a wheelie bin, a gate, a parking space — then capture what “normal” looks like. Daylight is enough to start: the night reference is optional, and without it the scene simply sits the infrared hours out instead of reporting a problem.`)}),(0,D.jsx)(`div`,{className:`relative overflow-hidden rounded-md border border-border`,children:(0,D.jsx)(w,{items:ne,supportedShapes:[`rect`],selectedId:P??(B===null?null:`__draft__`),onSelect:e=>F(e===null?null:String(e)),onShapeChange:re,onDrawComplete:ie,drawingKind:R&&B===null?`rect`:null,backdrop:f.src===null?null:(0,D.jsx)(`img`,{src:f.src,alt:``,className:`h-full w-full object-contain`,draggable:!1})})}),(0,D.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,D.jsx)(`button`,{type:`button`,className:R?Y:J,"aria-pressed":R,onClick:()=>{z(e=>!e),V(null)},disabled:k!==null,children:R?n(`uiLibrary.sceneMonitor.cancel`,`Cancel`):n(`uiLibrary.sceneMonitor.newScene`,`+ New scene`)}),(0,D.jsx)(`button`,{type:`button`,className:J,onClick:f.refresh,disabled:k!==null,children:n(`uiLibrary.sceneMonitor.refresh`,`Refresh frame`)})]}),R&&(0,D.jsxs)(`div`,{className:`flex flex-col gap-2 rounded-md border border-border bg-surface p-2`,children:[(0,D.jsx)(`p`,{className:`text-[10px] text-foreground-subtle`,children:B===null?n(`uiLibrary.sceneMonitor.draftHint`,`Click on the frame to drop a box, then drag its corner to fit it around the thing you want watched.`):n(`uiLibrary.sceneMonitor.nameHint`,`Name it, then create. You capture what “normal” looks like next.`)}),B!==null&&s(B)&&(0,D.jsx)(`p`,{className:`text-[11px] leading-relaxed text-warning`,children:n(`uiLibrary.sceneMonitor.tooLarge`,`That box covers most of the frame. A scene that big is dominated by the weather, the sky and passing cars — it will quietly stop noticing the thing you actually care about. Draw it tighter.`)}),(0,D.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,D.jsx)(`input`,{type:`text`,value:H,onChange:e=>U(e.target.value),placeholder:n(`uiLibrary.sceneMonitor.placeholder`,`e.g. Immondizia prelevata`),className:`flex-1 rounded-md border border-border bg-surface px-2 py-1 text-[12px] text-foreground`}),(0,D.jsx)(`button`,{type:`button`,className:Y,onClick:()=>void ae(),disabled:B===null||H.trim().length===0||k!==null,children:n(`uiLibrary.sceneMonitor.create`,`Create`)})]})]}),j!==null&&(0,D.jsx)(`p`,{className:`text-[11px] leading-relaxed text-danger`,children:j}),q.length===0?(0,D.jsx)(`p`,{className:`${c} leading-relaxed`,children:n(`uiLibrary.sceneMonitor.empty`,`No scenes on this camera yet.`)}):(0,D.jsx)(`ul`,{className:`flex flex-col gap-2`,children:q.map(e=>{let t=v(e,n);return(0,D.jsxs)(`li`,{className:`flex flex-col gap-1.5 rounded-md border p-2 ${P===e.id?`border-primary/50`:`border-border`}`,children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,D.jsx)(`button`,{type:`button`,className:`flex-1 text-left text-[12px] font-medium text-foreground`,onClick:()=>F(e.id),children:e.label}),(0,D.jsx)(`span`,{className:`rounded border px-1.5 py-0.5 text-[10px] font-medium ${Z[t.tone]}`,children:t.text})]}),(0,D.jsx)(`p`,{className:`${c} leading-relaxed`,children:_(e,Q,n)}),(0,D.jsx)(`p`,{className:`${c} tabular-nums`,children:p(e,n)}),(0,D.jsx)(N,{monitor:e,disabled:k!==null,onDelete:({stateId:t,index:n})=>void $(`refdel-${e.id}-${t}-${String(n)}`,async()=>r.sceneMonitor?.deleteReference({monitorId:e.id,stateId:t,index:n}))}),(0,D.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[g.map(t=>{let i=t===`ir`;return(0,D.jsxs)(`button`,{type:`button`,className:J,disabled:k!==null,title:i?n(`uiLibrary.sceneMonitor.optionalTitle`,`Optional. Without a night reference the checks in infrared are simply skipped — the scene keeps working in daylight and nothing is reported as broken.`):n(`uiLibrary.sceneMonitor.captureTitle`,`Take a fresh photo now and store it as the {{variant}} reference`,{variant:y(t,n).toLowerCase()}),onClick:()=>void $(`cap-${e.id}-${t}`,async()=>r.sceneMonitor?.captureReference({monitorId:e.id,condition:t})),children:[(0,D.jsx)(a,{className:`mr-1 inline h-3 w-3`}),n(`uiLibrary.sceneMonitor.capture`,`Capture {{variant}}`,{variant:y(t,n).toLowerCase()}),i&&(0,D.jsx)(`span`,{className:`ml-1 text-foreground-subtle/70`,children:n(`uiLibrary.sceneMonitor.optional`,`(optional)`)})]},t)}),(0,D.jsxs)(`button`,{type:`button`,className:Y,disabled:k!==null||e.states.length===0,title:n(`uiLibrary.sceneMonitor.resetTitle`,`Clear the flag and re-photograph what normal looks like right now`),onClick:()=>void $(`reset-${e.id}`,async()=>r.sceneMonitor?.resetScene({monitorId:e.id})),children:[(0,D.jsx)(C,{className:`mr-1 inline h-3 w-3`}),n(`uiLibrary.sceneMonitor.reset`,`Reset`)]}),(0,D.jsx)(`button`,{type:`button`,className:J,disabled:k!==null,onClick:()=>void $(`check-${e.id}`,async()=>r.sceneMonitor?.recheckNow({monitorId:e.id})),children:n(`uiLibrary.sceneMonitor.checkNow`,`Check now`)}),(0,D.jsxs)(`button`,{type:`button`,className:I===e.id?Y:J,"aria-pressed":I===e.id,"aria-label":n(`uiLibrary.sceneMonitor.settingsFor`,`Settings for {{label}}`,{label:e.label}),disabled:k!==null,onClick:()=>L(t=>t===e.id?null:e.id),children:[(0,D.jsx)(T,{className:`mr-1 inline h-3 w-3`}),n(`uiLibrary.sceneMonitor.settings`,`Settings`)]}),(0,D.jsx)(`button`,{type:`button`,className:X,disabled:k!==null,onClick:()=>void $(`del-${e.id}`,async()=>r.sceneMonitor?.deleteScene({monitorId:e.id})),children:(0,D.jsx)(o,{className:`h-3 w-3`})})]}),I===e.id&&(0,D.jsx)(G,{monitor:e,disabled:k!==null,onPatch:t=>void $(`tune-${e.id}`,async()=>r.sceneMonitor?.updateScene({monitorId:e.id,patch:t}))})]},e.id)})})]})}):null}export{Q as SceneMonitorEditor};
1
+ import{a as e,i as t,l as n,n as r,o as i}from"./scheduler-0XZJE03d.js";import{C as a,_ as o,a as s,c,d as l,f as u,g as d,h as f,i as p,l as m,m as h,n as g,o as _,r as v,s as y,u as b,w as x,x as S,y as C}from"./index-KdTdngTk.js";import{MaskShapeCanvas as w}from"./MaskShapeCanvas-BTvl6Rin.js";var T=x(`settings-2`,[[`path`,{d:`M14 17H5`,key:`gfn3mx`}],[`path`,{d:`M19 7h-9`,key:`6i9tg`}],[`circle`,{cx:`17`,cy:`17`,r:`3`,key:`18b49y`}],[`circle`,{cx:`7`,cy:`7`,r:`3`,key:`dfmy0x`}]]),E=n(i(),1),D=n(e(),1),O=h(`/addon/pipeline-analytics/event-media`);function k(e){return`${O}/m/${e}`}function A(e){let t=new Map;for(let n of e.states)n.references.forEach((e,r)=>{let i=t.get(e.condition)??[];i.push({stateId:n.id,index:r,reference:e}),t.set(e.condition,i)});return[...t.entries()].map(([e,t])=>({condition:e,tiles:[...t].sort((e,t)=>t.reference.capturedAt-e.reference.capturedAt)})).sort((e,t)=>e.condition.localeCompare(t.condition))}function j(e){return e.states.reduce((e,t)=>e+t.references.length,0)}var M=`rounded border border-danger/50 bg-danger/10 px-1 py-0.5 text-[10px] font-medium text-danger hover:bg-danger/20 disabled:opacity-40 transition-colors`;function N({monitor:e,disabled:n,onDelete:r}){let i=t(),a=A(e),s=j(e),l=f();return a.length===0?(0,D.jsx)(`p`,{className:`${c} leading-relaxed`,children:i(`uiLibrary.sceneReferenceGallery.empty`,`No photographs captured yet. Press “Capture daylight” to take the one this scene will judge everything against.`)}):(0,D.jsx)(`div`,{className:`flex flex-col gap-2`,children:a.map(e=>(0,D.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,D.jsxs)(`p`,{className:`text-[10px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:[y(e.condition,i),` · `,e.tiles.length]}),(0,D.jsx)(`ul`,{className:`flex flex-wrap gap-1.5`,children:e.tiles.map(t=>{let a=`${t.stateId}:${String(t.index)}`,u=s===1;return(0,D.jsxs)(`li`,{className:`flex w-24 flex-col gap-1 rounded-md border border-border p-1`,children:[(0,D.jsx)(P,{reference:t.reference}),(0,D.jsx)(`span`,{className:`${c} tabular-nums`,children:F(t.reference.capturedAt)}),(0,D.jsxs)(`button`,{type:`button`,className:M,disabled:n,"aria-label":i(`uiLibrary.sceneReferenceGallery.deleteLabel`,`Delete the {{variant}} photograph from {{date}}`,{variant:y(e.condition,i).toLowerCase(),date:F(t.reference.capturedAt)}),onClick:()=>{(async()=>{u&&!await l({title:i(`uiLibrary.sceneReferenceGallery.deleteTitle`,`Delete the only photograph?`),message:i(`uiLibrary.sceneReferenceGallery.lastWarning`,`This is the only photograph this scene has. Delete it and the scene no longer knows what normal looks like — it stops judging until you capture again.`),confirmLabel:i(`uiLibrary.sceneReferenceGallery.delete`,`Delete`),variant:`danger`})||r({stateId:t.stateId,index:t.index})})()},children:[(0,D.jsx)(o,{className:`mr-1 inline h-3 w-3`}),i(`uiLibrary.sceneReferenceGallery.delete`,`Delete`)]})]},a)})})]},e.condition))})}function P({reference:e}){let n=t(),[r,i]=(0,E.useState)(!1),a=e.thumbnailMediaId;return a===void 0||r?(0,D.jsxs)(`div`,{className:`flex h-16 w-full flex-col items-center justify-center gap-0.5 rounded bg-surface text-foreground-subtle`,title:n(`uiLibrary.sceneReferenceGallery.missingPicture`,`The picture for this reference is no longer stored. The reference itself is intact and still being scored against.`),children:[(0,D.jsx)(S,{className:`h-4 w-4`}),(0,D.jsx)(`span`,{className:`text-[9px]`,children:n(`uiLibrary.sceneReferenceGallery.noPicture`,`no picture`)})]}):(0,D.jsx)(`img`,{src:k(a),alt:``,loading:`lazy`,className:`h-16 w-full rounded object-cover`,onError:()=>i(!0)})}function F(e){let t=new Date(e);return`${t.toLocaleDateString()} ${t.toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`})}`}var I=`rounded-md border border-border bg-surface px-2 py-1 text-[11px] text-foreground focus:border-primary focus:outline-none disabled:opacity-50`,L=`text-[10px] font-medium text-foreground-subtle`,R=`flex flex-col gap-2 rounded-md border border-border bg-surface/40 p-2`,z=`text-[10px] font-semibold uppercase tracking-wide text-foreground-subtle`,B=5,V=3600;function H(e,t){switch(e){case`periodic`:return t(`uiLibrary.sceneSettingsForm.triggerHintPeriodic`,`Only on the clock. Predictable, and it notices a change even on a camera nothing ever moves in front of.`);case`on-motion`:return t(`uiLibrary.sceneSettingsForm.triggerHintOnMotion`,`Only after the camera has been still again for the quiet window below. Cheapest, but a change nobody walks past is never seen.`);case`both`:return t(`uiLibrary.sceneSettingsForm.triggerHintBoth`,`Both — the clock is the safety net that lets the motion path miss. This is the right answer for almost every scene.`)}}function U(e,t){switch(e){case`skip`:return t(`uiLibrary.sceneSettingsForm.uncoveredHintSkip`,`Sit that light out. No verdict, no alarm, no flag touched — it picks itself back up when a light it knows returns. This is why the night capture is optional.`);case`judge-anyway`:return t(`uiLibrary.sceneSettingsForm.uncoveredHintJudge`,`Compare against the references you do have. Only correct when the two lights genuinely look alike (a floodlit driveway, an indoor lamp) — against a real infrared frame it will report a change that did not happen.`)}}function W(e){return{label:e.label,checkIntervalSec:e.checkIntervalSec??60,threshold:e.check.mode===`similarity`?e.check.threshold:.8,hysteresisCount:e.check.hysteresisCount,quietSeconds:e.quietSeconds,minObservationSpacingSec:e.minObservationSpacingSec,confirmPrompt:e.confirm?.prompt??``}}function G({monitor:e,disabled:n,onPatch:i}){let a=t(),[o,s]=(0,E.useState)(()=>W(e)),[l,u]=(0,E.useState)(!1);(0,E.useEffect)(()=>{l||s(W(e))},[e,l]);let d=e=>{u(!1),i(e)},f=t=>e.check.mode===`similarity`?{mode:`similarity`,threshold:t.threshold??e.check.threshold,hysteresisCount:t.hysteresisCount??e.check.hysteresisCount}:{...e.check,hysteresisCount:t.hysteresisCount??e.check.hysteresisCount},p=e.confirm?.enabled===!0,m=e.check.mode===`similarity`?e.check.threshold:null;return(0,D.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,D.jsxs)(`div`,{className:R,children:[(0,D.jsx)(`p`,{className:z,children:a(`uiLibrary.sceneSettingsForm.whatItWatches`,`What it watches`)}),(0,D.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,D.jsx)(`span`,{className:L,children:a(`uiLibrary.sceneSettingsForm.name`,`Name`)}),(0,D.jsx)(`input`,{type:`text`,value:o.label,disabled:n,className:I,onFocus:()=>u(!0),onChange:e=>s(t=>({...t,label:e.target.value})),onBlur:()=>{let t=o.label.trim();t.length>0&&t!==e.label?d({label:t}):u(!1)}})]}),(0,D.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,D.jsx)(`input`,{type:`checkbox`,checked:e.enabled,disabled:n,onChange:e=>d({enabled:e.target.checked})}),(0,D.jsx)(`span`,{className:L,children:a(`uiLibrary.sceneSettingsForm.watching`,`Watching`)})]}),(0,D.jsx)(`p`,{className:c,children:a(`uiLibrary.sceneSettingsForm.watchingHint`,`Turned off, the scene keeps its region, its references and its flag — it simply stops checking. Nothing is lost by pausing one for a while.`)}),(0,D.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,D.jsx)(`span`,{className:L,children:a(`uiLibrary.sceneSettingsForm.whenToLook`,`When to look`)}),(0,D.jsxs)(`select`,{value:e.triggerMode,disabled:n,className:I,onChange:e=>{let t=e.target.value;(t===`periodic`||t===`on-motion`||t===`both`)&&d({triggerMode:t})},children:[(0,D.jsx)(`option`,{value:`both`,children:a(`uiLibrary.sceneSettingsForm.triggerBoth`,`On the clock and after motion settles`)}),(0,D.jsx)(`option`,{value:`periodic`,children:a(`uiLibrary.sceneSettingsForm.triggerPeriodic`,`On the clock only`)}),(0,D.jsx)(`option`,{value:`on-motion`,children:a(`uiLibrary.sceneSettingsForm.triggerOnMotion`,`After motion settles only`)})]})]}),(0,D.jsx)(`p`,{className:c,children:H(e.triggerMode,a)}),(0,D.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,D.jsx)(`span`,{className:L,children:a(`uiLibrary.sceneSettingsForm.checkEvery`,`Check every (seconds)`)}),(0,D.jsx)(`input`,{type:`number`,min:B,max:V,value:o.checkIntervalSec,disabled:n,className:I,onFocus:()=>u(!0),onChange:e=>s(t=>({...t,checkIntervalSec:Number(e.target.value)||0})),onBlur:()=>{let t=K(o.checkIntervalSec,B,V);t===e.checkIntervalSec?u(!1):d({checkIntervalSec:t})}})]}),(0,D.jsx)(`p`,{className:c,children:a(`uiLibrary.sceneSettingsForm.intervalHint`,`60 s suits “is the bin still out”. Every check costs one photograph and one encode, so going below about 30 s buys latency you almost never need and multiplies the cost by the number of scenes you own.`)})]}),(0,D.jsxs)(`div`,{className:R,children:[(0,D.jsx)(`p`,{className:z,children:a(`uiLibrary.sceneSettingsForm.howSure`,`How sure it has to be`)}),e.check.mode===`similarity`&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,D.jsx)(`span`,{className:L,children:(0,D.jsx)(r,{uiKey:`uiLibrary.sceneSettingsForm.matchThreshold`,fallback:`Match threshold — <0>{{value}}</0>`,components:[(0,D.jsx)(`span`,{className:`tabular-nums`},`value`)],values:{value:o.threshold.toFixed(2)}})}),(0,D.jsx)(`input`,{type:`range`,min:.3,max:.99,step:.01,value:o.threshold,disabled:n,onFocus:()=>u(!0),onChange:e=>s(t=>({...t,threshold:Number(e.target.value)})),onMouseUp:()=>{o.threshold===m?u(!1):d({check:f({threshold:o.threshold})})},onBlur:()=>{o.threshold===m?u(!1):d({check:f({threshold:o.threshold})})}})]}),(0,D.jsx)(`p`,{className:`text-[10px] text-foreground-subtle`,children:a(`uiLibrary.sceneSettingsForm.thresholdHint`,`How closely the region still has to resemble the photograph to count as unchanged. Higher means fussier: at 0.95 a passing cloud can read as a change; at 0.60 the bin can be taken and the scene will shrug. 0.80 is a sensible start — if it cries wolf, lower it; if it misses the thing you care about, raise it.`)})]}),(0,D.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,D.jsx)(`span`,{className:L,children:a(`uiLibrary.sceneSettingsForm.agreeingChecks`,`Agreeing checks before it changes its mind`)}),(0,D.jsx)(`input`,{type:`number`,min:1,max:10,value:o.hysteresisCount,disabled:n,className:I,onFocus:()=>u(!0),onChange:e=>s(t=>({...t,hysteresisCount:Number(e.target.value)||1})),onBlur:()=>{let t=K(o.hysteresisCount,1,10);t===e.check.hysteresisCount?u(!1):d({check:f({hysteresisCount:t})})}})]}),(0,D.jsx)(`p`,{className:c,children:a(`uiLibrary.sceneSettingsForm.agreeingHint`,`One bad photograph must never be able to flip a scene. 3 agreeing checks at 60 s is about four minutes of latency and is what makes the answer trustworthy — leaving a state costs exactly the same as entering one.`)}),(0,D.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,D.jsx)(`span`,{className:L,children:a(`uiLibrary.sceneSettingsForm.quietFor`,`Quiet for (seconds) before a check counts`)}),(0,D.jsx)(`input`,{type:`number`,min:0,max:3600,value:o.quietSeconds,disabled:n,className:I,onFocus:()=>u(!0),onChange:e=>s(t=>({...t,quietSeconds:Number(e.target.value)||0})),onBlur:()=>{let t=K(o.quietSeconds,0,3600);t===e.quietSeconds?u(!1):d({quietSeconds:t})}})]}),(0,D.jsx)(`p`,{className:c,children:a(`uiLibrary.sceneSettingsForm.quietHint`,`A check taken while something is moving is a photograph of the van parked in front of the bin, so it is discarded rather than merely delayed. 0 disables the gate.`)}),(0,D.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,D.jsx)(`span`,{className:L,children:a(`uiLibrary.sceneSettingsForm.minGap`,`Minimum gap between counted checks (seconds)`)}),(0,D.jsx)(`input`,{type:`number`,min:0,max:3600,value:o.minObservationSpacingSec,disabled:n,className:I,onFocus:()=>u(!0),onChange:e=>s(t=>({...t,minObservationSpacingSec:Number(e.target.value)||0})),onBlur:()=>{let t=K(o.minObservationSpacingSec,0,3600);t===e.minObservationSpacingSec?u(!1):d({minObservationSpacingSec:t})}})]}),(0,D.jsx)(`p`,{className:c,children:a(`uiLibrary.sceneSettingsForm.minGapHint`,`Spreads the agreeing checks over real time instead of letting three adjacent polls inside one long occlusion be mistaken for three independent opinions.`)})]}),(0,D.jsxs)(`div`,{className:R,children:[(0,D.jsx)(`p`,{className:z,children:a(`uiLibrary.sceneSettingsForm.lighting`,`Lighting`)}),(0,D.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,D.jsx)(`span`,{className:L,children:a(`uiLibrary.sceneSettingsForm.noReference`,`When a light has no reference of its own`)}),(0,D.jsxs)(`select`,{value:e.onUncoveredCondition,disabled:n,className:I,onChange:e=>{let t=e.target.value;(t===`skip`||t===`judge-anyway`)&&d({onUncoveredCondition:t})},children:[(0,D.jsx)(`option`,{value:`skip`,children:a(`uiLibrary.sceneSettingsForm.uncoveredSkip`,`Skip the check (recommended)`)}),(0,D.jsx)(`option`,{value:`judge-anyway`,children:a(`uiLibrary.sceneSettingsForm.uncoveredJudge`,`Judge against the other light anyway`)})]})]}),(0,D.jsx)(`p`,{className:c,children:U(e.onUncoveredCondition,a)})]}),(0,D.jsxs)(`div`,{className:R,children:[(0,D.jsx)(`p`,{className:z,children:a(`uiLibrary.sceneSettingsForm.whatYouGetTold`,`What you get told`)}),(0,D.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,D.jsx)(`span`,{className:L,children:a(`uiLibrary.sceneSettingsForm.notificationsFollow`,`Notifications follow`)}),(0,D.jsxs)(`select`,{value:e.emit,disabled:n,className:I,onChange:e=>{let t=e.target.value;(t===`latched`||t===`live`)&&d({emit:t})},children:[(0,D.jsx)(`option`,{value:`latched`,children:a(`uiLibrary.sceneSettingsForm.emitLatched`,`The flag — told once, still visible at breakfast`)}),(0,D.jsx)(`option`,{value:`live`,children:a(`uiLibrary.sceneSettingsForm.emitLive`,`The live state — follows the region as it changes`)})]})]}),(0,D.jsx)(`p`,{className:c,children:a(`uiLibrary.sceneSettingsForm.emitHint`,`“Is the bin gone” is a flag: you want to be told once and still see it later. “Is the gate open” is a live state.`)}),(0,D.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,D.jsx)(`input`,{type:`checkbox`,checked:e.autoRestore,disabled:n,onChange:e=>d({autoRestore:e.target.checked})}),(0,D.jsx)(`span`,{className:L,children:a(`uiLibrary.sceneSettingsForm.autoRestore`,`Clear the flag by itself when things look normal again`)})]}),(0,D.jsx)(`p`,{className:c,children:a(`uiLibrary.sceneSettingsForm.autoRestoreHint`,`Off by default, so an alarm never silently clears itself. The “back to normal” moment is recorded either way, so an automation can still react to it.`)})]}),(0,D.jsxs)(`div`,{className:R,children:[(0,D.jsx)(`p`,{className:z,children:a(`uiLibrary.sceneSettingsForm.aiDoubleCheck`,`AI double-check`)}),(0,D.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,D.jsx)(`input`,{type:`checkbox`,checked:p,disabled:n||o.confirmPrompt.trim().length===0,onChange:e=>d(e.target.checked?{confirm:{...q(o.confirmPrompt.trim()),enabled:!0}}:{confirm:null})}),(0,D.jsx)(`span`,{className:L,children:a(`uiLibrary.sceneSettingsForm.askVision`,`Ask a vision model before changing the answer`)})]}),(0,D.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,D.jsx)(`span`,{className:L,children:a(`uiLibrary.sceneSettingsForm.question`,`The question to ask`)}),(0,D.jsx)(`input`,{type:`text`,value:o.confirmPrompt,placeholder:a(`uiLibrary.sceneSettingsForm.questionPlaceholder`,`e.g. Is the wheelie bin still there?`),disabled:n,className:I,onFocus:()=>u(!0),onChange:e=>s(t=>({...t,confirmPrompt:e.target.value})),onBlur:()=>{let t=o.confirmPrompt.trim();t.length>0&&t!==e.confirm?.prompt?d({confirm:{...q(t),enabled:p}}):u(!1)}})]}),(0,D.jsx)(`p`,{className:c,children:(0,D.jsx)(r,{uiKey:`uiLibrary.sceneSettingsForm.confirmHint`,fallback:`The model is asked <0>only</0> when the region has already changed enough to flip the answer — roughly twice a week for a bin, not once a minute. It reasons about the object rather than the pixels, so rain, shadows and a repositioned bin stop counting as the thing being taken. If it cannot be reached, the change is held rather than announced.`,components:[(0,D.jsx)(`strong`,{},`only`)]})})]})]})}function K(e,t,n){return Math.min(n,Math.max(t,e))}function q(e){return{enabled:!1,prompt:e,timeoutMs:8e3,maxImagePx:448,onTimeout:`hold`}}var J=`rounded-md border border-border bg-surface px-2 py-1 text-[11px] font-medium text-foreground-subtle hover:bg-surface-hover disabled:opacity-40 transition-colors`,Y=`rounded-md border border-primary/50 bg-primary/15 px-2.5 py-1 text-[11px] font-medium text-primary hover:bg-primary/25 disabled:opacity-40 transition-colors`,X=`rounded-md border border-danger/50 bg-danger/10 px-2 py-1 text-[11px] font-medium text-danger hover:bg-danger/20 disabled:opacity-40 transition-colors`,Z={alarm:`border-danger/50 bg-danger/15 text-danger`,ok:`border-success/50 bg-success/15 text-success`,unknown:`border-border bg-surface text-foreground-subtle`},ee=.8,te=3;function Q({deviceId:e}){let n=t(),r=l(d().trpcClient,e),i=u(r?.state.sceneMonitor),f=b(e,{width:640}),[h,x]=(0,E.useState)(null),[S,O]=(0,E.useState)(!1),[k,A]=(0,E.useState)(null),[j,M]=(0,E.useState)(null),[P,F]=(0,E.useState)(null),[I,L]=(0,E.useState)(null),[R,z]=(0,E.useState)(!1),[B,V]=(0,E.useState)(null),[H,U]=(0,E.useState)(``),W=(0,E.useRef)(!0);(0,E.useEffect)(()=>(W.current=!0,()=>{W.current=!1}),[]);let K=(0,E.useCallback)(async()=>{if(r)try{let e=await r.sceneMonitor?.listScenes({});if(!W.current)return;e&&x(e)}catch(e){if(!W.current)return;m(e)?O(!0):M(e instanceof Error?e.message:String(e))}},[r]);(0,E.useEffect)(()=>{x(null),O(!1),M(null),K()},[K]);let q=i?.monitors??h?.monitors??[],Q=Date.now(),$=(0,E.useCallback)(async(e,t)=>{A(e),M(null);try{await t(),await K()}catch(e){W.current&&M(e instanceof Error?e.message:String(e))}finally{W.current&&A(null)}},[K]),ne=(0,E.useMemo)(()=>{let e=q.map(e=>({id:e.id,shape:e.roi,label:e.label,enabled:e.enabled}));return B===null?e:[...e,{id:`__draft__`,shape:B,label:n(`uiLibrary.sceneMonitor.newSceneLabel`,`New scene`)}]},[q,B,n]),re=(0,E.useCallback)((e,t)=>{if(t.kind===`rect`){if(e===`__draft__`){V(t);return}$(`roi-${String(e)}`,async()=>r?.sceneMonitor?.updateScene({monitorId:String(e),patch:{roi:t}}))}},[r,$]),ie=(0,E.useCallback)(e=>{e.kind===`rect`&&V(e)},[]),ae=(0,E.useCallback)(async()=>{B===null||H.trim().length===0||(await $(`create`,async()=>{await r?.sceneMonitor?.createScene({label:H.trim(),roi:B,check:{mode:`similarity`,threshold:ee,hysteresisCount:te}})}),V(null),U(``),z(!1))},[r,B,H,$]);return r?(0,D.jsx)(`div`,{className:`flex flex-col gap-3`,children:S?(0,D.jsx)(`p`,{className:`${c} leading-relaxed`,children:n(`uiLibrary.sceneMonitor.unsupported`,`Scene monitoring is not available for this camera.`)}):(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`p`,{className:`${c} leading-relaxed`,children:n(`uiLibrary.sceneMonitor.intro`,`A scene watches one region of this camera and tells you when it stops looking like the picture you captured. Draw a box around the thing you care about — a wheelie bin, a gate, a parking space — then capture what “normal” looks like. Daylight is enough to start: the night reference is optional, and without it the scene simply sits the infrared hours out instead of reporting a problem.`)}),(0,D.jsx)(`div`,{className:`relative overflow-hidden rounded-md border border-border`,children:(0,D.jsx)(w,{items:ne,supportedShapes:[`rect`],selectedId:P??(B===null?null:`__draft__`),onSelect:e=>F(e===null?null:String(e)),onShapeChange:re,onDrawComplete:ie,drawingKind:R&&B===null?`rect`:null,backdrop:f.src===null?null:(0,D.jsx)(`img`,{src:f.src,alt:``,className:`h-full w-full object-contain`,draggable:!1})})}),(0,D.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,D.jsx)(`button`,{type:`button`,className:R?Y:J,"aria-pressed":R,onClick:()=>{z(e=>!e),V(null)},disabled:k!==null,children:R?n(`uiLibrary.sceneMonitor.cancel`,`Cancel`):n(`uiLibrary.sceneMonitor.newScene`,`+ New scene`)}),(0,D.jsx)(`button`,{type:`button`,className:J,onClick:f.refresh,disabled:k!==null,children:n(`uiLibrary.sceneMonitor.refresh`,`Refresh frame`)})]}),R&&(0,D.jsxs)(`div`,{className:`flex flex-col gap-2 rounded-md border border-border bg-surface p-2`,children:[(0,D.jsx)(`p`,{className:`text-[10px] text-foreground-subtle`,children:B===null?n(`uiLibrary.sceneMonitor.draftHint`,`Click on the frame to drop a box, then drag its corner to fit it around the thing you want watched.`):n(`uiLibrary.sceneMonitor.nameHint`,`Name it, then create. You capture what “normal” looks like next.`)}),B!==null&&s(B)&&(0,D.jsx)(`p`,{className:`text-[11px] leading-relaxed text-warning`,children:n(`uiLibrary.sceneMonitor.tooLarge`,`That box covers most of the frame. A scene that big is dominated by the weather, the sky and passing cars — it will quietly stop noticing the thing you actually care about. Draw it tighter.`)}),(0,D.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,D.jsx)(`input`,{type:`text`,value:H,onChange:e=>U(e.target.value),placeholder:n(`uiLibrary.sceneMonitor.placeholder`,`e.g. Immondizia prelevata`),className:`flex-1 rounded-md border border-border bg-surface px-2 py-1 text-[12px] text-foreground`}),(0,D.jsx)(`button`,{type:`button`,className:Y,onClick:()=>void ae(),disabled:B===null||H.trim().length===0||k!==null,children:n(`uiLibrary.sceneMonitor.create`,`Create`)})]})]}),j!==null&&(0,D.jsx)(`p`,{className:`text-[11px] leading-relaxed text-danger`,children:j}),q.length===0?(0,D.jsx)(`p`,{className:`${c} leading-relaxed`,children:n(`uiLibrary.sceneMonitor.empty`,`No scenes on this camera yet.`)}):(0,D.jsx)(`ul`,{className:`flex flex-col gap-2`,children:q.map(e=>{let t=v(e,n);return(0,D.jsxs)(`li`,{className:`flex flex-col gap-1.5 rounded-md border p-2 ${P===e.id?`border-primary/50`:`border-border`}`,children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,D.jsx)(`button`,{type:`button`,className:`flex-1 text-left text-[12px] font-medium text-foreground`,onClick:()=>F(e.id),children:e.label}),(0,D.jsx)(`span`,{className:`rounded border px-1.5 py-0.5 text-[10px] font-medium ${Z[t.tone]}`,children:t.text})]}),(0,D.jsx)(`p`,{className:`${c} leading-relaxed`,children:_(e,Q,n)}),(0,D.jsx)(`p`,{className:`${c} tabular-nums`,children:p(e,n)}),(0,D.jsx)(N,{monitor:e,disabled:k!==null,onDelete:({stateId:t,index:n})=>void $(`refdel-${e.id}-${t}-${String(n)}`,async()=>r.sceneMonitor?.deleteReference({monitorId:e.id,stateId:t,index:n}))}),(0,D.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[g.map(t=>{let i=t===`ir`;return(0,D.jsxs)(`button`,{type:`button`,className:J,disabled:k!==null,title:i?n(`uiLibrary.sceneMonitor.optionalTitle`,`Optional. Without a night reference the checks in infrared are simply skipped — the scene keeps working in daylight and nothing is reported as broken.`):n(`uiLibrary.sceneMonitor.captureTitle`,`Take a fresh photo now and store it as the {{variant}} reference`,{variant:y(t,n).toLowerCase()}),onClick:()=>void $(`cap-${e.id}-${t}`,async()=>r.sceneMonitor?.captureReference({monitorId:e.id,condition:t})),children:[(0,D.jsx)(a,{className:`mr-1 inline h-3 w-3`}),n(`uiLibrary.sceneMonitor.capture`,`Capture {{variant}}`,{variant:y(t,n).toLowerCase()}),i&&(0,D.jsx)(`span`,{className:`ml-1 text-foreground-subtle/70`,children:n(`uiLibrary.sceneMonitor.optional`,`(optional)`)})]},t)}),(0,D.jsxs)(`button`,{type:`button`,className:Y,disabled:k!==null||e.states.length===0,title:n(`uiLibrary.sceneMonitor.resetTitle`,`Clear the flag and re-photograph what normal looks like right now`),onClick:()=>void $(`reset-${e.id}`,async()=>r.sceneMonitor?.resetScene({monitorId:e.id})),children:[(0,D.jsx)(C,{className:`mr-1 inline h-3 w-3`}),n(`uiLibrary.sceneMonitor.reset`,`Reset`)]}),(0,D.jsx)(`button`,{type:`button`,className:J,disabled:k!==null,onClick:()=>void $(`check-${e.id}`,async()=>r.sceneMonitor?.recheckNow({monitorId:e.id})),children:n(`uiLibrary.sceneMonitor.checkNow`,`Check now`)}),(0,D.jsxs)(`button`,{type:`button`,className:I===e.id?Y:J,"aria-pressed":I===e.id,"aria-label":n(`uiLibrary.sceneMonitor.settingsFor`,`Settings for {{label}}`,{label:e.label}),disabled:k!==null,onClick:()=>L(t=>t===e.id?null:e.id),children:[(0,D.jsx)(T,{className:`mr-1 inline h-3 w-3`}),n(`uiLibrary.sceneMonitor.settings`,`Settings`)]}),(0,D.jsx)(`button`,{type:`button`,className:X,disabled:k!==null,onClick:()=>void $(`del-${e.id}`,async()=>r.sceneMonitor?.deleteScene({monitorId:e.id})),children:(0,D.jsx)(o,{className:`h-3 w-3`})})]}),I===e.id&&(0,D.jsx)(G,{monitor:e,disabled:k!==null,onPatch:t=>void $(`tune-${e.id}`,async()=>r.sceneMonitor?.updateScene({monitorId:e.id,patch:t}))})]},e.id)})})]})}):null}export{Q as SceneMonitorEditor};