1import{j as n}from"./query-vendor-DBbghNzL.js";import{u as Pe,r as m,L as X}from"./react-vendor-B4iqnpmg.js";import{h as R,au as Te,A as Ie,l as $e,m as Le,i as Fe,s as b,B as g,C as F,av as D}from"./index-Dddl32Ja.js";import{Q as De}from"./index-DgE2fuR2.js";import{S as V,n as Me,H as Ae,r as Ue,a4 as He,N as Ve,aw as Oe,av as J,ax as We,T as Z,j as M,ay as ze,az as qe,ae as Be,aA as Ge,aB as Qe}from"./icons-vendor-DfIUqQcN.js";import{t as Ye}from"./loyalty-BrR-y0gR.js";import"./supabase-vendor-DRR_Es6B.js";const Ke={Pacer:5,Strider:10,Trailblazer:15,"Elite Runner":20};function oe(e){return Ke[e]??5}const Xe={Pacer:V,Strider:Ue,Trailblazer:He,"Elite Runner":Ve},ee={Pacer:"from-sky-400 to-sky-600",Strider:"from-emerald-400 to-emerald-600",Trailblazer:"from-amber-400 to-orange-500","Elite Runner":"from-fuchsia-500 to-rose-500"};function te({data:e,qrValue:t,showQr:s=!0,className:r,highContrastQr:i=!1}){var d;const a=Xe[e.tier]??V,l=ee[e.tier]??ee.Pacer,c=oe(e.tier),o=e.member_since?new Date(e.member_since).getFullYear():null;return n.jsxs("div",{className:R("relative w-full max-w-[360px] aspect-[3/4] rounded-3xl overflow-hidden shadow-2xl","bg-gradient-to-br from-primary via-primary-deep to-[hsl(96_55%_28%)]","text-primary-foreground",r),style:{boxShadow:"0 25px 50px -12px hsl(96 55% 25% / 0.55), inset 0 1px 0 0 hsl(0 0% 100% / 0.15)"},children:[n.jsxs("svg",{"aria-hidden":!0,className:"absolute inset-0 w-full h-full opacity-[0.14] mix-blend-screen",viewBox:"0 0 360 480",preserveAspectRatio:"none",children:[n.jsx("defs",{children:n.jsxs("pattern",{id:"topo-p",width:"60",height:"60",patternUnits:"userSpaceOnUse",children:[n.jsx("path",{d:"M0 30 Q15 10 30 30 T60 30",stroke:"white",strokeWidth:"0.6",fill:"none"}),n.jsx("path",{d:"M0 50 Q15 30 30 50 T60 50",stroke:"white",strokeWidth:"0.6",fill:"none"})]})}),n.jsx("rect",{width:"360",height:"480",fill:"url(#topo-p)"}),n.jsx("path",{d:"M-10 360 C 60 300, 120 400, 200 320 S 320 270, 380 340",stroke:"white",strokeWidth:"2.5",fill:"none",strokeLinecap:"round",opacity:"0.45"})]}),n.jsx("div",{className:R("absolute top-0 left-0 right-0 h-2 bg-gradient-to-r",l)}),e.founding_member&&n.jsx("div",{className:"absolute -right-10 top-6 rotate-45 bg-accent text-accent-foreground text-[10px] font-extrabold tracking-widest px-12 py-1 shadow-md z-10",children:"FOUNDING"}),n.jsxs("div",{className:"relative h-full flex flex-col p-5",children:[n.jsxs("div",{className:"flex items-center justify-between gap-2",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("div",{className:"bg-white/95 rounded-lg px-2 py-1.5 shadow-sm",children:n.jsx("img",{src:Te,alt:"wedorunning",className:"h-5 w-auto"})}),n.jsxs("div",{className:"leading-tight",children:[n.jsx("p",{className:"text-[9px] uppercase tracking-[0.18em] opacity-80",children:"Member ID"}),n.jsx("p",{className:"text-[10px] font-semibold opacity-95",children:"Your Running Family"})]})]}),n.jsxs("div",{className:R("flex items-center gap-1.5 px-2.5 py-1 rounded-full bg-gradient-to-r text-white text-[11px] font-bold shadow-md",l),children:[n.jsx(a,{className:"h-3 w-3"}),e.tier]})]}),s&&t&&n.jsx("div",{className:"flex justify-center mt-4",children:n.jsx("div",{className:R("rounded-2xl p-3 shadow-lg",i?"bg-white":"bg-white/95"),children:n.jsx(De,{value:t,size:i?240:200,level:"M",bgColor:"#ffffff",fgColor:"#1a1a1a"})})}),n.jsxs("div",{className:"flex items-center gap-3 mt-4 min-w-0",children:[n.jsxs("div",{className:"relative shrink-0",children:[e.looking_for_buddy&&n.jsx("span",{className:"absolute inset-0 rounded-full ring-2 ring-accent animate-ping opacity-60"}),n.jsxs(Ie,{className:"h-12 w-12 border-2 border-white/90 shadow-md",children:[n.jsx($e,{src:e.avatar_url??void 0}),n.jsx(Le,{className:"bg-white/30 text-white text-base font-bold",children:((d=e.display_name)==null?void 0:d[0])??"R"})]})]}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("p",{className:"text-base font-extrabold leading-tight truncate",style:{fontFamily:"'Plus Jakarta Sans', sans-serif"},children:e.display_name}),n.jsxs("p",{className:"text-[11px] opacity-85 truncate",children:["@",e.handle,e.city?` · ${e.city}`:""]})]})]}),n.jsxs("div",{className:"grid grid-cols-3 gap-1 mt-3 bg-white/10 rounded-xl py-2 px-2 backdrop-blur-sm",children:[n.jsx(A,{label:"Miles",value:Math.round(e.miles).toLocaleStr
1ing()}),n.jsx(A,{label:"Points",value:e.points.toLocaleString()}),n.jsx(A,{label:"Saves",value:`${c}%`,icon:n.jsx(Me,{className:"h-2.5 w-2.5"})})]}),n.jsx("div",{className:"flex-1"}),n.jsxs("div",{className:"flex items-end justify-between gap-2 pt-3 border-t border-white/20",children:[n.jsxs("div",{className:"leading-tight",children:[n.jsx("p",{className:"text-[8px] uppercase tracking-widest opacity-70",children:"Member No."}),n.jsx("p",{className:"text-[12px] font-mono font-semibold",children:e.member_number})]}),n.jsxs("div",{className:"leading-tight text-center",children:[n.jsx("p",{className:"text-[8px] uppercase tracking-widest opacity-70",children:"Since"}),n.jsx("p",{className:"text-[12px] font-semibold",children:o??"â"})]}),e.is_active_member&&n.jsxs("div",{className:"flex items-center gap-1 bg-white/15 backdrop-blur-sm px-2 py-1 rounded-full",children:[n.jsx(Ae,{className:"h-2.5 w-2.5 fill-white"}),n.jsx("span",{className:"text-[9px] font-bold uppercase tracking-wider",children:"Member"})]})]})]})]})}function A({label:e,value:t,icon:s}){return n.jsxs("div",{className:"leading-tight text-center",children:[n.jsxs("p",{className:"text-base font-extrabold tabular-nums flex items-center justify-center gap-1",children:[s,t]}),n.jsx("p",{className:"text-[8px] uppercase tracking-widest opacity-75",children:e})]})}function Je(e,t){if(e.match(/^[a-z]+:\/\//i))return e;if(e.match(/^\/\//))return window.location.protocol+e;if(e.match(/^[a-z]+:/i))return e;const s=document.implementation.createHTMLDocument(),r=s.createElement("base"),i=s.createElement("a");return s.head.appendChild(r),s.body.appendChild(i),t&&(r.href=t),i.href=e,i.href}const Ze=(()=>{let e=0;const t=()=>`0000${(Math.random()*36**4<<0).toString(36)}`.slice(-4);return()=>(e+=1,`u${t()}${e}`)})();function w(e){const t=[];for(let s=0,r=e.length;s<r;s++)t.push(e[s]);return t}let j=null;function ue(e={}){return j||(e.includeStyleProperties?(j=e.includeStyleProperties,j):(j=w(window.getComputedStyle(document.documentElement)),j))}function C(e,t){const r=(e.ownerDocument.defaultView||window).getComputedStyle(e).getPropertyValue(t);return r?parseFloat(r.replace("px","")):0}function et(e){const t=C(e,"border-left-width"),s=C(e,"border-right-width");return e.clientWidth+t+s}function tt(e){const t=C(e,"border-top-width"),s=C(e,"border-bottom-width");return e.clientHeight+t+s}function de(e,t={}){const s=t.width||et(e),r=t.height||tt(e);return{width:s,height:r}}function st(){let e,t;try{t=process}catch{}const s=t&&t.env?t.env.devicePixelRatio:null;return s&&(e=parseInt(s,10),Number.isNaN(e)&&(e=1)),e||window.devicePixelRatio||1}const f=16384;function rt(e){(e.width>f||e.height>f)&&(e.width>f&&e.height>f?e.width>e.height?(e.height*=f/e.width,e.width=f):(e.width*=f/e.height,e.height=f):e.width>f?(e.height*=f/e.width,e.width=f):(e.width*=f/e.height,e.height=f))}function E(e){return new Promise((t,s)=>{const r=new Image;r.onload=()=>{r.decode().then(()=>{requestAnimationFrame(()=>t(r))})},r.onerror=s,r.crossOrigin="anonymous",r.decoding="async",r.src=e})}async function nt(e){return Promise.resolve().then(()=>new XMLSerializer().serializeToString(e)).then(encodeURIComponent).then(t=>`data:image/svg+xml;charset=utf-8,${t}`)}async function at(e,t,s){const r="http://www.w3.org/2000/svg",i=document.createElementNS(r,"svg"),a=document.createElementNS(r,"foreignObject");return i.setAttribute("width",`${t}`),i.setAttribute("height",`${s}`),i.setAttribute("viewBox",`0 0 ${t} ${s}`),a.setAttribute("width","100%"),a.setAttribute("height","100%"),a.setAttribute("x","0"),a.setAttribute("y","0"),a.setAttribute("externalResourcesRequired","true"),i.appendChild(a),a.appendChild(e),nt(i)}const h=(e,t)=>{if(e instanceof t)return!0;const s=Object.getPrototypeOf(e);return s===null?!1:s.constructor.name===t.name||h(s,t)};function it(e){const t=e.getPropertyValue("content");return`${e.cssText} content: '${t.replace(/'|"/g,"")}';`}function lt(e,t){return ue(t).map(s=>{const r=e.getPropertyValue(s),i=e.getPropertyPriority(s);return`${s}: ${r}${i?" !important":""};`}).join(" ")}function ct(e,t,s,r){const i=`.${e}:${t}`,a=s.cssText?it(s):lt(s,r);return document.createTextNode(`${i}{${a}}`)}function se(e,t,s,r){const i=window.getComputedStyle(e,s),a=i.getPropertyValue("content");
1if(a===""||a==="none")return;const l=Ze();try{t.className=`${t.className} ${l}`}catch{return}const c=document.createElement("style");c.appendChild(ct(l,s,i,r)),t.appendChild(c)}function ot(e,t,s){se(e,t,":before",s),se(e,t,":after",s)}const re="application/font-woff",ne="image/jpeg",ut={woff:re,woff2:re,ttf:"application/font-truetype",eot:"application/vnd.ms-fontobject",png:"image/png",jpg:ne,jpeg:ne,gif:"image/gif",tiff:"image/tiff",svg:"image/svg+xml",webp:"image/webp"};function dt(e){const t=/\.([^./]*?)$/g.exec(e);return t?t[1]:""}function O(e){const t=dt(e).toLowerCase();return ut[t]||""}function mt(e){return e.split(/,/)[1]}function H(e){return e.search(/^(data:)/)!==-1}function ht(e,t){return`data:${t};base64,${e}`}async function me(e,t,s){const r=await fetch(e,t);if(r.status===404)throw new Error(`Resource "${r.url}" not found`);const i=await r.blob();return new Promise((a,l)=>{const c=new FileReader;c.onerror=l,c.onloadend=()=>{try{a(s({res:r,result:c.result}))}catch(o){l(o)}},c.readAsDataURL(i)})}const U={};function ft(e,t,s){let r=e.replace(/\?.*/,"");return s&&(r=e),/ttf|otf|eot|woff2?/i.test(r)&&(r=r.replace(/.*\//,"")),t?`[${t}]${r}`:r}async function W(e,t,s){const r=ft(e,t,s.includeQueryParams);if(U[r]!=null)return U[r];s.cacheBust&&(e+=(/\?/.test(e)?"&":"?")+new Date().getTime());let i;try{const a=await me(e,s.fetchRequestInit,({res:l,result:c})=>(t||(t=l.headers.get("Content-Type")||""),mt(c)));i=ht(a,t)}catch(a){i=s.imagePlaceholder||"";let l=`Failed to fetch resource: ${e}`;a&&(l=typeof a=="string"?a:a.message),l&&console.warn(l)}return U[r]=i,i}async function xt(e){const t=e.toDataURL();return t==="data:,"?e.cloneNode(!1):E(t)}async function gt(e,t){if(e.currentSrc){const a=document.createElement("canvas"),l=a.getContext("2d");a.width=e.clientWidth,a.height=e.clientHeight,l==null||l.drawImage(e,0,0,a.width,a.height);const c=a.toDataURL();return E(c)}const s=e.poster,r=O(s),i=await W(s,r,t);return E(i)}async function pt(e,t){var s;try{if(!((s=e==null?void 0:e.contentDocument)===null||s===void 0)&&s.body)return await _(e.contentDocument.body,t,!0)}catch{}return e.cloneNode(!1)}async function wt(e,t){return h(e,HTMLCanvasElement)?xt(e):h(e,HTMLVideoElement)?gt(e,t):h(e,HTMLIFrameElement)?pt(e,t):e.cloneNode(he(e))}const yt=e=>e.tagName!=null&&e.tagName.toUpperCase()==="SLOT",he=e=>e.tagName!=null&&e.tagName.toUpperCase()==="SVG";async function bt(e,t,s){var r,i;if(he(t))return t;let a=[];return yt(e)&&e.assignedNodes?a=w(e.assignedNodes()):h(e,HTMLIFrameElement)&&(!((r=e.contentDocument)===null||r===void 0)&&r.body)?a=w(e.contentDocument.body.childNodes):a=w(((i=e.shadowRoot)!==null&&i!==void 0?i:e).childNodes),a.length===0||h(e,HTMLVideoElement)||await a.reduce((l,c)=>l.then(()=>_(c,s)).then(o=>{o&&t.appendChild(o)}),Promise.resolve()),t}function jt(e,t,s){const r=t.style;if(!r)return;const i=window.getComputedStyle(e);i.cssText?(r.cssText=i.cssText,r.transformOrigin=i.transformOrigin):ue(s).forEach(a=>{let l=i.getPropertyValue(a);a==="font-size"&&l.endsWith("px")&&(l=`${Math.floor(parseFloat(l.substring(0,l.length-2)))-.1}px`),h(e,HTMLIFrameElement)&&a==="display"&&l==="inline"&&(l="block"),a==="d"&&t.getAttribute("d")&&(l=`path(${t.getAttribute("d")})`),r.setProperty(a,l,i.getPropertyPriority(a))})}function St(e,t){h(e,HTMLTextAreaElement)&&(t.innerHTML=e.value),h(e,HTMLInputElement)&&t.setAttribute("value",e.value)}function vt(e,t){if(h(e,HTMLSelectElement)){const s=t,r=Array.from(s.children).find(i=>e.value===i.getAttribute("value"));r&&r.setAttribute("selected","")}}
1function Nt(e,t,s){return h(t,Element)&&(jt(e,t,s),ot(e,t,s),St(e,t),vt(e,t)),t}async function kt(e,t){const s=e.querySelectorAll?e.querySelectorAll("use"):[];if(s.length===0)return e;const r={};for(let a=0;a<s.length;a++){const c=s[a].getAttribute("xlink:href");if(c){const o=e.querySelector(c),d=document.querySelector(c);!o&&d&&!r[c]&&(r[c]=await _(d,t,!0))}}const i=Object.values(r);if(i.length){const a="http://www.w3.org/1999/xhtml",l=document.createElementNS(a,"svg");l.setAttribute("xmlns",a),l.style.position="absolute",l.style.width="0",l.style.height="0",l.style.overflow="hidden",l.style.display="none";const c=document.createElementNS(a,"defs");l.appendChild(c);for(let o=0;o<i.length;o++)c.appendChild(i[o]);e.appendChild(l)}return e}async function _(e,t,s){return!s&&t.filter&&!t.filter(e)?null:Promise.resolve(e).then(r=>wt(r,t)).then(r=>bt(e,r,t)).then(r=>Nt(e,r,t)).then(r=>kt(r,t))}const fe=/url\((['"]?)([^'"]+?)\1\)/g,Rt=/url\([^)]+\)\s*format\((["']?)([^"']+)\1\)/g,Ct=/src:\s*(?:url\([^)]+\)\s*format\([^)]+\)[,;]\s*)+/g;function Et(e){const t=e.replace(/([.*+?^${}()|\[\]\/\\])/g,"\\$1");return new RegExp(`(url\\(['"]?)(${t})(['"]?\\))`,"g")}function _t(e){const t=[];return e.replace(fe,(s,r,i)=>(t.push(i),s)),t.filter(s=>!H(s))}async function Pt(e,t,s,r,i){try{const a=s?Je(t,s):t,l=O(t);let c;return i||(c=await W(a,l,r)),e.replace(Et(t),`$1${c}$3`)}catch{}return e}function Tt(e,{preferredFontFormat:t}){return t?e.replace(Ct,s=>{for(;;){const[r,,i]=Rt.exec(s)||[];if(!i)return"";if(i===t)return`src: ${r};`}}):e}function xe(e){return e.search(fe)!==-1}async function ge(e,t,s){if(!xe(e))return e;const r=Tt(e,s);return _t(r).reduce((a,l)=>a.then(c=>Pt(c,l,t,s)),Promise.resolve(r))}async function S(e,t,s){var r;const i=(r=t.style)===null||r===void 0?void 0:r.getPropertyValue(e);if(i){const a=await ge(i,null,s);return t.style.setProperty(e,a,t.style.getPropertyPriority(e)),!0}return!1}async function It(e,t){await S("background",e,t)||await S("background-image",e,t),await S("mask",e,t)||await S("-webkit-mask",e,t)||await S("mask-image",e,t)||await S("-webkit-mask-image",e,t)}async function $t(e,t){const s=h(e,HTMLImageElement);if(!(s&&!H(e.src))&&!(h(e,SVGImageElement)&&!H(e.href.baseVal)))return;const r=s?e.src:e.href.baseVal,i=await W(r,O(r),t);await new Promise((a,l)=>{e.onload=a,e.onerror=t.onImageErrorHandler?(...o)=>{try{a(t.onImageErrorHandler(...o))}catch(d){l(d)}}:l;const c=e;c.decode&&(c.decode=a),c.loading==="lazy"&&(c.loading="eager"),s?(e.srcset="",e.src=i):e.href.baseVal=i})}async function Lt(e,t){const r=w(e.childNodes).map(i=>pe(i,t));await Promise.all(r).then(()=>e)}async function pe(e,t){h(e,Element)&&(await It(e,t),await $t(e,t),await Lt(e,t))}function Ft(e,t){const{style:s}=e;t.backgroundColor&&(s.backgroundColor=t.backgroundColor),t.width&&(s.width=`${t.width}px`),t.height&&(s.height=`${t.height}px`);const r=t.style;return r!=null&&Object.keys(r).forEach(i=>{s[i]=r[i]}),e}const ae={};async function ie(e){let t=ae[e];if(t!=null)return t;const r=await(await fetch(e)).text();return t={url:e,cssText:r},ae[e]=t,t}async function le(e,t){let s=e.cssText;const r=/url\(["']?([^"')]+)["']?\)/g,a=(s.match(/url\([^)]+\)/g)||[]).map(async l=>{let c=l.replace(r,"$1");return c.startsWith("https://")||(c=new URL(c,e.url).href),me(c,t.fetchRequestInit,({result:o})=>(s=s.replace(l,`url(${o})`),[l,o]))});return Promise.all(a).then(()=>s)}function ce(e){if(e==null)return[];const t=[],s=/(\/\*[\s\S]*?\*\/)/gi;let r=e.replace(s,"");const i=new RegExp("((@.*?keyframes [\\s\\S]*?){([\\s\\S]*?}\\s*?)}
1)","gi");for(;;){const o=i.exec(r);if(o===null)break;t.push(o[0])}r=r.replace(i,"");const a=/@import[\s\S]*?url\([^)]*\)[\s\S]*?;/gi,l="((\\s*?(?:\\/\\*[\\s\\S]*?\\*\\/)?\\s*?@media[\\s\\S]*?){([\\s\\S]*?)}\\s*?})|(([\\s\\S]*?){([\\s\\S]*?)})",c=new RegExp(l,"gi");for(;;){let o=a.exec(r);if(o===null){if(o=c.exec(r),o===null)break;a.lastIndex=c.lastIndex}else c.lastIndex=a.lastIndex;t.push(o[0])}return t}async function Dt(e,t){const s=[],r=[];return e.forEach(i=>{if("cssRules"in i)try{w(i.cssRules||[]).forEach((a,l)=>{if(a.type===CSSRule.IMPORT_RULE){let c=l+1;const o=a.href,d=ie(o).then(x=>le(x,t)).then(x=>ce(x).forEach(y=>{try{i.insertRule(y,y.startsWith("@import")?c+=1:i.cssRules.length)}catch(P){console.error("Error inserting rule from remote css",{rule:y,error:P})}})).catch(x=>{console.error("Error loading remote css",x.toString())});r.push(d)}})}catch(a){const l=e.find(c=>c.href==null)||document.styleSheets[0];i.href!=null&&r.push(ie(i.href).then(c=>le(c,t)).then(c=>ce(c).forEach(o=>{l.insertRule(o,l.cssRules.length)})).catch(c=>{console.error("Error loading remote stylesheet",c)})),console.error("Error inlining remote css file",a)}}),Promise.all(r).then(()=>(e.forEach(i=>{if("cssRules"in i)try{w(i.cssRules||[]).forEach(a=>{s.push(a)})}catch(a){console.error(`Error while reading CSS rules from ${i.href}`,a)}}),s))}function Mt(e){return e.filter(t=>t.type===CSSRule.FONT_FACE_RULE).filter(t=>xe(t.style.getPropertyValue("src")))}async function At(e,t){if(e.ownerDocument==null)throw new Error("Provided element is not within a Document");const s=w(e.ownerDocument.styleSheets),r=await Dt(s,t);return Mt(r)}function we(e){return e.trim().replace(/["']/g,"")}function Ut(e){const t=new Set;function s(r){(r.style.fontFamily||getComputedStyle(r).fontFamily).split(",").forEach(a=>{t.add(we(a))}),Array.from(r.children).forEach(a=>{a instanceof HTMLElement&&s(a)})}return s(e),t}async function Ht(e,t){const s=await At(e,t),r=Ut(e);return(await Promise.all(s.filter(a=>r.has(we(a.style.fontFamily))).map(a=>{const l=a.parentStyleSheet?a.parentStyleSheet.href:null;return ge(a.cssText,l,t)}))).join(` 2`)}async function Vt(e,t){const s=t.fontEmbedCSS!=null?t.fontEmbedCSS:t.skipFonts?null:await Ht(e,t);if(s){const r=document.createElement("style"),i=document.createTextNode(s);r.appendChild(i),e.firstChild?e.insertBefore(r,e.firstChild):e.appendChild(r)}}async function Ot(e,t={}){const{width:s,height:r}=de(e,t),i=await _(e,t,!0);return await Vt(i,t),await pe(i,t),Ft(i,t),await at(i,s,r)}async function Wt(e,t={}){const{width:s,height:r}=de(e,t),i=await Ot(e,t),a=await E(i),l=document.createElement("canvas"),c=l.getContext("2d"),o=t.pixelRatio||st(),d=t.canvasWidth||s,x=t.canvasHeight||r;return l.width=d*o,l.height=x*o,t.skipAutoScale||rt(l),l.style.width=`${d}`,l.style.height=`${x}`,t.backgroundColor&&(c.fillStyle=t.backgroundColor,c.fillRect(0,0,l.width,l.height)),c.drawImage(a,0,0,l.width,l.height),l}async function zt(e,t={}){return(await Wt(e,t)).toDataURL()}function Jt(){const{user:e,profile:t}=Fe(),s=Pe(),[r,i]=m.useState(null),[a,l]=m.useState({points:0,miles:0,totalKm:0}),[c,o]=m.useState(""),[d,x]=m.useState(null),[y,P]=m.useState(!1),[z,ye]=m.useState(!1),[q,be]=m.useState([]),[je,Se]=m.useState(!1),[ve,B]=m.useState(!1),[G,Q]=m.useState(!1),T=m.useRef(null),Y=async()=>{if(e){Q(!0);try{const{data:u,error:p}=await b.functions.invoke("id-card-token");if(p)throw p;i(u.token),u.member_number&&o(u.member_number)}catch(u){D({title:"Couldn't refresh ID",description:u.message,variant:"destructive"})}finally{Q(!1)}}};m.useEffect(()=>{e&&((async()=>{const[{data:u},{data:p},{data:Re},{data:Ce},{data:Ee}]=await Promise.all([b.from("profiles").select("member_number, created_at, looking_for_buddy_until").eq("id",e.id).maybeSingle(),b.from("loyalty_points").select("delta").eq("user_id",e.id),b.from("runs").select("distance_km").eq("user_id",e.id),b.from("memberships").select("status, expires_at").eq("user_id",e.id).eq("status","active").maybeSingle(),b.from("id_card_scans").select("*").eq("member_id",e.id).order("created_at",{ascending:!1}).limit(8)]),_e=(p??[]).reduce(($,L)=>$+(L.delta??0),0),K=(Re??[]).reduce(($,L)=>$+Number(L.distance_km??0),0);l({points:_e,totalKm:K,miles:K*.621371}),o((u==null?void 0:u.member_number)??""),x((u==null?void 0:u.created_at)??null),P(!!(u!=null&&u.looking_for_buddy_until)&&new Date(u.looking_for_buddy_until)>new Date),ye(!!Ce),be(Ee??[])})(),Y())},[e]);const v=Ye(a.points).name,k=oe(v),N=m.useMemo(()=>
2{if(r)return`${window.location.origin}/v/${r}`},[r]),I=m.useMemo(()=>t?{display_name:t.display_name,handle:t.handle,avatar_url:t.avatar_url,member_number:c||"WDR-ââââ",city:t.city,member_since:d,tier:v,points:a.points,miles:a.miles,is_active_member:z,looking_for_buddy:y}:null,[t,c,d,v,a,z,y]),Ne=async()=>{if(T.current)try{const u=await zt(T.current,{pixelRatio:3,cacheBust:!0}),p=document.createElement("a");p.href=u,p.download=`wedorunning-id-${c||"card"}.png`,p.click()}catch(u){D({title:"Download failed",description:u.message,variant:"destructive"})}},ke=async()=>{if(!N)return;const u={title:"My wedorunning ID",text:`I'm a ${v} on wedorunning. Scan to connect with me!`,url:N};if(navigator.share)try{await navigator.share(u)}catch{}else await navigator.clipboard.writeText(N),D({title:"Link copied",description:"Share it with a buddy."})};return e?I?ve?n.jsxs("div",{className:"fixed inset-0 z-50 bg-foreground flex flex-col items-center justify-center p-4 gap-6",children:[n.jsx("div",{className:"w-full max-w-[360px]",children:n.jsx(te,{data:I,qrValue:N,highContrastQr:!0,className:"w-full max-w-none"})}),n.jsxs("p",{className:"text-background/80 text-sm flex items-center gap-2",children:[n.jsx(Oe,{className:"h-4 w-4"})," Show this to the cashier â ",k,"% off"]}),n.jsx(g,{variant:"secondary",className:"rounded-full",onClick:()=>B(!1),children:"Done"})]}):n.jsxs("div",{className:"container py-8 sm:py-12 max-w-3xl",children:[n.jsxs("div",{className:"text-center mb-6",children:[n.jsxs("span",{className:"inline-flex items-center gap-2 px-3 py-1.5 rounded-full bg-primary/15 text-primary-deep text-xs font-semibold mb-3",children:[n.jsx(J,{className:"h-3.5 w-3.5"})," Member ID Card"]}),n.jsx("h1",{className:"text-3xl sm:text-4xl font-extrabold mb-1",children:"Your running passport"}),n.jsxs("p",{className:"text-muted-foreground text-sm sm:text-base",children:["Tap to flip · Scan at retailers for ",k,"% off · Show at meetups"]})]}),n.jsx("div",{className:"flex justify-center mb-6 [perspective:1500px]",children:n.jsxs("div",{className:"relative w-full max-w-[360px] aspect-[3/4] cursor-pointer transition-transform duration-700 [transform-style:preserve-3d]",style:{transform:je?"rotateY(180deg)":"none"},onClick:()=>Se(u=>!u),children:[n.jsx("div",{className:"absolute inset-0 [backface-visibility:hidden]",ref:T,children:n.jsx(te,{data:I,qrValue:N,className:"w-full max-w-none h-full"})}),n.jsx("div",{className:"absolute inset-0 [transform:rotateY(180deg)] [backface-visibility:hidden] rounded-3xl bg-gradient-to-br from-primary-deep to-foreground text-primary-foreground p-5 sm:p-6 shadow-2xl",children:n.jsxs("div",{className:"h-full flex flex-col",children:[n.jsxs("div",{className:"flex items-center justify-between mb-3",children:[n.jsx("p",{className:"text-xs uppercase tracking-widest opacity-80",children:"How to use"}),n.jsx(We,{className:"h-4 w-4 opacity-60"})]}),n.jsxs("ul",{className:"space-y-2 text-sm flex-1",children:[n.jsxs("li",{className:"flex gap-2",children:[n.jsx(Z,{className:"h-4 w-4 mt-0.5 shrink-0 text-accent"})," ",k,"% off at partner retailers â show your QR at checkout"]}),n.jsxs("li",{className:"flex gap-2",children:[n.jsx(M,{className:"h-4 w-4 mt-0.5 shrink-0 text-accent"})," Scan another runner's QR at meetups to connect instantly"]}),n.jsxs("li",{className:"flex gap-2",children:[n.jsx(J,{className:"h-4 w-4 mt-0.5 shrink-0 text-accent"})," QR rotates every 15 min â screenshots can't be reused for long"]}),n.jsxs("li",{className:"flex gap-2",children:[n.jsx(V,{className:"h-4 w-4 mt-0.5 shrink-0 text-accent"})," Earn miles & points to climb tiers and unlock bigger discounts"]})]}),n.jsx("div",{className:"text-[10px] opacity-70 mt-3",children:"Lost your phone? Visit Settings â ID card to revoke and reissue."})]})})]})}),n.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-2 mb-8",children:[n.jsxs(g,{onClick:()=>B(!0),className:"rounded-full h-11",size:"sm",children:[n.jsx(ze,{className:"h-4 w-4 mr-1.5"})," Present"]}),n.jsxs(g,{onClick:()=>
2s("/scan"),variant:"secondary",className:"rounded-full h-11",size:"sm",children:[n.jsx(M,{className:"h-4 w-4 mr-1.5"})," Scan"]}),n.jsxs(g,{onClick:ke,variant:"secondary",className:"rounded-full h-11",size:"sm",children:[n.jsx(qe,{className:"h-4 w-4 mr-1.5"})," Share"]}),n.jsxs(g,{onClick:Ne,variant:"outline",className:"rounded-full h-11",size:"sm",children:[n.jsx(Be,{className:"h-4 w-4 mr-1.5"})," PNG"]})]}),n.jsxs(F,{className:"p-5 rounded-2xl mb-6 flex items-center gap-4 flex-wrap",children:[n.jsx("div",{className:"h-11 w-11 rounded-full bg-foreground text-background flex items-center justify-center shrink-0",children:n.jsx(Ge,{className:"h-5 w-5"})}),n.jsxs("div",{className:"flex-1 min-w-[200px]",children:[n.jsx("p",{className:"font-semibold",children:"Add to your phone wallet"}),n.jsx("p",{className:"text-sm text-muted-foreground",children:"Apple Wallet & Google Wallet support is coming soon. For now, save the PNG to your photos and add it as a Wallet pass via Shortcuts."})]}),n.jsx(g,{variant:"outline",className:"rounded-full",disabled:!0,children:"Coming soon"})]}),n.jsxs(F,{className:"p-5 rounded-2xl mb-6",children:[n.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[n.jsx(Z,{className:"h-4 w-4 text-primary-deep"}),n.jsx("h2",{className:"font-bold",children:"Your retailer discount"})]}),n.jsxs("p",{className:"text-3xl font-extrabold text-primary-deep mb-1",children:[k,"% off"]}),n.jsxs("p",{className:"text-sm text-muted-foreground",children:["You're a ",n.jsx("strong",{className:"text-foreground",children:v}),". Climb to the next tier to unlock more."]}),n.jsx(g,{asChild:!0,variant:"link",className:"px-0 h-auto mt-1 text-primary-deep",children:n.jsx(X,{to:"/loyalty",children:"See all tiers â"})})]}),n.jsxs("div",{className:"flex items-center justify-between text-xs text-muted-foreground mb-6",children:[n.jsx("span",{children:"QR refreshes automatically"}),n.jsxs(g,{variant:"ghost",size:"sm",onClick:Y,disabled:G,children:[n.jsx(Qe,{className:`h-3.5 w-3.5 mr-1 ${G?"animate-spin":""}`})," Refresh now"]})]}),n.jsxs(F,{className:"p-5 rounded-2xl",children:[n.jsxs("h2",{className:"font-bold mb-3 flex items-center gap-2",children:[n.jsx(M,{className:"h-4 w-4 text-primary-deep"})," Recent scans"]}),q.length===0?n.jsx("p",{className:"text-sm text-muted-foreground",children:"No-one's scanned your card yet. Show it at a meetup or partner store."}):n.jsx("ul",{className:"divide-y divide-border",children:q.map(u=>n.jsx("li",{className:"py-2.5 flex items-center justify-between text-sm",children:n.jsxs("div",{children:[n.jsxs("p",{className:"font-medium capitalize",children:[u.scan_type,u.retailer_name?` · ${u.retailer_name}`:""]}),n.jsx("p",{className:"text-xs text-muted-foreground",children:new Date(u.created_at).toLocaleString()})]})},u.id))})]})]}):n.jsx("div",{className:"container py-20 text-center text-muted-foreground",children:"Loading your cardâ¦"}):n.jsxs("div",{className:"container py-20 text-center",children:[n.jsx("h1",{className:"text-2xl font-bold mb-2",children:"Your ID card"}),n.jsx("p",{className:"text-muted-foreground mb-4",children:"Sign in to see your card."}),n.jsx(g,{asChild:!0,className:"rounded-full",children:n.jsx(X,{to:"/auth",children:"Sign in"})})]})}export{Jt 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.