1import{j as e}from"./vendor-react-CYGQtLbL.js";import{u as p}from"./useDashboardStats-DxeDiFMe.js";import{h as f,t as x,s as h,j,C as c,r as d,a as i,q as m}from"./index-BI5Xs1tD.js";import{a as N}from"./vendor-query-CTv-0CvJ.js";import{R as b,P as g,c as w,d as y}from"./vendor-recharts-B1eFEiga.js";import{bn as C}from"./vendor-icons-DUSjHmPI.js";import"./vendor-sentry-N2mFvU_B.js";import"./vendor-radix-B8Jde9zG.js";import"./vendor-supabase-BxFEoWbK.js";import"./vendor-style-utils--BulIq_u.js";import"./vendor-toast-C2ugWvTP.js";import"./vendor-router-ru3jn0Tj.js";import"./vendor-d3-CHRfgbu5.js";function v(){const{user:a}=f(),r=N({queryKey:["top-courses",a?.id],queryFn:async()=>{const{data:l,error:t}=await h.functions.invoke("get-top-courses",{method:"GET"});if(t)throw x(t)&&j.warn("Top courses transient error:",t),t;return l?.courses||[]},enabled:!!a,staleTime:5*6e4,gcTime:10*6e4,retry:(l,t)=>x(t)?l<2:!1});return{courses:r.data??[],loading:r.isLoading,error:r.isError?r.error?.message??"Failed to fetch top courses":null,refetch:async()=>{await r.refetch()}}}const u=["#5BB5B0","#F5C542","#8B7EC8","#E57373","#81C784"];function T(){const{courses:a,loading:r}=v();if(r)return e.jsxs(c,{className:"border-border/40 shadow-none",children:[e.jsx(d,{className:"pb-3 sm:pb-2 pt-3 px-4 sm:px-6",children:e.jsx("p",{className:"text-sm font-medium text-foreground",children:"Cursos em destaque"})}),e.jsx(i,{className:"pt-2 sm:pt-0 pb-4",children:e.jsxs("div",{className:"flex flex-col items-center gap-4",children:[e.jsx(m,{className:"w-28 h-28 sm:w-32 sm:h-32 rounded-full"}),e.jsx("div",{className:"flex-1 flex flex-col gap-1.5 w-full",children:[1,2,3].map(s=>e.jsxs("div",{className:"flex-1",children:[e.jsx(m,{className:"h-4 w-24 mb-1"}),e.jsx(m,{className:"h-3 w-full"})]},s))})]})})]});if(!a||a.length===0)return e.jsxs(c,{className:"border-border/40 shadow-none",children:[e.jsx(d,{className:"pb-3 sm:pb-2 pt-3 px-4 sm:px-6",children:e.jsx("p",{className:"text-sm font-medium text-foreground",children:"Cursos em destaque"})}),e.jsx(i,{className:"pt-2 sm:pt-0 pb-4",children:e.jsxs("div",{className:"flex flex-col items-center justify-center h-40 text-center",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Nenhum curso publicado ainda"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Publique cursos para ver as estatÃsticas"})]})})]});const l=a.map((s,n)=>({...s,color:u[n%u.length]})),t=l.reduce((s,n)=>s+n.students,0),o=l.map(s=>({name:s.name,value:s.students,percentage:t>0?Math.round(s.students/t*100):0,color:s.color}));return e.jsxs(c,{className:"border-border/40 shadow-none",children:[e.jsx(d,{className:"pb-3 sm:pb-2 pt-3 px-4 sm:px-6",children:e.jsx("p",{className:"text-sm font-medium text-foreground",children:"Cursos em destaque"})}),e.jsx(i,{className:"pt-2 sm:pt-0 pb-4",children:e.jsxs("div",{className:"flex flex-col items-center gap-4",children:[e.jsxs("div",{className:"relative w-28 h-28 sm:w-32 sm:h-32 flex-shrink-0",children:[e.jsx(b,{width:"100%",height:"100%",children:e.jsx(g,{children:e.jsx(w,{data:o,cx:"50%",cy:"50%",innerRadius:"60%",outerRadius:"90%",paddingAngle:2,dataKey:"value",stroke:"none",children:o.map((s,n)=>e.jsx(y,{fill:s.color},`cell-${n}`))})})}),e.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"Total"}),e.jsx("span",{className:"text-base font-bold",children:t})]})]}),e.jsx("div",{className:"flex-1 flex flex-col gap-1.5 w-full",children:o.map((s,n)=>e.jsxs("div",{className:"flex-1 ",style:{animationDelay:`${n*50}ms`},children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-0.5",children:[e.jsx("div",{className:"w-2 h-2 rounded-full flex-shrink-0",style:{backgroundColor:s.color}}),e.jsx("span",{className:"text-xs text-foreground font-medium truncate",children:s.name})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"text-sm font-bold tabular-nums",children:[s.percentage,"%"]}),e.jsx("div",{className:"flex-1 h-1 bg-muted/50 rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full transition-all duration-500",style:{width:`${s.percentage}%`,backgroundColor:s.color}})})]})]},s.name))})]})})]})}function k(){return e.jsxs(c,{className:"border-border/40 shadow-none h-full flex flex-col",children:[e.jsx(d,{className:"pb-3 sm:pb-2 pt-3 px-4 sm:px-6 flex-shrink-0",children:e.jsx("p",{className:"text-sm font-medium text-foreground",children:"Cursos em destaque"})}),e.jsxs(i,{className:"pt-2 sm:pt-0 flex-1 flex flex-col items-center justify-center pb-4",children:[e.jsx("div",{className:"w-10 h-10 rounded-full bg-brand/10 flex items-center justify-center mb-4 ",children:e.jsx(C,{className:"w-5 h-5 text-brand"})}),e.jsx("p",{className:"text-sm font-medium text-foreground text-center ",style:{animationDelay:"50ms"},children:"Seus cursos mais acessados"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1.5 text-center max-w-[200px] ",style:{animationDelay:"100ms"},children:"aparecerão aqui"})]})]})}function G({membersAreaId:a,kpis:r}){const{data:l}=p(a,!!a&&!r),t=r??l;return t&&t.totalStudents>
10?e.jsx(T,{}):e.jsx(k,{})}export{G as SmartTopCourses};
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.