1import{r as l,y as g,c as j,p as w,z as N,g as v,j as e,L as k}from"./index-D6UrFXqh.js";import{A as _}from"./AppShell-DKhCxBd5.js";import{A as R}from"./arrow-left-DJrC1F0y.js";import{R as T}from"./refresh-cw-ByC1R9TZ.js";import"./Logo-VUZnl8oB.js";import"./createLucideIcon-DBOTLUhc.js";import"./shield-check-Nz0OL0hG.js";import"./sparkles-DMSCgezF.js";import"./help-circle-DfpDRC0m.js";import"./appContent-Bmmk0ks2.js";import"./file-text-DXawlq-x.js";const A=15e3,x=s=>new Intl.DateTimeFormat("en",{month:"short",day:"numeric",timeZone:"UTC"}).format(new Date(`${s}T00:00:00Z`)),y=s=>{if(!s||typeof s!="object")return!1;const r=s;return typeof r.week_start=="string"&&typeof r.week_end=="string"&&typeof r.total_referrals=="number"&&typeof r.kyc_verified=="number"},E=s=>{if(!s||typeof s!="object")return!1;const r=s;return y(r.current_week)&&Array.isArray(r.weekly_history)&&r.weekly_history.every(y)},O=()=>{const[s,r]=l.useState(null),[o,f]=l.useState(!0),[d,i]=l.useState(""),[u,b]=l.useState(0),h=l.useCallback(async t=>{f(!0),i("");try{const a=await g(j.referralDashboard(12),{signal:t}),n=await w(a);if(!a.ok){const m=N(n,a.status);i((m==null?void 0:m.message)??v(n,a.status,{fallback:"We could not load your referral activity right now.",serverError:"Referral activity is temporarily unavailable. Please try again shortly.",fieldOrder:["weeks","non_field_errors"]}));return}if(!E(n)){i("The referral activity response was incomplete.");return}r(n)}catch{t.aborted?i("Referral activity took too long to load. Please try again."):i("Network or server error. Please try again.")}finally{f(!1)}},[]);l.useEffect(()=>{const t=new AbortController,a=window.setTimeout(()=>t.abort(),A);return h(t.signal),()=>{window.clearTimeout(a),t.abort()}},[h,u]);const c=(s==null?void 0:s.weekly_history)??[],p=Math.max(1,...c.map(t=>t.total_referrals));return e.jsx(_,{children:e.jsxs("main",{className:"mx-auto max-w-3xl",children:[e.jsxs(k,{to:"/dashboard/refer",className:"inline-flex items-center gap-2 text-sm font-semibold text-slate-500 transition hover:text-primary",children:[e.jsx(R,{className:"h-4 w-4"}),"Refer and earn"]}),e.jsxs("section",{className:"mt-4 overflow-hidden rounded-xl border border-slate-100 bg-white shadow-xl shadow-slate-200/70",children:[e.jsxs("header",{className:"bg-primary px-5 py-8 text-white sm:px-8 sm:py-10",children:[e.jsx("p",{className:"text-sm font-semibold text-white/75",children:"Referral dashboard"}),e.jsx("h1",{className:"mt-2 text-3xl font-bold",children:"Your referral activity"}),e.jsx("p",{className:"mt-3 text-sm text-white/80",children:"Track referrals and completed KYC verification across the last 12 weeks."})]}),e.jsxs("div",{className:"space-y-6 p-4 sm:p-6",children:[d&&e.jsxs("div",{className:"flex flex-col gap-3 rounded-lg border border-amber-200 bg-amber-50 px-4 py-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsx("p",{className:"text-sm font-semibold text-amber-800",children:d}),e.jsxs("button",{type:"button",onClick:()=>b(t=>t+1),className:"inline-flex items-center justify-center gap-2 rounded-full bg-white px-4 py-2 text-xs font-bold text-amber-800 shadow-sm",children:[e.jsx(T,{className:"h-3.5 w-3.5"})," Try again"]})]}),e.jsxs("section",{"aria-labelledby":"current-week-heading",children:[e.jsx("div",{className:"flex items-end justify-between gap-3",children:e.jsxs("div",{children:[e.jsx("h2",{id:"current-week-heading",className:"text-base font-bold text-slate-900",children:"This week"}),e.jsx("p",{className:"mt-1 text-xs font-medium text-slate-500",children:s?`${x(s.current_week.week_start)} - ${x(s.current_week.week_end)}`:"Monday - Sunday"})]})}),e.jsxs("div",{className:"mt-4 grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"rounded-lg bg-primary/5 px-4 py-4",children:[e.jsx("p",{className:"text-3xl font-black text-slate-950",children:o?"...":(s==null?void 0:s.current_week.total_referrals)??0}),e.jsx("p",{className:"mt-1 text-xs font-semibold text-slate-500",children:"Total referrals"})]}),e.jsxs("div",{className:"rounded-lg bg-emerald-50 px-4 py-4",children:[e.jsx("p",{className:"text-3xl font-black text-emerald-700",children:o?"...":(s==null?void 0:s.current_week.kyc_verified)??0}),e.jsx("p",{className:"mt-1 text-xs font-semibold text-slate-500",children:"KYC verified"})]})]})]}),e.jsxs("section",{className:"border-t border-slate-100 pt-6","aria-labelledby":"history-heading",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("h2",{id:"history-heading",className:"text-base font-bold text-slate-900",children:"Weekly history"}),e.jsx("p",{className:"mt-1 text-xs font-medium text-slate-500",children:"Previous 12 weeks"})]}),e.jsxs("div",{className:"flex gap-3 text-[11px] font-semibold text-slate-500",children:[e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx("span",{className:"h-2.5 w-2.5 rounded-sm bg-primary"})," Referrals"]}),e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx("span",{className:"h-2.5 w-2.5 rounded-sm bg-emerald-500"})," KYC verified"]})]})]}),o?e.jsx("div",{className:"mt-5 space-y-3",role:"status","aria-label":"Loading referral activity",children:Array.from({length:6}).map((t,a)=>e.jsx("div",{className:"h-9 animate-pulse rounded bg-slate-100"},a))}):c.length>0?e.jsx("div",{className:"mt-5 space-y-3",children:c.map(t=>e.jsxs("div",{className:"grid grid-cols-[5.5rem_minmax(0,1fr)_2.5rem] items-center gap-3",children:[e.jsx("p",{className:"text-[11px] font-semibold text-slate-500",children:x(t.week_start)}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("div",{className:"h-2 overflow-hidden rounded-full bg-slate-100",children:e.jsx("div",{className:"h-full rounded-full bg-primary",style:{width:`${t.total_referrals/p*100}%`}})}),e.jsx("div",{className:"h-2 overflow-hidden rounded-full bg-slate-100",children:e.jsx("div",{className:"h-full rounded-full bg-emerald-500",style:{width:`${t.kyc_verified/p*100}%`}})})]}),e.jsxs("p",{className:"text-right text-[11px] font-bold text-slate-600","aria-label":`${t.total_referrals} referrals, ${t.kyc_verified} KYC verified`,children:[t.total_referrals,"/",t.kyc_verified]})]},t.week_start))}):d?null:e.jsx("p",{className:"mt-5 rounded-lg bg-slate-50 px-4 py-8 text-center text-sm font-medium text-slate-500",children:"No referral activity yet."})]})]})]})]})})};export{O as default};
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.