1import{r as m,j as e}from"./vendor-react-core-Ba2gwJNM.js";import{cp as T,C as _,i as H,aM as L,v as G,bA as z,bB as K,B as w,c4 as Q,bm as N,bC as W,bD as g,c,a9 as C,aa as y,m as A,f as J,a1 as V,bF as X}from"./index-D-XLV-_s.js";import{S as Y}from"./switch-DeplDPKd.js";import{L as Z}from"./label-C7mpxRQf.js";import{C as ee}from"./contributor-hover-card-C0HX-wbl.js";import{a as se}from"./workspace-hover-card-utils-BkMVgsNA.js";import{S as te}from"./shareable-card-C6xl7CxJ.js";import"./vendor-ui-C6PEtgd7.js";import"./vendor-utils-MSNXLbuZ.js";import"./vendor-supabase-De54M4W1.js";import"./optimized-avatar-h4G6FDnr.js";import"./optimized-avatar-utils-DZFOtv7e.js";import"./separator-Czgj9iqU.js";import"./learn-more-link-BqXmoMmb.js";import"./index-B0Ir_8Hh.js";import"./dub-Bh1lUtcN.js";function ve({pullRequests:h,onAuthorClick:j,className:B,maxVisible:R=10,title:b="Pull Request Author Status",repositories:P,workspaceName:$}){const[f,S]=m.useState(!0),[v,D]=m.useState(!1),[d,x]=m.useState("all"),o=m.useMemo(()=>{const s=new Map;h.filter(t=>t.state==="open"||t.state==="draft").forEach(t=>{const r=t.author.username,M=t.author.avatar_url,I=T({username:r});let l=s.get(r);if(l||(l={username:r,avatar_url:M,totalOpenPRs:0,openPRs:0,draftPRs:0,blockedPRs:0,approvedPRs:0,pendingPRs:0,isBot:I},s.set(r,l)),l.totalOpenPRs++,t.state==="draft")l.draftPRs++;else if(t.state==="open")if(l.openPRs++,t.reviewers&&t.reviewers.length>0){const q=t.reviewers.some(u=>u.approved||u.state==="APPROVED");t.reviewers.some(u=>u.state==="CHANGES_REQUESTED")?l.blockedPRs++:q?l.approvedPRs++:l.pendingPRs++}else l.pendingPRs++});let n=Array.from(s.values());return f&&(n=n.filter(t=>!t.isBot)),d!=="all"&&(n=n.filter(t=>{switch(d){case"blocked":return t.blockedPRs>0;case"approved":return t.approvedPRs>0;case"pending":return t.pendingPRs>0;default:return!0}})),n.sort((t,r)=>t.approvedPRs!==r.approvedPRs?r.approvedPRs-t.approvedPRs:t.blockedPRs!==r.blockedPRs?r.blockedPRs-t.blockedPRs:t.totalOpenPRs!==r.totalOpenPRs?r.totalOpenPRs-t.totalOpenPRs:0)},[h,f,d]),O=v?o:o.slice(0,R),E=o.length>R,p=Math.max(...o.map(s=>s.totalOpenPRs),1),k=s=>{j&&j(s.username)},i=m.useMemo(()=>o.reduce((s,a)=>({totalOpen:s.totalOpen+a.openPRs,totalDraft:s.totalDraft+a.draftPRs,totalBlocked:s.totalBlocked+a.blockedPRs,totalApproved:s.totalApproved+a.approvedPRs,totalPending:s.totalPending+a.pendingPRs}),{totalOpen:0,totalDraft:0,totalBlocked:0,totalApproved:0,totalPending:0}),[o]),U=s=>{const a=encodeURIComponent(s.username);if(P&&P.length===1){const n=P[0];return`https://github.com/${encodeURIComponent(n.owner)}/${encodeURIComponent(n.name)}/pulls?q=is%3Apr+author%3A${a}`}return`https://github.com/pulls?q=is%3Apr+author%3A${a}`};if(o.length===0)return null;const F=()=>{switch(d){case"blocked":return"Blocked PRs";case"approved":return"Approved PRs";
1case"pending":return"Pending Review";default:return"All PRs"}};return e.jsx(te,{title:b,contextInfo:{repository:$||"Workspace",metric:"pr-author-status"},chartType:"pr-author-status",children:e.jsxs(_,{className:c("w-full",B),children:[e.jsx(H,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(L,{className:"h-5 w-5 text-muted-foreground"}),e.jsx(G,{children:b})]}),e.jsxs(z,{children:[e.jsx(K,{asChild:!0,children:e.jsxs(w,{variant:"outline",size:"sm",className:"h-8",children:[e.jsx(Q,{className:"h-3 w-3 mr-2"}),F(),e.jsx(N,{className:"h-3 w-3 ml-2"})]})}),e.jsxs(W,{align:"end",children:[e.jsx(g,{onClick:()=>x("all"),className:c(d==="all"&&"bg-accent"),children:"All PRs"}),e.jsxs(g,{onClick:()=>x("blocked"),className:c(d==="blocked"&&"bg-accent"),children:[e.jsx(C,{className:"h-3 w-3 mr-2 text-red-500"}),"Blocked (Changes Requested)"]}),e.jsxs(g,{onClick:()=>x("approved"),className:c(d==="approved"&&"bg-accent"),children:[e.jsx(y,{className:"h-3 w-3 mr-2 text-green-500"}),"Approved"]}),e.jsxs(g,{onClick:()=>x("pending"),className:c(d==="pending"&&"bg-accent"),children:[e.jsx(A,{className:"h-3 w-3 mr-2 text-yellow-500"}),"Pending Review"]})]})]})]})}),e.jsxs(J,{children:[e.jsxs("div",{className:"space-y-3",children:[O.map(s=>{const a=U(s);return e.jsx("div",{className:"group cursor-pointer hover:bg-muted/50 rounded-lg p-2 -mx-2 transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-primary",onClick:()=>k(s),onKeyDown:n=>{n.currentTarget===n.target&&(n.key==="Enter"||n.key===" ")&&(n.preventDefault(),k(s))},tabIndex:0,role:"button","aria-label":`Select ${s.username}, ${s.totalOpenPRs} open PRs`,children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(ee,{contributor:{login:s.username,avatar_url:s.avatar_url||`https://github.com/${encodeURIComponent(s.username)}.png`,pullRequests:s.totalOpenPRs,percentage:0,recentPRs:se(s.username,h,5)},children:e.jsx("a",{href:a,target:"_blank",rel:"noopener noreferrer",className:"flex-shrink-0",onClick:n=>n.stopPropagation(),title:`View PRs authored by ${s.username}`,children:e.jsx("img",{src:s.avatar_url||`https://github.com/${encodeURIComponent(s.username)}.png`,alt:`${s.username}'s avatar - ${s.totalOpenPRs} open PRs`,className:"h-8 w-8 rounded-full hover:ring-2 hover:ring-primary transition-all",onError:n=>{n.currentTarget.src=`https://github.com/${encodeURIComponent(s.username)}.png`}})})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("span",{className:"text-sm font-medium truncate",children:s.username}),s.isBot&&e.jsx(V,{variant:"secondary",className:"text-xs",children:"Bot"}),e.jsxs("div",{className:"flex items-center gap-1 text-xs text-muted-foreground",children:[s.blockedPRs>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{title:"Changes requested (blocked)",children:e.jsx(C,{className:"h-3 w-3 text-red-500"})}),e.jsx("span",{children:s.blockedPRs})]}),s.approvedPRs>0&&e.jsxs(e.Fragment,{children:[s.blockedPRs>0&&e.jsx("span",{children:"/"}),e.jsx("span",{title:"Approved PRs",children:e.jsx(y,{className:"h-3 w-3 text-green-500"})}),e.jsx("span",{children:s.approvedPRs})]}),s.pendingPRs>0&&e.jsxs(e.Fragment,{children:[(s.blockedPRs>0||s.approvedPRs>0)&&e.jsx("span",{children:"/"}),e.jsx("span",{title:"Pending review",children:e.jsx(A,{className:"h-3 w-3 text-yellow-500"})}),e.jsx("span",{children:s.pendingPRs})]})]})]}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"h-6 bg-muted rounded-md overflow-hidden",children:e.jsxs("div",{className:"flex h-full",children:[s.blockedPRs>0&&e.jsx("div",{className:"bg-red-500 dark:bg-red-600 transition-all duration-500 ease-out",style:{width:`${s.blockedPRs/p*100}%`},title:`${s.blockedPRs} blocked (changes requested)`}),s.pendingPRs>0&&e.jsx("div",{className:"bg-yellow-500 dark:bg-yellow-600 transition-all duration-500 ease-out",style:{width:`${s.pendingPRs/p*100}%`},title:`${s.pendingPRs} pending review`}),s.approvedPRs>0&&e.jsx("div",{className:"bg-green-500 dark:bg-green-600 transition-all duration-500 ease-out",style:{width:`${s.approvedPRs/p*100}%`},title:`${s.approvedPRs} approved`}),s.draftPRs>0&&e.jsx("div",{className:"bg-gray-500 dark:bg-gray-600 transition-all duration-500 ease-out",style:{width:`${s.draftPRs/p*100}%`},title:`${s.draftPRs} draft`})]})}),e.jsx("div",{className:"absolute inset-0 flex items-center justify-end pr-2",children:e.jsx("span",{className:c("text-xs font-medium",s.totalOpenPRs/p>.6?"text-white dark:text-black":"text-foreground"),children:s.totalOpenPRs})})]})]})]})},s.username)}),E&&e.jsx(w,{variant:"ghost",size:"sm",onClick:()=>D(!v),className:"w-full",children:v?e.jsxs(e.Fragment,{children:[e.jsx(X,{className:"h-4 w-4 mr-1"}),"Show Less"]}):e.jsxs(e.Fragment,{children:[e.jsx(N,{className:"h-4 w-4 mr-1"}),"Show ",o.length-R," More"]})})]}),e.jsxs("div",{className:"mt-4 pt-4 border-t space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between text-sm text-muted-foreground",children:[e.jsxs("span",{children:["Total authors: ",o.length]}),e.jsxs("div",{className:"flex gap-2 flex-wrap",children:[i.totalBlocked>0&&e.jsxs("span",{className:"text-red-600 dark:text-red-400 font-medium",children:[i.totalBlocked," blocked"]}),i.totalApproved>0&&e.jsxs("span",{className:"text-green-600 dark:text-green-400",children:[i.totalApproved," approved"]}),i.totalPending>0&&e.jsxs("span",{className:"text-yellow-600 dark:text-yellow-400",children:[i.totalPending," pending"]})]})]}),e.jsx("div",{className:"flex items-center justify-end gap-4",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Y,{id:"exclude-bots-pr-author",checked:f,onCheckedChange:S}),e.jsx(Z,{htmlFor:"exclude-bots-pr-author",className:"text-sm text-muted-foreground",children:"Exclude Bots"})]})})]})]})]})})}export{ve as PRAuthorStatusChart};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.