DefectRAG / frontend /dist /assets /TeamWorkspace-Rlmhwv_4.js
Wizzas's picture
Update verified React dashboard
ced4b4c verified
Raw History Blame Contribute Delete
46.1 kB
import{c as fe,r as a,l as ct,a as it,b as ot,d as dt,e as mt,s as tt,f as M,R as ut,g as Ge,h as e,i as Ue,p as at,n as Me,j as rt,k as st,m as pt,w as Re,o as Qe,q as ft,t as ht,u as Et,v as yt,x as vt,y as gt,z as bt,A as wt,B as Nt,C as St,L as kt,S as _t,D as Ct,E as Xe,F as Dt,G as Rt,H as Ze,I as xt}from"./index-pB2283yq.js";/**
* @license lucide-react v0.468.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/const Tt=fe("ArchiveRestore",[["rect",{width:"20",height:"5",x:"2",y:"3",rx:"1",key:"1wp1u1"}],["path",{d:"M4 8v11a2 2 0 0 0 2 2h2",key:"tvwodi"}],["path",{d:"M20 8v11a2 2 0 0 1-2 2h-2",key:"1gkqxj"}],["path",{d:"m9 15 3-3 3 3",key:"1pd0qc"}],["path",{d:"M12 12v9",key:"192myk"}]]);/**
* @license lucide-react v0.468.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/const Be=fe("Cloud",[["path",{d:"M17.5 19H9a7 7 0 1 1 6.71-9h1.79a4.5 4.5 0 1 1 0 9Z",key:"p7xjir"}]]);/**
* @license lucide-react v0.468.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/const qt=fe("ExternalLink",[["path",{d:"M15 3h6v6",key:"1q9fwt"}],["path",{d:"M10 14 21 3",key:"gplh6r"}],["path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6",key:"a6xqqp"}]]);/**
* @license lucide-react v0.468.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/const At=fe("LogIn",[["path",{d:"M15 3h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-4",key:"u53s6r"}],["polyline",{points:"10 17 15 12 10 7",key:"1ail0h"}],["line",{x1:"15",x2:"3",y1:"12",y2:"12",key:"v6grx8"}]]);/**
* @license lucide-react v0.468.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/const Lt=fe("LogOut",[["path",{d:"M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4",key:"1uf3rs"}],["polyline",{points:"16 17 21 12 16 7",key:"1gabdz"}],["line",{x1:"21",x2:"9",y1:"12",y2:"12",key:"1uyos4"}]]);/**
* @license lucide-react v0.468.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/const Pt=fe("RefreshCw",[["path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8",key:"v9h5vc"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}],["path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16",key:"3uifl3"}],["path",{d:"M8 16H3v5",key:"1cv678"}]]);/**
* @license lucide-react v0.468.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/const It=fe("Send",[["path",{d:"M14.536 21.686a.5.5 0 0 0 .937-.024l6.5-19a.496.496 0 0 0-.635-.635l-19 6.5a.5.5 0 0 0-.024.937l7.93 3.18a2 2 0 0 1 1.112 1.11z",key:"1ffxy3"}],["path",{d:"m21.854 2.147-10.94 10.939",key:"12cjpa"}]]);/**
* @license lucide-react v0.468.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/const Ft=fe("Users",[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}],["path",{d:"M22 21v-2a4 4 0 0 0-3-3.87",key:"kshegd"}],["path",{d:"M16 3.13a4 4 0 0 1 0 7.75",key:"1da9ce"}]]),Ye="17:00",Ot=[{label:"Tomorrow",days:1},{label:"In 3 days",days:3},{label:"In 1 week",days:7},{label:"In 2 weeks",days:14}],Pe=n=>String(n).padStart(2,"0"),je=n=>n.getFullYear()+"-"+Pe(n.getMonth()+1)+"-"+Pe(n.getDate());function Je(n,s=new Date){const m=new Date(s);return m.setDate(m.getDate()+n),je(m)}const Ve=(n,s)=>n?n+"T"+(s||Ye):"",Mt=n=>({date:n?n.slice(0,10):"",time:n?n.slice(11,16):""}),nt=n=>{const[s,m]=n.split(":").map(Number);return(s%12||12)+":"+Pe(m)+" "+(s<12?"AM":"PM")};function zt(n){const s=[];for(let m=420;m<=1200;m+=30)s.push(Pe(Math.floor(m/60))+":"+Pe(m%60));return n&&/^\d\d:\d\d$/.test(n)&&!s.includes(n)&&s.push(n),s.sort()}function Ut(n,s=new Date){const m=Math.round((new Date(n.slice(0,10)+"T00:00")-new Date(je(s)+"T00:00"))/864e5);return m===0?"today":m===1?"tomorrow":m>1?"in "+m+" days":m===-1?"yesterday":Math.abs(m)+" days ago"}function lt(n,s=new Date){if(!n||!Number.isFinite(Date.parse(n)))return"";const m=new Date(n.slice(0,10)+"T00:00"),i=D=>m.toLocaleDateString("en-GB",D);return i({weekday:"long"})+", "+m.getDate()+" "+i({month:"short"})+" "+m.getFullYear()+" at "+nt(n.slice(11,16))+" · "+Ut(n,s)}const ze=n=>new Date(n).toLocaleString([],{dateStyle:"medium",timeStyle:"short"}),jt=n=>{const s=new Date(n);return je(s)+"T"+String(s.getHours()).padStart(2,"0")+":"+String(s.getMinutes()).padStart(2,"0")};function et({legend:n,prefix:s,value:m,time:i,setValue:D,setTime:v,disabled:z,required:_,keep:F}){const g=Mt(m),U=g.time||i,Y=h=>D(Ve(h,U)),$=h=>{v(h),g.date&&D(Ve(g.date,h))};return e.createElement("fieldset",{className:"due-field"},e.createElement("legend",null,n),e.createElement("div",{className:"due-shortcuts",role:"group","aria-label":n+" shortcuts"},F&&e.createElement("button",{type:"button",className:"chip"+(m?"":" selected"),"aria-pressed":!m,disabled:z,onClick:()=>D("")},"Keep current"),Ot.map(h=>{const O=Je(h.days);return e.createElement("button",{type:"button",key:h.days,className:"chip"+(g.date===O?" selected":""),"aria-pressed":g.date===O,disabled:z,onClick:()=>Y(O)},h.label)})),e.createElement("div",{className:"due-inputs"},e.createElement("label",{className:"field"},s,"date",e.createElement("input",{type:"date",disabled:z,required:_,min:je(new Date),max:Je(365),value:g.date,onInput:h=>Y(h.target.value),onChange:h=>Y(h.target.value)})),e.createElement("label",{className:"field"},s,"time",e.createElement("select",{disabled:z,value:U,onChange:h=>$(h.target.value)},zt(U).map(h=>e.createElement("option",{key:h,value:h},nt(h)))))),e.createElement("p",{className:"caption due-summary","aria-live":"polite"},m?e.createElement(e.Fragment,null,"Due ",e.createElement("strong",null,lt(m))):F||"Pick a day within the next year. Time starts at 5:00 PM."))}function Ht({user:n,inspection:s,notes:m=[],inspections:i=[],inspectionLoading:D=!1,onSelectInspection:v,onEvidence:z}){var Ke;const _=a.useRef(0),F=a.useRef(!1),g=a.useRef(s==null?void 0:s.id),U=a.useRef(null),Y=a.useRef(null),$=a.useRef(null),[h,O]=a.useState("checking"),[T,j]=a.useState([]),[H,E]=a.useState([]),[de,f]=a.useState(""),[se,N]=a.useState([]),[q,L]=a.useState([]),[he,A]=a.useState(""),[S,J]=a.useState(!1),[me,w]=a.useState(""),[P,Ee]=a.useState(""),[K,l]=a.useState(""),[b,W]=a.useState("Normal"),[ne,u]=a.useState(""),[R,ye]=a.useState(Ye),[V,le]=a.useState(!1),[ee,Se]=a.useState(""),[xe,ke]=a.useState(""),[_e,Te]=a.useState(null),[qe,He]=a.useState(0),[Ce,Ae]=a.useState(""),[Ie,ce]=a.useState(""),[ue,ve]=a.useState(""),[De,Q]=a.useState(Ye),c=T.find(t=>t.id===de),B=ct(m),ie=it(T),C=ot(s,m,T,D),Fe=dt({description:me,owner:P,supervisor:K,priority:b,due:ne},H),r=C.ready?Fe||(V?"":"Tick the box to confirm the defect."):C.reason,[d,o]=a.useState([]),[x,ge]=a.useState("all"),k=t=>["Resolved","Closed","Cancelled"].includes(t.state),X=t=>!k(t)&&Date.parse(t.due_at)<Date.now(),te=[["all","All",()=>!0],["open","Open",t=>!k(t)],["overdue","Overdue",X],["done","Done",k]],be=T.filter(((Ke=te.find(t=>t[0]===x))==null?void 0:Ke[2])||(()=>!0)),G=i.filter(t=>!t.archived_at),ae=G.map(t=>t.id).join(","),I=t=>pt(t.id===(s==null?void 0:s.id)?m:d.filter(p=>p.inspection_id===t.id),T),re=G.map(t=>({row:t,status:I(t)})).sort((t,p)=>(p.status.key==="ready")-(t.status.key==="ready")),pe=re.filter(t=>t.status.key==="ready").length,oe=mt(c,n.id,H.some(t=>t.user_id===n.id&&t.role==="developer")),we=!!c&&_e!==null&&_e!==c.version;async function Oe(){const t=++_.current,p=await M(),y=await p.rpc("defectrag_ca_staff");if(t!==_.current)return;if(y.error||y.data!==!0)throw O("denied"),j([]),E([]),f(""),N([]),L([]),new Error("Sign in with an approved Staff account and verify the security code before opening corrective actions.");const Z=await Promise.all([p.from("corrective_actions").select("*").order("created_at",{ascending:!1}).limit(500),p.from("staff_members").select("user_id,display_name,role,revoked_at").is("revoked_at",null)]);if(t===_.current){if(Z.some(Le=>Le.error))throw O("unavailable"),j([]),E([]),f(""),N([]),L([]),Z.find(Le=>Le.error).error;O("authorized"),j(Z[0].data||[]),E(Z[1].data||[]),A(""),He(Le=>Le+1)}}a.useEffect(()=>{const t=tt(Oe,{onState:p=>{p.error&&(O("unavailable"),A(p.error),j([]),E([]),f(""),N([]),L([]))}});return()=>{t.stop(),_.current++}},[n.id]),a.useEffect(()=>{const t=()=>{_.current++,O("checking"),j([]),E([]),f(""),N([]),L([]),Oe().catch(p=>A(p.message))};return window.addEventListener("defectrag-auth-change",t),()=>window.removeEventListener("defectrag-auth-change",t)},[n.id]),a.useEffect(()=>{g.current&&g.current!==(s==null?void 0:s.id)&&(w(""),Ee(""),l(""),u(""),W("Normal")),g.current=s==null?void 0:s.id,le(!1)},[s==null?void 0:s.id]),a.useEffect(()=>{le(!1)},[B==null?void 0:B.id]),a.useEffect(()=>{let t=!0;const p=ae?ae.split(","):[];if(h!=="authorized"||!p.length){o([]);return}return M().then(y=>y.from("staff_notes").select("id,inspection_id,author_id,body,created_at").in("inspection_id",p).like("body",ut+"%").order("created_at").limit(2e3)).then(({data:y,error:Z})=>{if(t){if(Z)throw Z;o(y||[])}}).catch(()=>{t&&o([])}),()=>{t=!1}},[h,ae,qe]),a.useEffect(()=>{h==="authorized"&&Ge(Y.current)},[h,s==null?void 0:s.id,B==null?void 0:B.id]);function $e(){ke(""),Se((c==null?void 0:c.state)||""),Ae((c==null?void 0:c.owner_id)||""),ce((c==null?void 0:c.supervisor_id)||""),ve(""),Te((c==null?void 0:c.version)??null)}a.useEffect($e,[c==null?void 0:c.id]),a.useEffect(()=>{c&&Ge(U.current)},[c==null?void 0:c.id]),a.useEffect(()=>{let t=!0;const p=_.current;if(!c||h!=="authorized"){$.current=null,N([]),L([]);return}return $.current!==c.id&&($.current=c.id,N([]),L([])),M().then(y=>Promise.all([y.from("corrective_action_history").select("*").eq("case_id",c.id).order("version"),y.from("corrective_action_events").select("id,case_id,version,kind,status,attempts,last_error,created_at").eq("case_id",c.id).order("created_at",{ascending:!1})])).then(y=>{if(!(!t||p!==_.current)){if(y.some(Z=>Z.error))throw y.find(Z=>Z.error).error;N(y[0].data||[]),L(y[1].data||[])}}).catch(y=>{t&&p===_.current&&A(y.message)}),()=>{t=!1}},[c==null?void 0:c.id,c==null?void 0:c.version,qe,n.id,h]);async function We(t){if(!F.current){F.current=!0,J(!0),A("");try{await t(),await Oe(),Re()}catch(p){A(p.message||"Corrective action request failed.")}finally{F.current=!1,J(!1)}}}const Ne=t=>{var p;return((p=H.find(y=>y.user_id===t))==null?void 0:p.display_name)||"Former / unavailable staff"};return e.createElement("section",{className:"card case-workspace",ref:Y,tabIndex:-1,"aria-label":"Corrective Actions workspace"},e.createElement("div",{className:"section-title"},e.createElement("div",null,e.createElement("h2",null,"Corrective Actions"),e.createElement("p",null,"Fix confirmed defects. Say who fixes each one, and by when.")),e.createElement("button",{className:"secondary",disabled:S,onClick:()=>We(Oe)},"Refresh cases")),he&&e.createElement("div",{className:"error",role:"alert"},Ue(he)),h==="checking"&&e.createElement("p",{role:"status"},"Checking your access…"),h!=="checking"&&h!=="authorized"&&e.createElement("p",{className:"note"},"Sign in on the Staff workspace page and enter your security code. Then come back here."),h==="authorized"&&e.createElement(e.Fragment,null,e.createElement("div",{className:"case-stats",role:"group","aria-label":"Case summary"},e.createElement("div",null,e.createElement("b",null,ie.open),e.createElement("span",null,"Open")),e.createElement("div",{className:ie.overdue?"late":""},e.createElement("b",null,ie.overdue),e.createElement("span",null,"Overdue")),e.createElement("div",null,e.createElement("b",null,ie.resolved),e.createElement("span",null,"Done")),e.createElement("div",null,e.createElement("b",null,ie.averageResolutionHours===null?"–":ie.averageResolutionHours.toFixed(1)+" h"),e.createElement("span",null,"Average time to fix"))),e.createElement("h3",null,"Create a new case"),e.createElement("ol",{className:"stepper","aria-label":"Steps to create a case"},["Pick an inspection","Save a defect review","Assign the fix"].map((t,p)=>{const y=s?C.ready||C.existingCaseId?3:2:1;return e.createElement("li",{key:t,className:p+1<y?"done":p+1===y?"now":"","aria-current":p+1===y?"step":void 0},e.createElement("b",null,p+1<y?"✓":p+1),t)})),v&&e.createElement("label",{className:"field"},"Team inspection",e.createElement("select",{value:(s==null?void 0:s.id)||"",disabled:S||D,onChange:t=>v(t.target.value)},e.createElement("option",{value:""},"Pick an inspection"),re.map(({row:t,status:p})=>{var y;return e.createElement("option",{key:t.id,value:t.id},at((y=t.payload)==null?void 0:y.category)," · ",new Date(t.created_at).toLocaleString()," · ",t.id.slice(0,8)," — ",p.label)}))),v&&G.length>0&&e.createElement("p",{className:"caption"},pe?`${pe} inspection${pe>1?"s are":" is"} ready, listed first.`:"None are ready yet. A case needs a saved defect review."),v&&!G.length&&e.createElement("p",{className:"note"},"No Team inspections yet. Open a personal inspection and choose “Share with team”."),e.createElement("div",{className:"case-step "+(C.ready?"ready":"blocked")},e.createElement("strong",null,C.ready?"Ready to assign":s?C.existingCaseId?"This inspection already has a case":C.needsReview?"Step 2: save a defect review":"Not available yet":"Step 1: pick an inspection"),e.createElement("p",{id:"case-creation-guidance",role:"status"},C.reason),s&&!s.archived_at&&!D&&e.createElement("button",{type:"button",className:C.needsReview?"primary":"secondary",disabled:S,onClick:()=>z==null?void 0:z(s.id)},C.needsReview?"Open the review":"Open photo and review"),C.existingCaseId&&e.createElement("button",{type:"button",className:"secondary",onClick:()=>f(C.existingCaseId)},"Open existing case")),e.createElement("p",{className:"caption"},"You can fill this in now. Nothing is saved until you press “Create corrective action”."),!H.length&&e.createElement("p",{className:"note"},"No active Staff to assign. Press Refresh cases, or ask the administrator."),e.createElement("form",{className:"login-form","data-tour":"case","aria-label":"Assign corrective action","aria-describedby":"case-creation-guidance case-submit-guidance",onSubmit:t=>{if(t.preventDefault(),!(r||S||F.current))return We(async()=>{const p=await M(),y=await Qe(p,"defectrag_create_corrective_action",{p_inspection:s.id,p_review:C.review.id,p_confirmed:V,p_owner:P,p_supervisor:K,p_priority:b,p_description:me,p_due:new Date(ne).toISOString()});f(y),w(""),le(!1)})}},e.createElement("label",{className:"field"},"What needs fixing?",e.createElement("textarea",{disabled:S,required:!0,minLength:10,maxLength:2e3,value:me,onInput:t=>w(t.target.value),onChange:t=>w(t.target.value)})),e.createElement("label",{className:"field"},"Person responsible",e.createElement("select",{disabled:S,required:!0,value:P,onChange:t=>Ee(t.target.value)},e.createElement("option",{value:""},"Choose a person"),H.map(t=>e.createElement("option",{key:t.user_id,value:t.user_id},t.display_name)))),e.createElement("label",{className:"field"},"Supervisor",e.createElement("select",{disabled:S,required:!0,value:K,onChange:t=>l(t.target.value)},e.createElement("option",{value:""},"Choose a person"),H.map(t=>e.createElement("option",{key:t.user_id,value:t.user_id},t.display_name)))),e.createElement("label",{className:"field"},"Priority",e.createElement("select",{disabled:S,value:b,onChange:t=>W(t.target.value)},["Low","Normal","High","Critical"].map(t=>e.createElement("option",{key:t},t)))),et({legend:"Due date and time",prefix:"Due ",value:ne,time:R,setValue:u,setTime:ye,disabled:S,required:!0}),e.createElement("p",{className:"note"},"When email is switched on, saving a case emails the supervisor and copies the person responsible. See “Email delivery” in the case details."),e.createElement("label",{className:"consent-check"+(C.ready?"":" locked")},e.createElement("input",{type:"checkbox",disabled:S||!C.ready,checked:V,onChange:t=>le(t.target.checked)}),e.createElement("span",null,"I confirm Staff found a real defect that needs fixing.",!C.ready&&e.createElement("small",null,"Finish steps 1 and 2 first."))),e.createElement("p",{className:"note",id:"case-submit-guidance",role:"status"},r?"Not ready: "+r:"All set. Press the button to save."),e.createElement("button",{className:"primary",disabled:S||!!r},"Create corrective action")),e.createElement("div",{className:"section-title section-gap"},e.createElement("h3",null,"Saved cases"),T.length>0&&e.createElement("div",{className:"segmented case-filter",role:"group","aria-label":"Show cases"},te.map(([t,p,y])=>e.createElement("button",{type:"button",key:t,className:x===t?"on":"","aria-pressed":x===t,onClick:()=>ge(t)},p," ",e.createElement("span",{className:"count"},T.filter(y).length))))),e.createElement("div",{className:"table-wrap","data-tour":c?void 0:"case-update"},e.createElement("table",{className:"stackable"},e.createElement("thead",null,e.createElement("tr",null,e.createElement("th",null,"Case"),e.createElement("th",null,"Status"),e.createElement("th",null,"Owner"),e.createElement("th",null,"Priority"),e.createElement("th",null,"Due"),e.createElement("th",null))),e.createElement("tbody",null,be.map(t=>e.createElement("tr",{key:t.id,className:t.id===de?"selected-row":void 0},e.createElement("td",{"data-label":"Case"},t.id.slice(0,8)),e.createElement("td",{"data-label":"Status"},e.createElement("span",{className:"case-state "+t.state.toLowerCase().replace(/\s+/g,"-")},t.state),X(t)&&e.createElement("span",{className:"case-state overdue"},"Overdue")),e.createElement("td",{"data-label":"Owner"},Ne(t.owner_id)),e.createElement("td",{"data-label":"Priority"},e.createElement("span",{className:"priority "+String(t.priority||"").toLowerCase()},t.priority||"Normal")),e.createElement("td",{"data-label":"Due"},ze(t.due_at)),e.createElement("td",{className:"row-action"},e.createElement("button",{className:"text-button","aria-label":"Details for case "+t.id.slice(0,8),onClick:()=>f(t.id)},"Details")))))),T.length?!be.length&&e.createElement("p",{className:"caption"},"No cases in this group. Choose All to see every case."):e.createElement("p",{className:"caption"},"No cases yet.")),c&&e.createElement("div",{className:"cloud-message","data-tour":"case-update",ref:U,tabIndex:-1,"aria-label":"Corrective action case details"},e.createElement("div",{className:"section-title"},e.createElement("h3",null,"Case ",c.id.slice(0,8)," · ",c.state),e.createElement("button",{className:"text-button",onClick:()=>f("")},"Close details")),e.createElement("p",null,c.description),e.createElement("p",null,"Person responsible: ",Ne(c.owner_id)," · Supervisor: ",Ne(c.supervisor_id)," · Due: ",ze(c.due_at)),e.createElement("p",null,"Confirmed by: ",Ne(c.confirmed_by)),e.createElement("button",{className:"secondary",onClick:()=>z(c.inspection_id)},"Open photo and review"),Me(c.state).length>0&&!oe&&e.createElement("p",{className:"note"},"Only the person responsible, the supervisor or a Developer can update this case."),!Me(c.state).length&&e.createElement("p",{className:"note"},"This case is ",c.state.toLowerCase(),". You can read it but not change it."),we&&oe&&e.createElement("p",{className:"note",role:"status"},"Someone changed this case while you were typing. Your text is kept but not saved. Copy it, then load the latest case. ",e.createElement("button",{className:"secondary",disabled:S,onClick:()=>{$e(),A("")}},"Load latest case and replace draft")),Me(c.state).length>0&&oe&&e.createElement("form",{className:"login-form",onSubmit:t=>{t.preventDefault(),We(async()=>{if(we)throw new Error("The case changed. Load the latest case before saving.");const p=await M(),y=await Qe(p,"defectrag_update_corrective_action",{p_id:c.id,p_version:_e,p_state:ee,p_note:xe,p_owner:Ce,p_supervisor:Ie,p_due:ue?new Date(ue).toISOString():null});Te(y),ke(""),ve("")})}},e.createElement("label",{className:"field"},"Case status",e.createElement("select",{disabled:S||we,value:ee,onChange:t=>Se(t.target.value)},Me(c.state).map(t=>e.createElement("option",{key:t},t)))),e.createElement("label",{className:"field"},"Person responsible",e.createElement("select",{disabled:S||we,required:!0,value:Ce,onChange:t=>Ae(t.target.value)},e.createElement("option",{value:""},"Choose a person"),H.map(t=>e.createElement("option",{key:t.user_id,value:t.user_id},t.display_name)))),e.createElement("label",{className:"field"},"Supervisor",e.createElement("select",{disabled:S||we,required:!0,value:Ie,onChange:t=>ce(t.target.value)},e.createElement("option",{value:""},"Choose a person"),H.map(t=>e.createElement("option",{key:t.user_id,value:t.user_id},t.display_name)))),et({legend:"New deadline (optional)",prefix:"New due ",value:ue,time:De,setValue:ve,setTime:Q,disabled:S||we,keep:"The deadline stays: "+lt(jt(c.due_at))+"."}),e.createElement("label",{className:"field"},"What changed or was fixed?",e.createElement("textarea",{disabled:S,required:!0,minLength:3,maxLength:2e3,value:xe,onInput:t=>ke(t.target.value),onChange:t=>ke(t.target.value)})),e.createElement("button",{className:"primary",disabled:S||!ee||we},"Save case update")),e.createElement("h3",null,"Status history"),se.map(t=>e.createElement("p",{key:t.id},e.createElement("strong",null,t.state)," · ",Ne(t.actor_id)," · ",ze(t.created_at),e.createElement("br",null),t.note,t.snapshot&&e.createElement("small",null,e.createElement("br",null),"Owner: ",Ne(t.snapshot.owner_id)," · Supervisor: ",Ne(t.snapshot.supervisor_id)," · Due: ",ze(t.snapshot.due_at)))),e.createElement("h3",null,"Email delivery"),e.createElement("p",{className:"caption"},"Emails go to the supervisor, with a copy to the person responsible. If one fails, tell the administrator. The case stays saved either way."),!q.length&&e.createElement("p",{className:"caption"},"No emails recorded for this case yet."),q.map(t=>e.createElement("p",{key:t.id},rt(t.kind)," · ",st(t.status)," · attempts ",t.attempts,t.last_error?" · "+Ue(t.last_error):"")))))}function Wt({client:n,user:s,onChange:m}){var K;const[i,D]=a.useState(null),[v,z]=a.useState([]),[_,F]=a.useState([]),[g,U]=a.useState(null),[Y,$]=a.useState(""),[h,O]=a.useState(""),[T,j]=a.useState(""),[H,E]=a.useState(""),[de,f]=a.useState(""),[se,N]=a.useState(""),[q,L]=a.useState(!1),[he,A]=a.useState([]),[S,J]=a.useState([]),me=((K=window.DEFECTRAG_PUBLIC_CONFIG)==null?void 0:K.registrationEnabled)===!0;async function w(){if(!s){D(null),A([]),J([]);return}const l=await ft(n);D(l);const{data:b,error:W}=await n.auth.mfa.listFactors();if(W)throw W;const ne=(b.totp||[]).filter(u=>u.status==="verified");if(z(ne),F((b.all||[]).filter(u=>u.factor_type==="totp"&&u.status==="unverified")),O(u=>{var R;return ne.some(ye=>ye.id===u)?u:((R=ne[0])==null?void 0:R.id)||""}),l.role==="developer"&&l.approved&&l.aal2){const[u,R]=await Promise.all([n.rpc("defectrag_access_directory"),n.rpc("defectrag_notification_status")]);if(u.error)throw u.error;if(R.error)throw R.error;A(u.data||[]),J(R.data||[])}else A([]),J([])}async function P(l){L(!0),N("");try{await l()}catch(b){N(b.message||"Security request failed.")}finally{L(!1)}}a.useEffect(()=>{let l=!0;return U(null),$(""),A([]),J([]),n&&s?w().catch(b=>{l&&N(b.message)}):D(null),()=>{l=!1}},[n,s==null?void 0:s.id]);async function Ee(){await gt(n,(g==null?void 0:g.id)||h,Y),$(""),U(null),await w(),m(),N("Security code verified. Staff access is available only after the account is approved.")}return e.createElement("div",{className:"section-gap"},s&&e.createElement("h3",null,"Sign-in and account security"),se&&e.createElement("p",{className:"note",role:"status"},Ue(se)),s?e.createElement(e.Fragment,null,e.createElement("p",null,"Access: ",e.createElement("strong",null,i!=null&&i.revoked?"revoked":i!=null&&i.approved?"approved":(i==null?void 0:i.request_status)||"not requested")," · Authenticator: ",e.createElement("strong",null,i!=null&&i.aal2?"security code verified":"enter security code")),e.createElement("button",{className:"secondary",disabled:q,onClick:()=>P(w)},"Refresh account status"),i&&!i.approved&&!i.revoked&&!i.request_status&&e.createElement("form",{className:"login-form",onSubmit:l=>{l.preventDefault(),P(async()=>{await Et(n,T),await w(),N("Request sent. Check back here for Developer approval. Team and private Staff work are not available while the request is waiting."),m()})}},e.createElement("label",{className:"field"},"Display name",e.createElement("input",{value:T,maxLength:80,onChange:l=>j(l.target.value),required:!0})),e.createElement("button",{className:"primary",disabled:q||!i.registration_enabled||!i.email_verified},"Request staff access")),e.createElement("p",{className:"caption"},"Use an authenticator app for the extra six-digit sign-in code. Keep access to that app. If it is lost, contact the workspace administrator; resetting the password does not remove this security check."),!g&&!v.length&&!_.length&&e.createElement("button",{className:"secondary",disabled:q,onClick:()=>P(async()=>U(await yt(n)))},"Set up a security code app"),!g&&_.map(l=>e.createElement("p",{key:l.id,className:"caption"},"Authenticator setup was not finished. ",e.createElement("button",{className:"text-button",disabled:q,onClick:()=>P(async()=>{const{error:b}=await n.auth.mfa.unenroll({factorId:l.id});if(b)throw b;await w()})},"Cancel incomplete setup"))),g&&e.createElement("div",{className:"note"},e.createElement("div",null,e.createElement("p",null,"Open an authenticator app, scan this private QR code, then enter the six-digit code below to finish. Do not share the QR code or security codes."),e.createElement("img",{src:g.totp.qr_code,width:"200",height:"200",alt:"Private authenticator enrollment QR code"}),e.createElement("button",{className:"text-button",disabled:q,onClick:()=>P(async()=>{const{error:l}=await n.auth.mfa.unenroll({factorId:g.id});if(l)throw l;U(null),$("")})},"Cancel incomplete setup"))),!g&&v.length>0&&(i==null?void 0:i.aal2)&&e.createElement("p",{className:"caption"},"The security code is verified for this sign-in."),(g||v.length>0&&!(i!=null&&i.aal2))&&e.createElement("form",{className:"login-form",onSubmit:l=>{l.preventDefault(),P(Ee)}},!g&&e.createElement("label",{className:"field"},"Security code app",e.createElement("select",{value:h,onChange:l=>O(l.target.value)},v.map(l=>e.createElement("option",{key:l.id,value:l.id},l.friendly_name||"Authenticator")))),e.createElement("label",{className:"field"},"Six-digit security code",e.createElement("input",{inputMode:"numeric",autoComplete:"one-time-code",pattern:"[0-9]{6}",maxLength:6,value:Y,onChange:l=>$(l.target.value),required:!0})),e.createElement("button",{className:"primary",disabled:q},"Verify security code")),(i==null?void 0:i.role)==="developer"&&i.approved&&i.aal2&&e.createElement(e.Fragment,null,e.createElement("h3",{className:"section-gap"},"Staff access management"),e.createElement("p",null,"Approve or reject requests that are still waiting. Removing access stops new Staff actions but keeps inspection history."),e.createElement("div",{className:"table-wrap"},e.createElement("table",null,e.createElement("thead",null,e.createElement("tr",null,e.createElement("th",null,"Account"),e.createElement("th",null,"Status"),e.createElement("th",null,"Role"),e.createElement("th",null,"Action"))),e.createElement("tbody",null,he.map(l=>e.createElement("tr",{key:l.user_id},e.createElement("td",null,l.display_name,e.createElement("br",null),e.createElement("small",null,l.email)),e.createElement("td",null,l.status),e.createElement("td",null,l.role||"applicant"),e.createElement("td",null,l.user_id!==s.id&&(l.status==="pending"?["approve","reject"]:l.status==="approved"?["revoke"]:[]).map(b=>e.createElement("button",{key:b,className:"text-button",disabled:q,onClick:()=>{window.confirm(`${b[0].toUpperCase()+b.slice(1)} access for ${l.display_name}?`)&&P(async()=>{await vt(n,l,b),await w(),m(),N("Account access updated. Check Email delivery below separately; saving this change does not confirm an email was sent.")})}},{approve:"Approve",reject:"Reject",revoke:"Remove access"}[b])))))))),e.createElement("h3",{className:"section-gap"},"Email delivery"),e.createElement("p",{className:"caption"},"Waiting emails have not been sent. Delivery depends on administrator settings and the email service being available. Sent means the email service accepted the message; it may still reach Spam or fail to arrive."),e.createElement("div",{className:"table-wrap"},e.createElement("table",null,e.createElement("thead",null,e.createElement("tr",null,e.createElement("th",null,"Event"),e.createElement("th",null,"Delivery"),e.createElement("th",null,"Attempts"),e.createElement("th",null))),e.createElement("tbody",null,S.map(l=>e.createElement("tr",{key:l.id},e.createElement("td",null,rt(l.kind)),e.createElement("td",null,st(l.status)),e.createElement("td",null,l.attempts),e.createElement("td",null,l.status==="dead"&&e.createElement("button",{className:"text-button",disabled:q,onClick:()=>P(async()=>{const{error:b}=await n.rpc("defectrag_retry_notification",{p_id:l.id});if(b)throw b;await w()})},"Retry delivery"))))))))):me?e.createElement("details",{className:"register-panel"},e.createElement("summary",null,"New to Staff work? Create an account"),e.createElement("form",{className:"login-form",onSubmit:l=>{l.preventDefault(),P(async()=>{await ht(n,{email:H,password:de,displayName:T,redirectTo:location.origin+location.pathname}),f(""),N("Check the inbox and Spam folder for a confirmation email. Open its link, sign in, then choose Request staff access. A Developer must approve the request before Staff work is available.")})}},e.createElement("p",null,"New to Staff work? Create an account, confirm the email, then request access. The public demo can be used without an account."),e.createElement("label",{className:"field"},"Display name",e.createElement("input",{value:T,onChange:l=>j(l.target.value),maxLength:80,autoComplete:"name",required:!0})),e.createElement("label",{className:"field"},"Email",e.createElement("input",{type:"email",value:H,onChange:l=>E(l.target.value),autoComplete:"email",required:!0})),e.createElement("label",{className:"field"},"New password",e.createElement("input",{type:"password",minLength:12,value:de,onChange:l=>f(l.target.value),autoComplete:"new-password",required:!0})),e.createElement("button",{className:"secondary",disabled:q||!n},"Register account"))):e.createElement("p",{className:"caption"},"New account registration is currently closed. Existing Staff can sign in below. The public demo is still available."))}function Gt({onOpenInspection:n,onOpenCorrectiveActions:s,onChooseInspection:m,casesView:i=!1,initialInspectionId:D=null}){var Fe;const v=a.useRef(0),z=a.useRef(null),_=a.useRef(0),F=a.useRef(null),g=a.useRef(0),U=a.useRef(null),Y=a.useRef(null),[$,h]=a.useState(0),[O,T]=a.useState(!1),[j,H]=a.useState({state:"refreshing"}),[E,de]=a.useState(null),[f,se]=a.useState(null),[N,q]=a.useState([]),[L,he]=a.useState({}),[A,S]=a.useState(""),[J,me]=a.useState(""),[w,P]=a.useState(!1),[Ee,K]=a.useState(""),[l,b]=a.useState(""),[W,ne]=a.useState(!1),[u,R]=a.useState(null),[ye,V]=a.useState([]),[le,ee]=a.useState([]),[Se,xe]=a.useState(""),[ke,_e]=a.useState(!1),[Te,qe]=a.useState(""),[He,Ce]=a.useState(!1),[Ae,Ie]=a.useState(null),ce=bt(),ue=wt(window.DEFECTRAG_PUBLIC_CONFIG);a.useEffect(()=>()=>{ye.filter(r=>r.startsWith("blob:")).forEach(r=>URL.revokeObjectURL(r))},[ye]),a.useEffect(()=>{F.current=u},[u]),a.useEffect(()=>{u&&Ge(U.current)},[$]),a.useEffect(()=>{if(!E||!f||!D)return;const r=E.id+":"+D;Y.current!==r&&(Y.current=r,B({id:D},{focus:!i}))},[E==null?void 0:E.id,f==null?void 0:f.user_id,D]);const ve=Nt(),De=ce&&Ae&&(!i||!f)?e.createElement(Wt,{key:(E==null?void 0:E.id)||"anonymous",client:Ae,user:E,onChange:()=>{Re(),E&&Q(c)}}):null;async function Q(r){P(!0),K(""),b("");try{await r()}catch(d){K(d.message||"Team request failed.")}finally{P(!1)}}async function c(){var I;const r=++_.current,d=v.current,o=(I=F.current)==null?void 0:I.id,{client:x,staff:ge}=await xt();let k=x.from("shared_inspections").select("*").order("created_at",{ascending:!1}).limit(200);k=W?k.not("archived_at","is",null):k.is("archived_at",null);const[{data:X,error:te},{data:be,error:G},ae]=await Promise.all([k,x.from("staff_members").select("*"),o?x.from("staff_notes").select("*").eq("inspection_id",o).order("created_at"):{data:[]}]);if(te)throw te;if(G)throw G;if(ae.error)throw ae.error;if(r===_.current&&(se(ge),K(""),q(X||[]),he(Object.fromEntries((be||[]).map(re=>[re.user_id,re.display_name]))),o&&d===v.current)){const re=(X||[]).find(pe=>pe.id===o);if(!re)v.current++,R(null),V([]),ee([]);else if(R(re),ee(ae.data||[]),!ce&&Date.now()-g.current>480*1e3){const pe=await Promise.all([re.image_path,re.heatmap_path].map(oe=>x.storage.from("team-inspections").createSignedUrl(oe,900)));if(r===_.current&&d===v.current){if(pe.some(oe=>oe.error))throw new Error("Shared image links could not refresh.");V(pe.map(oe=>oe.data.signedUrl)),g.current=Date.now()}}}}a.useEffect(()=>{if(!ve)return;let r=!1,d;return M().then(async o=>{!r&&ce&&Ie(o),d=o.auth.onAuthStateChange((ge,k)=>{var X;if(!r){const te=((X=k==null?void 0:k.user)==null?void 0:X.id)||null;z.current!==te&&(v.current++,_.current++,R(null),q([]),V([]),ee([]),se(null),z.current=te),de((k==null?void 0:k.user)||null),ge==="PASSWORD_RECOVERY"&&_e(!0)}}).data.subscription;const{data:x}=await o.auth.getUser();r||de(x.user)}).catch(o=>{r||K(o.message)}),()=>{r=!0,v.current++,d==null||d.unsubscribe()}},[ve]),a.useEffect(()=>{if(!E)return;const r=tt(c,{onState:d=>{H(d),d.error&&(K(d.error),ce&&(v.current++,q([]),he({}),R(null),V([]),ee([]),se(null)))}});return()=>{r.stop(),_.current++}},[E==null?void 0:E.id,W]);async function B(r,{focus:d=!0}={}){const o=++v.current;T(!0);try{await Q(async()=>{if(o!==v.current)return;const x=await M(),ge=x.storage.from("team-inspections"),[{data:k,error:X},{data:te,error:be}]=await Promise.all([x.from("shared_inspections").select("*").eq("id",r.id).single(),x.from("staff_notes").select("*").eq("inspection_id",r.id).order("created_at")]);if(o!==v.current)return;if(X)throw X;if(be)throw be;const G=ce?await St(x,k):null,ae=G?G.map(I=>({data:{signedUrl:I}})):await Promise.all([k.image_path,k.heatmap_path].map(I=>ge.createSignedUrl(I,900)));if(ae.some(I=>I.error))throw new Error("Private images could not be loaded. Check staff/storage policies.");if(o!==v.current){G==null||G.forEach(I=>URL.revokeObjectURL(I));return}F.current=k,g.current=Date.now(),R(k),V(ae.map(I=>I.data.signedUrl)),ee(te||[]),d&&h(I=>I+1)})}finally{o===v.current&&T(!1)}}function ie(){v.current++,F.current=null,T(!1),R(null),V([]),ee([])}async function C(){await Q(async()=>{const r=await M(),d=N.filter(o=>o.owner_id===E.id).map(o=>o.id);if(d.length){const{error:o}=await r.rpc("archive_team_inspections",{p_ids:d});if(o)throw o}v.current++,R(null),Ce(!1),await c(),Re()})}return ve?e.createElement(e.Fragment,null,e.createElement("section",{className:"card"},e.createElement("div",{className:"section-title"},e.createElement("div",null,e.createElement("h2",null,e.createElement(Ft,{size:21})," ",i?"Corrective Actions access":"Staff workspace"),e.createElement("p",null,f?"Inspections your team has shared. New inspections stay private until you share them.":"Sign in to review inspections your team has shared.")),e.createElement("span",{className:"subtle-tag"},e.createElement(Be,{size:13})," STAFF ACCESS")),Ee&&e.createElement("div",{className:"error",role:"alert"},Ue(Ee)),l&&e.createElement("div",{className:"success",role:"status"},e.createElement("span",null,l)),O&&e.createElement("p",{role:"status"},"Opening the shared photo and review…"),i&&!ue&&e.createElement("p",{className:"note"},"Corrective Actions has been turned off for this app. Inspections and reviews are still available. Contact the workspace administrator if needed."),E&&!f&&De,E?e.createElement(e.Fragment,null,e.createElement("div",{className:"team-toolbar"},e.createElement("div",null,e.createElement(_t,{size:18}),e.createElement("strong",null,(f==null?void 0:f.display_name)||E.email),e.createElement("span",{className:"subtle-tag"},(f==null?void 0:f.role)||"CHECKING ACCESS")),e.createElement("button",{className:"secondary",disabled:w,onClick:()=>Q(c)},e.createElement(Pt,{size:16})," Refresh"),!i&&f&&ue&&e.createElement("button",{className:"secondary",onClick:()=>s==null?void 0:s()},"Open Corrective Actions"),i&&f&&e.createElement("button",{className:"secondary",onClick:()=>m==null?void 0:m()},"Choose a Team inspection"),e.createElement("button",{className:"secondary",onClick:()=>Q(async()=>{await(await M()).auth.signOut(),q([]),R(null),se(null)})},e.createElement(Lt,{size:16})," Sign out")),ke&&e.createElement("form",{className:"login-form",onSubmit:r=>{r.preventDefault(),Q(async()=>{const d=await M(),{error:o}=await d.auth.updateUser({password:Te});if(o)throw o;qe(""),_e(!1)})}},e.createElement("label",{className:"field"},"Set a new password",e.createElement("input",{type:"password",minLength:12,autoComplete:"new-password",value:Te,onChange:r=>qe(r.target.value),required:!0})),e.createElement("button",{className:"primary",disabled:w},"Save password")),!i&&e.createElement(e.Fragment,null,e.createElement("div",{className:"team-toolbar"},e.createElement("span",{role:"status"},N.length," shared inspections · ",j.state==="synced"?"updated "+new Date(j.at).toLocaleTimeString([],{hour:"numeric",minute:"2-digit"}):j.state==="offline"?"offline; shown results may be out of date":j.state==="stale"?"update failed; shown results may be out of date":"refreshing…"),(f==null?void 0:f.role)==="developer"&&e.createElement("button",{className:"secondary",onClick:()=>{ne(!W),R(null)}},e.createElement(Tt,{size:16}),W?"Active history":"Restore archived team work"),!W&&e.createElement("button",{className:"secondary danger",disabled:w||!N.some(r=>r.owner_id===E.id),onClick:()=>Ce(!0)},e.createElement(Ct,{size:16})," Archive my shared inspections")),He&&e.createElement("div",{className:"note"},e.createElement("div",null,e.createElement("strong",null,"Archive your visible records?"),e.createElement("p",null,"They will leave the shared active history. Original files and conversations remain recoverable by a developer. Other staff members’ records will stay active."),e.createElement("div",{className:"button-row"},e.createElement("button",{className:"primary",disabled:w,onClick:C},"Archive my records"),e.createElement("button",{className:"secondary",onClick:()=>Ce(!1)},"Cancel")))),e.createElement("div",{className:"table-wrap"},e.createElement("table",{className:"stackable"},e.createElement("thead",null,e.createElement("tr",null,e.createElement("th",null,"Inspection"),e.createElement("th",null,"Product"),e.createElement("th",null,"Result"),e.createElement("th",null,"Shared by"),e.createElement("th",null,"Saved"),e.createElement("th",null))),e.createElement("tbody",null,N.map(r=>{var d;return e.createElement("tr",{key:r.id},e.createElement("td",{"data-label":"Inspection"},e.createElement("strong",null,r.id.slice(0,8))),e.createElement("td",{"data-label":"Product"},at(r.payload.category)),e.createElement("td",{"data-label":"Result"},e.createElement("span",{className:"badge "+((d=r.payload.verdict)==null?void 0:d.toLowerCase())},Xe(r.payload.verdict))),e.createElement("td",{"data-label":"Shared by"},L[r.owner_id]||"Staff member"),e.createElement("td",{"data-label":"Saved"},new Date(r.created_at).toLocaleString()),e.createElement("td",{className:"row-action"},e.createElement("button",{className:"text-button",disabled:w,onClick:()=>B(r)},"Review"),W&&(f==null?void 0:f.role)==="developer"&&e.createElement("button",{className:"text-button",disabled:w,onClick:()=>Q(async()=>{const o=await M(),{error:x}=await o.rpc("restore_team_inspections",{p_ids:[r.id]});if(x)throw x;await c(),Re()})},"Restore")))}))),!N.length&&e.createElement("div",{className:"empty"},e.createElement(Be,{size:30}),e.createElement("p",null,W?"No archived records to recover.":"No shared inspections yet. Open an inspection result and select Share with team."))))):e.createElement(e.Fragment,null,e.createElement("h3",{className:"section-gap"},"Sign in"),e.createElement("form",{className:"login-form",onSubmit:r=>{r.preventDefault(),Q(async()=>{const d=await M(),{error:o}=await d.auth.signInWithPassword({email:A,password:J});if(o)throw o;me("")})}},e.createElement("label",{className:"field"},"Work email",e.createElement("input",{type:"email",autoComplete:"username",value:A,onChange:r=>S(r.target.value),required:!0})),e.createElement("label",{className:"field"},"Password",e.createElement("input",{type:"password",autoComplete:"current-password",value:J,onChange:r=>me(r.target.value),required:!0})),e.createElement("button",{className:"primary",disabled:w},w?e.createElement(kt,{className:"spin",size:17}):e.createElement(At,{size:17})," Sign in"),e.createElement("button",{type:"button",className:"text-button",disabled:!A||w,onClick:()=>Q(async()=>{const r=await M(),{error:d}=await r.auth.resetPasswordForEmail(A,{redirectTo:location.origin+location.pathname});if(d)throw d;b("Password reset email requested. Check the inbox and the Spam folder.")})},"Reset password"),e.createElement("p",{className:"caption"},ce?"A new account needs Developer approval before Staff work is available. Approved Staff must also enter their security code when asked.":"The workspace administrator must approve an account before it can access Staff work.")),De),E&&f&&De&&e.createElement("details",{className:"account-panel section-gap"},e.createElement("summary",null,"Account & security"),De)),i&&E&&f&&ue&&e.createElement(Ht,{key:E.id,user:E,inspection:u,notes:le,inspections:N,inspectionLoading:O,onSelectInspection:r=>r?B({id:r},{focus:!1}):ie(),onEvidence:r=>B({id:r})}),E&&u&&e.createElement("section",{className:"card",ref:U,tabIndex:-1,"aria-labelledby":"shared-inspection-title"},e.createElement("div",{className:"section-title"},e.createElement("div",null,e.createElement("h2",{id:"shared-inspection-title"},"Shared inspection · ",u.id.slice(0,8)),e.createElement("p",null,"Shared by ",L[u.owner_id]||"a colleague",". These are saved results. Nothing is checked again.")),e.createElement("div",{className:"button-row"},n&&!u.archived_at&&e.createElement("button",{className:"secondary",onClick:()=>n(u)},"Open full result and assistant"),!i&&ue&&!u.archived_at&&e.createElement("button",{className:"secondary",onClick:()=>s==null?void 0:s(u)},"Create or view corrective actions"),e.createElement("button",{className:"text-button",onClick:ie},"Close"))),e.createElement("div",{className:"shared-images"},ye.map((r,d)=>e.createElement("img",{key:r,src:r,alt:d?"Saved highlighted areas":"Saved inspected product"}))),e.createElement("div",{className:"observation"},e.createElement("strong",null,"SAVED RESULT"),e.createElement("span",null,Xe(u.payload.verdict)," · score ",Number(u.payload.score).toFixed(5)," · review limit ",Number(u.payload.threshold).toFixed(5))),e.createElement("h3",{className:"section-gap"},"Saved assistant conversation"),(Fe=u.conversation)!=null&&Fe.length?u.conversation.map((r,d)=>e.createElement("p",{className:"cloud-message",key:d},e.createElement("strong",null,r.role==="user"?"Inspector":"Evidence Assistant",": "),r.question||r.answer)):e.createElement("p",{className:"caption"},"No assistant conversation was shared with this inspection."),!u.archived_at&&e.createElement(Dt,{key:u.id+String(le.length),current:le.map(r=>Ze(r,L)).filter(Boolean).at(-1),disabled:w,onSave:async r=>{const d=await M(),{error:o}=await d.from("staff_notes").insert({inspection_id:u.id,author_id:E.id,body:Rt(r.status,r.decision,r.note)});if(o)throw o;await B(u,{focus:!i}),Re()}}),e.createElement("h3",{className:"section-gap"},"Team notes"),le.filter(r=>!Ze(r,L)).map(r=>e.createElement("div",{className:"cloud-message",key:r.id},e.createElement("strong",null,L[r.author_id]||"Staff member"),e.createElement("p",null,r.body),e.createElement("small",null,new Date(r.created_at).toLocaleString()))),!u.archived_at&&e.createElement("form",{className:"question-form",onSubmit:r=>{r.preventDefault(),Q(async()=>{const d=await M(),{error:o}=await d.from("staff_notes").insert({inspection_id:u.id,author_id:E.id,body:Se.trim()});if(o)throw o;xe(""),await B(u),Re()})}},e.createElement("input",{"aria-label":"Staff review note",maxLength:2e3,placeholder:"Add a note for the team…",value:Se,onChange:r=>xe(r.target.value)}),e.createElement("button",{className:"primary",disabled:w||!Se.trim()},e.createElement(It,{size:16})," Add note")))):e.createElement("section",{className:"card cloud-setup"},e.createElement("div",{className:"setup-icon"},e.createElement(Be,{size:32})),e.createElement("span",{className:"eyebrow"},"TEAM WORKSPACE"),e.createElement("h2",null,"Team workspace is not available yet."),e.createElement("p",null,"The workspace administrator needs to connect shared storage before Staff can sign in here."),e.createElement("div",{className:"setup-grid"},[["01","Connect shared storage","The workspace administrator completes this setup."],["02","Set up staff access","The administrator sets up approval and account security."],["03","Connect this dashboard","The administrator connects the app, then Staff can sign in."]].map(([r,d,o])=>e.createElement("div",{key:r},e.createElement("b",null,r),e.createElement("h3",null,d),e.createElement("p",null,o)))),e.createElement("a",{className:"primary",href:"https://supabase.com/dashboard",target:"_blank",rel:"noreferrer"},"Administrator setup ",e.createElement(qt,{size:16})),e.createElement("p",{className:"caption"},"Contact the workspace administrator for help. The public demo can be used without Staff access."))}export{Gt as default};