driftdetect-dashboard 0.6.1 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/client/assets/{GalaxyTab-DA9097-Z.js → GalaxyTab-Bc9PKsMk.js} +4 -4
- package/dist/client/assets/{GalaxyTab-DA9097-Z.js.map → GalaxyTab-Bc9PKsMk.js.map} +1 -1
- package/dist/client/assets/{main-D1M_eef4.js → main-BdVQNGtK.js} +2 -2
- package/dist/client/assets/{main-D1M_eef4.js.map → main-BdVQNGtK.js.map} +1 -1
- package/dist/client/assets/main-NejYwKFb.css +2 -0
- package/dist/client/assets/{sfxr-BUUZlhMn.js → sfxr-CO3_Kukg.js} +2 -2
- package/dist/client/assets/{sfxr-BUUZlhMn.js.map → sfxr-CO3_Kukg.js.map} +1 -1
- package/dist/client/index.html +2 -2
- package/package.json +20 -20
- package/dist/client/assets/main-CqioacxX.css +0 -2
|
@@ -55,5 +55,5 @@ Error generating stack: `+l.message+`
|
|
|
55
55
|
* LICENSE file in the root directory of this source tree.
|
|
56
56
|
*/var fl=S,gv=vv;function yv(e,t){return e===t&&(e!==0||1/e===1/t)||e!==e&&t!==t}var jv=typeof Object.is=="function"?Object.is:yv,Nv=gv.useSyncExternalStore,bv=fl.useRef,kv=fl.useEffect,wv=fl.useMemo,Sv=fl.useDebugValue;Sh.useSyncExternalStoreWithSelector=function(e,t,n,r,s){var l=bv(null);if(l.current===null){var a={hasValue:!1,value:null};l.current=a}else a=l.current;l=wv(function(){function c(m){if(!u){if(u=!0,h=m,m=r(m),s!==void 0&&a.hasValue){var y=a.value;if(s(y,m))return d=y}return d=m}if(y=d,jv(h,m))return y;var N=r(m);return s!==void 0&&s(y,N)?(h=m,y):(h=m,d=N)}var u=!1,h,d,f=n===void 0?null:n;return[function(){return c(t())},f===null?void 0:function(){return c(f())}]},[t,n,r,s]);var o=Nv(e,l[0],l[1]);return kv(function(){a.hasValue=!0,a.value=o},[o]),Sv(o),o};wh.exports=Sh;var Cv=wh.exports;const Ev=Zu(Cv),Ph={},{useDebugValue:Pv}=cd,{useSyncExternalStoreWithSelector:Tv}=Ev;let Pu=!1;const _v=e=>e;function Ov(e,t=_v,n){(Ph?"production":void 0)!=="production"&&n&&!Pu&&(console.warn("[DEPRECATED] Use `createWithEqualityFn` instead of `create` or use `useStoreWithEqualityFn` instead of `useStore`. They can be imported from 'zustand/traditional'. https://github.com/pmndrs/zustand/discussions/1937"),Pu=!0);const r=Tv(e.subscribe,e.getState,e.getServerState||e.getInitialState,t,n);return Pv(r),r}const Tu=e=>{(Ph?"production":void 0)!=="production"&&typeof e!="function"&&console.warn("[DEPRECATED] Passing a vanilla store will be unsupported in a future version. Instead use `import { useStore } from 'zustand'`.");const t=typeof e=="function"?av(e):e,n=(r,s)=>Ov(t,r,s);return Object.assign(n,t),n},Th=e=>e?Tu(e):Tu,Lr=Th(e=>({connectionStatus:"disconnected",setConnectionStatus:t=>e({connectionStatus:t}),activeTab:"overview",setActiveTab:t=>e({activeTab:t}),realtimeViolations:[],addRealtimeViolation:t=>e(n=>({realtimeViolations:[t,...n.realtimeViolations].slice(0,100)})),clearRealtimeViolations:()=>e({realtimeViolations:[]}),expandedViolations:new Set,toggleViolationExpanded:t=>e(n=>{const r=new Set(n.expandedViolations);return r.has(t)?r.delete(t):r.add(t),{expandedViolations:r}}),selectedPattern:null,setSelectedPattern:t=>e({selectedPattern:t}),expandedFolders:new Set,toggleFolderExpanded:t=>e(n=>{const r=new Set(n.expandedFolders);return r.has(t)?r.delete(t):r.add(t),{expandedFolders:r}}),patternFilters:{},setPatternFilters:t=>e({patternFilters:t}),violationFilters:{},setViolationFilters:t=>e({violationFilters:t})})),hl="/api";async function vt(e){const t=await fetch(`${hl}${e}`);if(!t.ok)throw new Error(`API error: ${t.status} ${t.statusText}`);return t.json()}async function Ds(e,t){const n=await fetch(`${hl}${e}`,{method:"POST",headers:{"Content-Type":"application/json"},body:t?JSON.stringify(t):void 0});if(!n.ok)throw new Error(`API error: ${n.status} ${n.statusText}`);return n.json()}async function Iv(e,t){const n=await fetch(`${hl}${e}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!n.ok)throw new Error(`API error: ${n.status} ${n.statusText}`);return n.json()}async function Rv(e){const t=await fetch(`${hl}${e}`,{method:"DELETE"});if(!t.ok)throw new Error(`API error: ${t.status} ${t.statusText}`);return t.json()}function Fv(){return xt({queryKey:["stats"],queryFn:()=>vt("/stats"),refetchInterval:3e4})}function Mv(e){const t=new URLSearchParams;e!=null&&e.category&&t.set("category",e.category),e!=null&&e.status&&t.set("status",e.status),e!=null&&e.minConfidence&&t.set("minConfidence",String(e.minConfidence)),e!=null&&e.search&&t.set("search",e.search);const n=t.toString();return xt({queryKey:["patterns",e],queryFn:()=>vt(`/patterns${n?`?${n}`:""}`)})}function _h(e){return xt({queryKey:["pattern",e],queryFn:()=>vt(`/patterns/${e}`),enabled:!!e})}function Oh(){const e=pt();return Hn({mutationFn:t=>Ds(`/patterns/${t}/approve`),onSuccess:()=>{e.invalidateQueries({queryKey:["patterns"]}),e.invalidateQueries({queryKey:["stats"]})}})}function Ih(){const e=pt();return Hn({mutationFn:t=>Ds(`/patterns/${t}/ignore`),onSuccess:()=>{e.invalidateQueries({queryKey:["patterns"]}),e.invalidateQueries({queryKey:["stats"]})}})}function Lv(){const e=pt();return Hn({mutationFn:t=>Rv(`/patterns/${t}`),onSuccess:()=>{e.invalidateQueries({queryKey:["patterns"]}),e.invalidateQueries({queryKey:["stats"]})}})}function Dv(){const e=pt();return Hn({mutationFn:t=>Ds("/patterns/bulk-approve",{ids:t}),onSuccess:()=>{e.invalidateQueries({queryKey:["patterns"]}),e.invalidateQueries({queryKey:["stats"]})}})}function Rh(e){const t=new URLSearchParams;e!=null&&e.severity&&t.set("severity",e.severity),e!=null&&e.file&&t.set("file",e.file),e!=null&&e.patternId&&t.set("patternId",e.patternId),e!=null&&e.search&&t.set("search",e.search);const n=t.toString();return xt({queryKey:["violations",e],queryFn:()=>vt(`/violations${n?`?${n}`:""}`)})}function $v(){return xt({queryKey:["files","tree"],queryFn:()=>vt("/files")})}function Av(e){return xt({queryKey:["files","details",e],queryFn:()=>vt(`/files/${encodeURIComponent(e)}`),enabled:!!e})}function zv(){return xt({queryKey:["config"],queryFn:()=>vt("/config")})}function Uv(){const e=pt();return Hn({mutationFn:t=>Iv("/config",t),onSuccess:()=>{e.invalidateQueries({queryKey:["config"]})}})}function Vv(e){const t=new URLSearchParams;e!=null&&e.status&&t.set("status",e.status),e!=null&&e.method&&t.set("method",e.method),(e==null?void 0:e.hasMismatches)!==void 0&&t.set("hasMismatches",String(e.hasMismatches)),e!=null&&e.search&&t.set("search",e.search);const n=t.toString();return xt({queryKey:["contracts",e],queryFn:()=>vt(`/contracts${n?`?${n}`:""}`)})}function Qv(e){return xt({queryKey:["contract",e],queryFn:()=>vt(`/contracts/${e}`),enabled:!!e})}function Hv(){const e=pt();return Hn({mutationFn:t=>Ds(`/contracts/${t}/verify`),onSuccess:()=>{e.invalidateQueries({queryKey:["contracts"]})}})}function Bv(){const e=pt();return Hn({mutationFn:t=>Ds(`/contracts/${t}/ignore`),onSuccess:()=>{e.invalidateQueries({queryKey:["contracts"]})}})}function Wv(e="7d"){return xt({queryKey:["trends",e],queryFn:()=>vt(`/trends?period=${e}`),refetchInterval:6e4})}const Kv=3e3,Gv=3e4;function qv(){const e=S.useRef(null),t=S.useRef(null),n=S.useRef(null),r=pt(),{setConnectionStatus:s,addRealtimeViolation:l}=Lr(),a=S.useCallback(()=>{e.current&&e.current.close(),s("connecting");const f=`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/ws`;try{const m=new WebSocket(f);e.current=m,m.onopen=()=>{s("connected"),t.current=setInterval(()=>{m.readyState===WebSocket.OPEN&&m.send(JSON.stringify({type:"ping"}))},Gv)},m.onmessage=y=>{try{const N=JSON.parse(y.data);o(N)}catch{console.error("Failed to parse WebSocket message")}},m.onclose=()=>{s("disconnected"),c(),u()},m.onerror=()=>{s("disconnected")}}catch{s("disconnected"),u()}},[s]),o=S.useCallback(d=>{switch(d.type){case"violation":l(d.payload),r.invalidateQueries({queryKey:["violations"]}),r.invalidateQueries({queryKey:["stats"]});break;case"pattern_updated":r.invalidateQueries({queryKey:["patterns"]}),r.invalidateQueries({queryKey:["pattern",d.payload.id]}),r.invalidateQueries({queryKey:["stats"]});break;case"patterns_changed":r.invalidateQueries({queryKey:["patterns"]}),r.invalidateQueries({queryKey:["stats"]}),r.invalidateQueries({queryKey:["violations"]}),r.invalidateQueries({queryKey:["files"]});break;case"stats_updated":r.setQueryData(["stats"],d.payload);break}},[l,r]),c=S.useCallback(()=>{t.current&&(clearInterval(t.current),t.current=null)},[]),u=S.useCallback(()=>{n.current&&clearTimeout(n.current),n.current=setTimeout(a,Kv)},[a]),h=S.useCallback(()=>{n.current&&(clearTimeout(n.current),n.current=null),c(),e.current&&(e.current.close(),e.current=null),s("disconnected")},[c,s]);return S.useEffect(()=>(a(),()=>{h()}),[a,h]),{connect:a,disconnect:h}}function _u({patternName:e,category:t,type:n,previousValue:r,currentValue:s,changePercent:l,severity:a,details:o}){const c=n==="regression",u={critical:"border-l-severity-error bg-severity-error/5",warning:"border-l-severity-warning bg-severity-warning/5",info:"border-l-status-approved bg-status-approved/5"},h=c?"text-severity-error":"text-status-approved",d=c?"↓":"↑";return i.jsxs("div",{className:`p-3 rounded-lg border-l-4 ${u[a]}`,children:[i.jsxs("div",{className:"flex items-start justify-between gap-2",children:[i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsx("div",{className:"font-medium text-sm truncate",children:e}),i.jsx("div",{className:"text-xs text-dark-muted mt-0.5",children:t})]}),i.jsxs("div",{className:`text-right ${h}`,children:[i.jsxs("div",{className:"font-semibold text-sm",children:[d," ",Math.abs(l).toFixed(0),"%"]}),i.jsxs("div",{className:"text-xs text-dark-muted",children:[(r*100).toFixed(0),"% → ",(s*100).toFixed(0),"%"]})]})]}),i.jsx("div",{className:"text-xs text-dark-muted mt-2",children:o})]})}function Yv({period:e,onChange:t}){const n=[{value:"7d",label:"7 days"},{value:"30d",label:"30 days"},{value:"90d",label:"90 days"}];return i.jsx("div",{className:"flex gap-1 bg-dark-bg rounded-lg p-1",children:n.map(({value:r,label:s})=>i.jsx("button",{onClick:()=>t(r),className:`px-3 py-1 text-xs rounded transition-colors ${e===r?"bg-dark-surface text-dark-text":"text-dark-muted hover:text-dark-text"}`,children:s},r))})}function Xv({trend:e,healthDelta:t}){const n={improving:{icon:"📈",label:"Improving",color:"text-status-approved",bg:"bg-status-approved/10"},declining:{icon:"📉",label:"Declining",color:"text-severity-error",bg:"bg-severity-error/10"},stable:{icon:"➡️",label:"Stable",color:"text-dark-muted",bg:"bg-dark-surface"}}[e];return i.jsxs("div",{className:`flex items-center gap-2 px-3 py-1.5 rounded-lg ${n.bg}`,children:[i.jsx("span",{children:n.icon}),i.jsx("span",{className:`text-sm font-medium ${n.color}`,children:n.label}),t!==0&&i.jsxs("span",{className:`text-xs ${n.color}`,children:["(",t>0?"+":"",(t*100).toFixed(1),"%)"]})]})}function Zv(){var c,u;const[e,t]=S.useState("7d"),{data:n,isLoading:r,error:s}=Wv(e);if(r)return i.jsxs("div",{className:"card",children:[i.jsx("div",{className:"flex items-center justify-between mb-4",children:i.jsx("h3",{className:"text-sm font-medium text-dark-muted uppercase tracking-wide",children:"Pattern Trends"})}),i.jsx("div",{className:"text-dark-muted text-sm",children:"Loading trends..."})]});if(s)return i.jsxs("div",{className:"card",children:[i.jsx("div",{className:"flex items-center justify-between mb-4",children:i.jsx("h3",{className:"text-sm font-medium text-dark-muted uppercase tracking-wide",children:"Pattern Trends"})}),i.jsx("div",{className:"text-severity-error text-sm",children:"Failed to load trends"})]});const l=n&&(((c=n.regressions)==null?void 0:c.length)>0||((u=n.improvements)==null?void 0:u.length)>0),a=(n==null?void 0:n.regressions)||[],o=(n==null?void 0:n.improvements)||[];return i.jsxs("div",{className:"card",children:[i.jsxs("div",{className:"flex items-center justify-between mb-4",children:[i.jsx("h3",{className:"text-sm font-medium text-dark-muted uppercase tracking-wide",children:"Pattern Trends"}),i.jsx(Yv,{period:e,onChange:t})]}),l?i.jsxs("div",{className:"space-y-4",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx(Xv,{trend:n.overallTrend,healthDelta:n.healthDelta}),i.jsxs("div",{className:"text-xs text-dark-muted",children:[n.startDate," → ",n.endDate]})]}),i.jsxs("div",{className:"grid grid-cols-3 gap-3 text-center",children:[i.jsxs("div",{className:"p-2 bg-severity-error/10 rounded",children:[i.jsx("div",{className:"text-lg font-semibold text-severity-error",children:a.length}),i.jsx("div",{className:"text-xs text-dark-muted",children:"Regressions"})]}),i.jsxs("div",{className:"p-2 bg-status-approved/10 rounded",children:[i.jsx("div",{className:"text-lg font-semibold text-status-approved",children:o.length}),i.jsx("div",{className:"text-xs text-dark-muted",children:"Improvements"})]}),i.jsxs("div",{className:"p-2 bg-dark-surface rounded",children:[i.jsx("div",{className:"text-lg font-semibold text-dark-muted",children:n.stable}),i.jsx("div",{className:"text-xs text-dark-muted",children:"Stable"})]})]}),a.length>0&&i.jsxs("div",{children:[i.jsxs("div",{className:"text-xs font-medium text-severity-error mb-2 flex items-center gap-1",children:[i.jsx("span",{children:"📉"})," Regressions (",a.length,")"]}),i.jsxs("div",{className:"space-y-2",children:[a.slice(0,5).map((h,d)=>i.jsx(_u,{patternName:h.patternName,category:h.category,type:"regression",metric:h.metric,previousValue:h.previousValue,currentValue:h.currentValue,changePercent:h.changePercent,severity:h.severity,details:h.details},`${h.patternId}-${d}`)),a.length>5&&i.jsxs("div",{className:"text-xs text-dark-muted text-center",children:["+",a.length-5," more regressions"]})]})]}),o.length>0&&i.jsxs("div",{children:[i.jsxs("div",{className:"text-xs font-medium text-status-approved mb-2 flex items-center gap-1",children:[i.jsx("span",{children:"📈"})," Improvements (",o.length,")"]}),i.jsxs("div",{className:"space-y-2",children:[o.slice(0,3).map((h,d)=>i.jsx(_u,{patternName:h.patternName,category:h.category,type:"improvement",metric:h.metric,previousValue:h.previousValue,currentValue:h.currentValue,changePercent:h.changePercent,severity:h.severity,details:h.details},`${h.patternId}-${d}`)),o.length>3&&i.jsxs("div",{className:"text-xs text-dark-muted text-center",children:["+",o.length-3," more improvements"]})]})]})]}):i.jsxs("div",{className:"text-center py-8",children:[i.jsx("div",{className:"text-4xl mb-2",children:"📊"}),i.jsx("div",{className:"text-dark-muted text-sm",children:"Not enough history data yet."}),i.jsx("div",{className:"text-dark-muted text-xs mt-1",children:"Run more scans to see pattern trends over time."})]})]})}function Wl({label:e,value:t,subtext:n}){return i.jsxs("div",{className:"card",children:[i.jsx("div",{className:"text-sm text-dark-muted mb-1",children:e}),i.jsx("div",{className:"text-2xl font-semibold",children:t}),n&&i.jsx("div",{className:"text-xs text-dark-muted mt-1",children:n})]})}function Jv({score:e}){const t=()=>e>=80?"text-status-approved":e>=60?"text-severity-warning":"text-severity-error";return i.jsxs("div",{className:"card flex flex-col items-center justify-center py-8",children:[i.jsx("div",{className:"text-sm text-dark-muted mb-2",children:"Health Score"}),i.jsx("div",{className:`text-5xl font-bold ${t()}`,children:e}),i.jsx("div",{className:"text-xs text-dark-muted mt-2",children:"out of 100"})]})}function eg({bySeverity:e}){const t=[{severity:"error",label:"Errors",className:"badge-error"},{severity:"warning",label:"Warnings",className:"badge-warning"},{severity:"info",label:"Info",className:"badge-info"},{severity:"hint",label:"Hints",className:"badge-hint"}];return i.jsxs("div",{className:"card",children:[i.jsx("div",{className:"text-sm text-dark-muted mb-3",children:"Violations by Severity"}),i.jsx("div",{className:"space-y-2",children:t.map(({severity:n,label:r,className:s})=>i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("span",{className:`px-2 py-0.5 rounded text-xs ${s}`,children:r}),i.jsx("span",{className:"font-medium",children:e[n]||0})]},n))})]})}function tg({byStatus:e}){const t=[{status:"discovered",label:"Discovered",className:"badge-discovered"},{status:"approved",label:"Approved",className:"badge-approved"},{status:"ignored",label:"Ignored",className:"badge-ignored"}];return i.jsxs("div",{className:"card",children:[i.jsx("div",{className:"text-sm text-dark-muted mb-3",children:"Patterns by Status"}),i.jsx("div",{className:"space-y-2",children:t.map(({status:n,label:r,className:s})=>i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("span",{className:`px-2 py-0.5 rounded text-xs ${s}`,children:r}),i.jsx("span",{className:"font-medium",children:e[n]||0})]},n))})]})}function ng(){const{realtimeViolations:e}=Lr(),{data:t}=Rh(),n=e.length>0?e.slice(0,5):(t||[]).slice(0,5);return n.length===0?i.jsxs("div",{className:"card",children:[i.jsx("div",{className:"text-sm text-dark-muted mb-3",children:"Recent Violations"}),i.jsx("div",{className:"text-dark-muted text-sm",children:"No violations detected"})]}):i.jsxs("div",{className:"card",children:[i.jsx("div",{className:"text-sm text-dark-muted mb-3",children:"Recent Violations"}),i.jsx("div",{className:"space-y-2",children:n.map(r=>i.jsxs("div",{className:"flex items-start gap-2 p-2 rounded bg-dark-bg/50",children:[i.jsx("span",{className:`px-1.5 py-0.5 rounded text-xs badge-${r.severity}`,children:r.severity}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsx("div",{className:"text-sm truncate",children:r.message}),i.jsx("div",{className:"text-xs text-dark-muted truncate",children:r.file})]})]},r.id))})]})}function rg(){const{data:e,isLoading:t,error:n}=Fv();return t?i.jsx("div",{className:"flex items-center justify-center h-64",children:i.jsx("div",{className:"text-dark-muted",children:"Loading stats..."})}):n||!e?i.jsx("div",{className:"flex items-center justify-center h-64",children:i.jsx("div",{className:"text-severity-error",children:"Failed to load stats"})}):i.jsxs("div",{className:"space-y-6",children:[i.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-4 gap-4",children:[i.jsx(Jv,{score:e.healthScore}),i.jsx(Wl,{label:"Total Patterns",value:e.patterns.total,subtext:`${e.patterns.byStatus.approved||0} approved`}),i.jsx(Wl,{label:"Total Violations",value:e.violations.total,subtext:`${e.violations.bySeverity.error||0} errors`}),i.jsx(Wl,{label:"Files Scanned",value:e.files.scanned,subtext:`of ${e.files.total} total`})]}),i.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[i.jsx(eg,{bySeverity:e.violations.bySeverity}),i.jsx(tg,{byStatus:e.patterns.byStatus}),i.jsx(ng,{})]}),i.jsx("div",{className:"grid grid-cols-1 gap-4",children:i.jsx(Zv,{})}),e.lastScan&&i.jsxs("div",{className:"text-sm text-dark-muted text-center",children:["Last scan: ",new Date(e.lastScan).toLocaleString()]})]})}const Fh=["api","auth","security","errors","logging","data-access","config","testing","performance","components","styling","structural","types","accessibility","documentation","validation","error-handling","other"],on={api:{label:"API Patterns",icon:"🔌",description:"HTTP routes, responses, and API communication patterns",color:"text-blue-400"},auth:{label:"Authentication",icon:"🔐",description:"Login, sessions, permissions, and access control",color:"text-purple-400"},security:{label:"Security",icon:"🛡️",description:"Input validation, sanitization, and security practices",color:"text-red-400"},errors:{label:"Error Handling",icon:"⚠️",description:"Error throwing, catching, and handling patterns",color:"text-orange-400"},logging:{label:"Logging",icon:"📝",description:"Console logs, debug statements, and logging conventions",color:"text-gray-400"},"data-access":{label:"Data Access",icon:"💾",description:"Database queries, ORM usage, and data fetching",color:"text-green-400"},config:{label:"Configuration",icon:"⚙️",description:"Environment variables, settings, and config management",color:"text-slate-400"},testing:{label:"Testing",icon:"🧪",description:"Test structure, mocking patterns, and test utilities",color:"text-cyan-400"},performance:{label:"Performance",icon:"⚡",description:"Caching, memoization, and optimization patterns",color:"text-yellow-400"},components:{label:"Components",icon:"🧩",description:"React component structure, hooks, and state management",color:"text-pink-400"},styling:{label:"Styling",icon:"🎨",description:"CSS classes, design tokens, Tailwind usage, theming",color:"text-fuchsia-400"},structural:{label:"Structural",icon:"📁",description:"File naming, imports, exports, and code organization",color:"text-amber-400"},types:{label:"Types",icon:"📋",description:"TypeScript types, interfaces, and type definitions",color:"text-indigo-400"},accessibility:{label:"Accessibility",icon:"♿",description:"ARIA labels, keyboard navigation, screen reader support",color:"text-teal-400"},documentation:{label:"Documentation",icon:"📚",description:"Comments, JSDoc, README patterns",color:"text-emerald-400"},validation:{label:"Validation",icon:"✅",description:"Input validation, schema validation, and data checks",color:"text-lime-400"},"error-handling":{label:"Error Handling",icon:"🚨",description:"Error boundaries, fallbacks, and recovery patterns",color:"text-rose-400"},other:{label:"Other",icon:"📦",description:"Patterns that don't fit other categories",color:"text-neutral-400"}},tt={discovered:{label:"Discovered",icon:"🔍",color:"text-blue-400",bgColor:"bg-blue-500/10 border-blue-500/20",description:"Newly detected pattern awaiting review"},approved:{label:"Approved",icon:"✓",color:"text-status-approved",bgColor:"bg-status-approved/10 border-status-approved/20",description:"Verified as an intentional pattern"},ignored:{label:"Ignored",icon:"✗",color:"text-dark-muted",bgColor:"bg-dark-muted/10 border-dark-muted/20",description:"Marked as not relevant or false positive"}},Fe={HIGH:.95,MEDIUM:.7,LOW:.5},Ou={high:{label:"High Confidence",color:"text-status-approved",bgColor:"bg-status-approved/10",threshold:Fe.HIGH},medium:{label:"Medium Confidence",color:"text-severity-warning",bgColor:"bg-severity-warning/10",threshold:Fe.MEDIUM},low:{label:"Low Confidence",color:"text-orange-400",bgColor:"bg-orange-400/10",threshold:Fe.LOW},uncertain:{label:"Uncertain",color:"text-severity-error",bgColor:"bg-severity-error/10",threshold:0}},me={LOCATIONS_PREVIEW:20,OUTLIERS_PREVIEW:10,QUICK_REVIEW_LOCATIONS:3,QUICK_REVIEW_OUTLIERS:5,NEEDS_REVIEW_OUTLIERS:15,NEEDS_REVIEW_LOCATIONS:5,REALTIME_VIOLATIONS:100};function Iu(e){if(e.length===0)return{totalLocations:0,totalOutliers:0,avgConfidence:0,minConfidence:0,maxConfidence:0,complianceRate:0};const t=e.reduce((a,o)=>a+o.locationCount,0),n=e.reduce((a,o)=>a+o.outlierCount,0),r=e.map(a=>a.confidence.score),s=r.reduce((a,o)=>a+o,0)/r.length,l=t+n;return{totalLocations:t,totalOutliers:n,avgConfidence:s,minConfidence:Math.min(...r),maxConfidence:Math.max(...r),complianceRate:l>0?t/l:1}}function sg(e){const t={discovered:0,approved:0,ignored:0},n={},r={high:0,medium:0,low:0,uncertain:0};let s=0,l=0,a=0;for(const d of e)t[d.status]++,n[d.category]=(n[d.category]||0)+1,s+=d.outlierCount,l+=d.confidence.score,a+=d.locationCount,d.confidence.score>=Fe.HIGH?r.high++:d.confidence.score>=Fe.MEDIUM?r.medium++:d.confidence.score>=Fe.LOW?r.low++:r.uncertain++;const o=e.filter(d=>d.status==="discovered"),c=o.filter(d=>d.confidence.score<Fe.HIGH).length,u=o.filter(d=>d.confidence.score>=Fe.HIGH).length,h=a+s;return{total:e.length,byStatus:t,byCategory:n,byConfidenceLevel:r,needsReview:c,readyForApproval:u,totalOutliers:s,avgConfidence:e.length>0?l/e.length:0,complianceRate:h>0?a/h:1}}function ig(e){return e.replace(/ Detector$/,"").replace(/ Pattern$/,"").trim()}function lg(e){return e.has("approved")?"approved":e.has("ignored")?"ignored":"discovered"}function ag(e){const t=new Map;for(const r of e){const s=r.category;t.has(s)||t.set(s,new Map);const l=t.get(s),a=ig(r.name);l.has(a)||l.set(a,[]),l.get(a).push(r)}const n=[];for(const r of Fh){const s=t.get(r);if(!s||s.size===0)continue;const l=on[r],a=[];for(const[c,u]of s){const h=Iu(u),d=new Set(u.map(f=>f.status));a.push({id:`${r}-${c}`,detectorName:c,category:r,patterns:u,metrics:h,statuses:d,dominantStatus:lg(d)})}a.sort((c,u)=>u.metrics.totalLocations-c.metrics.totalLocations);const o=Iu(a.flatMap(c=>c.patterns));n.push({category:r,label:l.label,description:l.description,icon:l.icon,detectors:a,metrics:o,patternCount:a.reduce((c,u)=>c+u.patterns.length,0)})}return n}function og(e,t){const n=[...e],r=t.direction==="asc"?1:-1;return n.sort((s,l)=>{switch(t.field){case"name":return r*s.name.localeCompare(l.name);case"confidence":return r*(s.confidence.score-l.confidence.score);case"locations":return r*(s.locationCount-l.locationCount);case"outliers":return r*(s.outlierCount-l.outlierCount);case"status":return r*s.status.localeCompare(l.status);case"category":return r*s.category.localeCompare(l.category);default:return 0}}),n}function Mh(e,t){const n=Fe.HIGH;return e.filter(s=>s.status!=="discovered"?!1:t==="quick"?s.confidence.score>=n:s.confidence.score<n).map(s=>({...s,reviewPriority:cg(s,t),reviewReason:ug(s,t)})).sort((s,l)=>l.reviewPriority-s.reviewPriority)}function cg(e,t){return t==="quick"?e.confidence.score*100+e.locationCount:e.outlierCount*10+(1-e.confidence.score)*100}function ug(e,t){if(t==="quick")return`${Math.round(e.confidence.score*100)}% confidence with ${e.locationCount} consistent locations`;const n=[];return e.confidence.score<Fe.MEDIUM&&n.push("low confidence"),e.outlierCount>0&&n.push(`${e.outlierCount} outliers`),n.length>0?n.join(", "):"needs manual verification"}function dg(e){return e>=Fe.HIGH?"high":e>=Fe.MEDIUM?"medium":e>=Fe.LOW?"low":"uncertain"}function dn(e){switch(dg(e)){case"high":return"text-status-approved";case"medium":return"text-severity-warning";case"low":return"text-orange-400";case"uncertain":return"text-severity-error"}}function Ie(e){return`${Math.round(e*100)}%`}function Lh(e,t=50){if(e.length<=t)return e;const r=e.split("/").pop()||"";return r.length>=t-3?"..."+r.slice(-(t-3)):".../"+r}function ii({label:e,value:t,subValue:n,icon:r,color:s="text-dark-text"}){return i.jsxs("div",{className:"p-4 bg-dark-surface border border-dark-border rounded-lg",children:[i.jsxs("div",{className:"flex items-center justify-between mb-2",children:[i.jsx("span",{className:"text-xs text-dark-muted uppercase tracking-wide",children:e}),r&&i.jsx("span",{className:"text-lg",children:r})]}),i.jsx("div",{className:`text-2xl font-semibold ${s}`,children:t}),n&&i.jsx("div",{className:"text-xs text-dark-muted mt-1",children:n})]})}function fg({byStatus:e,total:t}){return i.jsxs("div",{className:"p-4 bg-dark-surface border border-dark-border rounded-lg",children:[i.jsx("div",{className:"text-xs text-dark-muted uppercase tracking-wide mb-3",children:"By Status"}),i.jsx("div",{className:"space-y-2",children:Object.entries(e).map(([n,r])=>{const s=tt[n],l=t>0?r/t*100:0;return i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("span",{className:"text-sm w-6",children:s==null?void 0:s.icon}),i.jsxs("div",{className:"flex-1",children:[i.jsxs("div",{className:"flex items-center justify-between text-sm mb-1",children:[i.jsx("span",{className:s==null?void 0:s.color,children:(s==null?void 0:s.label)||n}),i.jsx("span",{className:"text-dark-muted",children:r})]}),i.jsx("div",{className:"h-1.5 bg-dark-bg rounded-full overflow-hidden",children:i.jsx("div",{className:`h-full rounded-full transition-all ${n==="approved"?"bg-status-approved":n==="ignored"?"bg-dark-muted":"bg-blue-500"}`,style:{width:`${l}%`}})})]})]},n)})})]})}function hg({byConfidenceLevel:e,total:t}){const n=["high","medium","low","uncertain"];return i.jsxs("div",{className:"p-4 bg-dark-surface border border-dark-border rounded-lg",children:[i.jsx("div",{className:"text-xs text-dark-muted uppercase tracking-wide mb-3",children:"By Confidence"}),i.jsx("div",{className:"flex gap-1 h-8 rounded overflow-hidden",children:n.map(r=>{const s=e[r],l=t>0?s/t*100:0,a=Ou[r];return l===0?null:i.jsx("div",{className:`${a.bgColor} flex items-center justify-center transition-all`,style:{width:`${l}%`},title:`${a.label}: ${s} (${Math.round(l)}%)`,children:l>15&&i.jsx("span",{className:`text-xs font-medium ${a.color}`,children:s})},r)})}),i.jsx("div",{className:"flex justify-between mt-2 text-xs",children:n.map(r=>{const s=Ou[r];return e[r]===0?null:i.jsxs("div",{className:"flex items-center gap-1",children:[i.jsx("div",{className:`w-2 h-2 rounded-full ${s.bgColor}`}),i.jsx("span",{className:"text-dark-muted",children:s.label.split(" ")[0]})]},r)})})]})}function mg({statistics:e,onQuickReview:t,onNeedsReview:n}){return i.jsxs("div",{className:"space-y-4",children:[i.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[i.jsx(ii,{label:"Total Patterns",value:e.total,icon:"📊"}),i.jsx(ii,{label:"Compliance Rate",value:Ie(e.complianceRate),subValue:`${e.totalOutliers} outliers`,icon:"✓",color:e.complianceRate>=.9?"text-status-approved":"text-severity-warning"}),i.jsx(ii,{label:"Avg Confidence",value:Ie(e.avgConfidence),icon:"🎯",color:e.avgConfidence>=.8?"text-status-approved":"text-severity-warning"}),i.jsx(ii,{label:"Categories",value:Object.keys(e.byCategory).length,icon:"📁"})]}),(e.readyForApproval>0||e.needsReview>0)&&i.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[e.readyForApproval>0&&i.jsx("button",{onClick:t,className:"p-4 bg-status-approved/10 border border-status-approved/20 rounded-lg text-left hover:bg-status-approved/20 transition-colors group",children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("div",{className:"text-sm font-medium text-status-approved",children:"⚡ Quick Approve"}),i.jsxs("div",{className:"text-xs text-dark-muted mt-1",children:[e.readyForApproval," high-confidence patterns ready"]})]}),i.jsx("span",{className:"text-2xl font-semibold text-status-approved group-hover:scale-110 transition-transform",children:e.readyForApproval})]})}),e.needsReview>0&&i.jsx("button",{onClick:n,className:"p-4 bg-severity-warning/10 border border-severity-warning/20 rounded-lg text-left hover:bg-severity-warning/20 transition-colors group",children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("div",{className:"text-sm font-medium text-severity-warning",children:"🔍 Needs Review"}),i.jsxs("div",{className:"text-xs text-dark-muted mt-1",children:[e.needsReview," patterns need attention"]})]}),i.jsx("span",{className:"text-2xl font-semibold text-severity-warning group-hover:scale-110 transition-transform",children:e.needsReview})]})})]}),i.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[i.jsx(fg,{byStatus:e.byStatus,total:e.total}),i.jsx(hg,{byConfidenceLevel:e.byConfidenceLevel,total:e.total})]})]})}function pg({filters:e,onFiltersChange:t,viewMode:n,onViewModeChange:r,sort:s,onSortChange:l,resultCount:a}){var u,h,d,f,m;const o=()=>{t({})},c=!!(e.category||e.status||e.minConfidence||e.search);return i.jsxs("div",{className:"space-y-3",children:[i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsxs("div",{className:"relative flex-1",children:[i.jsx("input",{type:"text",placeholder:"Search patterns...",className:"w-full bg-dark-bg border border-dark-border rounded-lg px-4 py-2 pl-10 text-sm focus:outline-none focus:border-blue-500 transition-colors",value:e.search||"",onChange:y=>t({...e,search:y.target.value||void 0})}),i.jsx("span",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-dark-muted",children:"🔍"})]}),i.jsx("div",{className:"flex bg-dark-bg border border-dark-border rounded-lg p-0.5",children:["grouped","flat","table"].map(y=>i.jsx("button",{onClick:()=>r(y),className:`px-3 py-1.5 text-sm rounded-md transition-colors ${n===y?"bg-blue-500/20 text-blue-400":"text-dark-muted hover:text-dark-text"}`,title:`${y.charAt(0).toUpperCase()+y.slice(1)} view`,children:y==="grouped"?"📁":y==="flat"?"📋":"📊"},y))})]}),i.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[i.jsxs("select",{className:"bg-dark-bg border border-dark-border rounded-lg px-3 py-2 text-sm focus:outline-none focus:border-blue-500",value:e.category||"",onChange:y=>t({...e,category:y.target.value||void 0}),children:[i.jsx("option",{value:"",children:"All Categories"}),Fh.map(y=>{const N=on[y];return i.jsxs("option",{value:y,children:[N.icon," ",N.label]},y)})]}),i.jsxs("select",{className:"bg-dark-bg border border-dark-border rounded-lg px-3 py-2 text-sm focus:outline-none focus:border-blue-500",value:e.status||"",onChange:y=>t({...e,status:y.target.value||void 0}),children:[i.jsx("option",{value:"",children:"All Statuses"}),Object.entries(tt).map(([y,N])=>i.jsxs("option",{value:y,children:[N.icon," ",N.label]},y))]}),i.jsxs("select",{className:"bg-dark-bg border border-dark-border rounded-lg px-3 py-2 text-sm focus:outline-none focus:border-blue-500",value:((u=e.minConfidence)==null?void 0:u.toString())||"",onChange:y=>t({...e,minConfidence:y.target.value?parseFloat(y.target.value):void 0}),children:[i.jsx("option",{value:"",children:"Any Confidence"}),i.jsx("option",{value:"0.95",children:"High (≥95%)"}),i.jsx("option",{value:"0.70",children:"Medium+ (≥70%)"}),i.jsx("option",{value:"0.50",children:"Low+ (≥50%)"})]}),i.jsxs("div",{className:"flex items-center gap-1 ml-auto",children:[i.jsx("span",{className:"text-xs text-dark-muted",children:"Sort:"}),i.jsxs("select",{className:"bg-dark-bg border border-dark-border rounded-lg px-2 py-1.5 text-sm focus:outline-none focus:border-blue-500",value:s.field,onChange:y=>l({...s,field:y.target.value}),children:[i.jsx("option",{value:"confidence",children:"Confidence"}),i.jsx("option",{value:"locations",children:"Locations"}),i.jsx("option",{value:"outliers",children:"Outliers"}),i.jsx("option",{value:"name",children:"Name"}),i.jsx("option",{value:"category",children:"Category"}),i.jsx("option",{value:"status",children:"Status"})]}),i.jsx("button",{onClick:()=>l({...s,direction:s.direction==="asc"?"desc":"asc"}),className:"p-1.5 bg-dark-bg border border-dark-border rounded-lg text-sm hover:bg-dark-border/50 transition-colors",title:s.direction==="asc"?"Ascending":"Descending",children:s.direction==="asc"?"↑":"↓"})]})]}),i.jsxs("div",{className:"flex items-center justify-between text-sm",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("span",{className:"text-dark-muted",children:[a," pattern",a!==1?"s":""]}),c&&i.jsxs(i.Fragment,{children:[i.jsx("span",{className:"text-dark-border",children:"•"}),i.jsx("button",{onClick:o,className:"text-blue-400 hover:text-blue-300 transition-colors",children:"Clear filters"})]})]}),c&&i.jsxs("div",{className:"flex items-center gap-2",children:[e.category&&i.jsxs("span",{className:"px-2 py-0.5 bg-dark-bg border border-dark-border rounded text-xs",children:[(h=on[e.category])==null?void 0:h.icon," ",(d=on[e.category])==null?void 0:d.label,i.jsx("button",{onClick:()=>t({...e,category:void 0}),className:"ml-1 text-dark-muted hover:text-dark-text",children:"×"})]}),e.status&&i.jsxs("span",{className:"px-2 py-0.5 bg-dark-bg border border-dark-border rounded text-xs",children:[(f=tt[e.status])==null?void 0:f.icon," ",(m=tt[e.status])==null?void 0:m.label,i.jsx("button",{onClick:()=>t({...e,status:void 0}),className:"ml-1 text-dark-muted hover:text-dark-text",children:"×"})]}),e.minConfidence&&i.jsxs("span",{className:"px-2 py-0.5 bg-dark-bg border border-dark-border rounded text-xs",children:["≥",Math.round(e.minConfidence*100),"%",i.jsx("button",{onClick:()=>t({...e,minConfidence:void 0}),className:"ml-1 text-dark-muted hover:text-dark-text",children:"×"})]})]})]})]})}function xg({pattern:e,isSelected:t,onSelect:n}){const r=tt[e.status],s=on[e.category],l=dn(e.confidence.score);return i.jsx("button",{onClick:n,className:`w-full text-left p-3 rounded-lg border transition-all ${t?"bg-blue-500/10 border-blue-500/30":"bg-dark-surface border-dark-border hover:border-dark-muted"}`,children:i.jsxs("div",{className:"flex items-center justify-between gap-4",children:[i.jsxs("div",{className:"flex items-center gap-3 min-w-0 flex-1",children:[i.jsx("span",{className:"text-lg shrink-0",children:s==null?void 0:s.icon}),i.jsxs("div",{className:"min-w-0",children:[i.jsx("div",{className:"font-medium truncate",children:e.name}),i.jsx("div",{className:"text-xs text-dark-muted",children:s==null?void 0:s.label})]})]}),i.jsxs("div",{className:"flex items-center gap-4 shrink-0",children:[i.jsxs("div",{className:"text-right",children:[i.jsx("div",{className:`text-sm font-medium ${l}`,children:Ie(e.confidence.score)}),i.jsx("div",{className:"text-xs text-dark-muted",children:"confidence"})]}),i.jsxs("div",{className:"text-right",children:[i.jsx("div",{className:"text-sm font-medium text-status-approved",children:e.locationCount}),i.jsx("div",{className:"text-xs text-dark-muted",children:"locations"})]}),e.outlierCount>0&&i.jsxs("div",{className:"text-right",children:[i.jsx("div",{className:"text-sm font-medium text-severity-warning",children:e.outlierCount}),i.jsx("div",{className:"text-xs text-dark-muted",children:"outliers"})]}),i.jsxs("span",{className:`px-2 py-1 rounded text-xs ${r==null?void 0:r.bgColor} ${r==null?void 0:r.color}`,children:[r==null?void 0:r.icon," ",r==null?void 0:r.label]})]})]})})}function vg({group:e,isExpanded:t,onToggle:n,selectedPatternId:r,onSelectPattern:s}){const l=tt[e.dominantStatus],a=dn(e.metrics.avgConfidence);return i.jsxs("div",{className:"border border-dark-border rounded-lg overflow-hidden",children:[i.jsxs("button",{onClick:n,className:"w-full text-left p-4 bg-dark-surface hover:bg-dark-border/30 transition-colors",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("span",{className:"text-dark-muted text-sm",children:t?"▼":"▶"}),i.jsx("span",{className:"font-medium",children:e.detectorName}),e.patterns.length>1&&i.jsxs("span",{className:"px-2 py-0.5 bg-dark-bg rounded text-xs text-dark-muted",children:[e.patterns.length," variants"]})]}),i.jsxs("span",{className:`px-2 py-1 rounded text-xs ${l==null?void 0:l.bgColor} ${l==null?void 0:l.color}`,children:[l==null?void 0:l.icon," ",l==null?void 0:l.label]})]}),i.jsxs("div",{className:"flex items-center gap-6 mt-3 ml-7 text-sm",children:[i.jsxs("div",{className:"flex items-center gap-1.5",children:[i.jsx("span",{className:"text-status-approved",children:"✓"}),i.jsxs("span",{className:"text-dark-muted",children:[e.metrics.totalLocations," consistent"]})]}),e.metrics.totalOutliers>0&&i.jsxs("div",{className:"flex items-center gap-1.5",children:[i.jsx("span",{className:"text-severity-warning",children:"⚠"}),i.jsxs("span",{className:"text-dark-muted",children:[e.metrics.totalOutliers," outliers"]})]}),i.jsxs("div",{className:"flex items-center gap-1.5",children:[i.jsx("span",{className:a,children:Ie(e.metrics.avgConfidence)}),i.jsx("span",{className:"text-dark-muted",children:"confidence"})]})]})]}),t&&i.jsx("div",{className:"border-t border-dark-border bg-dark-bg p-2 space-y-1",children:e.patterns.map(o=>{var c,u,h;return i.jsxs("button",{onClick:()=>s(o.id),className:`w-full text-left p-3 rounded-lg transition-colors ${r===o.id?"bg-blue-500/20 text-blue-400":"hover:bg-dark-border/50"}`,children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("span",{className:"truncate font-medium",children:o.name}),i.jsx("span",{className:`px-2 py-0.5 rounded text-xs ${(c=tt[o.status])==null?void 0:c.bgColor} ${(u=tt[o.status])==null?void 0:u.color}`,children:(h=tt[o.status])==null?void 0:h.label})]}),i.jsxs("div",{className:"flex items-center gap-4 mt-2 text-xs text-dark-muted",children:[i.jsxs("span",{className:"text-status-approved",children:["✓ ",o.locationCount]}),o.outlierCount>0&&i.jsxs("span",{className:"text-severity-warning",children:["⚠ ",o.outlierCount]}),i.jsx("span",{className:dn(o.confidence.score),children:Ie(o.confidence.score)})]})]},o.id)})})]})}function gg({group:e,expandedDetectors:t,onToggleDetector:n,selectedPatternId:r,onSelectPattern:s}){const[l,a]=S.useState(!1),o=on[e.category];return i.jsxs("div",{className:"mb-6",children:[i.jsxs("button",{onClick:()=>a(!l),className:"w-full text-left group",children:[i.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[i.jsx("span",{className:"text-dark-muted text-sm",children:l?"▶":"▼"}),i.jsx("span",{className:"text-xl",children:o==null?void 0:o.icon}),i.jsx("span",{className:"text-lg font-semibold group-hover:text-blue-400 transition-colors",children:o==null?void 0:o.label}),i.jsx("span",{className:"px-2 py-0.5 bg-dark-bg rounded text-xs text-dark-muted",children:e.patternCount})]}),i.jsx("p",{className:"text-xs text-dark-muted ml-10 mb-2",children:o==null?void 0:o.description}),i.jsxs("div",{className:"flex items-center gap-4 text-xs ml-10",children:[i.jsxs("span",{className:"text-dark-muted",children:[e.detectors.length," detector",e.detectors.length!==1?"s":""]}),i.jsxs("span",{className:"text-status-approved",children:["✓ ",e.metrics.totalLocations," consistent"]}),e.metrics.totalOutliers>0&&i.jsxs("span",{className:"text-severity-warning",children:["⚠ ",e.metrics.totalOutliers," outliers"]})]})]}),!l&&i.jsx("div",{className:"space-y-2 ml-6 mt-4",children:e.detectors.map(c=>i.jsx(vg,{group:c,isExpanded:t.has(c.id),onToggle:()=>n(c.id),selectedPatternId:r,onSelectPattern:s},c.id))})]})}function yg({patterns:e,groupedPatterns:t,viewMode:n,expandedDetectors:r,onToggleDetector:s,selectedPatternId:l,onSelectPattern:a}){return e.length===0?i.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-center",children:[i.jsx("span",{className:"text-4xl mb-4",children:"🔍"}),i.jsx("h3",{className:"text-lg font-medium mb-2",children:"No patterns found"}),i.jsx("p",{className:"text-dark-muted text-sm max-w-md",children:"Try adjusting your filters or run a scan to detect patterns in your codebase."})]}):n==="flat"?i.jsx("div",{className:"space-y-2",children:e.map(o=>i.jsx(xg,{pattern:o,isSelected:l===o.id,onSelect:()=>a(o.id)},o.id))}):n==="table"?i.jsx("div",{className:"overflow-x-auto",children:i.jsxs("table",{className:"w-full text-sm",children:[i.jsx("thead",{children:i.jsxs("tr",{className:"border-b border-dark-border text-left",children:[i.jsx("th",{className:"pb-3 font-medium text-dark-muted",children:"Pattern"}),i.jsx("th",{className:"pb-3 font-medium text-dark-muted",children:"Category"}),i.jsx("th",{className:"pb-3 font-medium text-dark-muted text-right",children:"Confidence"}),i.jsx("th",{className:"pb-3 font-medium text-dark-muted text-right",children:"Locations"}),i.jsx("th",{className:"pb-3 font-medium text-dark-muted text-right",children:"Outliers"}),i.jsx("th",{className:"pb-3 font-medium text-dark-muted",children:"Status"})]})}),i.jsx("tbody",{children:e.map(o=>{const c=tt[o.status],u=on[o.category];return i.jsxs("tr",{onClick:()=>a(o.id),className:`border-b border-dark-border/50 cursor-pointer transition-colors ${l===o.id?"bg-blue-500/10":"hover:bg-dark-surface"}`,children:[i.jsx("td",{className:"py-3 font-medium",children:o.name}),i.jsx("td",{className:"py-3",children:i.jsxs("span",{className:"flex items-center gap-2",children:[i.jsx("span",{children:u==null?void 0:u.icon}),i.jsx("span",{className:"text-dark-muted",children:u==null?void 0:u.label})]})}),i.jsx("td",{className:`py-3 text-right ${dn(o.confidence.score)}`,children:Ie(o.confidence.score)}),i.jsx("td",{className:"py-3 text-right text-status-approved",children:o.locationCount}),i.jsx("td",{className:`py-3 text-right ${o.outlierCount>0?"text-severity-warning":"text-dark-muted"}`,children:o.outlierCount}),i.jsx("td",{className:"py-3",children:i.jsx("span",{className:`px-2 py-1 rounded text-xs ${c==null?void 0:c.bgColor} ${c==null?void 0:c.color}`,children:c==null?void 0:c.label})})]},o.id)})})]})}):i.jsx("div",{children:t.map(o=>i.jsx(gg,{group:o,expandedDetectors:r,onToggleDetector:s,selectedPatternId:l,onSelectPattern:a},o.category))})}function Ru({location:e,variant:t}){const n=t==="outlier",r=e.file.split("/").pop()||e.file;return i.jsx("div",{className:`p-3 rounded-lg text-sm ${n?"bg-severity-warning/10 border border-severity-warning/20":"bg-dark-bg"}`,children:i.jsxs("div",{className:"flex items-start gap-2",children:[i.jsx("span",{className:`shrink-0 ${n?"text-severity-warning":"text-status-approved"}`,children:n?"⚠":"✓"}),i.jsxs("div",{className:"min-w-0 flex-1",children:[i.jsx("div",{className:"font-medium truncate",title:e.file,children:r}),i.jsx("div",{className:"text-xs text-dark-muted truncate",title:e.file,children:Lh(e.file)}),e.name&&i.jsxs("div",{className:"text-xs text-blue-400 mt-1",children:[e.kind&&i.jsxs("span",{className:"text-dark-muted",children:[e.kind,": "]}),e.name]}),e.reason&&i.jsx("div",{className:`text-xs mt-1 ${n?"text-severity-warning":"text-dark-muted"}`,children:e.reason}),i.jsxs("div",{className:"text-xs text-dark-muted mt-1",children:["Line ",e.range.start.line]})]})]})})}function jg({pattern:e,onCopyForAI:t,isCopying:n,copySuccess:r}){const s=Oh(),l=Ih(),a=Lv(),o=()=>{confirm("Are you sure you want to delete this pattern? This action cannot be undone.")&&a.mutate(e.id)};return i.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.status==="discovered"&&i.jsxs(i.Fragment,{children:[i.jsxs("button",{onClick:()=>s.mutate(e.id),disabled:s.isPending,className:"btn btn-primary text-sm flex items-center gap-1.5",children:[s.isPending?i.jsx("span",{className:"animate-spin",children:"⏳"}):i.jsx("span",{children:"✓"}),"Approve"]}),i.jsxs("button",{onClick:()=>l.mutate(e.id),disabled:l.isPending,className:"btn btn-secondary text-sm flex items-center gap-1.5",children:[l.isPending?i.jsx("span",{className:"animate-spin",children:"⏳"}):i.jsx("span",{children:"✗"}),"Ignore"]})]}),i.jsxs("button",{onClick:t,disabled:n,className:`btn text-sm flex items-center gap-1.5 ${r?"btn-primary":"btn-secondary"}`,children:[n?i.jsx("span",{className:"animate-spin",children:"⏳"}):r?i.jsx("span",{children:"✓"}):i.jsx("span",{children:"📋"}),r?"Copied!":"Copy for AI"]}),i.jsxs("button",{onClick:o,disabled:a.isPending,className:"btn btn-danger text-sm flex items-center gap-1.5 ml-auto",children:[a.isPending?i.jsx("span",{className:"animate-spin",children:"⏳"}):i.jsx("span",{children:"🗑️"}),"Delete"]})]})}function Ng({pattern:e}){const t=dn(e.confidence.score),n=e.locations.length/(e.locations.length+e.outliers.length);return i.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[i.jsxs("div",{className:"p-3 bg-dark-bg rounded-lg",children:[i.jsx("div",{className:"text-xs text-dark-muted mb-1",children:"Confidence"}),i.jsx("div",{className:`text-xl font-semibold ${t}`,children:Ie(e.confidence.score)}),i.jsx("div",{className:"text-xs text-dark-muted capitalize",children:e.confidence.level})]}),i.jsxs("div",{className:"p-3 bg-dark-bg rounded-lg",children:[i.jsx("div",{className:"text-xs text-dark-muted mb-1",children:"Compliance"}),i.jsx("div",{className:`text-xl font-semibold ${n>=.9?"text-status-approved":"text-severity-warning"}`,children:Ie(n)}),i.jsxs("div",{className:"text-xs text-dark-muted",children:[e.locations.length," / ",e.locations.length+e.outliers.length]})]}),i.jsxs("div",{className:"p-3 bg-status-approved/10 rounded-lg",children:[i.jsx("div",{className:"text-xs text-dark-muted mb-1",children:"Consistent"}),i.jsx("div",{className:"text-xl font-semibold text-status-approved",children:e.locations.length}),i.jsx("div",{className:"text-xs text-dark-muted",children:"locations"})]}),e.outliers.length>0&&i.jsxs("div",{className:"p-3 bg-severity-warning/10 rounded-lg",children:[i.jsx("div",{className:"text-xs text-dark-muted mb-1",children:"Outliers"}),i.jsx("div",{className:"text-xl font-semibold text-severity-warning",children:e.outliers.length}),i.jsx("div",{className:"text-xs text-dark-muted",children:"need fixing"})]})]})}function bg({patternId:e}){const{data:t,isLoading:n,error:r}=_h(e),[s,l]=S.useState(!1),[a,o]=S.useState(!1),c=async()=>{if(t){l(!0),o(!1);try{const d=[`# Pattern: ${t.name}`,`Category: ${t.category} | Status: ${t.status} | Confidence: ${Ie(t.confidence.score)}`,""];if(t.locations.length>0){d.push(`## Established Pattern (${t.locations.length} locations)`),d.push("These files follow the pattern correctly:"),d.push("");const f=t.locations.slice(0,me.QUICK_REVIEW_LOCATIONS);for(const m of f)try{const y=await fetch(`/api/snippet?file=${encodeURIComponent(m.file)}&line=${m.range.start.line}&context=2`);if(y.ok){const N=await y.json();d.push(`### ${m.file}:${m.range.start.line}`),d.push("```"+N.language),d.push(N.code),d.push("```"),d.push("")}}catch{d.push(`- ${m.file}:${m.range.start.line}`)}t.locations.length>me.QUICK_REVIEW_LOCATIONS&&(d.push(`... and ${t.locations.length-me.QUICK_REVIEW_LOCATIONS} more locations`),d.push(""))}if(t.outliers.length>0){d.push(`## ⚠️ Outliers to Fix (${t.outliers.length} violations)`),d.push("These files deviate from the established pattern:"),d.push("");const f=t.outliers.slice(0,me.QUICK_REVIEW_OUTLIERS);for(const m of f)try{const y=await fetch(`/api/snippet?file=${encodeURIComponent(m.file)}&line=${m.range.start.line}&context=3`);if(y.ok){const N=await y.json();d.push(`### ${m.file}:${m.range.start.line}`),m.reason&&d.push(`Reason: ${m.reason}`),d.push("```"+N.language),d.push(N.code),d.push("```"),d.push("")}}catch{d.push(`- ${m.file}:${m.range.start.line}${m.reason?` - ${m.reason}`:""}`)}t.outliers.length>me.QUICK_REVIEW_OUTLIERS&&(d.push(`... and ${t.outliers.length-me.QUICK_REVIEW_OUTLIERS} more outliers`),d.push("")),d.push("---"),d.push("Please fix these outliers to match the established pattern shown above.")}await navigator.clipboard.writeText(d.join(`
|
|
57
57
|
`)),o(!0),setTimeout(()=>o(!1),2e3)}catch(d){console.error("Failed to copy:",d)}finally{l(!1)}}};if(n)return i.jsx("div",{className:"flex items-center justify-center py-12",children:i.jsx("div",{className:"text-dark-muted",children:"Loading pattern details..."})});if(r||!t)return i.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[i.jsx("span",{className:"text-3xl mb-3",children:"⚠️"}),i.jsx("div",{className:"text-severity-error",children:"Failed to load pattern"}),i.jsx("div",{className:"text-xs text-dark-muted mt-1",children:"Pattern may have been deleted"})]});const u=tt[t.status],h=on[t.category];return i.jsxs("div",{className:"space-y-5",children:[i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-start justify-between gap-3",children:[i.jsx("h3",{className:"text-lg font-semibold leading-tight",children:t.name}),i.jsxs("span",{className:`px-2 py-1 rounded text-xs shrink-0 ${u==null?void 0:u.bgColor} ${u==null?void 0:u.color}`,children:[u==null?void 0:u.icon," ",u==null?void 0:u.label]})]}),i.jsxs("div",{className:"flex items-center gap-2 mt-2 text-sm text-dark-muted",children:[i.jsx("span",{children:h==null?void 0:h.icon}),i.jsx("span",{children:h==null?void 0:h.label})]})]}),i.jsx(jg,{pattern:t,onCopyForAI:c,isCopying:s,copySuccess:a}),i.jsx(Ng,{pattern:t}),i.jsxs("div",{children:[i.jsxs("h4",{className:"text-sm font-medium mb-3 flex items-center gap-2",children:[i.jsx("span",{className:"text-status-approved",children:"✓"}),"Consistent Locations (",t.locations.length,")"]}),i.jsxs("div",{className:"space-y-2 max-h-48 overflow-y-auto scrollbar-dark",children:[t.locations.slice(0,me.LOCATIONS_PREVIEW).map((d,f)=>i.jsx(Ru,{location:d,variant:"consistent"},f)),t.locations.length>me.LOCATIONS_PREVIEW&&i.jsxs("div",{className:"text-xs text-dark-muted text-center py-2",children:["... and ",t.locations.length-me.LOCATIONS_PREVIEW," more"]})]})]}),t.outliers.length>0&&i.jsxs("div",{children:[i.jsxs("h4",{className:"text-sm font-medium mb-3 flex items-center gap-2 text-severity-warning",children:[i.jsx("span",{children:"⚠"}),"Outliers (",t.outliers.length,")"]}),i.jsxs("div",{className:"space-y-2 max-h-48 overflow-y-auto scrollbar-dark",children:[t.outliers.slice(0,me.OUTLIERS_PREVIEW).map((d,f)=>i.jsx(Ru,{location:d,variant:"outlier"},f)),t.outliers.length>me.OUTLIERS_PREVIEW&&i.jsxs("div",{className:"text-xs text-dark-muted text-center py-2",children:["... and ",t.outliers.length-me.OUTLIERS_PREVIEW," more"]})]})]})]})}function kg(){return i.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[i.jsx("span",{className:"text-4xl mb-4",children:"📋"}),i.jsx("h3",{className:"text-lg font-medium mb-2",children:"No pattern selected"}),i.jsx("p",{className:"text-dark-muted text-sm max-w-xs",children:"Select a pattern from the list to view its details, locations, and outliers."})]})}function Dh({title:e,subtitle:t,onClose:n,children:r,footer:s}){return i.jsx("div",{className:"fixed inset-0 bg-black/60 flex items-center justify-center z-50 p-4",children:i.jsxs("div",{className:"bg-dark-surface border border-dark-border rounded-xl w-full max-w-5xl max-h-[90vh] overflow-hidden flex flex-col shadow-2xl",children:[i.jsx("div",{className:"p-5 border-b border-dark-border",children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("h2",{className:"text-xl font-semibold",children:e}),i.jsx("p",{className:"text-sm text-dark-muted mt-1",children:t})]}),i.jsx("button",{onClick:n,className:"p-2 text-dark-muted hover:text-dark-text hover:bg-dark-border/50 rounded-lg transition-colors",children:i.jsx("span",{className:"text-xl",children:"✕"})})]})}),i.jsx("div",{className:"flex-1 overflow-hidden",children:r}),s&&i.jsx("div",{className:"p-4 border-t border-dark-border bg-dark-bg",children:s})]})})}function $h({icon:e,title:t,message:n,onClose:r}){return i.jsx("div",{className:"fixed inset-0 bg-black/60 flex items-center justify-center z-50 p-4",children:i.jsxs("div",{className:"bg-dark-surface border border-dark-border rounded-xl p-8 max-w-md text-center",children:[i.jsx("span",{className:"text-5xl mb-4 block",children:e}),i.jsx("h2",{className:"text-xl font-semibold mb-3",children:t}),i.jsx("p",{className:"text-dark-muted mb-6",children:n}),i.jsx("button",{onClick:r,className:"btn btn-secondary w-full",children:"Close"})]})})}function wg({patterns:e,onClose:t}){const n=Dv(),[r,s]=S.useState(new Set),[l,a]=S.useState(0),o=S.useMemo(()=>Mh(e,"quick"),[e]),c=o.filter(f=>!r.has(f.id)),u=o[l],h=f=>{s(m=>{const y=new Set(m);return y.has(f)?y.delete(f):y.add(f),y})},d=async()=>{const f=c.map(m=>m.id);f.length!==0&&(await n.mutateAsync(f),t())};return o.length===0?i.jsx($h,{icon:"⚡",title:"Quick Review",message:"No high-confidence patterns (≥95%) need review. All patterns either need manual review or are already approved.",onClose:t}):i.jsx(Dh,{title:"⚡ Quick Review",subtitle:`${o.length} high-confidence patterns (≥95%) ready for approval`,onClose:t,footer:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"text-sm",children:[i.jsx("span",{className:"text-dark-muted",children:"Selected: "}),i.jsx("span",{className:"font-semibold text-status-approved",children:c.length}),i.jsxs("span",{className:"text-dark-muted",children:[" of ",o.length]})]}),i.jsxs("div",{className:"flex gap-3",children:[i.jsx("button",{onClick:t,className:"btn btn-secondary",children:"Cancel"}),i.jsx("button",{onClick:d,disabled:c.length===0||n.isPending,className:"btn btn-primary",children:n.isPending?"⏳ Approving...":`✓ Approve ${c.length} Patterns`})]})]}),children:i.jsxs("div",{className:"flex h-[60vh]",children:[i.jsx("div",{className:"w-80 border-r border-dark-border overflow-y-auto",children:i.jsx("div",{className:"p-3 space-y-1",children:o.map((f,m)=>i.jsx("button",{onClick:()=>a(m),className:`w-full text-left p-3 rounded-lg transition-colors ${l===m?"bg-blue-500/20 border border-blue-500/30":r.has(f.id)?"bg-dark-bg/50 opacity-50":"hover:bg-dark-border/50 border border-transparent"}`,children:i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("input",{type:"checkbox",checked:!r.has(f.id),onChange:()=>h(f.id),onClick:y=>y.stopPropagation(),className:"rounded border-dark-border"}),i.jsxs("div",{className:"min-w-0 flex-1",children:[i.jsx("div",{className:`font-medium truncate ${r.has(f.id)?"line-through":""}`,children:f.name}),i.jsxs("div",{className:"flex items-center gap-2 mt-1 text-xs",children:[i.jsx("span",{className:"text-status-approved",children:Ie(f.confidence.score)}),i.jsx("span",{className:"text-dark-muted",children:"•"}),i.jsxs("span",{className:"text-dark-muted",children:[f.locationCount," locations"]})]})]})]})},f.id))})}),i.jsx("div",{className:"flex-1 overflow-y-auto p-5",children:u&&i.jsxs("div",{className:"space-y-5",children:[i.jsxs("div",{className:"flex items-start justify-between",children:[i.jsxs("div",{children:[i.jsx("h3",{className:"text-lg font-semibold",children:u.name}),i.jsxs("div",{className:"flex items-center gap-2 mt-1 text-sm text-dark-muted",children:[i.jsx("span",{children:u.category}),i.jsx("span",{children:"•"}),i.jsxs("span",{className:"text-status-approved font-medium",children:[Ie(u.confidence.score)," confidence"]})]}),i.jsx("div",{className:"text-xs text-dark-muted mt-2",children:u.reviewReason})]}),i.jsx("button",{onClick:()=>h(u.id),className:`btn text-sm ${r.has(u.id)?"btn-primary":"btn-secondary"}`,children:r.has(u.id)?"✓ Include":"✗ Exclude"})]}),i.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[i.jsxs("div",{className:"p-4 bg-dark-bg rounded-lg",children:[i.jsx("div",{className:"text-xs text-dark-muted mb-1",children:"Consistent Locations"}),i.jsx("div",{className:"text-2xl font-semibold text-status-approved",children:u.locationCount})]}),i.jsxs("div",{className:"p-4 bg-dark-bg rounded-lg",children:[i.jsx("div",{className:"text-xs text-dark-muted mb-1",children:"Outliers"}),i.jsx("div",{className:`text-2xl font-semibold ${u.outlierCount>0?"text-severity-warning":"text-dark-text"}`,children:u.outlierCount})]})]}),i.jsxs("div",{className:"flex items-center justify-between pt-4 border-t border-dark-border",children:[i.jsx("button",{onClick:()=>a(Math.max(0,l-1)),disabled:l===0,className:"btn btn-secondary text-sm",children:"← Previous"}),i.jsxs("span",{className:"text-sm text-dark-muted",children:[l+1," of ",o.length]}),i.jsx("button",{onClick:()=>a(Math.min(o.length-1,l+1)),disabled:l===o.length-1,className:"btn btn-secondary text-sm",children:"Next →"})]})]})})]})})}function Sg({patternId:e}){const{data:t,isLoading:n}=_h(e);return n?i.jsx("div",{className:"text-dark-muted text-sm py-8 text-center",children:"Loading details..."}):t?i.jsxs("div",{className:"space-y-5",children:[i.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[i.jsxs("div",{className:"p-4 bg-dark-bg rounded-lg",children:[i.jsx("div",{className:"text-xs text-dark-muted mb-1",children:"Confidence"}),i.jsx("div",{className:`text-2xl font-semibold ${dn(t.confidence.score)}`,children:Ie(t.confidence.score)})]}),i.jsxs("div",{className:"p-4 bg-dark-bg rounded-lg",children:[i.jsx("div",{className:"text-xs text-dark-muted mb-1",children:"Consistent"}),i.jsx("div",{className:"text-2xl font-semibold text-status-approved",children:t.locations.length})]}),i.jsxs("div",{className:"p-4 bg-dark-bg rounded-lg",children:[i.jsx("div",{className:"text-xs text-dark-muted mb-1",children:"Outliers"}),i.jsx("div",{className:`text-2xl font-semibold ${t.outliers.length>0?"text-severity-warning":"text-dark-text"}`,children:t.outliers.length})]})]}),t.outliers.length>0&&i.jsxs("div",{children:[i.jsxs("h4",{className:"text-sm font-medium mb-3 text-severity-warning flex items-center gap-2",children:[i.jsx("span",{children:"⚠"})," Outliers - What's Wrong"]}),i.jsxs("div",{className:"space-y-2 max-h-64 overflow-y-auto scrollbar-dark",children:[t.outliers.slice(0,me.NEEDS_REVIEW_OUTLIERS).map((r,s)=>i.jsx("div",{className:"p-3 bg-severity-warning/10 border border-severity-warning/20 rounded-lg text-sm",children:i.jsxs("div",{className:"flex items-start gap-2",children:[i.jsx("span",{className:"text-severity-warning shrink-0",children:"⚠"}),i.jsxs("div",{className:"min-w-0 flex-1",children:[i.jsx("div",{className:"font-medium truncate",children:r.file.split("/").pop()}),i.jsx("div",{className:"text-xs text-dark-muted truncate",children:Lh(r.file)}),r.name&&i.jsxs("div",{className:"text-xs text-blue-400 mt-1",children:[r.kind&&i.jsxs("span",{className:"text-dark-muted",children:[r.kind,": "]}),r.name]}),r.reason&&i.jsx("div",{className:"text-xs text-severity-warning mt-1",children:r.reason}),i.jsxs("div",{className:"text-xs text-dark-muted mt-1",children:["Line ",r.range.start.line]})]})]})},s)),t.outliers.length>me.NEEDS_REVIEW_OUTLIERS&&i.jsxs("div",{className:"text-xs text-dark-muted text-center py-2",children:["... and ",t.outliers.length-me.NEEDS_REVIEW_OUTLIERS," more"]})]})]}),t.locations.length>0&&i.jsxs("div",{children:[i.jsxs("h4",{className:"text-sm font-medium mb-3 text-status-approved flex items-center gap-2",children:[i.jsx("span",{children:"✓"})," Sample Consistent Locations"]}),i.jsx("div",{className:"space-y-1 max-h-32 overflow-y-auto scrollbar-dark",children:t.locations.slice(0,me.NEEDS_REVIEW_LOCATIONS).map((r,s)=>i.jsxs("div",{className:"p-2 bg-dark-bg rounded text-xs flex items-center gap-2",children:[i.jsx("span",{className:"text-status-approved",children:"✓"}),i.jsx("span",{className:"truncate flex-1",children:r.file}),i.jsxs("span",{className:"text-dark-muted shrink-0",children:["L",r.range.start.line]})]},s))})]})]}):i.jsx("div",{className:"text-severity-error text-sm py-8 text-center",children:"Failed to load"})}function Cg({patterns:e,onClose:t}){const n=Oh(),r=Ih(),[s,l]=S.useState(0),a=S.useMemo(()=>Mh(e,"needs-review"),[e]),o=a[s],c=async u=>{if(!o)return;await(u==="approve"?n:r).mutateAsync(o.id),s>=a.length-1&&(a.length<=1?t():l(s-1))};return a.length===0?i.jsx($h,{icon:"🔍",title:"Needs Review",message:"No patterns need manual review. All discovered patterns are high-confidence (≥95%).",onClose:t}):i.jsx(Dh,{title:"🔍 Needs Review",subtitle:`${a.length} patterns with lower confidence (<95%) need your attention`,onClose:t,footer:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-4",children:[i.jsx("button",{onClick:()=>l(Math.max(0,s-1)),disabled:s===0,className:"btn btn-secondary text-sm",children:"← Previous"}),i.jsxs("span",{className:"text-sm text-dark-muted",children:[s+1," of ",a.length]}),i.jsx("button",{onClick:()=>l(Math.min(a.length-1,s+1)),disabled:s===a.length-1,className:"btn btn-secondary text-sm",children:"Next →"})]}),i.jsxs("div",{className:"flex gap-3",children:[i.jsx("button",{onClick:()=>c("ignore"),disabled:r.isPending||!o,className:"btn btn-secondary",children:r.isPending?"⏳...":"✗ Ignore"}),i.jsx("button",{onClick:()=>c("approve"),disabled:n.isPending||!o,className:"btn btn-primary",children:n.isPending?"⏳...":"✓ Approve"})]})]}),children:i.jsxs("div",{className:"flex h-[60vh]",children:[i.jsx("div",{className:"w-80 border-r border-dark-border overflow-y-auto",children:i.jsx("div",{className:"p-3 space-y-1",children:a.map((u,h)=>i.jsxs("button",{onClick:()=>l(h),className:`w-full text-left p-3 rounded-lg transition-colors ${s===h?"bg-blue-500/20 border border-blue-500/30":"hover:bg-dark-border/50 border border-transparent"}`,children:[i.jsx("div",{className:"font-medium truncate",children:u.name}),i.jsxs("div",{className:"flex items-center gap-2 mt-1 text-xs",children:[i.jsx("span",{className:dn(u.confidence.score),children:Ie(u.confidence.score)}),i.jsx("span",{className:"text-dark-muted",children:"•"}),i.jsx("span",{className:"text-dark-muted",children:u.category})]}),i.jsxs("div",{className:"flex items-center gap-3 mt-1 text-xs",children:[i.jsxs("span",{className:"text-status-approved",children:["✓ ",u.locationCount]}),u.outlierCount>0&&i.jsxs("span",{className:"text-severity-warning",children:["⚠ ",u.outlierCount]})]}),i.jsx("div",{className:"text-xs text-dark-muted mt-1",children:u.reviewReason})]},u.id))})}),i.jsx("div",{className:"flex-1 overflow-y-auto p-5",children:o&&i.jsxs("div",{className:"space-y-5",children:[i.jsxs("div",{children:[i.jsx("h3",{className:"text-lg font-semibold",children:o.name}),i.jsxs("div",{className:"flex items-center gap-2 mt-1 text-sm text-dark-muted",children:[i.jsx("span",{children:o.category}),i.jsx("span",{children:"•"}),i.jsxs("span",{className:dn(o.confidence.score),children:[Ie(o.confidence.score)," confidence"]})]})]}),i.jsx(Sg,{patternId:o.id})]})})]})})}function Eg(){const{patternFilters:e,setPatternFilters:t,selectedPattern:n,setSelectedPattern:r}=Lr(),[s,l]=S.useState("grouped"),[a,o]=S.useState({field:"confidence",direction:"desc"}),[c,u]=S.useState(new Set),[h,d]=S.useState(!1),[f,m]=S.useState(!1),[y,N]=S.useState(!0),{data:w,isLoading:v,error:x}=Mv(e),g=S.useMemo(()=>w?og(w,a):[],[w,a]),j=S.useMemo(()=>w?ag(w):[],[w]),k=S.useMemo(()=>w?sg(w):null,[w]),C=S.useCallback(E=>{u(U=>{const T=new Set(U);return T.has(E)?T.delete(E):T.add(E),T})},[]),_=S.useCallback(E=>{r(E===n?null:E)},[n,r]);return v?i.jsx("div",{className:"flex items-center justify-center h-64",children:i.jsxs("div",{className:"flex flex-col items-center gap-3",children:[i.jsx("div",{className:"w-8 h-8 border-2 border-blue-500 border-t-transparent rounded-full animate-spin"}),i.jsx("span",{className:"text-dark-muted",children:"Loading patterns..."})]})}):x?i.jsxs("div",{className:"flex flex-col items-center justify-center h-64 text-center",children:[i.jsx("span",{className:"text-4xl mb-4",children:"⚠️"}),i.jsx("h3",{className:"text-lg font-medium text-severity-error mb-2",children:"Failed to load patterns"}),i.jsx("p",{className:"text-dark-muted text-sm max-w-md",children:"There was an error loading the pattern data. Please try refreshing the page."})]}):i.jsxs("div",{className:"space-y-6",children:[h&&w&&i.jsx(wg,{patterns:w,onClose:()=>d(!1)}),f&&w&&i.jsx(Cg,{patterns:w,onClose:()=>m(!1)}),k&&y&&i.jsxs("div",{className:"relative",children:[i.jsx("button",{onClick:()=>N(!1),className:"absolute -top-1 -right-1 p-1 text-dark-muted hover:text-dark-text z-10",title:"Hide statistics",children:i.jsx("span",{className:"text-xs",children:"✕"})}),i.jsx(mg,{statistics:k,onQuickReview:()=>d(!0),onNeedsReview:()=>m(!0)})]}),!y&&i.jsx("button",{onClick:()=>N(!0),className:"text-sm text-blue-400 hover:text-blue-300 transition-colors",children:"📊 Show statistics"}),i.jsxs("div",{className:"flex gap-6",children:[i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsx("div",{className:"mb-4",children:i.jsx(pg,{filters:e,onFiltersChange:t,viewMode:s,onViewModeChange:l,sort:a,onSortChange:o,resultCount:(w==null?void 0:w.length)||0})}),i.jsx("div",{className:"max-h-[calc(100vh-400px)] overflow-y-auto scrollbar-dark pr-2",children:i.jsx(yg,{patterns:g,groupedPatterns:j,viewMode:s,expandedDetectors:c,onToggleDetector:C,selectedPatternId:n,onSelectPattern:_})})]}),i.jsx("div",{className:"w-96 shrink-0",children:i.jsx("div",{className:"sticky top-4 bg-dark-surface border border-dark-border rounded-xl p-5",children:n?i.jsx(bg,{patternId:n}):i.jsx(kg,{})})})]})]})}const Ss=["GET","POST","PUT","PATCH","DELETE"],Dr={GET:{label:"GET",color:"text-green-400",bgColor:"bg-green-400/10",description:"Retrieve data"},POST:{label:"POST",color:"text-blue-400",bgColor:"bg-blue-400/10",description:"Create new resource"},PUT:{label:"PUT",color:"text-yellow-400",bgColor:"bg-yellow-400/10",description:"Replace resource"},PATCH:{label:"PATCH",color:"text-orange-400",bgColor:"bg-orange-400/10",description:"Partial update"},DELETE:{label:"DELETE",color:"text-red-400",bgColor:"bg-red-400/10",description:"Remove resource"}},dr={discovered:{label:"Discovered",icon:"🔍",color:"text-blue-400",bgColor:"bg-blue-500/10",borderColor:"border-blue-500/20",description:"Newly detected contract"},verified:{label:"Verified",icon:"✓",color:"text-status-approved",bgColor:"bg-status-approved/10",borderColor:"border-status-approved/20",description:"Confirmed as correct"},mismatch:{label:"Mismatch",icon:"⚠️",color:"text-severity-error",bgColor:"bg-severity-error/10",borderColor:"border-severity-error/20",description:"Type mismatches detected"},ignored:{label:"Ignored",icon:"✗",color:"text-dark-muted",bgColor:"bg-dark-muted/10",borderColor:"border-dark-muted/20",description:"Marked as not relevant"}},rc={missing_in_frontend:{label:"Missing in Frontend",icon:"🔴",color:"text-severity-error",description:"Backend returns field that frontend doesn't expect",severity:"error"},missing_in_backend:{label:"Missing in Backend",icon:"🟡",color:"text-severity-warning",description:"Frontend expects field that backend doesn't return",severity:"warning"},type_mismatch:{label:"Type Mismatch",icon:"⚠️",color:"text-severity-error",description:"Field types don't match between BE and FE",severity:"error"},optionality_mismatch:{label:"Optionality Mismatch",icon:"❓",color:"text-severity-warning",description:"Optional/required status differs",severity:"warning"},nullability_mismatch:{label:"Nullability Mismatch",icon:"∅",color:"text-severity-info",description:"Nullable status differs",severity:"info"}},dt={FIELDS_PREVIEW:10,MISMATCHES_PREVIEW:5,FRONTEND_CALLS_PREVIEW:5,TOP_MISMATCHED:5},Fu={list:{label:"List",icon:"📋",description:"All contracts in a flat list"},"by-endpoint":{label:"By Endpoint",icon:"🔗",description:"Contracts grouped by base path"},"by-method":{label:"By Method",icon:"📡",description:"Contracts grouped by HTTP method"}};function Pg(e){const t={discovered:0,verified:0,mismatch:0,ignored:0},n={GET:0,POST:0,PUT:0,PATCH:0,DELETE:0},r={};let s=0;for(const c of e){t[c.status]++,n[c.method]++,s+=c.mismatchCount;for(const u of c.mismatches)r[u.mismatchType]=(r[u.mismatchType]||0)+1}const l=e.length,a=l>0?t.verified/l:0,o=_g(e);return{total:l,byStatus:t,byMethod:n,totalMismatches:s,mismatchesByType:r,verifiedRate:a,healthScore:o}}function Tg(e){const t=Pg(e),n={error:0,warning:0,info:0};for(const s of e)for(const l of s.mismatches)n[l.severity]++;const r=e.filter(s=>s.mismatchCount>0).sort((s,l)=>l.mismatchCount-s.mismatchCount).slice(0,dt.TOP_MISMATCHED).map(s=>({endpoint:s.endpoint,method:s.method,count:s.mismatchCount}));return{...t,mismatchesBySeverity:n,topMismatchedEndpoints:r}}function _g(e){if(e.length===0)return 100;let t=100;const n=e.length,r=e.filter(a=>a.status==="mismatch").length;t-=r/n*40;const s=e.filter(a=>a.status==="discovered").length;t-=s/n*20;const l=e.filter(a=>a.confidence.score<.7).length;return t-=l/n*10,Math.max(0,Math.round(t))}function Og(e){const t=new Map;for(const n of e){const s="/"+n.endpoint.split("/").filter(Boolean).slice(0,2).join("/"),l=t.get(s);l?l.push(n):t.set(s,[n])}return Array.from(t.entries()).map(([n,r])=>({basePath:n,contracts:r.sort((s,l)=>s.endpoint.localeCompare(l.endpoint)),metrics:{total:r.length,mismatches:r.reduce((s,l)=>s+l.mismatchCount,0),verified:r.filter(s=>s.status==="verified").length}})).sort((n,r)=>r.metrics.mismatches-n.metrics.mismatches||r.metrics.total-n.metrics.total)}function Ig(e){const t=new Map;for(const n of e){const r=t.get(n.method);r?r.push(n):t.set(n.method,[n])}return Ss.filter(n=>t.has(n)).map(n=>({method:n,contracts:t.get(n).sort((r,s)=>r.endpoint.localeCompare(s.endpoint)),metrics:{total:t.get(n).length,mismatches:t.get(n).reduce((r,s)=>r+s.mismatchCount,0)}}))}function Rg(e,t){const n=[...e],r=t.direction==="asc"?1:-1;return n.sort((s,l)=>{switch(t.field){case"endpoint":return r*s.endpoint.localeCompare(l.endpoint);case"method":return r*Ss.indexOf(s.method)-Ss.indexOf(l.method);case"status":return r*s.status.localeCompare(l.status);case"mismatches":return r*(s.mismatchCount-l.mismatchCount);case"confidence":return r*(s.confidence.score-l.confidence.score);default:return 0}}),n}function Fg(e){const t=[];let n=100;e.mismatchCount>0&&(n-=Math.min(50,e.mismatchCount*10),t.push(`${e.mismatchCount} field mismatch${e.mismatchCount!==1?"es":""}`)),e.confidence.score<.7&&(n-=20,t.push("Low confidence match")),e.frontend.length===0&&(n-=30,t.push("No frontend consumers found"));const r=n>=80?"healthy":n>=50?"warning":"critical";return{score:Math.max(0,n),status:r,issues:t}}function Ah(e){return e>=.9?"text-status-approved":e>=.7?"text-severity-warning":"text-severity-error"}function Wi(e){return`${Math.round(e*100)}%`}function Kl({label:e,value:t,subValue:n,icon:r,color:s="text-dark-text"}){return i.jsxs("div",{className:"p-4 bg-dark-surface border border-dark-border rounded-lg",children:[i.jsxs("div",{className:"flex items-center justify-between mb-2",children:[i.jsx("span",{className:"text-xs text-dark-muted uppercase tracking-wide",children:e}),r&&i.jsx("span",{className:"text-lg",children:r})]}),i.jsx("div",{className:`text-2xl font-semibold ${s}`,children:t}),n&&i.jsx("div",{className:"text-xs text-dark-muted mt-1",children:n})]})}function Mg({score:e}){const t=e>=80?"text-status-approved":e>=50?"text-severity-warning":"text-severity-error",n=e>=80?"bg-status-approved":e>=50?"bg-severity-warning":"bg-severity-error";return i.jsxs("div",{className:"p-4 bg-dark-surface border border-dark-border rounded-lg",children:[i.jsx("div",{className:"text-xs text-dark-muted uppercase tracking-wide mb-3",children:"Contract Health"}),i.jsxs("div",{className:"flex items-center gap-4",children:[i.jsx("div",{className:`text-3xl font-bold ${t}`,children:e}),i.jsxs("div",{className:"flex-1",children:[i.jsx("div",{className:"h-2 bg-dark-bg rounded-full overflow-hidden",children:i.jsx("div",{className:`h-full ${n} transition-all`,style:{width:`${e}%`}})}),i.jsx("div",{className:"text-xs text-dark-muted mt-1",children:e>=80?"Healthy":e>=50?"Needs attention":"Critical issues"})]})]})]})}function Lg({byStatus:e,total:t}){return i.jsxs("div",{className:"p-4 bg-dark-surface border border-dark-border rounded-lg",children:[i.jsx("div",{className:"text-xs text-dark-muted uppercase tracking-wide mb-3",children:"By Status"}),i.jsx("div",{className:"space-y-2",children:Object.entries(e).map(([n,r])=>{const s=dr[n],l=t>0?r/t*100:0;return i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("span",{className:"text-sm w-6",children:s==null?void 0:s.icon}),i.jsxs("div",{className:"flex-1",children:[i.jsxs("div",{className:"flex items-center justify-between text-sm mb-1",children:[i.jsx("span",{className:s==null?void 0:s.color,children:(s==null?void 0:s.label)||n}),i.jsx("span",{className:"text-dark-muted",children:r})]}),i.jsx("div",{className:"h-1.5 bg-dark-bg rounded-full overflow-hidden",children:i.jsx("div",{className:`h-full rounded-full transition-all ${n==="verified"?"bg-status-approved":n==="mismatch"?"bg-severity-error":n==="ignored"?"bg-dark-muted":"bg-blue-500"}`,style:{width:`${l}%`}})})]})]},n)})})]})}function Dg({byMethod:e}){return i.jsxs("div",{className:"p-4 bg-dark-surface border border-dark-border rounded-lg",children:[i.jsx("div",{className:"text-xs text-dark-muted uppercase tracking-wide mb-3",children:"By Method"}),i.jsx("div",{className:"flex gap-2 flex-wrap",children:Ss.map(t=>{const n=e[t]||0;if(n===0)return null;const r=Dr[t];return i.jsxs("div",{className:`px-3 py-2 rounded-lg ${r.bgColor} border border-dark-border`,children:[i.jsx("div",{className:`font-mono text-sm font-bold ${r.color}`,children:t}),i.jsx("div",{className:"text-xs text-dark-muted",children:n})]},t)})})]})}function $g({mismatchesByType:e,mismatchesBySeverity:t,total:n}){return n===0?i.jsx("div",{className:"p-4 bg-status-approved/10 border border-status-approved/20 rounded-lg",children:i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("span",{className:"text-2xl",children:"✅"}),i.jsxs("div",{children:[i.jsx("div",{className:"font-medium text-status-approved",children:"No Mismatches"}),i.jsx("div",{className:"text-xs text-dark-muted",children:"All contracts are type-safe"})]})]})}):i.jsxs("div",{className:"p-4 bg-severity-error/10 border border-severity-error/20 rounded-lg",children:[i.jsxs("div",{className:"flex items-center justify-between mb-3",children:[i.jsx("div",{className:"text-xs text-dark-muted uppercase tracking-wide",children:"Mismatches"}),i.jsx("span",{className:"text-lg font-semibold text-severity-error",children:n})]}),i.jsxs("div",{className:"flex gap-4 mb-3 text-sm",children:[t.error>0&&i.jsxs("span",{className:"text-severity-error",children:["🔴 ",t.error," errors"]}),t.warning>0&&i.jsxs("span",{className:"text-severity-warning",children:["🟡 ",t.warning," warnings"]}),t.info>0&&i.jsxs("span",{className:"text-severity-info",children:["🔵 ",t.info," info"]})]}),i.jsx("div",{className:"space-y-1",children:Object.entries(e).map(([r,s])=>{const l=rc[r];return l?i.jsxs("div",{className:"flex items-center justify-between text-xs",children:[i.jsxs("span",{className:l.color,children:[l.icon," ",l.label]}),i.jsx("span",{className:"text-dark-muted",children:s})]},r):null})})]})}function Ag({statistics:e}){return i.jsxs("div",{className:"space-y-4",children:[i.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[i.jsx(Kl,{label:"Total Contracts",value:e.total,icon:"🔗"}),i.jsx(Kl,{label:"Verified",value:e.byStatus.verified||0,subValue:Wi(e.verifiedRate),icon:"✓",color:"text-status-approved"}),i.jsx(Kl,{label:"With Mismatches",value:e.byStatus.mismatch||0,icon:"⚠️",color:e.byStatus.mismatch>0?"text-severity-error":"text-dark-text"}),i.jsx(Mg,{score:e.healthScore})]}),i.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-3",children:[i.jsx(Lg,{byStatus:e.byStatus,total:e.total}),i.jsx(Dg,{byMethod:e.byMethod}),i.jsx($g,{mismatchesByType:e.mismatchesByType,mismatchesBySeverity:e.mismatchesBySeverity,total:e.totalMismatches})]}),e.topMismatchedEndpoints.length>0&&i.jsxs("div",{className:"p-4 bg-dark-surface border border-dark-border rounded-lg",children:[i.jsx("div",{className:"text-xs text-dark-muted uppercase tracking-wide mb-3",children:"Top Mismatched Endpoints"}),i.jsx("div",{className:"space-y-2",children:e.topMismatchedEndpoints.map((t,n)=>i.jsxs("div",{className:"flex items-center justify-between text-sm",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:`font-mono text-xs font-bold ${Dr[t.method].color}`,children:t.method}),i.jsx("span",{className:"font-mono text-dark-muted truncate",children:t.endpoint})]}),i.jsx("span",{className:"text-severity-error font-medium",children:t.count})]},n))})]})]})}function zg({filters:e,onFiltersChange:t,viewMode:n,onViewModeChange:r,sort:s,onSortChange:l,resultCount:a}){var u,h,d;const o=()=>{t({})},c=!!(e.status||e.method||e.hasMismatches||e.search);return i.jsxs("div",{className:"space-y-3",children:[i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsxs("div",{className:"relative flex-1",children:[i.jsx("input",{type:"text",placeholder:"Search endpoints...",className:"w-full bg-dark-bg border border-dark-border rounded-lg px-4 py-2 pl-10 text-sm focus:outline-none focus:border-blue-500 transition-colors font-mono",value:e.search||"",onChange:f=>t({...e,search:f.target.value||void 0})}),i.jsx("span",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-dark-muted",children:"🔍"})]}),i.jsx("div",{className:"flex bg-dark-bg border border-dark-border rounded-lg p-0.5",children:Object.keys(Fu).map(f=>{const m=Fu[f];return i.jsx("button",{onClick:()=>r(f),className:`px-3 py-1.5 text-sm rounded-md transition-colors ${n===f?"bg-blue-500/20 text-blue-400":"text-dark-muted hover:text-dark-text"}`,title:m.description,children:m.icon},f)})})]}),i.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[i.jsxs("select",{className:"bg-dark-bg border border-dark-border rounded-lg px-3 py-2 text-sm focus:outline-none focus:border-blue-500",value:e.status||"",onChange:f=>t({...e,status:f.target.value||void 0}),children:[i.jsx("option",{value:"",children:"All Statuses"}),Object.entries(dr).map(([f,m])=>i.jsxs("option",{value:f,children:[m.icon," ",m.label]},f))]}),i.jsxs("select",{className:"bg-dark-bg border border-dark-border rounded-lg px-3 py-2 text-sm focus:outline-none focus:border-blue-500",value:e.method||"",onChange:f=>t({...e,method:f.target.value||void 0}),children:[i.jsx("option",{value:"",children:"All Methods"}),Ss.map(f=>i.jsx("option",{value:f,children:f},f))]}),i.jsxs("label",{className:"flex items-center gap-2 px-3 py-2 bg-dark-bg border border-dark-border rounded-lg text-sm cursor-pointer hover:bg-dark-border/50 transition-colors",children:[i.jsx("input",{type:"checkbox",checked:e.hasMismatches||!1,onChange:f=>t({...e,hasMismatches:f.target.checked||void 0}),className:"rounded border-dark-border"}),i.jsx("span",{className:"text-severity-warning",children:"⚠️"}),i.jsx("span",{children:"Has Mismatches"})]}),i.jsxs("div",{className:"flex items-center gap-1 ml-auto",children:[i.jsx("span",{className:"text-xs text-dark-muted",children:"Sort:"}),i.jsxs("select",{className:"bg-dark-bg border border-dark-border rounded-lg px-2 py-1.5 text-sm focus:outline-none focus:border-blue-500",value:s.field,onChange:f=>l({...s,field:f.target.value}),children:[i.jsx("option",{value:"mismatches",children:"Mismatches"}),i.jsx("option",{value:"endpoint",children:"Endpoint"}),i.jsx("option",{value:"method",children:"Method"}),i.jsx("option",{value:"status",children:"Status"}),i.jsx("option",{value:"confidence",children:"Confidence"})]}),i.jsx("button",{onClick:()=>l({...s,direction:s.direction==="asc"?"desc":"asc"}),className:"p-1.5 bg-dark-bg border border-dark-border rounded-lg text-sm hover:bg-dark-border/50 transition-colors",title:s.direction==="asc"?"Ascending":"Descending",children:s.direction==="asc"?"↑":"↓"})]})]}),i.jsxs("div",{className:"flex items-center justify-between text-sm",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("span",{className:"text-dark-muted",children:[a," contract",a!==1?"s":""]}),c&&i.jsxs(i.Fragment,{children:[i.jsx("span",{className:"text-dark-border",children:"•"}),i.jsx("button",{onClick:o,className:"text-blue-400 hover:text-blue-300 transition-colors",children:"Clear filters"})]})]}),c&&i.jsxs("div",{className:"flex items-center gap-2",children:[e.status&&i.jsxs("span",{className:"px-2 py-0.5 bg-dark-bg border border-dark-border rounded text-xs",children:[(u=dr[e.status])==null?void 0:u.icon," ",(h=dr[e.status])==null?void 0:h.label,i.jsx("button",{onClick:()=>t({...e,status:void 0}),className:"ml-1 text-dark-muted hover:text-dark-text",children:"×"})]}),e.method&&i.jsxs("span",{className:`px-2 py-0.5 bg-dark-bg border border-dark-border rounded text-xs font-mono ${(d=Dr[e.method])==null?void 0:d.color}`,children:[e.method,i.jsx("button",{onClick:()=>t({...e,method:void 0}),className:"ml-1 text-dark-muted hover:text-dark-text",children:"×"})]}),e.hasMismatches&&i.jsxs("span",{className:"px-2 py-0.5 bg-dark-bg border border-dark-border rounded text-xs",children:["⚠️ Has Mismatches",i.jsx("button",{onClick:()=>t({...e,hasMismatches:void 0}),className:"ml-1 text-dark-muted hover:text-dark-text",children:"×"})]})]})]})]})}function sc({contract:e,isSelected:t,onSelect:n}){const r=Dr[e.method],s=dr[e.status];return i.jsxs("button",{onClick:n,className:`w-full text-left p-4 rounded-lg border transition-all ${t?"bg-blue-500/10 border-blue-500/30":"bg-dark-surface border-dark-border hover:border-dark-muted"}`,children:[i.jsxs("div",{className:"flex items-center justify-between mb-2",children:[i.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[i.jsx("span",{className:`font-mono text-xs font-bold px-2 py-1 rounded ${r.bgColor} ${r.color}`,children:e.method}),i.jsx("span",{className:"font-mono text-sm truncate",title:e.endpoint,children:e.endpoint})]}),i.jsxs("span",{className:`px-2 py-1 rounded text-xs shrink-0 ${s.bgColor} ${s.color}`,children:[s.icon," ",s.label]})]}),i.jsxs("div",{className:"flex items-center gap-4 text-xs text-dark-muted",children:[i.jsxs("span",{title:"Backend framework",children:["🔧 ",e.backend.framework]}),i.jsxs("span",{title:"Frontend calls",children:["📱 ",e.frontend.length," call",e.frontend.length!==1?"s":""]}),e.mismatchCount>0&&i.jsxs("span",{className:"text-severity-error",title:"Field mismatches",children:["⚠️ ",e.mismatchCount," mismatch",e.mismatchCount!==1?"es":""]}),i.jsx("span",{className:Ah(e.confidence.score),title:"Confidence",children:Wi(e.confidence.score)})]})]})}function Ug({group:e,isExpanded:t,onToggle:n,selectedContractId:r,onSelectContract:s}){return i.jsxs("div",{className:"border border-dark-border rounded-lg overflow-hidden",children:[i.jsxs("button",{onClick:n,className:"w-full text-left p-4 bg-dark-surface hover:bg-dark-border/30 transition-colors",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("span",{className:"text-dark-muted",children:t?"▼":"▶"}),i.jsx("span",{className:"text-lg",children:"🔗"}),i.jsx("span",{className:"font-mono font-medium",children:e.basePath}),i.jsxs("span",{className:"px-2 py-0.5 bg-dark-bg rounded text-xs text-dark-muted",children:[e.contracts.length," endpoint",e.contracts.length!==1?"s":""]})]}),e.metrics.mismatches>0&&i.jsxs("span",{className:"text-severity-error text-sm",children:["⚠️ ",e.metrics.mismatches]})]}),i.jsxs("div",{className:"flex items-center gap-4 mt-2 ml-10 text-xs text-dark-muted",children:[i.jsxs("span",{className:"text-status-approved",children:["✓ ",e.metrics.verified," verified"]}),e.metrics.mismatches>0&&i.jsxs("span",{className:"text-severity-error",children:["⚠ ",e.metrics.mismatches," mismatches"]})]})]}),t&&i.jsx("div",{className:"border-t border-dark-border bg-dark-bg p-3 space-y-2",children:e.contracts.map(l=>i.jsx(sc,{contract:l,isSelected:r===l.id,onSelect:()=>s(l.id)},l.id))})]})}function Vg({group:e,isExpanded:t,onToggle:n,selectedContractId:r,onSelectContract:s}){const l=Dr[e.method];return i.jsxs("div",{className:"border border-dark-border rounded-lg overflow-hidden",children:[i.jsx("button",{onClick:n,className:"w-full text-left p-4 bg-dark-surface hover:bg-dark-border/30 transition-colors",children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("span",{className:"text-dark-muted",children:t?"▼":"▶"}),i.jsx("span",{className:`font-mono text-lg font-bold px-3 py-1 rounded ${l.bgColor} ${l.color}`,children:e.method}),i.jsx("span",{className:"text-dark-muted text-sm",children:l.description}),i.jsx("span",{className:"px-2 py-0.5 bg-dark-bg rounded text-xs text-dark-muted",children:e.contracts.length})]}),e.metrics.mismatches>0&&i.jsxs("span",{className:"text-severity-error text-sm",children:["⚠️ ",e.metrics.mismatches]})]})}),t&&i.jsx("div",{className:"border-t border-dark-border bg-dark-bg p-3 space-y-2",children:e.contracts.map(a=>i.jsx(sc,{contract:a,isSelected:r===a.id,onSelect:()=>s(a.id)},a.id))})]})}function Qg({contracts:e,viewMode:t,selectedContractId:n,onSelectContract:r}){const[s,l]=S.useState(new Set),a=c=>{l(u=>{const h=new Set(u);return h.has(c)?h.delete(c):h.add(c),h})};if(e.length===0)return i.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-center",children:[i.jsx("span",{className:"text-4xl mb-4",children:"📋"}),i.jsx("h3",{className:"text-lg font-medium mb-2",children:"No contracts found"}),i.jsxs("p",{className:"text-dark-muted text-sm max-w-md",children:["Run ",i.jsx("code",{className:"bg-dark-bg px-2 py-0.5 rounded font-mono text-xs",children:"drift scan --contracts"})," to detect BE↔FE contracts"]})]});if(t==="list")return i.jsx("div",{className:"space-y-2",children:e.map(c=>i.jsx(sc,{contract:c,isSelected:n===c.id,onSelect:()=>r(c.id)},c.id))});if(t==="by-endpoint"){const c=Og(e);return i.jsx("div",{className:"space-y-3",children:c.map(u=>i.jsx(Ug,{group:u,isExpanded:s.has(u.basePath),onToggle:()=>a(u.basePath),selectedContractId:n,onSelectContract:r},u.basePath))})}const o=Ig(e);return i.jsx("div",{className:"space-y-3",children:o.map(c=>i.jsx(Vg,{group:c,isExpanded:s.has(c.method),onToggle:()=>a(c.method),selectedContractId:n,onSelectContract:r},c.method))})}function Mu({fields:e,title:t,color:n}){const[r,s]=S.useState(!1),l=r?e:e.slice(0,dt.FIELDS_PREVIEW);return i.jsxs("div",{children:[i.jsx("div",{className:"text-xs text-dark-muted mb-2",children:t}),i.jsxs("div",{className:"space-y-1",children:[l.map((a,o)=>i.jsxs("div",{className:"font-mono text-xs flex items-center gap-1",children:[i.jsx("span",{className:n,children:a.name}),i.jsx("span",{className:"text-dark-muted",children:":"}),i.jsx("span",{className:"text-purple-400",children:a.type}),a.optional&&i.jsx("span",{className:"text-yellow-400",children:"?"}),a.nullable&&i.jsx("span",{className:"text-orange-400",children:"| null"})]},o)),e.length>dt.FIELDS_PREVIEW&&i.jsx("button",{onClick:()=>s(!r),className:"text-xs text-blue-400 hover:text-blue-300",children:r?"Show less":`Show ${e.length-dt.FIELDS_PREVIEW} more`})]})]})}function Hg({mismatch:e}){const t=rc[e.mismatchType],n=e.severity==="error"?"bg-severity-error/20 text-severity-error border-severity-error/30":e.severity==="warning"?"bg-severity-warning/20 text-severity-warning border-severity-warning/30":"bg-severity-info/20 text-severity-info border-severity-info/30";return i.jsxs("div",{className:"p-3 bg-dark-bg rounded-lg text-sm",children:[i.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[i.jsx("span",{className:"font-mono text-blue-400",children:e.fieldPath}),i.jsx("span",{className:`px-1.5 py-0.5 rounded text-xs border ${n}`,children:e.severity})]}),i.jsxs("div",{className:`text-xs ${t.color} mb-1`,children:[t.icon," ",t.label]}),i.jsx("div",{className:"text-xs text-dark-muted",children:e.description})]})}function Bg({contract:e,onCopyForAI:t,isCopying:n,copySuccess:r}){const s=Hv(),l=Bv();return i.jsxs("div",{className:"flex flex-wrap gap-2",children:[(e.status==="discovered"||e.status==="mismatch")&&i.jsxs(i.Fragment,{children:[i.jsxs("button",{onClick:()=>s.mutate(e.id),disabled:s.isPending,className:"btn btn-primary text-sm flex items-center gap-1.5",children:[s.isPending?i.jsx("span",{className:"animate-spin",children:"⏳"}):i.jsx("span",{children:"✓"}),"Verify"]}),i.jsxs("button",{onClick:()=>l.mutate(e.id),disabled:l.isPending,className:"btn btn-secondary text-sm flex items-center gap-1.5",children:[l.isPending?i.jsx("span",{className:"animate-spin",children:"⏳"}):i.jsx("span",{children:"✗"}),"Ignore"]})]}),i.jsxs("button",{onClick:t,disabled:n,className:`btn text-sm flex items-center gap-1.5 ${r?"btn-primary":"btn-secondary"}`,children:[n?i.jsx("span",{className:"animate-spin",children:"⏳"}):r?i.jsx("span",{children:"✓"}):i.jsx("span",{children:"📋"}),r?"Copied!":"Copy for AI"]})]})}function Wg({contractId:e}){const{data:t,isLoading:n,error:r}=Qv(e),[s,l]=S.useState(!1),[a,o]=S.useState(!1),c=async()=>{if(t){l(!0),o(!1);try{const f=[`# API Contract: ${t.method} ${t.endpoint}`,`Status: ${t.status} | Confidence: ${Wi(t.confidence.score)}`,"","## Backend Endpoint",`File: ${t.backend.file}:${t.backend.line}`,`Framework: ${t.backend.framework}`,"","### Response Fields:",...t.backend.responseFields.map(m=>`- ${m.name}: ${m.type}${m.optional?" (optional)":""}${m.nullable?" (nullable)":""}`),"","## Frontend API Calls",...t.frontend.flatMap(m=>[`### ${m.file}:${m.line}`,`Library: ${m.library}`,m.responseType?`Response Type: ${m.responseType}`:"","Expected Fields:",...m.responseFields.map(y=>`- ${y.name}: ${y.type}${y.optional?" (optional)":""}`),""])];if(t.mismatches.length>0){f.push("## ⚠️ Mismatches to Fix"),f.push("");for(const m of t.mismatches){const y=rc[m.mismatchType];f.push(`### ${m.fieldPath}`),f.push(`Type: ${y.icon} ${y.label}`),f.push(`Description: ${m.description}`),f.push(`Severity: ${m.severity}`),f.push("")}f.push("---"),f.push("Please fix these mismatches to ensure type safety between backend and frontend.")}await navigator.clipboard.writeText(f.join(`
|
|
58
|
-
`)),o(!0),setTimeout(()=>o(!1),2e3)}catch(f){console.error("Failed to copy:",f)}finally{l(!1)}}};if(n)return i.jsx("div",{className:"flex items-center justify-center py-12",children:i.jsx("div",{className:"text-dark-muted",children:"Loading contract details..."})});if(r||!t)return i.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[i.jsx("span",{className:"text-3xl mb-3",children:"⚠️"}),i.jsx("div",{className:"text-severity-error",children:"Failed to load contract"})]});const u=Dr[t.method],h=dr[t.status],d=Fg(t);return i.jsxs("div",{className:"space-y-5",children:[i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[i.jsx("span",{className:`font-mono text-lg font-bold px-2 py-1 rounded ${u.bgColor} ${u.color}`,children:t.method}),i.jsx("span",{className:"font-mono text-lg truncate",title:t.endpoint,children:t.endpoint})]}),i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsxs("span",{className:`px-2 py-1 rounded text-xs ${h.bgColor} ${h.color}`,children:[h.icon," ",h.label]}),i.jsxs("span",{className:`text-sm ${Ah(t.confidence.score)}`,children:[Wi(t.confidence.score)," confidence"]})]})]}),d.issues.length>0&&i.jsxs("div",{className:`p-3 rounded-lg text-sm ${d.status==="critical"?"bg-severity-error/10 border border-severity-error/20":d.status==="warning"?"bg-severity-warning/10 border border-severity-warning/20":"bg-status-approved/10 border border-status-approved/20"}`,children:[i.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[i.jsx("span",{children:d.status==="critical"?"🔴":d.status==="warning"?"🟡":"🟢"}),i.jsxs("span",{className:"font-medium",children:["Health Score: ",d.score]})]}),i.jsx("ul",{className:"text-xs text-dark-muted list-disc list-inside",children:d.issues.map((f,m)=>i.jsx("li",{children:f},m))})]}),i.jsx(Bg,{contract:t,onCopyForAI:c,isCopying:s,copySuccess:a}),i.jsxs("div",{className:"p-4 bg-dark-bg rounded-lg",children:[i.jsxs("h4",{className:"text-sm font-medium mb-3 text-green-400 flex items-center gap-2",children:[i.jsx("span",{children:"🔧"})," Backend"]}),i.jsxs("div",{className:"text-xs space-y-2",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:"text-dark-muted",children:"File:"}),i.jsxs("span",{className:"font-mono",children:[t.backend.file,":",t.backend.line]})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:"text-dark-muted",children:"Framework:"}),i.jsx("span",{children:t.backend.framework})]}),t.backend.responseFields.length>0&&i.jsx(Mu,{fields:t.backend.responseFields,title:"Response Fields:",color:"text-green-400"})]})]}),i.jsxs("div",{className:"p-4 bg-dark-bg rounded-lg",children:[i.jsxs("h4",{className:"text-sm font-medium mb-3 text-blue-400 flex items-center gap-2",children:[i.jsx("span",{children:"📱"})," Frontend (",t.frontend.length,")"]}),i.jsxs("div",{className:"space-y-4",children:[t.frontend.slice(0,dt.FRONTEND_CALLS_PREVIEW).map((f,m)=>i.jsxs("div",{className:"text-xs border-l-2 border-dark-border pl-3",children:[i.jsxs("div",{className:"font-mono",children:[f.file,":",f.line]}),i.jsxs("div",{className:"text-dark-muted",children:["Library: ",f.library]}),f.responseType&&i.jsxs("div",{className:"text-dark-muted",children:["Type: ",i.jsx("span",{className:"text-purple-400",children:f.responseType})]}),f.responseFields.length>0&&i.jsx(Mu,{fields:f.responseFields,title:"Expected Fields:",color:"text-blue-400"})]},m)),t.frontend.length>dt.FRONTEND_CALLS_PREVIEW&&i.jsxs("div",{className:"text-xs text-dark-muted",children:["... and ",t.frontend.length-dt.FRONTEND_CALLS_PREVIEW," more"]})]})]}),t.mismatches.length>0&&i.jsxs("div",{className:"p-4 bg-severity-error/10 border border-severity-error/30 rounded-lg",children:[i.jsxs("h4",{className:"text-sm font-medium mb-3 text-severity-error flex items-center gap-2",children:[i.jsx("span",{children:"⚠️"})," Mismatches (",t.mismatches.length,")"]}),i.jsxs("div",{className:"space-y-2 max-h-64 overflow-y-auto scrollbar-dark",children:[t.mismatches.slice(0,dt.MISMATCHES_PREVIEW).map((f,m)=>i.jsx(Hg,{mismatch:f},m)),t.mismatches.length>dt.MISMATCHES_PREVIEW&&i.jsxs("div",{className:"text-xs text-dark-muted text-center py-2",children:["... and ",t.mismatches.length-dt.MISMATCHES_PREVIEW," more"]})]})]})]})}function Kg(){return i.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[i.jsx("span",{className:"text-4xl mb-4",children:"🔗"}),i.jsx("h3",{className:"text-lg font-medium mb-2",children:"No contract selected"}),i.jsx("p",{className:"text-dark-muted text-sm max-w-xs",children:"Select a contract from the list to view its details, fields, and mismatches."})]})}function Gg(){const[e,t]=S.useState({}),[n,r]=S.useState("list"),[s,l]=S.useState({field:"mismatches",direction:"desc"}),[a,o]=S.useState(null),[c,u]=S.useState(!0),{data:h,isLoading:d,error:f}=Vv(e),m=S.useMemo(()=>h?Rg(h,s):[],[h,s]),y=S.useMemo(()=>h?Tg(h):null,[h]),N=S.useCallback(w=>{o(w===a?null:w)},[a]);return d?i.jsx("div",{className:"flex items-center justify-center h-64",children:i.jsxs("div",{className:"flex flex-col items-center gap-3",children:[i.jsx("div",{className:"w-8 h-8 border-2 border-blue-500 border-t-transparent rounded-full animate-spin"}),i.jsx("span",{className:"text-dark-muted",children:"Loading contracts..."})]})}):f?i.jsxs("div",{className:"flex flex-col items-center justify-center h-64 text-center",children:[i.jsx("span",{className:"text-4xl mb-4",children:"⚠️"}),i.jsx("h3",{className:"text-lg font-medium text-severity-error mb-2",children:"Failed to load contracts"}),i.jsx("p",{className:"text-dark-muted text-sm max-w-md",children:"There was an error loading the contract data. Please try refreshing the page."})]}):i.jsxs("div",{className:"space-y-6",children:[y&&c&&i.jsxs("div",{className:"relative",children:[i.jsx("button",{onClick:()=>u(!1),className:"absolute -top-1 -right-1 p-1 text-dark-muted hover:text-dark-text z-10",title:"Hide statistics",children:i.jsx("span",{className:"text-xs",children:"✕"})}),i.jsx(Ag,{statistics:y})]}),!c&&i.jsx("button",{onClick:()=>u(!0),className:"text-sm text-blue-400 hover:text-blue-300 transition-colors",children:"📊 Show statistics"}),i.jsxs("div",{className:"flex gap-6",children:[i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsx("div",{className:"mb-4",children:i.jsx(zg,{filters:e,onFiltersChange:t,viewMode:n,onViewModeChange:r,sort:s,onSortChange:l,resultCount:(h==null?void 0:h.length)||0})}),i.jsx("div",{className:"max-h-[calc(100vh-400px)] overflow-y-auto scrollbar-dark pr-2",children:i.jsx(Qg,{contracts:m,viewMode:n,selectedContractId:a,onSelectContract:N})})]}),i.jsx("div",{className:"w-96 shrink-0",children:i.jsx("div",{className:"sticky top-4 bg-dark-surface border border-dark-border rounded-xl p-5",children:a?i.jsx(Wg,{contractId:a}):i.jsx(Kg,{})})})]})]})}const Cs=["error","warning","info","hint"],De={error:{label:"Error",icon:"🔴",color:"text-severity-error",bgColor:"bg-severity-error/10",borderColor:"border-severity-error/30",description:"Critical issues that must be fixed",priority:4},warning:{label:"Warning",icon:"🟡",color:"text-severity-warning",bgColor:"bg-severity-warning/10",borderColor:"border-severity-warning/30",description:"Issues that should be addressed",priority:3},info:{label:"Info",icon:"🔵",color:"text-severity-info",bgColor:"bg-severity-info/10",borderColor:"border-severity-info/30",description:"Informational notices",priority:2},hint:{label:"Hint",icon:"💡",color:"text-dark-muted",bgColor:"bg-dark-muted/10",borderColor:"border-dark-muted/30",description:"Suggestions for improvement",priority:1}},be={security:{label:"Security",icon:"🔒",color:"text-red-400",bgColor:"bg-red-500/10",description:"Security vulnerabilities and risks",priority:10},auth:{label:"Authentication",icon:"🔑",color:"text-orange-400",bgColor:"bg-orange-500/10",description:"Authentication and authorization issues",priority:9},api:{label:"API",icon:"🌐",color:"text-blue-400",bgColor:"bg-blue-500/10",description:"API structure and consistency",priority:8},"data-access":{label:"Data Access",icon:"💾",color:"text-purple-400",bgColor:"bg-purple-500/10",description:"Database and data layer patterns",priority:7},errors:{label:"Error Handling",icon:"⚠️",color:"text-yellow-400",bgColor:"bg-yellow-500/10",description:"Error handling patterns",priority:6},structural:{label:"Structure",icon:"🏗️",color:"text-cyan-400",bgColor:"bg-cyan-500/10",description:"Code organization and architecture",priority:5},components:{label:"Components",icon:"🧩",color:"text-green-400",bgColor:"bg-green-500/10",description:"Component patterns and structure",priority:4},styling:{label:"Styling",icon:"🎨",color:"text-pink-400",bgColor:"bg-pink-500/10",description:"CSS and styling patterns",priority:3},performance:{label:"Performance",icon:"⚡",color:"text-amber-400",bgColor:"bg-amber-500/10",description:"Performance optimizations",priority:2},documentation:{label:"Documentation",icon:"📝",color:"text-slate-400",bgColor:"bg-slate-500/10",description:"Documentation and comments",priority:1},testing:{label:"Testing",icon:"🧪",color:"text-teal-400",bgColor:"bg-teal-500/10",description:"Testing patterns and coverage",priority:1},other:{label:"Other",icon:"📋",color:"text-gray-400",bgColor:"bg-gray-500/10",description:"Other violations",priority:0}},zh=Object.keys(be).sort((e,t)=>be[t].priority-be[e].priority),Gl={TOP_FILES:5,TOP_PATTERNS:5,TOP_CATEGORIES:5},Lu={list:{label:"List",icon:"📋",description:"All violations in a flat list"},"by-severity":{label:"By Severity",icon:"⚠️",description:"Violations grouped by severity level"},"by-category":{label:"By Category",icon:"📂",description:"Violations grouped by category"},"by-file":{label:"By File",icon:"📁",description:"Violations grouped by file"},"by-pattern":{label:"By Pattern",icon:"🔍",description:"Violations grouped by pattern"}};function qg(e){const t={error:0,warning:0,info:0,hint:0},n={},r={},s={};for(const l of e){t[l.severity]++,n[l.patternId]=(n[l.patternId]||0)+1,r[l.file]=(r[l.file]||0)+1;const a=Ki(l.patternId,l.patternName);s[a]=(s[a]||0)+1}return{total:e.length,bySeverity:t,byPattern:n,byFile:r,byCategory:s,criticalCount:t.error+t.warning}}function Ki(e,t){if(t){const l=t.toLowerCase(),a={"sql injection":"security",xss:"security",csrf:"security",credential:"security",secret:"security",sanitiz:"security",security:"security",auth:"auth",rbac:"auth",permission:"auth",role:"auth",session:"auth",token:"auth",jwt:"auth",audit:"auth","http method":"api",route:"api",endpoint:"api","response envelope":"api",rest:"api",api:"api",database:"data-access",query:"data-access",repository:"data-access","data access":"data-access",error:"errors",exception:"errors",barrel:"structural",import:"structural",export:"structural","file naming":"structural",directory:"structural",module:"structural",package:"structural",circular:"structural",component:"components",composition:"components","state pattern":"components","ref forward":"components",hook:"components",prop:"components",typography:"styling",color:"styling",spacing:"styling","z-index":"styling",responsive:"styling",tailwind:"styling",css:"styling",style:"styling","class naming":"styling",performance:"performance",lazy:"performance",memo:"performance",cache:"performance"};for(const[o,c]of Object.entries(a))if(l.includes(o))return c}const n=e.toLowerCase();if(n.includes("/")){const a=n.split("/")[0],o={api:"api",auth:"auth",security:"security",styling:"styling",structural:"structural",components:"components",component:"components",data:"data-access",database:"data-access",error:"errors",errors:"errors",performance:"performance",testing:"testing",documentation:"documentation"};if(o[a])return o[a]}const r=n.replace(/\//g,"-").split("-"),s={security:"security",xss:"security",injection:"security",csrf:"security",sanitize:"security",validate:"security",credential:"security",secret:"security",auth:"auth",authentication:"auth",authorization:"auth",rbac:"auth",permission:"auth",role:"auth",session:"auth",token:"auth",jwt:"auth",audit:"auth",api:"api",endpoint:"api",rest:"api",route:"api",handler:"api",controller:"api",middleware:"api",request:"api",response:"api",http:"api",data:"data-access",database:"data-access",sql:"data-access",query:"data-access",repository:"data-access",model:"data-access",schema:"data-access",migration:"data-access",error:"errors",exception:"errors",throw:"errors",catch:"errors",handling:"errors",structural:"structural",file:"structural",directory:"structural",naming:"structural",import:"structural",export:"structural",module:"structural",package:"structural",barrel:"structural",circular:"structural",component:"components",components:"components",react:"components",vue:"components",angular:"components",hook:"components",prop:"components",state:"components",render:"components",ref:"components",composition:"components",style:"styling",styling:"styling",css:"styling",typography:"styling",color:"styling",spacing:"styling",layout:"styling",theme:"styling",tailwind:"styling",class:"styling",performance:"performance",perf:"performance",optimization:"performance",cache:"performance",lazy:"performance",memo:"performance"};for(const l of r.slice(0,3))if(s[l])return s[l];return"other"}function Yg(e,t=0){const n=qg(e),r=new Map;for(const o of e){const c=r.get(o.patternId);c?c.count++:r.set(o.patternId,{name:o.patternName,count:1})}const s=Object.entries(n.byFile).sort((o,c)=>c[1]-o[1]).slice(0,Gl.TOP_FILES).map(([o,c])=>({file:o,count:c})),l=Array.from(r.entries()).sort((o,c)=>c[1].count-o[1].count).slice(0,Gl.TOP_PATTERNS).map(([o,{name:c,count:u}])=>({id:o,name:c,count:u})),a=Object.entries(n.byCategory).sort((o,c)=>c[1]-o[1]).slice(0,Gl.TOP_CATEGORIES).map(([o,c])=>{var u;return{category:o,count:c,icon:((u=be[o])==null?void 0:u.icon)||"📋"}});return{total:e.length,bySeverity:n.bySeverity,byCategory:n.byCategory,byPattern:r,affectedFiles:Object.keys(n.byFile).length,topFiles:s,topPatterns:l,topCategories:a,realtimeCount:t,trend:"stable"}}function Xg(e){const t=new Map;for(const n of e){const r=t.get(n.file);r?r.push(n):t.set(n.file,[n])}return Array.from(t.entries()).map(([n,r])=>{const s={error:0,warning:0,info:0,hint:0};for(const a of r)s[a.severity]++;const l=ty(s);return{file:n,violations:r.sort((a,o)=>a.range.start.line-o.range.start.line),metrics:{total:r.length,bySeverity:s,maxSeverity:l}}}).sort((n,r)=>{const s=Gi(r.metrics.maxSeverity)-Gi(n.metrics.maxSeverity);return s!==0?s:r.metrics.total-n.metrics.total})}function Zg(e){const t=new Map;for(const n of e){const r=t.get(n.patternId);r?r.violations.push(n):t.set(n.patternId,{name:n.patternName,violations:[n]})}return Array.from(t.entries()).map(([n,{name:r,violations:s}])=>{const l={error:0,warning:0,info:0,hint:0},a=new Set;for(const o of s)l[o.severity]++,a.add(o.file);return{patternId:n,patternName:r,violations:s,metrics:{total:s.length,bySeverity:l,affectedFiles:a.size}}}).sort((n,r)=>r.metrics.total-n.metrics.total)}function Uh(e){const t=new Map;for(const n of e){const r=Ki(n.patternId,n.patternName),s=t.get(r);s?s.push(n):t.set(r,[n])}return zh.filter(n=>t.has(n)).map(n=>{const r=t.get(n)||[],s=be[n]??be.other,l={error:0,warning:0,info:0,hint:0},a=new Set,o=new Set;for(const c of r)l[c.severity]++,a.add(c.file),o.add(c.patternId);return{category:n,displayName:s.label,icon:s.icon,violations:r,metrics:{total:r.length,bySeverity:l,affectedFiles:a.size,patterns:Array.from(o)}}})}function Jg(e){const t=new Map;for(const n of e){const r=t.get(n.severity);r?r.push(n):t.set(n.severity,[n])}return Cs.filter(n=>t.has(n)).map(n=>{const r=t.get(n)||[],s=Uh(r);return{severity:n,violations:r,categories:s}})}function ey(e,t){const n=[...e],r=t.direction==="asc"?1:-1;return n.sort((s,l)=>{var a,o;switch(t.field){case"severity":return r*(Gi(l.severity)-Gi(s.severity));case"category":{const c=Ki(s.patternId,s.patternName),u=Ki(l.patternId,l.patternName),h=((a=be[c])==null?void 0:a.priority)??0,d=((o=be[u])==null?void 0:o.priority)??0;return r*(d-h)}case"file":return r*s.file.localeCompare(l.file);case"pattern":return r*s.patternName.localeCompare(l.patternName);case"line":return r*(s.range.start.line-l.range.start.line);default:return 0}}),n}function Gi(e){return De[e].priority}function ty(e){for(const t of Cs)if(e[t]>0)return t;return"hint"}function Vh(e){return be[e]||be.other}function Qh(e,t=50){if(e.length<=t)return e;const r=e.split("/").pop()||"";return r.length>=t-3?"..."+r.slice(-(t-3)):".../"+r}function ny(e,t){return e.line===t.line?`L${e.line}:${e.character}-${t.character}`:`L${e.line}:${e.character} - L${t.line}:${t.character}`}function Hh(e){return e.split("/").pop()||e}function ry(e,t){const n=new Set(e.map(s=>s.id));return[...t.filter(s=>!n.has(s.id)),...e]}function li({label:e,value:t,subValue:n,icon:r,color:s="text-dark-text"}){return i.jsxs("div",{className:"p-4 bg-dark-surface border border-dark-border rounded-lg",children:[i.jsxs("div",{className:"flex items-center justify-between mb-2",children:[i.jsx("span",{className:"text-xs text-dark-muted uppercase tracking-wide",children:e}),r&&i.jsx("span",{className:"text-lg",children:r})]}),i.jsx("div",{className:`text-2xl font-semibold ${s}`,children:t}),n&&i.jsx("div",{className:"text-xs text-dark-muted mt-1",children:n})]})}function sy({bySeverity:e,total:t}){return i.jsxs("div",{className:"p-4 bg-dark-surface border border-dark-border rounded-lg",children:[i.jsx("div",{className:"text-xs text-dark-muted uppercase tracking-wide mb-3",children:"By Severity"}),i.jsx("div",{className:"flex h-3 rounded-full overflow-hidden bg-dark-bg mb-3",children:Cs.map(n=>{const r=e[n]||0,s=t>0?r/t*100:0;if(s===0)return null;const l=De[n];return i.jsx("div",{className:`${l.bgColor} transition-all`,style:{width:`${s}%`},title:`${l.label}: ${r} (${Math.round(s)}%)`},n)})}),i.jsx("div",{className:"grid grid-cols-2 gap-2",children:Cs.map(n=>{const r=e[n]||0,s=De[n];return i.jsxs("div",{className:"flex items-center justify-between text-sm",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{children:s.icon}),i.jsx("span",{className:s.color,children:s.label})]}),i.jsx("span",{className:"font-medium",children:r})]},n)})})]})}function Du({title:e,icon:t,items:n,emptyMessage:r}){return i.jsxs("div",{className:"p-4 bg-dark-surface border border-dark-border rounded-lg",children:[i.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[i.jsx("span",{children:t}),i.jsx("span",{className:"text-xs text-dark-muted uppercase tracking-wide",children:e})]}),n.length>0?i.jsx("div",{className:"space-y-2",children:n.map((s,l)=>i.jsxs("div",{className:"flex items-center justify-between text-sm",children:[i.jsx("span",{className:"truncate text-dark-muted",title:s.label,children:s.label}),i.jsx("span",{className:"font-medium ml-2 shrink-0",children:s.count})]},l))}):i.jsx("div",{className:"text-sm text-dark-muted",children:r})]})}function iy({byCategory:e,total:t}){const n=Object.entries(e).sort((r,s)=>s[1]-r[1]).slice(0,6);return i.jsxs("div",{className:"p-4 bg-dark-surface border border-dark-border rounded-lg",children:[i.jsx("div",{className:"text-xs text-dark-muted uppercase tracking-wide mb-3",children:"By Category"}),n.length>0?i.jsx("div",{className:"space-y-2",children:n.map(([r,s])=>{const l=be[r]||be.other,a=t>0?Math.round(s/t*100):0;return i.jsxs("div",{className:"space-y-1",children:[i.jsxs("div",{className:"flex items-center justify-between text-sm",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{children:l.icon}),i.jsx("span",{className:l.color,children:l.label})]}),i.jsx("span",{className:"font-medium",children:s})]}),i.jsx("div",{className:"h-1.5 bg-dark-bg rounded-full overflow-hidden",children:i.jsx("div",{className:`h-full ${l.bgColor} transition-all`,style:{width:`${a}%`}})})]},r)})}):i.jsx("div",{className:"text-sm text-dark-muted",children:"No category data"})]})}function ly({statistics:e}){const t=(e.bySeverity.error||0)+(e.bySeverity.warning||0);return i.jsxs("div",{className:"space-y-4",children:[i.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[i.jsx(li,{label:"Total Violations",value:e.total,icon:"⚠️",color:e.total>0?"text-severity-warning":"text-status-approved"}),i.jsx(li,{label:"Critical",value:t,subValue:"errors + warnings",icon:"🔴",color:t>0?"text-severity-error":"text-status-approved"}),i.jsx(li,{label:"Affected Files",value:e.affectedFiles,icon:"📁"}),i.jsx(li,{label:"Patterns",value:e.byPattern.size,subValue:"with violations",icon:"🔍"})]}),e.realtimeCount>0&&i.jsxs("div",{className:"p-3 bg-blue-500/10 border border-blue-500/20 rounded-lg flex items-center gap-3",children:[i.jsxs("span",{className:"relative flex h-3 w-3",children:[i.jsx("span",{className:"animate-ping absolute inline-flex h-full w-full rounded-full bg-blue-400 opacity-75"}),i.jsx("span",{className:"relative inline-flex rounded-full h-3 w-3 bg-blue-500"})]}),i.jsxs("span",{className:"text-sm text-blue-400",children:[e.realtimeCount," new violation",e.realtimeCount!==1?"s":""," detected in real-time"]})]}),i.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-3",children:[i.jsx(sy,{bySeverity:e.bySeverity,total:e.total}),i.jsx(iy,{byCategory:e.byCategory,total:e.total}),i.jsx(Du,{title:"Top Files",icon:"📄",items:e.topFiles.map(n=>({label:Hh(n.file),count:n.count})),emptyMessage:"No files with violations"}),i.jsx(Du,{title:"Top Patterns",icon:"🔍",items:e.topPatterns.map(n=>({label:n.name,count:n.count})),emptyMessage:"No pattern violations"})]})]})}function ay({filters:e,onFiltersChange:t,viewMode:n,onViewModeChange:r,sort:s,onSortChange:l,resultCount:a}){var u,h,d,f;const o=()=>{t({})},c=!!(e.severity||e.file||e.patternId||e.search||e.category);return i.jsxs("div",{className:"space-y-3",children:[i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsxs("div",{className:"relative flex-1",children:[i.jsx("input",{type:"text",placeholder:"Search violations...",className:"w-full bg-dark-bg border border-dark-border rounded-lg px-4 py-2 pl-10 text-sm focus:outline-none focus:border-blue-500 transition-colors",value:e.search||"",onChange:m=>t({...e,search:m.target.value||void 0})}),i.jsx("span",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-dark-muted",children:"🔍"})]}),i.jsx("div",{className:"flex bg-dark-bg border border-dark-border rounded-lg p-0.5",children:Object.keys(Lu).map(m=>{const y=Lu[m];return i.jsx("button",{onClick:()=>r(m),className:`px-3 py-1.5 text-sm rounded-md transition-colors ${n===m?"bg-blue-500/20 text-blue-400":"text-dark-muted hover:text-dark-text"}`,title:y.description,children:y.icon},m)})})]}),i.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[i.jsxs("select",{className:"bg-dark-bg border border-dark-border rounded-lg px-3 py-2 text-sm focus:outline-none focus:border-blue-500",value:e.severity||"",onChange:m=>t({...e,severity:m.target.value||void 0}),children:[i.jsx("option",{value:"",children:"All Severities"}),Cs.map(m=>{const y=De[m];return i.jsxs("option",{value:m,children:[y.icon," ",y.label]},m)})]}),i.jsxs("select",{className:"bg-dark-bg border border-dark-border rounded-lg px-3 py-2 text-sm focus:outline-none focus:border-blue-500",value:e.category||"",onChange:m=>t({...e,category:m.target.value||void 0}),children:[i.jsx("option",{value:"",children:"All Categories"}),zh.map(m=>{const y=be[m];return i.jsxs("option",{value:m,children:[y.icon," ",y.label]},m)})]}),i.jsx("input",{type:"text",placeholder:"Filter by file...",className:"bg-dark-bg border border-dark-border rounded-lg px-3 py-2 text-sm focus:outline-none focus:border-blue-500 w-48",value:e.file||"",onChange:m=>t({...e,file:m.target.value||void 0})}),i.jsxs("div",{className:"flex items-center gap-1 ml-auto",children:[i.jsx("span",{className:"text-xs text-dark-muted",children:"Sort:"}),i.jsxs("select",{className:"bg-dark-bg border border-dark-border rounded-lg px-2 py-1.5 text-sm focus:outline-none focus:border-blue-500",value:s.field,onChange:m=>l({...s,field:m.target.value}),children:[i.jsx("option",{value:"severity",children:"Severity"}),i.jsx("option",{value:"category",children:"Category"}),i.jsx("option",{value:"file",children:"File"}),i.jsx("option",{value:"pattern",children:"Pattern"}),i.jsx("option",{value:"line",children:"Line"})]}),i.jsx("button",{onClick:()=>l({...s,direction:s.direction==="asc"?"desc":"asc"}),className:"p-1.5 bg-dark-bg border border-dark-border rounded-lg text-sm hover:bg-dark-border/50 transition-colors",title:s.direction==="asc"?"Ascending":"Descending",children:s.direction==="asc"?"↑":"↓"})]})]}),i.jsxs("div",{className:"flex items-center justify-between text-sm",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("span",{className:"text-dark-muted",children:[a," violation",a!==1?"s":""]}),c&&i.jsxs(i.Fragment,{children:[i.jsx("span",{className:"text-dark-border",children:"•"}),i.jsx("button",{onClick:o,className:"text-blue-400 hover:text-blue-300 transition-colors",children:"Clear filters"})]})]}),c&&i.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.severity&&i.jsxs("span",{className:"px-2 py-0.5 bg-dark-bg border border-dark-border rounded text-xs",children:[(u=De[e.severity])==null?void 0:u.icon," ",(h=De[e.severity])==null?void 0:h.label,i.jsx("button",{onClick:()=>t({...e,severity:void 0}),className:"ml-1 text-dark-muted hover:text-dark-text",children:"×"})]}),e.category&&i.jsxs("span",{className:"px-2 py-0.5 bg-dark-bg border border-dark-border rounded text-xs",children:[(d=be[e.category])==null?void 0:d.icon," ",(f=be[e.category])==null?void 0:f.label,i.jsx("button",{onClick:()=>t({...e,category:void 0}),className:"ml-1 text-dark-muted hover:text-dark-text",children:"×"})]}),e.file&&i.jsxs("span",{className:"px-2 py-0.5 bg-dark-bg border border-dark-border rounded text-xs",children:["📁 ",e.file.length>20?e.file.slice(0,20)+"...":e.file,i.jsx("button",{onClick:()=>t({...e,file:void 0}),className:"ml-1 text-dark-muted hover:text-dark-text",children:"×"})]})]})]})]})}function ml({violation:e,isExpanded:t,onToggle:n}){const r=De[e.severity];return i.jsxs("div",{className:`border rounded-lg overflow-hidden ${r.borderColor} ${r.bgColor}`,children:[i.jsx("button",{onClick:n,className:"w-full text-left p-4 hover:bg-dark-border/20 transition-colors",children:i.jsxs("div",{className:"flex items-start gap-3",children:[i.jsxs("span",{className:`px-2 py-0.5 rounded text-xs font-medium ${r.bgColor} ${r.color} border ${r.borderColor} shrink-0`,children:[r.icon," ",r.label]}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsx("div",{className:"font-medium",children:e.message}),i.jsxs("div",{className:"flex items-center gap-2 mt-1 text-sm text-dark-muted flex-wrap",children:[i.jsx("span",{className:"truncate",title:e.file,children:Qh(e.file)}),i.jsx("span",{children:"•"}),i.jsxs("span",{children:["Line ",e.range.start.line]}),i.jsx("span",{children:"•"}),i.jsx("span",{className:"text-blue-400",children:e.patternName})]})]}),i.jsx("span",{className:"text-dark-muted shrink-0",children:t?"▼":"▶"})]})}),t&&i.jsxs("div",{className:"p-4 pt-0 space-y-4 border-t border-dark-border/50",children:[i.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[i.jsxs("div",{children:[i.jsx("div",{className:"text-xs text-dark-muted mb-2",children:"Expected"}),i.jsx("div",{className:"p-3 bg-status-approved/10 border border-status-approved/20 rounded-lg font-mono text-sm",children:e.expected})]}),i.jsxs("div",{children:[i.jsx("div",{className:"text-xs text-dark-muted mb-2",children:"Actual"}),i.jsx("div",{className:"p-3 bg-severity-error/10 border border-severity-error/20 rounded-lg font-mono text-sm",children:e.actual})]})]}),e.codeSnippet&&i.jsxs("div",{children:[i.jsx("div",{className:"text-xs text-dark-muted mb-2",children:"Code"}),i.jsx("pre",{className:"p-3 bg-dark-bg rounded-lg overflow-x-auto font-mono text-xs leading-relaxed",children:e.codeSnippet})]}),i.jsxs("div",{className:"flex items-center gap-4 text-xs text-dark-muted",children:[i.jsxs("span",{children:["Pattern: ",e.patternId]}),i.jsxs("span",{children:["Range: ",ny(e.range.start,e.range.end)]})]})]})]})}function oy({group:e,isExpanded:t,onToggle:n,expandedViolations:r,onToggleViolation:s}){const l=De[e.metrics.maxSeverity];return i.jsxs("div",{className:"border border-dark-border rounded-lg overflow-hidden",children:[i.jsxs("button",{onClick:n,className:"w-full text-left p-4 bg-dark-surface hover:bg-dark-border/30 transition-colors",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[i.jsx("span",{className:"text-dark-muted",children:t?"▼":"▶"}),i.jsx("span",{className:"text-lg",children:"📄"}),i.jsxs("div",{className:"min-w-0",children:[i.jsx("div",{className:"font-medium truncate",title:e.file,children:Hh(e.file)}),i.jsx("div",{className:"text-xs text-dark-muted truncate",title:e.file,children:Qh(e.file)})]})]}),i.jsx("div",{className:"flex items-center gap-3 shrink-0",children:i.jsxs("span",{className:`px-2 py-1 rounded text-xs ${l.bgColor} ${l.color}`,children:[e.metrics.total," violation",e.metrics.total!==1?"s":""]})})]}),i.jsx("div",{className:"flex items-center gap-3 mt-2 ml-10 text-xs",children:Object.entries(e.metrics.bySeverity).map(([a,o])=>{if(o===0)return null;const c=De[a];return i.jsxs("span",{className:c.color,children:[c.icon," ",o]},a)})})]}),t&&i.jsx("div",{className:"border-t border-dark-border bg-dark-bg p-3 space-y-2",children:e.violations.map(a=>i.jsx(ml,{violation:a,isExpanded:r.has(a.id),onToggle:()=>s(a.id)},a.id))})]})}function cy({group:e,isExpanded:t,onToggle:n,expandedViolations:r,onToggleViolation:s}){return i.jsxs("div",{className:"border border-dark-border rounded-lg overflow-hidden",children:[i.jsxs("button",{onClick:n,className:"w-full text-left p-4 bg-dark-surface hover:bg-dark-border/30 transition-colors",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[i.jsx("span",{className:"text-dark-muted",children:t?"▼":"▶"}),i.jsx("span",{className:"text-lg",children:"🔍"}),i.jsxs("div",{className:"min-w-0",children:[i.jsx("div",{className:"font-medium truncate",children:e.patternName}),i.jsxs("div",{className:"text-xs text-dark-muted",children:[e.metrics.affectedFiles," file",e.metrics.affectedFiles!==1?"s":""," affected"]})]})]}),i.jsx("div",{className:"flex items-center gap-3 shrink-0",children:i.jsxs("span",{className:"px-2 py-1 rounded text-xs bg-severity-warning/10 text-severity-warning",children:[e.metrics.total," violation",e.metrics.total!==1?"s":""]})})]}),i.jsx("div",{className:"flex items-center gap-3 mt-2 ml-10 text-xs",children:Object.entries(e.metrics.bySeverity).map(([l,a])=>{if(a===0)return null;const o=De[l];return i.jsxs("span",{className:o.color,children:[o.icon," ",a]},l)})})]}),t&&i.jsx("div",{className:"border-t border-dark-border bg-dark-bg p-3 space-y-2",children:e.violations.map(l=>i.jsx(ml,{violation:l,isExpanded:r.has(l.id),onToggle:()=>s(l.id)},l.id))})]})}function Bh({group:e,isExpanded:t,onToggle:n,expandedViolations:r,onToggleViolation:s}){const l=Vh(e.category),a=e.metrics.bySeverity.error>0?"error":e.metrics.bySeverity.warning>0?"warning":e.metrics.bySeverity.info>0?"info":"hint",o=De[a];return i.jsxs("div",{className:`border rounded-lg overflow-hidden ${l.bgColor} border-dark-border`,children:[i.jsxs("button",{onClick:n,className:"w-full text-left p-4 hover:bg-dark-border/20 transition-colors",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[i.jsx("span",{className:"text-dark-muted",children:t?"▼":"▶"}),i.jsx("span",{className:"text-2xl",children:e.icon}),i.jsxs("div",{className:"min-w-0",children:[i.jsx("div",{className:`font-semibold ${l.color}`,children:e.displayName}),i.jsxs("div",{className:"text-xs text-dark-muted",children:[e.metrics.patterns.length," pattern",e.metrics.patterns.length!==1?"s":""," • ",e.metrics.affectedFiles," file",e.metrics.affectedFiles!==1?"s":""]})]})]}),i.jsx("div",{className:"flex items-center gap-3 shrink-0",children:i.jsxs("span",{className:`px-3 py-1.5 rounded-lg text-sm font-medium ${o.bgColor} ${o.color}`,children:[e.metrics.total," violation",e.metrics.total!==1?"s":""]})})]}),i.jsx("div",{className:"flex items-center gap-4 mt-3 ml-10 text-sm",children:Object.entries(e.metrics.bySeverity).map(([c,u])=>{if(u===0)return null;const h=De[c];return i.jsxs("span",{className:`flex items-center gap-1 ${h.color}`,children:[h.icon," ",u]},c)})})]}),t&&i.jsx("div",{className:"border-t border-dark-border bg-dark-bg p-3 space-y-2",children:e.violations.map(c=>i.jsx(ml,{violation:c,isExpanded:r.has(c.id),onToggle:()=>s(c.id)},c.id))})]})}function uy({group:e,isExpanded:t,onToggle:n,expandedCategories:r,onToggleCategory:s,expandedViolations:l,onToggleViolation:a}){const o=De[e.severity];return i.jsxs("div",{className:`border-2 rounded-xl overflow-hidden ${o.borderColor} ${o.bgColor}`,children:[i.jsxs("button",{onClick:n,className:"w-full text-left p-5 hover:bg-dark-border/10 transition-colors",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-4",children:[i.jsx("span",{className:"text-dark-muted text-lg",children:t?"▼":"▶"}),i.jsx("span",{className:"text-3xl",children:o.icon}),i.jsxs("div",{children:[i.jsx("div",{className:`text-xl font-bold ${o.color}`,children:o.label}),i.jsx("div",{className:"text-sm text-dark-muted",children:o.description})]})]}),i.jsx("div",{className:"flex items-center gap-4 shrink-0",children:i.jsxs("div",{className:"text-right",children:[i.jsx("div",{className:`text-3xl font-bold ${o.color}`,children:e.violations.length}),i.jsxs("div",{className:"text-xs text-dark-muted",children:["violation",e.violations.length!==1?"s":""]})]})})]}),e.categories.length>0&&i.jsxs("div",{className:"flex flex-wrap items-center gap-2 mt-4 ml-14",children:[e.categories.slice(0,5).map(c=>{const u=Vh(c.category);return i.jsxs("span",{className:`px-2 py-1 rounded text-xs ${u.bgColor} ${u.color} border border-dark-border/30`,children:[c.icon," ",c.displayName," (",c.metrics.total,")"]},c.category)}),e.categories.length>5&&i.jsxs("span",{className:"text-xs text-dark-muted",children:["+",e.categories.length-5," more"]})]})]}),t&&i.jsx("div",{className:"border-t border-dark-border bg-dark-bg p-4 space-y-3",children:e.categories.map(c=>i.jsx(Bh,{group:c,isExpanded:r.has(c.category),onToggle:()=>s(c.category),expandedViolations:l,onToggleViolation:a},c.category))})]})}function dy({violations:e,viewMode:t,expandedViolations:n,onToggleViolation:r}){const[s,l]=S.useState(new Set),[a,o]=S.useState(new Set),c=d=>{l(f=>{const m=new Set(f);return m.has(d)?m.delete(d):m.add(d),m})},u=d=>{o(f=>{const m=new Set(f);return m.has(d)?m.delete(d):m.add(d),m})};if(e.length===0)return i.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-center",children:[i.jsx("span",{className:"text-4xl mb-4",children:"✅"}),i.jsx("h3",{className:"text-lg font-medium mb-2",children:"No violations found"}),i.jsx("p",{className:"text-dark-muted text-sm max-w-md",children:"Great job! Your codebase is following all detected patterns consistently."})]});if(t==="list")return i.jsx("div",{className:"space-y-3",children:e.map(d=>i.jsx(ml,{violation:d,isExpanded:n.has(d.id),onToggle:()=>r(d.id)},d.id))});if(t==="by-severity"){const d=Jg(e);return i.jsx("div",{className:"space-y-4",children:d.map(f=>i.jsx(uy,{group:f,isExpanded:s.has(f.severity),onToggle:()=>c(f.severity),expandedCategories:a,onToggleCategory:u,expandedViolations:n,onToggleViolation:r},f.severity))})}if(t==="by-category"){const d=Uh(e);return i.jsx("div",{className:"space-y-3",children:d.map(f=>i.jsx(Bh,{group:f,isExpanded:s.has(f.category),onToggle:()=>c(f.category),expandedViolations:n,onToggleViolation:r},f.category))})}if(t==="by-file"){const d=Xg(e);return i.jsx("div",{className:"space-y-3",children:d.map(f=>i.jsx(oy,{group:f,isExpanded:s.has(f.file),onToggle:()=>c(f.file),expandedViolations:n,onToggleViolation:r},f.file))})}const h=Zg(e);return i.jsx("div",{className:"space-y-3",children:h.map(d=>i.jsx(cy,{group:d,isExpanded:s.has(d.patternId),onToggle:()=>c(d.patternId),expandedViolations:n,onToggleViolation:r},d.patternId))})}function fy(){const{violationFilters:e,setViolationFilters:t,expandedViolations:n,toggleViolationExpanded:r,realtimeViolations:s}=Lr(),[l,a]=S.useState("by-severity"),[o,c]=S.useState({field:"severity",direction:"desc"}),[u,h]=S.useState(!0),{data:d,isLoading:f,error:m}=Rh(e),y=S.useMemo(()=>d?ry(d,s):s,[d,s]),N=S.useMemo(()=>ey(y,o),[y,o]),w=S.useMemo(()=>Yg(y,s.length),[y,s.length]),v=S.useCallback(x=>{r(x)},[r]);return f?i.jsx("div",{className:"flex items-center justify-center h-64",children:i.jsxs("div",{className:"flex flex-col items-center gap-3",children:[i.jsx("div",{className:"w-8 h-8 border-2 border-blue-500 border-t-transparent rounded-full animate-spin"}),i.jsx("span",{className:"text-dark-muted",children:"Loading violations..."})]})}):m?i.jsxs("div",{className:"flex flex-col items-center justify-center h-64 text-center",children:[i.jsx("span",{className:"text-4xl mb-4",children:"⚠️"}),i.jsx("h3",{className:"text-lg font-medium text-severity-error mb-2",children:"Failed to load violations"}),i.jsx("p",{className:"text-dark-muted text-sm max-w-md",children:"There was an error loading the violation data. Please try refreshing the page."})]}):i.jsxs("div",{className:"space-y-6",children:[u&&i.jsxs("div",{className:"relative",children:[i.jsx("button",{onClick:()=>h(!1),className:"absolute -top-1 -right-1 p-1 text-dark-muted hover:text-dark-text z-10",title:"Hide statistics",children:i.jsx("span",{className:"text-xs",children:"✕"})}),i.jsx(ly,{statistics:w})]}),!u&&i.jsx("button",{onClick:()=>h(!0),className:"text-sm text-blue-400 hover:text-blue-300 transition-colors",children:"📊 Show statistics"}),i.jsx(ay,{filters:e,onFiltersChange:t,viewMode:l,onViewModeChange:a,sort:o,onSortChange:c,resultCount:N.length}),i.jsx("div",{className:"max-h-[calc(100vh-400px)] overflow-y-auto scrollbar-dark pr-2",children:i.jsx(dy,{violations:N,viewMode:l,expandedViolations:n,onToggleViolation:v})})]})}function Wh({node:e,depth:t=0,selectedPath:n,onSelect:r}){const{expandedFolders:s,toggleFolderExpanded:l}=Lr(),a=s.has(e.path),o=n===e.path,c=e.type==="directory",u=()=>{c?l(e.path):r(e.path)},h=e.severity?{error:"text-severity-error",warning:"text-severity-warning",info:"text-severity-info",hint:"text-severity-hint"}[e.severity]:"";return i.jsxs("div",{children:[i.jsxs("button",{onClick:u,className:`w-full text-left px-2 py-1 rounded text-sm flex items-center gap-2 hover:bg-dark-border/50 ${o?"bg-blue-500/20 text-blue-400":""}`,style:{paddingLeft:`${t*16+8}px`},children:[i.jsx("span",{className:"w-4 text-center text-dark-muted",children:c?a?"📂":"📁":"📄"}),i.jsx("span",{className:`flex-1 truncate ${h}`,children:e.name}),(e.patternCount||e.violationCount)&&i.jsxs("span",{className:"text-xs text-dark-muted",children:[e.patternCount?`${e.patternCount}P`:"",e.patternCount&&e.violationCount?" ":"",e.violationCount?`${e.violationCount}V`:""]})]}),c&&a&&e.children&&i.jsx("div",{children:e.children.map(d=>i.jsx(Wh,{node:d,depth:t+1,selectedPath:n,onSelect:r},d.path))})]})}function hy({path:e}){const{data:t,isLoading:n,error:r}=Av(e);return n?i.jsx("div",{className:"text-dark-muted",children:"Loading file details..."}):r||!t?i.jsx("div",{className:"text-severity-error",children:"Failed to load file details"}):i.jsxs("div",{className:"space-y-4",children:[i.jsxs("div",{children:[i.jsx("h3",{className:"font-medium truncate",title:t.path,children:t.path.split("/").pop()}),i.jsxs("div",{className:"text-sm text-dark-muted mt-1",children:[i.jsx("span",{children:t.language}),i.jsx("span",{className:"mx-2",children:"•"}),i.jsxs("span",{children:[t.lineCount," lines"]})]})]}),t.patterns.length>0&&i.jsxs("div",{children:[i.jsxs("h4",{className:"text-sm font-medium mb-2",children:["Patterns (",t.patterns.length,")"]}),i.jsx("div",{className:"space-y-2",children:t.patterns.map(s=>i.jsxs("div",{className:"p-2 bg-dark-bg rounded text-sm",children:[i.jsx("div",{className:"font-medium",children:s.name}),i.jsxs("div",{className:"text-xs text-dark-muted mt-1",children:[s.category," • ",s.locations.length," locations"]})]},s.id))})]}),t.violations.length>0&&i.jsxs("div",{children:[i.jsxs("h4",{className:"text-sm font-medium mb-2",children:["Violations (",t.violations.length,")"]}),i.jsx("div",{className:"space-y-2",children:t.violations.map(s=>i.jsxs("div",{className:"p-2 bg-dark-bg rounded text-sm",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:`px-1.5 py-0.5 rounded text-xs badge-${s.severity}`,children:s.severity}),i.jsx("span",{className:"truncate",children:s.message})]}),i.jsxs("div",{className:"text-xs text-dark-muted mt-1",children:["Line ",s.range.start.line]})]},s.id))})]}),t.patterns.length===0&&t.violations.length===0&&i.jsx("div",{className:"text-dark-muted text-sm",children:"No patterns or violations in this file"})]})}function my(){const[e,t]=S.useState(null),{data:n,isLoading:r,error:s}=$v();return r?i.jsx("div",{className:"flex items-center justify-center h-64",children:i.jsx("div",{className:"text-dark-muted",children:"Loading file tree..."})}):s?i.jsx("div",{className:"flex items-center justify-center h-64",children:i.jsx("div",{className:"text-severity-error",children:"Failed to load file tree"})}):i.jsxs("div",{className:"flex gap-6",children:[i.jsx("div",{className:"w-80 shrink-0",children:i.jsx("div",{className:"card max-h-[600px] overflow-y-auto scrollbar-dark",children:n&&n.length>0?n.map(l=>i.jsx(Wh,{node:l,selectedPath:e,onSelect:t},l.path)):i.jsx("div",{className:"text-dark-muted text-center py-4",children:"No files found"})})}),i.jsx("div",{className:"flex-1",children:i.jsx("div",{className:"card",children:e?i.jsx(hy,{path:e}):i.jsx("div",{className:"text-dark-muted text-center py-8",children:"Select a file to view details"})})})]})}const py=e=>(t,n,r)=>{const s=r.subscribe;return r.subscribe=(a,o,c)=>{let u=a;if(o){const h=(c==null?void 0:c.equalityFn)||Object.is;let d=a(r.getState());u=f=>{const m=a(f);if(!h(d,m)){const y=d;o(d=m,y)}},c!=null&&c.fireImmediately&&o(d,d)}return s(u)},e(t,n,r)},xy=py,Ry={critical:"#ff3366",high:"#ff9933",medium:"#ffcc00",low:"#33ccff",public:"#66ff99"},Fy={critical:.8,high:.6,medium:.4,low:.2,public:.1},My={P0:"#ff0000",P1:"#ff6600",P2:"#ffcc00",P3:"#66ccff",P4:"#99ff99"},Ly={public:"#ff3333",authenticated:"#ffcc00",admin:"#33cc33",internal:"#3366ff"},Dy={read:"#33ccff",write:"#ff9933",delete:"#ff3366",unknown:"#999999"},$y={MIN_RADIUS:.5,MAX_RADIUS:3},Ay={RADIUS:.15,ORBIT_RADIUS:2,ORBIT_SPEED:.5},zy={SCALE:.8},Uy={BASE_WIDTH:.05,MAX_WIDTH:.3,CURVE_SEGMENTS:50,FLOW_SPEED:2,DASH_SIZE:.5,GAP_SIZE:.3},Vy={RADIUS:40,HEIGHT:15,CLUSTER_SEPARATION:20,SIMULATION_ITERATIONS:300,FORCE_STRENGTH:-30,LINK_DISTANCE:10},qi={DEFAULT_POSITION:{x:0,y:30,z:60},DEFAULT_TARGET:{x:0,y:0,z:0},FOV:60,NEAR:.1,FAR:1e3,MIN_ZOOM:.5,MAX_ZOOM:5},Qy={STAR_COUNT:5e3,STAR_SIZE:.1},Hy={HOVER_SCALE:1.2,SELECTION_SCALE:1.3,PULSE_FREQUENCY:2,IDLE_ROTATION:.001},By={FONT_SIZE:12,FONT_FAMILY:"Inter, system-ui, sans-serif",BG_OPACITY:.8,PADDING:4,OFFSET:.5},Wy={auth:["users","accounts","sessions","tokens","permissions","roles"],commerce:["orders","products","carts","payments","invoices","subscriptions"],content:["posts","comments","media","files","documents","attachments"],messaging:["messages","notifications","emails","chats","threads"],analytics:["events","logs","metrics","analytics","tracking"],config:["settings","preferences","configurations","features","flags"]},Ky={auth:"#ff6b6b",commerce:"#4ecdc4",content:"#45b7d1",messaging:"#96ceb4",analytics:"#dda0dd",config:"#98d8c8",other:"#7f8c8d"},$u={selectedTable:null,selectedField:null,selectedEntryPoint:null,selectedPath:null,hoveredNode:null,hoveredType:null},Au={position:qi.DEFAULT_POSITION,target:qi.DEFAULT_TARGET,zoom:1},zu={minSensitivity:null,operationType:null,untestedOnly:!1,publicOnly:!1,searchQuery:"",clusters:[]},vy={showFields:!0,showPaths:!0,showRelationships:!0,showLabels:!0,enableBloom:!0,animationSpeed:1,pathOpacity:.6},$r=Th()(xy((e,t)=>({galaxyData:null,isLoading:!1,error:null,selection:$u,camera:Au,viewMode:"overview",filters:zu,display:vy,recentEvents:[],isLiveMode:!1,isPanelOpen:!1,activePanel:null,searchQuery:"",searchResults:[],setGalaxyData:n=>e({galaxyData:n,isLoading:!1,error:null}),setLoading:n=>e({isLoading:n}),setError:n=>e({error:n,isLoading:!1}),selectTable:n=>e(r=>({selection:{...r.selection,selectedTable:n,selectedField:null},isPanelOpen:n!==null,activePanel:n!==null?"details":r.activePanel})),selectField:n=>e(r=>({selection:{...r.selection,selectedField:n}})),selectEntryPoint:n=>e(r=>({selection:{...r.selection,selectedEntryPoint:n,selectedTable:null,selectedField:null},isPanelOpen:n!==null,activePanel:n!==null?"details":r.activePanel})),selectPath:n=>e(r=>({selection:{...r.selection,selectedPath:n}})),setHovered:(n,r)=>e(s=>({selection:{...s.selection,hoveredNode:n,hoveredType:r}})),clearSelection:()=>e({selection:$u,isPanelOpen:!1,activePanel:null}),setCameraPosition:n=>e(r=>({camera:{...r.camera,position:n}})),setCameraTarget:n=>e(r=>({camera:{...r.camera,target:n}})),setZoom:n=>e(r=>({camera:{...r.camera,zoom:Math.max(qi.MIN_ZOOM,Math.min(qi.MAX_ZOOM,n))}})),resetCamera:()=>e({camera:Au}),focusOnNode:n=>{const{galaxyData:r}=t();if(!r)return;const s=r.tables.find(o=>o.id===n),l=r.entryPoints.find(o=>o.id===n),a=(s==null?void 0:s.position)||(l==null?void 0:l.position);a&&e(o=>({camera:{...o.camera,target:a,position:{x:a.x,y:a.y+20,z:a.z+30}}}))},setViewMode:n=>e({viewMode:n}),setFilters:n=>e(r=>({filters:{...r.filters,...n}})),setDisplay:n=>e(r=>({display:{...r.display,...n}})),resetFilters:()=>e({filters:zu}),addEvent:n=>e(r=>({recentEvents:[n,...r.recentEvents].slice(0,100)})),clearEvents:()=>e({recentEvents:[]}),setLiveMode:n=>e({isLiveMode:n}),togglePanel:n=>e(r=>({isPanelOpen:r.activePanel===n?!r.isPanelOpen:!0,activePanel:n})),closePanel:()=>e({isPanelOpen:!1,activePanel:null}),setSearchQuery:n=>e({searchQuery:n}),setSearchResults:n=>e({searchResults:n})}))),Gy=()=>$r(e=>!e.selection.selectedTable||!e.galaxyData?null:e.galaxyData.tables.find(t=>t.id===e.selection.selectedTable)||null),qy=()=>$r(e=>!e.selection.selectedEntryPoint||!e.galaxyData?null:e.galaxyData.entryPoints.find(t=>t.id===e.selection.selectedEntryPoint)||null),Yy=()=>$r(e=>!e.selection.selectedTable||!e.galaxyData?[]:e.galaxyData.dataPaths.filter(t=>t.targetTableId===e.selection.selectedTable)),Xy=()=>$r(e=>{if(!e.galaxyData)return[];let t=e.galaxyData.tables;const{filters:n}=e;if(n.minSensitivity){const r=["public","low","medium","high","critical"],s=r.indexOf(n.minSensitivity);t=t.filter(l=>r.indexOf(l.sensitivity)>=s)}if(n.clusters.length>0&&(t=t.filter(r=>r.cluster&&n.clusters.includes(r.cluster))),n.searchQuery){const r=n.searchQuery.toLowerCase();t=t.filter(s=>s.name.toLowerCase().includes(r)||s.fields.some(l=>l.name.toLowerCase().includes(r)))}return t}),Zy=()=>$r(e=>{if(!e.galaxyData)return[];let t=e.galaxyData.dataPaths;const{filters:n}=e;return n.operationType&&(t=t.filter(r=>r.operation===n.operationType)),n.untestedOnly&&(t=t.filter(r=>!r.isTested)),t}),Jy=()=>$r(e=>{if(!e.galaxyData)return[];let t=e.galaxyData.entryPoints;const{filters:n}=e;return n.publicOnly&&(t=t.filter(r=>r.authLevel==="public")),t});function gy({detector:e,onToggle:t}){return i.jsxs("div",{className:"flex items-center justify-between p-3 bg-dark-bg rounded",children:[i.jsxs("div",{children:[i.jsx("div",{className:"font-medium",children:e.name}),i.jsxs("div",{className:"text-xs text-dark-muted mt-0.5",children:[e.category," • ",e.id]})]}),i.jsx("button",{onClick:()=>t(!e.enabled),className:`w-12 h-6 rounded-full transition-colors ${e.enabled?"bg-status-approved":"bg-dark-border"}`,children:i.jsx("div",{className:`w-5 h-5 rounded-full bg-white shadow transition-transform ${e.enabled?"translate-x-6":"translate-x-0.5"}`})})]})}function yy({patterns:e,onChange:t}){const[n,r]=S.useState(""),s=()=>{n.trim()&&!e.includes(n.trim())&&(t([...e,n.trim()]),r(""))},l=a=>{t(e.filter(o=>o!==a))};return i.jsxs("div",{children:[i.jsxs("div",{className:"flex gap-2 mb-3",children:[i.jsx("input",{type:"text",placeholder:"Add ignore pattern (e.g., **/test/**)",className:"flex-1 bg-dark-bg border border-dark-border rounded px-3 py-1.5 text-sm",value:n,onChange:a=>r(a.target.value),onKeyDown:a=>a.key==="Enter"&&s()}),i.jsx("button",{onClick:s,className:"btn btn-secondary text-sm",children:"Add"})]}),i.jsxs("div",{className:"space-y-1",children:[e.map(a=>i.jsxs("div",{className:"flex items-center justify-between p-2 bg-dark-bg rounded text-sm",children:[i.jsx("code",{className:"font-mono",children:a}),i.jsx("button",{onClick:()=>l(a),className:"text-dark-muted hover:text-severity-error",children:"✕"})]},a)),e.length===0&&i.jsx("div",{className:"text-dark-muted text-sm",children:"No ignore patterns configured"})]})]})}function jy({overrides:e,onChange:t}){const[n,r]=S.useState(""),[s,l]=S.useState("warning"),a=()=>{n.trim()&&(t({...e,[n.trim()]:s}),r(""))},o=u=>{const h={...e};delete h[u],t(h)},c=["error","warning","info","hint"];return i.jsxs("div",{children:[i.jsxs("div",{className:"flex gap-2 mb-3",children:[i.jsx("input",{type:"text",placeholder:"Pattern ID",className:"flex-1 bg-dark-bg border border-dark-border rounded px-3 py-1.5 text-sm",value:n,onChange:u=>r(u.target.value)}),i.jsx("select",{className:"bg-dark-bg border border-dark-border rounded px-3 py-1.5 text-sm",value:s,onChange:u=>l(u.target.value),children:c.map(u=>i.jsx("option",{value:u,children:u},u))}),i.jsx("button",{onClick:a,className:"btn btn-secondary text-sm",children:"Add"})]}),i.jsxs("div",{className:"space-y-1",children:[Object.entries(e).map(([u,h])=>i.jsxs("div",{className:"flex items-center justify-between p-2 bg-dark-bg rounded text-sm",children:[i.jsx("code",{className:"font-mono",children:u}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:`px-2 py-0.5 rounded text-xs badge-${h}`,children:h}),i.jsx("button",{onClick:()=>o(u),className:"text-dark-muted hover:text-severity-error",children:"✕"})]})]},u)),Object.keys(e).length===0&&i.jsx("div",{className:"text-dark-muted text-sm",children:"No severity overrides configured"})]})]})}function Ny(){const{data:e,isLoading:t,error:n}=zv(),r=Uv();if(t)return i.jsx("div",{className:"flex items-center justify-center h-64",children:i.jsx("div",{className:"text-dark-muted",children:"Loading configuration..."})});if(n||!e)return i.jsx("div",{className:"flex items-center justify-center h-64",children:i.jsx("div",{className:"text-severity-error",children:"Failed to load configuration"})});const s=(c,u)=>{const h=e.detectors.map(d=>d.id===c?{...d,enabled:u}:d);r.mutate({detectors:h})},l=c=>{r.mutate({ignorePatterns:c})},a=c=>{r.mutate({severityOverrides:c})},o=e.detectors.reduce((c,u)=>{const h=u.category;return c[h]||(c[h]=[]),c[h].push(u),c},{});return i.jsxs("div",{className:"space-y-6 max-w-3xl",children:[i.jsxs("div",{className:"card",children:[i.jsx("h3",{className:"font-medium mb-2",children:"Configuration"}),i.jsxs("div",{className:"text-sm text-dark-muted",children:["Version: ",e.version]})]}),i.jsxs("div",{className:"card",children:[i.jsx("h3",{className:"font-medium mb-4",children:"Detectors"}),i.jsx("div",{className:"space-y-4",children:Object.entries(o).map(([c,u])=>i.jsxs("div",{children:[i.jsx("h4",{className:"text-sm text-dark-muted mb-2 capitalize",children:c}),i.jsx("div",{className:"space-y-2",children:u.map(h=>i.jsx(gy,{detector:h,onToggle:d=>s(h.id,d)},h.id))})]},c))})]}),i.jsxs("div",{className:"card",children:[i.jsx("h3",{className:"font-medium mb-4",children:"Ignore Patterns"}),i.jsx(yy,{patterns:e.ignorePatterns,onChange:l})]}),i.jsxs("div",{className:"card",children:[i.jsx("h3",{className:"font-medium mb-4",children:"Severity Overrides"}),i.jsx(jy,{overrides:e.severityOverrides,onChange:a})]}),r.isPending&&i.jsx("div",{className:"text-sm text-dark-muted",children:"Saving..."}),r.isError&&i.jsx("div",{className:"text-sm text-severity-error",children:"Failed to save changes"})]})}class by extends S.Component{constructor(t){super(t),this.state={hasError:!1,error:null}}static getDerivedStateFromError(t){return{hasError:!0,error:t}}componentDidCatch(t,n){console.error("Dashboard error:",t,n)}render(){return this.state.hasError?this.props.fallback?this.props.fallback:i.jsx("div",{className:"min-h-screen bg-dark-bg text-dark-text flex items-center justify-center p-6",children:i.jsxs("div",{className:"card max-w-md text-center",children:[i.jsx("div",{className:"text-4xl mb-4",children:"⚠️"}),i.jsx("h2",{className:"text-xl font-semibold mb-2",children:"Something went wrong"}),i.jsx("p",{className:"text-dark-muted mb-4",children:"The dashboard encountered an error. Try refreshing the page."}),this.state.error&&i.jsx("pre",{className:"text-xs text-left bg-dark-bg p-3 rounded overflow-auto max-h-32 text-severity-error",children:this.state.error.message}),i.jsx("button",{onClick:()=>window.location.reload(),className:"btn btn-primary mt-4",children:"Refresh Page"})]})}):this.props.children}}const ky=S.lazy(()=>iv(()=>import("./GalaxyTab-DA9097-Z.js"),[]).then(e=>({default:e.GalaxyTab}))),wy=[{id:"overview",label:"Overview"},{id:"patterns",label:"Patterns"},{id:"contracts",label:"Contracts"},{id:"violations",label:"Violations"},{id:"files",label:"Files"},{id:"galaxy",label:"🌌 Galaxy"},{id:"settings",label:"Settings"}];function Sy({status:e}){const t={connected:{color:"bg-status-approved",label:"Connected"},connecting:{color:"bg-severity-warning",label:"Connecting..."},disconnected:{color:"bg-dark-muted",label:"Disconnected"}}[e];return i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:`h-2 w-2 rounded-full ${t.color}`}),i.jsx("span",{className:"text-sm text-dark-muted",children:t.label})]})}function Cy(){return i.jsxs("div",{className:"flex flex-col items-center justify-center h-[calc(100vh-200px)] bg-slate-950 rounded-lg",children:[i.jsx("div",{className:"text-6xl mb-4 animate-pulse",children:"🌌"}),i.jsx("p",{className:"text-slate-400",children:"Loading Galaxy..."})]})}function Ey({tab:e}){switch(e){case"overview":return i.jsx(rg,{});case"patterns":return i.jsx(Eg,{});case"contracts":return i.jsx(Gg,{});case"violations":return i.jsx(fy,{});case"files":return i.jsx(my,{});case"galaxy":return i.jsx(S.Suspense,{fallback:i.jsx(Cy,{}),children:i.jsx(ky,{})});case"settings":return i.jsx(Ny,{});default:return null}}function Py(){const{connectionStatus:e,activeTab:t,setActiveTab:n}=Lr();return qv(),i.jsxs("div",{className:"min-h-screen bg-dark-bg text-dark-text",children:[i.jsx("header",{className:"border-b border-dark-border bg-dark-surface px-6 py-4",children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("div",{className:"flex items-center gap-3",children:i.jsx("h1",{className:"text-xl font-semibold",children:"Drift Dashboard"})}),i.jsx(Sy,{status:e})]})}),i.jsx("nav",{className:"border-b border-dark-border bg-dark-surface",children:i.jsx("div",{className:"flex gap-1 px-6",children:wy.map(r=>i.jsx("button",{onClick:()=>n(r.id),className:`px-4 py-3 text-sm font-medium transition-colors border-b-2 ${t===r.id?"text-dark-text border-blue-500":"text-dark-muted hover:text-dark-text border-transparent hover:border-dark-border"}`,children:r.label},r.id))})}),i.jsx("main",{className:"p-6",children:i.jsx(Ey,{tab:t})})]})}const Ty=new Hx({defaultOptions:{queries:{staleTime:3e4,retry:1}}}),Kh=document.getElementById("root");if(!Kh)throw new Error("Root element not found");ql.createRoot(Kh).render(i.jsx(cd.StrictMode,{children:i.jsx(by,{children:i.jsx(Bx,{client:Ty,children:i.jsx(Py,{})})})}));export{Ly as A,Ky as C,Wy as D,zy as E,Ay as F,Vy as G,By as L,Dy as O,Uy as P,Fy as S,$y as T,iv as _,Ry as a,My as b,jx as c,Hy as d,Qy as e,qi as f,Zu as g,Xy as h,Zy as i,i as j,Jy as k,Gy as l,qy as m,Yy as n,Oy as o,S as r,$r as u};
|
|
59
|
-
//# sourceMappingURL=main-
|
|
58
|
+
`)),o(!0),setTimeout(()=>o(!1),2e3)}catch(f){console.error("Failed to copy:",f)}finally{l(!1)}}};if(n)return i.jsx("div",{className:"flex items-center justify-center py-12",children:i.jsx("div",{className:"text-dark-muted",children:"Loading contract details..."})});if(r||!t)return i.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[i.jsx("span",{className:"text-3xl mb-3",children:"⚠️"}),i.jsx("div",{className:"text-severity-error",children:"Failed to load contract"})]});const u=Dr[t.method],h=dr[t.status],d=Fg(t);return i.jsxs("div",{className:"space-y-5",children:[i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[i.jsx("span",{className:`font-mono text-lg font-bold px-2 py-1 rounded ${u.bgColor} ${u.color}`,children:t.method}),i.jsx("span",{className:"font-mono text-lg truncate",title:t.endpoint,children:t.endpoint})]}),i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsxs("span",{className:`px-2 py-1 rounded text-xs ${h.bgColor} ${h.color}`,children:[h.icon," ",h.label]}),i.jsxs("span",{className:`text-sm ${Ah(t.confidence.score)}`,children:[Wi(t.confidence.score)," confidence"]})]})]}),d.issues.length>0&&i.jsxs("div",{className:`p-3 rounded-lg text-sm ${d.status==="critical"?"bg-severity-error/10 border border-severity-error/20":d.status==="warning"?"bg-severity-warning/10 border border-severity-warning/20":"bg-status-approved/10 border border-status-approved/20"}`,children:[i.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[i.jsx("span",{children:d.status==="critical"?"🔴":d.status==="warning"?"🟡":"🟢"}),i.jsxs("span",{className:"font-medium",children:["Health Score: ",d.score]})]}),i.jsx("ul",{className:"text-xs text-dark-muted list-disc list-inside",children:d.issues.map((f,m)=>i.jsx("li",{children:f},m))})]}),i.jsx(Bg,{contract:t,onCopyForAI:c,isCopying:s,copySuccess:a}),i.jsxs("div",{className:"p-4 bg-dark-bg rounded-lg",children:[i.jsxs("h4",{className:"text-sm font-medium mb-3 text-green-400 flex items-center gap-2",children:[i.jsx("span",{children:"🔧"})," Backend"]}),i.jsxs("div",{className:"text-xs space-y-2",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:"text-dark-muted",children:"File:"}),i.jsxs("span",{className:"font-mono",children:[t.backend.file,":",t.backend.line]})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:"text-dark-muted",children:"Framework:"}),i.jsx("span",{children:t.backend.framework})]}),t.backend.responseFields.length>0&&i.jsx(Mu,{fields:t.backend.responseFields,title:"Response Fields:",color:"text-green-400"})]})]}),i.jsxs("div",{className:"p-4 bg-dark-bg rounded-lg",children:[i.jsxs("h4",{className:"text-sm font-medium mb-3 text-blue-400 flex items-center gap-2",children:[i.jsx("span",{children:"📱"})," Frontend (",t.frontend.length,")"]}),i.jsxs("div",{className:"space-y-4",children:[t.frontend.slice(0,dt.FRONTEND_CALLS_PREVIEW).map((f,m)=>i.jsxs("div",{className:"text-xs border-l-2 border-dark-border pl-3",children:[i.jsxs("div",{className:"font-mono",children:[f.file,":",f.line]}),i.jsxs("div",{className:"text-dark-muted",children:["Library: ",f.library]}),f.responseType&&i.jsxs("div",{className:"text-dark-muted",children:["Type: ",i.jsx("span",{className:"text-purple-400",children:f.responseType})]}),f.responseFields.length>0&&i.jsx(Mu,{fields:f.responseFields,title:"Expected Fields:",color:"text-blue-400"})]},m)),t.frontend.length>dt.FRONTEND_CALLS_PREVIEW&&i.jsxs("div",{className:"text-xs text-dark-muted",children:["... and ",t.frontend.length-dt.FRONTEND_CALLS_PREVIEW," more"]})]})]}),t.mismatches.length>0&&i.jsxs("div",{className:"p-4 bg-severity-error/10 border border-severity-error/30 rounded-lg",children:[i.jsxs("h4",{className:"text-sm font-medium mb-3 text-severity-error flex items-center gap-2",children:[i.jsx("span",{children:"⚠️"})," Mismatches (",t.mismatches.length,")"]}),i.jsxs("div",{className:"space-y-2 max-h-64 overflow-y-auto scrollbar-dark",children:[t.mismatches.slice(0,dt.MISMATCHES_PREVIEW).map((f,m)=>i.jsx(Hg,{mismatch:f},m)),t.mismatches.length>dt.MISMATCHES_PREVIEW&&i.jsxs("div",{className:"text-xs text-dark-muted text-center py-2",children:["... and ",t.mismatches.length-dt.MISMATCHES_PREVIEW," more"]})]})]})]})}function Kg(){return i.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[i.jsx("span",{className:"text-4xl mb-4",children:"🔗"}),i.jsx("h3",{className:"text-lg font-medium mb-2",children:"No contract selected"}),i.jsx("p",{className:"text-dark-muted text-sm max-w-xs",children:"Select a contract from the list to view its details, fields, and mismatches."})]})}function Gg(){const[e,t]=S.useState({}),[n,r]=S.useState("list"),[s,l]=S.useState({field:"mismatches",direction:"desc"}),[a,o]=S.useState(null),[c,u]=S.useState(!0),{data:h,isLoading:d,error:f}=Vv(e),m=S.useMemo(()=>h?Rg(h,s):[],[h,s]),y=S.useMemo(()=>h?Tg(h):null,[h]),N=S.useCallback(w=>{o(w===a?null:w)},[a]);return d?i.jsx("div",{className:"flex items-center justify-center h-64",children:i.jsxs("div",{className:"flex flex-col items-center gap-3",children:[i.jsx("div",{className:"w-8 h-8 border-2 border-blue-500 border-t-transparent rounded-full animate-spin"}),i.jsx("span",{className:"text-dark-muted",children:"Loading contracts..."})]})}):f?i.jsxs("div",{className:"flex flex-col items-center justify-center h-64 text-center",children:[i.jsx("span",{className:"text-4xl mb-4",children:"⚠️"}),i.jsx("h3",{className:"text-lg font-medium text-severity-error mb-2",children:"Failed to load contracts"}),i.jsx("p",{className:"text-dark-muted text-sm max-w-md",children:"There was an error loading the contract data. Please try refreshing the page."})]}):i.jsxs("div",{className:"space-y-6",children:[y&&c&&i.jsxs("div",{className:"relative",children:[i.jsx("button",{onClick:()=>u(!1),className:"absolute -top-1 -right-1 p-1 text-dark-muted hover:text-dark-text z-10",title:"Hide statistics",children:i.jsx("span",{className:"text-xs",children:"✕"})}),i.jsx(Ag,{statistics:y})]}),!c&&i.jsx("button",{onClick:()=>u(!0),className:"text-sm text-blue-400 hover:text-blue-300 transition-colors",children:"📊 Show statistics"}),i.jsxs("div",{className:"flex gap-6",children:[i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsx("div",{className:"mb-4",children:i.jsx(zg,{filters:e,onFiltersChange:t,viewMode:n,onViewModeChange:r,sort:s,onSortChange:l,resultCount:(h==null?void 0:h.length)||0})}),i.jsx("div",{className:"max-h-[calc(100vh-400px)] overflow-y-auto scrollbar-dark pr-2",children:i.jsx(Qg,{contracts:m,viewMode:n,selectedContractId:a,onSelectContract:N})})]}),i.jsx("div",{className:"w-96 shrink-0",children:i.jsx("div",{className:"sticky top-4 bg-dark-surface border border-dark-border rounded-xl p-5",children:a?i.jsx(Wg,{contractId:a}):i.jsx(Kg,{})})})]})]})}const Cs=["error","warning","info","hint"],De={error:{label:"Error",icon:"🔴",color:"text-severity-error",bgColor:"bg-severity-error/10",borderColor:"border-severity-error/30",description:"Critical issues that must be fixed",priority:4},warning:{label:"Warning",icon:"🟡",color:"text-severity-warning",bgColor:"bg-severity-warning/10",borderColor:"border-severity-warning/30",description:"Issues that should be addressed",priority:3},info:{label:"Info",icon:"🔵",color:"text-severity-info",bgColor:"bg-severity-info/10",borderColor:"border-severity-info/30",description:"Informational notices",priority:2},hint:{label:"Hint",icon:"💡",color:"text-dark-muted",bgColor:"bg-dark-muted/10",borderColor:"border-dark-muted/30",description:"Suggestions for improvement",priority:1}},be={security:{label:"Security",icon:"🔒",color:"text-red-400",bgColor:"bg-red-500/10",description:"Security vulnerabilities and risks",priority:10},auth:{label:"Authentication",icon:"🔑",color:"text-orange-400",bgColor:"bg-orange-500/10",description:"Authentication and authorization issues",priority:9},api:{label:"API",icon:"🌐",color:"text-blue-400",bgColor:"bg-blue-500/10",description:"API structure and consistency",priority:8},"data-access":{label:"Data Access",icon:"💾",color:"text-purple-400",bgColor:"bg-purple-500/10",description:"Database and data layer patterns",priority:7},errors:{label:"Error Handling",icon:"⚠️",color:"text-yellow-400",bgColor:"bg-yellow-500/10",description:"Error handling patterns",priority:6},structural:{label:"Structure",icon:"🏗️",color:"text-cyan-400",bgColor:"bg-cyan-500/10",description:"Code organization and architecture",priority:5},components:{label:"Components",icon:"🧩",color:"text-green-400",bgColor:"bg-green-500/10",description:"Component patterns and structure",priority:4},styling:{label:"Styling",icon:"🎨",color:"text-pink-400",bgColor:"bg-pink-500/10",description:"CSS and styling patterns",priority:3},performance:{label:"Performance",icon:"⚡",color:"text-amber-400",bgColor:"bg-amber-500/10",description:"Performance optimizations",priority:2},documentation:{label:"Documentation",icon:"📝",color:"text-slate-400",bgColor:"bg-slate-500/10",description:"Documentation and comments",priority:1},testing:{label:"Testing",icon:"🧪",color:"text-teal-400",bgColor:"bg-teal-500/10",description:"Testing patterns and coverage",priority:1},other:{label:"Other",icon:"📋",color:"text-gray-400",bgColor:"bg-gray-500/10",description:"Other violations",priority:0}},zh=Object.keys(be).sort((e,t)=>be[t].priority-be[e].priority),Gl={TOP_FILES:5,TOP_PATTERNS:5,TOP_CATEGORIES:5},Lu={list:{label:"List",icon:"📋",description:"All violations in a flat list"},"by-severity":{label:"By Severity",icon:"⚠️",description:"Violations grouped by severity level"},"by-category":{label:"By Category",icon:"📂",description:"Violations grouped by category"},"by-file":{label:"By File",icon:"📁",description:"Violations grouped by file"},"by-pattern":{label:"By Pattern",icon:"🔍",description:"Violations grouped by pattern"}};function qg(e){const t={error:0,warning:0,info:0,hint:0},n={},r={},s={};for(const l of e){t[l.severity]++,n[l.patternId]=(n[l.patternId]||0)+1,r[l.file]=(r[l.file]||0)+1;const a=Ki(l.patternId,l.patternName);s[a]=(s[a]||0)+1}return{total:e.length,bySeverity:t,byPattern:n,byFile:r,byCategory:s,criticalCount:t.error+t.warning}}function Ki(e,t){if(t){const l=t.toLowerCase(),a={"sql injection":"security",xss:"security",csrf:"security",credential:"security",secret:"security",sanitiz:"security",security:"security",auth:"auth",rbac:"auth",permission:"auth",role:"auth",session:"auth",token:"auth",jwt:"auth",audit:"auth","http method":"api",route:"api",endpoint:"api","response envelope":"api",rest:"api",api:"api",database:"data-access",query:"data-access",repository:"data-access","data access":"data-access",error:"errors",exception:"errors",barrel:"structural",import:"structural",export:"structural","file naming":"structural",directory:"structural",module:"structural",package:"structural",circular:"structural",component:"components",composition:"components","state pattern":"components","ref forward":"components",hook:"components",prop:"components",typography:"styling",color:"styling",spacing:"styling","z-index":"styling",responsive:"styling",tailwind:"styling",css:"styling",style:"styling","class naming":"styling",performance:"performance",lazy:"performance",memo:"performance",cache:"performance"};for(const[o,c]of Object.entries(a))if(l.includes(o))return c}const n=e.toLowerCase();if(n.includes("/")){const a=n.split("/")[0],o={api:"api",auth:"auth",security:"security",styling:"styling",structural:"structural",components:"components",component:"components",data:"data-access",database:"data-access",error:"errors",errors:"errors",performance:"performance",testing:"testing",documentation:"documentation"};if(o[a])return o[a]}const r=n.replace(/\//g,"-").split("-"),s={security:"security",xss:"security",injection:"security",csrf:"security",sanitize:"security",validate:"security",credential:"security",secret:"security",auth:"auth",authentication:"auth",authorization:"auth",rbac:"auth",permission:"auth",role:"auth",session:"auth",token:"auth",jwt:"auth",audit:"auth",api:"api",endpoint:"api",rest:"api",route:"api",handler:"api",controller:"api",middleware:"api",request:"api",response:"api",http:"api",data:"data-access",database:"data-access",sql:"data-access",query:"data-access",repository:"data-access",model:"data-access",schema:"data-access",migration:"data-access",error:"errors",exception:"errors",throw:"errors",catch:"errors",handling:"errors",structural:"structural",file:"structural",directory:"structural",naming:"structural",import:"structural",export:"structural",module:"structural",package:"structural",barrel:"structural",circular:"structural",component:"components",components:"components",react:"components",vue:"components",angular:"components",hook:"components",prop:"components",state:"components",render:"components",ref:"components",composition:"components",style:"styling",styling:"styling",css:"styling",typography:"styling",color:"styling",spacing:"styling",layout:"styling",theme:"styling",tailwind:"styling",class:"styling",performance:"performance",perf:"performance",optimization:"performance",cache:"performance",lazy:"performance",memo:"performance"};for(const l of r.slice(0,3))if(s[l])return s[l];return"other"}function Yg(e,t=0){const n=qg(e),r=new Map;for(const o of e){const c=r.get(o.patternId);c?c.count++:r.set(o.patternId,{name:o.patternName,count:1})}const s=Object.entries(n.byFile).sort((o,c)=>c[1]-o[1]).slice(0,Gl.TOP_FILES).map(([o,c])=>({file:o,count:c})),l=Array.from(r.entries()).sort((o,c)=>c[1].count-o[1].count).slice(0,Gl.TOP_PATTERNS).map(([o,{name:c,count:u}])=>({id:o,name:c,count:u})),a=Object.entries(n.byCategory).sort((o,c)=>c[1]-o[1]).slice(0,Gl.TOP_CATEGORIES).map(([o,c])=>{var u;return{category:o,count:c,icon:((u=be[o])==null?void 0:u.icon)||"📋"}});return{total:e.length,bySeverity:n.bySeverity,byCategory:n.byCategory,byPattern:r,affectedFiles:Object.keys(n.byFile).length,topFiles:s,topPatterns:l,topCategories:a,realtimeCount:t,trend:"stable"}}function Xg(e){const t=new Map;for(const n of e){const r=t.get(n.file);r?r.push(n):t.set(n.file,[n])}return Array.from(t.entries()).map(([n,r])=>{const s={error:0,warning:0,info:0,hint:0};for(const a of r)s[a.severity]++;const l=ty(s);return{file:n,violations:r.sort((a,o)=>a.range.start.line-o.range.start.line),metrics:{total:r.length,bySeverity:s,maxSeverity:l}}}).sort((n,r)=>{const s=Gi(r.metrics.maxSeverity)-Gi(n.metrics.maxSeverity);return s!==0?s:r.metrics.total-n.metrics.total})}function Zg(e){const t=new Map;for(const n of e){const r=t.get(n.patternId);r?r.violations.push(n):t.set(n.patternId,{name:n.patternName,violations:[n]})}return Array.from(t.entries()).map(([n,{name:r,violations:s}])=>{const l={error:0,warning:0,info:0,hint:0},a=new Set;for(const o of s)l[o.severity]++,a.add(o.file);return{patternId:n,patternName:r,violations:s,metrics:{total:s.length,bySeverity:l,affectedFiles:a.size}}}).sort((n,r)=>r.metrics.total-n.metrics.total)}function Uh(e){const t=new Map;for(const n of e){const r=Ki(n.patternId,n.patternName),s=t.get(r);s?s.push(n):t.set(r,[n])}return zh.filter(n=>t.has(n)).map(n=>{const r=t.get(n)||[],s=be[n]??be.other,l={error:0,warning:0,info:0,hint:0},a=new Set,o=new Set;for(const c of r)l[c.severity]++,a.add(c.file),o.add(c.patternId);return{category:n,displayName:s.label,icon:s.icon,violations:r,metrics:{total:r.length,bySeverity:l,affectedFiles:a.size,patterns:Array.from(o)}}})}function Jg(e){const t=new Map;for(const n of e){const r=t.get(n.severity);r?r.push(n):t.set(n.severity,[n])}return Cs.filter(n=>t.has(n)).map(n=>{const r=t.get(n)||[],s=Uh(r);return{severity:n,violations:r,categories:s}})}function ey(e,t){const n=[...e],r=t.direction==="asc"?1:-1;return n.sort((s,l)=>{var a,o;switch(t.field){case"severity":return r*(Gi(l.severity)-Gi(s.severity));case"category":{const c=Ki(s.patternId,s.patternName),u=Ki(l.patternId,l.patternName),h=((a=be[c])==null?void 0:a.priority)??0,d=((o=be[u])==null?void 0:o.priority)??0;return r*(d-h)}case"file":return r*s.file.localeCompare(l.file);case"pattern":return r*s.patternName.localeCompare(l.patternName);case"line":return r*(s.range.start.line-l.range.start.line);default:return 0}}),n}function Gi(e){return De[e].priority}function ty(e){for(const t of Cs)if(e[t]>0)return t;return"hint"}function Vh(e){return be[e]||be.other}function Qh(e,t=50){if(e.length<=t)return e;const r=e.split("/").pop()||"";return r.length>=t-3?"..."+r.slice(-(t-3)):".../"+r}function ny(e,t){return e.line===t.line?`L${e.line}:${e.character}-${t.character}`:`L${e.line}:${e.character} - L${t.line}:${t.character}`}function Hh(e){return e.split("/").pop()||e}function ry(e,t){const n=new Set(e.map(s=>s.id));return[...t.filter(s=>!n.has(s.id)),...e]}function li({label:e,value:t,subValue:n,icon:r,color:s="text-dark-text"}){return i.jsxs("div",{className:"p-4 bg-dark-surface border border-dark-border rounded-lg",children:[i.jsxs("div",{className:"flex items-center justify-between mb-2",children:[i.jsx("span",{className:"text-xs text-dark-muted uppercase tracking-wide",children:e}),r&&i.jsx("span",{className:"text-lg",children:r})]}),i.jsx("div",{className:`text-2xl font-semibold ${s}`,children:t}),n&&i.jsx("div",{className:"text-xs text-dark-muted mt-1",children:n})]})}function sy({bySeverity:e,total:t}){return i.jsxs("div",{className:"p-4 bg-dark-surface border border-dark-border rounded-lg",children:[i.jsx("div",{className:"text-xs text-dark-muted uppercase tracking-wide mb-3",children:"By Severity"}),i.jsx("div",{className:"flex h-3 rounded-full overflow-hidden bg-dark-bg mb-3",children:Cs.map(n=>{const r=e[n]||0,s=t>0?r/t*100:0;if(s===0)return null;const l=De[n];return i.jsx("div",{className:`${l.bgColor} transition-all`,style:{width:`${s}%`},title:`${l.label}: ${r} (${Math.round(s)}%)`},n)})}),i.jsx("div",{className:"grid grid-cols-2 gap-2",children:Cs.map(n=>{const r=e[n]||0,s=De[n];return i.jsxs("div",{className:"flex items-center justify-between text-sm",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{children:s.icon}),i.jsx("span",{className:s.color,children:s.label})]}),i.jsx("span",{className:"font-medium",children:r})]},n)})})]})}function Du({title:e,icon:t,items:n,emptyMessage:r}){return i.jsxs("div",{className:"p-4 bg-dark-surface border border-dark-border rounded-lg",children:[i.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[i.jsx("span",{children:t}),i.jsx("span",{className:"text-xs text-dark-muted uppercase tracking-wide",children:e})]}),n.length>0?i.jsx("div",{className:"space-y-2",children:n.map((s,l)=>i.jsxs("div",{className:"flex items-center justify-between text-sm",children:[i.jsx("span",{className:"truncate text-dark-muted",title:s.label,children:s.label}),i.jsx("span",{className:"font-medium ml-2 shrink-0",children:s.count})]},l))}):i.jsx("div",{className:"text-sm text-dark-muted",children:r})]})}function iy({byCategory:e,total:t}){const n=Object.entries(e).sort((r,s)=>s[1]-r[1]).slice(0,6);return i.jsxs("div",{className:"p-4 bg-dark-surface border border-dark-border rounded-lg",children:[i.jsx("div",{className:"text-xs text-dark-muted uppercase tracking-wide mb-3",children:"By Category"}),n.length>0?i.jsx("div",{className:"space-y-2",children:n.map(([r,s])=>{const l=be[r]||be.other,a=t>0?Math.round(s/t*100):0;return i.jsxs("div",{className:"space-y-1",children:[i.jsxs("div",{className:"flex items-center justify-between text-sm",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{children:l.icon}),i.jsx("span",{className:l.color,children:l.label})]}),i.jsx("span",{className:"font-medium",children:s})]}),i.jsx("div",{className:"h-1.5 bg-dark-bg rounded-full overflow-hidden",children:i.jsx("div",{className:`h-full ${l.bgColor} transition-all`,style:{width:`${a}%`}})})]},r)})}):i.jsx("div",{className:"text-sm text-dark-muted",children:"No category data"})]})}function ly({statistics:e}){const t=(e.bySeverity.error||0)+(e.bySeverity.warning||0);return i.jsxs("div",{className:"space-y-4",children:[i.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[i.jsx(li,{label:"Total Violations",value:e.total,icon:"⚠️",color:e.total>0?"text-severity-warning":"text-status-approved"}),i.jsx(li,{label:"Critical",value:t,subValue:"errors + warnings",icon:"🔴",color:t>0?"text-severity-error":"text-status-approved"}),i.jsx(li,{label:"Affected Files",value:e.affectedFiles,icon:"📁"}),i.jsx(li,{label:"Patterns",value:e.byPattern.size,subValue:"with violations",icon:"🔍"})]}),e.realtimeCount>0&&i.jsxs("div",{className:"p-3 bg-blue-500/10 border border-blue-500/20 rounded-lg flex items-center gap-3",children:[i.jsxs("span",{className:"relative flex h-3 w-3",children:[i.jsx("span",{className:"animate-ping absolute inline-flex h-full w-full rounded-full bg-blue-400 opacity-75"}),i.jsx("span",{className:"relative inline-flex rounded-full h-3 w-3 bg-blue-500"})]}),i.jsxs("span",{className:"text-sm text-blue-400",children:[e.realtimeCount," new violation",e.realtimeCount!==1?"s":""," detected in real-time"]})]}),i.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-3",children:[i.jsx(sy,{bySeverity:e.bySeverity,total:e.total}),i.jsx(iy,{byCategory:e.byCategory,total:e.total}),i.jsx(Du,{title:"Top Files",icon:"📄",items:e.topFiles.map(n=>({label:Hh(n.file),count:n.count})),emptyMessage:"No files with violations"}),i.jsx(Du,{title:"Top Patterns",icon:"🔍",items:e.topPatterns.map(n=>({label:n.name,count:n.count})),emptyMessage:"No pattern violations"})]})]})}function ay({filters:e,onFiltersChange:t,viewMode:n,onViewModeChange:r,sort:s,onSortChange:l,resultCount:a}){var u,h,d,f;const o=()=>{t({})},c=!!(e.severity||e.file||e.patternId||e.search||e.category);return i.jsxs("div",{className:"space-y-3",children:[i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsxs("div",{className:"relative flex-1",children:[i.jsx("input",{type:"text",placeholder:"Search violations...",className:"w-full bg-dark-bg border border-dark-border rounded-lg px-4 py-2 pl-10 text-sm focus:outline-none focus:border-blue-500 transition-colors",value:e.search||"",onChange:m=>t({...e,search:m.target.value||void 0})}),i.jsx("span",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-dark-muted",children:"🔍"})]}),i.jsx("div",{className:"flex bg-dark-bg border border-dark-border rounded-lg p-0.5",children:Object.keys(Lu).map(m=>{const y=Lu[m];return i.jsx("button",{onClick:()=>r(m),className:`px-3 py-1.5 text-sm rounded-md transition-colors ${n===m?"bg-blue-500/20 text-blue-400":"text-dark-muted hover:text-dark-text"}`,title:y.description,children:y.icon},m)})})]}),i.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[i.jsxs("select",{className:"bg-dark-bg border border-dark-border rounded-lg px-3 py-2 text-sm focus:outline-none focus:border-blue-500",value:e.severity||"",onChange:m=>t({...e,severity:m.target.value||void 0}),children:[i.jsx("option",{value:"",children:"All Severities"}),Cs.map(m=>{const y=De[m];return i.jsxs("option",{value:m,children:[y.icon," ",y.label]},m)})]}),i.jsxs("select",{className:"bg-dark-bg border border-dark-border rounded-lg px-3 py-2 text-sm focus:outline-none focus:border-blue-500",value:e.category||"",onChange:m=>t({...e,category:m.target.value||void 0}),children:[i.jsx("option",{value:"",children:"All Categories"}),zh.map(m=>{const y=be[m];return i.jsxs("option",{value:m,children:[y.icon," ",y.label]},m)})]}),i.jsx("input",{type:"text",placeholder:"Filter by file...",className:"bg-dark-bg border border-dark-border rounded-lg px-3 py-2 text-sm focus:outline-none focus:border-blue-500 w-48",value:e.file||"",onChange:m=>t({...e,file:m.target.value||void 0})}),i.jsxs("div",{className:"flex items-center gap-1 ml-auto",children:[i.jsx("span",{className:"text-xs text-dark-muted",children:"Sort:"}),i.jsxs("select",{className:"bg-dark-bg border border-dark-border rounded-lg px-2 py-1.5 text-sm focus:outline-none focus:border-blue-500",value:s.field,onChange:m=>l({...s,field:m.target.value}),children:[i.jsx("option",{value:"severity",children:"Severity"}),i.jsx("option",{value:"category",children:"Category"}),i.jsx("option",{value:"file",children:"File"}),i.jsx("option",{value:"pattern",children:"Pattern"}),i.jsx("option",{value:"line",children:"Line"})]}),i.jsx("button",{onClick:()=>l({...s,direction:s.direction==="asc"?"desc":"asc"}),className:"p-1.5 bg-dark-bg border border-dark-border rounded-lg text-sm hover:bg-dark-border/50 transition-colors",title:s.direction==="asc"?"Ascending":"Descending",children:s.direction==="asc"?"↑":"↓"})]})]}),i.jsxs("div",{className:"flex items-center justify-between text-sm",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("span",{className:"text-dark-muted",children:[a," violation",a!==1?"s":""]}),c&&i.jsxs(i.Fragment,{children:[i.jsx("span",{className:"text-dark-border",children:"•"}),i.jsx("button",{onClick:o,className:"text-blue-400 hover:text-blue-300 transition-colors",children:"Clear filters"})]})]}),c&&i.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.severity&&i.jsxs("span",{className:"px-2 py-0.5 bg-dark-bg border border-dark-border rounded text-xs",children:[(u=De[e.severity])==null?void 0:u.icon," ",(h=De[e.severity])==null?void 0:h.label,i.jsx("button",{onClick:()=>t({...e,severity:void 0}),className:"ml-1 text-dark-muted hover:text-dark-text",children:"×"})]}),e.category&&i.jsxs("span",{className:"px-2 py-0.5 bg-dark-bg border border-dark-border rounded text-xs",children:[(d=be[e.category])==null?void 0:d.icon," ",(f=be[e.category])==null?void 0:f.label,i.jsx("button",{onClick:()=>t({...e,category:void 0}),className:"ml-1 text-dark-muted hover:text-dark-text",children:"×"})]}),e.file&&i.jsxs("span",{className:"px-2 py-0.5 bg-dark-bg border border-dark-border rounded text-xs",children:["📁 ",e.file.length>20?e.file.slice(0,20)+"...":e.file,i.jsx("button",{onClick:()=>t({...e,file:void 0}),className:"ml-1 text-dark-muted hover:text-dark-text",children:"×"})]})]})]})]})}function ml({violation:e,isExpanded:t,onToggle:n}){const r=De[e.severity];return i.jsxs("div",{className:`border rounded-lg overflow-hidden ${r.borderColor} ${r.bgColor}`,children:[i.jsx("button",{onClick:n,className:"w-full text-left p-4 hover:bg-dark-border/20 transition-colors",children:i.jsxs("div",{className:"flex items-start gap-3",children:[i.jsxs("span",{className:`px-2 py-0.5 rounded text-xs font-medium ${r.bgColor} ${r.color} border ${r.borderColor} shrink-0`,children:[r.icon," ",r.label]}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsx("div",{className:"font-medium",children:e.message}),i.jsxs("div",{className:"flex items-center gap-2 mt-1 text-sm text-dark-muted flex-wrap",children:[i.jsx("span",{className:"truncate",title:e.file,children:Qh(e.file)}),i.jsx("span",{children:"•"}),i.jsxs("span",{children:["Line ",e.range.start.line]}),i.jsx("span",{children:"•"}),i.jsx("span",{className:"text-blue-400",children:e.patternName})]})]}),i.jsx("span",{className:"text-dark-muted shrink-0",children:t?"▼":"▶"})]})}),t&&i.jsxs("div",{className:"p-4 pt-0 space-y-4 border-t border-dark-border/50",children:[i.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[i.jsxs("div",{children:[i.jsx("div",{className:"text-xs text-dark-muted mb-2",children:"Expected"}),i.jsx("div",{className:"p-3 bg-status-approved/10 border border-status-approved/20 rounded-lg font-mono text-sm",children:e.expected})]}),i.jsxs("div",{children:[i.jsx("div",{className:"text-xs text-dark-muted mb-2",children:"Actual"}),i.jsx("div",{className:"p-3 bg-severity-error/10 border border-severity-error/20 rounded-lg font-mono text-sm",children:e.actual})]})]}),e.codeSnippet&&i.jsxs("div",{children:[i.jsx("div",{className:"text-xs text-dark-muted mb-2",children:"Code"}),i.jsx("pre",{className:"p-3 bg-dark-bg rounded-lg overflow-x-auto font-mono text-xs leading-relaxed",children:e.codeSnippet})]}),i.jsxs("div",{className:"flex items-center gap-4 text-xs text-dark-muted",children:[i.jsxs("span",{children:["Pattern: ",e.patternId]}),i.jsxs("span",{children:["Range: ",ny(e.range.start,e.range.end)]})]})]})]})}function oy({group:e,isExpanded:t,onToggle:n,expandedViolations:r,onToggleViolation:s}){const l=De[e.metrics.maxSeverity];return i.jsxs("div",{className:"border border-dark-border rounded-lg overflow-hidden",children:[i.jsxs("button",{onClick:n,className:"w-full text-left p-4 bg-dark-surface hover:bg-dark-border/30 transition-colors",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[i.jsx("span",{className:"text-dark-muted",children:t?"▼":"▶"}),i.jsx("span",{className:"text-lg",children:"📄"}),i.jsxs("div",{className:"min-w-0",children:[i.jsx("div",{className:"font-medium truncate",title:e.file,children:Hh(e.file)}),i.jsx("div",{className:"text-xs text-dark-muted truncate",title:e.file,children:Qh(e.file)})]})]}),i.jsx("div",{className:"flex items-center gap-3 shrink-0",children:i.jsxs("span",{className:`px-2 py-1 rounded text-xs ${l.bgColor} ${l.color}`,children:[e.metrics.total," violation",e.metrics.total!==1?"s":""]})})]}),i.jsx("div",{className:"flex items-center gap-3 mt-2 ml-10 text-xs",children:Object.entries(e.metrics.bySeverity).map(([a,o])=>{if(o===0)return null;const c=De[a];return i.jsxs("span",{className:c.color,children:[c.icon," ",o]},a)})})]}),t&&i.jsx("div",{className:"border-t border-dark-border bg-dark-bg p-3 space-y-2",children:e.violations.map(a=>i.jsx(ml,{violation:a,isExpanded:r.has(a.id),onToggle:()=>s(a.id)},a.id))})]})}function cy({group:e,isExpanded:t,onToggle:n,expandedViolations:r,onToggleViolation:s}){return i.jsxs("div",{className:"border border-dark-border rounded-lg overflow-hidden",children:[i.jsxs("button",{onClick:n,className:"w-full text-left p-4 bg-dark-surface hover:bg-dark-border/30 transition-colors",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[i.jsx("span",{className:"text-dark-muted",children:t?"▼":"▶"}),i.jsx("span",{className:"text-lg",children:"🔍"}),i.jsxs("div",{className:"min-w-0",children:[i.jsx("div",{className:"font-medium truncate",children:e.patternName}),i.jsxs("div",{className:"text-xs text-dark-muted",children:[e.metrics.affectedFiles," file",e.metrics.affectedFiles!==1?"s":""," affected"]})]})]}),i.jsx("div",{className:"flex items-center gap-3 shrink-0",children:i.jsxs("span",{className:"px-2 py-1 rounded text-xs bg-severity-warning/10 text-severity-warning",children:[e.metrics.total," violation",e.metrics.total!==1?"s":""]})})]}),i.jsx("div",{className:"flex items-center gap-3 mt-2 ml-10 text-xs",children:Object.entries(e.metrics.bySeverity).map(([l,a])=>{if(a===0)return null;const o=De[l];return i.jsxs("span",{className:o.color,children:[o.icon," ",a]},l)})})]}),t&&i.jsx("div",{className:"border-t border-dark-border bg-dark-bg p-3 space-y-2",children:e.violations.map(l=>i.jsx(ml,{violation:l,isExpanded:r.has(l.id),onToggle:()=>s(l.id)},l.id))})]})}function Bh({group:e,isExpanded:t,onToggle:n,expandedViolations:r,onToggleViolation:s}){const l=Vh(e.category),a=e.metrics.bySeverity.error>0?"error":e.metrics.bySeverity.warning>0?"warning":e.metrics.bySeverity.info>0?"info":"hint",o=De[a];return i.jsxs("div",{className:`border rounded-lg overflow-hidden ${l.bgColor} border-dark-border`,children:[i.jsxs("button",{onClick:n,className:"w-full text-left p-4 hover:bg-dark-border/20 transition-colors",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[i.jsx("span",{className:"text-dark-muted",children:t?"▼":"▶"}),i.jsx("span",{className:"text-2xl",children:e.icon}),i.jsxs("div",{className:"min-w-0",children:[i.jsx("div",{className:`font-semibold ${l.color}`,children:e.displayName}),i.jsxs("div",{className:"text-xs text-dark-muted",children:[e.metrics.patterns.length," pattern",e.metrics.patterns.length!==1?"s":""," • ",e.metrics.affectedFiles," file",e.metrics.affectedFiles!==1?"s":""]})]})]}),i.jsx("div",{className:"flex items-center gap-3 shrink-0",children:i.jsxs("span",{className:`px-3 py-1.5 rounded-lg text-sm font-medium ${o.bgColor} ${o.color}`,children:[e.metrics.total," violation",e.metrics.total!==1?"s":""]})})]}),i.jsx("div",{className:"flex items-center gap-4 mt-3 ml-10 text-sm",children:Object.entries(e.metrics.bySeverity).map(([c,u])=>{if(u===0)return null;const h=De[c];return i.jsxs("span",{className:`flex items-center gap-1 ${h.color}`,children:[h.icon," ",u]},c)})})]}),t&&i.jsx("div",{className:"border-t border-dark-border bg-dark-bg p-3 space-y-2",children:e.violations.map(c=>i.jsx(ml,{violation:c,isExpanded:r.has(c.id),onToggle:()=>s(c.id)},c.id))})]})}function uy({group:e,isExpanded:t,onToggle:n,expandedCategories:r,onToggleCategory:s,expandedViolations:l,onToggleViolation:a}){const o=De[e.severity];return i.jsxs("div",{className:`border-2 rounded-xl overflow-hidden ${o.borderColor} ${o.bgColor}`,children:[i.jsxs("button",{onClick:n,className:"w-full text-left p-5 hover:bg-dark-border/10 transition-colors",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-4",children:[i.jsx("span",{className:"text-dark-muted text-lg",children:t?"▼":"▶"}),i.jsx("span",{className:"text-3xl",children:o.icon}),i.jsxs("div",{children:[i.jsx("div",{className:`text-xl font-bold ${o.color}`,children:o.label}),i.jsx("div",{className:"text-sm text-dark-muted",children:o.description})]})]}),i.jsx("div",{className:"flex items-center gap-4 shrink-0",children:i.jsxs("div",{className:"text-right",children:[i.jsx("div",{className:`text-3xl font-bold ${o.color}`,children:e.violations.length}),i.jsxs("div",{className:"text-xs text-dark-muted",children:["violation",e.violations.length!==1?"s":""]})]})})]}),e.categories.length>0&&i.jsxs("div",{className:"flex flex-wrap items-center gap-2 mt-4 ml-14",children:[e.categories.slice(0,5).map(c=>{const u=Vh(c.category);return i.jsxs("span",{className:`px-2 py-1 rounded text-xs ${u.bgColor} ${u.color} border border-dark-border/30`,children:[c.icon," ",c.displayName," (",c.metrics.total,")"]},c.category)}),e.categories.length>5&&i.jsxs("span",{className:"text-xs text-dark-muted",children:["+",e.categories.length-5," more"]})]})]}),t&&i.jsx("div",{className:"border-t border-dark-border bg-dark-bg p-4 space-y-3",children:e.categories.map(c=>i.jsx(Bh,{group:c,isExpanded:r.has(c.category),onToggle:()=>s(c.category),expandedViolations:l,onToggleViolation:a},c.category))})]})}function dy({violations:e,viewMode:t,expandedViolations:n,onToggleViolation:r}){const[s,l]=S.useState(new Set),[a,o]=S.useState(new Set),c=d=>{l(f=>{const m=new Set(f);return m.has(d)?m.delete(d):m.add(d),m})},u=d=>{o(f=>{const m=new Set(f);return m.has(d)?m.delete(d):m.add(d),m})};if(e.length===0)return i.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-center",children:[i.jsx("span",{className:"text-4xl mb-4",children:"✅"}),i.jsx("h3",{className:"text-lg font-medium mb-2",children:"No violations found"}),i.jsx("p",{className:"text-dark-muted text-sm max-w-md",children:"Great job! Your codebase is following all detected patterns consistently."})]});if(t==="list")return i.jsx("div",{className:"space-y-3",children:e.map(d=>i.jsx(ml,{violation:d,isExpanded:n.has(d.id),onToggle:()=>r(d.id)},d.id))});if(t==="by-severity"){const d=Jg(e);return i.jsx("div",{className:"space-y-4",children:d.map(f=>i.jsx(uy,{group:f,isExpanded:s.has(f.severity),onToggle:()=>c(f.severity),expandedCategories:a,onToggleCategory:u,expandedViolations:n,onToggleViolation:r},f.severity))})}if(t==="by-category"){const d=Uh(e);return i.jsx("div",{className:"space-y-3",children:d.map(f=>i.jsx(Bh,{group:f,isExpanded:s.has(f.category),onToggle:()=>c(f.category),expandedViolations:n,onToggleViolation:r},f.category))})}if(t==="by-file"){const d=Xg(e);return i.jsx("div",{className:"space-y-3",children:d.map(f=>i.jsx(oy,{group:f,isExpanded:s.has(f.file),onToggle:()=>c(f.file),expandedViolations:n,onToggleViolation:r},f.file))})}const h=Zg(e);return i.jsx("div",{className:"space-y-3",children:h.map(d=>i.jsx(cy,{group:d,isExpanded:s.has(d.patternId),onToggle:()=>c(d.patternId),expandedViolations:n,onToggleViolation:r},d.patternId))})}function fy(){const{violationFilters:e,setViolationFilters:t,expandedViolations:n,toggleViolationExpanded:r,realtimeViolations:s}=Lr(),[l,a]=S.useState("by-severity"),[o,c]=S.useState({field:"severity",direction:"desc"}),[u,h]=S.useState(!0),{data:d,isLoading:f,error:m}=Rh(e),y=S.useMemo(()=>d?ry(d,s):s,[d,s]),N=S.useMemo(()=>ey(y,o),[y,o]),w=S.useMemo(()=>Yg(y,s.length),[y,s.length]),v=S.useCallback(x=>{r(x)},[r]);return f?i.jsx("div",{className:"flex items-center justify-center h-64",children:i.jsxs("div",{className:"flex flex-col items-center gap-3",children:[i.jsx("div",{className:"w-8 h-8 border-2 border-blue-500 border-t-transparent rounded-full animate-spin"}),i.jsx("span",{className:"text-dark-muted",children:"Loading violations..."})]})}):m?i.jsxs("div",{className:"flex flex-col items-center justify-center h-64 text-center",children:[i.jsx("span",{className:"text-4xl mb-4",children:"⚠️"}),i.jsx("h3",{className:"text-lg font-medium text-severity-error mb-2",children:"Failed to load violations"}),i.jsx("p",{className:"text-dark-muted text-sm max-w-md",children:"There was an error loading the violation data. Please try refreshing the page."})]}):i.jsxs("div",{className:"space-y-6",children:[u&&i.jsxs("div",{className:"relative",children:[i.jsx("button",{onClick:()=>h(!1),className:"absolute -top-1 -right-1 p-1 text-dark-muted hover:text-dark-text z-10",title:"Hide statistics",children:i.jsx("span",{className:"text-xs",children:"✕"})}),i.jsx(ly,{statistics:w})]}),!u&&i.jsx("button",{onClick:()=>h(!0),className:"text-sm text-blue-400 hover:text-blue-300 transition-colors",children:"📊 Show statistics"}),i.jsx(ay,{filters:e,onFiltersChange:t,viewMode:l,onViewModeChange:a,sort:o,onSortChange:c,resultCount:N.length}),i.jsx("div",{className:"max-h-[calc(100vh-400px)] overflow-y-auto scrollbar-dark pr-2",children:i.jsx(dy,{violations:N,viewMode:l,expandedViolations:n,onToggleViolation:v})})]})}function Wh({node:e,depth:t=0,selectedPath:n,onSelect:r}){const{expandedFolders:s,toggleFolderExpanded:l}=Lr(),a=s.has(e.path),o=n===e.path,c=e.type==="directory",u=()=>{c?l(e.path):r(e.path)},h=e.severity?{error:"text-severity-error",warning:"text-severity-warning",info:"text-severity-info",hint:"text-severity-hint"}[e.severity]:"";return i.jsxs("div",{children:[i.jsxs("button",{onClick:u,className:`w-full text-left px-2 py-1 rounded text-sm flex items-center gap-2 hover:bg-dark-border/50 ${o?"bg-blue-500/20 text-blue-400":""}`,style:{paddingLeft:`${t*16+8}px`},children:[i.jsx("span",{className:"w-4 text-center text-dark-muted",children:c?a?"📂":"📁":"📄"}),i.jsx("span",{className:`flex-1 truncate ${h}`,children:e.name}),(e.patternCount||e.violationCount)&&i.jsxs("span",{className:"text-xs text-dark-muted",children:[e.patternCount?`${e.patternCount}P`:"",e.patternCount&&e.violationCount?" ":"",e.violationCount?`${e.violationCount}V`:""]})]}),c&&a&&e.children&&i.jsx("div",{children:e.children.map(d=>i.jsx(Wh,{node:d,depth:t+1,selectedPath:n,onSelect:r},d.path))})]})}function hy({path:e}){const{data:t,isLoading:n,error:r}=Av(e);return n?i.jsx("div",{className:"text-dark-muted",children:"Loading file details..."}):r||!t?i.jsx("div",{className:"text-severity-error",children:"Failed to load file details"}):i.jsxs("div",{className:"space-y-4",children:[i.jsxs("div",{children:[i.jsx("h3",{className:"font-medium truncate",title:t.path,children:t.path.split("/").pop()}),i.jsxs("div",{className:"text-sm text-dark-muted mt-1",children:[i.jsx("span",{children:t.language}),i.jsx("span",{className:"mx-2",children:"•"}),i.jsxs("span",{children:[t.lineCount," lines"]})]})]}),t.patterns.length>0&&i.jsxs("div",{children:[i.jsxs("h4",{className:"text-sm font-medium mb-2",children:["Patterns (",t.patterns.length,")"]}),i.jsx("div",{className:"space-y-2",children:t.patterns.map(s=>i.jsxs("div",{className:"p-2 bg-dark-bg rounded text-sm",children:[i.jsx("div",{className:"font-medium",children:s.name}),i.jsxs("div",{className:"text-xs text-dark-muted mt-1",children:[s.category," • ",s.locations.length," locations"]})]},s.id))})]}),t.violations.length>0&&i.jsxs("div",{children:[i.jsxs("h4",{className:"text-sm font-medium mb-2",children:["Violations (",t.violations.length,")"]}),i.jsx("div",{className:"space-y-2",children:t.violations.map(s=>i.jsxs("div",{className:"p-2 bg-dark-bg rounded text-sm",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:`px-1.5 py-0.5 rounded text-xs badge-${s.severity}`,children:s.severity}),i.jsx("span",{className:"truncate",children:s.message})]}),i.jsxs("div",{className:"text-xs text-dark-muted mt-1",children:["Line ",s.range.start.line]})]},s.id))})]}),t.patterns.length===0&&t.violations.length===0&&i.jsx("div",{className:"text-dark-muted text-sm",children:"No patterns or violations in this file"})]})}function my(){const[e,t]=S.useState(null),{data:n,isLoading:r,error:s}=$v();return r?i.jsx("div",{className:"flex items-center justify-center h-64",children:i.jsx("div",{className:"text-dark-muted",children:"Loading file tree..."})}):s?i.jsx("div",{className:"flex items-center justify-center h-64",children:i.jsx("div",{className:"text-severity-error",children:"Failed to load file tree"})}):i.jsxs("div",{className:"flex gap-6",children:[i.jsx("div",{className:"w-80 shrink-0",children:i.jsx("div",{className:"card max-h-[600px] overflow-y-auto scrollbar-dark",children:n&&n.length>0?n.map(l=>i.jsx(Wh,{node:l,selectedPath:e,onSelect:t},l.path)):i.jsx("div",{className:"text-dark-muted text-center py-4",children:"No files found"})})}),i.jsx("div",{className:"flex-1",children:i.jsx("div",{className:"card",children:e?i.jsx(hy,{path:e}):i.jsx("div",{className:"text-dark-muted text-center py-8",children:"Select a file to view details"})})})]})}const py=e=>(t,n,r)=>{const s=r.subscribe;return r.subscribe=(a,o,c)=>{let u=a;if(o){const h=(c==null?void 0:c.equalityFn)||Object.is;let d=a(r.getState());u=f=>{const m=a(f);if(!h(d,m)){const y=d;o(d=m,y)}},c!=null&&c.fireImmediately&&o(d,d)}return s(u)},e(t,n,r)},xy=py,Ry={critical:"#ff3366",high:"#ff9933",medium:"#ffcc00",low:"#33ccff",public:"#66ff99"},Fy={critical:.8,high:.6,medium:.4,low:.2,public:.1},My={P0:"#ff0000",P1:"#ff6600",P2:"#ffcc00",P3:"#66ccff",P4:"#99ff99"},Ly={public:"#ff3333",authenticated:"#ffcc00",admin:"#33cc33",internal:"#3366ff"},Dy={read:"#33ccff",write:"#ff9933",delete:"#ff3366",unknown:"#999999"},$y={MIN_RADIUS:.5,MAX_RADIUS:3},Ay={RADIUS:.15,ORBIT_RADIUS:2,ORBIT_SPEED:.5},zy={SCALE:.8},Uy={BASE_WIDTH:.05,MAX_WIDTH:.3,CURVE_SEGMENTS:50,FLOW_SPEED:2,DASH_SIZE:.5,GAP_SIZE:.3},Vy={RADIUS:40,HEIGHT:15,CLUSTER_SEPARATION:20,SIMULATION_ITERATIONS:300,FORCE_STRENGTH:-30,LINK_DISTANCE:10},qi={DEFAULT_POSITION:{x:0,y:30,z:60},DEFAULT_TARGET:{x:0,y:0,z:0},FOV:60,NEAR:.1,FAR:1e3,MIN_ZOOM:.5,MAX_ZOOM:5},Qy={STAR_COUNT:5e3,STAR_SIZE:.1},Hy={HOVER_SCALE:1.2,SELECTION_SCALE:1.3,PULSE_FREQUENCY:2,IDLE_ROTATION:.001},By={FONT_SIZE:12,FONT_FAMILY:"Inter, system-ui, sans-serif",BG_OPACITY:.8,PADDING:4,OFFSET:.5},Wy={auth:["users","accounts","sessions","tokens","permissions","roles"],commerce:["orders","products","carts","payments","invoices","subscriptions"],content:["posts","comments","media","files","documents","attachments"],messaging:["messages","notifications","emails","chats","threads"],analytics:["events","logs","metrics","analytics","tracking"],config:["settings","preferences","configurations","features","flags"]},Ky={auth:"#ff6b6b",commerce:"#4ecdc4",content:"#45b7d1",messaging:"#96ceb4",analytics:"#dda0dd",config:"#98d8c8",other:"#7f8c8d"},$u={selectedTable:null,selectedField:null,selectedEntryPoint:null,selectedPath:null,hoveredNode:null,hoveredType:null},Au={position:qi.DEFAULT_POSITION,target:qi.DEFAULT_TARGET,zoom:1},zu={minSensitivity:null,operationType:null,untestedOnly:!1,publicOnly:!1,searchQuery:"",clusters:[]},vy={showFields:!0,showPaths:!0,showRelationships:!0,showLabels:!0,enableBloom:!0,animationSpeed:1,pathOpacity:.6},$r=Th()(xy((e,t)=>({galaxyData:null,isLoading:!1,error:null,selection:$u,camera:Au,viewMode:"overview",filters:zu,display:vy,recentEvents:[],isLiveMode:!1,isPanelOpen:!1,activePanel:null,searchQuery:"",searchResults:[],setGalaxyData:n=>e({galaxyData:n,isLoading:!1,error:null}),setLoading:n=>e({isLoading:n}),setError:n=>e({error:n,isLoading:!1}),selectTable:n=>e(r=>({selection:{...r.selection,selectedTable:n,selectedField:null},isPanelOpen:n!==null,activePanel:n!==null?"details":r.activePanel})),selectField:n=>e(r=>({selection:{...r.selection,selectedField:n}})),selectEntryPoint:n=>e(r=>({selection:{...r.selection,selectedEntryPoint:n,selectedTable:null,selectedField:null},isPanelOpen:n!==null,activePanel:n!==null?"details":r.activePanel})),selectPath:n=>e(r=>({selection:{...r.selection,selectedPath:n}})),setHovered:(n,r)=>e(s=>({selection:{...s.selection,hoveredNode:n,hoveredType:r}})),clearSelection:()=>e({selection:$u,isPanelOpen:!1,activePanel:null}),setCameraPosition:n=>e(r=>({camera:{...r.camera,position:n}})),setCameraTarget:n=>e(r=>({camera:{...r.camera,target:n}})),setZoom:n=>e(r=>({camera:{...r.camera,zoom:Math.max(qi.MIN_ZOOM,Math.min(qi.MAX_ZOOM,n))}})),resetCamera:()=>e({camera:Au}),focusOnNode:n=>{const{galaxyData:r}=t();if(!r)return;const s=r.tables.find(o=>o.id===n),l=r.entryPoints.find(o=>o.id===n),a=(s==null?void 0:s.position)||(l==null?void 0:l.position);a&&e(o=>({camera:{...o.camera,target:a,position:{x:a.x,y:a.y+20,z:a.z+30}}}))},setViewMode:n=>e({viewMode:n}),setFilters:n=>e(r=>({filters:{...r.filters,...n}})),setDisplay:n=>e(r=>({display:{...r.display,...n}})),resetFilters:()=>e({filters:zu}),addEvent:n=>e(r=>({recentEvents:[n,...r.recentEvents].slice(0,100)})),clearEvents:()=>e({recentEvents:[]}),setLiveMode:n=>e({isLiveMode:n}),togglePanel:n=>e(r=>({isPanelOpen:r.activePanel===n?!r.isPanelOpen:!0,activePanel:n})),closePanel:()=>e({isPanelOpen:!1,activePanel:null}),setSearchQuery:n=>e({searchQuery:n}),setSearchResults:n=>e({searchResults:n})}))),Gy=()=>$r(e=>!e.selection.selectedTable||!e.galaxyData?null:e.galaxyData.tables.find(t=>t.id===e.selection.selectedTable)||null),qy=()=>$r(e=>!e.selection.selectedEntryPoint||!e.galaxyData?null:e.galaxyData.entryPoints.find(t=>t.id===e.selection.selectedEntryPoint)||null),Yy=()=>$r(e=>!e.selection.selectedTable||!e.galaxyData?[]:e.galaxyData.dataPaths.filter(t=>t.targetTableId===e.selection.selectedTable)),Xy=()=>$r(e=>{if(!e.galaxyData)return[];let t=e.galaxyData.tables;const{filters:n}=e;if(n.minSensitivity){const r=["public","low","medium","high","critical"],s=r.indexOf(n.minSensitivity);t=t.filter(l=>r.indexOf(l.sensitivity)>=s)}if(n.clusters.length>0&&(t=t.filter(r=>r.cluster&&n.clusters.includes(r.cluster))),n.searchQuery){const r=n.searchQuery.toLowerCase();t=t.filter(s=>s.name.toLowerCase().includes(r)||s.fields.some(l=>l.name.toLowerCase().includes(r)))}return t}),Zy=()=>$r(e=>{if(!e.galaxyData)return[];let t=e.galaxyData.dataPaths;const{filters:n}=e;return n.operationType&&(t=t.filter(r=>r.operation===n.operationType)),n.untestedOnly&&(t=t.filter(r=>!r.isTested)),t}),Jy=()=>$r(e=>{if(!e.galaxyData)return[];let t=e.galaxyData.entryPoints;const{filters:n}=e;return n.publicOnly&&(t=t.filter(r=>r.authLevel==="public")),t});function gy({detector:e,onToggle:t}){return i.jsxs("div",{className:"flex items-center justify-between p-3 bg-dark-bg rounded",children:[i.jsxs("div",{children:[i.jsx("div",{className:"font-medium",children:e.name}),i.jsxs("div",{className:"text-xs text-dark-muted mt-0.5",children:[e.category," • ",e.id]})]}),i.jsx("button",{onClick:()=>t(!e.enabled),className:`w-12 h-6 rounded-full transition-colors ${e.enabled?"bg-status-approved":"bg-dark-border"}`,children:i.jsx("div",{className:`w-5 h-5 rounded-full bg-white shadow transition-transform ${e.enabled?"translate-x-6":"translate-x-0.5"}`})})]})}function yy({patterns:e,onChange:t}){const[n,r]=S.useState(""),s=()=>{n.trim()&&!e.includes(n.trim())&&(t([...e,n.trim()]),r(""))},l=a=>{t(e.filter(o=>o!==a))};return i.jsxs("div",{children:[i.jsxs("div",{className:"flex gap-2 mb-3",children:[i.jsx("input",{type:"text",placeholder:"Add ignore pattern (e.g., **/test/**)",className:"flex-1 bg-dark-bg border border-dark-border rounded px-3 py-1.5 text-sm",value:n,onChange:a=>r(a.target.value),onKeyDown:a=>a.key==="Enter"&&s()}),i.jsx("button",{onClick:s,className:"btn btn-secondary text-sm",children:"Add"})]}),i.jsxs("div",{className:"space-y-1",children:[e.map(a=>i.jsxs("div",{className:"flex items-center justify-between p-2 bg-dark-bg rounded text-sm",children:[i.jsx("code",{className:"font-mono",children:a}),i.jsx("button",{onClick:()=>l(a),className:"text-dark-muted hover:text-severity-error",children:"✕"})]},a)),e.length===0&&i.jsx("div",{className:"text-dark-muted text-sm",children:"No ignore patterns configured"})]})]})}function jy({overrides:e,onChange:t}){const[n,r]=S.useState(""),[s,l]=S.useState("warning"),a=()=>{n.trim()&&(t({...e,[n.trim()]:s}),r(""))},o=u=>{const h={...e};delete h[u],t(h)},c=["error","warning","info","hint"];return i.jsxs("div",{children:[i.jsxs("div",{className:"flex gap-2 mb-3",children:[i.jsx("input",{type:"text",placeholder:"Pattern ID",className:"flex-1 bg-dark-bg border border-dark-border rounded px-3 py-1.5 text-sm",value:n,onChange:u=>r(u.target.value)}),i.jsx("select",{className:"bg-dark-bg border border-dark-border rounded px-3 py-1.5 text-sm",value:s,onChange:u=>l(u.target.value),children:c.map(u=>i.jsx("option",{value:u,children:u},u))}),i.jsx("button",{onClick:a,className:"btn btn-secondary text-sm",children:"Add"})]}),i.jsxs("div",{className:"space-y-1",children:[Object.entries(e).map(([u,h])=>i.jsxs("div",{className:"flex items-center justify-between p-2 bg-dark-bg rounded text-sm",children:[i.jsx("code",{className:"font-mono",children:u}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:`px-2 py-0.5 rounded text-xs badge-${h}`,children:h}),i.jsx("button",{onClick:()=>o(u),className:"text-dark-muted hover:text-severity-error",children:"✕"})]})]},u)),Object.keys(e).length===0&&i.jsx("div",{className:"text-dark-muted text-sm",children:"No severity overrides configured"})]})]})}function Ny(){const{data:e,isLoading:t,error:n}=zv(),r=Uv();if(t)return i.jsx("div",{className:"flex items-center justify-center h-64",children:i.jsx("div",{className:"text-dark-muted",children:"Loading configuration..."})});if(n||!e)return i.jsx("div",{className:"flex items-center justify-center h-64",children:i.jsx("div",{className:"text-severity-error",children:"Failed to load configuration"})});const s=(c,u)=>{const h=e.detectors.map(d=>d.id===c?{...d,enabled:u}:d);r.mutate({detectors:h})},l=c=>{r.mutate({ignorePatterns:c})},a=c=>{r.mutate({severityOverrides:c})},o=e.detectors.reduce((c,u)=>{const h=u.category;return c[h]||(c[h]=[]),c[h].push(u),c},{});return i.jsxs("div",{className:"space-y-6 max-w-3xl",children:[i.jsxs("div",{className:"card",children:[i.jsx("h3",{className:"font-medium mb-2",children:"Configuration"}),i.jsxs("div",{className:"text-sm text-dark-muted",children:["Version: ",e.version]})]}),i.jsxs("div",{className:"card",children:[i.jsx("h3",{className:"font-medium mb-4",children:"Detectors"}),i.jsx("div",{className:"space-y-4",children:Object.entries(o).map(([c,u])=>i.jsxs("div",{children:[i.jsx("h4",{className:"text-sm text-dark-muted mb-2 capitalize",children:c}),i.jsx("div",{className:"space-y-2",children:u.map(h=>i.jsx(gy,{detector:h,onToggle:d=>s(h.id,d)},h.id))})]},c))})]}),i.jsxs("div",{className:"card",children:[i.jsx("h3",{className:"font-medium mb-4",children:"Ignore Patterns"}),i.jsx(yy,{patterns:e.ignorePatterns,onChange:l})]}),i.jsxs("div",{className:"card",children:[i.jsx("h3",{className:"font-medium mb-4",children:"Severity Overrides"}),i.jsx(jy,{overrides:e.severityOverrides,onChange:a})]}),r.isPending&&i.jsx("div",{className:"text-sm text-dark-muted",children:"Saving..."}),r.isError&&i.jsx("div",{className:"text-sm text-severity-error",children:"Failed to save changes"})]})}class by extends S.Component{constructor(t){super(t),this.state={hasError:!1,error:null}}static getDerivedStateFromError(t){return{hasError:!0,error:t}}componentDidCatch(t,n){console.error("Dashboard error:",t,n)}render(){return this.state.hasError?this.props.fallback?this.props.fallback:i.jsx("div",{className:"min-h-screen bg-dark-bg text-dark-text flex items-center justify-center p-6",children:i.jsxs("div",{className:"card max-w-md text-center",children:[i.jsx("div",{className:"text-4xl mb-4",children:"⚠️"}),i.jsx("h2",{className:"text-xl font-semibold mb-2",children:"Something went wrong"}),i.jsx("p",{className:"text-dark-muted mb-4",children:"The dashboard encountered an error. Try refreshing the page."}),this.state.error&&i.jsx("pre",{className:"text-xs text-left bg-dark-bg p-3 rounded overflow-auto max-h-32 text-severity-error",children:this.state.error.message}),i.jsx("button",{onClick:()=>window.location.reload(),className:"btn btn-primary mt-4",children:"Refresh Page"})]})}):this.props.children}}const ky=S.lazy(()=>iv(()=>import("./GalaxyTab-Bc9PKsMk.js"),[]).then(e=>({default:e.GalaxyTab}))),wy=[{id:"overview",label:"Overview"},{id:"patterns",label:"Patterns"},{id:"contracts",label:"Contracts"},{id:"violations",label:"Violations"},{id:"files",label:"Files"},{id:"galaxy",label:"🌌 Galaxy"},{id:"settings",label:"Settings"}];function Sy({status:e}){const t={connected:{color:"bg-status-approved",label:"Connected"},connecting:{color:"bg-severity-warning",label:"Connecting..."},disconnected:{color:"bg-dark-muted",label:"Disconnected"}}[e];return i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:`h-2 w-2 rounded-full ${t.color}`}),i.jsx("span",{className:"text-sm text-dark-muted",children:t.label})]})}function Cy(){return i.jsxs("div",{className:"flex flex-col items-center justify-center h-[calc(100vh-200px)] bg-slate-950 rounded-lg",children:[i.jsx("div",{className:"text-6xl mb-4 animate-pulse",children:"🌌"}),i.jsx("p",{className:"text-slate-400",children:"Loading Galaxy..."})]})}function Ey({tab:e}){switch(e){case"overview":return i.jsx(rg,{});case"patterns":return i.jsx(Eg,{});case"contracts":return i.jsx(Gg,{});case"violations":return i.jsx(fy,{});case"files":return i.jsx(my,{});case"galaxy":return i.jsx(S.Suspense,{fallback:i.jsx(Cy,{}),children:i.jsx(ky,{})});case"settings":return i.jsx(Ny,{});default:return null}}function Py(){const{connectionStatus:e,activeTab:t,setActiveTab:n}=Lr();return qv(),i.jsxs("div",{className:"min-h-screen bg-dark-bg text-dark-text",children:[i.jsx("header",{className:"border-b border-dark-border bg-dark-surface px-6 py-4",children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("div",{className:"flex items-center gap-3",children:i.jsx("h1",{className:"text-xl font-semibold",children:"Drift Dashboard"})}),i.jsx(Sy,{status:e})]})}),i.jsx("nav",{className:"border-b border-dark-border bg-dark-surface",children:i.jsx("div",{className:"flex gap-1 px-6",children:wy.map(r=>i.jsx("button",{onClick:()=>n(r.id),className:`px-4 py-3 text-sm font-medium transition-colors border-b-2 ${t===r.id?"text-dark-text border-blue-500":"text-dark-muted hover:text-dark-text border-transparent hover:border-dark-border"}`,children:r.label},r.id))})}),i.jsx("main",{className:"p-6",children:i.jsx(Ey,{tab:t})})]})}const Ty=new Hx({defaultOptions:{queries:{staleTime:3e4,retry:1}}}),Kh=document.getElementById("root");if(!Kh)throw new Error("Root element not found");ql.createRoot(Kh).render(i.jsx(cd.StrictMode,{children:i.jsx(by,{children:i.jsx(Bx,{client:Ty,children:i.jsx(Py,{})})})}));export{Ly as A,Ky as C,Wy as D,zy as E,Ay as F,Vy as G,By as L,Dy as O,Uy as P,Fy as S,$y as T,iv as _,Ry as a,My as b,jx as c,Hy as d,Qy as e,qi as f,Zu as g,Xy as h,Zy as i,i as j,Jy as k,Gy as l,qy as m,Yy as n,Oy as o,S as r,$r as u};
|
|
59
|
+
//# sourceMappingURL=main-BdVQNGtK.js.map
|