const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/js/react-apexcharts.min-CeFxfyVu.js","assets/js/chunk-UIGDSWPH-BhuNDbxn.js"])))=>i.map(i=>d[i]); import{u as oe,r,j as e,L as le,_ as de}from"./chunk-UIGDSWPH-BhuNDbxn.js";import{b as ce,d as ge,P as W,g as ue,k as me,l as he,N as xe}from"./main-af3pcbZa.js";import{C as c}from"./ComponentCard-C2b5w2__.js";import{P as z}from"./ProgressBar-0v269fGL.js";import{W as pe}from"./WorkflowPipeline-Ck3TPaPI.js";import{E as x}from"./EnhancedMetricCard-YOSFdLZV.js";import{S as be}from"./box-jJ_LUJjA.js";import{S as fe}from"./file-CeG1FbGg.js";import{S as ye}from"./arrow-right-DC7G5FiV.js";import{S as G}from"./pencil-CuC2vg9I.js";import{P as je}from"./PageHeader-iXTYKDGo.js";import"./check-circle--AtVWUy0.js";import"./Tooltip-D9yIUHzL.js";import"./arrow-up-Ba39LAbN.js";const p=r.lazy(()=>de(()=>import("./react-apexcharts.min-CeFxfyVu.js").then(m=>m.r),__vite__mapDeps([0,1])).then(m=>({default:m.default})));function De(){const m=oe(),{activeSite:b}=ce(),{activeSector:n}=ge(),[t,B]=r.useState(null),[_,R]=r.useState(!0),[E,A]=r.useState(new Date),[f,L]=r.useState({tasks:0,content:0,images:0}),y=async()=>{try{R(!0);const[a,o,i]=await Promise.all([me({page_size:1e3,sector_id:n==null?void 0:n.id}),he({page_size:1e3,sector_id:n==null?void 0:n.id}),xe({page_size:1e3,sector_id:n==null?void 0:n.id})]),l=a.results||[],g={};let h=0,C=0;l.forEach(s=>{g[s.status||"draft"]=(g[s.status||"draft"]||0)+1,s.word_count&&(h+=s.word_count,C++)});const U=l.filter(s=>s.status==="draft"||s.status==="pending").length,q=l.filter(s=>s.status==="in_progress"||s.status==="review").length,H=l.filter(s=>s.status==="completed"||s.status==="published").length,V=C>0?Math.round(h/C):0,d=o.results||[],O={},J={};let T=0,F=0;d.forEach(s=>{O[s.status||"draft"]=(O[s.status||"draft"]||0)+1,s.word_count&&(T+=s.word_count,F++)});const K=d.filter(s=>s.status==="draft").length,Q=d.filter(s=>s.status==="review").length,P=d.filter(s=>s.status==="published").length,X=F>0?Math.round(T/F):0,u=i.results||[],D={},S={};u.forEach(s=>{D[s.status||"pending"]=(D[s.status||"pending"]||0)+1,s.image_type&&(S[s.image_type]=(S[s.image_type]||0)+1)});const $=u.filter(s=>s.status==="generated"&&s.image_url).length,Z=u.filter(s=>s.status==="pending"||s.status==="draft"||!s.image_url).length,ee=u.filter(s=>s.status==="failed"||s.status==="error").length,M=new Date,te=new Date(M.getTime()-7*24*60*60*1e3),se=new Date(M.getTime()-30*24*60*60*1e3),ae=d.filter(s=>s.generated_at?new Date(s.generated_at)>=te:!1).length,re=d.filter(s=>s.generated_at?new Date(s.generated_at)>=se:!1).length,ne=d.length>0?Math.round(P/d.length*100):0;t&&L({tasks:l.length-t.tasks.total,content:d.length-t.content.total,images:u.length-t.images.total}),B({tasks:{total:l.length,byStatus:g,pending:U,inProgress:q,completed:H,avgWordCount:V,totalWordCount:h},content:{total:d.length,drafts:K,review:Q,published:P,totalWordCount:T,avgWordCount:X,byContentType:J},images:{total:u.length,generated:$,pending:Z,failed:ee,byType:S},workflow:{tasksCreated:l.length>0,contentGenerated:d.length>0,imagesGenerated:$>0,readyToPublish:P>0},productivity:{contentThisWeek:ae,contentThisMonth:re,avgGenerationTime:0,publishRate:ne}}),A(new Date)}catch(a){console.error("Error fetching dashboard data:",a)}finally{R(!1)}};r.useEffect(()=>{y();const a=setInterval(y,3e4);return()=>clearInterval(a)},[n==null?void 0:n.id,b==null?void 0:b.id]);const j=r.useMemo(()=>{if(!t)return null;const a={chart:{type:"donut",fontFamily:"Outfit, sans-serif",toolbar:{show:!1}},labels:Object.keys(t.tasks.byStatus).filter(i=>t.tasks.byStatus[i]>0),colors:["#465FFF","#F59E0B","#10B981","#EF4444","#8B5CF6"],legend:{position:"bottom",fontFamily:"Outfit",show:!0},dataLabels:{enabled:!1},tooltip:{enabled:!0,y:{formatter:(i,{seriesIndex:l,w:g})=>`${g.globals.labels[l]||""}: ${i}`}},plotOptions:{pie:{donut:{size:"70%",labels:{show:!0,name:{show:!1},value:{show:!0,fontSize:"24px",fontWeight:700,color:"#465FFF",fontFamily:"Outfit",formatter:()=>{const i=Object.values(t.tasks.byStatus).reduce((l,g)=>l+g,0);return i>0?i.toString():"0"}},total:{show:!1}}}}}},o=Object.keys(t.tasks.byStatus).filter(i=>t.tasks.byStatus[i]>0).map(i=>t.tasks.byStatus[i]);return{options:a,series:o}},[t]),v=r.useMemo(()=>{if(!t)return null;const a={chart:{type:"bar",fontFamily:"Outfit, sans-serif",toolbar:{show:!1},height:250},colors:["#465FFF","#F59E0B","#10B981"],plotOptions:{bar:{horizontal:!1,columnWidth:"55%",borderRadius:5}},dataLabels:{enabled:!0},xaxis:{categories:["Drafts","In Review","Published"],labels:{style:{fontFamily:"Outfit"}}},yaxis:{labels:{style:{fontFamily:"Outfit"}}},grid:{strokeDashArray:4}},o=[{name:"Content",data:[t.content.drafts,t.content.review,t.content.published]}];return{options:a,series:o}},[t]),k=r.useMemo(()=>{if(!t||Object.keys(t.images.byType).length===0)return null;const a={chart:{type:"bar",fontFamily:"Outfit, sans-serif",toolbar:{show:!1},height:250},colors:["#10B981"],plotOptions:{bar:{horizontal:!0,borderRadius:5}},dataLabels:{enabled:!0},xaxis:{categories:Object.keys(t.images.byType),labels:{style:{fontFamily:"Outfit",fontSize:"12px"}}},yaxis:{labels:{style:{fontFamily:"Outfit"}}}},o=[{name:"Images",data:Object.values(t.images.byType)}];return{options:a,series:o}},[t]),w=r.useMemo(()=>{if(!t)return null;const a={chart:{type:"area",fontFamily:"Outfit, sans-serif",toolbar:{show:!1},height:200},colors:["#465FFF"],stroke:{curve:"smooth",width:2},fill:{type:"gradient",gradient:{opacityFrom:.6,opacityTo:.1}},xaxis:{categories:["Week","Month"],labels:{style:{fontFamily:"Outfit"}}},yaxis:{labels:{style:{fontFamily:"Outfit"}}},grid:{strokeDashArray:4},dataLabels:{enabled:!0}},o=[{name:"Content Created",data:[t.productivity.contentThisWeek,t.productivity.contentThisMonth]}];return{options:a,series:o}},[t]);if(_&&!t)return e.jsxs(e.Fragment,{children:[e.jsx(W,{title:"Writer Dashboard - IGNY8",description:"Content creation overview"}),e.jsx("div",{className:"flex items-center justify-center h-96",children:e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"inline-block animate-spin rounded-full h-12 w-12 border-4 border-brand-500 border-t-transparent"}),e.jsx("p",{className:"mt-4 text-gray-600 dark:text-gray-400",children:"Loading dashboard data..."})]})})]});if(!t&&!_)return e.jsxs(e.Fragment,{children:[e.jsx(W,{title:"Writer Dashboard - IGNY8",description:"Content creation overview"}),e.jsx("div",{className:"text-center py-12",children:e.jsx("p",{className:"text-gray-600 dark:text-gray-400",children:n?"No data available for the selected sector.":"No data available. Select a sector or wait for data to load."})})]});if(!t)return null;const Y=[{number:1,title:"Create Tasks",status:t.workflow.tasksCreated?"completed":"pending",count:t.tasks.total,path:"/writer/tasks"},{number:2,title:"Generate Content",status:t.workflow.contentGenerated?"completed":"pending",count:t.content.total,path:"/writer/content"},{number:3,title:"Generate Images",status:t.workflow.imagesGenerated?"completed":"pending",count:t.images.generated,path:"/writer/images"},{number:4,title:"Publish",status:t.workflow.readyToPublish?"completed":"pending",count:t.content.published,path:"/writer/published"}],N=t.tasks.total>0?Math.round(t.tasks.completed/t.tasks.total*100):0,I=[...t.tasks.pending>0?[{text:`${t.tasks.pending} tasks pending content generation`,action:"Generate Content",path:"/writer/tasks"}]:[],...t.content.drafts>0?[{text:`${t.content.drafts} drafts ready for review`,action:"Review Content",path:"/writer/content"}]:[],...t.images.pending>0?[{text:`${t.images.pending} images pending generation`,action:"Generate Images",path:"/writer/images"}]:[],...t.content.review>0?[{text:`${t.content.review} content pieces ready to publish`,action:"Publish Content",path:"/writer/published"}]:[]];return e.jsxs(e.Fragment,{children:[e.jsx(W,{title:"Writer Dashboard - IGNY8",description:"Content creation overview"}),e.jsxs("div",{className:"space-y-5 sm:space-y-6",children:[e.jsx(je,{title:"Writer Dashboard",lastUpdated:E,showRefresh:!0,onRefresh:y,badge:{icon:e.jsx(G,{}),color:"blue"}}),e.jsx("div",{className:"rounded-2xl border border-gray-200 bg-gradient-to-br from-brand-50 to-white dark:from-brand-500/10 dark:to-gray-800/50 dark:border-gray-800 p-6 md:p-8",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-gray-600 dark:text-gray-400",children:"Content Creation Progress"}),e.jsx("h3",{className:"mt-2 text-3xl font-bold text-gray-800 dark:text-white/90",children:t.content.published>0?e.jsxs(e.Fragment,{children:[t.content.published," Content Pieces Published"]}):t.content.review>0?e.jsxs(e.Fragment,{children:[t.content.review," Pieces Ready to Publish"]}):t.content.drafts>0?e.jsxs(e.Fragment,{children:[t.content.drafts," Drafts Ready for Review"]}):t.tasks.total>0?e.jsxs(e.Fragment,{children:[t.tasks.total," Tasks Created"]}):e.jsx(e.Fragment,{children:"Ready to Create Content"})}),e.jsxs("p",{className:"mt-2 text-sm text-gray-500 dark:text-gray-400",children:[t.tasks.total," tasks • ",t.content.total," content pieces • ",t.images.generated," images generated"]})]}),e.jsxs("div",{className:"hidden md:flex items-center gap-4",children:[e.jsxs("div",{className:"text-center",children:[e.jsxs("div",{className:"text-2xl font-bold text-brand-500",children:[N,"%"]}),e.jsx("div",{className:"text-xs text-gray-500 dark:text-gray-400",children:"Complete"})]}),e.jsxs("div",{className:"text-center",children:[e.jsxs("div",{className:"text-2xl font-bold text-success-500",children:[t.productivity.publishRate,"%"]}),e.jsx("div",{className:"text-xs text-gray-500 dark:text-gray-400",children:"Published"})]}),e.jsxs("div",{className:"text-center",children:[e.jsxs("div",{className:"text-2xl font-bold text-warning-500",children:[t.images.generated>0?Math.round(t.images.generated/t.images.total*100):0,"%"]}),e.jsx("div",{className:"text-xs text-gray-500 dark:text-gray-400",children:"Images"})]})]})]})}),e.jsxs("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-2 lg:grid-cols-4 md:gap-6",children:[e.jsx(x,{title:"Total Tasks",value:t.tasks.total,subtitle:`${t.tasks.completed} completed • ${t.tasks.pending} pending`,trend:f.tasks,icon:e.jsx(fe,{className:"size-6"}),accentColor:"blue",href:"/writer/tasks",details:[{label:"Total Tasks",value:t.tasks.total},{label:"Completed",value:t.tasks.completed},{label:"Pending",value:t.tasks.pending},{label:"In Progress",value:t.tasks.inProgress},{label:"Avg Word Count",value:t.tasks.avgWordCount}]}),e.jsx(x,{title:"Content Pieces",value:t.content.total,subtitle:`${t.content.published} published • ${t.content.drafts} drafts`,trend:f.content,icon:e.jsx(G,{className:"size-6"}),accentColor:"green",href:"/writer/content",details:[{label:"Total Content",value:t.content.total},{label:"Published",value:t.content.published},{label:"In Review",value:t.content.review},{label:"Drafts",value:t.content.drafts},{label:"Avg Word Count",value:t.content.avgWordCount.toLocaleString()}]}),e.jsx(x,{title:"Images Generated",value:t.images.generated,subtitle:`${t.images.total} total • ${t.images.pending} pending`,trend:f.images,icon:e.jsx(be,{className:"size-6"}),accentColor:"orange",href:"/writer/images",details:[{label:"Generated",value:t.images.generated},{label:"Total Images",value:t.images.total},{label:"Pending",value:t.images.pending},{label:"Failed",value:t.images.failed}]}),e.jsx(x,{title:"Publish Rate",value:`${t.productivity.publishRate}%`,subtitle:`${t.content.published} of ${t.content.total} published`,icon:e.jsx(ue,{className:"size-6"}),accentColor:"purple",href:"/writer/published",details:[{label:"Publish Rate",value:`${t.productivity.publishRate}%`},{label:"Published",value:t.content.published},{label:"Total Content",value:t.content.total},{label:"This Week",value:t.productivity.contentThisWeek},{label:"This Month",value:t.productivity.contentThisMonth}]})]}),e.jsx(c,{title:"Writer Workflow Pipeline",desc:"Track your content creation progress through each stage",children:e.jsx(pe,{steps:Y.map(a=>({number:a.number,title:a.title,status:a.status==="completed"?"completed":a.status==="in_progress"?"in_progress":"pending",count:a.count||0,path:a.path,description:a.title,details:a.status==="completed"?`✓ ${a.title} completed with ${a.count} items`:a.status==="pending"?`→ ${a.title} pending - ${a.count} items ready`:`⟳ ${a.title} in progress`})),onStepClick:a=>{m(a.path)},showConnections:!0})}),e.jsxs("div",{className:"grid grid-cols-1 gap-6 lg:grid-cols-3",children:[e.jsx(c,{title:"Productivity Metrics",desc:"Content creation performance",className:"lg:col-span-1",children:e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("span",{className:"text-sm font-medium text-gray-700 dark:text-gray-300",children:"Task Completion"}),e.jsxs("span",{className:"text-sm font-semibold text-gray-800 dark:text-white/90",children:[N,"%"]})]}),e.jsx(z,{value:N,color:"primary",size:"md"}),e.jsxs("p",{className:"mt-1 text-xs text-gray-500 dark:text-gray-400",children:[t.tasks.completed," of ",t.tasks.total," tasks completed"]})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("span",{className:"text-sm font-medium text-gray-700 dark:text-gray-300",children:"Publish Rate"}),e.jsxs("span",{className:"text-sm font-semibold text-gray-800 dark:text-white/90",children:[t.productivity.publishRate,"%"]})]}),e.jsx(z,{value:t.productivity.publishRate,color:"success",size:"md"}),e.jsxs("p",{className:"mt-1 text-xs text-gray-500 dark:text-gray-400",children:[t.content.published," of ",t.content.total," content published"]})]}),e.jsx("div",{className:"pt-4 border-t border-gray-200 dark:border-gray-800",children:e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400 mb-1",children:"This Week"}),e.jsx("p",{className:"text-lg font-bold text-gray-800 dark:text-white/90",children:t.productivity.contentThisWeek})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400 mb-1",children:"This Month"}),e.jsx("p",{className:"text-lg font-bold text-gray-800 dark:text-white/90",children:t.productivity.contentThisMonth})]})]})}),e.jsx("div",{className:"pt-4 border-t border-gray-200 dark:border-gray-800",children:e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400 mb-1",children:"Avg Word Count"}),e.jsx("p",{className:"text-lg font-bold text-gray-800 dark:text-white/90",children:t.content.avgWordCount.toLocaleString()}),e.jsxs("p",{className:"text-xs text-gray-500 dark:text-gray-400 mt-1",children:[t.content.totalWordCount.toLocaleString()," total words"]})]})})]})}),v&&e.jsx(c,{title:"Content by Status",desc:"Distribution across workflow stages",className:"lg:col-span-2",children:e.jsx(r.Suspense,{fallback:e.jsx("div",{className:"flex items-center justify-center h-[300px]",children:e.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-4 border-brand-500 border-t-transparent"})}),children:e.jsx(p,{options:v.options,series:v.series,type:"bar",height:300})})})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-6 lg:grid-cols-2",children:[j&&e.jsx(c,{title:"Tasks by Status",desc:"Task distribution across statuses",children:e.jsx(r.Suspense,{fallback:e.jsx("div",{className:"flex items-center justify-center h-[300px]",children:e.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-4 border-brand-500 border-t-transparent"})}),children:e.jsx(p,{options:j.options,series:j.series,type:"donut",height:300})})}),k?e.jsx(c,{title:"Images by Type",desc:"Image generation breakdown",children:e.jsx(r.Suspense,{fallback:e.jsx("div",{className:"flex items-center justify-center h-[300px]",children:e.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-4 border-brand-500 border-t-transparent"})}),children:e.jsx(p,{options:k.options,series:k.series,type:"bar",height:300})})}):e.jsx(c,{title:"Images Overview",desc:"Image generation status",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between p-4 rounded-lg bg-gray-50 dark:bg-gray-900/50",children:[e.jsx("span",{className:"text-sm font-medium text-gray-700 dark:text-gray-300",children:"Generated"}),e.jsx("span",{className:"text-lg font-bold text-success-500",children:t.images.generated})]}),e.jsxs("div",{className:"flex items-center justify-between p-4 rounded-lg bg-gray-50 dark:bg-gray-900/50",children:[e.jsx("span",{className:"text-sm font-medium text-gray-700 dark:text-gray-300",children:"Pending"}),e.jsx("span",{className:"text-lg font-bold text-warning-500",children:t.images.pending})]}),e.jsxs("div",{className:"flex items-center justify-between p-4 rounded-lg bg-gray-50 dark:bg-gray-900/50",children:[e.jsx("span",{className:"text-sm font-medium text-gray-700 dark:text-gray-300",children:"Failed"}),e.jsx("span",{className:"text-lg font-bold text-error-500",children:t.images.failed})]})]})})]}),w&&e.jsx(c,{title:"Content Creation Trend",desc:"Content created this week and month",children:e.jsx(r.Suspense,{fallback:e.jsx("div",{className:"flex items-center justify-center h-[200px]",children:e.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-4 border-brand-500 border-t-transparent"})}),children:e.jsx(p,{options:w.options,series:w.series,type:"area",height:200})})}),I.length>0&&e.jsx(c,{title:"Next Actions",desc:"Actionable items requiring attention",children:e.jsx("div",{className:"space-y-3",children:I.map((a,o)=>e.jsxs("div",{className:"flex items-center justify-between p-4 rounded-lg bg-gradient-to-r from-gray-50 to-white dark:from-gray-900/50 dark:to-gray-800/50 border border-gray-200 dark:border-gray-800 hover:border-brand-300 dark:hover:border-brand-500/30 transition-all group",children:[e.jsx("span",{className:"text-sm font-medium text-gray-700 dark:text-gray-300",children:a.text}),e.jsxs(le,{to:a.path,className:"inline-flex items-center gap-2 text-sm font-medium text-brand-500 hover:text-brand-600 group-hover:translate-x-1 transition-transform",children:[a.action,e.jsx(ye,{className:"size-4"})]})]},o))})})]})]})}export{De as default};