1import{w as K,t as M,n as m,l as e}from"./vendor-react-DqEQpdJ_.js";import{y as Z,O as I,B as q}from"./index-vP4jtEGS.js";import{C as l,a as r,d,e as p}from"./card-CCwkw-eX.js";import{P as h}from"./pill-DLeX0aLu.js";import{S as i}from"./skeleton-CoDBdCU0.js";import{T as ee,b as se,c as R}from"./tabs-B1w75L_L.js";import{B as C,c as T,a as u,b as S,e as V,d as E}from"./breadcrumb-C4danDTy.js";import{p as L}from"./policyService-COED7eT4.js";import{J as $,a4 as F,r as G,bu as O,ao as te,bp as y,E as P,w as ae,t as le}from"./vendor-icons-B-8y0biV.js";import"./vendor-radix-BAR1pTYe.js";function N({badge:x,pillVariant:v,title:j,description:a,bgClass:w,borderClass:b}){return e.jsxs("div",{className:`p-3 ${w} border ${b} rounded-lg`,children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx(h,{variant:v,showDot:!1,children:x}),e.jsx("p",{className:"text-sm font-medium text-pc-text truncate flex-1",title:j,children:j})]}),a&&e.jsx("p",{className:"text-xs text-pc-text-3 mt-2 line-clamp-2",children:a})]})}function he(){const{policyId:x}=K();M();const[v,j]=m.useState(!0),[a,w]=m.useState(null),[b,W]=m.useState(null),[o,z]=m.useState(null),[Q,_]=m.useState(null),[U,H]=m.useState(new Set([0])),[g,J]=m.useState("overview");m.useEffect(()=>{x&&k()},[x]);const k=async()=>{if(x)try{j(!0),_(null);const s=await Z.get(`/api/policy-extraction/workflow-results/${x}?asset_type=QUALITY_REPORT`);if(!s.success)throw new Error("Quality report request failed");const t=s.workflow_results?.asset_data?.buildWorkflowAssets?.qualityReport;if(!t)throw new Error("No quality report data found");w(t);const f=await L.downloadPolicy(x);W(f);try{const c=await L.getPolicyStatus(x);if(c?.file_info?.original_filename){const Y=c.file_info.original_filename.replace(/\.[^/.]+$/,"");z(Y)}}catch(c){console.warn("Could not fetch policy name from status:",c)}}catch(s){console.error("Error loading quality report:",s);const t=s instanceof Error?s.message:"Failed to load quality report";_(t),I.error(t)}finally{j(!1)}},A=s=>b?.rules?.find(t=>t.aws_ar_rule_id===s),B=s=>b?.variables?.find(t=>t.name===s),D=s=>b?.types?.find(t=>t.name===s),X=s=>{const t=new Set(U);t.has(s)?t.delete(s):t.add(s),H(t)};return v?e.jsxs("div",{className:"min-h-screen",children:[e.jsx("div",{className:"",children:e.jsxs("div",{className:"max-w-[960px] xl:max-w-[1100px] 2xl:max-w-[1400px] mx-auto w-full py-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(i,{className:"h-4 w-24"}),e.jsx("span",{className:"text-pc-text-4",children:">"}),e.jsx(i,{className:"h-4 w-48"})]}),e.jsx(i,{className:"h-7 w-64 mb-1"}),e.jsx(i,{className:"h-4 w-32"})]})}),e.jsxs("div",{className:"max-w-[960px] xl:max-w-[1100px] 2xl:max-w-[1400px] mx-auto w-full py-8",children:[e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-4 gap-6 mb-8",children:[...Array(4)].map((s,t)=>e.jsx(l,{className:"bg-pc-surface border-pc-border",children:e.jsx(r,{className:"p-6",children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(i,{className:"w-10 h-10 rounded-lg"}),e.jsxs("div",{children:[e.jsx(i,{className:"h-4 w-20 mb-2"}),e.jsx(i,{className:"h-8 w-12"})]})]})})},t))}),e.jsx(i,{className:"h-10 w-80 rounded-full mb-6"}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[e.jsxs(l,{className:"bg-pc-surface border-pc-border",children:[e.jsx(d,{children:e.jsx(i,{className:"h-6 w-40"})}),e.jsx(r,{className:"space-y-3",children:[...Array(4)].map((s,t)=>e.jsx(i,{className:"h-12 w-full rounded-lg"},t))})]}),e.jsxs(l,{className:"bg-pc-surface border-pc-border",children:[e.jsx(d,{children:e.jsx(i,{className:"h-6 w-32"})}),e.jsx(r,{className:"space-y-3",children:[...Array(3)].map((s,t)=>e.jsx(i,{className:"h-12 w-full rounded-lg"},t))})]})]})]})]}):Q?e.jsxs("div",{className:"min-h-screen flex flex-col",children:[e.jsx("div",{className:"",children:e.jsx("div",{className:"max-w-[960px] xl:max-w-[1100px] 2xl:max-w-[1400px] mx-auto w-full py-4",children:e.jsx(C,{children:e.jsxs(T,{children:[e.jsx(u,{children:e.jsx(S,{href:"/policies",children:"Ground Truth"})}),e.jsx(V,{}),e.jsx(u,{children:e.jsxs(E,{title:`Quality Report (${o||"Policy"})`,children:["Quality Report (",o||"Policy",")"]})})]})})})}),e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"text-center",children:[e.jsx($,{className:"w-12 h-12 text-pc-error mx-auto mb-4"}),e.jsx("h3",{className:"text-lg font-semibold text-pc-text mb-2",children:"Error Loading Quality Report"}),e.jsx("p",{className:"text-pc-text-3 mb-4",children:Q}),e.jsx(q,{onClick:k,children:"Try Again"})]})})]}):a?e.jsxs("div",{className:"min-h-screen",children:[e.jsx("div",{className:"",children:e.jsxs("div",{className:"max-w-[960px] xl:max-w-[1100px] 2xl:max-w-[1400px] mx-auto w-full py-4",children:[e.jsx(C,{className:"mb-3",children:e.jsxs(T,{children:[e.jsx(u,{children:e.jsx(S,{href:"/policies",children:"Ground Truth"})}),e.jsx(V,{}),e.jsx(u,{children:e.jsxs(E,{title:`Quality Report (${o||"Policy"})`,children:["Quality Report (",o||"Policy",")"]})})]})}),e.jsx("h1",{className:"text-xl md:text-2xl font-semibold text-pc-text",children:o||"Policy"}),e.jsx("p",{className:"text-sm text-pc-text-3 mt-0.5",children:"Quality Report"})]})}),e.jsxs("div",{className:"max-w-[960px] xl:max-w-[1100px] 2xl:max-w-[1400px] mx-auto w-full py-8",children:[e.jsxs("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-3 md:gap-6 mb-8",children:[e.jsx(l,{className:"bg-pc-surface border-pc-border",children:e.jsx(r,{className:"p-4 md:p-6",children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"p-2 bg-pc-tint-blue border border-pc-tint-blue-border text-pc-primary rounded-lg",children:e.jsx(G,{className:"w-5 h-5 md:w-6 md:h-6"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs md:text-sm font-medium text-pc-text-3",children:"Total Rules"}),e.jsx("p",{className:"text-xl md:text-2xl font-bold text-pc-text",children:a.ruleCount})]})]})})}),e.jsx(l,{className:"bg-pc-surface border-pc-border",children:e.jsx(r,{className:"p-4 md:p-6",children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"p-2 bg-pc-tint-green border border-pc-tint-green-border text-pc-success rounded-lg",children:e.jsx(O,{className:"w-5 h-5 md:w-6 md:h-6"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs md:text-sm font-medium text-pc-text-3",children:"Variables"}),e.jsx("p",{className:"text-xl md:text-2xl font-bold text-pc-text",children:a.variableCount})]})]})})}),e.jsx(l,{className:"bg-pc-surface border-pc-border",children:e.jsx(r,{className:"p-4 md:p-6",children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"p-2 bg-pc-surface-2 text-pc-primary rounded-lg",children:e.jsx(te,{className:"w-5 h-5 md:w-6 md:h-6"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs md:text-sm font-medium text-pc-text-3",children:"Types"}),e.jsx("p",{className:"text-xl md:text-2xl font-bold text-pc-text",children:a.typeCount})]})]})})}),e.jsx(l,{className:"bg-pc-surface border-pc-border",children:e.jsx(r,{className:"p-4 md:p-6",children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:`p-2 rounded-lg ${a.conflictingRules.length>0?"bg-pc-tint-red border border-pc-tint-red-border text-pc-error":"bg-pc-tint-green border border-pc-tint-green-border text-pc-success"}`,children:a.conflictingRules.length>0?e.jsx(y,{className:"w-5 h-5 md:w-6 md:h-6"}):e.jsx(P,{className:"w-5 h-5 md:w-6 md:h-6"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs md:text-sm font-medium text-pc-text-3",children:"Conflicts"}),e.jsx("p",{className:"text-xl md:text-2xl font-bold text-pc-text",children:a.conflictingRules.length})]})]})})})]}),e.jsx("div",{className:"flex justify-center mb-6",children:e.jsx(ee,{value:g,onValueChange:s=>J(s),variant:"pill",children:e.jsxs(se,{children:[e.jsx(R,{value:"overview",children:"Overview"}),e.jsx(R,{value:"rules",children:"Rule Sets"}),e.jsx(R,{value:"unused",children:"Unused"})]})})}),g==="overview"&&e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[e.jsxs(l,{className:"bg-pc-surface border-pc-border",children:[e.jsx(d,{className:"pb-4",children:e.jsxs(p,{className:"flex items-center gap-2 text-base font-semibold text-pc-text",children:[e.jsx(P,{className:"w-5 h-5 text-pc-success"}),"Quality Summary"]})}),e.jsxs(r,{className:"space-y-3",children:[e.jsxs("div",{className:"flex justify-between items-center p-3 bg-pc-surface-2 rounded-lg",children:[e.jsx("span",{className:"text-sm font-medium text-pc-text",children:"Rule Coverage"}),e.jsxs(h,{variant:"neutral",children:[a.ruleCount," rules"]})]}),e.jsxs("div",{className:"flex justify-between items-center p-3 bg-pc-surface-2 rounded-lg",children:[e.jsx("span",{className:"text-sm font-medium text-pc-text",children:"Variable Usage"}),e.jsxs(h,{variant:"neutral",children:[a.variableCount-a.unusedVariables.length," active"]})]}),e.jsxs("div",{className:"flex justify-between items-center p-3 bg-pc-surface-2 rounded-lg",children:[e.jsx("span",{className:"text-sm font-medium text-pc-text",children:"Type Definitions"}),e.jsxs(h,{variant:"neutral",children:[a.typeCount," types"]})]}),e.jsxs("div",{className:"flex justify-between items-center p-3 bg-pc-surface-2 rounded-lg",children:[e.jsx("span",{className:"text-sm font-medium text-pc-text",children:"Rule Conflicts"}),e.jsxs(h,{variant:a.conflictingRules.length>0?"error":"success",children:[a.conflictingRules.length," conflicts"]})]})]})]}),a.disjointRuleSets.length>0&&e.jsxs(l,{className:"bg-pc-surface border-pc-border",children:[e.jsx(d,{className:"pb-4",children:e.jsxs(p,{className:"flex items-center gap-2 text-base font-semibold text-pc-text",children:[e.jsx(G,{className:"w-5 h-5 text-pc-primary"}),"Rule Sets"]}
1)}),e.jsxs(r,{children:[e.jsxs("p",{className:"text-sm text-pc-text-3 mb-4",children:["Found ",a.disjointRuleSets.length," disjoint rule set(s)"]}),e.jsx("div",{className:"space-y-2",children:a.disjointRuleSets.map((s,t)=>e.jsxs("div",{className:"flex justify-between items-center p-3 bg-pc-surface-2 rounded-lg",children:[e.jsxs("span",{className:"text-sm font-medium text-pc-text",children:["Rule Set ",t+1]}),e.jsxs("span",{className:"text-xs text-pc-text-3",children:[s.rules.length," rules, ",s.variables.length," variables"]})]},t))})]})]})]}),g==="rules"&&e.jsxs("div",{className:"space-y-6",children:[a.disjointRuleSets.map((s,t)=>{const f=U.has(t);return e.jsxs(l,{className:"bg-pc-surface border-pc-border",children:[e.jsx(d,{className:"pb-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsxs(p,{className:"text-base font-semibold text-pc-text",children:["Rule Set ",t+1]}),e.jsxs("p",{className:"text-sm text-pc-text-3 mt-0.5",children:[s.rules.length," rules and ",s.variables.length," variables"]})]}),e.jsx(q,{variant:"ghost",size:"sm",onClick:()=>X(t),className:"h-8 w-8 p-0",children:f?e.jsx(ae,{className:"h-4 w-4"}):e.jsx(le,{className:"h-4 w-4"})})]})}),f&&e.jsxs(r,{className:"space-y-6 pt-0",children:[e.jsxs("div",{children:[e.jsxs("h4",{className:"text-sm font-semibold text-pc-text mb-3 flex items-center gap-2",children:[e.jsx(F,{className:"w-4 h-4"}),"Rules (",s.rules.length,")"]}),e.jsx("div",{className:"space-y-2",children:s.rules.map(c=>{const n=A(c);return e.jsx(N,{badge:n?.rule_type||"Unknown",pillVariant:"neutral",title:n?.id||c,description:n?.description,bgClass:"bg-pc-surface-2 hover:bg-pc-surface-3 transition-colors",borderClass:"border-transparent"},c)})})]}),e.jsxs("div",{children:[e.jsxs("h4",{className:"text-sm font-semibold text-pc-text mb-3 flex items-center gap-2",children:[e.jsx(O,{className:"w-4 h-4"}),"Variables (",s.variables.length,")"]}),e.jsx("div",{className:"space-y-2",children:s.variables.map(c=>{const n=B(c);return e.jsx(N,{badge:n?.type||"Unknown",pillVariant:"running",title:c,description:n?.description,bgClass:"bg-pc-tint-blue",borderClass:"border-pc-tint-blue-border"},c)})})]})]})]},t)}),a.conflictingRules.length>0&&e.jsxs(l,{className:"bg-pc-surface border-pc-border",children:[e.jsx(d,{className:"pb-4",children:e.jsxs(p,{className:"flex items-center gap-2 text-base font-semibold text-pc-error",children:[e.jsx(y,{className:"w-5 h-5"}),"Conflicting Rules"]})}),e.jsx(r,{children:e.jsx("div",{className:"space-y-2",children:a.conflictingRules.map(s=>{const t=A(s);return e.jsx("div",{className:"p-3 bg-pc-tint-red border border-pc-tint-red-border rounded-lg",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(h,{variant:"error",showDot:!1,children:t?.rule_type||"Unknown"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium text-pc-text",children:t?.id||s}),t?.description&&e.jsx("p",{className:"text-xs text-pc-text-3 mt-1 line-clamp-2",children:t.description})]})]})},s)})})})]})]}),g==="unused"&&e.jsxs("div",{className:"space-y-6",children:[a.unusedVariables.length>0&&e.jsxs(l,{className:"bg-pc-surface border-pc-border",children:[e.jsxs(d,{className:"pb-4",children:[e.jsxs(p,{className:"flex items-center gap-2 text-base font-semibold text-pc-warning",children:[e.jsx(y,{className:"w-5 h-5"}),"Unused Variables"]}),e.jsxs("p",{className:"text-sm text-pc-text-3 mt-0.5",children:[a.unusedVariables.length," variables are defined but not used in any rules"]})]}),e.jsx(r,{children:e.jsx("div",{className:"space-y-2",children:a.unusedVariables.map(s=>{const t=B(s);return e.jsx(N,{badge:t?.type||"Unknown",pillVariant:"warning",title:s,description:t?.description,bgClass:"bg-pc-tint-amber",borderClass:"border-pc-tint-amber-border"},s)})})})]}),a.unusedTypeValues.length>0&&e.jsxs(l,{className:"bg-pc-surface border-pc-border",children:[e.jsxs(d,{className:"pb-4",children:[e.jsxs(p,{className:"flex items-center gap-2 text-base font-semibold text-pc-warning",children:[e.jsx(y,{className:"w-5 h-5"}),"Unused Type Values"]}),e.jsxs("p",{className:"text-sm text-pc-text-3 mt-0.5",children:[a.unusedTypeValues.length," type values are defined but not referenced"]})]}),e.jsx(r,{children:e.jsx("div",{className:"space-y-2",children:a.unusedTypeValues.map((s,t)=>{const c=D(s.typeName)?.values?.find(n=>n.value===s.valueName);return e.jsx(N,{badge:s.typeName,pillVariant:"warning",title:s.valueName,description:c?.description,bgClass:"bg-pc-tint-amber",borderClass:"border-pc-tint-amber-border"},t)})})})]}),a.unusedTypes.length>0&&e.jsxs(l,{className:"bg-pc-surface border-pc-border",children:[e.jsxs(d,{className:"pb-4",children:[e.jsxs(p,{className:"flex items-center gap-2 text-base font-semibold text-pc-error",children:[e.jsx($,{className:"w-5 h-5"}),"Unused Types"]}),e.jsxs("p",{className:"text-sm text-pc-text-3 mt-0.5",children:[a.unusedTypes.length," types are defined but completely unused"]})]}),e.jsx(r,{children:e.jsx("div",{className:"space-y-2",children:a.unusedTypes.map(s=>{const t=D(s);return e.jsx(N,{badge:"Type",pillVariant:"error",title:s,description:t?.description,bgClass:"bg-pc-tint-red",borderClass:"border-pc-tint-red-border"},s)})})})]}),a.unusedVariables.length===0&&a.unusedTypeValues.length===0&&a.unusedTypes.length===0&&e.jsx(l,{className:"bg-pc-surface border-pc-border",children:e.jsxs(r,{className:"p-8 text-center",children:[e.jsx(P,{className:"w-12 h-12 text-pc-success mx-auto mb-4"}),e.jsx("h3",{className:"text-lg font-semibold text-pc-text mb-2",children:"No Unused Elements"}),e.jsx("p",{className:"text-pc-text-3",children:"All defined variables, types, and type values are being used in the policy rules."})]})})]})]})]}):e.jsxs("div",{className:"min-h-screen flex flex-col",children:[e.jsx("div",{className:"",children:e.jsx("div",{className:"max-w-[960px] xl:max-w-[1100px] 2xl:max-w-[1400px] mx-auto w-full py-4",children:e.jsx(C,{children:e.jsxs(T,{children:[e.jsx(u,{children:e.jsx(S,{href:"/policies",children:"Ground Truth"})}),e.jsx(V,{}),e.jsx(u,{children:e.jsxs(E,{title:`Quality Report (${o||"Policy"})`,children:["Quality Report (",o||"Policy",")"]})})]})})})}),e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"text-center",children:[e.jsx(F,{className:"w-12 h-12 text-pc-text-4 mx-auto mb-4"}),e.jsx("h3",{className:"text-lg font-semibold text-pc-text mb-2",children:"No Quality Report Available"}),e.jsx("p",{className:"text-pc-text-3",children:"Quality report data is not available for this policy."})]})})]})}export{he as QualityReportPage};
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.