1import{aL as $,a as C,aM as P,r as a,s as W,j as e,N as x,L as R,m as F,T as G,X as K}from"./index-BxjVRxRT.js";import{b as B,u as O}from"./cards.functions-BQouObSo.js";import{A as X}from"./arrow-left-BtCDvX6z.js";import{C as _}from"./circle-check-CSgZ-ZEK.js";import{S as q}from"./smartphone-B5D8sKOh.js";function ee(){const{nation:w}=$.useParams(),Y=C(P),p=C(B),D=C(O),[n,t]=a.useState("idle"),[v,c]=a.useState(""),[b,g]=a.useState(""),[f,h]=a.useState(""),[N,i]=a.useState(null),[m,u]=a.useState([]),[I,M]=a.useState(null),[j,L]=a.useState(""),[l,E]=a.useState(!1),y=a.useRef(null);a.useEffect(()=>{W.auth.getUser().then(({data:s})=>{const r=!!s.user;M(r),r&&p().then(u).catch(()=>{})})},[p]);const S=typeof window<"u"&&"NDEFReader"in window,k=()=>{y.current?.abort(),y.current=null},T=async()=>{if(i(null),c(""),!window.NDEFReader){t("unsupported");return}try{t("permission");const s=new window.NDEFReader,r=new AbortController;y.current=r,await s.scan({signal:r.signal}),t("scanning"),s.addEventListener("reading",d=>{const z=(d.serialNumber??"").replace(/[^0-9a-fA-F]/g,"").toLowerCase();if(!z){i("Card detected, but no UID was readable."),t("error");return}c(z),t("got-uid"),k()}),s.addEventListener("readingerror",()=>{i("Couldn't read the card."),t("error")})}catch(s){const r=s.message??String(s);/permission|notallowed/i.test(r)?(t("denied"),i("NFC permission denied.")):(t("error"),i(r))}};a.useEffect(()=>()=>k(),[]);const A=async()=>{const s=(v||j).replace(/[^0-9a-fA-F]/g,"").toLowerCase();if(!s)return;const r=f.trim();if(!/^\d{4}[\/-]\d{2}$/.test(r)){i("Enter expiration as YYYY/MM (e.g. 2027/06).");return}E(!0),i(null);try{const{card:d}=await Y({data:{uid:s,expires_at:r,label:b.trim()||void 0}}),o=await p().catch(()=>null);o&&u(o),c(""),g(""),L(""),h(""),t("idle")}catch(d){i(d.message)}finally{E(!1)}},U=async s=>{if(!confirm(`Unlink "${s.label??s.uid}"?`))return;const r=m;u(d=>d.filter(o=>o.id!==s.id));try{await D({data:{id:s.id}})}catch(d){u(r),alert(d.message)}};return I===!1?e.jsxs("div",{className:"min-h-screen bg-background text-foreground flex flex-col items-center justify-center p-6 text-center",children:[e.jsx(x,{className:"size-10 text-muted-foreground"}),e.jsx("h1",{className:"mt-3 font-semibold",children:"Sign in to link a card"}),e.jsx(R,{to:"/login",search:{redirect:`/${w}/wallet/link-card`},className:"mt-5 h-11 px-8 rounded-lg bg-primary text-primary-foreground text-sm font-bold tracking-widest inline-flex items-center",children:"SIGN IN"})]}):e.jsxs("div",{className:"min-h-screen bg-background text-foreground",children:[e.jsxs("header",{className:"sticky top-0 z-10 bg-background/95 backdrop-blur border-b border-border px-4 py-3 flex items-center gap-3",children:[e.jsx(R,{to:"/$nation/wallet",params:{nation:w},className:"rounded-full p-2 hover:bg-secondary","aria-label":"Back",children:e.jsx(X,{className:"size-5"})}),e.jsx("h1",{className:"text-base font-bold tracking-tight",children:"Tap-to-pay cards"})]}),e.jsxs("main",{className:"max-w-md mx-auto px-4 py-6 space-y-6",children:[e.jsxs("section",{className:"rounded-2xl border border-border bg-card p-5",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"size-10 rounded-full bg-primary/10 border border-primary/30 flex items-center justify-center",children:e.jsx(x,{className:"size-5 text-primary"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"font-semibold",children:"Link a new card"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Tap an NFC card to the back of this phone."})]})]}),n==="idle"&&e.jsx("button",{onClick:T,disabled:!S,className:"mt-4 w-full h-12 rounded-lg bg-primary text-primary-foreground text-sm font-bold tracking-widest hover:bg-primary/90 disabled:opacity-40",children:S?"START SCANNING":"NFC NOT SUPPORTED"}),(n==="permission"||n==="scanning")&&e.jsxs("div",{className:"mt-4 rounded-lg border border-dashed border-primary/40 bg-primary/5 p-5 text-center",children:[e.jsx("div",{className:"mx-auto size-16 rounded-full bg-primary/15 flex items-center justify-center animate-pulse",children:e.jsx(x,{className:"size-8 text-primary"})}),e.jsx("p",{className:"mt-3 text-sm font-semibold",children:n==="permission"?"Allow NFC accessâ¦":"Waiting for tapâ¦"}),e.jsx("button",{onClick:()=>{k(),t("idle")},className:"mt-3 text-[10px] font-bold tracking-widest text-muted-foreground",children:"CANCEL"})]}),n==="got-uid"&&e.jsxs("div",{className:"mt-4 space-y-3",children:[e.jsxs("div",{className:"rounded-lg border border-primary/40 bg-primary/5 p-4 flex items-start gap-3",children:[e.jsx(_,{className:"size-5 text-primary shrink-0 mt-0.5"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-xs font-bold tracking-widest text-primary",children:"CARD DETECTED"}),e.jsx("p",{className:"mt-1 font-mono text-sm break-all",children:v})]})]}),e.jsx("input",{value:b,onChange:s=>g(s.target.value),placeholder:"Label (optional)",className:"w-full rounded-lg border border-border bg-background px-3 py-2.5 text-sm",maxLength:64}),e.jsx("input",{value:f,onChange:s=>h(s.target.value),placeholder:"Expiration YYYY/MM",inputMode:"numeric",className:"w-full rounded-lg border border-border bg-background px-3 py-2.5 text-sm",maxLength:7}),N&&e.jsx("p",{className:"text-xs text-destructive",children:N}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx("button",{onClick:()=>{t("idle"),c(""),i(null)},disabled:l,className:"h-11 rounded-lg border border-border text-xs font-bold tracking-widest disabled:opacity-40",children:"CANCEL"}),e.jsxs("button",{onClick:A,disabled:l,className:"h-11 rounded-lg bg-primary text-primary-foreground text-xs font-bold tracking-widest disabled:opacity-40 inline-flex items-center justify-center gap-2",children:[l&&e.jsx(F,{className:"size-3.5 animate-spin"})," LINK CARD"]})]})]}),(n==="unsupported"||n==="denied"||n==="error")&&e.jsxs("div",{className:"mt-4 rounded-lg border border-amber-500/40 bg-amber-500/5 p-4 flex items-start gap-3",children:[e.jsx(G,{className:"size-5 text-amber-500 shrink-0 mt-0.5"}),e.jsxs("div",{className:"text-xs space-y-2",children:[n==="unsupported"&&e.jsx("p",{className:"text-muted-foreground",children:"Web NFC isn't available here. Use Chrome on Android."}),(n==="denied"||n==="error")&&e.jsx("p",{className:"text-muted-foreground",children:N}),e.jsx("button",{onClick:()=>{t("idle"),i(null)},className:"text-[10px] font-bold tracking-widest",children:"TRY AGAIN"})]})]}),e.jsxs("details",{className:"mt-4",children:[e.jsx("summary",{className:"cursor-pointer text-[11px] font-bold tracking-widest text-muted-foreground",children:"ENTER UID MANUALLY"}),e.jsxs("div",{className:"mt-3 space-y-2",children:[e.jsx("input",{value:j,onChange:s=>L(s.target.value),placeholder:"e.g. 04a1b2c3d4e5f6",className:"w-full rounded-lg border border-border bg-background px-3 py-2.5 font-mono text-sm",maxLength:32}),e.jsx("input",{value:b,onChange:s=>g(s.target.value),placeholder:"Label (optional)",className:"w-full rounded-lg border border-border bg-background px-3 py-2.5 text-sm",maxLength:64}),e.jsx("input",{value:f,onChange:s=>h(s.target.value),placeholder:"Expiration YYYY/MM",inputMode:"numeric",className:"w-full rounded-lg border border-border bg-background px-3 py-2.5 text-sm",maxLength:7}),e.jsxs("button",{onClick:A,disabled:!j.trim()||l,className:"h-10 w-full rounded-lg bg-secondary text-xs font-bold tracking-widest disabled:opacity-40 inline-flex items-center justify-center gap-2",children:[l&&e.jsx(F,{className:"size-3.5 animate-spin"})," LINK CARD"]})]})]})]}),e.jsxs("section",{children:[e.jsxs("h2",{className:"text-xs font-bold tracking-widest text-muted-foreground mb-2",children:["LINKED CARDS · ",m.length]}),m.length===0?e.jsxs("div",{className:"rounded-2xl border border-dashed border-border p-8 text-center",children:[e.jsx(q,{className:"mx-auto
1size-8 text-muted-foreground"}),e.jsx("p",{className:"mt-2 text-sm text-muted-foreground",children:"No cards linked yet."})]}):e.jsx("ul",{className:"space-y-2",children:m.map(s=>e.jsxs("li",{className:"rounded-xl border border-border bg-card p-3 flex items-center gap-3",children:[e.jsx("div",{className:"size-9 rounded-full bg-primary/10 flex items-center justify-center shrink-0",children:e.jsx(x,{className:"size-4 text-primary"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-sm font-semibold truncate",children:s.label??`Card ${s.uid.slice(-6).toUpperCase()}`}),e.jsx("p",{className:"font-mono text-[10px] text-muted-foreground truncate",children:s.uid})]}),e.jsx("button",{onClick:()=>U(s),className:"rounded-full p-1.5 hover:bg-destructive/10 text-muted-foreground hover:text-destructive","aria-label":"Unlink",children:e.jsx(K,{className:"size-4"})})]},s.id))})]})]})]})}export{ee as component};
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.