1import{j as e,u as y,r as x,a as L,b as R,C as h,B as u,L as m,A as d,D as G,U as w}from"./index-C5HFcgnI.js";import{g as E}from"./group-Cq184g7s.js";import{s as F}from"./socialImpact-D7wqoutY.js";import{g as $}from"./goal-ivuQYUff.js";import{b as A}from"./business-dAWSONPt.js";import{C as T}from"./Badge-BFCTe5Vm.js";import{P as B}from"./ProgressBar-5eOSHtbw.js";import"./client-Cfb1KgHR.js";const M=({message:a,onDismiss:t,className:l=""})=>e.jsx("div",{className:`bg-green-50 border-l-4 border-green-400 p-4 rounded-md shadow-sm ${l}`,children:e.jsxs("div",{className:"flex",children:[e.jsx("div",{className:"flex-shrink-0",children:e.jsx("svg",{className:"h-5 w-5 text-green-400",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z",clipRule:"evenodd"})})}),e.jsx("div",{className:"ml-3 flex-1",children:e.jsx("p",{className:"text-sm text-green-700",children:a})}),e.jsx("div",{className:"ml-auto pl-3",children:e.jsx("div",{className:"-mx-1.5 -my-1.5",children:e.jsxs("button",{type:"button",onClick:t,className:"inline-flex bg-green-50 rounded-md p-1.5 text-green-500 hover:bg-green-100 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-offset-green-50 focus:ring-green-600","aria-label":"Dismiss",children:[e.jsx("span",{className:"sr-only",children:"Dismiss"}),e.jsx("svg",{className:"h-5 w-5",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{d:"M6.28 5.22a.75.75 0 00-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 101.06 1.06L10 11.06l3.72 3.72a.75.75 0 101.06-1.06L11.06 10l3.72-3.72a.75.75 0 00-1.06-1.06L10 8.94 6.28 5.22z"})})]})})})]})}),_=({user:a})=>{const{getText:t}=y();return a?e.jsxs("div",{className:"mb-8",children:[e.jsxs("h1",{className:"text-3xl font-bold text-textPrimary",children:[t("welcome"),", ",a.name,"!"]}),e.jsx("p",{className:"text-md text-textSecondary",children:"Here's your Sòl summary at a glance."})]}):null},O=({user:a})=>{y();const t=a.creditScore,l=60,o=2*Math.PI*l,n=o-t/100*o;let i="stroke-green-500";return t<50?i="stroke-red-500":t<75&&(i="stroke-yellow-500"),a.isFlaggedByAdmin&&(i="stroke-red-600"),e.jsxs(h,{title:"Credit Score Builder",className:"h-full flex flex-col",children:[e.jsxs("div",{className:"flex-grow flex flex-col items-center justify-center",children:[e.jsx("div",{className:"relative w-40 h-40",children:e.jsxs("svg",{className:"w-full h-full",viewBox:"0 0 140 140",children:[e.jsx("circle",{className:"text-gray-200",strokeWidth:"12",stroke:"currentColor",fill:"transparent",r:l,cx:"70",cy:"70"}),e.jsx("circle",{className:`${i} transition-all duration-1000 ease-out`,strokeWidth:"12",strokeDasharray:o,strokeDashoffset:n,strokeLinecap:"round",fill:"transparent",r:l,cx:"70",cy:"70",transform:"rotate(-90 70 70)"}),e.jsxs("text",{x:"50%",y:"50%",textAnchor:"middle",dy:".3em",className:"text-3xl font-bold fill-current text-textPrimary",children:[t,"%"]})]})}),e.jsx(T,{score:a.creditScore,isFlagged:a.isFlaggedByAdmin,flagReason:a.adminFlagReason,size:"md",className:"mt-4"})]}),e.jsx("p",{className:"text-center text-sm text-textSecondary mt-4",children:"Positive participation keeps your score high and unlocks new opportunities."})]})},Y=({projects:a,invitations:t,groups:l})=>{const o=x.useMemo(()=>{const n=a.filter(r=>r.status==="pending_approval"||r.status==="rejected").map(r=>({id:`proj-${r.id}`,type:"project",date:new Date(r.submissionDate),icon:e.jsx(G,{className:"w-5 h-5 text-secondary"}),bgColor:"bg-secondary/10",text:`Your project submission "${r.name}" is ${r.status.replace("_"," ")}.`,link:d.SOCIAL_IMPACT_DIRECTORY})),i=t.map(r=>({id:`inv-${r.id}`,type:"invitation",date:new Date,icon:e.jsx(w,{className:"w-5 h-5 text-blue-500"}),bgColor:"bg-blue-500/10",text:`You have a staff invitation from ${r.businessName}.`,link:d.DASHBOARD})),j=l.slice(0,1).map(r=>({id:`group-${r.id}`,type:"group",date:new Date(r.createdAt),icon:e.jsx(w,{className:"w-5 h-5 text-green-500"}),bgColor:"bg-green-500/10",text:`You joined or created a new group: "${r.name}".`,link:d.GROUP_DETAILS.replace(":groupId",r.id)}));return[...n,...i,...j].sort((r,g)=>
1g.date.getTime()-r.date.getTime()).slice(0,5)},[a,t,l]);return e.jsx(h,{title:"Recent Activity",className:"h-full",children:o.length===0?e.jsx("p",{className:"text-center text-textSecondary py-8",children:"No recent activity."}):e.jsx("ul",{className:"space-y-3",children:o.map(n=>e.jsx("li",{children:e.jsxs(m,{to:n.link,className:"flex items-center space-x-3 p-2 rounded-lg hover:bg-gray-50",children:[e.jsx("div",{className:`flex-shrink-0 w-8 h-8 rounded-full flex items-center justify-center ${n.bgColor}`,children:n.icon}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"text-sm text-textPrimary",children:n.text}),e.jsx("p",{className:"text-xs text-textSecondary",children:n.date.toLocaleDateString()})]})]})},n.id))})})},Q=()=>{const{currentUser:a,getText:t,setIsLoading:l,isLoading:o,setError:n}=y(),[i,j]=x.useState([]),[r,g]=x.useState([]),[C,k]=x.useState([]),[f,v]=x.useState([]),N=L(),p=R(),[b,S]=x.useState(null);x.useEffect(()=>{p.state?.successMessage&&(S(p.state.successMessage),N(p.pathname,{replace:!0,state:{}}))},[p.state,N]);const I=async()=>{if(!a)return;l(!0);const s=[E.getGroupsForUser(a.id).then(j).catch(c=>{console.error("Failed to load groups:",c),n(c.message)}),$.getGoalsForUser(a.id).then(g).catch(c=>{console.error("Failed to load goals:",c),n(c.message)}),F.getMySubmittedProjects(a.id).then(k).catch(c=>console.error("Failed to load submitted projects:",c)),A.getStaffInvitations().then(v).catch(c=>console.error("Failed to load staff invitations:",c))];await Promise.all(s),l(!1)};x.useEffect(()=>{I()},[a]);const P=async s=>{try{await A.confirmStaffInvitation(s),v(c=>c.filter(D=>D.id!==s)),alert("Invitation accepted! You are now a staff member.")}catch(c){n(c instanceof Error?c.message:"Failed to accept invitation.")}};return o&&i.length===0&&!a?e.jsx("div",{className:"flex justify-center items-center h-screen",children:e.jsx("p",{children:t("loading")})}):a?e.jsxs("div",{className:"container mx-auto px-4 py-8",children:[b&&e.jsx(M,{message:b,onDismiss:()=>S(null),className:"mb-6"}),e.jsx(_,{user:a}),f.length>0&&e.jsx(h,{className:"mb-6 bg-blue-50 border-primary-light",children:e.jsx("ul",{className:"space-y-3",children:f.map(s=>e.jsxs("li",{className:"flex flex-col sm:flex-row justify-between items-start sm:items-center p-3 rounded-md border border-gray-200 bg-white",children:[e.jsxs("p",{className:"text-textSecondary mb-2 sm:mb-0",children:["You have been invited to be a staff member at ",e.jsx("span",{className:"font-semibold text-textPrimary",children:s.businessName}),"."]}),e.jsx(u,{size:"sm",onClick:()=>P(s.id),children:"Accept Invitation"})]},s.id))})}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 xl:grid-cols-3 gap-6",children:[e.jsxs("div",{className:"space-y-6",children:[e.jsxs(h,{title:t("myGroups"),actions:e.jsx(m,{to:d.CREATE_GROUP,children:e.jsx(u,{variant:"ghost",size:"sm",children:t("createGroup")})}),children:[o&&i.length===0&&e.jsxs("p",{className:"text-sm text-center py-4",children:[t("loading"),"..."]}),!o&&i.length===0&&e.jsxs("div",{className:"text-center py-4",children:[e.jsx("p",{className:"text-textSecondary mb-4",children:"You haven't joined any groups yet."}),e.jsx(m,{to:d.CREATE_GROUP,children:e.jsx(u,{variant:"secondary",size:"sm",children:t("createYourFirstGroup")})})]}),i.length>0&&e.jsx("ul",{className:"space-y-3",children:i.slice(0,4).map(s=>e.jsx("li",{children:e.jsxs(m,{to:`/group/${s.id}`,className:"block p-3 rounded-lg hover:bg-gray-50 border transition-colors",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("p",{className:"font-semibold text-primary truncate",children:s.name}),e.jsxs("span",{className:"text-xs text-textSecondary",children:[s.members.length," members"]})]}),e.jsxs("p",{className:"text-xs text-textSecondary mt-1",children:["Next Payout: ",s.nextPayout?`${s.nextPayout.memberName} on ${new Date(s.nextPayout.payoutDate).toLocaleDateString()}`:"N/A"]})]})},s.id))})]}),e.jsx(h,{title:t("goalBasedSaving"),actions:e.jsx(m,{to:d.CREATE_GOAL,children:e.jsx(u,{variant:"ghost",size:"sm",children:t("createSavingGoal")})}),children:r.length>0?e.jsxs("div",{className:"space-y-4",children:[r.slice(0,2).map(s=>e.jsx("div",{children:e.jsxs(m,{to:d.VIEW_GOAL.replace(":goalId",s.id),className:"block hover:bg-gray-50 p-2 rounded-md",children:[e.jsxs("div",{className:"flex justify-between text-sm font-semibold text-textPrimary",children:[e.jsx("span",{children:s.goalName}),e.jsxs("span",{children:[(s.currentAmount/s.targetAmount*100).toFixed(0),"%"]})]}),e.jsx(B,{value:s.currentAmount,max:s.targetAmount,className:"h-2 my-1"}),e.jsx("div",{className:"flex justify-between text-xs text-textSecondary",children:e.jsxs("span",{children:[t("currentProgress"),": $",s.currentAmount.toLocaleStr
1ing()]})})]})},s.id)),e.jsx(m,{to:d.MY_GOALS,className:"mt-4 block text-center",children:e.jsx(u,{variant:"outline",size:"sm",children:t("viewDetails","View All Goals")})})]}):e.jsx("p",{className:"text-sm text-textSecondary text-center py-4",children:t("noGoalsDescription")})})]}),e.jsx("div",{className:"space-y-6",children:e.jsx(Y,{projects:C,invitations:f,groups:i})}),e.jsxs("div",{className:"space-y-6",children:[e.jsx(O,{user:a}),e.jsxs(h,{title:t("socialImpactCircles"),children:[e.jsx("p",{className:"text-sm text-textSecondary mb-4",children:"Discover and support community projects. Your vote helps guide funding decisions."}),e.jsx(m,{to:d.SOCIAL_IMPACT_DIRECTORY,className:"block text-center",children:e.jsx(u,{variant:"outline",className:"w-full",children:t("exploreProjects")})})]})]})]})]}):null};export{Q as DashboardPage};
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.