1import{v as ie,r as B,j as e,L as ce,B as R,T as oe,C as xe}from"./index-qUK8Hdpx.js";import{u as q}from"./useQuery-CPigJIO8.js";import{A as D,c as me}from"./app-layout-3v6Gn9Sa.js";import{C as d,a as i,b as h,c as p}from"./card-BiWwXSqu.js";import{B as u}from"./badge-BIIZzDl8.js";import{T as ue,a as he,b as f,c as N}from"./tabs-CfFInmvj.js";import{P as pe}from"./progress-C3UeGtO9.js";import{R as je}from"./refresh-cw-goksMloN.js";import{A as fe}from"./arrow-left-eiwfggE3.js";import{D as M}from"./download-DVcrlv_q.js";import{C as Ne,M as S,a as I}from"./message-square-Z_3Z7reJ.js";import{S as ge}from"./shield-BiG9WfHj.js";import{F as we}from"./folder-open-BWVFqCYd.js";import{F as G}from"./file-text-BTYIWt8s.js";import{C as J}from"./select-DBovPMB7.js";import{C as K}from"./chevron-down-BwA7OcuG.js";import{C as be}from"./circle-x-CfH_Ja2U.js";import"./check-MYrTRj9c.js";import"./logo_new-Dyl6rEJX.js";import"./users-xw4djSrm.js";function v(n){switch(n){case"PASS":return"default";case"PARTIAL":return"secondary";case"FAIL":return"destructive";default:return"outline"}}function y(n){switch(n){case"PASS":return"bg-green-500/10 text-green-500 border-green-500/20";case"PARTIAL":return"bg-yellow-500/10 text-yellow-500 border-yellow-500/20";case"FAIL":return"bg-red-500/10 text-red-500 border-red-500/20";default:return"bg-gray-500/10 text-gray-400 border-gray-500/20"}}function ve({result:n}){switch(n){case"PASS":return e.jsx(xe,{className:"h-4 w-4 text-green-500"});case"PARTIAL":return e.jsx(oe,{className:"h-4 w-4 text-yellow-500"});case"FAIL":return e.jsx(be,{className:"h-4 w-4 text-red-500"});default:return e.jsx(I,{className:"h-4 w-4 text-gray-400"})}}function Je(){const{auditRunId:n}=ie(),[W,z]=B.useState(new Set),[Q,V]=B.useState(new Set(["5","6","7","8"])),{data:g,isLoading:H}=q({queryKey:[`/api/audit-runs/${n}/stage2-report`],queryFn:async()=>{const s=await fetch(`/api/audit-runs/${n}/stage2-report`,{credentials:"include"});if(!s.ok)throw new Error("Failed to fetch stage2 report");return s.json()},enabled:!!n}),{data:A}=q({queryKey:[`/api/audit-runs/${n}/audit-plan`],queryFn:async()=>{const s=await fetch(`/api/audit-runs/${n}/audit-plan`,{credentials:"include"});if(!s.ok)throw new Error("Failed to fetch audit plan");return s.json()},enabled:!!n}),{data:X}=q({queryKey:[`/api/audits/${A?.auditId}`],queryFn:async()=>{const s=await fetch(`/api/audits/${A?.auditId}`,{credentials:"include"});if(!s.ok)throw new Error("Failed to fetch audit");return s.json()},enabled:!!A?.auditId}),F=X?.framework==="SOC2",o=g?.assessments??[],w=g?.bundles??[],Y=g?.samples??[],Z=g?.followUps??[],L=g?.evidenceIndex??[],P=o.filter(s=>s.result==="PASS").length,U=o.filter(s=>s.result==="PARTIAL").length,k=o.filter(s=>s.result==="FAIL").length,c=o.length,_=c>0?Math.round(P/c*100):0,ee=c>0?Math.round(U/c*100):0,se=c>0?Math.round(k/c*100):0,T=c>0?Math.round(o.reduce((s,t)=>t.result==="PASS"?s+100:t.result==="PARTIAL"?s+50:s,0)/c):0,E=o.filter(s=>!s.reqId.startsWith("A.")),$=o.filter(s=>s.reqId.startsWith("A.")),te=$.reduce((s,t)=>{const a=t.reqId.match(/^A\.(\d+)/),r=a?a[1]:"other";return s[r]||(s[r]=[]),s[r].push(t),s},{}),m=[];o.forEach(s=>{(s.followUps??[]).forEach(t=>m.push({reqId:s.reqId,followUp:t}))}
1),w.forEach(s=>{(s.followUps??[]).forEach(t=>m.push({reqId:s.title,followUp:t}))}),Z.forEach(s=>m.push({reqId:"General",followUp:s}));const ae=s=>{z(t=>{const a=new Set(t);return a.has(s)?a.delete(s):a.add(s),a})},le=s=>{V(t=>{const a=new Set(t);return a.has(s)?a.delete(s):a.add(s),a})},re=async()=>{try{const s=await fetch(`/api/audit-runs/${n}/stage2-report`,{credentials:"include"});if(!s.ok)throw new Error("Failed to fetch report");const t=await s.json(),a=new Blob([JSON.stringify(t,null,2)],{type:"application/json"}),r=URL.createObjectURL(a),x=document.createElement("a");x.href=r,x.download=`stage2-report-${n}.json`,document.body.appendChild(x),x.click(),document.body.removeChild(x),URL.revokeObjectURL(r)}catch(s){console.error("Download failed:",s)}},ne=()=>{const s=new Blob([JSON.stringify(m,null,2)],{type:"application/json"}),t=URL.createObjectURL(s),a=document.createElement("a");a.href=t,a.download=`stage2-followups-${n}.json`,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(t)};if(H)return e.jsx(D,{children:e.jsx("div",{className:"flex items-center justify-center min-h-[50vh]",children:e.jsx(je,{className:"h-8 w-8 animate-spin text-muted-foreground"})})});const C=s=>{const t=W.has(s.reqId);return e.jsxs("div",{className:"border rounded-lg","data-testid":`assessment-row-${s.reqId}`,children:[e.jsxs("button",{className:"w-full flex items-center justify-between p-4 text-left hover:bg-muted/50 transition-colors",onClick:()=>ae(s.reqId),"data-testid":`toggle-assessment-${s.reqId}`,children:[e.jsxs("div",{className:"flex items-center gap-3 flex-1 min-w-0",children:[e.jsx(ve,{result:s.result}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("span",{className:"font-medium text-sm",children:s.reqId}),s.title&&e.jsx("span",{className:"text-muted-foreground text-sm ml-2",children:s.title})]})]}),e.jsxs("div",{className:"flex items-center gap-3 shrink-0",children:[e.jsx(u,{variant:v(s.result),className:y(s.result),"data-testid":`badge-result-${s.reqId}`,children:s.result}),(s.designResult||s.operatingResult)&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:[s.designResult??"â"," | ",s.operatingResult??"â"]}),t?e.jsx(J,{className:"h-4 w-4"}):e.jsx(K,{className:"h-4 w-4"})]})]}),t&&e.jsxs("div",{className:"px-4 pb-4 space-y-3 border-t pt-3",children:[s.rationale&&e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground mb-1",children:"Rationale"}),e.jsx("p",{className:"text-sm",children:s.rationale})]}),s.citations&&s.citations.length>0&&e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground mb-1",children:"Citations"}),e.jsx("ul",{className:"text-sm list-disc list-inside space-y-1",children:s.citations.map((a,r)=>e.jsx("li",{children:a},r))})]}),s.gaps&&s.gaps.length>0&&e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground mb-1",children:"Gaps"}),e.jsx("ul",{className:"text-sm list-disc list-inside space-y-1",children:s.gaps.map((a,r)=>e.jsx("li",{className:"text-red-500",children:a},r))})]}),s.correctiveActions&&s.correctiveActions.length>0&&e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground mb-1",children:"Corrective Actions"}),e.jsx("ul",{className:"text-sm list-disc list-inside space-y-1",children:s.correctiveActions.map((a,r)=>e.jsx("li",{children:a},r))})]}),s.followUps&&s.followUps.length>0&&e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground mb-1",children:"Follow-ups"}),e.jsx("ul",{className:"text-sm list-disc list-inside space-y-1",children:s.followUps.map((a,r)=>e.jsx("li",{className:"text-blue-500",children:a},r))})]})]})]},s.reqId)};return e.jsx(D,{children:e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(ce,{href:"/command-center",children:e.jsx(R,{variant:"ghost",size:"icon","data-testid":"btn-back",children:e.jsx(fe,{className:"h-5 w-5"})})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold","data-testid":"text-page-title",children:F?"Type II Audit Results":"Stage 2 Audit Results"}),e.jsxs("p",{className:"text-sm text-muted-foreground","data-testid":"text-run-id",children:["Run ID: ",n]})]})]}),e.jsxs(R,{onClick:re,"data-testid":"btn-download-report",children:[e.jsx(M,{className:"h-4 w-4 mr-2"}),"Download Report"]})]}),e.jsxs(ue,{defaultValue:"overview",className:"space-y-4",children:[e.jsxs(he,{className:"grid w-full grid-cols-6","data-testid":"tabs-list",children:[e.jsxs(f,{value:"overview","data-testid":"tab-overview",children:[e.jsx(Ne,{className:"h-4 w-4 mr-1.5"}),"Overview"]}),e.jsxs(f,{value:"clauses","data-testid":"tab-clauses",children:[e.jsx(ge,{className:"h-4 w-4 mr-1.5"}),"Clauses 4-10"]}),e.jsxs(f,{value:"annex","data-testid":"tab-annex",children:[e.jsx(me,{className:"h-4 w-4 mr-1.5"}),"Annex A Controls"]}
1),e.jsxs(f,{value:"bundles","data-testid":"tab-bundles",children:[e.jsx(we,{className:"h-4 w-4 mr-1.5"}),"Bundles"]}),e.jsxs(f,{value:"followups","data-testid":"tab-followups",children:[e.jsx(S,{className:"h-4 w-4 mr-1.5"}),"Follow-ups"]}),e.jsxs(f,{value:"evidence","data-testid":"tab-evidence",children:[e.jsx(G,{className:"h-4 w-4 mr-1.5"}),"Evidence Index"]})]}),e.jsx(N,{value:"overview",className:"space-y-6",children:c===0?e.jsx(d,{children:e.jsxs(i,{className:"py-12 text-center",children:[e.jsx(I,{className:"h-12 w-12 mx-auto mb-4 text-muted-foreground"}),e.jsx("p",{className:"text-lg font-medium","data-testid":"text-no-results",children:"No results yet"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:F?"Type II audit has not produced any assessments.":"Stage 2 audit has not produced any assessments."})]})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-4 gap-4",children:[e.jsxs(d,{"data-testid":"card-total-assessed",children:[e.jsx(h,{className:"pb-2",children:e.jsx(p,{className:"text-sm font-medium text-muted-foreground",children:"Total Requirements"})}),e.jsx(i,{children:e.jsx("p",{className:"text-3xl font-bold","data-testid":"text-total-count",children:c})})]}),e.jsxs(d,{"data-testid":"card-pass-rate",children:[e.jsx(h,{className:"pb-2",children:e.jsx(p,{className:"text-sm font-medium text-green-500",children:"Pass Rate"})}),e.jsxs(i,{children:[e.jsxs("p",{className:"text-3xl font-bold text-green-500","data-testid":"text-pass-rate",children:[_,"%"]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[P," of ",c]})]})]}),e.jsxs(d,{"data-testid":"card-partial-rate",children:[e.jsx(h,{className:"pb-2",children:e.jsx(p,{className:"text-sm font-medium text-yellow-500",children:"Partial Rate"})}),e.jsxs(i,{children:[e.jsxs("p",{className:"text-3xl font-bold text-yellow-500","data-testid":"text-partial-rate",children:[ee,"%"]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[U," of ",c]})]})]}),e.jsxs(d,{"data-testid":"card-fail-rate",children:[e.jsx(h,{className:"pb-2",children:e.jsx(p,{className:"text-sm font-medium text-red-500",children:"Fail Rate"})}),e.jsxs(i,{children:[e.jsxs("p",{className:"text-3xl font-bold text-red-500","data-testid":"text-fail-rate",children:[se,"%"]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[k," of ",c]})]})]})]}),e.jsxs(d,{"data-testid":"card-compliance-score",children:[e.jsx(h,{children:e.jsx(p,{className:"text-sm font-medium",children:"Compliance Score"})}),e.jsxs(i,{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"text-2xl font-bold","data-testid":"text-compliance-score",children:[T,"%"]}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"Weighted average (Pass=100, Partial=50, Fail=0)"})]}),e.jsx(pe,{value:T,className:"h-3"})]})]}),w.length>0&&e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold mb-3",children:"Bundle Status"}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4",children:w.map((s,t)=>e.jsxs(d,{"data-testid":`card-bundle-${t}`,children:[e.jsx(h,{className:"pb-2",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(p,{className:"text-sm font-medium truncate",children:s.title}),e.jsx(u,{variant:v(s.status),className:y(s.status),children:s.status})]})}),e.jsx(i,{children:e.jsxs("div",{className:"text-xs text-muted-foreground space-y-1",children:[e.jsxs("p",{children:["Design: ",s.designStatus??"â"," | Operating: ",s.operatingStatus??"â"]}),e.jsxs("p",{children:[(s.reqIds??s.requirements??[]).length," requirements"]})]})})]},t))})]})]})}),e.jsx(N,{value:"clauses",className:"space-y-3",children:E.length===0?e.jsx(d,{children:e.jsxs(i,{className:"py-12 text-center",children:[e.jsx(I,{className:"h-12 w-12 mx-auto mb-4 text-muted-foreground"}),e.jsx("p",{className:"text-lg font-medium","data-testid":"text-no-clauses",children:"No clause assessments"})]})}):E.map(C)}),e.jsx(N,{value:"annex",className:"space-y-4",children:$.length===0?e.jsx(d,{children:e.jsxs(i,{className:"py-12 text-center",children:[e.jsx(I,{className:"h-12 w-12 mx-auto mb-4 text-muted-foreground"}),e.jsx("p",{className:"text-lg font-medium","data-testid":"text-no-annex",children:"No Annex A assessments"})]})}):Object.entries(te).sort(([s],[t])=>Number(s)-Number(t)).map(([s,t])=>{const a=t.filter(l=>l.result==="PASS").length,r=t.filter(l=>l.result==="PARTIAL").length,x=t.filter(l=>l.result==="FAIL").length,j=Q.has(s);return e.jsxs("div",{className:"border rounded-lg","data-testid":`annex-group-${s}`,children:[e.jsxs("button",{className:"w-full flex items-center justify-between p-4 hover:bg-muted/50 transition-colors",onClick:()=>le(s),"data-testid":`toggle-group-${s}`,children:[e.jsxs("span",{className:"font-semibold",children:["A.",s," Controls"]}
1),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("span",{className:"text-xs text-green-500",children:[a," Pass"]}),e.jsxs("span",{className:"text-xs text-yellow-500",children:[r," Partial"]}),e.jsxs("span",{className:"text-xs text-red-500",children:[x," Fail"]}),j?e.jsx(J,{className:"h-4 w-4"}):e.jsx(K,{className:"h-4 w-4"})]})]}),j&&e.jsx("div",{className:"px-4 pb-4 space-y-2",children:t.map(C)})]},s)})}),e.jsx(N,{value:"bundles",className:"space-y-6",children:w.length===0?e.jsx(d,{children:e.jsxs(i,{className:"py-12 text-center",children:[e.jsx(I,{className:"h-12 w-12 mx-auto mb-4 text-muted-foreground"}),e.jsx("p",{className:"text-lg font-medium","data-testid":"text-no-bundles",children:"No bundles"})]})}):w.map((s,t)=>{const a=Y.filter(l=>l.bundleId===s.id||l.bundleTitle===s.title),r=s.requirements??[],x=s.reqIds??r.map(l=>l.reqId),j=o.filter(l=>x.includes(l.reqId));return e.jsxs(d,{"data-testid":`bundle-detail-${t}`,children:[e.jsxs(h,{children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(p,{children:s.title}),e.jsx(u,{variant:v(s.status),className:y(s.status),children:s.status})]}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Design: ",s.designStatus??"â"," | Operating: ",s.operatingStatus??"â"]})]}),e.jsxs(i,{className:"space-y-4",children:[(j.length>0||r.length>0)&&e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium mb-2",children:"Requirements"}),e.jsx("div",{className:"space-y-2",children:j.length>0?j.map(C):r.map((l,b)=>e.jsxs("div",{className:"flex items-center justify-between p-3 border rounded-lg",children:[e.jsx("span",{className:"text-sm",children:l.reqId}),e.jsx(u,{variant:v(l.result),className:y(l.result),children:l.result})]},b))})]}),a.length>0&&e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium mb-2",children:"Samples"}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm","data-testid":`table-samples-${t}`,children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b",children:[e.jsx("th",{className:"text-left p-2 font-medium text-muted-foreground",children:"#"}),e.jsx("th",{className:"text-left p-2 font-medium text-muted-foreground",children:"Attributes"}),e.jsx("th",{className:"text-left p-2 font-medium text-muted-foreground",children:"Result"}),e.jsx("th",{className:"text-left p-2 font-medium text-muted-foreground",children:"Supporting Chunks"})]})}),e.jsx("tbody",{children:a.map((l,b)=>e.jsxs("tr",{className:"border-b last:border-0",children:[e.jsx("td",{className:"p-2",children:l.sampleIndex}),e.jsx("td",{className:"p-2",children:l.attributes?Object.entries(l.attributes).map(([O,de])=>e.jsxs("span",{className:"inline-block mr-2 text-xs bg-muted px-2 py-0.5 rounded",children:[O,": ",de]},O)):"â"}),e.jsx("td",{className:"p-2",children:l.result?e.jsx(u,{variant:v(l.result),className:y(l.result),children:l.result}):"â"}),e.jsx("td",{className:"p-2 text-xs text-muted-foreground",children:l.supportingChunks?.length?l.supportingChunks.join(", "):"â"})]},b))})]})})]}),s.followUps&&s.followUps.length>0&&e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium mb-2",children:"Follow-ups"}),e.jsx("ul",{className:"list-disc list-inside space-y-1 text-sm",children:s.followUps.map((l,b)=>e.jsx("li",{className:"text-blue-500",children:l},b))})]})]})]},t)})}),e.jsxs(N,{value:"followups",className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("h3",{className:"text-lg font-semibold",children:["All Follow-up Requests (",m.length,")"]}),m.length>0&&e.jsxs(R,{variant:"outline",size:"sm",onClick:ne,"data-testid":"btn-export-followups",children:[e.jsx(M,{className:"h-4 w-4 mr-2"}),"Export as JSON"]})]}),m.length===0?e.jsx(d,{children:e.jsxs(i,{className:"py-12 text-center",children:[e.jsx(S,{className:"h-12 w-12 mx-auto mb-4 text-muted-foreground"}),e.jsx("p",{className:"text-lg font-medium","data-testid":"text-no-followups",children:"No follow-up requests"})]})}):m.map((s,t)=>e.jsx(d,{"data-testid":`card-followup-${t}`,children:e.jsx(i,{className:"p-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(S,{className:"h-4 w-4 text-blue-500 mt-0.5 shrink-0"}),e.jsxs("div",{children:[e.jsx(u,{variant:"outline",className:"mb-1 text-xs",children:s.reqId}),e.jsx("p",{className:"text-sm",children:s.followUp})]})]})})},t))]}),e.jsx(N,{value:"evidence",children:L.length===0?e.jsx(d,{children:e.jsxs(i,{className:"py-12 text-center",children:[e.jsx(G,{className:"h-12 w-12 mx-auto mb-4 text-muted-foreground"}),e.jsx("p",{className:"text-lg font-medium","data-testid":"text-no-evidence",children:"No evidence files indexed"})]})}):e.jsx(d,{children:e.jsx(i,{className:"p-0",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm","data-testid":"table-evidence-index",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b bg-muted/50",children:[e.jsx("th",{className:"text-left p-3 font-medium",children:"File Name"}),e.jsx("th",{className:"text-left p-3 font-medium",children:"Chunks"}),e.jsx("th",{className:"text-left p-3 font-medium",children:"Requirements Supp
1orted"}),e.jsx("th",{className:"text-left p-3 font-medium",children:"Coverage"})]})}),e.jsx("tbody",{children:L.map((s,t)=>e.jsxs("tr",{className:"border-b last:border-0","data-testid":`evidence-row-${t}`,children:[e.jsx("td",{className:"p-3 font-medium",children:s.fileName}),e.jsx("td",{className:"p-3",children:s.chunkCount}),e.jsx("td",{className:"p-3",children:e.jsxs("div",{className:"flex flex-wrap gap-1",children:[s.reqIds.slice(0,5).map((a,r)=>e.jsx(u,{variant:"outline",className:"text-xs",children:a},r)),s.reqIds.length>5&&e.jsxs(u,{variant:"outline",className:"text-xs",children:["+",s.reqIds.length-5," more"]})]})}),e.jsx("td",{className:"p-3",children:e.jsxs("span",{className:"text-muted-foreground",children:[s.reqIds.length," req",s.reqIds.length!==1?"s":""]})})]},t))})]})})})})})]})]})})}export{Je as default};
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.