1import{r as f,j as e}from"./vendor-react-core-Ba2gwJNM.js";import{g as I,cp as P,C as y,i as C,U as k,v as S,f as E,L as W,c as _,a1 as J,B as Q,bF as X,bm as Y}from"./index-D-XLV-_s.js";import{S as B}from"./switch-DeplDPKd.js";import{L}from"./label-C7mpxRQf.js";import{C as Z}from"./contributor-hover-card-C0HX-wbl.js";import{S as V}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";async function ee(c,x,g){const m=await I(),{data:o,error:d}=await m.from("issues").select("id, assignees, repository_id").in("repository_id",c).eq("state","open").limit(1e3);if(d)throw new Error(`Failed to fetch issues for fallback: ${d.message}`);if(!o||o.length===0)return[];const i=new Map;o.forEach(n=>{!n.assignees||!Array.isArray(n.assignees)||n.assignees.forEach(t=>{if(!t.login||x&&P({username:t.login}))return;const a=i.get(t.login);a?a.repos.add(n.repository_id):i.set(t.login,{login:t.login,avatar_url:t.avatar_url||"",repos:new Set([n.repository_id])})})});const h=Array.from(i.entries()).map(([n,t])=>({login:n,avatar_url:t.avatar_url,issue_count:o.filter(a=>a.assignees&&Array.isArray(a.assignees)&&a.assignees.some(u=>u.login===n)).length,repository_count:t.repos.size}));return h.sort((n,t)=>t.issue_count-n.issue_count),h.slice(0,g)}function se({repositoryIds:c,excludeBots:x=!0,limit:g=100,enabled:m=!0}){const[o,d]=f.useState([]),[i,h]=f.useState(!1),[n,t]=f.useState(null),a=f.useCallback(async()=>{if(!m||c.length===0){d([]),h(!1);return}try{h(!0),t(null);const u=await I(),{data:b,error:p}=await u.rpc("calculate_assignee_distribution",{p_repository_ids:c,p_exclude_bots:x,p_limit:g});if(p&&p.message.includes("Could not find the function")){console.warn("RPC function not found, falling back to client-side calculation:",p.message);const l=await ee(c,x,g);d(l);return}if(p)throw new Error(`Failed to fetch assignee distribution: ${p.message}`);d(b||[])}catch(u){console.error("Error fetching assignee distribution:",u),t(u instanceof Error?u.message:"Failed to fetch assignee distribution"),d([])}finally{h(!1)}},[c,x,g,m]);return f.useEffect(()=>{a()},[a]),{data:o,loading:i,error:n,refresh:a}}function pe({repositoryIds:c,issues:x,onAssigneeClick:g,className:m,maxVisible:o=5,showPercentage:d=!1,title:i="Issue Assignee Distribution",workspaceName:h}){const[n,t]=f.useState(!0),[a,u]=f.useState(d),[b,p]=f.useState(!1),{data:l,loading:U,error:A}=se({repositoryIds:c,excludeBots:n,limit:100,enabled:c.length>0}),M=b?l:l.slice(0,o),z=l.length>o,N=l.reduce((s,w)=>s+w.issue_count,0),D=Math.max(...l.map(s=>s.issue_count),1),F=s=>{g?.(s)},R=(s,w)=>w===0?null:`https://github.com/issues?q=assignee%3A${s}`;return U?e.jsxs(y,{className:_("w-full",m),children:[e.jsx(C,{children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(k,{className:"h-5 w-5 text-muted-foreground"}),e.jsx(S,{children:i})]})}),e.jsx(E,{className:"flex items-center justify-center py-8",children:e.jsx(W,{className:"h-6 w-6 animate-spin text-muted-foreground"})})]}):A?e.jsxs(y,{className:_("w-full",m),children:[e.jsx(C,{children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(k,{className:"h-5 w-5 text-muted-foreground"}),e.jsx(S,{children:i})]})}),e.jsx(E,{children:e.jsx("p",{className:"text-sm text-destructive",children:A})})]}):l.length===0?null:e.jsx(V,{title:i,contextInfo:{repository:h||"Workspace",metric:"assignee-distribution"},chartType:"assignee-distribution",children:e.jsxs(y,{className:_("w-full",m),children:[e.jsx(C,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(k,{className:"h-5 w-5 text-muted-foreground"}),e.jsx(S,{children:i})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(B,{id:"show-percentage",checked:a,onCheckedChange:u}),e.jsx(L,{htmlFor:"show-percentage",className:"text-sm",children:"Show %"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(B,{id:"exclude-bots",checked:n,onCheckedChange:t}),e.jsx(L,{htmlFor:"exclude-bots",className:"text-sm",children:"Exclude Bots"})]})]})]})}),e.jsxs(E,{children:[e.jsxs("div",{className:"space-y-3",children:[M.map(s=>{const w=N>0?s.issue_count/N*100:0,T=P({username:s.login}),v=R(s.login,s.repository_count),q=()=>{const j=v?"h-8 w-8 rounded-full hover:ring-2 hover:ring-primary transition-all":"h-8 w-8 rounded-full",H=x.filter(r=>r.state==="open"&&r.assignees?.some(O=>O.login===s.login)).slice(0,5).map(r=>({id:r.id,number:r.number,title:r.title,state:r.state,created_at:r.created_at,updated_at:r.updated_at,closed_at:r.closed_at,repository_owner:r.repository.owner,repository_name:r.repository.name,comments_count:r.comments_count,html_url:r.url})),G={login:s.login,avatar_url:s.avatar_url,pullRequests:s.issue_count,percentage:0,recentIssues:H},$=e.jsx("img",{src:s.avatar_url,alt:`${s.login}'s avatar - ${s.issue_count} assigned issues`,className:j,loading:"lazy"}),K=v?e.jsx("a",{href:v,target:"_blank",rel:"noopener noreferrer",className:"flex-shrink-0",onClick:r=>r.stopPropagation(),children:$}):$;return e.jsx(Z,{contributor:G,showReviews:!1,showComments:!1,useIssueIcons:!0,primaryLabel:"assigned",children:K})};return e.jsxs("div",{className:"group flex items-center gap-3 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:()=>F(s.login),onKeyDown:j=>{(j.key==="Enter"||j.key===" ")&&(j.preventDefault(),F(s.login))},tabIndex:0,role:"button","aria-label":`Select ${s.login}, ${s.issue_count} assigned issues`,children:[q(),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[v?e.jsx("a",{href:v,target:"_blank",rel:"noopener noreferrer",className:"text-sm font-medium truncate hover:underline",onClick:j=>j.stopPropagation(),children:s.login}):e.jsx("span",{className:"text-sm font-medium truncate",children:s.login}),T&&e.jsx(J,{variant:"secondary",className:"text-xs",children:"Bot"})]}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"h-6 bg-muted rounded-md overflow-hidden",children:e.jsx("div",{className:"h-full bg-black dark:bg-white transition-all duration-500 ease-out",style:{width:`${s.issue_count/D*100}%`}})}),e.jsx("div",{className:"absolute inset-0 flex items-center justify-end pr-2",children:e.jsx("span",{className:_("text-xs font-medium",s.issue_count/D>.6?"text-white dark:text-black":"text-foreground"),children:a?`${w.toFixed(1)}%`:s.issue_count})})]})]})]},s.login)}),z&&e.jsx(Q,{variant:"ghost",size:"sm",onClick:()=>p(!b),className:"w-full",children:b?e.jsxs(e.Fragment,{children:[e.jsx(X,{className:"h-4 w-4 mr-1"}),"Show Less"]}):e.jsxs(e.Fragment,{children:[e.jsx(Y,{className:"h-4 w-4 mr-1"}),"Show ",l.length-o," More"]})})]}),e.jsxs("div",{className:"mt-4 pt-4 border-t flex items-center justify-between text-sm text-muted-foreground",children:[e.jsxs("span",{children:["Total assignees: ",l.length]}),e.jsxs("span",{children:["Total assigned issues: ",N]})]})]})]})})}export{pe as AssigneeDistributionChartOptimized};
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.