1import{e as v,j as e}from"./vendor-react-C-tLJ3C8.js";import{d as E,c as N,b as k}from"./vendor-query-4BWL3uTy.js";import{p as R,g as F,h as T}from"./motion-BZ9X7-6B.js";import{v as P,ag as q,T as G,j as f}from"./index-DxoJEjRy.js";import{C as b}from"./Card-CD2rnSRu.js";import{B as H}from"./Badge-p3wyzqIi.js";import{B as h}from"./Button-Bj9BQB0O.js";import{I as y}from"./Input-BFzIVhaK.js";import{E as M}from"./EmptyState-Cgfuzv8-.js";import{L as C}from"./PageSkeletons-1YJNe-aZ.js";import{d as S}from"./apiError-Ck35BOpz.js";import{m as j}from"./vendor-motion-Dx4K3zup.js";import{G as I}from"./gift-Bl-GtY-p.js";import{S as A}from"./send-Bv5jd1NK.js";import{S as z}from"./sparkles-BC7WYZcl.js";import{C as B}from"./check-DAJrOQX0.js";import{C as Q}from"./copy-BSmz_6k4.js";import"./loader-circle-DOgBBCoV.js";import"./Skeleton-BbEO0Yrx.js";/** 2 * @license lucide-react v0.378.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const X=P("Ticket",[["path",{d:"M2 9a3 3 0 0 1 0 6v2a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-2a3 3 0 0 1 0-6V7a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2Z",key:"qn84l0"}],["path",{d:"M13 5v2",key:"dyzc3o"}],["path",{d:"M13 17v2",key:"1ont0d"}],["path",{d:"M13 11v2",key:"1wjjxi"}]]),D={unfunded:{variant:"warning",label:"Unfunded"},pending:{variant:"primary",label:"Ready to redeem"},redeemed:{variant:"success",label:"Redeemed"},expired:{variant:"muted",label:"Expired"},revoked:{variant:"danger",label:"Revoked"}};function K(t){return`â¦${(t/100).toLocaleString("en-NG")}`}function L(t){if(!t)return null;const n=new Date(t);return Number.isNaN(n.getTime())?null:n.toLocaleDateString()}function U(t){return t.split("_").map((n,d)=>d===0?n[0].toUpperCase()+n.slice(1):n).join(" ")}function pe(){var g,w;const{toast:t}=q(),n=E(),d=N({queryKey:["plans"],queryFn:async()=>{var s;return(((s=(await f.get("/subscriptions/plans")).data)==null?void 0:s.data)??[]).filter(l=>l.amount>0)},staleTime:60*60*1e3}),i=N({queryKey:["my-gifts"],queryFn:async()=>{var s;const r=(s=(await f.get("/gift-codes/mine")).data)==null?void 0:s.data;return Array.isArray(r)?r:(r==null?void 0:r.items)??[]}}),[o,c]=v.useState({planId:"",recipientHint:"",note:""}),m=k({mutationFn:async a=>{var s;return(s=(await f.post("/subscriptions/gift",{planId:a.planId,recipientHint:a.recipientHint||void 0,note:a.note||void 0})).data)==null?void 0:s.data},onSuccess:a=>{t("success","Opening payment â complete checkout in the new tab. Your gift will appear below once it clears."),window.open(a.paymentUrl,"_blank","noopener,noreferrer"),n.invalidateQueries({queryKey:["my-gifts"]}),c({planId:"",recipientHint:"",note:""})},onError:a=>{var s,l;const r=((l=(s=a==null?void 0:a.response)==null?void 0:s.data)==null?void 0:l.message)||"Couldn't initialize payment. Try again.";t("error",`Payment failed to start: ${r}`)}}),[p,u]=v.useState(""),x=k({mutationFn:async a=>{var s;return(s=(await f.post("/gift-codes/redeem",{code:a})).data)==null?void 0:s.data},onSuccess:a=>{t("success",`Gift redeemed â plan ${a.planId} unlocked. Refresh the app if your tier hasn't updated yet.`),u(""),n.invalidateQueries({queryKey:["my-gifts"]}),n.invalidateQueries({queryKey:["me"]})},onError:a=>{var s,l;const r=((l=(s=a==null?void 0:a.response)==null?void 0:s.data)==null?void 0:l.message)||"Couldn't redeem this code.";t("error",`Redeem failed: ${r}`)}});return e.jsxs(j.div,{variants:R,initial:"initial",animate:"animate",exit:"exit",className:"mx-auto w-full max-w-4xl px-4 py-6 sm:px-6",children:[e.jsxs("div",{className:"mb-6 flex items-center gap-3",children:[e.jsx("div",{className:"flex h-11 w-11 shrink-0 items-center justify-center rounded-xl bg-primary-50 dark:bg-primary-900/20",children:e.jsx(I,{className:"h-5 w-5 text-primary-700 dark:text-primary-300","aria-hidden":"true"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-gray-900 dark:text-white",children:"Gifts"}),e.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:"Buy a plan for a friend, or redeem a code someone gave you."})]})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-4 lg:grid-cols-2",children:[e.jsxs(b,{variant:"default",padding:"md",children:[e.jsxs("div",{className:"mb-4 flex items-center gap-2",children:[e.jsx(A,{className:"h-4 w-4 text-primary-700","aria-hidden":"true"}),e.jsx("h2",{className:"text-base font-semibold text-gray-900 dark:text-white",children:"Send a gift"})]}),d.isLoading&&e.jsx(C,{rows:3,rowHeight:"h-11",label:"Loading plans"}),d.isError&&e.jsxs("div",{role:"alert",className:"flex flex-wrap items-center gap-3",children:[e.jsx("p",{className:"text-sm text-red-600 dark:text-red-400",children:S(d.error,"Couldn't load plans.")}
6),e.jsx(h,{variant:"secondary",size:"sm",loading:d.isFetching,onClick:()=>void d.refetch(),children:"Retry"})]}),d.data&&e.jsxs("form",{className:"space-y-3",onSubmit:a=>{if(a.preventDefault(),!o.planId){t("error","Pick a plan first");return}m.mutate(o)},children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"gift-plan",className:"mb-1.5 block text-xs font-medium text-gray-700 dark:text-gray-300",children:"Plan"}),e.jsxs("select",{id:"gift-plan",value:o.planId,onChange:a=>c(r=>({...r,planId:a.target.value})),className:"w-full rounded-md border border-gray-300 bg-white px-3 py-2 text-sm shadow-sm focus:border-primary-500 focus:outline-none focus:ring-1 focus:ring-primary-500 dark:border-gray-700 dark:bg-dark-card dark:text-white",required:!0,children:[e.jsx("option",{value:"",children:"Choose a plan"}),d.data.map(a=>e.jsxs("option",{value:a.id,children:[a.name," â ",K(a.amount)]},a.id))]})]}),e.jsx(y,{label:"Recipient hint (optional)",placeholder:"e.g. For Tunde â JAMB 2026",value:o.recipientHint,onChange:a=>c(r=>({...r,recipientHint:a.target.value})),hint:"Shown only to you in your gift list. The code itself is what the recipient redeems.",maxLength:200}),e.jsx(y,{label:"Note (optional)",placeholder:"A short message you'll remember",value:o.note,onChange:a=>c(r=>({...r,note:a.target.value})),maxLength:2e3}),e.jsx(h,{type:"submit",variant:"primary",size:"md",disabled:m.isPending||!o.planId,className:"w-full",children:m.isPending?"Opening checkoutâ¦":"Pay & generate code"}),e.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:"Payment opens in a new tab. Once it clears, the code appears below ready to share."})]})]}),e.jsxs(b,{variant:"default",padding:"md",children:[e.jsxs("div",{className:"mb-4 flex items-center gap-2",children:[e.jsx(X,{className:"h-4 w-4 text-emerald-700","aria-hidden":"true"}),e.jsx("h2",{className:"text-base font-semibold text-gray-900 dark:text-white",children:"Redeem a code"})]}),e.jsxs("form",{className:"space-y-3",onSubmit:a=>{a.preventDefault();const r=p.trim().toUpperCase();if(r.length<6){t("error","Code must be at least 6 characters");return}x.mutate(r)},children:[e.jsx(y,{label:"Gift code",placeholder:"EXAM-XXXXXX",value:p,onChange:a=>u(a.target.value),hint:"Paste the code your friend sent you. We'll handle the upgrade.",autoComplete:"off",maxLength:20,required:!0}),e.jsx(h,{type:"submit",variant:"primary",size:"md",disabled:x.isPending||p.trim().length<6,className:"w-full",children:x.isPending?"Redeemingâ¦":"Redeem"}),e.jsxs("div",{className:"flex items-start gap-2 rounded-md border border-amber-200 bg-amber-50 p-3 text-xs text-amber-900 dark:border-amber-800 dark:bg-amber-900/20 dark:text-amber-200",children:[e.jsx(G,{className:"mt-0.5 h-3.5 w-3.5 shrink-0","aria-hidden":"true"}),e.jsx("span",{children:"Codes are case-insensitive. Each code can only be redeemed once, and not by the original sender."})]})]})]})]}),e.jsxs("div",{className:"mt-6",children:[e.jsxs("div",{className:"mb-3 flex items-center gap-2",children:[e.jsx(z,{className:"h-4 w-4 text-primary-700","aria-hidden":"true"}),e.jsx("h2",{className:"text-base font-semibold text-gray-900 dark:text-white",children:"My gifts"})]}),i.isLoading&&e.jsx(C,{rows:2,rowHeight:"h-16",label:"Loading your gifts"}),i.isError&&e.jsxs("div",{role:"alert",className:"flex flex-wrap items-center gap-3",children:[e.jsx("p",{className:"text-sm text-red-600 dark:text-red-400",children:S(i.error,"Couldn't load your gifts.")}),e.jsx(h,{variant:"secondary",size:"sm",loading:i.isFetching,onClick:()=>void i.refetch(),children:"Retry"})]}),!i.isLoading&&!i.isError&&(((g=i.data)==null?void 0:g.length)??0)===0&&e.jsx(M,{icon:I,title:"No gifts yet",description:"Gifts you've sent will appear here once payment clears."}),!i.isLoading&&!i.isError&&(((w=i.data)==null?void 0:w.length)??0)>0&&e.jsx(j.div,{variants:F,initial:"initial",animate:"animate",className:"space-y-2",children:i.data.map(a=>e.jsx(j.div,{variants:T,children:e.jsx($,{gift:a,plans:d.data??[]})},a.id))})]})]})}function $({gift:t,plans:n}){var x;const[d,i]=v.useState(!1),o=D[t.status],c=((x=n.find(g=>g.id===t.planId))==null?void 0:x.name)??U(t.planId),m=L(t.expiresAt),p=L(t.redeemedAt),u=t.status==="pending";return e.jsx(b,{variant:"default",padding:"md",children:e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 flex-col gap-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"rounded-md bg-gray-100 px-2 py-1 font-mono text-sm font-semibold tracking-wider text-gray-900 dark:bg-gray-800 dark:text-white",children:u?t.code:"â¢â¢â¢â¢â¢â¢â¢"}),e.jsx(H,{variant:o.variant,size:"sm",children:o.label})]}),e.jsxs("div",{className:"flex flex-wrap gap-x-3 gap-y-0.5 text-xs text-gray-500 dark:text-gray-400",children:[e.jsx("span",{children:c}),t.recipientHint&&e.jsxs("span",{children:["For: ",t.recipientHint]}),m&&e.jsxs("span",{children:["Expires ",m]}),p&&e.jsxs("span",{children:["Redeemed ",p]})]})]}),u&&e.jsx(h,{variant:"secondary",size:"sm",onClick:()=>{navigator.clipboard.writeText(t.code).then(()=>{i(!0),setTimeout(()=>i(!1),1500)}).catch(()=>{})},children:d?e.jsxs(e.Fragment,{children:[e.jsx(B,{className:"mr-1.5 h-3.5 w-3.5","aria-hidden":"true"}),"Copied"]}):e.jsxs(e.Fragment,{children:[e.jsx(Q,{className:"mr-1.5 h-3.5 w-3.5","aria-hidden":"true"}),"Copy"]})})]})})}export{pe 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.