1!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},t=(new e.Error).stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="9eb2d31a-8f9a-4457-9a8e-8a9d9f13d4ad",e._sentryDebugIdIdentifier="sentry-dbid-9eb2d31a-8f9a-4457-9a8e-8a9d9f13d4ad")}catch(e){}}();"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[3346],{3346:(e,t,r)=>{r.d(t,{ThermalV2Shell:()=>tM});var a=r(95155),n=r(12115),l=r(84158);function i(e){let{scope:t,selectedCount:r,totalCount:n,onChange:l}=e;return(0,a.jsxs)("div",{role:"radiogroup","aria-label":"Scope â what the next action applies to",title:"Choose what actions on this page apply to",className:"inline-flex shrink-0 items-center rounded-md border border-[var(--mobile-app-card-border)] p-0.5 text-[11px]",children:[[{kind:"image",label:"This image"},{kind:"selected",label:"Selected (".concat(r,")"),disabled:0===r},{kind:"all",label:"All (".concat(n,")")}].map(e=>{let r=t.kind===e.kind;return(0,a.jsx)("button",{type:"button",role:"radio","aria-checked":r,disabled:e.disabled,onClick:()=>l(e.kind),className:"rounded px-2 py-1 font-medium transition-colors disabled:cursor-not-allowed disabled:opacity-40 ".concat(r?"bg-[color-mix(in_srgb,var(--graphite-primary)_18%,transparent)] text-[var(--graphite-text-header)]":"text-[var(--graphite-muted)] hover:text-[var(--graphite-text-header)]"),children:e.label},e.kind)}),"image"!==t.kind?(0,a.jsx)("button",{type:"button",onClick:()=>l("image"),title:"Clear scope back to This image (Esc)","aria-label":"Clear scope",className:"ml-0.5 rounded px-1.5 py-1 text-[var(--graphite-muted)] hover:text-[var(--graphite-text-header)]",children:"â"}):null]})}let s=new Map,o=new Set;function d(){for(let e of o)e()}function c(){for(let[,e]of s)"error"===e.status&&e.retry&&e.retry()}let u=new Set,p=[1e3,3e3,9e3];function m(e,t){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;return s.set(e,{status:"saving"}),d(),fetch("/api/ops/thermal/captures/".concat(e),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}).then(e=>{if(!e.ok)throw Error("Save failed (".concat(e.status,")"));return e.json().catch(()=>null)}).then(t=>{if(s.set(e,{status:"saved"}),d(),null==t?void 0:t.metadata)for(let r of u)r(e,t.metadata);return!0}).catch(a=>{var n;if(r<p.length)return new Promise(a=>{setTimeout(()=>{a(m(e,t,r+1))},p[r])});let l=a instanceof Error?a.message:"Not saved";return n=()=>{m(e,t,0)},s.set(e,{status:"error",message:l,retry:n}),d(),!1})}function h(){let{status:e,failedCount:t}=function(){let[,e]=(0,n.useState)(0);(0,n.useEffect)(()=>{let t=()=>e(e=>e+1);return o.add(t),()=>{o.delete(t)}},[]);let t=0,r=!1;for(let[,e]of s)"error"===e.status&&(t+=1),"saving"===e.status&&(r=!0);return t>0?{status:"error",failedCount:t}:r?{status:"saving",failedCount:0}:{status:s.size?"saved":"idle",failedCount:0}}();return"idle"===e?null:"error"===e?(0,a.jsxs)("button",{type:"button",onClick:c,title:"".concat(t," change").concat(1===t?"":"s"," did not save"),className:"flex items-center gap-1.5 rounded-md border border-red-500/40 bg-red-500/10 px-2 py-0.5 text-[11px] text-red-400",children:[(0,a.jsx)("span",{className:"h-1.5 w-1.5 rounded-full bg-red-500"}),"Not saved â Retry"]}):"saving"===e?(0,a.jsxs)("span",{className:"flex items-center gap-1.5 rounded-md border border-[var(--mobile-app-card-border)] px-2 py-0.5 text-[11px] text-[var(--graphite-muted)]",children:[(0,a.jsx)("span",{className:"h-1.5 w-1.5 rounded-full bg-[var(--graphite-muted)]"}),"Savingâ¦"]}):(0,a.jsxs)("span",{title:"All changes saved",className:"flex items-center gap-1.5 rounded-md border border-[var(--mobile-app-card-border)] px-2 py-0.5 text-[11px] text-[var(--graphite-muted)]",children:[(0,a.jsx)("span",{className:"h-1.5 w-1.5 rounded-full bg-[var(--graphite-muted)]"}),"Saved â"]})}var x=r(11186);function g(e){var t,r,n;let{sessionId:l,onRetry:i}=e,{job:s}=(0,x.r)(l);if(!s||"completed"===s.status&&!s.partial)return(0,a.jsxs)("span",{title:(null==s?void 0:s.partial)?void 0:"No processing job running",className:"flex items-center gap-1.5 rounded-md border border-[var(--mobile-app-card-border)] px-2 py-0.5 text-[11px] text-[var(--graphite-muted)]",children:[(0,a.jsx)("span",{className:"h-1.5 w-1.5 rounded-full bg-[var(--graphite-muted)]"}),(null==s?void 0:s.status)==="completed"?"Complete":"Idle"]});if("queued"===s.status||"processing"===s.status)return(0,a.jsxs)("span",{className:"flex items-center gap-1.5 rounded-md border border-[var(--mobile-app-card-border)] px-2 py-0.5 text-[11px] text-[var(--graphite-muted)]",children:[(0,a.jsx)("span",{className:"h-1.5 w-1.5 animate-pulse rounded-full bg-[var(--graphite-muted)]"}),"queued"===s.status?"Queuedâ¦":"Processing ".concat(s.progress_pct,"%")]});let o=s.partial?null!=(t=s.failed_capture_ids)?t:[]:null!=(r=s.input_capture_ids)?r:[],d=s.partial?"".concat(o.length," failed â Retry"):"Failed â Retry";return(0,a.jsxs)("button",{type:"button",onClick:()=>{var e;return null==i?void 0:i(null!=(e=s.job_type)?e:"extract",o)},title:null!=(n=s.error_log)?n:"Job failed",className:"flex items-center gap-1.5 rounded-md border border-red-500/40 bg-red-500/10 px-2 py-0.5 text-[11px] text-red-400",children:[(0,a.jsx)("span",{className:"h-1.5 w-1.5 rounded-full bg-red-500"}),d]})}var f=r(67909),v=r(26496),b=r(56745),y=r(77931),j=r(55412),w=r(97492);function N(e){var t,r,n;let{left:l,center:i,right:s,bottom:o,toolbar:d}=e,c=100-(null!=(t=null==l?void 0:l.defaultSize)?t:22*!!l)-(null!=(r=null==s?void 0:s.defaultSize)?r:22*!!s),u=(0,a.jsxs)(b.YZ,{direction:"horizontal",className:"min-h-0 flex-1",children:[l?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(k,{side:"left",order:1,...l}),(0,a.jsx)(w.$,{vertical:!0})]}):null,(0,a.jsxs)(b.Zk,{order:2,defaultSize:c,minSize:30,"data-testid":"v2-viewer-panel",className:"flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden bg-[var(--graphite-canvas-deep)]",children:[d?(0,a.jsx)("div",{className:"flex shrink-0 items-center gap-2 border-b border-[var(--mobile-app-card-border)] px-3 py-1.5",children:d}):null,(0,a.jsx)("div",{className:"min-h-0 flex-1 overflow-hidden",children:i})]}),s?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(w.$,{vertical:!0}),(0,a.jsx)(k,{side:"right",order:3,...s})]}):null]});return o?(0,a.jsxs)(b.YZ,{direction:"vertical",className:"flex h-full min-h-0 flex-col overflow-hidden",children:[(0,a.jsx)(b.Zk,{order:1,defaultSize:100-(null!=(n=o.defaultSize)?n:16),minSize:30,className:"flex min-h-0 flex-col overflow-hidden",children:u}),(0,a.jsx)(w.$,{}),(0,a.jsx)(S,{order:2,...o}
1)]}):(0,a.jsx)("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:u})}function k(e){let{side:t,order:r,title:l,content:i,defaultSize:s=22,minSize:o=14}=e,d=(0,n.useRef)(null);return(0,a.jsx)(C,{side:t,order:r,title:l,defaultSize:s,minSize:o,panelRef:d,children:i})}function C(e){let{side:t,order:r,title:l,defaultSize:i,minSize:s,panelRef:o,children:d}=e,[c,u]=(0,n.useState)(!1),p="left"===t?y.A:j.A;return(0,a.jsx)(b.Zk,{ref:o,order:r,defaultSize:i,minSize:s,collapsedSize:4,collapsible:!0,onCollapse:()=>u(!0),onExpand:()=>u(!1),className:"flex min-h-0 flex-col overflow-hidden",children:c?(0,a.jsxs)("button",{type:"button",onClick:()=>{var e;return null==(e=o.current)?void 0:e.expand()},title:"Show ".concat(l),className:"flex h-full w-full flex-col items-center justify-start gap-2 py-3 text-[10px] font-medium uppercase tracking-wide text-[var(--graphite-muted)] hover:text-[var(--graphite-text-header)]",children:[(0,a.jsx)(p,{className:"size-3.5 shrink-0"}),(0,a.jsx)("span",{style:{writingMode:"vertical-rl"},children:l})]}):(0,a.jsxs)("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:[(0,a.jsxs)("div",{className:"flex shrink-0 items-center justify-between border-b border-[var(--mobile-app-card-border)] px-3 py-2",children:[(0,a.jsx)("span",{className:"text-[10px] font-semibold uppercase tracking-wide text-[var(--graphite-muted)]",style:{fontFamily:"var(--font-mono)"},children:l}),(0,a.jsx)("button",{type:"button",onClick:()=>{var e;return null==(e=o.current)?void 0:e.collapse()},"aria-label":"Hide ".concat(l),title:"Hide ".concat(l),className:"rounded p-1 text-[var(--graphite-muted)] hover:text-[var(--graphite-text-header)]",children:(0,a.jsx)(p,{className:"size-3.5"})})]}),(0,a.jsx)("div",{className:"min-h-0 flex-1 overflow-y-auto p-3",children:d})]})})}function S(e){let{order:t,title:r,content:l,defaultSize:i=16,minSize:s=8,compact:o=!1}
1=e,d=(0,n.useRef)(null),[c,u]=(0,n.useState)(!1);return(0,a.jsxs)(b.Zk,{ref:d,order:t,defaultSize:i,minSize:s,collapsedSize:4,collapsible:!0,onCollapse:()=>u(!0),onExpand:()=>u(!1),className:"relative flex min-h-0 flex-col overflow-hidden",children:[o?(0,a.jsx)("button",{type:"button",onClick:()=>{var e,t;return c?null==(e=d.current)?void 0:e.expand():null==(t=d.current)?void 0:t.collapse()},"aria-label":c?"Show ".concat(r):"Hide ".concat(r),title:c?"Show ".concat(r):"Hide ".concat(r),"aria-pressed":c,className:"absolute right-2 top-1.5 z-10 rounded bg-black/40 p-1 text-[var(--graphite-muted)] hover:bg-black/60 hover:text-[var(--graphite-text-header)]",children:c?"â²":"â¼"}):(0,a.jsxs)("div",{className:"flex shrink-0 items-center justify-between border-b border-[var(--mobile-app-card-border)] px-3 py-1.5",children:[(0,a.jsx)("span",{className:"text-[10px] font-semibold uppercase tracking-wide text-[var(--graphite-muted)]",style:{fontFamily:"var(--font-mono)"},children:r}),(0,a.jsx)("button",{type:"button",onClick:()=>{var e,t;return c?null==(e=d.current)?void 0:e.expand():null==(t=d.current)?void 0:t.collapse()},"aria-label":c?"Show ".concat(r):"Hide ".concat(r),title:c?"Show ".concat(r):"Hide ".concat(r),"aria-pressed":c,className:"rounded p-1 text-[var(--graphite-muted)] hover:text-[var(--graphite-text-header)]",children:c?"â²":"â¼"})]}),c?null:(0,a.jsx)("div",{className:"min-h-0 flex-1 overflow-y-auto ".concat(o?"":"p-2"),children:l})]})}async function _(e,t,r){if(!r.length)return{ok:!1,message:"Nothing selected"};try{let n=await fetch("/api/ops/thermal/jobs",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({session_id:e,job_type:t,capture_ids:r})});if(!n.ok){var a;let e=await n.json().catch(()=>null);return{ok:!1,message:null!=(a=null==e?void 0:e.error)?a:"Failed (".concat(n.status,")")}}return{ok:!0,message:"Job queued"}}catch(e){return{ok:!1,message:"Network error â job not queued"}}}async function I(){try{var e;let t=await fetch("/api/ops/thermal/projects");if(!t.ok)return[];return null!=(e=(await t.json()).projects)?e:[]}catch(e){return[]}}async function E(e){try{var t,r;let a=await fetch("/api/ops/thermal/slatedrop-images?projectId=".concat(encodeURIComponent(e)));if(!a.ok)return{files:[],folders:[]};let n=await a.json();return{files:null!=(t=n.files)?t:[],folders:null!=(r=n.folders)?r:[]}}catch(e){return{files:[],folders:[]}}}async function M(e,t){if(!t.length)return{ok:!1,message:"Nothing selected"};try{let a=await fetch("/api/ops/thermal/sessions/".concat(e,"/import-slatedrop"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({uploadIds:t})});if(!a.ok){var r;let e=await a.json().catch(()=>null);return{ok:!1,message:null!=(r=null==e?void 0:e.error)?r:"Failed (".concat(a.status,")")}}return{ok:!0,message:"Imported ".concat(t.length)}}catch(e){return{ok:!1,message:"Network error â import failed"}}}async function T(e,t,r){try{let a=await fetch("/api/ops/thermal/upload",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({phase:"presign",sessionId:e,filename:t.name,contentType:t.type||"application/octet-stream",sizeBytes:t.size})});if(!a.ok)return{ok:!1,message:"Presign failed (".concat(a.status,")")};let{captureId:n,storagePath:l,signedUrl:i}=await a.json();if(!i||!n)return{ok:!1,message:"Presign response missing fields"};await new Promise((e,a)=>{let n=new XMLHttpRequest;n.open("PUT",i),n.upload.onprogress=e=>{e.lengthComputable&&r&&r(Math.round(e.loaded/e.total*100))},n.onload=()=>n.status<300?e():a(Error("Upload failed (".concat(n.status,")"))),n.onerror=()=>a(Error("Upload network error")),n.send(t)});let s=await fetch("/api/ops/thermal/upload",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({phase:"finalize",captureId:n,storagePath:l,sizeBytes:t.size})});if(!s.ok)return{ok:!1,message:"Finalize failed (".concat(s.status,")")};return{ok:!0,message:"Uploaded"}}catch(e){return{ok:!1,message:"Upload failed"}}}function R(e){let{label:t,active:r,onClick:n}=e;return(0,a.jsx)("button",{type:"button",onClick:n,className:"rounded-md px-2 py-1 text-left text-[11px] font-medium transition-colors ".concat(r?"bg-[color-mix(in_srgb,var(--graphite-primary)_18%,transparent)] text-[var(--graphite-text-header)]":"text-[var(--graphite-muted)] hover:text-[var(--graphite-text-header)]"),children:t})}function A(e){let{captures:t,reportIds:r,filter:l,onFilterChange:i,sessionId:s,onUploaded:o,onOpenSlateDropImport:d}
1=e,[c,u]=(0,n.useState)(!1),[p,m]=(0,n.useState)(null),[h,x]=(0,n.useState)(null),g=(0,n.useRef)(null),f=Array.from(new Set(t.map(v.nG))).sort(),b=t.filter(e=>{var t,r;return(null!=(r=null==(t=e.anomalies)?void 0:t.length)?r:0)>0}).length,y=t.filter(e=>r.has(e.id)||(0,v.kN)(e)).length,j=t.filter(e=>(0,v.T1)(e)).length,w=t.filter(e=>!e.qualityMetrics).length,N=t.filter(e=>null==e.anomalies).length,k=t.filter(e=>{var t,r,a;let n=null==(t=e.metadata)?void 0:t.findings_review;return(null!=(a=null==n||null==(r=n.accepted)?void 0:r.length)?a:0)>0}).length,C=t.filter(e=>{var t;return!!(null==(t=e.metadata)?void 0:t.findings_review)}).length;async function S(e){if(!(null==e?void 0:e.length))return;let t=Array.from(e);m({done:0,total:t.length});let r=0,a=[];for(let e=0;e<t.length;e++){let n=await T(s,t[e]);n.ok?r+=1:a.push("".concat(t[e].name,": ").concat(n.message)),m({done:e+1,total:t.length})}m(null),x(a.length?r>0?"".concat(r," uploaded, ").concat(a.length," failed â ").concat(a[0]):"Upload failed â ".concat(a[0]):null),r>0&&o()}return(0,a.jsxs)("div",{className:"flex h-full min-h-0 flex-col gap-3",children:[(0,a.jsxs)("div",{onDragOver:e=>{e.preventDefault(),u(!0)},onDragLeave:()=>u(!1),onDrop:e=>{e.preventDefault(),u(!1),S(e.dataTransfer.files)},onClick:()=>{var e;return null==(e=g.current)?void 0:e.click()},role:"button",tabIndex:0,title:"Drag radiometric image files here, or click to choose files",className:"flex cursor-pointer flex-col items-center justify-center gap-1 rounded-lg border border-dashed p-4 text-center transition-colors ".concat(c?"border-[var(--graphite-primary)] bg-[color-mix(in_srgb,var(--graphite-primary)_10%,transparent)]":"border-[var(--mobile-app-card-border)]"),children:[(0,a.jsx)("input",{ref:g,type:"file",accept:"image/*,.tif,.tiff",multiple:!0,className:"hidden",onChange:e=>void S(e.target.files)}),(0,a.jsx)("span",{className:"text-xs font-semibold text-[var(--graphite-text-header)]",children:"Drop images here"}),(0,a.jsx)("span",{className:"text-[10px] text-[var(--graphite-muted)]",children:"or click to choose files"}),p?(0,a.jsxs)("span",{className:"text-[10px] text-[var(--graphite-primary)]",children:["Uploading ",p.done,"/",p.total,"â¦"]}):null,h?(0,a.jsx)("span",{className:"text-[10px] text-[#fca5a5]",children:h}):null]}),(0,a.jsx)("button",{type:"button",onClick:d,className:"rounded-md border border-[var(--mobile-app-card-border)] px-2 py-1.5 text-xs font-medium text-[var(--graphite-text-header)] hover:border-[var(--graphite-primary)]",children:"+ Import from SlateDropâ¦"}),(0,a.jsxs)("div",{className:"flex flex-col gap-0.5",children:[(0,a.jsx)("span",{className:"mb-1 text-[10px] font-semibold uppercase tracking-wide text-[var(--graphite-muted)]",children:"Filters"}),(0,a.jsx)(R,{label:"All (".concat(t.length,")"),active:"all"===l,onClick:()=>i("all")}),(0,a.jsx)(R,{label:"Flagged (".concat(b,")"),active:"flagged"===l,onClick:()=>i("flagged")}),(0,a.jsx)(R,{label:"In report (".concat(y,")"),active:"in_report"===l,onClick:()=>i("in_report")}),(0,a.jsx)(R,{label:"High ÎT (".concat(j,")"),active:"high_delta"===l,onClick:()=>i("high_delta")}),(0,a.jsx)(R,{label:"Not decoded (".concat(w,")"),active:"not_decoded"===l,onClick:()=>i("not_decoded")}),(0,a.jsx)(R,{label:"Not AI-analyzed (".concat(N,")"),active:"not_ai_analyzed"===l,onClick:()=>i("not_ai_analyzed")}),(0,a.jsx)(R,{label:"Has findings (".concat(k,")"),active:"has_findings"===l,onClick:()=>i("has_findings")}),(0,a.jsx)(R,{label:"Reviewed (".concat(C,")"),active:"reviewed"===l,onClick:()=>i("reviewed")}),f.map(e=>(0,a.jsx)(R,{label:e,active:l===e,onClick:()=>i(e)},e))]})]})}function D(e){let{captures:t,selectedIds:r,reportIds:l,onClick:i,onOpenInAnalyze:s,sessionId:o,onUploaded:d}
1=e,[c,u]=(0,n.useState)(null),[p,m]=(0,n.useState)(null),h=(0,n.useRef)(null);async function x(e){if(!(null==e?void 0:e.length)||!o)return;let t=Array.from(e);m(null),u({done:0,total:t.length});let r=0,a=[];for(let e=0;e<t.length;e++){let n=await T(o,t[e]);n.ok?r+=1:a.push("".concat(t[e].name,": ").concat(n.message)),u({done:e+1,total:t.length})}u(null),a.length&&m(r>0?"".concat(r," uploaded, ").concat(a.length," failed â ").concat(a[0]):"Upload failed â ".concat(a[0])),r>0&&(null==d||d())}return t.length?(0,a.jsx)("div",{className:"grid h-full auto-rows-max grid-cols-[repeat(auto-fill,minmax(120px,1fr))] gap-2 overflow-y-auto p-3",children:t.map((e,t)=>{var n,o,d,c;let u=r.has(e.id),p=null!=(c=null==(n=e.anomalies)?void 0:n.length)?c:0,m=e.qualityMetrics,h=m?m.is_radiometric?"radiometric":"display-only":"pending",x=!!(null==(o=e.metadata)?void 0:o.visual_pair_id),g=!!(null==(d=e.metadata)?void 0:d.panorama),f=(0,v.T1)(e),b=l.has(e.id)||(0,v.kN)(e);return(0,a.jsxs)("button",{type:"button",title:"".concat(e.filename," â ").concat((0,v.nG)(e)," (double-click to analyze)"),onClick:r=>i(e.id,t,{shift:r.shiftKey,toggle:r.metaKey||r.ctrlKey}),onDoubleClick:()=>null==s?void 0:s(e.id,t),className:"group relative flex aspect-square flex-col overflow-hidden rounded-lg border text-left transition-colors ".concat(u?"border-[var(--graphite-primary)] ring-1 ring-[var(--graphite-primary)]":"border-[var(--mobile-app-card-border)] hover:border-[color-mix(in_srgb,var(--graphite-primary)_45%,var(--mobile-app-card-border))]"),children:[e.previewUrl?(0,a.jsx)("img",{src:e.previewUrl,alt:e.filename,className:"h-full w-full object-cover"}):(0,a.jsx)("div",{className:"flex h-full w-full items-center justify-center bg-[var(--graphite-canvas-deep)] text-[10px] text-[var(--graphite-muted)]",children:e.filename}),(0,a.jsxs)("div",{className:"absolute inset-x-0 top-0 flex items-center justify-between p-1",children:[(0,a.jsx)("span",{title:"radiometric"===h?"Radiometric â every pixel has a real temperature":"display-only"===h?"No temperature data â display only":"Not decoded yet",className:"rounded px-1 text-[9px] font-bold ".concat("radiometric"===h?"bg-[color-mix(in_srgb,var(--graphite-primary)_70%,transparent)] text-[var(--graphite-canvas)]":"bg-black/50 text-[var(--graphite-muted)]"),children:"radiometric"===h?"â":"display-only"===h?"â":"â¦"}),(0,a.jsxs)("div",{className:"flex items-center gap-1",children:[g?(0,a.jsx)("span",{title:"Stitched panorama",className:"rounded bg-black/50 px-1 text-[9px] font-bold text-[var(--graphite-primary)]",children:"PAN"}):null,x?(0,a.jsx)("span",{title:"Has a paired visual photo",className:"h-1.5 w-1.5 rounded-full bg-sky-400"}):null]})]}),(0,a.jsxs)("div",{className:"absolute inset-x-0 bottom-0 flex items-center justify-between p-1",children:[p>0?(0,a.jsx)("span",{title:"".concat(p," finding").concat(1===p?"":"s"),className:"rounded px-1 text-[9px] font-bold ".concat(f?"bg-[color-mix(in_srgb,#ef4444_60%,transparent)] text-white":"bg-black/50 text-[var(--graphite-text-header)]"),children:p}):(0,a.jsx)("span",{}),b?(0,a.jsx)("span",{title:"In report",className:"text-[10px] text-[var(--graphite-primary)]",children:"â
"}):null]})]},e.id)})}):(0,a.jsxs)("div",{onDragOver:e=>e.preventDefault(),onDrop:e=>{e.preventDefault(),x(e.dataTransfer.files)},className:"flex h-full flex-col items-center justify-center gap-3 p-6 text-center",children:[(0,a.jsx)("span",{className:"text-sm font-semibold text-[var(--graphite-text-header)]",children:"Drop thermal photos to begin â radiometric data is preserved"}),(0,a.jsx)("span",{className:"text-[11px] text-[var(--graphite-muted)]",children:"Supported cameras: FLIR \xb7 DJI \xb7 HIKMICRO \xb7 Autel \xb7 Topdon \xb7 InfiRay + any radiometric JPEG"}),(0,a.jsx)("input",{ref:h,type:"file",accept:"image/*,.tif,.tiff",multiple:!0,className:"hidden",onChange:e=>void x(e.target.files)}),(0,a.jsx)("button",{type:"button",onClick:()=>{var e;return null==(e=h.current)?void 0:e.click()},className:"rounded-md border border-[var(--mobile-app-card-border)] px-3 py-1.5 text-xs font-semibold text-[var(--graphite-text-header)] hover:border-[var(--graphite-primary)]",children:"Choose files"}),c?(0,a.jsxs)("span",{className:"text-[11px] text-[var(--graphite-muted)]",children:["Uploading ",c.done,"/",c.total,"â¦"]}):null,p?(0,a.jsx)("span",{className:"text-[11px] text-[#fca5a5]",children:p}):null]})}var F=r(7496),P=r.n(F);async function O(e){try{var t,r,a;let n=await fetch("/api/ops/thermal/captures/".concat(e,"/grid"));if(!n.ok){let e=await n.json().catch(()=>null);return{error:(r=n.status,a=null==e?void 0:e.error,401===r?"Sign in to load this image's temperature data.":415===r?null!=a?a:"This image hasn't been decoded yet â run Decode temperatures first.":404===r?"This image couldn't be found â it may have been deleted.":!a||/invalid input syntax|constraint|relation|column/i.test(a)?"This image's temperature data couldn't be loaded right now.":a)}}let l=await n.json();return{grid:{width:l.width,height:l.height,temps:l.temps,minC:l.minC,maxC:l.maxC,emissivity:null!=(t=l.emissivity)?t:null}}}catch(e){return{error:"Network error â grid not loaded"}}}var L=r(40870),z=r(47330),B=r(4709);function U(e,t){return("F"===t?9*e/5+32:e).toFixed(1)}function H(e){return new Promise((t,r)=>{e.toBlob(e=>e?t(e):r(Error("canvas.toBlob failed")),"image/png")})}async function X(e,t){let r=new(P()),a=[],n=0;for(let o of e){var l,i,s;let e=await O(o.id);if("error"in e){a.push({id:o.id,filename:o.filename,reason:e.error});continue}let d=e.grid,c=null!=(l=o.metadata)?l:{},u=null!=(i=c.tuning)?i:{emissivity:.95,reflected_c:20},p=null!=(s=d.emissivity)?s:.95,m=(0,L.y)(d.temps,d.minC,d.maxC,p,u.emissivity,u.reflected_c),h={...d,temps:Array.from(m.temps),minC:m.minC,maxC:m.maxC},x="string"==typeof c.palette?c.palette:"Iron",g=Array.isArray(c.spots)?c.spots:[],f=c.display_span,v=f&&Number.isFinite(f.lo)&&Number.isFinite(f.hi)?f:{lo:h.minC,hi:h.maxC},b=function(e,t,r){let a=document.createElement("canvas");a.width=e.width,a.height=e.height;let n=a.getContext("2d");return n&&(0,z.vQ)(n,e.temps,e.width,e.height,t,r.lo,r.hi,null),a}(h,x,v),y=await H(b),j=document.createElement("canvas");j.width=h.width,j.height=h.height;let w=j.getContext("2d"),N=y;w&&(w.drawImage(b,0,0),g.length&&function(e,t){let r=Math.max(1,Math.round(e.canvas.width/320)),a=Math.max(10,Math.round(e.canvas.width/32));e.save(),e.strokeStyle="#ffffff",e.lineWidth=r,e.font="bold ".concat(a,"px sans-serif"),e.textBaseline="bottom",t.forEach((t,n)=>{if("line"===t.kind&&null!=t.x2&&null!=t.y2)e.beginPath(),e.moveTo(t.x,t.y),e.lineTo(t.x2,t.y2),e.stroke();else if("polygon"===t.kind&&Array.isArray(t.points)&&t.points.length>=3){for(let r of(e.beginPath(),e.moveTo(t.points[0].x,t.points[0].y),t.points.slice(1)))e.lineTo(r.x,r.y);e.closePath(),e.stroke()}else if("area"===t.kind){var l,i;let r=null!=(l=t.w)?l:20,a=null!=(i=t.h)?i:20;"circle"===t.areaShape?(e.beginPath(),e.ellipse(t.x,t.y,r/2,a/2,0,0,2*Math.PI),e.stroke()):e.strokeRect(t.x-r/2,t.y-a/2,r,a)}else e.beginPath(),e.arc(t.x,t.y,3*r,0,2*Math.PI),e.stroke();let s=t.label||String(n+1),o=e.measureText(s).width+.6*a;e.fillStyle="rgba(0,0,0,0.7)",e.fillRect(t.x+4,t.y-a-4,o,a+4),e.fillStyle="#ffffff",e.fillText(s,t.x+4+.3*a,t.y)}
1),e.restore()}(w,g),N=await H(j));let k="".concat(o.filename.replace(/\.[^.]+$/,"").replace(/[^a-zA-Z0-9._-]/g,"_").slice(0,80)||"capture","-").concat(o.id.slice(0,8));r.file("".concat(k,"/clean.png"),y),r.file("".concat(k,"/annotated.png"),N),r.file("".concat(k,"/measurements.csv"),function(e,t,r){return"id,label,kind,x,y,value_".concat(r,",min_").concat(r,",max_").concat(r,",pixels\n")+e.map(e=>{var a,n,l;let i=(0,B.K)(e,t.temps,t.width,t.height);return[e.id,(null!=(a=e.label)?a:"").replace(/[,\n]/g," "),null!=(n=e.kind)?n:"point",e.x.toFixed(1),e.y.toFixed(1),U(i.value,r),null!=i.min?U(i.min,r):"",null!=i.max?U(i.max,r):"",null!=(l=i.pixels)?l:""].join(",")}).join("\n")}(g,h,t)),r.file("".concat(k,"/full-grid.csv"),function(e,t){let r=[];for(let a=0;a<e.height;a++){let n=Array(e.width);for(let r=0;r<e.width;r++)n[r]=U(e.temps[a*e.width+r],t);r.push(n.join(","))}return r.join("\n")}(h,t)),r.file("".concat(k,"/metadata.json"),function(e,t,r,a){var n,l;return JSON.stringify({id:e.id,filename:e.filename,width:t.width,height:t.height,min_c:t.minC,max_c:t.maxC,tuning:r,palette:a,camera:null!=(n=e.qualityMetrics)?n:null,capture_metadata:null!=(l=e.metadata)?l:null,exported_at:new Date().toISOString()},null,2)}(o,h,u,x)),n+=1}return{zipBlob:await r.generateAsync({type:"blob",compression:"DEFLATE"}),exportedCount:n,skipped:a}}async function Y(e,t){try{var r,a,n;let l=await fetch("/api/ops/thermal/sessions/".concat(e,"/panorama"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({captureIds:t})}),i=await l.json();if(!l.ok)return{error:null!=(r=null==i?void 0:i.error)?r:"Failed to start panorama stitch"};let s=null!=(a=i.data)?a:i;return{dispatched:!!s.dispatched,sources:Number(null!=(n=s.sources)?n:t.length)}}catch(e){return{error:"Network error â stitch not started"}}}function V(e){let{sessionId:t,captures:r,scope:l,scopeIds:i,onAddToReport:s,totalInScope:o}=e,[d,c]=(0,n.useState)(null),[u,p]=(0,n.useState)(!1),m=0===o||u;async function h(){p(!0),c("Exportingâ¦");let e="C"===window.localStorage.getItem("thermal-v2-unit")?"C":"F",t=r.filter(e=>i.includes(e.id)),{zipBlob:a,exportedCount:n,skipped:l}=await X(t,e);n>0&&function(e,t){let r=URL.createObjectURL(e),a=document.createElement("a");a.href=r,a.download=t,document.body.appendChild(a),a.click(),a.remove(),URL.revokeObjectURL(r)}(a,"thermal-export-".concat(new Date().toISOString().slice(0,10),".zip")),c(l.length?"Exported ".concat(n," â skipped ").concat(l.length," (no temperature data)"):"Exported ".concat(n," image").concat(1===n?"":"s")),p(!1)}async function x(e,r){p(!0),c("".concat(r,"â¦")),c((await _(t,e,i)).message),p(!1)}async function g(){p(!0),c("Stitchingâ¦");let e=await Y(t,i);c("error"in e?e.error:e.dispatched?"Stitching in the cloud â the panorama will appear in Library when ready.":"Saved â will stitch once the cloud worker is enabled for this environment."),p(!1)}return(0,a.jsxs)("div",{className:"flex h-full flex-col gap-3",children:[(0,a.jsxs)("button",{type:"button",disabled:m,onClick:()=>void x("extract","Decoding"),title:"Turn raw camera files into per-pixel temperature data",className:"rounded-md border border-[var(--mobile-app-card-border)] px-3 py-2 text-left text-xs font-semibold text-[var(--graphite-text-header)] transition-colors hover:border-[var(--graphite-primary)] disabled:cursor-not-allowed disabled:opacity-40",children:["Decode temperatures (",o,")",(0,a.jsx)("div",{className:"mt-0.5 text-[10px] font-normal text-[var(--graphite-muted)]",children:"Reads the raw file so every pixel has a real temperature"})]}),(0,a.jsxs)("button",{type:"button",disabled:m,onClick:()=>void x("analyze","Running AI"),title:"Have AI scan the decoded images for possible problems",className:"rounded-md border border-[var(--mobile-app-card-border)] px-3 py-2 text-left text-xs font-semibold text-[var(--graphite-text-header)] transition-colors hover:border-[var(--graphite-primary)] disabled:cursor-not-allowed disabled:opacity-40",children:["Find problems with AI (",o,")",(0,a.jsx)("div",{className:"mt-0.5 text-[10px] font-normal text-[var(--graphite-muted)]",children:"Suggests hot/cold spots for you to accept, edit, or dismiss"})]}),(0,a.jsxs)("button",{type:"button",disabled:m,onClick:()=>s(i),title:"Add these images to the report you're building",className:"rounded-md border border-[var(--mobile-app-card-border)] px-3 py-2 text-left text-xs font-semibold text-[var(--graphite-text-header)] transition-colors hover:border-[var(--graphite-primary)] disabled:cursor-not-allowed disabled:opacity-40",children:["â
Add ",o," to report"]}),(0,a.jsxs)("button",{type:"button",disabled:m,onClick:()=>void h(),title:"Download Clean + Annotated PNGs, CSVs, and metadata for these images as a ZIP",className:"rounded-md border border-[var(--mobile-app-card-border)] px-3 py-2 text-left text-xs font-semibold text-[var(--graphite-text-header)] transition-colors hover:border-[var(--graphite-primary)] disabled:cursor-not-allowed disabled:opacity-40",children:["Export ",o,(0,a.jsx)("div",{className:"mt-0.5 text-[10px] font-normal text-[var(--graphite-muted)]",children:"Clean + annotated PNG, measurement CSV, full-grid CSV, metadata JSON â zipped"})]}),o>=2?(0,a.jsxs)("button",{type:"button",disabled:u,onClick:()=>void g(),title:"Register and blend these images into one wider panorama you can measure and export like any image",className:"rounded-md border border-[var(--mobile-app-card-border)] px-3 py-2 text-left text-xs font-semibold text-[var(--graphite-text-header)] transition-colors hover:border-[var(--graphite-primary)] disabled:cursor-not-allowed disabled:opacity-40",children:["Stitch panorama (",o,")",(0,a.jsx)("div",{className:"mt-0.5 text-[10px] font-normal text-[var(--graphite-muted)]",children:"Blends these images into one wider capture, in temperature space"})]}):null,d?(0,a.jsx)("span",{className:"text-[11px] text-[var(--graphite-muted)]",children:d}):null,(0,a.jsxs)("div",{className:"mt-auto border-t border-[var(--mobile-app-card-border)] pt-2 text-[10px] text-[var(--graphite-muted)]",children:["Scope: ","image"===l.kind?"This image":"selected"===l.kind?"Selected (".concat(l.count,")"):"All (".concat(l.count,")")]})]})}function G(e){let{sessionId:t,onClose:r,onImported:l}
1=e,[i,s]=(0,n.useState)([]),[o,d]=(0,n.useState)(""),[c,u]=(0,n.useState)([]),[p,m]=(0,n.useState)([]),[h,x]=(0,n.useState)(new Set),[g,f]=(0,n.useState)(new Set),[v,b]=(0,n.useState)(!1),[y,j]=(0,n.useState)(null);async function w(){j("Importingâ¦");let e=await M(t,Array.from(g));j(e.message),e.ok&&(l(),r())}return(0,n.useEffect)(()=>{I().then(s)},[]),(0,n.useEffect)(()=>{if(!o){u([]),m([]);return}b(!0),E(o).then(e=>{let{files:t,folders:r}=e;m(t),u(r),x(new Set(r.map(e=>e.id))),b(!1)})},[o]),(0,a.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-6",children:(0,a.jsxs)("div",{className:"flex max-h-[80vh] w-full max-w-2xl flex-col overflow-hidden rounded-xl border border-[var(--mobile-app-card-border)] bg-[var(--graphite-canvas)]",children:[(0,a.jsxs)("div",{className:"flex shrink-0 items-center justify-between border-b border-[var(--mobile-app-card-border)] px-4 py-2.5",children:[(0,a.jsx)("span",{className:"text-sm font-semibold text-[var(--graphite-text-header)]",children:"Import from SlateDrop"}),(0,a.jsx)("button",{type:"button",onClick:r,"aria-label":"Close",title:"Close",className:"text-[var(--graphite-muted)] hover:text-[var(--graphite-text-header)]",children:"â"})]}),(0,a.jsxs)("div",{className:"flex shrink-0 items-center gap-2 border-b border-[var(--mobile-app-card-border)] px-4 py-2",children:[(0,a.jsx)("label",{className:"text-xs text-[var(--graphite-muted)]",children:"Project"}),(0,a.jsxs)("select",{value:o,onChange:e=>d(e.target.value),className:"rounded-md border border-[var(--mobile-app-card-border)] bg-transparent px-2 py-1 text-xs text-[var(--graphite-text-header)]",children:[(0,a.jsx)("option",{value:"",children:"Choose a projectâ¦"}),i.map(e=>(0,a.jsx)("option",{value:e.id,children:e.name},e.id))]})]}),(0,a.jsxs)("div",{className:"min-h-0 flex-1 overflow-y-auto p-3",children:[v?(0,a.jsx)("div",{className:"text-xs text-[var(--graphite-muted)]",children:"Loadingâ¦"}):null,v||!o||c.length?null:(0,a.jsx)("div",{className:"text-xs text-[var(--graphite-muted)]",children:"No images found in this project's folders."}),c.map(e=>{let t=p.filter(t=>t.folder_id===e.id),r=h.has(e.id);return(0,a.jsxs)("div",{className:"mb-2",children:[(0,a.jsxs)("button",{type:"button",onClick:()=>{var t;return t=e.id,void x(e=>{let r=new Set(e);return r.has(t)?r.delete(t):r.add(t),r})},className:"flex w-full items-center gap-1.5 rounded px-1.5 py-1 text-left text-xs font-medium text-[var(--graphite-text-header)] hover:bg-[color-mix(in_srgb,var(--graphite-text-header)_6%,transparent)]",children:[(0,a.jsx)("span",{children:r?"â¾":"â¸"}),e.name," (",e.count,")"]}),r?(0,a.jsx)("div",{className:"ml-4 grid grid-cols-[repeat(auto-fill,minmax(90px,1fr))] gap-1.5 py-1",children:t.map(e=>(0,a.jsx)("button",{type:"button",onClick:()=>{var t;return t=e.id,void f(e=>{let r=new Set(e);return r.has(t)?r.delete(t):r.add(t),r})},title:e.file_name,className:"flex aspect-square flex-col overflow-hidden rounded border text-left ".concat(g.has(e.id)?"border-[var(--graphite-primary)] ring-1 ring-[var(--graphite-primary)]":"border-[var(--mobile-app-card-border)]"),children:e.previewUrl?(0,a.jsx)("img",{src:e.previewUrl,alt:e.file_name,className:"h-full w-full object-cover"}):(0,a.jsx)("div",{className:"flex h-full w-full items-center justify-center bg-[var(--graphite-canvas-deep)] p-1 text-center text-[9px] text-[var(--graphite-muted)]",children:e.file_name})},e.id))}):null]},e.id)})]}),(0,a.jsxs)("div",{className:"flex shrink-0 items-center justify-between border-t border-[var(--mobile-app-card-border)] px-4 py-2.5",children:[(0,a.jsx)("span",{className:"text-xs text-[var(--graphite-muted)]",children:null!=y?y:"".concat(g.size," selected")}),(0,a.jsxs)("button",{type:"button",disabled:!g.size,onClick:()=>void w(),className:"rounded-md bg-[color-mix(in_srgb,var(--graphite-primary)_85%,transparent)] px-3 py-1.5 text-xs font-semibold text-[var(--graphite-canvas)] disabled:cursor-not-allowed disabled:opacity-40",children:["Import ",g.size||""]})]})]})})}let J=(0,f.default)(()=>Promise.all([r.e(44804),r.e(21761),r.e(83628)]).then(r.bind(r,83628)).then(e=>e.LibraryMap),{loadableGenerated:{webpack:()=>[83628]},ssr:!1});function K(e){let{sessionId:t,captures:r,scope:l,selection:i,onOpenInAnalyze:s,refetchCaptures:o}
1=e,[d,c]=(0,n.useState)("all"),[u,p]=(0,n.useState)(!1),[m,h]=(0,n.useState)(null),[x,g]=(0,n.useState)("grid");function f(){h("Uploaded â"),o(),setTimeout(()=>h(null),2500)}let b=(0,n.useMemo)(()=>"all"===d?r:"flagged"===d?r.filter(e=>{var t,r;return(null!=(r=null==(t=e.anomalies)?void 0:t.length)?r:0)>0}):"in_report"===d?r.filter(e=>i.reportIds.has(e.id)||(0,v.kN)(e)):"high_delta"===d?r.filter(e=>(0,v.T1)(e)):"not_decoded"===d?r.filter(e=>!e.qualityMetrics):"not_ai_analyzed"===d?r.filter(e=>null==e.anomalies):"has_findings"===d?r.filter(e=>{var t,r,a;let n=null==(t=e.metadata)?void 0:t.findings_review;return(null!=(a=null==n||null==(r=n.accepted)?void 0:r.length)?a:0)>0}):"reviewed"===d?r.filter(e=>{var t;return!!(null==(t=e.metadata)?void 0:t.findings_review)}):r.filter(e=>(0,v.nG)(e)===d),[r,d,i.reportIds]),y=(0,n.useMemo)(()=>{var e,t,a;if("all"===l.kind)return r.map(e=>e.id);if("selected"===l.kind)return r.filter(e=>i.selectedIds.has(e.id)).map(e=>e.id);let n=null!=(a=null!=(t=i.focusedId)?t:null==(e=r[0])?void 0:e.id)?a:null;return n?[n]:[]},[l,r,i.selectedIds,i.focusedId]);return(0,a.jsxs)("div",{className:"relative flex h-full min-h-0 flex-col overflow-hidden",children:[(0,a.jsx)(N,{toolbar:(0,a.jsxs)("div",{className:"flex items-center gap-1",children:[(0,a.jsx)("button",{type:"button",onClick:()=>g("grid"),className:"rounded-md px-2 py-1 text-xs font-medium ".concat("grid"===x?"bg-[color-mix(in_srgb,var(--graphite-primary)_16%,transparent)] text-[var(--graphite-text-header)]":"text-[var(--graphite-muted)] hover:text-[var(--graphite-text-header)]"),children:"Grid"}),(0,a.jsx)("button",{type:"button",onClick:()=>g("map"),className:"rounded-md px-2 py-1 text-xs font-medium ".concat("map"===x?"bg-[color-mix(in_srgb,var(--graphite-primary)_16%,transparent)] text-[var(--graphite-text-header)]":"text-[var(--graphite-muted)] hover:text-[var(--graphite-text-header)]"),children:"Map"})]}),left:{title:"Folders & filters",content:(0,a.jsx)(A,{captures:r,reportIds:i.reportIds,filter:d,onFilterChange:c,sessionId:t,onUploaded:f,onOpenSlateDropImport:()=>p(!0)})},center:"map"===x?(0,a.jsx)(J,{captures:b,selectedIds:i.selectedIds,onToggleSelect:(e,t)=>i.click(e,t,{toggle:!0}),onOpenInAnalyze:s}):(0,a.jsx)(D,{captures:b,selectedIds:i.selectedIds,reportIds:i.reportIds,onClick:i.click,onOpenInAnalyze:s,sessionId:t,onUploaded:f}),right:{title:"Next steps",content:(0,a.jsx)(V,{sessionId:t,captures:r,scope:l,scopeIds:y,totalInScope:y.length,onAddToReport:i.addToReport})}}),m?(0,a.jsx)("div",{className:"pointer-events-none absolute bottom-3 left-1/2 -translate-x-1/2 rounded-md border border-[var(--mobile-app-card-border)] bg-[var(--graphite-canvas)] px-3 py-1.5 text-xs text-[var(--graphite-muted)]",children:m}):null,u?(0,a.jsx)(G,{sessionId:t,onClose:()=>p(!1),onImported:function(){h("Imported â"),o(),setTimeout(()=>h(null),2500)}}):null]})}function q(e,t){let r=17.62*e/(243.12+e)+Math.log(Math.max(.1,Math.min(100,t))/100);return 243.12*r/(17.62-r)}function W(e){let{captures:t,activeId:r,selectedIds:n,onOpen:l,onToggleSelect:i,layout:s}=e;return t.length?(0,a.jsx)("div",{className:"vertical"===s?"flex h-full flex-col gap-0.5 overflow-y-auto p-2":"flex h-full items-center gap-2 overflow-x-auto px-3 py-2",children:t.map(e=>{var t,o;let d=e.id===r,c=n.has(e.id),u=null!=(o=null==(t=e.anomalies)?void 0:t.length)?o:0;return(0,a.jsxs)("button",{type:"button",onClick:()=>l(e.id),title:e.filename,className:"vertical"===s?"relative flex w-full items-center gap-2 rounded-md p-1.5 text-left transition-colors ".concat(d?"bg-[color-mix(in_srgb,var(--graphite-primary)_14%,transparent)]":"hover:bg-[color-mix(in_srgb,var(--graphite-text-header)_5%,transparent)]"):"relative flex h-24 w-24 shrink-0 flex-col justify-center overflow-hidden rounded-md border text-left transition-colors ".concat(d?"border-[var(--graphite-primary)] ring-1 ring-[var(--graphite-primary)]":"border-[var(--mobile-app-card-border)] hover:border-[color-mix(in_srgb,var(--graphite-primary)_45%,var(--mobile-app-card-border))]"),children:[e.previewUrl?(0,a.jsx)("img",{src:e.previewUrl,alt:e.filename,className:"vertical"===s?"h-8 w-8 shrink-0 rounded object-cover":"h-full w-full object-cover"}):(0,a.jsx)("div",{className:"vertical"===s?"flex h-8 w-8 shrink-0 items-center justify-center rounded bg-[var(--graphite-canvas-deep)] text-[8px] text-[var(--graphite-muted)]":"flex h-full w-full items-center justify-center bg-[var(--graphite-canvas-deep)] p-1 text-center text-[9px] text-[var(--graphite-muted)]",children:"vertical"===s?"":e.filename}),"vertical"===s?(0,a.jsx)("span",{className:"min-w-0 flex-1 truncate text-[11px] ".concat(d?"text-[var(--graphite-text-header)]":"text-[var(--graphite-muted)]"),children:e.filename}):null,(0,a.jsx)("span",{role:"checkbox","aria-checked":c,onClick:t=>{t.stopPropagation(),i(e.id)},title:c?"Selected â click to deselect":"Click to select",className:"absolute right-1 top-1 flex h-3.5 w-3.5 items-center justify-center rounded-sm text-[8px] ".concat(c?"bg-[color-mix(in_srgb,var(--graphite-primary)_70%,transparent)] text-[var(--graphite-canvas)]":"bg-black/40 text-transparent"),children:"â"}),u>0?(0,a.jsx)("span",{className:"absolute bottom-1 right-1 rounded bg-black/60 px-1 text-[8px] font-bold text-[var(--graphite-text-header)]",children:u}):null]},e.id)})}):(0,a.jsx)("div",{className:"p-3 text-xs text-[var(--graphite-muted)]",children:"No images in this session yet."})}function Z(e){let{spot:t,index:r,gridWidth:n,gridHeight:l,selected:i,isReference:s,onSelect:o,onDelete:d,onDragStart:c,onResizeStart:u,onLineEndStart:p}=e,m=e=>"".concat(e/n*100,"%"),h=e=>"".concat(e/l*100,"%"),x=(0,a.jsx)("span",{title:s?"Reference measurement":"Measurement ".concat(r+1),className:"pointer-events-none absolute -translate-x-1/2 -translate-y-1/2 roun
1ded-sm px-1 text-[9px] font-bold ".concat(s?"bg-[var(--graphite-primary)] text-[var(--graphite-canvas)]":"bg-black/70 text-[var(--graphite-text-header)]"),style:{left:m(t.x),top:"calc(".concat(h(t.y)," - 10px)")},children:s?"â
":r+1}),g=(e,t)=>(0,a.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),d()},title:"Delete this measurement",className:"absolute z-10 flex h-3.5 w-3.5 translate-x-1/2 -translate-y-1/2 items-center justify-center rounded-full bg-black/70 text-[9px] text-[var(--graphite-text-header)] hover:bg-red-600",style:{left:e,top:t},children:"â"});if("line"===t.kind&&null!=t.x2&&null!=t.y2)return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("svg",{className:"pointer-events-none absolute inset-0 h-full w-full overflow-visible",children:(0,a.jsx)("line",{x1:m(t.x),y1:h(t.y),x2:m(t.x2),y2:h(t.y2),stroke:i?"var(--graphite-primary)":"white",strokeWidth:i?2:1.5})}),(0,a.jsx)("button",{type:"button",onMouseDown:e=>{e.stopPropagation(),o(),p(e,"start")},"aria-label":"Drag to move this line's start",title:"Drag to move this end",className:"absolute h-2.5 w-2.5 -translate-x-1/2 -translate-y-1/2 cursor-move rounded-full border border-white bg-black/60",style:{left:m(t.x),top:h(t.y)}}),(0,a.jsx)("button",{type:"button",onMouseDown:e=>{e.stopPropagation(),o(),p(e,"end")},"aria-label":"Drag to move this line's end",title:"Drag to move this end",className:"absolute h-2.5 w-2.5 -translate-x-1/2 -translate-y-1/2 cursor-move rounded-full border border-white bg-black/60",style:{left:m(t.x2),top:h(t.y2)}}),x,g(m(t.x),h(t.y))]});if("polygon"===t.kind&&Array.isArray(t.points)&&t.points.length>=3){let e=t.points.map(e=>"".concat(e.x/n*100,",").concat(e.y/l*100)).join(" ");return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("svg",{className:"absolute inset-0 h-full w-full cursor-move overflow-visible",viewBox:"0 0 100 100",preserveAspectRatio:"none",onMouseDown:e=>{e.stopPropagation(),o(),c(e)},children:(0,a.jsx)("polygon",{points:e,fill:i?"color-mix(in srgb, var(--graphite-primary) 20%, transparent)":"rgba(255,255,255,0.12)",stroke:i?"var(--graphite-primary)":"white",strokeWidth:i?.6:.4,vectorEffect:"non-scaling-stroke"})}),x,g(m(t.points[0].x),h(t.points[0].y))]})}if("area"===t.kind){var f,v;let e=null!=(f=t.w)?f:20,r=null!=(v=t.h)?v:20,n=t.x-e/2,l=t.y-r/2;return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("div",{onMouseDown:e=>{e.stopPropagation(),o(),c(e)},title:"Drag to move â grab the corner to resize",className:"absolute cursor-move border ".concat(i?"border-[var(--graphite-primary)]":"border-white/80"," ").concat("circle"===t.areaShape?"rounded-full":""),style:{left:m(n),top:h(l),width:m(e),height:h(r)},children:(0,a.jsx)("div",{onMouseDown:e=>{e.stopPropagation(),o(),u(e)},title:"Drag to resize",className:"absolute -bottom-1 -right-1 h-2.5 w-2.5 cursor-nwse-resize rounded-sm border border-white bg-black/70"})}),x,g(m(t.x+e/2),h(t.y-r/2))]})}return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("div",{onMouseDown:e=>{e.stopPropagation(),o(),c(e)},title:"Drag to move",className:"absolute -translate-x-1/2 -translate-y-1/2 cursor-move",style:{left:m(t.x),top:h(t.y)},children:(0,a.jsx)("span",{className:"block h-3 w-3 rounded-full border-2 ".concat(i?"border-[var(--graphite-primary)]":"border-white")})}),x,g("calc(".concat(m(t.x)," + 8px)"),"calc(".concat(h(t.y)," - 8px)"))]})}function Q(e){var t,r,l,i,s,o;let{grid:d,loading:c,error:u,palette:p,lo:m,hi:h,isotherm:x,displayTemps:g,displayTransform:f,onHover:v,canvasRef:b,spots:y,tool:j,areaShape:w="box",selectedId:N,referenceId:k,onSelect:C,onCreateSpot:S,onCommitSpots:_,visualUrl:I,blend:E,align:M}=e,T=function(e){let{grid:t,spots:r,canvasRef:a,onCommitSpots:l}=e,i=(0,n.useRef)(null),[s,o]=(0,n.useState)(1),[d,c]=(0,n.useState)({x:0,y:0}),[u,p]=(0,n.useState)({left:0,top:0,width:0,height:0}),m=(0,n.useRef)(null),[h,x]=(0,n.useState)(null),g=null!=h?h:r;(0,n.useEffect)(()=>{o(1),c({x:0,y:0})},[null==t?void 0:t.width,null==t?void 0:t.height]),(0,n.useEffect)(()=>{let e=a.current,r=i.current;if(!e||!r)return;function n(){let e=a.current,r=i.current;if(!e||!r||!t)return;let n=e.getBoundingClientRect(),l=r.getBoundingClientRect(),o=n.width>0?Math.min(n.width/t.width,n.height/t.height):0,d=t.width*o,c=t.height*o;p({left:(n.left-l.left+(n.width-d)/2)/s,top:(n.top-l.top+(n.height-c)/2)/s,width:d/s,height:c/s})}let l=new ResizeObserver(n);return l.observe(e),n(),()=>l.disconnect()},[t,s]);let f=(0,n.useCallback)((e,r)=>{let a=i.current;if(!a||!t||0===u.width)return null;let n=a.getBoundingClientRect(),l=(e-n.left)/s-u.left,o=(r-n.top)/s-u.top,d=l/u.width*t.width,c=o/u.height*t.height;return{imgX:d,imgY:c,inBounds:d>=0&&c>=0&&d<=t.width&&c<=t.height}},[t,u,s]);return(0,n.useEffect)(()=>{function e(e){let a=m.current;if(!a||!t)return;if("pan"===a.type)return void c({x:a.panX+(e.clientX-a.startX),y:a.panY+(e.clientY-a.startY)});let n=f(e.clientX,e.clientY);n&&x(e=>(null!=e?e:r).map(e=>{if(e.id!==a.id)return e;if("drag"===a.type){let l=n.imgX-a.origX,i=n.imgY-a.origY;if("polygon"===e.kind&&a.origPoints)return{...e,x:a.origX+l,y:a.origY+i,points:a.origPoints.map(e=>({x:e.x+l,y:e.y+i}))};if("line"===e.kind&&null!=e.x2&&null!=e.y2){var t,r;return{...e,x:a.origX+l,y:a.origY+i,x2:(null!=(t=a.origX2)?t:e.x2)+l,y2:(null!=(r=a.origY2)?r:e.y2)+i}}return{...e,x:n.imgX,y:n.imgY}}if("resize"===a.type){let t=Math.max(4,2*Math.abs(n.imgX-e.x)),r=Math.max(4,2*Math.abs(n.imgY-e.y));return{...e,w:t,h:r}}return"line-end"===a.type?"start"===a.which?{...e,x:n.imgX,y:n.imgY}:{...e,x2:n.imgX,y2:n.imgY}:e}))}function a(){let e=m.current;m.current=null,x(t=>(e&&"pan"!==e.type&&t&&l(t),null))}return window.addEventListener("mousemove",e),window.addEventListener("mouseup",a),()=>{window.removeEventListener("mousemove",e),window.removeEventListener("mouseup",a)}},[t,r,f,l]),{stageRef:i,zoom:s,pan:d,canvasBox:u,visibleSpots:g,toImageCoords:f,handleWheel:function(e){e.preventDefault();let t=e.deltaY<0?1.1:1/1.1;o(e=>Math.min(12,Math.max(.25,e*t)))},startPan:function(e){m.current={type:"pan",startX:e.clientX,startY:e.clientY,panX:d.x,panY:d.y}},startSpotDrag:function(e){let t=r.find(t=>
1t.id===e);t&&(m.current={type:"drag",id:e,origX:t.x,origY:t.y,origX2:t.x2,origY2:t.y2,origPoints:"polygon"===t.kind?t.points:void 0},x(r))},startResize:function(e){m.current={type:"resize",id:e},x(r)},startLineEnd:function(e,t){m.current={type:"line-end",id:e,which:t},x(r)},gestureActive:()=>null!==m.current}}({grid:d,spots:y,canvasRef:b,onCommitSpots:_}),{canvasBox:R,zoom:A,pan:D,visibleSpots:F,toImageCoords:P}=T,O=null!=(t=null==f?void 0:f.rotation)?t:0,L=null!=(r=null==f?void 0:f.flipH)&&r,B=null!=(l=null==f?void 0:f.flipV)&&l,U=0===O&&!L&&!B,[H,X]=(0,n.useState)([]);function Y(){if(H.length<3)return;let e=H.reduce((e,t)=>e+t.x,0)/H.length,t=H.reduce((e,t)=>e+t.y,0)/H.length,r=(0,z.sB)();S({id:r,kind:"polygon",x:e,y:t,points:H.slice(0,64)}),C(r),X([])}return(0,n.useEffect)(()=>{X([])},[j]),(0,n.useEffect)(()=>{function e(e){"polygon"===j&&0!==H.length&&("Escape"===e.key?X([]):"Enter"===e.key&&H.length>=3&&Y())}return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[j,H]),(0,n.useEffect)(()=>{let e=b.current;if(!e||!d)return;e.width=d.width,e.height=d.height;let t=e.getContext("2d");t&&(0,z.vQ)(t,null!=g?g:d.temps,d.width,d.height,p,m,h,null!=x?x:null)},[d,p,m,h,x,g,b]),(0,a.jsxs)("div",{title:"move"===j?"Scroll to zoom, drag to pan":"polygon"===j?"Click each corner, then Enter or double-click to close the shape (Esc cancels)":"Click to place a ".concat(j),className:"relative flex h-full w-full items-center justify-center overflow-hidden ".concat("move"===j?"cursor-grab active:cursor-grabbing":"cursor-crosshair"),children:[c?(0,a.jsx)("span",{className:"text-xs text-[var(--graphite-muted)]",children:"Loading gridâ¦"}):null,u?(0,a.jsx)("span",{className:"max-w-xs text-center text-xs text-[#fca5a5]",children:u}):null,U?null:(0,a.jsx)("div",{className:"pointer-events-none absolute left-2 top-2 z-20 rounded-md border border-[var(--mobile-app-card-border)] bg-[var(--graphite-canvas)]/90 px-2 py-1 text-[10px] text-[var(--graphite-muted)]",children:"Rotated view â reset rotation to measure"}),d?(0,a.jsxs)("div",{ref:T.stageRef,onWheel:T.handleWheel,onMouseDown:function(e){if("polygon"===j){if(!U)return;let t=P(e.clientX,e.clientY);(null==t?void 0:t.inBounds)&&X(e=>[...e,{x:t.imgX,y:t.imgY}]);return}if("move"!==j){if(!U)return;let t=P(e.clientX,e.clientY);(null==t?void 0:t.inBounds)&&function(e,t){let r;if(!d)return;let a=(0,z.sB)(),n=Math.min(d.width,d.height);if("area"===j){let l=.15*n;r={id:a,kind:"area",areaShape:w,x:e,y:t,w:l,h:l}}else if("line"===j){let l=.2*n;r={id:a,kind:"line",x:e-l/2,y:t,x2:e+l/2,y2:t}}else r={id:a,kind:"point",target:"crosshair",x:e,y:t};S(r),C(a)}(t.imgX,t.imgY);return}C(null),T.startPan(e)},onDoubleClick:function(){"polygon"===j&&Y()},onMouseMove:function(e){if(T.gestureActive()||!d)return;let t=P(e.clientX,e.clientY);if(!(null==t?void 0:t.inBounds))return void v(null);let r=Math.floor(t.imgX),a=Math.floor(t.imgY);v({x:r,y:a,tempC:d.temps[a*d.width+r]})},onMouseLeave:()=>v(null),style:{transform:"translate(".concat(D.x,"px, ").concat(D.y,"px) scale(").concat(A,") rotate(").concat(O,"deg) scaleX(").concat(L?-1:1,") scaleY(").concat(B?-1:1,")")},className:"relative flex h-full w-full items-center justify-center",children:[I&&R.width>0?(0,a.jsx)("img",{src:I,alt:"",className:"pointer-events-none absolute object-cover",style:{left:R.left,top:R.top,width:R.width,height:R.height,transform:"translate(".concat(null!=(i=null==M?void 0:M.dx)?i:0,"px, ").concat(null!=(s=null==M?void 0:M.dy)?s:0,"px) scale(").concat(null!=(o=null==M?void 0:M.scale)?o:1,")")}}):null,(0,a.jsx)("canvas",{ref:b,style:{position:"relative",width:"100%",height:"100%",objectFit:"contain",imageRendering:"pixelated",display:"block",opacity:I?(null!=E?E:100)/100:1}}),R.width>0?(0,a.jsxs)("div",{className:"pointer-events-none absolute",style:{left:R.left,top:R.top,width:R.width,height:R.height},children:[F.map((e,t)=>(0,a.jsx)("div",{className:"pointer-events-auto absolute inset-0",children:(0,a.jsx)(Z,{spot:e,index:t,gridWidth:d.width,gridHeight:d.height,selected:e.id===N,isReference:e.id===k,onSelect:()=>C(e.id),onDelete:()=>_(y.filter(t=>t.id!==e.id)),onDragStart:()=>"move"===j&&U&&T.startSpotDrag(e.id),onResizeStart:()=>"move"===j&&U&&T.startResize(e.id),onLineEndStart:(t,r)=>"move"===j&&U&&T.startLineEnd(e.id,r)})},e.id)),H.length>0?(0,a.jsxs)("svg",{className:"pointer-events-none absolute inset-0 h-full w-full overflow-visible",viewBox:"0 0 100 100",preserveAspectRatio:"none",children:[(0,a.jsx)("polyline",{points:H.map(e=>"".concat(e.x/d.width*100,",").concat(e.y/d.height*100)).join(" "),fill:"none",stroke:"var(--graphite-primary)",strokeWidth:.4,strokeDasharray:"2,1.5",vectorEffect:"non-scaling-stroke"}),H.map((e,t)=>(0,a.jsx)("circle",{cx:e.x/d.width*100,cy:e.y/d.height*100,r:.6,fill:"var(--graphite-primary)",vectorEffect:"non-scaling-stroke"},t))]}):null]}):null]}):null]})}function $(e){let{palette:t,lo:r,hi:l,gridMin:i,gridMax:s,unit:o,onChange:d}=e,c=(0,n.useRef)(null),u=(0,n.useRef)(null),p=(0,n.useCallback)(e=>{let t=c.current;if(!t)return null;let r=t.getBoundingClientRect();return i+(1-Math.min(1,Math.max(0,(e-r.top)/r.height)))*(s-i)},[i,s]);function m(e){function t(e){let t=p(e.clientY);null!==t&&u.current&&("lo"===u.current?d({lo:Math.min(t,l-.1),hi:l}):d({lo:r,hi:Math.max(t,r+.1)}))}u.current=e,window.addEventListener("mousemove",t),window.addEventListener("mouseup",function e(){u.current=null,window.removeEventListener("mousemove",t),window.removeEventListener("mouseup",e)})}let h=Array.from({length:24},(e,r)=>(0,z.GV)(t,r/23)),x=s>i?(r-i)/(s-i)*100:0,g=s>i?(l-i)/(s-i)*100:100;return(0,a.jsxs)("div",{className:"flex h-full w-10 flex-col items-center gap-1 py-2",title:"Drag the handles to change the display range",children:[(0,a.jsx)("span",{className:"text-[10px] font-semibold text-[var(--graphite-text-header)]",children:(0,z.IC)(l,o,!1)}),(0,a.jsxs)("div",{ref:c,className:"relative w-3 flex-1 overflow-hidden rounded-full",style:{background:"linear-gradient(to top, ".concat(h.map(e=>"rgb(".concat(e[0],",").concat(e[1],",").concat(e[2],")")).join(","),")")},children:[(0,a.jsx)("button",{type:"button",onMouseDown:()=>m("hi"),"aria-label":"Drag to change the high end â ".concat((0,z.IC)(l,o)),title:"High end â ".concat((0,z.IC)(l,o)),className:"absolute left-1/2 h-2 w-6 -translate-x-1/2 translate-y-1/2 cursor-ns-resize rounded-sm border border-[var(--graphite-text-header)] bg-white/80",style:{bottom:"".concat(g,"%")}}),(0,a.jsx)("button",{type:"button",onMouseDown:()=>m("lo"),"aria-label":"Drag to change the low end â ".concat((0,z.IC)(r,o)),title:"Low end â ".concat((0,z.IC)(r,o)),className:"absolute left-1/2 h-2 w-6 -translate-x-1/2 translate-y-1/2 cursor-ns-resize rounded-sm border border-[var(--graphite-text-header)] bg-white/80",style:{bottom:"".concat(x,"%")}
1})]}),(0,a.jsx)("span",{className:"text-[10px] font-semibold text-[var(--graphite-text-header)]",children:(0,z.IC)(r,o,!1)})]})}function ee(e){let{sourceCanvasRef:t,hover:r,unit:l="C"}=e,[i,s]=(0,n.useState)({x:16,y:16}),[o,d]=(0,n.useState)(160),[c,u]=(0,n.useState)(!1),p=(0,n.useRef)(null),m=(0,n.useRef)(null),h=(0,n.useRef)(null);return(0,n.useEffect)(()=>{let e=p.current,a=t.current;if(!e||!a||!r||c)return;e.width=o,e.height=o;let n=e.getContext("2d");if(!n)return;n.imageSmoothingEnabled=!1;let i=o/8,s=Math.max(0,Math.min(a.width-i,r.x-i/2)),d=Math.max(0,Math.min(a.height-i,r.y-i/2));n.clearRect(0,0,o,o),n.drawImage(a,s,d,i,i,0,0,o,o),n.strokeStyle="rgba(255,255,255,0.14)",n.lineWidth=1,n.beginPath();for(let e=-(s%1*8);e<=o;e+=8)n.moveTo(e,0),n.lineTo(e,o);for(let e=-(d%1*8);e<=o;e+=8)n.moveTo(0,e),n.lineTo(o,e);n.stroke();let u=(r.x+.5-s)*8,m=(r.y+.5-d)*8;n.strokeStyle="rgba(255,255,255,0.9)",n.beginPath(),n.moveTo(u-8,m),n.lineTo(u+8,m),n.moveTo(u,m-8),n.lineTo(u,m+8),n.stroke();let h=(0,z.IC)(r.tempC,l);n.font="600 11px ui-monospace, monospace";let x=n.measureText(h).width;n.fillStyle="rgba(0,0,0,0.65)",n.fillRect(o/2-x/2-5,o-20,x+10,16),n.fillStyle="#fff",n.fillText(h,o/2-x/2,o-8)},[r,o,c,t,l]),(0,a.jsxs)("div",{style:{left:i.x,top:i.y},className:"absolute z-10 flex flex-col overflow-hidden rounded-lg border border-[var(--mobile-app-card-border)] bg-[var(--graphite-canvas)] shadow-lg",children:[(0,a.jsxs)("div",{onMouseDown:function(e){function t(e){let t=m.current;t&&s({x:t.x+(e.clientX-t.startX),y:t.y+(e.clientY-t.startY)})}m.current={startX:e.clientX,startY:e.clientY,x:i.x,y:i.y},window.addEventListener("mousemove",t),window.addEventListener("mouseup",function e(){m.current=null,window.removeEventListener("mousemove",t),window.removeEventListener("mouseup",e)})},title:"Drag to move the loupe",className:"flex cursor-move items-center justify-between gap-2 border-b border-[var(--mobile-app-card-border)] px-2 py-1",children:[(0,a.jsx)("span",{className:"text-[10px] font-semibold uppercase tracking-wide text-[var(--graphite-muted)]",children:"Loupe"}),(0,a.jsx)("button",{type:"button",onClick:()=>u(e=>!e),"aria-label":c?"Expand loupe":"Collapse loupe to a pill",title:c?"Expand loupe":"Collapse loupe to a pill","aria-pressed":c,className:"rounded px-1 text-[var(--graphite-muted)] hover:text-[var(--graphite-text-header)]",children:c?"â¢":"â"})]}),c?null:(0,a.jsxs)("div",{className:"relative",style:{width:o,height:o},children:[(0,a.jsx)("canvas",{ref:p,className:"h-full w-full",style:{imageRendering:"pixelated"}}),r?null:(0,a.jsx)("div",{className:"absolute inset-0 flex items-center justify-center text-[10px] text-[var(--graphite-muted)]",children:"Hover the image"}),(0,a.jsx)("div",{onMouseDown:function(e){function t(e){let t=h.current;t&&d(Math.min(320,Math.max(100,t.startSize+(e.clientX-t.startX))))}e.stopPropagation(),h.current={startX:e.clientX,startSize:o},window.addEventListener("mousemove",t),window.addEventListener("mouseup",function e(){h.current=null,window.removeEventListener("mousemove",t),window.removeEventListener("mouseup",e)})},title:"Drag to resize",className:"absolute bottom-0 right-0 h-3 w-3 cursor-nwse-resize text-[8px] leading-3 text-[var(--graphite-muted)]",children:"⤢"})]})]})}function et(e){var t,r;let{grid:l,loading:i,error:s,palette:o,unit:d,span:c,onSpanChange:u,isotherm:p,localContrast:m,displayPalette:h,displaySpan:x,displayTransform:g,hover:f,onHoverChange:v,spots:b,tool:y,areaShape:j,selectedId:w,referenceId:N,onSelect:k,onCreateSpot:C,onCommitSpots:S,visualUrl:_,blend:I,align:E}=e,M=(0,n.useRef)(null),T=null!=h?h:o,R=null!=x?x:c,A=!g||0===g.rotation&&!g.flipH&&!g.flipV,D=(0,n.useMemo)(()=>m&&l&&R?(0,z.vw)(l.temps,R.lo,R.hi):null,[m,l,null==R?void 0:R.lo,null==R?void 0:R.hi]);return l||i||s?(0,a.jsxs)("div",{className:"relative flex h-full min-h-0 w-full",children:[(0,a.jsx)("div",{className:"min-h-0 min-w-0 flex-1",children:(0,a.jsx)(Q,{grid:l,loading:i,error:s,palette:T,lo:null!=(t=null==R?void 0:R.lo)?t:0,hi:null!=(r=null==R?void 0:R.hi)?r:1,isotherm:p,displayTemps:D,displayTransform:g,onHover:v,canvasRef:M,spots:b,tool:y,areaShape:j,selectedId:w,referenceId:N,onSelect:k,onCreateSpot:C,onCommitSpots:S,visualUrl:_,blend:I,al
1ign:E})}),l&&c?(0,a.jsx)($,{palette:o,lo:c.lo,hi:c.hi,gridMin:l.minC,gridMax:l.maxC,unit:d,onChange:u}):null,l&&A?(0,a.jsx)(ee,{sourceCanvasRef:M,hover:f,unit:d}):null]}):(0,a.jsx)("div",{className:"flex h-full items-center justify-center text-xs text-[var(--graphite-muted)]",children:"Select an image from the working set or filmstrip"})}let er={emissivity:.95,reflected_c:20};function ea(e){var t;let[r,a]=(0,n.useState)({grid:null,loading:!1,error:null}),l=null!=(t=null==e?void 0:e.id)?t:null;return(0,n.useEffect)(()=>{if(!l)return void a({grid:null,loading:!1,error:null});a({grid:null,loading:!0,error:null});let t=!1;return O(l).then(r=>{var n,l,i;if(t)return;if("error"in r)return void a({grid:null,loading:!1,error:r.error});let s=null!=(n=null==e?void 0:e.metadata)?n:null,o=null!=(l=null==s?void 0:s.tuning)?l:er,d=null!=(i=r.grid.emissivity)?i:.95,c=(0,L.y)(r.grid.temps,r.grid.minC,r.grid.maxC,d,o.emissivity,o.reflected_c);a({grid:{...r.grid,temps:Array.from(c.temps),minC:c.minC,maxC:c.maxC},loading:!1,error:null})}),()=>{t=!0}},[l]),r}function en(e){let{label:t,grid:r,loading:l,error:i,palette:s,span:o,zoom:d,pan:c,unit:u}=e,p=(0,n.useRef)(null),[m,h]=(0,n.useState)(null);return(0,n.useEffect)(()=>{let e=p.current;if(!e||!r||!o)return;e.width=r.width,e.height=r.height;let t=e.getContext("2d");t&&(0,z.vQ)(t,r.temps,r.width,r.height,s,o.lo,o.hi,null)},[r,s,o]),(0,a.jsxs)("div",{className:"relative flex h-full min-w-0 flex-1 flex-col overflow-hidden border border-[var(--mobile-app-card-border)]",children:[(0,a.jsxs)("div",{className:"flex shrink-0 items-center justify-between border-b border-[var(--mobile-app-card-border)] px-2 py-1 text-[10px] font-semibold uppercase tracking-wide text-[var(--graphite-muted)]",children:[(0,a.jsx)("span",{children:t}),null!=m?(0,a.jsx)("span",{className:"tabular-nums text-[var(--graphite-text-header)]",children:(0,z.IC)(m,u)}):null]}),(0,a.jsxs)("div",{className:"relative flex min-h-0 flex-1 items-center justify-center overflow-hidden",onMouseMove:function(e){let t=p.current;if(!t||!r)return;let a=t.getBoundingClientRect();if(0===a.width||0===a.height)return;let n=Math.min(a.width/r.width,a.height/r.height),l=r.width*n,i=r.height*n,s=(a.width-l)/2,o=(a.height-i)/2,d=e.clientX-a.left-s,c=e.clientY-a.top-o;if(d<0||c<0||d>l||c>i)return void h(null);let u=Math.min(r.width-1,Math.floor(d/n)),m=Math.min(r.height-1,Math.floor(c/n));h(r.temps[m*r.width+u])},onMouseLeave:()=>h(null),children:[l?(0,a.jsx)("span",{className:"text-xs text-[var(--graphite-muted)]",children:"Loading gridâ¦"}):null,i?(0,a.jsx)("span",{className:"max-w-xs text-center text-xs text-[#fca5a5]",children:i}):null,r?(0,a.jsx)("canvas",{ref:p,style:{width:"100%",height:"100%",objectFit:"contain",imageRendering:"pixelated",transform:"translate(".concat(c.x,"px, ").concat(c.y,"px) scale(").concat(d,")")}}):null]})]})}function el(e){var t,r,l,i;let{captureA:s,captureB:o,palette:d,unit:c,spanLock:u}=e,{a:p,b:m}=(l=s,i=o,{a:ea(l),b:ea(i)}),[h,x]=(0,n.useState)(1),[g,f]=(0,n.useState)({x:0,y:0}),v=(0,n.useRef)(null);(0,n.useEffect)(()=>{x(1),f({x:0,y:0})},[null==s?void 0:s.id,null==o?void 0:o.id]);let b=p.grid?{lo:p.grid.minC,hi:p.grid.maxC}:null,y=m.grid?{lo:m.grid.minC,hi:m.grid.maxC}:null,j=u&&p.grid&&m.grid?{lo:Math.min(p.grid.minC,m.grid.minC),hi:Math.max(p.grid.maxC,m.grid.maxC)}:null;return(0,n.useEffect)(()=>{function e(e){let t=v.current;t&&f({x:t.panX+(e.clientX-t.startX),y:t.panY+(e.clientY-t.startY)})}function t(){v.current=null}return window.addEventListener("mousemove",e),window.addEventListener("mouseup",t),()=>{window.removeEventListener("mousemove",e),window.removeEventListener("mouseup",t)}},[]),(0,a.jsxs)("div",{className:"flex h-full w-full cursor-grab gap-2 p-2 active:cursor-grabbing",onWheel:function(e){e.preventDefault();let t=e.deltaY<0?1.1:1/1.1;x(e=>Math.min(12,Math.max(.25,e*t)))},onMouseDown:function(e){v.current={startX:e.clientX,startY:e.clientY,panX:g.x,panY:g.y}},"data-testid":"analyze-compare-view",children:[(0,a.jsx)(en,{label:null!=(t=null==s?void 0:s.filename)?t:"â",grid:p.grid,loading:p.loading,error:p.error,palette:d,span:null!=j?j:b,zoom:h,pan:g,unit:c}),(0,a.jsx)(en,{label:null!=(r=null==o?void 0:o.filename)?r:"â",grid:m.grid,loading:m.loading,error:m.error,palette:d,span:null!=j?j:y,zoom:h,pan:g,unit:c})]})}function ei(e){let{unit:t,onUnitChange:r,displayTransform:n,onRotate90:l,onFlipHorizontal:i,onFlipVertical:s,onResetTransform:o}=e,d=!!n&&(0!==n.rotation||n.flipH||n.flipV);return(0,a.jsxs)("div",{className:"absolute left-0 top-8 z-50 flex flex-col gap-1 rounded-md border border-[var(--mobile-app-card-border)] bg-[var(--graphite-canvas)] p-2 text-[11px] shadow-lg",children:[(0,a.jsx)("span",{className:"px-1 text-[10px] font-semibold uppercase tracking-wide text-[var(--graphite-muted)]",children:"Units"}),(0,a.jsx)("div",{className:"inline-flex overflow-hidden rounded-md border border-[var(--mobile-app-card-border)]",children:["C","F"].map(e=>(0,a.jsxs)("button",{type:"button",onClick:()=>r(e),className:"px-2.5 py-1 font-semibold ".concat(t===e?"bg-[color-mix(in_srgb,var(--graphite-primary)_18%,transparent)] text-[var(--graphite-text-header)]":"text-[var(--graphite-muted)] hover:text-[var(--graphite-text-header)]"),children:["\xb0",e]},e))}),(0,a.jsx)("span",{className:"mt-1 px-1 text-[10px] font-semibold uppercase tracking-wide text-[var(--graphite-muted)]",children:"Rotate / flip"}),(0,a.jsxs)("div",{className:"flex items-center gap-1",children:[(0,a.jsx)("button",{type:"button",onClick:l,title:"Rotate 90\xb0 clockwise (non-destructive â the grid itself never changes)",className:"rounded px-2 py-1 text-[var(--graphite-muted)] hover:text-[var(--graphite-text-header)]",children:"â³ 90\xb0"}),(0,a.jsx)("button",{type:"button",onClick:i,title:"Flip horizontally",className:"rounded px-2 py-1 text-[var(--graphite-muted)] hover:text-[var(--graphite-text-header)]",children:"â H"}),(0,a.jsx)("button",{type:"button",onClick:s,title:"Flip vertically",className:"rounded px-2 py-1 text-[var(--graphite-muted)] hover:text-[var(--graphite-text-header)]",children:"âµ V"})]}),d?(0,a.jsx)("button",{type:"button",onClick:o,className:"self-start px-1 text-[var(--graphite-muted)] underline hover:text-[var(--graphite-text-header)]",children:"Reset rotation"}):null]})}function es(e){let{viewOriginal:t,onViewOriginalStart:r,onViewOriginalEnd:n,focusMode:l,onToggleFocusMode:i}
1=e;return(0,a.jsxs)("div",{className:"flex items-center gap-1 border-l border-[var(--mobile-app-card-border)] pl-2",children:[(0,a.jsx)("button",{type:"button",onMouseDown:r,onMouseUp:n,onMouseLeave:n,"aria-label":"View original camera image (hold)",title:"Hold to view the original camera image (O) â no overlays, no tuning","aria-pressed":t,className:"rounded px-1.5 py-0.5 ".concat(t?"text-[var(--graphite-primary)]":"text-[var(--graphite-muted)] hover:text-[var(--graphite-text-header)]"),children:"\uD83D\uDC41"}),(0,a.jsx)("button",{type:"button",onClick:i,"aria-label":"Focus mode",title:"Focus mode â collapse the rails and filmstrip for a maximum viewer (F)","aria-pressed":l,className:"rounded px-1.5 py-0.5 ".concat(l?"text-[var(--graphite-primary)]":"text-[var(--graphite-muted)] hover:text-[var(--graphite-text-header)]"),children:"â¶"})]})}function eo(e){let{canCompare:t,compareMode:r,onToggleCompare:n,spanLock:l,onSpanLockChange:i}=e;return(0,a.jsxs)("div",{className:"flex items-center gap-2 border-l border-[var(--mobile-app-card-border)] pl-2",children:[(0,a.jsx)("button",{type:"button",onClick:n,disabled:!t&&!r,title:t||r?"Compare two selected images side by side":"Select exactly 2 images in Library to compare","aria-pressed":r,className:"rounded px-1.5 py-0.5 text-[11px] font-medium disabled:cursor-not-allowed disabled:opacity-30 ".concat(r?"text-[var(--graphite-primary)]":"text-[var(--graphite-muted)] hover:text-[var(--graphite-text-header)]"),children:"â§â§ Compare"}),r?(0,a.jsxs)("label",{className:"flex items-center gap-1 text-[11px] text-[var(--graphite-muted)]",children:[(0,a.jsx)("input",{type:"checkbox",checked:l,onChange:e=>i(e.target.checked)}),"Lock span across both"]}):null]})}function ed(e){let{canUndo:t,canRedo:r,onUndo:n,onRedo:l,onCopySettings:i,onPasteSettings:s,canPaste:o}=e;return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"flex items-center gap-1",children:[(0,a.jsx)("button",{type:"button",onClick:n,disabled:!t,title:"Undo (Ctrl+Z)",className:"rounded px-1.5 py-0.5 text-[var(--graphite-muted)] hover:text-[var(--graphite-text-header)] disabled:cursor-not-allowed disabled:opacity-30",children:"â¶"}),(0,a.jsx)("button",{type:"button",onClick:l,disabled:!r,title:"Redo (Ctrl+Shift+Z)",className:"rounded px-1.5 py-0.5 text-[var(--graphite-muted)] hover:text-[var(--graphite-text-header)] disabled:cursor-not-allowed disabled:opacity-30",children:"â·"})]}),(0,a.jsxs)("div",{className:"flex items-center gap-1 border-l border-[var(--mobile-app-card-border)] pl-2",children:[(0,a.jsx)("button",{type:"button",onClick:i,title:"Copy this image's palette, span, tuning, and alarm mode (Ctrl+Shift+C)",className:"rounded px-1.5 py-0.5 text-[11px] text-[var(--graphite-muted)] hover:text-[var(--graphite-text-header)]",children:"â§ Copy"}),(0,a.jsx)("button",{type:"button",onClick:s,disabled:!o,title:o?"Paste the copied look onto this scope (Ctrl+Shift+V)":"Copy a look first",className:"rounded px-1.5 py-0.5 text-[11px] text-[var(--graphite-muted)] hover:text-[var(--graphite-text-header)] disabled:cursor-not-allowed disabled:opacity-30",children:"â§ Paste"})]})]})}let ec=[{id:"move",label:"Move/Select",hint:"Select existing measurements to drag, resize, or delete"},{id:"point",label:"Point",hint:"Click the image to read one pixel's temperature"},{id:"area",label:"Area",hint:"Click the image to average a region's temperature"},{id:"line",label:"Line",hint:"Click the image to average along a line"},{id:"polygon",label:"Polygon",hint:"Click each corner, then Enter (or double-click) to close the shape"}];function eu(e){let{palette:t,onPaletteChange:r,unit:l,onUnitChange:i,hoverTemp:s,tool:o,onToolChange:d,areaShape:c,onAreaShapeChange:u,canUndo:p,canRedo:m,onUndo:h,onRedo:x,imageIndex:g,imageCount:f,onPrev:v,onNext:b,onCopySettings:y,onPasteSettings:j,canPaste:w,onEnhanceHere:N,displayTransform:k,onRotate90:C,onFlipHorizontal:S,onFlipVertical:_,onResetTransform:I,viewOriginal:E,onViewOriginalStart:M,onViewOriginalEnd:T,focusMode:R,onToggleFocusMode:A,canCompare:D,compareMode:F,onToggleCompare:P,spanLock:O,onSpanLockChange:L}
1=e,[B,U]=(0,n.useState)(!1),[H,X]=(0,n.useState)(!1);return(0,n.useEffect)(()=>{if(B||H)return window.addEventListener("keydown",e,!0),()=>window.removeEventListener("keydown",e,!0);function e(e){"Escape"===e.key&&(e.stopPropagation(),U(!1),X(!1))}},[B,H]),(0,a.jsxs)("div",{className:"flex w-full items-center justify-between gap-3",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)("div",{className:"inline-flex overflow-hidden rounded-md border border-[var(--mobile-app-card-border)] text-[11px]",children:ec.map(e=>(0,a.jsxs)("span",{className:"relative inline-flex",children:[(0,a.jsx)("button",{type:"button",onClick:()=>d(e.id),title:"area"===e.id?"".concat(e.hint," â current shape: ").concat(c):e.hint,className:"px-2 py-1 font-medium ".concat(o===e.id?"bg-[color-mix(in_srgb,var(--graphite-primary)_18%,transparent)] text-[var(--graphite-text-header)]":"text-[var(--graphite-muted)] hover:text-[var(--graphite-text-header)]"),children:"area"===e.id?"Area ".concat("circle"===c?"â":"â¡"):e.label}),"area"===e.id?(0,a.jsx)("button",{type:"button",onClick:()=>U(e=>!e),"aria-label":"Choose the area shape",title:"Choose the area shape","aria-expanded":B,className:"px-1 text-[var(--graphite-muted)] hover:text-[var(--graphite-text-header)]",children:"â¾"}):null]},e.id))}),B?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("div",{className:"fixed inset-0 z-40",onClick:()=>U(!1)}),(0,a.jsx)("div",{className:"absolute left-40 top-9 z-50 flex flex-col rounded-md border border-[var(--mobile-app-card-border)] bg-[var(--graphite-canvas)] p-1 text-[11px] shadow-lg",children:["box","circle"].map(e=>(0,a.jsx)("button",{type:"button",onClick:()=>{u(e),d("area"),U(!1)},className:"rounded px-3 py-1 text-left ".concat(c===e?"bg-[color-mix(in_srgb,var(--graphite-primary)_18%,transparent)] text-[var(--graphite-text-header)]":"text-[var(--graphite-muted)] hover:text-[var(--graphite-text-header)]"),children:"box"===e?"â¡ Box":"â Circle"},e))})]}):null,(0,a.jsx)("select",{value:t,onChange:e=>r(e.target.value),title:"Color palette",className:"rounded-md border border-[var(--mobile-app-card-border)] bg-transparent px-1.5 py-0.5 text-[11px] text-[var(--graphite-text-header)]",children:z.pj.map(e=>(0,a.jsx)("option",{value:e,children:e},e))}),(0,a.jsxs)("div",{className:"relative",children:[(0,a.jsx)("button",{type:"button",onClick:()=>X(e=>!e),title:"More display settings","aria-expanded":H,"aria-label":"More display settings",className:"rounded-md border border-[var(--mobile-app-card-border)] px-1.5 py-0.5 text-[11px] text-[var(--graphite-muted)] hover:text-[var(--graphite-text-header)]",children:"â¯"}),H?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("div",{className:"fixed inset-0 z-40",onClick:()=>X(!1)}),(0,a.jsx)(ei,{unit:l,onUnitChange:e=>{i(e),X(!1)},displayTransform:k,onRotate90:C,onFlipHorizontal:S,onFlipVertical:_,onResetTransform:I})]}):null]}),(0,a.jsx)(ed,{canUndo:p,canRedo:m,onUndo:h,onRedo:x,onCopySettings:y,onPasteSettings:j,canPaste:w}),(0,a.jsx)(es,{viewOriginal:E,onViewOriginalStart:M,onViewOriginalEnd:T,focusMode:R,onToggleFocusMode:A}),(0,a.jsx)(eo,{canCompare:D,compareMode:F,onToggleCompare:P,spanLock:O,onSpanLockChange:L})]}),(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[null!=s?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("span",{className:"text-[11px] font-semibold tabular-nums text-[var(--graphite-text-header)]",children:(0,z.IC)(s,l)}),(0,a.jsx)("button",{type:"button",onClick:N,"aria-label":"Enhance here",title:"Enhance here â center the display span on this temperature (E)",className:"rounded px-1.5 py-0.5 text-[var(--graphite-muted)] hover:text-[var(--graphite-text-header)]",children:"â"})]}):null,f>0?(0,a.jsxs)("div",{className:"flex items-center gap-1 text-[11px] text-[var(--graphite-muted)]",children:[(0,a.jsx)("button",{type:"button",onClick:v,disabled:g<=0,"aria-label":"Previous image",title:"Previous image ( [ )",className:"rounded px-1.5 py-0.5 hover:text-[var(--graphite-text-header)] disabled:cursor-not-allowed disabled:opacity-30",children:"â¹"}),(0,a.jsxs)("span",{className:"tabular-nums",children:[g+1,"/",f]}),(0,a.jsx)("button",{type:"button",onClick:b,disabled:g>=f-1,"aria-label":"Next image",title:"Next image ( ] )",className:"rounded px-1.5 py-0.5 hover:text-[var(--graphite-text-header)] disabled:cursor-not-allowed disabled:opacity-30",children:"âº"})]}):null]})]})}function ep(e){let{temps:t,unit:r}=e;if(!t)return null;let{max:n,min:l,avg:i}=function(e){let t=1/0,r=-1/0,a=0;for(let n=0;n<e.length;n++){let l=e[n];l<t&&(t=l),l>r&&(r=l),a+=l}return{min:t,max:r,avg:e.length?a/e.length:0}}(t);return(0,a.jsxs)("div",{className:"shrink-0 border-b border-[var(--mobile-app-card-border)] px-1 py-2 text-[11px] tabular-nums text-[var(--graphite-muted)]",children:["Max ",(0,z.IC)(n,r)," \xb7 Min ",(0,z.IC)(l,r)," \xb7 Avg ",(0,z.IC)(i,r)]})}function em(e){let{title:t,open:r,onToggle:n,children:l}=e;return(0,a.jsxs)("div",{className:"flex flex-col border-b border-[var(--mobile-app-card-border)] last:border-b-0",children:[(0,a.jsxs)("button",{type:"button",onClick:n,"aria-expanded":r,className:"flex shrink-0 items-center justify-between px-1 py-2 text-left",children:[(0,a.jsx)("span",{className:"text-[10px] font-semibold uppercase tracking-wide text-[var(--graphite-muted)]",children:t}),(0,a.jsx)("span",{className:"text-[var(--graphite-muted)]",children:r?"â¾":"â¸"})]}),r?(0,a.jsx)("div",{className:"min-h-0 pb-2",children:l}):null]})}function eh(e){return"action"===e?"Critical":"watch"===e?"Warning":"Advisory"}function ex(e){return"action"===e?0:"watch"===e?1:2}function eg(e){return"action"===e?"bg-red-500/15 text-red-400 border-red-500/40":"watch"===e?"bg-sky-4
100/15 text-sky-300 border-sky-400/40":"bg-[color-mix(in_srgb,var(--graphite-muted)_20%,transparent)] text-[var(--graphite-muted)] border-[var(--mobile-app-card-border)]"}let ef={line:"Line"};function ev(e){let{spots:t,grid:r,unit:n,comparePair:l,onClear:i}=e,s=t.findIndex(e=>e.id===l[0]),o=t.findIndex(e=>e.id===l[1]);if(s<0||o<0)return null;let d=(0,B.K)(t[s],r.temps,r.width,r.height).value,c=(0,B.K)(t[o],r.temps,r.width,r.height).value;return(0,a.jsxs)("div",{className:"flex shrink-0 items-center justify-between rounded-md border border-[var(--mobile-app-card-border)] px-2 py-1 text-[11px]",children:[(0,a.jsxs)("span",{className:"text-[var(--graphite-text-header)]",children:["#",o+1," vs #",s+1,": Î ",(0,z.OJ)(c-d,n)]}),(0,a.jsx)("button",{type:"button",onClick:i,"aria-label":"Clear Î-compare",title:"Clear Î-compare",className:"text-[var(--graphite-muted)] hover:text-[var(--graphite-text-header)]",children:"â"})]})}function eb(e){let{spot:t,grid:r,unit:n}=e,l=(0,B.u)(t,r.temps,r.width,r.height);if(l.length<2)return null;let i=Math.min(...l),s=Math.max(...l),o=s-i||1,d=l.map((e,t)=>"".concat(t/(l.length-1)*220,",").concat(80-(e-i)/o*80)).join(" ");return(0,a.jsxs)("div",{className:"flex shrink-0 flex-col gap-1 rounded-md border border-[var(--mobile-app-card-border)] p-2",children:[(0,a.jsxs)("span",{className:"text-[10px] font-semibold uppercase tracking-wide text-[var(--graphite-muted)]",children:["Line profile â ",ef.line]}),(0,a.jsx)("svg",{viewBox:"0 0 ".concat(220," ").concat(80),width:"100%",height:80,preserveAspectRatio:"none",children:(0,a.jsx)("polyline",{points:d,fill:"none",stroke:"var(--graphite-primary)",strokeWidth:1.5})}),(0,a.jsxs)("div",{className:"flex justify-between text-[10px] text-[var(--graphite-muted)]",children:[(0,a.jsxs)("span",{children:["Min ",(0,z.IC)(i,n)]}),(0,a.jsxs)("span",{children:["Max ",(0,z.IC)(s,n)]})]})]})}let ey={point:"Point",area:"Area",line:"Line",polygon:"Polygon"};function ej(e){var t;let{spots:r,grid:l,unit:i,referenceId:s,selectedId:o,onSelect:d,onSetReference:c,onRename:u,onDelete:p,onMarkExtreme:m,comparePair:h,pendingCompareId:x,onToggleCompare:g,onClearCompare:f,severityBands:v}=e,[b,y]=(0,n.useState)(null),[j,w]=(0,n.useState)("");if(!l)return(0,a.jsx)("div",{className:"p-3 text-xs text-[var(--graphite-muted)]",children:"Open an image to measure it."});let N=(0,a.jsxs)("div",{className:"flex shrink-0 gap-2",children:[(0,a.jsx)("button",{type:"button",onClick:()=>m("max"),title:"Place a marker on the hottest pixel â it follows the hottest pixel if tuning changes",className:"flex-1 rounded-md border border-[var(--mobile-app-card-border)] px-2 py-1 text-[11px] font-medium text-[var(--graphite-text-header)] hover:border-[var(--graphite-primary)]",children:"Mark hottest"}),(0,a.jsx)("button",{type:"button",onClick:()=>m("min"),title:"Place a marker on the coldest pixel â it follows the coldest pixel if tuning changes",className:"flex-1 rounded-md border border-[var(--mobile-app-card-border)] px-2 py-1 text-[11px] font-medium text-[var(--graphite-text-header)] hover:border-[var(--graphite-primary)]",children:"Mark coldest"})]});if(!r.length)return(0,a.jsxs)("div",{className:"flex flex-col gap-2",children:[N,(0,a.jsx)("div",{className:"p-1 text-xs text-[var(--graphite-muted)]",children:"No measurements yet â pick Point, Area, or Line above and click the image."})]});let k=r.map(e=>(0,B.K)(e,l.temps,l.width,l.height).value),C=r.findIndex(e=>e.id===s),S=C>=0?k[C]:null,_=null!=(t=r.find(e=>e.id===o))?t:null,I=k.reduce((e,t)=>e+t,0)/k.length,E=Math.max(...k)-Math.min(...k);async function M(){let e=["Label Temp Î vs reference",...r.map((e,t)=>{var r,a;let n=k[t],l=null!==S&&e.id!==s?n-S:null;return[null!=(a=e.label)?a:"".concat(ey[null!=(r=e.kind)?r:"point"]," ").concat(t+1),(0,z.IC)(n,i,!1),null!==l?(0,z.OJ)(l,i):""].join(" ")})].join("\n");try{await navigator.clipboard.writeText(e)}catch(e){}}return(0,a.jsxs)("div",{className:"flex h-full flex-col gap-2",children:[N,(0,a.jsx)("ul",{className:"flex flex-1 flex-col gap-1 overflow-y-auto",children:r.map((e,t)=>{var r,n,l,m;let h=k[t],f=e.id===s,N=null===S||f?null:h-S,C=null!==N?(l=Math.abs(N),(m=null!=v?v:null)?l>=m.critical?"action":l>=m.warning?"watch":l>=m.advisory?"advisory":null:null):null;return(0,a.jsxs)("li",{onClick:()=>d(e.id),className:"flex cursor-pointer items-center gap-2 rounded-md border px-2 py-1.5 text-[11px] ".concat(e.id===o?"border-[var(--graphite-primary)]":"border-[var(--mobile-app-card-border)]"),children:[(0,a.jsx)("button",{type:"button",onClick:t=>{t.stopPropagation(),c(e.id)},"aria-label":f?"Measurement ".concat(t+1," â reference"):"Set measurement ".concat(t+1," as reference"),title:f?"Reference measurement":"Set as reference","aria-pressed":f,className:"shrink-0 rounded-sm px-1 text-[9px] font-bold ".concat(f?"bg-[var(--graphite-primary)] text-[var(--graphite-canvas)]":"bg-black/40 text-[var(--graphite-muted)]"),children:t+1}),(0,a.jsx)("span",{className:"w-10 shrink-0 text-[var(--graphite-muted)]",children:ey[null!=(r=e.kind)?r:"point"]}),b===e.id?(0,a.jsx)("input",{autoFocus:!0,value:j,onChange:e=>w(e.target.value),onClick:e=>e.stopPropagation(),onBlur:()=>{u(e.id,j),y(null)},onKeyDown:t=>{"Enter"===t.key&&(u(e.id,j),y(null))},className:"min-w-0 flex-1 rounded border border-[var(--mobile-app-card-border)] bg-transparent px-1 text-[var(--graphite-text-header)]"}):(0,a.jsx)("span",{className:"min-w-0 flex-1 truncate text-[var(--graphite-text-header)]",children:null!=(n=e.label)?n:""}),(0,a.jsx)("span",{className:"shrink-0 font-semibold text-[var(--graphite-text-header)]",children:(0,z.IC)(h,i)}),(0,a.jsx)("span",{className:"w-14 shrink-0 rounded px-1 text-right ".concat(C?"border ".concat(eg(C)):"border-transparent text-[var(--graphite-muted)]"),children:f?"ref":null!==N?(0,z.OJ)(N,i):"â"}),(0,a.jsx)("button",{type:"button",onClick:t=>{var r;t.stopPropagation(),w(null!=(r=e.label)?r:""),y(e.id)},"aria-label":"Rename measurement ".concat(t+1),title:"Rename",className:"shrink-0 text-[var(--graphite-muted)] hover:text-[var(--graphite-text-header)]",children:"â"}),(0,a.jsx)("button",{type:"button",onClick:t=>{t.stopPropagation(),g(e.id)},"aria-label":x===e.id?"Cancel comparing measurement ".concat(t+1):"Compare measurement ".concat(t+1," to another"),title:x===e.id?"Cancel compare":"Compare to another measurement","aria-pressed":x===e.id,className:"shrink-0 text-[10px] ".concat(x===e.id?"text-[var(--graphite-primary)]":"text-[var(--graphite-muted)] hover:text-[var(--graphite-text-header)]"),children:"â"}),(0,a.jsx)("button",{type:"button",onClick:t=>{t.stopPropagation(),p(e.id)},"aria-label":"Delete measurement ".concat(t+1),title:"Delete this measurement",className:"shrink-0 text-[var(--graphite-muted)] hover:text-red-400",children:"â"})]},e.id)})}),r.length>1?(0,a.jsxs)("div",{className:"shrink-0 border-t border-[var(--mobile-app-card-border)] pt-2 text-[11px] text-[var(--graphite-muted)]",children:["Average ",(0,z.IC)(I,i)," \xb7 Spread ",(0,z.OJ)(E,i)]}):null,h?(0,a.jsx)(ev,{spots:r,grid:l,unit:i,comparePair:h,onClear:f}):null,(null==_?void 0:_.kind)==="line"?(0,a.jsx)(eb,{spot:_,grid:l,unit:i}):null,(0,a.jsx)("button",{type:"button",onClick:()=>void M(),className:"shrink-0 rounded-md border border-[var(--mobile-app-card-border)] px-2 py-1 text-[11px] font-medium text-[var(--graphite-text-header)] hover:border-[var(--graphite-primary)]",children:"Copy table"})]})}var ew=r(4115);async function eN(e,t){let r=await Promise.all(e.map(e=>m(e,{tuning:t}))),a=r.filter(Boolean).length;return{ok:a,failed:r.length-a}}function ek(e){let{message:t,onKeep:r,onUndo:l}
1=e,[i,s]=(0,n.useState)(Math.ceil(10));return(0,n.useEffect)(()=>{let e=setInterval(()=>s(e=>Math.max(0,e-1)),1e3),t=setTimeout(r,1e4);return()=>{clearInterval(e),clearTimeout(t)}},[]),(0,a.jsxs)("div",{role:"status","aria-live":"polite",className:"pointer-events-auto fixed left-1/2 top-4 z-[100] flex -translate-x-1/2 items-center gap-3 rounded-lg border border-[var(--mobile-app-card-border)] bg-[var(--graphite-canvas)] px-4 py-2.5 shadow-lg",children:[(0,a.jsx)("span",{className:"text-xs text-[var(--graphite-text-header)]",children:t}),(0,a.jsx)("button",{type:"button",onClick:l,className:"rounded-md border border-[var(--mobile-app-card-border)] px-2 py-1 text-xs font-semibold text-[var(--graphite-text-header)] hover:border-[var(--graphite-primary)]",children:"Undo"}),(0,a.jsxs)("button",{type:"button",onClick:r,title:"Keeps automatically in ".concat(i,"s"),className:"rounded-md bg-[color-mix(in_srgb,var(--graphite-primary)_85%,transparent)] px-2 py-1 text-xs font-semibold text-[var(--graphite-canvas)]",children:["Keep (",i,"s)"]})]})}function eC(e){let{label:t,hint:r,value:n,min:l,max:i,step:s,onChange:o}=e;return(0,a.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between",children:[(0,a.jsx)("label",{title:r,className:"text-[11px] text-[var(--graphite-muted)]",children:t}),(0,a.jsx)("input",{type:"number",value:n,min:l,max:i,step:s,onChange:e=>{let t=Number(e.target.value);Number.isFinite(t)&&o(t)},onBlur:e=>{var t;let r=Number(e.target.value);o((t=Number.isFinite(r)?r:l,Math.min(i,Math.max(l,t))))},className:"w-16 border-b border-[var(--mobile-app-card-border)] bg-transparent py-0.5 text-right text-[11px] text-[var(--graphite-text-header)] focus:border-[var(--graphite-primary)] focus:outline-none"})]}),(0,a.jsx)("input",{type:"range",min:l,max:i,step:s,value:n,onChange:e=>o(Number(e.target.value)),className:"w-full accent-[var(--graphite-primary)]"})]})}function eS(e){let{label:t,hint:r,value:n,onChange:l}=e;return(0,a.jsxs)("label",{title:r,className:"flex flex-col gap-1 text-[var(--graphite-muted)]",children:[t,(0,a.jsx)("input",{type:"number",value:null!=n?n:"",onChange:e=>l(""===e.target.value?void 0:Number(e.target.value)),className:"border-b border-[var(--mobile-app-card-border)] bg-transparent py-0.5 text-[var(--graphite-text-header)] focus:border-[var(--graphite-primary)] focus:outline-none"})]})}function e_(e){let{captureId:t,captures:r,tuning:l,baseEmissivity:i,onTuningChange:s,scope:o,scopeIds:d}
1=e,[c,u]=(0,n.useState)(!1),[p,m]=(0,n.useState)(null);if(!t)return(0,a.jsx)("div",{className:"p-2 text-xs text-[var(--graphite-muted)]",children:"Open an image to tune it."});function h(e){s({...l,...e})}let x="image"===o.kind?"This image":"selected"===o.kind?"Selected (".concat(o.count,")"):"All (".concat(o.count,")");async function g(){if(!d.length)return;u(!0);let e=new Map;for(let a of d){var t;let n=r.find(e=>e.id===a),l=null==n||null==(t=n.metadata)?void 0:t.tuning;e.set(a,null!=l?l:{emissivity:.95,reflected_c:20})}let a=await eN(d,l);u(!1),m({message:"Applied tuning to ".concat(a.ok," image").concat(1===a.ok?"":"s").concat(a.failed?" (".concat(a.failed," failed)"):""),previous:e,ids:d})}return(0,a.jsxs)("div",{className:"flex flex-col gap-4 p-1",children:[(0,a.jsx)(eC,{label:"Emissivity",hint:"How much of the surface's own heat (vs reflected heat) the camera is reading",value:l.emissivity,min:.05,max:1,step:.01,onChange:e=>h({emissivity:e})}),(0,a.jsxs)("select",{onChange:e=>{let t=Number(e.target.value);Number.isFinite(t)&&h({emissivity:t})},value:"",title:"Set emissivity from a known material",className:"rounded-md border border-[var(--mobile-app-card-border)] bg-transparent px-1.5 py-1 text-[11px] text-[var(--graphite-text-header)]",children:[(0,a.jsx)("option",{value:"",children:"Set from materialâ¦"}),ew.a.map(e=>(0,a.jsxs)("option",{value:e.emissivity,children:[e.material," (",e.emissivity,")"]},e.material))]}),(0,a.jsx)(eC,{label:"Reflected temperature (\xb0C)",hint:"The apparent temperature of what's reflecting off the surface â usually ambient air",value:l.reflected_c,min:-20,max:60,step:.5,onChange:e=>h({reflected_c:e})}),(0,a.jsxs)("div",{className:"grid grid-cols-3 gap-3 text-[11px]",children:[(0,a.jsx)(eS,{label:"Distance (m)",hint:"Camera-to-target distance",value:l.distance_m,onChange:e=>h({distance_m:e})}),(0,a.jsx)(eS,{label:"Humidity (%)",hint:"Relative humidity at capture",value:l.humidity_pct,onChange:e=>h({humidity_pct:e})}),(0,a.jsx)(eS,{label:"Atmosphere (\xb0C)",hint:"Air temperature between camera and target",value:l.atmospheric_c,onChange:e=>h({atmospheric_c:e})}),(0,a.jsx)(eS,{label:"Ext. optics (\xb0C)",hint:"Temperature of any external lens or window",value:l.ext_optics_temp_c,onChange:e=>h({ext_optics_temp_c:e})}),(0,a.jsx)(eS,{label:"Optics transmission",hint:"How much infrared the external optics pass (0â1)",value:l.ext_optics_trans,onChange:e=>h({ext_optics_trans:e})}),(0,a.jsx)(eS,{label:"Reference (\xb0C)",hint:"Known reference temperature in the scene",value:l.reference_temp_c,onChange:e=>h({reference_temp_c:e})})]}),(0,a.jsx)("button",{type:"button",onClick:function(){s({emissivity:i,reflected_c:20})},className:"self-start text-[11px] text-[var(--graphite-muted)] underline hover:text-[var(--graphite-text-header)]",children:"Reset to camera values"}),(0,a.jsx)("button",{type:"button",disabled:c||!d.length,onClick:()=>void g(),title:"Apply this tuning to ".concat(x.toLowerCase()),className:"rounded-md border border-[var(--mobile-app-card-border)] px-2 py-1.5 text-xs font-semibold text-[var(--graphite-text-header)] hover:border-[var(--graphite-primary)] disabled:cursor-not-allowed disabled:opacity-40",children:c?"Applyingâ¦":"Apply to ".concat(x)}),p?(0,a.jsx)(ek,{message:p.message,onKeep:()=>m(null),onUndo:()=>{for(let e of p.ids){let t=p.previous.get(e);t&&eN([e],t)}m(null)}}):null]})}let eI=[{id:"off",label:"Off"},{id:"above",label:"Above limit"},{id:"below",label:"Below limit"},{id:"interval",label:"Interval (band)"},{id:"dewpoint",label:"Dew point risk"},{id:"insulation",label:"Insulation deficiency"}],eE="border-b border-[var(--mobile-app-card-border)] bg-transparent py-0.5 text-[var(--graphite-text-header)] focus:border-[var(--graphite-primary)] focus:outline-none";function eM(e){var t,r,n,l,i,s,o,d,c,u,p,m,h,x,g,f,v,b,y,j,w,N,k,C,S,_;let{alarm:I,onAlarmChange:E,tuning:M,unit:T,gridMin:R,gridMax:A}=e;return(0,a.jsxs)("div",{className:"flex flex-col gap-3",children:[(0,a.jsxs)("label",{className:"flex flex-col gap-1 text-[11px] text-[var(--graphite-muted)]",children:["Alarm mode â highlight one condition, dim the rest",(0,a.jsx)("select",{value:I.mode,onCh
1ange:e=>E({mode:e.target.value}),className:"rounded-md border border-[var(--mobile-app-card-border)] bg-transparent px-1.5 py-1 text-[11px] text-[var(--graphite-text-header)]",children:eI.map(e=>(0,a.jsx)("option",{value:e.id,children:e.label},e.id))})]}),"above"===I.mode?(0,a.jsxs)("label",{className:"flex flex-col gap-1 text-[11px] text-[var(--graphite-muted)]",children:["Limit (",(0,z.IC)(null!=(t=I.lo)?t:0,T,!1),") â highlight everything hotter",(0,a.jsx)("input",{type:"number",value:null!=(r=I.lo)?r:0,onChange:e=>E({...I,lo:Number(e.target.value)}),className:eE})]}):null,"below"===I.mode?(0,a.jsxs)("label",{className:"flex flex-col gap-1 text-[11px] text-[var(--graphite-muted)]",children:["Limit (",(0,z.IC)(null!=(n=I.hi)?n:0,T,!1),") â highlight everything colder",(0,a.jsx)("input",{type:"number",value:null!=(l=I.hi)?l:0,onChange:e=>E({...I,hi:Number(e.target.value)}),className:eE})]}):null,"interval"===I.mode?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"grid grid-cols-2 gap-3 text-[11px]",children:[(0,a.jsxs)("label",{className:"flex flex-col gap-1 text-[var(--graphite-muted)]",children:["Band low (",(0,z.IC)(null!=(i=I.lo)?i:R,T,!1),")",(0,a.jsx)("input",{type:"number",value:null!=(s=I.lo)?s:R,onChange:e=>E({...I,lo:Number(e.target.value)}),className:eE})]}),(0,a.jsxs)("label",{className:"flex flex-col gap-1 text-[var(--graphite-muted)]",children:["Band high (",(0,z.IC)(null!=(o=I.hi)?o:A,T,!1),")",(0,a.jsx)("input",{type:"number",value:null!=(d=I.hi)?d:A,onChange:e=>E({...I,hi:Number(e.target.value)}),className:eE})]})]}),(0,a.jsxs)("label",{className:"flex flex-col gap-1 text-[11px] text-[var(--graphite-muted)]",title:"Drag to scan this band across the full range â watch which pixels light up",children:["Sweep",(0,a.jsx)("input",{type:"range",min:R,max:A,step:(A-R)/200||.1,value:((null!=(c=I.lo)?c:R)+(null!=(u=I.hi)?u:A))/2,onChange:e=>{var t,r;let a=Number(e.target.value),n=(null!=(t=I.hi)?t:A)-(null!=(r=I.lo)?r:R)||(A-R)*.05;E({...I,lo:a-n/2,hi:a+n/2})},className:"w-full accent-[var(--graphite-primary)]"})]})]}):null,"dewpoint"===I.mode?(0,a.jsxs)("div",{className:"flex flex-col gap-2 text-[11px] text-[var(--graphite-muted)]",children:[(0,a.jsxs)("label",{className:"flex flex-col gap-1",children:["Air temp (",(0,z.IC)(null!=(m=null!=(p=I.indoor_c)?p:M.atmospheric_c)?m:20,T,!1),")",(0,a.jsx)("input",{type:"number",value:null!=(x=null!=(h=I.indoor_c)?h:M.atmospheric_c)?x:20,onChange:e=>E({...I,indoor_c:Number(e.target.value)}),className:eE})]}),(0,a.jsxs)("label",{className:"flex flex-col gap-1",children:["Margin above dew point (",(0,z.IC)(null!=(g=I.margin)?g:2,T,!1),")",(0,a.jsx)("input",{type:"number",value:null!=(f=I.margin)?f:2,onChange:e=>E({...I,margin:Number(e.target.value)}),className:eE})]}),(0,a.jsxs)("div",{children:["RH ",Math.round(null!=(v=M.humidity_pct)?v:50),"% (Tuning) â dew point"," ",(0,z.IC)(q(null!=(y=null!=(b=I.indoor_c)?b:M.atmospheric_c)?y:20,null!=(j=M.humidity_pct)?j:50),T)]})]}):null,"insulation"===I.mode?(0,a.jsxs)("div",{className:"grid grid-cols-2 gap-3 text-[11px] text-[var(--graphite-muted)]",children:[(0,a.jsxs)("label",{className:"flex flex-col gap-1",children:["Indoor (",(0,z.IC)(null!=(w=I.indoor_c)?w:20,T,!1),")",(0,a.jsx)("input",{type:"number",value:null!=(N=I.indoor_c)?N:20,onChange:e=>E({...I,indoor_c:Number(e.target.value)}),className:eE})]}),(0,a.jsxs)("label",{className:"flex flex-col gap-1",children:["Outdoor (",(0,z.IC)(null!=(k=I.outdoor_c)?k:0,T,!1),")",(0,a.jsx)("input",{type:"number",value:null!=(C=I.outdoor_c)?C:0,onChange:e=>E({...I,outdoor_c:Number(e.target.value)}),className:eE})]}),(0,a.jsxs)("div",{className:"col-span-2 flex flex-col gap-1",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between",children:[(0,a.jsx)("label",{className:"text-[var(--graphite-muted)]",title:"Thermographic-index-style threshold: 100% = as warm as indoor air, 0% = as cold as outdoor air",children:"Threshold factor"}),(0,a.jsx)("input",{type:"number",min:0,max:100,value:Math.round((null!=(S=I.factor)?S:.7)*100),onChange:e=>E({...I,factor:Number(e.target.value)/100}),className:"w-16 border-b border-[var(--mobile-app-card-border)] bg-transparent py-0.5 text-right text-[var(--graphite-text-header)] focus:border-[var(--graphite-primary)] focus:outline-none"})]}
1),(0,a.jsx)("input",{type:"range",min:0,max:1,step:.05,value:null!=(_=I.factor)?_:.7,onChange:e=>E({...I,factor:Number(e.target.value)}),className:"w-full accent-[var(--graphite-primary)]"})]})]}):null]})}let eT=[{label:"Off â no coloring",bands:null},{label:"Neutral defaults",bands:{advisory:1,warning:3,critical:6}},{label:"NETA-style ÎT",bands:{advisory:1,warning:4,critical:8}},{label:"RESNET-style envelope",bands:{advisory:.5,warning:2,critical:4}}];function eR(e){let{bands:t,onBandsChange:r,unit:n}=e,l=function(e){var t;let r=eT.find(t=>null===t.bands&&null===e||null!==t.bands&&null!==e&&t.bands.advisory===e.advisory&&t.bands.warning===e.warning&&t.bands.critical===e.critical);return null!=(t=null==r?void 0:r.label)?t:"Custom"}(t);return(0,a.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,a.jsxs)("label",{className:"flex flex-col gap-1 text-[11px] text-[var(--graphite-muted)]",children:["Severity bands â colors Measurements' Î vs reference",(0,a.jsxs)("select",{value:l,onChange:e=>{let t=eT.find(t=>t.label===e.target.value);t&&r(t.bands)},className:"rounded-md border border-[var(--mobile-app-card-border)] bg-transparent px-1.5 py-1 text-[11px] text-[var(--graphite-text-header)]",children:["Custom"===l?(0,a.jsx)("option",{value:"Custom",children:"Custom"}):null,eT.map(e=>(0,a.jsx)("option",{value:e.label,children:e.label},e.label))]})]}),t?(0,a.jsx)("div",{className:"grid grid-cols-3 gap-2 text-[11px] text-[var(--graphite-muted)]",children:["advisory","warning","critical"].map(e=>(0,a.jsxs)("label",{className:"flex flex-col gap-1",children:[e[0].toUpperCase()+e.slice(1)," (",(0,z.OJ)(t[e],n),")",(0,a.jsx)("input",{type:"number",min:0,step:.5,value:t[e],onChange:a=>r({...t,[e]:Number(a.target.value)}),className:"border-b border-[var(--mobile-app-card-border)] bg-transparent py-0.5 text-[var(--graphite-text-header)] focus:border-[var(--graphite-primary)] focus:outline-none"})]},e))}):null]})}function eA(e){let{localContrast:t,onLocalContrastChange:r,hasA:n,hasB:l,flickerShowing:i,autoFlicker:s,onAutoFlickerChange:o,onSnapshotA:d,onSnapshotB:c,onToggleView:u,onClearFlicker:p}=e,m=n&&l;return(0,a.jsxs)("div",{className:"flex flex-col gap-3 border-t border-[var(--mobile-app-card-border)] pt-3",children:[(0,a.jsxs)("label",{className:"flex items-center gap-2 text-[11px] text-[var(--graphite-text-header)]",children:[(0,a.jsx)("input",{type:"checkbox",checked:t,onChange:e=>r(e.target.checked)}),"Local contrast (display only)"]}),(0,a.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,a.jsx)("span",{className:"text-[11px] text-[var(--graphite-muted)]",children:"Snapshot A/B â compare two looks"}),(0,a.jsxs)("div",{className:"flex items-center gap-2 text-[11px]",children:[(0,a.jsx)("button",{type:"button",onClick:d,title:"Store the current palette + span as snapshot A",className:"rounded-md border border-[var(--mobile-app-card-border)] px-2 py-1 font-medium text-[var(--graphite-text-header)] hover:border-[var(--graphite-primary)]",children:n?"â A":"Store A"}),(0,a.jsx)("button",{type:"button",onClick:c,title:"Store the current palette + span as snapshot B",className:"rounded-md border border-[var(--mobile-app-card-border)] px-2 py-1 font-medium text-[var(--graphite-text-header)] hover:border-[var(--graphite-primary)]",children:l?"â B":"Store B"}),m?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("button",{type:"button",onClick:u,title:"Swap between A and B ( \\\\ )",className:"rounded-md border border-[var(--graphite-primary)] px-2 py-1 font-semibold text-[var(--graphite-text-header)]",children:["Showing ",i]}),(0,a.jsx)("button",{type:"button",onClick:p,"aria-label":"Clear both snapshots",title:"Clear both snapshots",className:"text-[var(--graphite-muted)] hover:text-red-400",children:"â"})]}):null]}),m?(0,a.jsxs)("label",{className:"flex items-center gap-2 text-[11px] text-[var(--graphite-text-header)]",children:[(0,a.jsx)("input",{type:"checkbox",checked:s,onChange:e=>o(e.target.checked)}),"Auto-flicker (2Hz â off if you prefer reduced motion)"]}):null]})]})}function eD(e){let{blend:t,onBlendChange:r,align:n,onNudge:l,onScaleChange:i,onResetAlign:s}=e,o="rounded-md border border-[var(--mobile-app-card-border)] px-2 py-1 text-[var(--graphite-text-header)] hover:border-[var(--graphite-primary)]";return(0,a.jsxs)("div",{className:"flex flex-col gap-3 border-t border-[var(--mobile-app-card-border)] pt-3",children:[(0,a.jsx)("span",{className:"text-[11px] text-[var(--graphite-muted)]",children:"Fusion â thermal over paired visual photo"}),(0,a.jsxs)("div",{className:"flex flex-col gap-1 text-[11px] text-[var(--graphite-text-header)]",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,a.jsxs)("label",{htmlFor:"fusion-blend-range",className:"min-w-0 truncate",children:["Blend (",t,"% thermal)"]}),(0,a.jsx)("input",{type:"number","aria-label":"Thermal blend, percent",min:0,max:100,value:t,onChange:e=>r(Math.min(100,Math.max(0,Number(e.target.value)||0))),className:"w-14 shrink-0 border-b border-[var(--mobile-app-card-border)] bg-transparent py-0.5 text-right text-[var(--graphite-text-header)] focus:border-[var(--graphite-primary)] focus:outline-none"})]}),(0,a.jsx)("input",{id:"fusion-blend-range",type:"range",min:0,max:100,value:t,onChange:e=>r(Number(e.target.value))})]}),(0,a.jsxs)("div",{className:"flex items-center gap-2 text-[11px] text-[var(--graphite-text-header)]",children:[(0,a.jsx)("span",{className:"text-[var(--graphite-muted)]",children:"Align photo"}),(0,a.jsx)("button",{type:"button","aria-label":"Nudge left",title:"Nudge left",className:o,onClick:()=>l(-2,0),children:"â"}),(0,a.jsx)("button",{type:"button","aria-label":"Nudge up",title:"Nudge up",className:o,onClick:()=>l(0,-2),children:"â"}),(0,a.jsx)("button",{type:"button","aria-label":"Nudge down",title:"Nudge down",className:o,onClick:()=>l(0,2),children:"â"}),(0,a.jsx)("button",{type:"button","aria-label":"Nudge right",title:"Nudge right",className:o,onClick:()=>l(2,0),children:"â"})]}),(0,a.jsxs)("div",{className:"flex flex-col gap-1 text-[11px] text-[var(--graphite-text-header)]",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,a.jsxs)("label",{htmlFor:"fusion-scale-range",className:"min-w-0 truncate",children:["Scale (",Math.round(100*n.scale),"%)"]}),(0,a.jsx)("input",{type:"number","aria-label":"Photo scale, percent",min:50,max:200,value:Math.round(100*n.scale),onChange:e=>i(Math.min(200,Math.max(50,Number(e.target.value)||100))/100),className:"w-14 shrink-0 border-b border-[var(--mobile-app-card-border)] bg-transparent py-0.5 text-right text-[var(--graphite-text-header)] focus:border-[var(--graphite-primary)] focus:outline-none"})]}),(0,a.jsx)("input",{id:"fusion-scale-range",type:"range",min:50,max:200,value:Math.round(100*n.scale),onChange:e=>i(Number(e.target.value)/100)})]}),(0,a.jsx)("button",{type:"button",onClick:s,className:"self-start text-[11px] text-[var(--graphite-muted)] underline hover:text-[var(--graphite-text-header)]",children:"Reset alignment"})]})}function eF(e){let{temps:t,span:r,gridMin:n,gridMax:l,unit:i,onSpanChange:s,alarm:o,onAlarmChange:d,tuning:c,severityBands:u,onSeverityBandsChange:p,localContrast:m,onLocalContrastChange:h,hasFlickerA:x,hasFlickerB:g,flickerShowing:f,autoFlicker:v,onAutoFlickerChange:b,onSnapshotFlickerA:y,onSnapshotFlickerB:j,onToggleFlickerView:w,onClearFlicker:N,hasPairedVisual:k,blend:C,onBlendChange:S,align:_,onNudge:I,onScaleChange:E,onResetAlign:M}=e;if(!t||!r)return(0,a.jsx)("div",{className:"p-2 text-xs text-[var(--graphite-muted)]",children:"Open an image to adjust its display."});let T=(0,z.Cg)(t,r.lo,r.hi,32),R=Math.max(1,...T);return(0,a.jsxs)("div",{className:"flex flex-col gap-4 p-1",children:[(0,a.jsxs)("div",{className:"grid grid-cols-2 gap-3 text-[11px]",children:[(0,a.jsxs)("label",{className:"flex flex-col gap-1 text-[var(--graphite-muted)]",children:["Low (",(0,z.IC)(r.lo,i,!1),")",(0,a.jsx)("input",{type:"number",value:Math.round(10*r.lo)/10,onChange:e=>s({lo:Number(e.target.value),hi:r.hi}),className:"border-b border-[var(--mobile-app-card-border)] bg-transparent py-0.5 text-[var(--graphite-text-header)] focus:border-[var(--graphite-primary)] focus:outline-none"})]}),(0,a.jsxs)("label",{className:"flex flex-col gap-1 text-[var(--graphite-muted)]",children:["High (",(0,z.IC)(r.hi,i,!1),")",(0,a.jsx)("input",{type:"number",value:Math.round(10*r.hi)/10,onChange:e=>s({lo:r.lo,hi:Number(e.target.value)}),className:"border-b border-[var(--mobile-app-card-border)] bg-transparent py-0.5 text-[var(--graphite-text-header)] focus:border-[var(--graphite-primary)] focus:outline-none"})]})]}),(0,a.jsx)("button",{type:"button",onClick:()=>s({lo:n,hi:l}),className:"self-start text-[11px] text-[var(--graphite-muted)] underline hover:text-[var(--graphite-text-header)]",children:"Reset to full range"}),(0,a.jsx)("div",{className:"flex h-16 items-end gap-px",title:"How many pixels fall at each temperature within the current display range",children:T.map((e,t)=>(0,a.jsx)("span",{style:{height:"".concat(e/R*100,"%")},className:"min-h-px flex-1 rounded-sm bg-[color-mix(in_srgb,var(--graphite-primary)_55%,transparent)]"},t))}),(0,a.jsx)(eM,{alarm:o,onAlarmChange:d,tuning:c,unit:i,gridMin:n,gridMax:l}),(0,a.jsx)(eR,{bands:u,onBandsChange:p,unit:i}),(0,a.jsx)(eA,{localContrast:m,onLocalContrastChange:h,hasA:x,hasB:g,flickerShowing:f,autoFlicker:v,onAutoFlickerChange:b,onSnapshotA:y,onSnapshotB:j,onToggleView:w,onClearFlicker:N}),k?(0,a.jsx)(eD,{blend:C,onBlendChange:S,align:_,onNudge:I,onScaleChange:E,onResetAlign:M}):null]})}let eP=(0,f.default)(()=>Promise.all([r.e(44804),r.e(21761),r.e(50434)]).then(r.bind(r,50434)).then(e=>e.AnalyzeGpsMiniMap),{loadableGenerated:{webpack:()=>[50434]},ssr:!1});function eO(e,t){return t?[e,t]:null}function eL(e){return"string"==typeof e&&e.length?e:"number"==typeof e&&Number.isFinite(e)?String(e):null}function ez(e){var t,r,l,i,s,o,d,c;let{capture:u}=e,p=null!=(t=null==u?void 0:u.id)?t:null,h=null!=(r=null==u?void 0:u.metadata)?r:{},x=null!=(l=null==u?void 0:u.qualityMetrics)?l:{}
1,[g,f]=(0,n.useState)(""),[b,y]=(0,n.useState)(!0),j=(0,n.useRef)(null);if((0,n.useEffect)(()=>{f("string"==typeof h.findings?h.findings:""),y(!0)},[p]),!u)return(0,a.jsx)("div",{className:"p-2 text-xs text-[var(--graphite-muted)]",children:"Open an image to see its details."});let w=null!=(i=h.gps)?i:null,N=w&&Number.isFinite(w.lat)&&Number.isFinite(w.lon),k=[eO("Camera","Unknown camera"===(0,v.nG)(u)?null:(0,v.nG)(u)),eO("Serial",eL(null!=(s=x.sensor_serial)?s:h.camera_serial)),eO("Lens",eL(null!=(o=x.lens)?o:h.lens)),eO("Resolution",null!=(d=eL(x.resolution))?d:Number.isFinite(Number(x.width))&&Number.isFinite(Number(x.height))?"".concat(x.width," \xd7 ").concat(x.height):null),eO("Captured",eL(null!=(c=h.captured_at)?c:h.created_at)),eO("Ambient",Number.isFinite(Number(h.ambient_temp_c))?"".concat(Number(h.ambient_temp_c).toFixed(1)," \xb0C"):null),eO("Humidity",Number.isFinite(Number(h.humidity_pct))?"".concat(Number(h.humidity_pct).toFixed(0)," %"):null),eO("Compass",eL(h.compass))].filter(e=>null!==e);return(0,a.jsxs)("div",{className:"flex flex-col gap-3 p-1",children:[(0,a.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between",children:[(0,a.jsx)("label",{htmlFor:"thermal-v2-findings",className:"text-[11px] text-[var(--graphite-muted)]",children:"Findings note"}),(0,a.jsx)("span",{className:"text-[10px] text-[var(--graphite-muted)]",children:b?"Saved â":"Savingâ¦"})]}),(0,a.jsx)("textarea",{id:"thermal-v2-findings",value:g,onChange:e=>{var t;f(t=e.target.value),y(!1),j.current&&clearTimeout(j.current),j.current=setTimeout(()=>{p&&m(p,{findings:t}),y(!0)},800)},rows:4,maxLength:5e3,placeholder:"What you observed on this image â goes into the report.",className:"resize-y rounded-md border border-[var(--mobile-app-card-border)] bg-transparent px-2 py-1.5 text-xs text-[var(--graphite-text-header)] placeholder:text-[var(--graphite-muted)] focus:border-[var(--graphite-primary)] focus:outline-none"})]}),k.length?(0,a.jsx)("dl",{className:"flex flex-col gap-1 text-[11px]",children:k.map(e=>{let[t,r]=e;return(0,a.jsxs)("div",{className:"flex items-baseline justify-between gap-3",children:[(0,a.jsx)("dt",{className:"shrink-0 text-[var(--graphite-muted)]",children:t}),(0,a.jsx)("dd",{className:"m-0 min-w-0 truncate text-right text-[var(--graphite-text-header)]",children:r})]},t)})}):null,N?(0,a.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,a.jsx)(eP,{lat:Number(w.lat),lon:Number(w.lon)}),(0,a.jsxs)("a",{href:"https://www.openstreetmap.org/?mlat=".concat(w.lat,"&mlon=").concat(w.lon,"#map=17/").concat(w.lat,"/").concat(w.lon),target:"_blank",rel:"noreferrer",className:"text-[11px] text-[var(--graphite-primary)] underline",title:"Open the capture location in OpenStreetMap",children:[Number(w.lat).toFixed(5),", ",Number(w.lon).toFixed(5)," â open full map"]})]}):null]})}function eB(e){var t,r,n,l,i,s,o,d,c;let{img:u,unit:p,activeId:m,activeCapture:h,captures:x,scope:g,scopeIds:f,openSection:v,onOpenSectionChange:b}=e;function y(e){b(v===e?"":e)}let j=!!(null==h||null==(t=h.metadata)?void 0:t.visual_pair_id);return(0,a.jsxs)("div",{className:"flex h-full flex-col overflow-hidden",children:[(0,a.jsx)(ep,{temps:null!=(s=null==(r=u.grid)?void 0:r.temps)?s:null,unit:p}),(0,a.jsxs)("div",{className:"min-h-0 flex-1 overflow-y-auto",children:[(0,a.jsx)(em,{title:"Measurements",open:"Measurements"===v,onToggle:()=>y("Measurements"),children:(0,a.jsx)(ej,{spots:u.spots,grid:u.grid,unit:p,referenceId:u.referenceId,selectedId:u.selectedId,onSelect:u.setSelectedId,onSetReference:u.setReferenceId,onRename:u.renameSpot,onDelete:u.deleteSpot,onMarkExtreme:u.markExtreme,comparePair:u.comparePair,pendingCompareId:u.pendingCompareId,onToggleCompare:u.toggleCompare,onClearCompare:u.clearCompare,severityBands:u.severityBands})}),(0,a.jsx)(em,{title:"Tuning",open:"Tuning"===v,onToggle:()=>y("Tuning"),children:(0,a.jsx)(e_,{captureId:m,captures:x,tuning:u.tuning,baseEmissivity:u.baseEmissivity,onTuningChange:u.setTuning,scope:g,scopeIds:f})}),(0,a.jsx)(em,{title:"Display",open:"Display"===v,onToggle:()=>y("Display"),children:(0,a.jsx)(eF,{temps:null!=(o=null==(n=u.grid)?void 0:n.temps)?o:null,span:u.span,gridMin:null!=(d=null==(l=u.grid)?void 0:l.minC)?d:0,gridMax:null!=(c=null==(i=u.grid)?void 0:i.maxC)?c:1,unit:p,onSpanChange:u.setSpan,alarm:u.alarm,onAlarmChange:u.setAlarm,tuning:u.tuning,severityBands:u.severityBands,onSeverityBandsChange:u.setSeverityBands,localContrast:u.localContrast,onLocalContrastChange:u.setLocalContrast,hasFlickerA:!!u.flickerA,hasFlickerB:!!u.flickerB,flickerShowing:u.flickerShowing,autoFlicker:u.autoFlicker,onAutoFlickerChange:u.setAutoFlicker,onSnapshotFlickerA:u.snapshotFlickerA,onSnapshotFlickerB:u.snapshotFlickerB,onToggleFlickerView:u.toggleFlickerView,onClearFlicker:u.clearFlicker,hasPairedVisual:j,blend:u.blend,onBlendChange:u.setBlend,align:u.align,onNudge:u.nudge,onScaleChange:u.setScale,onResetAlign:u.resetAlign})}),(0,a.jsx)(em,{title:"Notes & photo data",open:"Notes & photo data"===v,onToggle:()=>y("Notes & photo data"),children:(0,a.jsx)(ez,{capture:h})})]})]})}async function eU(e,t){try{let r=await fetch("/api/ops/thermal/sessions/".concat(e,"/chat?capture_id=").concat(encodeURIComponent(t)));if(!r.ok)return[];let a=await r.json();return Array.isArray(null==a?void 0:a.thread)?a.thread:[]}catch(e){return[]}}async function eH(e,t,r){try{var a,n;let l=await fetch("/api/ops/thermal/sessions/".concat(e,"/chat"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({capture_id:t,message:r})}),i=await l.json();if(!l.ok||(null==i?void 0:i.error))return{error:null!=(a=null==i?void 0:i.error)?a:"The analyst couldn't respond right now."};return{reply:i.reply,proposal:null!=(n=i.proposal)?n:null}}catch(e){return{error:"Network error â message not sent."}}}function eX(e){let{sessionId:t,captureId:r,onAcceptProposal:l}=e,{thread:i,loading:s,sending:o,error:d,send:c,dismissedProposals:u,dismissProposal:p}
1=function(e,t){let[r,a]=(0,n.useState)([]),[l,i]=(0,n.useState)(!1),[s,o]=(0,n.useState)(!1),[d,c]=(0,n.useState)(null),[u,p]=(0,n.useState)(new Set);async function m(r){if(!t||!r.trim()||s)return;o(!0),c(null);let n=new Date().toISOString();a(e=>[...e,{role:"user",content:r.trim(),capture_id:t,at:n}]);let l=await eH(e,t,r.trim());"error"in l?(c(l.error),a(e=>{let t=[...e],r=t.map(e=>e.role).lastIndexOf("user");return -1!==r&&(t[r]={...t[r],failed:!0}),t})):a(e=>[...e,{role:"assistant",content:l.reply,capture_id:t,at:new Date().toISOString(),proposal:l.proposal}]),o(!1)}return(0,n.useEffect)(()=>{if(a([]),c(null),p(new Set),!t)return;i(!0);let r=!1;return eU(e,t).then(e=>{r||(a(e),i(!1))}),()=>{r=!0}},[e,t]),{thread:r,loading:l,sending:s,error:d,send:m,dismissedProposals:u,dismissProposal:function(e){p(t=>new Set(t).add(e))}}}(t,r),[m,h]=(0,n.useState)("");function x(){m.trim()&&(c(m),h(""))}return r?(0,a.jsxs)("div",{className:"flex h-full flex-col gap-2",children:[(0,a.jsxs)("div",{className:"min-h-0 flex-1 space-y-2 overflow-y-auto pr-1",children:[s?(0,a.jsx)("p",{className:"text-xs text-[var(--graphite-muted)]",children:"Loading threadâ¦"}):null,s||0!==i.length?null:(0,a.jsx)("p",{className:"text-xs text-[var(--graphite-muted)]",children:'Ask a question about this image\'s findings, or correct one ("finding 2 is a sun-warmed junction box, not moisture").'}),i.map((e,t)=>(0,a.jsx)(eY,{message:e,dismissed:!!e.proposal&&u.has(e.proposal.anomaly_index),onAccept:l,onDismiss:p},t)),o?(0,a.jsx)("p",{className:"text-xs text-[var(--graphite-muted)]",children:"Analyst is thinkingâ¦"}):null,d?(0,a.jsx)("p",{className:"text-xs text-[#fca5a5]",children:d}):null]}),(0,a.jsxs)("div",{className:"flex shrink-0 gap-1.5 border-t border-[var(--mobile-app-card-border)] pt-2",children:[(0,a.jsx)("input",{type:"text",value:m,onChange:e=>h(e.target.value),onKeyDown:e=>{"Enter"!==e.key||e.shiftKey||(e.preventDefault(),x())},placeholder:"Ask the analystâ¦",className:"min-w-0 flex-1 rounded-md border border-[var(--mobile-app-card-border)] bg-transparent px-2 py-1.5 text-xs text-[var(--graphite-text-header)] focus:border-[var(--graphite-primary)] focus:outline-none"}),(0,a.jsx)("button",{type:"button",disabled:o||!m.trim(),onClick:x,className:"rounded-md border border-[var(--mobile-app-card-border)] px-2.5 py-1.5 text-xs font-semibold text-[var(--graphite-text-header)] hover:border-[var(--graphite-primary)] disabled:cursor-not-allowed disabled:opacity-40",children:"Send"})]})]}):(0,a.jsx)("div",{className:"p-2 text-xs text-[var(--graphite-muted)]",children:"Open an image to ask the analyst about its findings."})}function eY(e){let{message:t,dismissed:r,onAccept:n,onDismiss:l}=e,i="user"===t.role;return(0,a.jsxs)("div",{className:"flex flex-col ".concat(i?"items-end":"items-start"),children:[(0,a.jsx)("div",{className:"max-w-[90%] min-w-0 break-words rounded-md px-2.5 py-1.5 text-xs ".concat(t.failed?"border border-red-400/50 bg-red-400/10 text-[var(--graphite-text-header)]":i?"bg-[color-mix(in_srgb,var(--graphite-primary)_18%,transparent)] text-[var(--graphite-text-header)]":"border border-[var(--mobile-app-card-border)] text-[var(--graphite-text-header)]"),children:t.content}),t.failed?(0,a.jsx)("span",{className:"mt-0.5 text-[10px] text-red-400",children:"Not sent â try again"}):null,t.proposal&&!r?(0,a.jsxs)("div",{className:"mt-1 flex max-w-[90%] min-w-0 flex-col gap-1.5 rounded-md border border-[var(--graphite-primary)] p-2 text-xs",children:[(0,a.jsxs)("span",{className:"break-words font-semibold text-[var(--graphite-text-header)]",children:["Proposed revision â finding ",t.proposal.anomaly_index+1]}),(0,a.jsx)("span",{className:"break-words text-[var(--graphite-muted)]",children:t.proposal.note}),(0,a.jsxs)("div",{className:"flex gap-2",children:[(0,a.jsx)("button",{type:"button",onClick:()=>n(t.proposal.anomaly_index,t.proposal.note),className:"rounded-md border border-[var(--graphite-primary)] px-2 py-1 font-semibold text-[var(--graphite-text-header)]",children:"Accept"}),(0,a.jsx)("button",{type:"button",onClick:()=>l(t.proposal.anomaly_index),className:"text-[var(--graphite-muted)] hover:text-red-400",children:"Dismiss"})]})]}):null]})}function eV(e){let{sessionId:t,captureId:r,onAcceptProposal:l,children:i}
1=e,[s,o]=(0,n.useState)(!1);return(0,n.useEffect)(()=>{if(s)return window.addEventListener("keydown",e,!0),()=>window.removeEventListener("keydown",e,!0);function e(e){"Escape"===e.key&&(e.stopPropagation(),o(!1))}},[s]),(0,a.jsxs)("div",{className:"flex h-full flex-col gap-2",children:[(0,a.jsx)("button",{type:"button",onClick:()=>o(e=>!e),className:"self-start rounded-md border border-[var(--mobile-app-card-border)] px-2 py-1 text-[11px] font-semibold text-[var(--graphite-text-header)] hover:border-[var(--graphite-primary)]",children:s?"â Back":"\uD83D\uDCAC Ask the analyst"}),(0,a.jsx)("div",{className:"min-h-0 flex-1 overflow-hidden",children:s?(0,a.jsx)(eX,{sessionId:t,captureId:r,onAcceptProposal:l}):i})]})}let eG={rotation:0,flipH:!1,flipV:!1};function eJ(e,t){let r=0;for(let a=1;a<e.length;a++)("max"===t?e[a]>e[r]:e[a]<e[r])&&(r=a);return r}let eK={dx:0,dy:0,scale:1},eq={emissivity:.95,reflected_c:20};function eW(e){var t,r,a,n,l;let i=null!=(t=null==e?void 0:e.metadata)?t:null,s=null!=(r=null==i?void 0:i.findings_review)?r:null;return{accepted:new Set((null!=(a=null==s?void 0:s.accepted)?a:[]).map(Number).filter(Number.isFinite)),dismissed:new Set((null!=(n=null==s?void 0:s.dismissed)?n:[]).map(Number).filter(Number.isFinite)),edits:new Map(Object.entries(null!=(l=null==s?void 0:s.edits)?l:{}).map(e=>{let[t,r]=e;return[Number(t),r]}))}}function eZ(e){var t;
1let r=null!=(t=null==e?void 0:e.id)?t:null,[a,l]=(0,n.useState)(()=>eW(e)),i=(0,n.useRef)(null);function s(e){r&&(i.current&&clearTimeout(i.current),i.current=setTimeout(()=>{m(r,{findings_review:{accepted:[...e.accepted].map(String),dismissed:[...e.dismissed].map(String),edits:Object.fromEntries([...e.edits].map(e=>{let[t,r]=e;return[String(t),r]}))}})},400))}return(0,n.useEffect)(()=>{l(eW(e))},[r]),{...a,accept:function(e){l(t=>{let r=new Set(t.accepted).add(e),a=new Set(t.dismissed);a.delete(e);let n={...t,accepted:r,dismissed:a};return s(n),n})},dismiss:function(e){l(t=>{let r=new Set(t.dismissed).add(e),a=new Set(t.accepted);a.delete(e);let n={...t,accepted:a,dismissed:r};return s(n),n})},restore:function(e){l(t=>{let r=new Set(t.dismissed);r.delete(e);let a={...t,dismissed:r};return s(a),a})},setEdit:function(e,t){l(r=>{let a=new Map(r.edits).set(e,t),n={...r,edits:a};return s(n),n})},acceptAllSevere:function(e){l(t=>{let r=new Set(t.accepted),a=new Set(t.dismissed);for(let t of e)r.add(t),a.delete(t);let n={...t,accepted:r,dismissed:a};return s(n),n})}}}function eQ(){let[e,t]=(0,n.useState)("F");return(0,n.useEffect)(()=>{"C"===window.localStorage.getItem("thermal-v2-unit")&&t("C")},[]),{unit:e,setUnit:function(e){t(e);try{window.localStorage.setItem("thermal-v2-unit",e)}catch(e){}}}}let e$=null;async function e0(e,t){let r=await Promise.all(e.map(e=>m(e,t))),a=r.filter(Boolean).length;return{ok:a,failed:r.length-a}}function e1(e){var t,r,l,i,s,o,d,c,u;let{sessionId:p,captures:h,selection:x,scope:g,registerEscapeHandler:f}=e,[v,b]=(0,n.useState)("Measurements"),{unit:y,setUnit:j}=eQ(),[w,k]=(0,n.useState)(null),[C,S]=(0,n.useState)(null),[_,I]=(0,n.useState)(!1),[E,M]=(0,n.useState)(!1),[T,R]=(0,n.useState)(!1),A=Array.from(x.selectedIds),D=2===A.length,F=null!=(i=null!=(l=x.focusedId)?l:null==(t=h[0])?void 0:t.id)?i:null,P=null!=(s=h.find(e=>e.id===F))?s:null,B=h.findIndex(e=>e.id===F),U=function(e){var t,r;let a=null!=(t=null==e?void 0:e.id)?t:null,[l,i]=(0,n.useState)(null),[s,o]=(0,n.useState)(!1),[d,c]=(0,n.useState)(null),[u,p]=(0,n.useState)(null),[h,x]=(0,n.useState)(!1),[g,f]=(0,n.useState)({mode:"off"}),[v,b]=(0,n.useState)(null),[y,j]=(0,n.useState)(!1),[w,N]=(0,n.useState)(!1),[k,C]=(0,n.useState)(eq),[S,_]=(0,n.use
1State)("Iron"),I=function(e,t){let[r,a]=(0,n.useState)(null),[l,i]=(0,n.useState)(null),[s,o]=(0,n.useState)("A"),[d,c]=(0,n.useState)(!1);(0,n.useEffect)(()=>{var e,t;if(!d||!r||!l||(null==(e=(t=window).matchMedia)?void 0:e.call(t,"(prefers-reduced-motion: reduce)").matches))return;let a=setInterval(()=>o(e=>"A"===e?"B":"A"),500);return()=>clearInterval(a)},[d,r,l]);let u=!!(r&&l),p=u?"A"===s?r.palette:l.palette:e,m=u?"A"===s?r.span:l.span:t;return{flickerA:r,flickerB:l,flickerShowing:s,flickerActive:u,autoFlicker:d,setAutoFlicker:c,snapshotFlickerA:function(){t&&a({palette:e,span:t})},snapshotFlickerB:function(){t&&i({palette:e,span:t})},toggleFlickerView:function(){o(e=>"A"===e?"B":"A")},clearFlicker:function(){a(null),i(null),c(!1)},displayPalette:p,displaySpan:m}}(S,u),[E,M]=(0,n.useState)("move"),[T,R]=(0,n.useState)("box"),[A,D]=(0,n.useState)(null),[F,P]=(0,n.useState)(null),[B,U]=(0,n.useState)(null),[H,X]=(0,n.useState)(null),Y=function(e){var t;let r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},a=null!=(t=r.maxHistory)?t:100,[l,i]=(0,n.useState)([]),[s,o]=(0,n.useState)(e),[d,c]=(0,n.useState)([]),u=(0,n.useRef)(l),p=(0,n.useRef)(s),m=(0,n.useRef)(d);u.current=l,p.current=s,m.current=d;let h=(0,n.useCallback)(e=>{if(Object.is(e,p.current))return;let t=[...u.current,p.current];i(t.length>a?t.slice(t.length-a):t),o(e),c([])},[a]),x=(0,n.useCallback)(e=>{o(e)},[]),g=(0,n.useCallback)(()=>{let e=u.current;if(0===e.length)return;let t=e[e.length-1];i(e.slice(0,-1)),c([p.current,...m.current]),o(t)},[]),f=(0,n.useCallback)(()=>{let e=m.current;if(0===e.length)return;let t=e[0];c(e.slice(1)),i([...u.current,p.current]),o(t)},[]),v=(0,n.useCallback)(e=>{i([]),c([]),void 0!==e&&o(e)},[]);return(0,n.useMemo)(()=>({state:s,canUndo:l.length>0,canRedo:d.length>0,commitState:h,replaceState:x,undo:g,redo:f,reset:v}),[s,l.length,d.length,h,x,g,f,v])}([]),V=(0,n.useRef)(Y);V.current=Y;let G=null!=(r=null==l?void 0:l.emissivity)?r:.95;(0,n.useEffect)(()=>{var t;i(null),p(null),f({mode:"off"}),j(!1),N(!1),I.clearFlicker(),c(null),D(null),P(null);let r=null!=(t=null==e?void 0:e.metadata)?t:null,n=null==r?void 0:r.spots;Y.reset(Array.isArray(n)?n:[]);let l=null==r?void 0:r.tuning;C(null!=l?l:eq),_("string"==typeof(null==r?void 0:r.palette)?r.palette:"Iron");let s=null==r?void 0:r.display_span,d=!!s&&Number.isFinite(s.lo)&&Number.isFinite(s.hi);if(x(d),d&&p(s),!a)return;o(!0);let u=!1;return O(a).then(e=>{if(!u){if(o(!1),"error"in e)return void c(e.error);i(e.grid),d||p({lo:e.grid.minC,hi:e.grid.maxC})}}),()=>{u=!0}},[a]);let J=(0,n.useMemo)(()=>{if(!l)return null;let e=(0,L.y)(l.temps,l.minC,l.maxC,G,k.emissivity,k.reflected_c);return{...l,temps:Array.from(e.temps),minC:e.minC,maxC:e.maxC}},[l,G,k.emissivity,k.reflected_c]),K=function(e,t){var r;let a=null!=(r=null==e?void 0:e.id)?r:null,[l,i]=(0,n.useState)(eG);(0,n.useEffect)(()=>{var t;let r=null!=(t=null==e?void 0:e.metadata)?t:null,a=null==r?void 0:r.display_transform;i(null!=a?a:eG)},[a]);let s=(0,n.useRef)(null);(0,n.useEffect)(()=>{if(a&&t)return s.current&&clearTimeout(s.current),s.current=setTimeout(()=>{m(a,{display_transform:l})},600),()=>{s.current&&clearTimeout(s.current)}},[l,a,t]);let o=0===l.rotation&&!l.flipH&&!l.flipV;return{transform:l,rotate90:function(){i(e=>({...e,rotation:(e.rotation+90)%360}))},flipHorizontal:function(){i(e=>({...e,flipH:!e.flipH}))},flipVertical:function(){i(e=>({...e,flipV:!e.flipV}))},resetTransform:function(){i(eG)},isIdentity:o}}(e,!!J),q=function(e,t){var r;let a=null!=(r=null==e?void 0:e.id)?r:null,[l,i]=(0,n.useState)(100),[s,o]=(0,n.useState)(eK);(0,n.useEffect)(()=>{var t;i(100);let r=null!=(t=null==e?void 0:e.metadata)?t:null,a=null==r?void 0:r.pair_align;o(null!=a?a:eK)},[a]);let d=(0,n.useRef)(null);return(0,n.useEffect)(()=>{if(a&&t)return d.current&&clearTimeout(d.current),d.current=setTimeout(()=>{m(a,{pair_align:s})},600),()=>{d.current&&clearTimeout(d.current)}},[s,a,t]),{blend:l,setBlend:i,align:s,nudge:function(e,t){o(r=>({...r,dx:r.dx+e,dy:r.dy+t}))},setScale:function(e){o(t=>({...t,scale:Math.max(.1,e)}))},resetAlign:function(){o(eK)}}}(e,!!J),{markExtreme:W}=((0,n.useEffect)(()=>
1{if(!J)return;let e=V.current.state;if(!e.some(e=>e.auto))return;let t=!1,r=e.map(e=>{if(!e.auto)return e;let r=eJ(J.temps,e.auto),a=r%J.width,n=Math.floor(r/J.width);return .01>Math.abs(a-e.x)&&.01>Math.abs(n-e.y)?e:(t=!0,{...e,x:a,y:n})});t&&V.current.replaceState(r)},[J]),{markExtreme:function(e){if(!J)return;let t=eJ(J.temps,e),r=t%J.width,a=Math.floor(t/J.width),n="max"===e?"Hottest":"Coldest",l=V.current,i=l.state.find(t=>t.auto===e);if(i){l.commitState(l.state.map(t=>t.auto===e?{...t,x:r,y:a}:t)),D(i.id);return}let s={id:(0,z.sB)(),kind:"point",target:"crosshair",x:r,y:a,auto:e,label:n};l.commitState([...l.state,s]),D(s.id)}});function Z(e){x(!0),p(e)}(0,n.useEffect)(()=>{J&&!h&&p({lo:J.minC,hi:J.maxC})},[J,h]);let Q=(0,n.useRef)(null);(0,n.useEffect)(()=>{if(a&&J)return Q.current&&clearTimeout(Q.current),Q.current=setTimeout(()=>{m(a,{spots:Y.state})},600),()=>{Q.current&&clearTimeout(Q.current)}},[Y.state,a,J]);let $=(0,n.useRef)(null);(0,n.useEffect)(()=>{if(a&&J)return $.current&&clearTimeout($.current),$.current=setTimeout(()=>{m(a,{tuning:k})},600),()=>{$.current&&clearTimeout($.current)}},[k,a,J]);let ee=(0,n.useRef)(null);(0,n.useEffect)(()=>{if(a&&J)return ee.current&&clearTimeout(ee.current),ee.current=setTimeout(()=>{m(a,{palette:S})},600),()=>{ee.current&&clearTimeout(ee.current)}},[S,a,J]);let et=(0,n.useRef)(null);return(0,n.useEffect)(()=>{if(a&&J&&h&&u)return et.current&&clearTimeout(et.current),et.current=setTimeout(()=>{m(a,{display_span:u})},600),()=>{et.current&&clearTimeout(et.current)}},[u,h,a,J]),{grid:J,rawGrid:l,loading:s,error:d,span:u,setSpan:Z,spanCustomized:h,palette:S,setPalette:function(e){_(e)},alarm:g,setAlarm:f,severityBands:v,setSeverityBands:b,localContrast:y,setLocalContrast:j,viewOriginal:w,setViewOriginal:N,...I,...K,...q,enhanceHere:function(e){Z({lo:e-2,hi:e+2})},tuning:k,setTuning:C,baseEmissivity:G,tool:E,setTool:M,areaShape:T,setAreaShape:R,selectedId:A,setSelectedId:D,referenceId:F,setReferenceId:P,markExtreme:W,spots:Y.state,canUndo:Y.canUndo,canRedo:Y.canRedo,undo:Y.undo,redo:Y.redo,createSpot:function(e){Y.commitState([...Y.state,e])},commitSpots:function(e){Y.commitState(e)},deleteSpot:function(e){Y.commitState(Y.state.filter(t=>t.id!==e)),A===e&&D(null),F===e&&P(null),H===e&&X(null),B&&(B[0]===e||B[1]===e)&&U(null)},renameSpot:function(e,t){Y.commitState(Y.state.map(r=>r.id===e?{...r,label:t}:r))},comparePair:B,pendingCompareId:H,toggleCompare:function(e){if(B){U(null),X(e);return}return H?H===e?void X(null):void(U([H,e]),X(null)):void X(e)},clearCompare:function(){U(null),X(null)}}}(P),H=eZ(P),X=(0,n.useMemo)(()=>U.grid?function(e,t,r,a){var n,l,i,s,o,d,c,u,p,m,h,x,g;switch(e.mode){case"off":default:return null;case"above":return{lo:null!=(n=e.lo)?n:a,hi:1/0};case"below":return{lo:-1/0,hi:null!=(l=e.hi)?l:r};case"interval":return{lo:null!=(i=e.lo)?i:r,hi:null!=(s=e.hi)?s:a};case"dewpoint":return{lo:-1/0,hi:q(null!=(d=null!=(o=e.indoor_c)?o:t.atmospheric_c)?d:20,null!=(c=t.humidity_pct)?c:50)+(null!=(u=e.margin)?u:2)};case"insulation":return{lo:-1/0,hi:(x=null!=(p=e.indoor_c)?p:20,(g=null!=(m=e.outdoor_c)?m:0)+Math.max(0,Math.min(1,null!=(h=e.factor)?h:.7))*(x-g))}}}(U.alarm,U.tuning,U.grid.minC,U.grid.maxC):null,[U.alarm,U.tuning,U.grid]),Y=U.viewOriginal?"Iron":U.displayPalette,V=U.viewOriginal&&U.rawGrid?{lo:U.rawGrid.minC,hi:U.rawGrid.maxC}:U.displaySpan,G=U.viewOriginal?null:X,J=U.viewOriginal?[]:U.spots,K=null==P||null==(r=P.metadata)?void 0:r.visual_pair_id,Z="string"==typeof K&&null!=(o=h.find(e=>e.id===K))?o:null,Q=U.viewOriginal?100:U.blend;function $(e){let t=h[B+e];t&&x.click(t.id,B+e,{})}(0,n.useEffect)(()=>{E&&!D&&M(!1)},[E,D]),(0,n.useEffect)(()=>{S(null)},[F]);let ee="all"===g.kind?h.map(e=>e.id):"selected"===g.kind?h.filter(e=>x.selectedIds.has(e.id)).map(e=>e.id):F?[F]:[],er=function(e,t,r,a){let[l,i]=(0,n.useState)(()=>null!==e$),[s,o]=(0,n.useState)(null);return{hasClip:l,pasteToast:s,copySettings:function(){e$={palette:e.palette,span:e.span,tuning:e.tuning,alarm:e.alarm},i(!0)},pasteSettings:async function n(){let n=e$;if(!n)return;if("image"===t.kind){e.setPalette(n.palette),n.span&&e.setSpan(n.span),e.setTuning(n.tuning),e.setAlarm(n.alarm);return}if(!r.length)return;let l=new Map;for(let e of r){var i,s;let t=a.find(t=>
1t.id===e),r=null!=(i=null==t?void 0:t.metadata)?i:null;l.set(e,{palette:"string"==typeof(null==r?void 0:r.palette)?r.palette:"Iron",tuning:null!=(s=null==r?void 0:r.tuning)?s:{emissivity:.95,reflected_c:20}})}let d=await e0(r,{palette:n.palette,tuning:n.tuning});o({message:"Pasted settings to ".concat(d.ok," image").concat(1===d.ok?"":"s").concat(d.failed?" (".concat(d.failed," failed)"):""),previous:l,ids:r})},keepPasteToast:function(){o(null)},undoPasteToast:function(){if(s){for(let e of s.ids){let t=s.previous.get(e);t&&e0([e],t)}o(null)}}}}(U,g,ee,h);return!function(e){let{img:t,hover:r,clipboard:a,step:l,focusMode:i,onToggleFocusMode:s}=e;(0,n.useEffect)(()=>{function e(e){let r=e.target;(!r||"INPUT"!==r.tagName&&"TEXTAREA"!==r.tagName)&&("o"!==e.key.toLowerCase()||e.ctrlKey||e.metaKey||e.repeat||(e.preventDefault(),t.setViewOriginal(!0)))}function r(e){"o"===e.key.toLowerCase()&&t.setViewOriginal(!1)}return window.addEventListener("keydown",e),window.addEventListener("keyup",r),()=>{window.removeEventListener("keydown",e),window.removeEventListener("keyup",r)}},[t]),(0,n.useEffect)(()=>{function e(e){let n=e.target;if(n&&("INPUT"===n.tagName||"TEXTAREA"===n.tagName))return;let i=e.ctrlKey||e.metaKey;if(i&&e.shiftKey&&"c"===e.key.toLowerCase()){e.preventDefault(),a.copySettings();return}if(i&&e.shiftKey&&"v"===e.key.toLowerCase()){e.preventDefault(),a.pasteSettings();return}if(i&&"z"===e.key.toLowerCase()){e.preventDefault(),e.shiftKey?t.redo():t.undo();return}if(i&&"y"===e.key.toLowerCase()){e.preventDefault(),t.redo();return}if(("Delete"===e.key||"Backspace"===e.key)&&t.selectedId){e.preventDefault(),t.deleteSpot(t.selectedId);return}if("["===e.key){e.preventDefault(),l(-1);return}if("]"===e.key){e.preventDefault(),l(1);return}if("e"===e.key.toLowerCase()&&!i&&r){e.preventDefault(),t.enhanceHere(r.tempC);return}if("\\"===e.key&&t.flickerActive){e.preventDefault(),t.toggleFlickerView();return}"f"!==e.key.toLowerCase()||i||(e.preventDefault(),s())}return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[t,a,r,l,s])}({img:U,hover:w,clipboard:er,step:$,focusMode:_,onToggleFocusMode:()=>I(e=>!e)}),(0,n.useEffect)(()=>{if(f)return f(()=>U.selectedId?(U.setSelectedId(null),!0):U.spanCustomized&&U.grid?(U.setSpan({lo:U.grid.minC,hi:U.grid.maxC}),!0):!!_&&(I(!1),!0)),()=>f(null)},[f,U,_]),(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(N,{toolbar:(0,a.jsx)(eu,{palette:U.palette,onPaletteChange:U.setPalette,unit:y,onUnitChange:j,hoverTemp:C,tool:U.tool,onToolChange:U.setTool,areaShape:U.areaShape,onAreaShapeChange:U.setAreaShape,canUndo:U.canUndo,canRedo:U.canRedo,onUndo:U.undo,onRedo:U.redo,imageIndex:B,imageCount:h.length,onPrev:()=>$(-1),onNext:()=>$(1),onCopySettings:er.copySettings,onPasteSettings:er.pasteSettings,canPaste:er.hasClip,onEnhanceHere:null!=C?()=>U.enhanceHere(C):void 0,displayTransform:U.transform,onRotate90:U.rotate90,onFlipHorizontal:U.flipHorizontal,onFlipVertical:U.flipVertical,onResetTransform:U.resetTransform,viewOriginal:U.viewOriginal,onViewOriginalStart:()=>U.setViewOriginal(!0),onViewOriginalEnd:()=>U.setViewOriginal(!1),focusMode:_,onToggleFocusMode:()=>I(e=>!e),canCompare:D,compareMode:E,onToggleCompare:()=>M(e=>!e),spanLock:T,onSpanLockChange:R}),center:E?(0,a.jsx)(el,{captureA:null!=(d=h.find(e=>e.id===A[0]))?d:null,captureB:null!=(c=h.find(e=>e.id===A[1]))?c:null,palette:U.palette,unit:y,spanLock:T}):(0,a.jsx)(et,{grid:U.grid,loading:U.loading,error:U.error,palette:U.palette,unit:y,span:U.span,onSpanChange:U.setSpan,isotherm:G,localContrast:!U.viewOriginal&&U.localContrast,displayPalette:Y,displaySpan:V,displayTransform:U.transform,hover:w,onHoverChange:function(e){k(e),e&&S(e.tempC)},spots:J,tool:U.tool,areaShape:U.areaShape,selectedId:U.selectedId,referenceId:U.referenceId,onSelect:U.setSelectedId,onCreateSpot:U.viewOriginal?()=>{}:U.createSpot,onCommitSpots:U.viewOriginal?()=>{}:U.commitSpots,visualUrl:null!=(u=null==Z?void 0:Z.previewUrl)?u:null,blend:Q,align:U.align}),right:_?void 0:{title:"Details",content:(0,a.jsx)(eV,{sessionId:p,captureId:F,onAcceptProposal:(e,t)=>{H.setEdit(e,t),H.accept(e)},children:(0,a.jsx)(eB,{img:U,unit:y,activeId:F,activeCapture:P,captures:h,scope:g,scopeIds:ee,openSection:v,onOpenSectionChange:b})})},bottom:_?void 0:{title:"Filmstrip",compact:!0,defaultSize:20,content:(0,a.jsx)(W,{captures:h,activeId:F,selectedIds:x.selectedIds,onOpen:function(e){let t=h.findIndex(t=>t.id===e);
1x.click(e,t,{})},onToggleSelect:e=>x.click(e,h.findIndex(t=>t.id===e),{toggle:!0}),layout:"horizontal"})}}),er.pasteToast?(0,a.jsx)(ek,{message:er.pasteToast.message,onKeep:er.keepPasteToast,onUndo:er.undoPasteToast}):null]})}function e2(e){let{captures:t,activeId:r,onOpen:n,filter:l,onFilterChange:i}=e,s=t.filter(e=>{var t,r;return(null!=(r=null==(t=e.anomalies)?void 0:t.length)?r:0)>0}),o=[..."all"===l?s:s.filter(e=>{var t;return null==(t=e.anomalies)?void 0:t.some(e=>e.severity===l)})].sort((e,t)=>{var r,a;return Math.min(...(null!=(r=e.anomalies)?r:[]).map(e=>{var t;return ex(null!=(t=e.severity)?t:"info")}))-Math.min(...(null!=(a=t.anomalies)?a:[]).map(e=>{var t;return ex(null!=(t=e.severity)?t:"info")}))}),d=[{id:"all",label:"All (".concat(s.length,")")},{id:"action",label:eh("action")},{id:"watch",label:eh("watch")},{id:"info",label:eh("info")}];return(0,a.jsxs)("div",{className:"flex h-full flex-col gap-2 overflow-hidden",children:[(0,a.jsx)("div",{className:"flex shrink-0 flex-wrap gap-1",children:d.map(e=>(0,a.jsx)("button",{type:"button",onClick:()=>i(e.id),className:"rounded-md px-2 py-1 text-[11px] font-medium transition-colors ".concat(l===e.id?"bg-[color-mix(in_srgb,var(--graphite-primary)_18%,transparent)] text-[var(--graphite-text-header)]":"text-[var(--graphite-muted)] hover:text-[var(--graphite-text-header)]"),children:e.label},e.id))}),(0,a.jsx)("div",{"data-testid":"ai-review-detections-list",className:"min-h-0 flex-1 overflow-y-auto",children:0===o.length?(0,a.jsx)("div",{className:"p-2 text-xs text-[var(--graphite-muted)]",children:"No detections yet â run AI on some images first."}):o.map(e=>{var t,l,i;let s=null!=(l=null==(t=e.anomalies)?void 0:t.length)?l:0,o=Math.min(...(null!=(i=e.anomalies)?i:[]).map(e=>{var t;return ex(null!=(t=e.severity)?t:"info")}));return(0,a.jsxs)("button",{type:"button",onClick:()=>n(e.id),className:"flex w-full items-center justify-between gap-2 rounded-md px-2 py-1.5 text-left text-xs transition-colors ".concat(e.id===r?"bg-[color-mix(in_srgb,var(--graphite-primary)_14%,transparent)] text-[var(--graphite-text-header)]":"text-[var(--graphite-muted)] hover:text-[var(--graphite-text-header)]"),children:[(0,a.jsx)("span",{className:"truncate",children:e.filename}),(0,a.jsx)("span",{className:"shrink-0 rounded px-1 text-[9px] font-bold ".concat(0===o?"bg-red-500/20 text-red-400":1===o?"bg-sky-400/20 text-sky-300":"bg-black/40 text-[var(--graphite-muted)]"),children:s})]},e.id)})})]})}let e5={action:"border-red-500",watch:"border-sky-400",info:"border-[var(--graphite-muted)]"};function e3(e){let{captureId:t,anomalies:r,selectedIndex:l,onSelectIndex:i}=e,[s,o]=(0,n.useState)(null),[d,c]=(0,n.useState)(null),u=(0,n.useRef)(null),p=(0,n.useRef)(null),[m,h]=(0,n.useState)({left:0,top:0,width:0,height:0});return((0,n.useEffect)(()=>{if(o(null),c(null),!t)return;let e=!1;return O(t).then(t=>{if(!e){if("error"in t)return void c(t.error);o(t.grid)}}),()=>{e=!0}},[t]),(0,n.useEffect)(()=>{let e=u.current;if(!e||!s)return;e.width=s.width,e.height=s.height;let t=e.getContext("2d");t&&(0,z.vQ)(t,s.temps,s.width,s.height,"Iron",s.minC,s.maxC)},[s]),(0,n.useEffect)(()=>{let e=u.current,t=p.current;if(!e||!t||!s)return;function r(){let e=u.current,t=p.current;if(!e||!t||!s)return;let r=e.getBoundingClientRect(),a=t.getBoundingClientRect(),n=r.width>0?Math.min(r.width/s.width,r.height/s.height):0,l=s.width*n,i=s.height*n;h({left:r.left-a.left+(r.width-l)/2,top:r.top-a.top+(r.height-i)/2,width:l,height:i})}let a=new ResizeObserver(r);return a.observe(e),r(),()=>a.disconnect()},[s]),t)?d?(0,a.jsx)("div",{className:"flex h-full items-center justify-center text-xs text-[var(--graphite-muted)]",children:d}):(0,a.jsxs)("div",{ref:p,className:"relative flex h-full w-full items-center justify-center overflow-hidden bg-[var(--graphite-canvas-deep)]",children:[(0,a.jsx)("canvas",{ref:u,className:"max-h-full max-w-full object-contain"}),s?r.map((e,t)=>{var r,n;if(!e.bbox)return null;let o=m.left+e.bbox.x/s.width*m.width,d=m.top+e.bbox.y/s.height*m.height,c=e.bbox.w/s.width*m.width,u=e.bbox.h/s.height*m.height,p=l===t;return(0,a.jsx)("button",{type:"button",onClick:()=>i(t),"aria-label":"Finding #".concat(t+1),title:"Finding #".concat(t+1),"aria-pressed":p,style:{left:o,top:d,width:Math.max(c,12),height:Math.max(u,12)},className:"absolute rounded border-2 ".concat(null!=(r=e5[e.severity])?r:e5.info," ").concat(p?"ring-2 ring-[var(--graphite-primary)]":""),children:(0,a.jsx)("span",{className:"absolute -left-1 -top-2 flex h-4 w-4 items-center justify-center rounded-full bg-black/70 text-[9px] font-bold text-white",children:t+1})},null!=(n=e.id)?n:t)}):null]}):(0,a.jsx)("div",{className:"flex h-full items-center justify-center text-xs text-[var(--graphite-muted)]",children:"Select an image to review."})}function e4(e){var t;let{anomaly:r,index:l,unit:i,selected:s,accepted:o,editedText:d,onSelect:c,onAccept:u,onDismiss:p,onEdit:m}
1=e,[h,x]=(0,n.useState)(!1),g=null!=(t=null!=d?d:r.observation)?t:"";return(0,a.jsxs)("div",{onClick:c,className:"flex cursor-pointer flex-col gap-2 rounded-md border p-2 text-xs transition-colors ".concat(s?"border-[var(--graphite-primary)]":"border-[var(--mobile-app-card-border)]"),children:[(0,a.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,a.jsxs)("span",{className:"font-semibold text-[var(--graphite-text-header)]",children:["#",l+1," ",r.type.replace(/_/g," ")]}),(0,a.jsx)("span",{className:"rounded border px-1.5 py-0.5 text-[10px] font-bold ".concat(eg(r.severity)),children:eh(r.severity)})]}),(0,a.jsxs)("div",{className:"text-[11px] text-[var(--graphite-muted)]",children:["number"==typeof r.temp_c?"Peak ".concat((0,z.IC)(r.temp_c,i)):null,"number"==typeof r.delta_c?" \xb7 Î ".concat((0,z.IC)(r.delta_c,i,!1)):null]}),h?(0,a.jsx)("textarea",{value:g,onChange:e=>m(e.target.value),onClick:e=>e.stopPropagation(),rows:3,className:"rounded-md border border-[var(--mobile-app-card-border)] bg-transparent px-2 py-1 text-[11px] text-[var(--graphite-text-header)] focus:border-[var(--graphite-primary)] focus:outline-none"}):g?(0,a.jsx)("p",{className:"text-[11px] text-[var(--graphite-text-header)]",children:g}):(0,a.jsx)("p",{className:"text-[11px] italic text-[var(--graphite-muted)]",children:"No AI explanation yet â run AI review on this image."}),(0,a.jsxs)("div",{className:"flex items-center gap-1.5",onClick:e=>e.stopPropagation(),children:[(0,a.jsx)("button",{type:"button",onClick:u,className:"rounded-md border px-2 py-1 text-[11px] font-semibold ".concat(o?"border-[var(--graphite-primary)] text-[var(--graphite-text-header)]":"border-[var(--mobile-app-card-border)] text-[var(--graphite-muted)] hover:border-[var(--graphite-primary)]"),children:"Accept â"}),(0,a.jsx)("button",{type:"button",onClick:()=>x(e=>!e),className:"rounded-md border border-[var(--mobile-app-card-border)] px-2 py-1 text-[11px] font-semibold text-[var(--graphite-muted)] hover:border-[var(--graphite-primary)]",children:"Edit â"}),(0,a.jsx)("button",{type:"button",onClick:p,className:"rounded-md border border-[var(--mobile-app-card-border)] px-2 py-1 text-[11px] font-semibold text-[var(--graphite-muted)] hover:border-red-500/60 hover:text-red-400",children:"Dismiss â"})]})]})}function e8(e){let{anomalies:t,unit:r,selectedIndex:l,onSelectIndex:i,review:s}=e,[o,d]=(0,n.useState)(!1);if(!t.length)return(0,a.jsx)("div",{className:"p-2 text-xs text-[var(--graphite-muted)]",children:"No findings on this image yet."});let c=t.map((e,t)=>({a:e,i:t})).filter(e=>{let{i:t}=e;return!s.dismissed.has(t)}),u=t.map((e,t)=>({a:e,i:t})).filter(e=>{let{i:t}=e;return s.dismissed.has(t)}),p=t.map((e,t)=>({a:e,i:t})).filter(e=>{let{a:t}=e;return"action"===t.severity}).map(e=>{let{i:t}=e;return t});return(0,a.jsxs)("div",{className:"flex h-full flex-col gap-2 overflow-y-auto p-1",children:[p.length>1?(0,a.jsxs)("button",{type:"button",onClick:()=>s.acceptAllSevere(p),className:"self-start rounded-md border border-[var(--mobile-app-card-border)] px-2 py-1 text-[11px] font-semibold text-[var(--graphite-text-header)] hover:border-[var(--graphite-primary)]",children:["Accept all severe (",p.length,")"]}):null,c.map(e=>{var t,n;let{a:o,i:d}=e;return(0,a.jsx)(e4,{anomaly:o,index:d,unit:r,selected:l===d,accepted:s.accepted.has(d),editedText:null!=(t=s.edits.get(d))?t:null,onSelect:()=>i(d),onAccept:()=>s.accept(d),onDismiss:()=>s.dismiss(d),onEdit:e=>s.setEdit(d,e)},null!=(n=o.id)?n:d)}),u.length?(0,a.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,a.jsxs)("button",{type:"button",onClick:()=>d(e=>!e),className:"flex items-center justify-between px-1 py-1 text-left text-[11px] text-[var(--graphite-muted)]",children:[(0,a.jsxs)("span",{children:["Dismissed (",u.length,")"]}),(0,a.jsx)("span",{children:o?"â¾":"â¸"})]}),o?u.map(e=>{var t;let{a:r,i:n}=e;return(0,a.jsxs)("div",{className:"flex items-center justify-between rounded-md border border-[var(--mobile-app-card-border)] px-2 py-1.5 text-[11px] text-[var(--graphite-muted)]",children:[(0,a.jsxs)("span",{className:"truncate",children:["#",n+1," ",r.type.replace(/_/g," ")
1]}),(0,a.jsx)("button",{type:"button",onClick:()=>s.restore(n),className:"shrink-0 text-[var(--graphite-primary)] underline",children:"Restore"})]},null!=(t=r.id)?t:n)}):null]}):null]})}async function e6(e,t){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"general";try{let l=await fetch("/api/ops/thermal/sessions/".concat(e,"/interpret"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({capture_ids:t,profile:r})}),i=await l.json().catch(()=>null);if(!l.ok){var a,n;if(402===l.status)return{ok:!1,message:"Need ".concat(null!=(a=null==i?void 0:i.required)?a:"more"," credits â Buy credits")};return{ok:!1,message:null!=(n=null==i?void 0:i.error)?n:"Failed (".concat(l.status,")")}}return{ok:!0,message:(null==i?void 0:i.deduped)?"Already running":"Running AI reviewâ¦"}}catch(e){return{ok:!1,message:"Network error â AI review not started"}}}function e9(e){var t,r,l,i;let{sessionId:s,captures:o,selection:d,scope:c}=e,[u,p]=(0,n.useState)("all"),[m,h]=(0,n.useState)(null),{unit:x}=eQ(),[g,f]=(0,n.useState)(null),[v,b]=(0,n.useState)(!1),y=o.filter(e=>{var t,r;return(null!=(r=null==(t=e.anomalies)?void 0:t.length)?r:0)>0}),j=d.focusedId&&y.some(e=>e.id===d.focusedId)?d.focusedId:null!=(r=null==(t=y[0])?void 0:t.id)?r:null,w=null!=(l=o.find(e=>e.id===j))?l:null,k=null!=(i=null==w?void 0:w.anomalies)?i:[],C=eZ(w);function S(e){let t=o.findIndex(t=>t.id===e);d.click(e,t,{}),h(null)}let _="all"===c.kind?y.map(e=>e.id):"selected"===c.kind?y.filter(e=>d.selectedIds.has(e.id)).map(e=>e.id):j?[j]:[];async function I(){_.length&&!v&&(b(!0),f("Running AI reviewâ¦"),f((await e6(s,_)).message),b(!1))}return(0,a.jsx)(N,{left:{title:"Detections",content:(0,a.jsxs)("div",{className:"flex h-full flex-col gap-2",children:[(0,a.jsxs)("button",{type:"button",disabled:!_.length||v,onClick:()=>void I(),title:"Have AI write explanations for the detections already found",className:"rounded-md border border-[var(--mobile-app-card-border)] px-2 py-1.5 text-left text-xs font-semibold text-[var(--graphite-text-header)] hover:border-[var(--graphite-primary)] disabled:cursor-not-allowed disabled:opacity-40",children:["Run AI on ",_.length,(0,a.jsx)("div",{className:"mt-0.5 text-[10px] font-normal text-[var(--graphite-muted)]",children:"Explains detections already found by Decode + Analyze"})]}),g?(0,a.jsx)("span",{className:"text-[10px] text-[var(--graphite-muted)]",children:g}):null,(0,a.jsx)("div",{className:"min-h-0 flex-1",children:(0,a.jsx)(e2,{captures:y,activeId:j,onOpen:S,filter:u,onFilterChange:p})})]})},center:(0,a.jsx)(e3,{captureId:j,anomalies:k,selectedIndex:m,onSelectIndex:h}),right:{title:"Findings",content:(0,a.jsx)(eV,{sessionId:s,captureId:j,onAcceptProposal:(e,t)=>{C.setEdit(e,t),C.accept(e)},children:(0,a.jsx)(e8,{anomalies:k,unit:x,selectedIndex:m,onSelectIndex:h,review:C})})},bottom:{title:"Filmstrip",compact:!0,defaultSize:20,content:(0,a.jsx)(W,{captures:y,activeId:j,selectedIds:d.selectedIds,onOpen:S,onToggleSelect:e=>d.click(e,o.findIndex(t=>t.id===e),{toggle:!0}),layout:"horizontal"})}})}let e7={cover:"Cover",executive_summary:"Executive summary",methodology:"Methodology",site_info:"Site info",findings:"Findings",severity_table:"Severity scale",recommendations:"Recommendations",disclaimer:"Disclaimer",signature:"Signature"};function te(e){let{order:t,byId:r,onReorder:l,onRemove:i,template:s,onToggleSection:o}=e,[d,c]=(0,n.useState)(null);return(0,a.jsxs)("div",{className:"flex h-full flex-col gap-3 overflow-y-auto",children:[(0,a.jsxs)("div",{children:[(0,a.jsxs)("span",{className:"mb-1 block text-[10px] font-semibold uppercase tracking-wide text-[var(--graphite-muted)]",children:["Images (",t.length,") â drag to reorder"]}),(0,a.jsx)("div",{className:"flex flex-col gap-0.5",children:0===t.length?(0,a.jsx)("p",{className:"p-1 text-[11px] text-[var(--graphite-muted)]",children:"Star â
images in Library to add them here."}):t.map(e=>{let n=r.get(e);return n?(0,a.jsxs)("div",{draggable:!0,onDragStart:()=>c(e),onDragOver:e=>e.preventDefault(),onDrop:()=>(function(e){if(!d||d===e)return;let r=[...t],a=r.indexOf(d),n=r.indexOf(e);-1!==a&&-1!==n&&(r.splice(a,1),r.splice(n,0,d),l(r),c(null))})(e),title:"Drag to reorder",className:"flex cursor-grab items-center gap-2 rounded-md px-2 py-1.5 text-[11px] transition-colors ".concat(d===e?"opacity-40":"text-[var(--graphite-text-header)] hover:bg-[color-mix(in_srgb,var(--graphite-text-header)_5%,transparent)]"),children:[(0,a.jsx)("span",{className:"text-[var(--graphite-muted)]",children:"â ¿"}),(0,a.jsx)("span",{className:"min-w-0 flex-1 truncate",children:n.filename}),(0,a.jsx)("button",{type:"button",onClick:t=>{t.stopPropagation(),i(e)},"aria-label":"Remove ".concat(n.filename," from report"),title:"Remove from report",className:"shrink-0 rounded px-1 text-[var(--graphite-muted)] hover:text-[var(--graphite-text-header)]",children:"\xd7"})]},e):null})})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("span",{className:"mb-1 block text-[10px] font-semibold uppercase tracking-wide text-[var(--graphite-muted)]",children:"Sections"}),(0,a.jsx)("div",{className:"flex flex-col gap-0.5",children:Object.keys(e7).map(e=>(0,a.jsxs)("label",{className:"flex items-center gap-2 px-1 py-0.5 text-[11px] text-[var(--graphite-text-header)]",children:[(0,a.jsx)("input",{type:"checkbox",checked:!1!==s.sections[e],onChange:t=>o(e,t.target.checked)}),e7[e]]},e))})]})]})}function tt(e){let{templates:t,activeId:r,onSelect:n}=e;return(0,a.jsx)("div",{className:"grid grid-cols-2 gap-2",children:t.map(e=>(0,a.jsxs)("button",{type:"button",onClick:()=>n(e.id),title:e.name,className:"flex flex-col gap-1 rounded-md border p-2 text-left transition-colors ".concat(e.id===r?"border-[var(--graphite-primary)]":"border-[var(--mobile-app-card-border)] hover:border-[color-mix(in_srgb,var(--graphite-primary)_45%,var(--mobile-app-card-border))]"),children:[(0,a.jsxs)("div",{className:"flex h-14 w-full flex-col justify-between rounded bg-white p-1.5",children:[(0,a.jsx)("div",{className:"h-1 w-2/3 rounded-full bg-slate-300"}),(0,a.jsxs)("div",{className:"flex flex-1 items-center gap-1 py-1",children:[(0,a.jsx)("div",{className:"h-full w-1/2 roun
1ded-sm bg-slate-100"}),(0,a.jsx)("div",{className:"h-full w-1/2 rounded-sm bg-slate-100"})]})]}),(0,a.jsx)("span",{className:"truncate text-[11px] font-semibold text-[var(--graphite-text-header)]",children:e.name}),(0,a.jsx)("span",{className:"text-[10px] text-[var(--graphite-muted)]",children:e.discipline})]},e.id))})}function tr(e){let{label:t,value:r,onChange:n,placeholder:l}=e;return(0,a.jsxs)("label",{className:"flex flex-col gap-1 text-[11px] text-[var(--graphite-muted)]",children:[t,(0,a.jsx)("input",{value:r,placeholder:l,onChange:e=>n(e.target.value),className:"rounded-md border border-[var(--mobile-app-card-border)] bg-transparent px-2 py-1 text-[var(--graphite-text-header)] focus:border-[var(--graphite-primary)] focus:outline-none"})]})}function ta(e){var t,r;let{sessionId:l,branding:i,onBrandingChange:s,conditions:o,onConditionsChange:d,signature:c,onSignatureChange:u,captureIds:p}=e,[m,h]=(0,n.useState)(!1),[x,g]=(0,n.useState)(null),[f,v]=(0,n.useState)([]);function b(){fetch("/api/ops/thermal/sessions/".concat(l,"/reports")).then(e=>e.ok?e.json():null).then(e=>{var t;return v(null!=(t=null==e?void 0:e.reports)?t:[])}).catch(()=>{})}async function y(){if(!p.length)return;h(!0),g("Generatingâ¦");let e=await _(l,"report",p);g(e.message),h(!1),e.ok&&setTimeout(b,3e3)}return(0,n.useEffect)(b,[l]),(0,a.jsxs)("div",{className:"flex h-full flex-col gap-3 overflow-y-auto",children:[(0,a.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,a.jsx)("span",{className:"text-[10px] font-semibold uppercase tracking-wide text-[var(--graphite-muted)]",children:"Branding"}),(0,a.jsx)(tr,{label:"Company",value:i.company_name,onChange:e=>s({company_name:e})}),(0,a.jsx)(tr,{label:"Logo URL",value:i.logo_url,onChange:e=>s({logo_url:e}),placeholder:"https://â¦"}),(0,a.jsx)(tr,{label:"Footer",value:i.custom_footer,onChange:e=>s({custom_footer:e})})]}),(0,a.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,a.jsx)("span",{className:"text-[10px] font-semibold uppercase tracking-wide text-[var(--graphite-muted)]",children:"Site conditions"}),(0,a.jsx)(tr,{label:"Ambient (\xb0C)",value:String(null!=(t=o.ambient_c)?t:""),onChange:e=>d({...o,ambient_c:e})}),(0,a.jsx)(tr,{label:"Wind (mph)",value:String(null!=(r=o.wind_mph)?r:""),onChange:e=>d({...o,wind_mph:e})})]}),(0,a.jsxs)("label",{className:"flex flex-col gap-1 text-[11px] text-[var(--graphite-muted)]",children:["Signature",(0,a.jsx)("textarea",{value:c,onChange:e=>u(e.target.value),rows:3,className:"rounded-md border border-[var(--mobile-app-card-border)] bg-transparent px-2 py-1 text-[var(--graphite-text-header)] focus:border-[var(--graphite-primary)] focus:outline-none"})]}),(0,a.jsx)("button",{type:"button",disabled:m||!p.length,onClick:()=>void y(),title:"Generate a PDF for ".concat(p.length," image").concat(1===p.length?"":"s"),className:"rounded-md border border-[var(--mobile-app-card-border)] px-2 py-1.5 text-xs font-semibold text-[var(--graphite-text-header)] hover:border-[var(--graphite-primary)] disabled:cursor-not-allowed disabled:opacity-40",children:m?"Generatingâ¦":"Generate PDF (".concat(p.length,")")}),x?(0,a.jsx)("span",{className:"text-[10px] text-[var(--graphite-muted)]",children:x}):null,f.length?(0,a.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,a.jsx)("span",{className:"text-[10px] font-semibold uppercase tracking-wide text-[var(--graphite-muted)]",children:"History"}),f.map(e=>(0,a.jsx)("a",{href:"/api/ops/thermal/sessions/".concat(l,"/reports?download=").concat(e.id,"&fmt=pdf"),target:"_blank",rel:"noreferrer",className:"truncate rounded-md border border-[var(--mobile-app-card-border)] px-2 py-1 text-[11px] text-[var(--graphite-text-header)] hover:border-[var(--graphite-primary)]",children:e.title},e.id))]}):null]})}var tn=r(23583);async function tl(){try{var e,t,r;let a=await fetch("/api/ops/thermal/report-templates");if(!a.ok)return[];let n=await a.json();return null!=(r=null!=(t=n.templates)?t:null==(e=n.data)?void 0:e.templates)?r:[]}catch(e){return[]}}let ti={company_name:"",logo_url:"",primary_color:"",show_metrics:!0,custom_footer:""};var ts=r(30738);function to(e){let{sessionId:t,captures:r,selection:l}=e,i=function(e){var t,r,a,l;
1let[i,s]=(0,n.useState)(""),[o,d]=(0,n.useState)(null),[c,u]=(0,n.useState)(tn.lv),[p,m]=(0,n.useState)(null!=(r=null==(t=tn.lv[0])?void 0:t.id)?r:""),[h,x]=(0,n.useState)(ti),[g,f]=(0,n.useState)({}),[v,b]=(0,n.useState)(""),[y,j]=(0,n.useState)({}),[w,N]=(0,n.useState)(!1),k=(0,n.useRef)(null);function C(t){k.current&&clearTimeout(k.current),k.current=setTimeout(()=>{fetch("/api/ops/thermal/sessions/".concat(e),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({branding_config:t.branding,metadata:{report:{templateId:t.templateId,conditions:t.conditions,signature:t.signature,sectionOverrides:t.sectionOverrides}}})}).catch(()=>{})},500)}(0,n.useEffect)(()=>{let t=!1;return tl().then(e=>{!t&&e.length&&u([...tn.lv,...e])}),fetch("/api/ops/thermal/sessions/".concat(e)).then(e=>e.ok?e.json():null).then(e=>{var r,a,n,l,i;if(t||!(null==e?void 0:e.session))return;let o=e.session;s(null!=(a=o.name)?a:""),d(null!=(n=o.summary_metrics)?n:null),x({...ti,...null!=(l=o.branding_config)?l:{}});let c=null!=(i=null==(r=o.metadata)?void 0:r.report)?i:null;(null==c?void 0:c.templateId)&&m(c.templateId),(null==c?void 0:c.conditions)&&f(c.conditions),"string"==typeof(null==c?void 0:c.signature)&&b(c.signature),(null==c?void 0:c.sectionOverrides)&&j(c.sectionOverrides),N(!0)}).catch(()=>N(!0)),()=>{t=!0}},[e]);let S=null!=(l=null!=(a=c.find(e=>e.id===p))?a:c[0])?l:tn.lv[0];return{loaded:w,sessionName:i,summary:o,templates:c,template:{...S,sections:{...S.sections,...y}},templateId:p,setTemplateId:function(e){m(e),C({templateId:e,conditions:g,signature:v,branding:h,sectionOverrides:y})},branding:h,setBranding:function(e){let t={...h,...e};x(t),C({templateId:p,conditions:g,signature:v,branding:t,sectionOverrides:y})},conditions:g,setConditions:function(e){f(e),C({templateId:p,conditions:e,signature:v,branding:h,sectionOverrides:y})},signature:v,setSignature:function(e){b(e),C({templateId:p,conditions:g,signature:e,branding:h,sectionOverrides:y})},toggleSection:function(e,t){let r={...y,[e]:t};j(r),C({templateId:p,conditions:g,signature:v,branding:h,sectionOverrides:r})}}}(t),s=(0,n.useMemo)(()=>new Map(r.map(e=>[e.id,e])),[r]),o=l.reportOrder;return(0,a.jsx)(N,{left:{title:"Outline",content:(0,a.jsx)(te,{order:o,byId:s,onReorder:l.reorderReport,onRemove:l.removeFromReport,template:i.template,onToggleSection:i.toggleSection})},center:(0,a.jsx)(ts.k,{sessionName:i.sessionName,template:i.template,branding:i.branding,conditions:i.conditions,signature:i.signature,order:o,byId:s,summary:i.summary}),right:{title:"Template & branding",content:(0,a.jsxs)("div",{className:"flex h-full flex-col gap-3 overflow-y-auto",children:[(0,a.jsx)(tt,{templates:i.templates,activeId:i.templateId,onSelect:i.setTemplateId}),(0,a.jsx)(ta,{sessionId:t,branding:i.branding,onBrandingChange:i.setBranding,conditions:i.conditions,onConditionsChange:i.setConditions,signature:i.signature,onSignatureChange:i.setSignature,captureIds:o})]})}})}let td=[{id:"share",label:"Share link"},{id:"reports",label:"Report downloads"},{id:"exports",label:"Data exports"},{id:"qa",label:"Q&A inbox"},{id:"motion",label:"Motion"}];function tc(e){let{active:t,onChange:r}=e;return(0,a.jsx)("nav",{className:"flex flex-col gap-0.5",children:td.map(e=>(0,a.jsx)("button",{type:"button",onClick:()=>r(e.id),className:"rounded-md px-2 py-1.5 text-left text-xs font-medium transition-colors ".concat(t===e.id?"bg-[color-mix(in_srgb,var(--graphite-primary)_16%,transparent)] text-[var(--graphite-text-header)]":"text-[var(--graphite-muted)] hover:text-[var(--graphite-text-header)]"),children:e.label},e.id))})}async function tu(e){try{var t;let r=await fetch("/api/ops/thermal/sessions/".concat(e,"/share"));if(!r.ok)return[];return null!=(t=(await r.json()).links)?t:[]}catch(e){return[]}}async function tp(e,t){try{var r,a,n;let l=await fetch("/api/ops/thermal/share/create",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({session_id:e,role:t.role,label:t.label,expires_at:null!=(r=t.expiresAt)?r:null,password:null!=(a=t.password)?a:null})});if(!l.ok){let e=await l.json().catch(()=>null);return{ok:!1,message:null!=(n=null==e?void 0:e.error)?n:"Failed (".concat(l.status,")")}}return{ok:!0,message:"Link created"}}catch(e){return{ok:!1,message:"Network error â link not created"}}}async function tm(e){try{return(await fetch("/api/ops/thermal/share/revoke",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({token:e})})).ok}catch(e){return!1}}async function th(e){try{var t;let r=await fetch("/api/ops/thermal/sessions/".concat(e,"/questions"));if(!r.ok)return[];return null!=(t=(await r.json()).questions)?t:[]}catch(e){return[]}}async function tx(e,t,r){try{return(await fetch("/api/ops/thermal/sessions/".concat(e,"/questions"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({body:r,parentId:t})})).ok}catch(e){return!1}}function tg(e){let{sessionId:t}
1=e,[r,l]=(0,n.useState)([]),[i,s]=(0,n.useState)("view"),[o,d]=(0,n.useState)(""),[c,u]=(0,n.useState)(""),[p,m]=(0,n.useState)(!1),[h,x]=(0,n.useState)(null);function g(){tu(t).then(l)}async function f(){m(!0);let e=await tp(t,{role:i,label:o||void 0,password:c||null});x(e.message),m(!1),e.ok&&(d(""),u(""),g())}async function v(e,t){window.confirm('Revoke "'.concat(t,'"? Anyone with this link will immediately lose access.'))&&await tm(e)&&g()}return(0,n.useEffect)(g,[t]),(0,a.jsxs)("div",{className:"flex h-full flex-col gap-4 overflow-y-auto",children:[(0,a.jsxs)("div",{className:"flex flex-col gap-2 rounded-md border border-[var(--mobile-app-card-border)] p-3",children:[(0,a.jsx)("span",{className:"text-[10px] font-semibold uppercase tracking-wide text-[var(--graphite-muted)]",children:"New link"}),(0,a.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,a.jsxs)("select",{value:i,onChange:e=>s(e.target.value),title:"What the client can do with this link",className:"rounded-md border border-[var(--mobile-app-card-border)] bg-transparent px-2 py-1 text-xs text-[var(--graphite-text-header)]",children:[(0,a.jsx)("option",{value:"view",children:"View only"}),(0,a.jsx)("option",{value:"annotate",children:"View + annotate"}),(0,a.jsx)("option",{value:"download",children:"View + download"})]}),(0,a.jsx)("input",{value:o,onChange:e=>d(e.target.value),placeholder:"Label (optional)",className:"min-w-0 flex-1 rounded-md border border-[var(--mobile-app-card-border)] bg-transparent px-2 py-1 text-xs text-[var(--graphite-text-header)]"})]}),(0,a.jsx)("input",{value:c,onChange:e=>u(e.target.value),placeholder:"Password (optional)",type:"password",className:"rounded-md border border-[var(--mobile-app-card-border)] bg-transparent px-2 py-1 text-xs text-[var(--graphite-text-header)]"}),(0,a.jsx)("button",{type:"button",disabled:p,onClick:()=>void f(),className:"self-start rounded-md border border-[var(--mobile-app-card-border)] px-2 py-1.5 text-xs font-semibold text-[var(--graphite-text-header)] hover:border-[var(--graphite-primary)] disabled:cursor-not-allowed disabled:opacity-40",children:p?"Creatingâ¦":"Create link"}),h?(0,a.jsx)("span",{className:"text-[11px] text-[var(--graphite-muted)]",children:h}):null]}),(0,a.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,a.jsxs)("span",{className:"text-[10px] font-semibold uppercase tracking-wide text-[var(--graphite-muted)]",children:["Saved links (",r.length,")"]}),0===r.length?(0,a.jsx)("p",{className:"text-xs text-[var(--graphite-muted)]",children:"No share links yet â create one above."}):r.map(e=>(0,a.jsxs)("div",{className:"flex flex-col gap-1 rounded-md border border-[var(--mobile-app-card-border)] p-2 text-xs",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,a.jsx)("span",{className:"truncate font-semibold text-[var(--graphite-text-header)]",children:e.label||e.role}),(0,a.jsx)("span",{className:e.is_revoked?"text-red-400":"text-[var(--graphite-muted)]",children:e.is_revoked?"Revoked":e.role})]}),(0,a.jsx)("a",{href:e.url,target:"_blank",rel:"noreferrer",className:"truncate text-[var(--graphite-primary)] underline",children:e.url}),(0,a.jsxs)("div",{className:"flex items-center justify-between text-[10px] text-[var(--graphite-muted)]",children:[(0,a.jsxs)("span",{children:[e.view_count," view",1===e.view_count?"":"s"]}),e.is_revoked?null:(0,a.jsx)("button",{type:"button",onClick:()=>void v(e.token,e.label||e.role),className:"text-red-400 underline",children:"Revoke"})]})]},e.id))]})]})}function tf(e){let{sessionId:t,mode:r}=e,[l,i]=(0,n.useState)([]);return((0,n.useEffect)(()=>{"reports"===r&&fetch("/api/ops/thermal/sessions/".concat(t,"/reports")).then(e=>e.ok?e.json():null).then(e=>{var t;return i(null!=(t=null==e?void 0:e.reports)?t:[])}).catch(()=>{})},[t,r]),"reports"===r)?(0,a.jsxs)("div",{className:"flex h-full flex-col gap-2 overflow-y-auto",children:[(0,a.jsxs)("span",{className:"text-[10px] font-semibold uppercase tracking-wide text-[var(--graphite-muted)]",children:["Generated reports (",l.length,")"]}),0===l.length?(0,a.jsx)("p",{className:"text-xs text-[var(--graphite-muted)]",children:"No reports generated yet â build one in the Report tab."}):l.map(e=>(0,a.jsxs)("div",{className:"flex items-center justify-between gap-2 rounded-md border border-[var(--mobile-app-card-border)] p-2 text-xs",children:[(0,a.jsx)("span",{className:"truncate text-[var(--graphite-text-header)]",children:e.title}),(0,a.jsxs)("div",{className:"flex shrink-0 gap-2",children:[(0,a.jsx)("a",{href:"/api/ops/thermal/sessions/".concat(t,"/reports?download=").concat(e.id,"&fmt=pdf"),target:"_blank",rel:"noreferrer",className:"text-[var(--graphite-primary)] underline",children:"PDF"}),(0,a.jsx)("a",{href:"/api/ops/thermal/sessions/".concat(t,"/reports?download=").concat(e.id,"&fmt=html"),target:"_blank",rel:"noreferrer",className:"text-[var(--graphite-primary)] underline",children:"HTML"})]})]},e.id))]}):(0,a.jsxs)("div",{className:"flex h-full flex-col gap-2",children:[(0,a.jsx)("span",{className:"text-[10px] font-semibold uppercase tracking-wide text-[var(--graphite-muted)]",children:"Export findings"}),[{id:"csv",label:"Spreadsheet (.csv)",hint:"One row per finding â opens in Excel/Sheets"},{id:"json",label:"Raw data (.json)",hint:"Every capture + anomaly, machine-readable"},{id:"geojson",label:"Map data (.geojson)",hint:"GPS-tagged findings for GIS tools"}].map(e=>(0,a.jsxs)("a",{href:"/api/ops/thermal/sessions/".concat(t,"/export?format=").concat(e.id),className:"flex flex-col rounded-md border border-[var(--mobile-app-card-border)] p-2 text-xs hover:border-[var(--graphite-primary)]",children:[(0,a.jsx)("span",{className:"font-semibold text-[var(--graphite-text-header)]",children:e.label}),(0,a.jsx)("span",{className:"text-[10px] text-[var(--graphite-muted)]",children:e.hint})]},e.id))]})}function tv(e){let{sessionId:t}
1=e,[r,l]=(0,n.useState)([]),[i,s]=(0,n.useState)({});function o(){th(t).then(l)}(0,n.useEffect)(o,[t]);let d=r.filter(e=>!e.is_owner_reply&&!e.parent_id);async function c(e){var r;let a=(null!=(r=i[e])?r:"").trim();a&&await tx(t,e,a)&&(s(t=>({...t,[e]:""})),o())}return d.length?(0,a.jsx)("div",{className:"flex h-full flex-col gap-3 overflow-y-auto",children:d.map(e=>{var t,n;let l=r.filter(t=>t.parent_id===e.id);return(0,a.jsxs)("div",{className:"flex flex-col gap-2 rounded-md border border-[var(--mobile-app-card-border)] p-2 text-xs",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,a.jsx)("span",{className:"font-semibold text-[var(--graphite-text-header)]",children:null!=(t=e.author_name)?t:"Client"}),(0,a.jsx)("span",{className:"answered"===e.status?"text-[var(--graphite-muted)]":"text-[var(--graphite-primary)]",children:e.status})]}),(0,a.jsx)("p",{className:"text-[var(--graphite-text-header)]",children:e.body}),l.map(e=>(0,a.jsx)("p",{className:"ml-3 border-l-2 border-[var(--mobile-app-card-border)] pl-2 text-[var(--graphite-muted)]",children:e.body},e.id)),(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)("input",{value:null!=(n=i[e.id])?n:"",onChange:t=>s(r=>({...r,[e.id]:t.target.value})),placeholder:"Replyâ¦",className:"min-w-0 flex-1 rounded-md border border-[var(--mobile-app-card-border)] bg-transparent px-2 py-1 text-xs text-[var(--graphite-text-header)]"}),(0,a.jsx)("button",{type:"button",onClick:()=>void c(e.id),className:"rounded-md border border-[var(--mobile-app-card-border)] px-2 py-1 text-xs font-semibold text-[var(--graphite-text-header)] hover:border-[var(--graphite-primary)]",children:"Send"})]})]},e.id)})}):(0,a.jsx)("p",{className:"p-2 text-xs text-[var(--graphite-muted)]",children:"No client questions yet."})}function tb(e){let{frameCount:t,onOpen:r}=e;return(0,a.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,a.jsxs)("span",{className:"text-[10px] font-semibold uppercase tracking-wide text-[var(--graphite-muted)]",children:["Motion (",t," frames available)"]}),[{mode:"timelapse",title:"Timelapse Builder",hint:"Condense a long capture window into a short MP4 (e.g. 6 hours â 30s)"},{mode:"video",title:"Video Trim",hint:"Trim, retime, and export a clip from this session's frames"}].map(e=>(0,a.jsxs)("button",{type:"button",onClick:()=>r(e.mode),disabled:t<1,className:"flex flex-col rounded-md border border-[var(--mobile-app-card-border)] p-3 text-left hover:border-[var(--graphite-primary)] disabled:cursor-not-allowed disabled:opacity-40",children:[(0,a.jsx)("span",{className:"text-sm font-semibold text-[var(--graphite-text-header)]",children:e.title}),(0,a.jsx)("span",{className:"mt-0.5 text-xs text-[var(--graphite-muted)]",children:e.hint})]},e.mode))]})}function ty(e){var t;let{frameCount:r,range:l,onRangeChange:i,filenames:s}=e,o=(0,n.useRef)(null),[d,c]=(0,n.useState)(null),u=Math.max(1,r-1);function p(e){let t=o.current;if(!t)return 0;let r=t.getBoundingClientRect();return Math.round(Math.max(0,Math.min(1,(e-r.left)/r.width))*u)}function m(e){return t=>{function r(t){let r=p(t.clientX);"in"===e?i({...l,inIdx:Math.min(r,l.outIdx)}):"out"===e?i({...l,outIdx:Math.max(r,l.inIdx)}):i({...l,playheadIdx:Math.max(l.inIdx,Math.min(l.outIdx,r))})}t.stopPropagation(),c(e),window.addEventListener("mousemove",r),window.addEventListener("mouseup",function e(){c(null),window.removeEventListener("mousemove",r),window.removeEventListener("mouseup",e)})}}let h=e=>"".concat(e/u*100,"%");return(0,a.jsxs)("div",{className:"flex h-full min-h-0 flex-col gap-1 px-2 py-1.5",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between gap-2 text-[10px] text-[var(--graphite-muted)]",children:[(0,a.jsxs)("span",{className:"shrink-0",children:[l.outIdx-l.inIdx+1," of ",r," frames in range"]}),(0,a.jsx)("span",{className:"min-w-0 truncate",children:null!=(t=s[l.playheadIdx])?t:""})]}),(0,a.jsxs)("div",{ref:o,onClick:function(e){if(d)return;let t=p(e.clientX);i({...l,playheadIdx:Math.max(l.inIdx,Math.min(l.outIdx,t))})},className:"relative h-8 shrink-0 cursor-pointer rounded-md border border-[var(--mobile-app-card-border)] bg-[var(--graphite-canvas-deep)]",children:[(0,a.jsx)("div",{className:"pointer-events-none absolute inset-y-0 bg-[color-mix(in_srgb,var(--graphite-primary)_18%,transparent)]",style:{left:h(l.inIdx),right:"calc(100% - ".concat(h(l.outIdx),")")}}),Array.from({length:r},(e,t)=>(0,a.jsx)("span",{className:"pointer-events-none absolute top-0 h-full w-px bg-[var(--mobile-app-card-border)]",style:{left:h(t)}},t)),(0,a.jsx)("div",{onMouseDown:m("in"),title:"Drag to set the in point",className:"absolute top-0 z-10 h-full w-2 -translate-x-1/2 cursor-ew-resize rounded-sm bg-[var(--graphite-primary)]",style:{left:h(l.inIdx)}}),(0,a.jsx)("div",{onMouseDown:m("out"),title:"Drag to set the out point",className:"absolute top-0 z-10 h-full w-2 -translate-x-1/2 cursor-ew-resize rounded-sm bg-[var(--graphite-primary)]",style:{left:h(l.outIdx)}}),(0,a.jsx)("div",{onMouseDown:m("playhead"),title:"Drag to scrub",className:"absolute -top-1 z-0 h-[calc(100%+8px)] w-0.5 -translate-x-1/2 cursor-ew-resize bg-white",style:{left:h(l.playheadIdx)}})]})]})}let tj={aspect:"16:9",fps:12,smoothing:"interpolate",deflicker:!0,overlay:"clean",retainRadiometric:!0};async function tw(e,t,r,a){try{var n,l,i;let s=await fetch("/api/ops/thermal/timelapse",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessionId:e,mode:t,frameIds:r,settings:a})}),o=await s.json();if(!s.ok)return{error:null!=(n=null==o?void 0:o.error)?n:"Failed to start render"};let d=null!=(l=o.data)?l:o;return{dispatched:!!d.dispatched,frames:Number(null!=(i=d.frames)?i:r.length)}}catch(e){return{error:"Network error â render not started"}}}let tN=["original","16:9","9:16","1:1","4:3","21:9"];function tk(e){var t;let{sessionId:r,captures:l,mode:i,range:s,onRangeChange:o,settings:d,onSettingsChange:c,onBack:u}
1=e,[p,m]=(0,n.useState)("Output"),[h,x]=(0,n.useState)(!1),[g,f]=(0,n.useState)(null);function v(e){m(t=>t===e?"":e)}function b(e){c({...d,...e})}(0,n.useEffect)(()=>{function e(e){"Escape"===e.key&&u()}return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[u]);let y=null!=(t=l[s.playheadIdx])?t:null,j=s.outIdx-s.inIdx+1,w=d.fps?j/d.fps:0;async function N(){let e=l.slice(s.inIdx,s.outIdx+1).map(e=>e.id);if(!e.length)return;x(!0),f(null);let t=await tw(r,i,e,d);f("error"in t?t.error:t.dispatched?"Rendering in the cloud â the MP4 will appear in Deliver's Share link when ready.":"Saved â will render once the cloud worker is enabled for this environment."),x(!1)}return(0,a.jsxs)("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:[(0,a.jsxs)("div",{className:"flex shrink-0 items-center gap-3 border-b border-[var(--mobile-app-card-border)] px-3 py-2",children:[(0,a.jsx)("button",{type:"button",onClick:u,className:"text-xs font-semibold text-[var(--graphite-muted)] hover:text-[var(--graphite-text-header)]",children:"â Deliver"}),(0,a.jsx)("span",{className:"text-xs font-semibold text-[var(--graphite-text-header)]",children:"timelapse"===i?"Timelapse Builder":"Video Trim"})]}),(0,a.jsxs)("div",{className:"flex min-h-0 flex-1",children:[(0,a.jsxs)("div",{className:"flex min-h-0 flex-1 flex-col",children:[(0,a.jsx)("div",{className:"flex min-h-0 flex-1 items-center justify-center overflow-hidden bg-[var(--graphite-canvas-deep)] p-3",children:(null==y?void 0:y.previewUrl)?(0,a.jsxs)("div",{className:"relative flex h-full w-full items-center justify-center",children:[(0,a.jsx)("img",{src:y.previewUrl,alt:y.filename,className:"max-h-full max-w-full rounded object-contain"}),(0,a.jsxs)("span",{className:"absolute left-2 top-2 rounded bg-black/60 px-1.5 py-0.5 text-[10px] text-white",children:[d.aspect," \xb7 ",w?"".concat(w.toFixed(1),"s @ ").concat(d.fps,"fps"):"no frames in range"]})]}):(0,a.jsx)("p",{className:"text-xs text-[var(--graphite-muted)]",children:"No frames available."})}),(0,a.jsx)("div",{className:"h-24 shrink-0 border-t border-[var(--mobile-app-card-border)]",children:(0,a.jsx)(ty,{frameCount:l.length,range:s,onRangeChange:o,filenames:l.map(e=>e.filename)})})]}),(0,a.jsxs)("div",{className:"w-72 shrink-0 overflow-y-auto border-l border-[var(--mobile-app-card-border)] p-2",children:[(0,a.jsxs)(em,{title:"timelapse"===i?"Speed & duration":"Playback speed",open:"speed"===p,onToggle:()=>v("speed"),children:[(0,a.jsxs)("label",{className:"block text-[11px] text-[var(--graphite-muted)]",children:[d.fps," fps",w?" â ".concat(w.toFixed(1),"s"):"",(0,a.jsx)("input",{type:"range",min:1,max:30,value:d.fps,onChange:e=>b({fps:Number(e.target.value)}),className:"mt-1 w-full accent-[var(--graphite-primary)]"})]}),(0,a.jsx)("input",{type:"number",min:1,max:30,value:d.fps,onChange:e=>b({fps:Number(e.target.value)}),className:"mt-2 w-20 rounded-md border border-[var(--mobile-app-card-border)] bg-transparent px-2 py-1 text-xs text-[var(--graphite-text-header)]"})]}),(0,a.jsx)(em,{title:"Overlay",open:"overlay"===p,onToggle:()=>v("overlay"),children:(0,a.jsx)("div",{className:"flex flex-col gap-1.5",children:[["clean","Clean â no marks (raw thermal)"],["keep","Keep marks static"],["animate","Animate temperatures changing"]].map(e=>{let[t,r]=e;return(0,a.jsxs)("label",{className:"flex items-center gap-2 text-[11px] text-[var(--graphite-text-header)]",children:[(0,a.jsx)("input",{type:"radio",name:"motion-overlay",checked:d.overlay===t,onChange:()=>b({overlay:t}),className:"accent-[var(--graphite-primary)]"}),r]},t)})})}),(0,a.jsxs)(em,{title:"Output",open:"Output"===p,onToggle:()=>v("Output"),children:[(0,a.jsxs)("label",{className:"block text-[11px] text-[var(--graphite-muted)]",children:["Aspect ratio",(0,a.jsx)("select",{value:d.aspect,onChange:e=>b({aspect:e.target.value}),className:"mt-1 block w-full rounded-md border border-[var(--mobile-app-card-border)] bg-[var(--graphite-canvas-deep)] px-2 py-1 text-xs text-[var(--graphite-text-header)]",children:tN.map(e=>(0,a.jsx)("option",{value:e,children:"original"===e?"Original":e},e))})]}),(0,a.jsxs)("label",{className:"mt-2 block text-[11px] text-[var(--graphite-muted)]",children:["Smoothing",(0,a.jsxs)("select",{value:d.smoothing,onChange:e=>b({smoothing:e.target.value}),className:"mt-1 block w-full rounded-md border border-[var(--mobile-app-card-border)] bg-[var(--graphite-canvas-deep)] px-2 py-1 text-xs text-[var(--graphite-text-header)]",children:[(0,a.jsx)("option",{value:"none",children:"None"}),(0,a.jsx)("option",{value:"interpolate",children:"Motion interpolation"}),(0,a.jsx)("option",{value:"rife",children:"High quality (RIFE)"})]})]}),(0,a.jsxs)("label",{className:"mt-2 flex items-center gap-2 text-[11px] text-[var(--graphite-text-header)]",children:[(0,a.jsx)("input",{type:"checkbox",checked:d.deflicker,onChange:e=>b({deflicker:e.target.checked}),className:"accent-[var(--graphite-primary)]"}),"Deflicker"]}
1),(0,a.jsxs)("label",{className:"mt-1 flex items-center gap-2 text-[11px] text-[var(--graphite-text-header)]",children:[(0,a.jsx)("input",{type:"checkbox",checked:d.retainRadiometric,onChange:e=>b({retainRadiometric:e.target.checked}),className:"accent-[var(--graphite-primary)]"}),"Also retain radiometric stack"]})]}),(0,a.jsxs)("div",{className:"mt-2 flex flex-col gap-1.5 p-1",children:[(0,a.jsx)("button",{type:"button",disabled:h||j<1,onClick:()=>void N(),className:"w-full rounded-lg bg-[var(--graphite-primary)] px-3 py-2 text-sm font-semibold text-[var(--graphite-canvas)] disabled:opacity-50",children:h?"Queuingâ¦":"Render ".concat("timelapse"===i?"time-lapse":"video"," â MP4")}),g?(0,a.jsx)("p",{className:"text-[11px] text-[var(--graphite-muted)]",children:g}):null]})]})]})]})}function tC(e){let{sessionId:t,captures:r,motion:l}=e,[i,s]=(0,n.useState)("share"),[o,d]=(0,n.useState)(null);if(o){let e=l.stateFor(o);return(0,a.jsx)(tk,{sessionId:t,captures:r,mode:o,range:e.range,onRangeChange:e=>l.setRange(o,e),settings:e.settings,onSettingsChange:e=>l.setSettings(o,e),onBack:()=>d(null)})}return(0,a.jsx)(N,{left:{title:"Sections",content:(0,a.jsx)(tc,{active:i,onChange:s})},center:(0,a.jsxs)("div",{className:"h-full overflow-y-auto p-3",children:["share"===i?(0,a.jsx)(tg,{sessionId:t}):null,"reports"===i?(0,a.jsx)(tf,{sessionId:t,mode:"reports"}):null,"exports"===i?(0,a.jsx)(tf,{sessionId:t,mode:"exports"}):null,"qa"===i?(0,a.jsx)(tv,{sessionId:t}):null,"motion"===i?(0,a.jsx)(tb,{frameCount:r.length,onOpen:d}):null]})})}function tS(e){return{range:{inIdx:0,outIdx:Math.max(0,e-1),playheadIdx:0},settings:tj}}var t_=r(64323),tI=r(8525);let tE=[{id:"library",label:"Library"},{id:"analyze",label:"Analyze"},{id:"ai-review",label:"AI Review"},{id:"report",label:"Report"},{id:"deliver",label:"Deliver"}];function tM(e){let{sessionId:t,sessionName:r,captures:o,initialTab:d,initialReportSet:c}
1=e,[p,m]=(0,n.useState)(o),[x,f]=(0,n.useState)(null!=d?d:"library"),[b,y]=(0,n.useState)({kind:"image"}),[j,w]=(0,n.useState)(null),N=function(e,t,r){let[a,l]=(0,n.useState)(new Set),[i,s]=(0,n.useState)(null),[o,d]=(0,n.useState)(null),[c,u]=(0,n.useState)(()=>(0,v.kS)(t,r)),p=(0,n.useMemo)(()=>new Set(c),[c]),m=(0,n.useCallback)(function(e,r){let a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};s(e),l(n=>{if(a.shift&&null!==o){let[e,a]=o<r?[o,r]:[r,o];return new Set([...n,...t.slice(e,a+1).map(e=>e.id)])}if(a.toggle){let t=new Set(n);return t.has(e)?t.delete(e):t.add(e),t}return new Set([e])}),a.shift||d(r)},[o,t]),h=(0,n.useCallback)(()=>{l(new Set(t.map(e=>e.id)))},[t]),x=(0,n.useCallback)(()=>l(new Set),[]),g=(0,n.useCallback)(t=>{u(r=>{let a=t.filter(e=>!r.includes(e));if(!a.length)return r;let n=[...r,...a];return a.forEach((e,t)=>void(0,v.wy)(e,!0,r.length+t)),(0,v.vc)(e,n),n})},[e]);return{selectedIds:a,focusedId:i,reportIds:p,reportOrder:c,click:m,selectAll:h,clearSelection:x,addToReport:g,reorderReport:(0,n.useCallback)(t=>{u(t),(0,v.vc)(e,t)},[e]),removeFromReport:(0,n.useCallback)(t=>{u(r=>{if(!r.includes(t))return r;let a=r.filter(e=>e!==t);return(0,v.wy)(t,!1,-1),(0,v.vc)(e,a),a})},[e])}}(t,p,c),k=function(e){let[t,r]=(0,n.useState)(()=>
1tS(e)),[a,l]=(0,n.useState)(()=>tS(e));function i(e){return"timelapse"===e?r:l}return{stateFor:function(e){return"timelapse"===e?t:a},setRange:function(e,t){i(e)(e=>({...e,range:t}))},setSettings:function(e,t){i(e)(e=>({...e,settings:t}))}}}(p.length),C=N.selectedIds.size,S=p.length,I=(0,n.useCallback)(async()=>{try{let e=await fetch("/api/ops/thermal/sessions/".concat(t));if(!e.ok)return;let r=await e.json();Array.isArray(null==r?void 0:r.captures)&&m(r.captures.map(e=>{var t,r,a,n,l;return{id:e.id,filename:null!=(t=e.filename)?t:"Capture",previewUrl:null!=(r=e.previewUrl)?r:null,qualityMetrics:null!=(a=e.quality_metrics)?a:null,metadata:null!=(n=e.metadata)?n:null,anomalies:null!=(l=e.anomalies)?l:null}}))}catch(e){}},[t]);function E(e){"selected"===e?y({kind:e,count:C}):"all"===e?y({kind:e,count:S}):y({kind:"image"})}(0,n.useEffect)(()=>{if(!t)return;let e=(0,tI.U)(),r=e.channel("thermal-captures:".concat(t)).on(t_.eO.POSTGRES_CHANGES,{event:"INSERT",schema:"public",table:"thermal_captures",filter:"session_id=eq.".concat(t)},()=>I()).subscribe();return()=>{e.removeChannel(r)}},[t]),(0,n.useEffect)(()=>{var e;return e=(e,t)=>{m(r=>r.map(r=>r.id===e?{...r,metadata:t}:r))},u.add(e),()=>{u.delete(e)}},[]);let M="selected"===b.kind?{kind:"selected",count:C}:"all"===b.kind?{kind:"all",count:S}:b;(0,n.useEffect)(()=>{function e(e){(function(){for(let[,e]of s)if("saving"===e.status||"error"===e.status)return!0;return!1})()&&(e.preventDefault(),e.returnValue="")}return window.addEventListener("beforeunload",e),()=>window.removeEventListener("beforeunload",e)},[]),(0,n.useEffect)(()=>{function e(e){var t;return!!(null==(t=e.dataTransfer)?void 0:t.types.includes("Files"))}function r(t){e(t)&&t.preventDefault()}async function a(r){var a,n;if(!e(r))return;r.preventDefault();let l=Array.from(null!=(n=null==(a=r.dataTransfer)?void 0:a.files)?n:[]);if(l.length){f("library"),w({done:0,total:l.length});for(let e=0;e<l.length;e++)await T(t,l[e]),w({done:e+1,total:l.length});setTimeout(()=>w(null),2e3),I()}}return window.addEventListener("dragover",r),window.addEventListener("drop",a),()=>{window.removeEventListener("dragover",r),window.removeEventListener("drop",a)}},[t,I]);let R=(0,n.useRef)(null);return(0,n.useEffect)(()=>{function e(e){var t,r;if("Escape"!==e.key)return;let a=e.target;(!a||"INPUT"!==a.tagName&&"TEXTAREA"!==a.tagName)&&(null!=(r=null==(t=R.current)?void 0:t.call(R))&&r||"image"===b.kind||E("image"))}return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[b.kind]),(0,a.jsxs)(l._V,{title:"Thermal Studio",subtitle:r,bare:!0,tabsSlot:(0,a.jsx)(l.RH,{tabs:tE,active:x,onChange:f}),rightSlot:(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(i,{scope:M,selectedCount:C,totalCount:S,onChange:E}),(0,a.jsx)(l.PB,{label:"Images",value:S}),(0,a.jsx)(h,{}),(0,a.jsx)(g,{sessionId:t,onRetry:function(e,r){r.length&&_(t,e,r)}}),j?(0,a.jsxs)("span",{className:"flex items-center gap-1.5 rounded-md border border-[var(--mobile-app-card-border)] px-2 py-0.5 text-[11px] text-[var(--graphite-muted)]",children:["Uploading ",j.done,"/",j.total,"â¦"]}):null]}),children:["library"===x?(0,a.jsx)(K,{sessionId:t,captures:p,scope:M,selection:N,onOpenInAnalyze:function(e,t){N.click(e,t,{}),f("analyze")},refetchCaptures:I}):null,"analyze"===x?(0,a.jsx)(e1,{sessionId:t,captures:p,selection:N,scope:M,registerEscapeHandler:e=>{R.current=e}}):null,"ai-review"===x?(0,a.jsx)(e9,{sessionId:t,captures:p,selection:N,scope:M}):null,"report"===x?(0,a.jsx)(to,{sessionId:t,captures:p,selection:N}):null,"deliver"===x?(0,a.jsx)(tC,{sessionId:t,captures:p,motion:k}):null]})}},8525:(e,t,r)=>{r.d(t,{U:()=>n});var a=r(89177);function n(){return(0,a.createBrowserClient)("https://hadnfcenpcfaeclczsmm.supabase.co","eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImhhZG5mY2VucGNmYWVjbGN6c21tIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NjQ1NzcwNzcsImV4cCI6MjA4MDE1MzA3N30.lUKufUuiGg-T-H3zX-oIIBiLwgKRYs_XLlBlK5hFhwo")}},11186:(e,t,r)=>{r.d(t,{r:()=>i});var a=r(12115),n=r(64323),l=r(8525);function i(e){let[t,r]=(0,a.useState)(null),[i,s]=(0,a.useState)(!1);return(0,a.useEffect)(()=>
1{if(!e){r(null),s(!1);return}let t=(0,l.U)(),a=t.channel("thermal-jobs:".concat(e)).on(n.eO.POSTGRES_CHANGES,{event:"*",schema:"public",table:"thermal_processing_jobs",filter:"session_id=eq.".concat(e)},e=>{var t;let a=null!=(t=e.new)?t:e.old;(null==a?void 0:a.id)&&r(a)}).subscribe(e=>{s(String(e).includes("SUBSCRIBED"))});return t.from("thermal_processing_jobs").select("id, status, progress_pct, stage, error_log, created_at, job_type, partial, failed_capture_ids, input_capture_ids").eq("session_id",e).order("created_at",{ascending:!1}).limit(1).maybeSingle().then(e=>{let{data:t}=e;t&&r(t)}),()=>{t.removeChannel(a)}},[e]),{job:t,connected:i}}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.