PageSourceSearch

https://datafuelsupplements.com/assets/Promos-BOeyCz9C.js

js datafuelsupplements.com collected 2026-10-02 01:28:11 UTC 32,637 bytes, 7 lines download raw bytes

1!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._posthogChunkIds=e._posthogChunkIds||{},e._posthogChunkIds[n]="01a086e7-d7e4-71c1-809a-012fb8cacc45")}catch(e){}}();
2!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="7eb173d9-a5c9-5257-b547-0ac16e4f6ec3")}catch(e){}}();
3import{c as ue,u as E,a as j,j as e}from"./query-vendor-Bpmm07UM.js";import{r as m,L as Se}from"./router-vendor-PdvXAmya.js";import{u as xe,a as h}from"./index-B4qsZXfP.js";const le=s=>`€${Number(s||0).toFixed(2)}`;function Ee(){const s=ue(),{toast:o}=xe(),[r,d]=m.useState(""),[_,A]=m.useState(!0),[u,f]=m.useState(!1),{data:p,isLoading:w,isError:L}=E({queryKey:["referral-settings"],queryFn:()=>h.get("/api/owner/referrals/settings")});m.useEffect(()=>{p&&!u&&(d(String(p.reward_eur)),A(p.is_enabled))},[p,u]);const N=j({mutationFn:c=>h.put("/api/owner/referrals/settings",c),onSuccess:()=>{s.invalidateQueries({queryKey:["referral-settings"]}),f(!1),o("Referral settings saved","success")},onError:c=>{o(c instanceof Error?c.message:"Could not save referral settings","error")}}),$=()=>{const c=Number(r);if(Number.isNaN(c)||c<0||c>100){o("Reward must be a number between 0 and 100","error");return}N.mutate({reward_eur:c,is_enabled:_})};return w?e.jsx("div",{className:"rounded-2xl border border-surface-border bg-[#111] p-6",children:e.jsx("div",{className:"h-5 w-48 animate-pulse rounded bg-surface-border"})}):L||!p?e.jsx("div",{className:"rounded-2xl border border-surface-border bg-[#111] p-6 text-sm text-neutral-400",children:"Couldn't load referral program settings."}):e.jsxs("div",{className:"rounded-2xl border border-surface-border bg-[#111] p-6",children:[e.jsxs("div",{className:"flex flex-col gap-1 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-bold text-white",children:"Referral program"}),e.jsx("p",{className:"mt-1 text-sm text-neutral-400",children:"Both the new customer and the referrer get this amount off a BASE box. Changes apply only to credits issued afterwards."})]}),e.jsxs("span",{className:`inline-flex w-fit items-center gap-2 rounded-full px-3 py-1 text-xs font-medium ${p.is_enabled?"bg-green-500/10 text-green-400":"bg-neutral-500/10 text-neutral-400"}`,children:[e.jsx("span",{className:`h-2 w-2 rounded-full ${p.is_enabled?"bg-green-500":"bg-neutral-500"}`}),p.is_enabled?"Active":"Paused"]})]}),e.jsxs("div",{className:"mt-5 flex flex-col gap-4 sm:flex-row sm:items-end",children:[e.jsxs("div",{className:"sm:w-48",children:[e.jsx("label",{htmlFor:"referral_reward",className:"mb-1.5 block text-sm font-medium text-neutral-300",children:"Reward per side (EUR)"}),e.jsx("input",{id:"referral_reward",type:"number",min:0,max:100,step:"0.01",inputMode:"decimal",value:r,onChange:c=>{d(c.target.value),f(!0)},className:"w-full rounded-xl border border-surface-border bg-surface-raised px-4 py-2.5 text-base sm:text-sm text-white placeholder:text-neutral-600 focus:border-brand focus:outline-none focus:ring-1 focus:ring-brand/30"})]}),e.jsxs("label",{className:"flex cursor-pointer items-center gap-2 py-2.5 text-sm text-neutral-300",children:[e.jsx("input",{type:"checkbox",checked:_,onChange:c=>{A(c.target.checked),f(!0)},className:"h-4 w-4 rounded border-surface-border bg-surface-raised accent-brand"}),"Program enabled (new sign-ups can use a code)"]}),e.jsx("button",{type:"button",onClick:$,disabled:N.isPending||!u,className:"rounded-full bg-brand px-6 py-2.5 text-sm font-semibold text-white transition hover:bg-[#e66e00] disabled:opacity-50 active:scale-[0.98] sm:w-auto",children:N.isPending?"Saving…":"Save"})]}),e.jsxs("div",{className:"mt-6 grid grid-cols-2 gap-3 sm:grid-cols-5",children:[e.jsx(D,{label:"Invited",value:String(p.stats.total_referrals)}),e.jsx(D,{label:"Joined",value:String(p.stats.total_converted)}),e.jsx(D,{label:"Pending",value:String(p.stats.pending_referrals)}),e.jsx(D,{label:"Credit outstanding",value:le(p.stats.credits_outstanding_eur),accent:!0}),e.jsx(D,{label:"Credit redeemed",value:le(p.stats.credits_redeemed_eur)})]})]})}function D({label:s,value:o,accent:r}){return e.jsxs("div",{className:"rounded-xl border border-surface-border bg-surface-raised p-3 text-center",children:[e.jsx("div",{className:`text-lg font-bold ${r?"text-brand":"text-white"}`,children:o}),e.jsx("div",{className:"mt-0.5 text-[11px] uppercase tracking-wide text-neutral-500",children:s})]})}const oe=s=>s?new Date(s).toLocaleDateString("en-GB",{day:"2-digit",month:"short",year:"2-digit"}):"—";function Fe({status:s}){const r={CONVERTED:{dot:"bg-green-500",text:"text-green-400",label:"Converted"}
3,PENDING:{dot:"bg-amber-500",text:"text-amber-400",label:"Pending"},VOID:{dot:"bg-neutral-500",text:"text-neutral-400",label:"Void"}}[s]??{dot:"bg-neutral-500",text:"text-neutral-400",label:s};return e.jsxs("span",{className:`inline-flex items-center gap-1.5 text-xs font-medium ${r.text}`,children:[e.jsx("span",{className:`h-2 w-2 rounded-full ${r.dot}`}),r.label]})}const ie=({p:s})=>s!=null&&s.athlete_id?e.jsx(Se,{to:`/admin/athletes/${s.athlete_id}`,className:"text-white no-underline hover:text-brand",children:s.name||`Athlete ${s.athlete_id}`}):e.jsx("span",{className:"text-neutral-500",children:"—"});function Pe(){const{data:s,isLoading:o,isError:r}=E({queryKey:["referrals-list"],queryFn:()=>h.get("/api/owner/referrals"),staleTime:3e4});return e.jsxs("div",{className:"rounded-2xl border border-surface-border bg-[#111] p-6",children:[e.jsx("h2",{className:"text-xl font-bold text-white",children:"Who referred whom"}),e.jsx("p",{className:"mt-1 text-sm text-neutral-400",children:"Every referral relationship and where it stands. The reward column shows the referrer's €10 credit status (issued once the friend's first box is paid; spent when used on a box)."}),o&&e.jsx("div",{className:"mt-5 h-5 w-40 animate-pulse rounded bg-surface-border"}),r&&e.jsx("p",{className:"mt-5 text-sm text-neutral-400",children:"Couldn't load referrals."}),s&&s.count===0&&e.jsx("p",{className:"mt-5 text-sm text-neutral-500",children:"No referrals yet."}),s&&s.count>0&&e.jsx("div",{className:"mt-5 overflow-x-auto",children:e.jsxs("table",{className:"w-full min-w-[640px] text-left text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-surface-border text-[11px] uppercase tracking-wide text-neutral-500",children:[e.jsx("th",{className:"py-2 pr-4 font-medium",children:"Referrer"}),e.jsx("th",{className:"py-2 pr-4 font-medium",children:"Referred"}),e.jsx("th",{className:"py-2 pr-4 font-medium",children:"Code"}),e.jsx("th",{className:"py-2 pr-4 font-medium",children:"Status"}),e.jsx("th",{className:"py-2 pr-4 font-medium",children:"Reward"}),e.jsx("th",{className:"py-2 pr-4 font-medium",children:"Invited"}),e.jsx("th",{className:"py-2 pr-0 font-medium",children:"Converted"})]})}),e.jsx("tbody",{children:s.referrals.map(d=>e.jsxs("tr",{className:"border-b border-[#1f1f1f]",children:[e.jsx("td",{className:"py-2.5 pr-4",children:e.jsx(ie,{p:d.referrer})}),e.jsx("td",{className:"py-2.5 pr-4",children:e.jsx(ie,{p:d.referee})}),e.jsx("td",{className:"py-2.5 pr-4 font-mono text-xs tracking-wider text-neutral-300",children:d.code_used}),e.jsx("td",{className:"py-2.5 pr-4",children:e.jsx(Fe,{status:d.status})}),e.jsx("td",{className:"py-2.5 pr-4 text-xs text-neutral-400",children:d.referrer_reward_status?d.referrer_reward_status.charAt(0)+d.referrer_reward_status.slice(1).toLowerCase():"—"}),e.jsx("td",{className:"py-2.5 pr-4 text-neutral-400",children:oe(d.created_at)}),e.jsx("td",{className:"py-2.5 pr-0 text-neutral-400",children:oe(d.converted_at)})]},d.id))})]})})]})}async function De(s,o){const r=new URLSearchParams;s!=="all"&&r.set("status",s),o.trim()&&r.set("search",o.trim());const d=r.toString()?`?${r.toString()}`:"";return h.get(`/api/owner/promos${d}`)}async function Ae(){return(await h.get("/api/coupons/admin/coupons")).filter(o=>o.discount_type==="FREE_BOX")}async function Ie(s){return h.get(`/api/coupons/admin/coupons/${s}/grants`)}async function Re(s){return h.get(`/api/owner/promos/${s}/usage-log`)}async function Le(s){return h.post("/api/owner/promos",s)}async function de(s){return h.post("/api/coupons/admin/coupons",s)}async function $e(s){return h.post("/api/coupons/admin/grant-bulk",s)}async function Be(s,o){return h.patch(`/api/owner/promos/${s}`,o)}async function Me(s){return h.delete(`/api/owner/promos/${s}`)}async function Te(s){return h.post(`/api/owner/promos/${s}/activate`,{})}async function qe(s){return h.post("/api/owner/promos/bulk/generate",s)}async function Ge(s){return h.post("/api/owner/promos/bulk/assign",s)}function ce(s){if(!s)return!1;const o=/([zZ])|([+-]\d{2}:?\d{2})$/.test(s),r=Date.parse(o?s:`${s}Z`);return Number.isFinite(r)&&r<Date.now()}function K(s){if(s.kind==="promo"){const r=s.promo;return r.is_draft?"draft":r.is_active?ce(r.expires_at)?"expired":"active":"deleted"}const o=s.coupon;return o.is_draft?"draft":o.is_active?ce(o.valid_until)?"expired":"active":"deleted"}function Ke(){const{toast:s}=xe(),o=ue(),[r,d]=m.useState("all"),[_,A]=m.useState(""),[u,f]=m.useState(null),[p,w]=m.useState(!1),[L,N]=m.useState(!1),[$,c]=m.useState(!1),[B,X]=m.useState(!1),[g,V]=m.useState(null),[a,x]=m.useState({code:"",description:"",discount_type:"PERCENT",discount_value:"",valid_until:"",max_uses:"",name:"",free_box_count:"1",delivery:"code",athlete_ids:"",reason:""}),M=()=>x({code:"",description:"",discount_type:"PERCENT",discount_value:"",valid_until:"",max_uses:"",name:"",free_box_count:"1",delivery:"code",athlete_ids:"",reason:""}),[i,y]=m.useState({prefix:"",count:"",discount_type:"PERCENT",discount_value:"",valid_until:"",max_uses_per_code:""}),[v,T]=m.useState({promo_code_id:"",athlete_ids:""}
3),[b,F]=m.useState({description:"",valid_until:"",max_uses:""}),{data:q,isLoading:me,refetch:C}=E({queryKey:["admin-promos",r,_],queryFn:()=>De(r,_)}),{data:pe,isLoading:he}=E({queryKey:["admin-free-box-coupons"],queryFn:Ae}),{data:Q,isLoading:fe}=E({queryKey:["free-box-coupon-grants",g==null?void 0:g.coupon_id],queryFn:()=>g?Ie(g.coupon_id):Promise.resolve([]),enabled:!!g}),{data:k,isLoading:be}=E({queryKey:["promo-usage-log",u==null?void 0:u.promo_code_id],queryFn:()=>u?Re(u.promo_code_id):Promise.resolve(null),enabled:!!u&&B}),W=j({mutationFn:Le,onSuccess:t=>{s(`Promo code "${t.code}" created in DRAFT status`,"success"),M(),w(!1),C()},onError:t=>{s((t==null?void 0:t.message)??"Failed to create promo code","error")}}),Z=j({mutationFn:async()=>{const t=parseInt(a.free_box_count,10),l=a.valid_until?new Date(a.valid_until).toISOString():null,ae=a.code.trim().toUpperCase(),re={name:a.name.trim()||ae||"Free box",description:a.description||null,discount_type:"FREE_BOX",discount_value:0,free_box_count:t,applies_to:"BOTH",first_box_only:!1,valid_until:l,is_active:!0,is_draft:!1};if(a.delivery==="code")return{mode:"code",coupon:await de({...re,source:"CAMPAIGN",code:ae,max_uses:parseInt(a.max_uses,10)})};const ne=await de({...re,source:"MANUAL"}),Ce=a.athlete_ids.split(",").map(R=>parseInt(R.trim(),10)).filter(R=>!isNaN(R)),ke=await $e({coupon_id:ne.coupon_id,athlete_ids:Ce,reason:a.reason||null});return{mode:"wallet",coupon:ne,result:ke}},onSuccess:t=>{if(t.mode==="code")s(`Free-box code "${t.coupon.code}" created`,"success");else{const l=t.result;s(`Granted ${l.granted} free box(es)`+(l.skipped?`, skipped ${l.skipped} (already had one)`:"")+(l.not_found?`, ${l.not_found} athlete ID(s) not found`:""),l.not_found?"info":"success")}M(),w(!1),o.invalidateQueries({queryKey:["admin-free-box-coupons"]})},onError:t=>{s((t==null?void 0:t.message)??"Failed to create free box","error")}}),G=j({mutationFn:qe,onSuccess:t=>{s(`Generated ${t.generated} promo codes`,"success"),y({prefix:"",count:"",discount_type:"PERCENT",discount_value:"",valid_until:"",max_uses_per_code:""}),N(!1),C()},onError:t=>{s((t==null?void 0:t.message)??"Failed to generate codes","error")}}),O=j({mutationFn:Ge,onSuccess:t=>{s(`Assigned to ${t.assigned_to} athletes`,"success"),T({promo_code_id:"",athlete_ids:""}),c(!1),C()},onError:t=>{s((t==null?void 0:t.message)??"Failed to assign code","error")}}),U=j({mutationFn:({id:t,data:l})=>Be(t,l),onSuccess:()=>{s("Promo code updated","success"),f(null),F({description:"",valid_until:"",max_uses:""}),C()},onError:t=>{s((t==null?void 0:t.message)??"Failed to update promo code","error")}}),H=j({mutationFn:Me,onSuccess:()=>{s("Promo code deleted","success"),f(null),C()},onError:t=>{s((t==null?void 0:t.message)??"Failed to delete promo code","error")}}),J=j({mutationFn:Te,onSuccess:()=>{s("Promo code activated","success"),f(null),C()},onError:t=>{s((t==null?void 0:t.message)??"Failed to activate promo code","error")}}),Y=(q==null?void 0:q.promos)??[],I=_.trim().toLowerCase(),ge=(pe??[]).filter(t=>r!=="all"&&K({kind:"freebox",coupon:t})!==r?!1:I?(t.code??"").toLowerCase().includes(I)||t.name.toLowerCase().includes(I)||(t.description??"").toLowerCase().includes(I):!0).map(t=>({kind:"freebox",coupon:t})),ve=Y.map(t=>({kind:"promo",promo:t})),ee=[...ge,...ve],je=me||he,z=a.discount_type==="FREE_BOX",_e=()=>{if(z){if(!a.free_box_count||parseInt(a.free_box_count,10)<1){s("Number of free boxes must be at least 1","error");return}if(a.delivery==="code"){if(!a.code.trim()){s("Code is required","error");return}if(!a.max_uses||parseInt(a.max_uses,10)<1){s("A typable free-box code requires a max-uses cap","error");return}}else{if(!a.name.trim()){s("Name is required for a wallet grant","error");return}if(a.athlete_ids.split(",").map(l=>parseInt(l.trim(),10)).filter(l=>!isNaN(l)).length===0){s("Enter at least one athlete ID","error");return}}Z.mutate();return}if(!a.code.trim()){s("Code is required","error");return}if(!a.discount_value){s("Discount value is required","error");return}W.mutate({code:a.code,description:a.description||null,discount_type:a.discount_type,discount_value:parseFloat(a.discount_value),valid_until:a.valid_until?new Date(a.valid_until).toISOString():null,max_uses:a.max_uses?parseInt(a.max_uses):null})},Ne=()=>{if(!i.prefix.trim()||!i.count||!i.discount_value){s("Prefix, count, and discount value are required","error");return}G.mutate({prefix:i.prefix,count:parseInt(i.count),discount_type:i.discount_type,discount_value:parseFloat(i.discount_value),valid_until:i.valid_until?new Date(i.valid_until).toISOString():null,max_uses_per_code:i.max_uses_per_code?parseInt(i.max_uses_per_code):null})},ye=()=>{if(!v.promo_code_id||!v.athlete_ids.trim()){s("Select a promo code and enter athlete IDs","error");return}const t=v.athlete_ids.split(",").map(l=>parseInt(l.trim())).filter(l=>!isNaN(l));if(t.length===0){s("No valid athlete IDs","error");return}
3O.mutate({promo_code_id:parseInt(v.promo_code_id),athlete_ids:t})},we=()=>{u&&U.mutate({id:u.promo_code_id,data:{description:b.description||null,valid_until:b.valid_until?new Date(b.valid_until).toISOString():null,max_uses:b.max_uses?parseInt(b.max_uses):null}})},n="w-full rounded-lg border border-surface-border bg-surface-raised px-3 py-2 text-base sm:text-sm text-white placeholder:text-neutral-500 focus:border-brand focus:outline-none focus:ring-1 focus:ring-brand/30",P="rounded-lg bg-brand px-4 py-2 text-sm font-medium text-white transition hover:bg-[#e66e00] disabled:opacity-40",S="rounded-lg border border-surface-border px-4 py-2 text-sm text-neutral-400 transition hover:border-brand hover:text-white",te=W.isPending||Z.isPending,se=t=>{switch(t){case"draft":return e.jsx("span",{className:"rounded-full bg-yellow-900/30 px-2 py-1 text-xs text-yellow-400",children:"DRAFT"});case"deleted":return e.jsx("span",{className:"rounded-full bg-red-900/30 px-2 py-1 text-xs text-red-400",children:"DELETED"});case"expired":return e.jsx("span",{className:"rounded-full bg-neutral-800 px-2 py-1 text-xs text-neutral-400",children:"EXPIRED"});default:return e.jsx("span",{className:"rounded-full bg-green-900/30 px-2 py-1 text-xs text-green-400",children:"ACTIVE"})}};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-bold text-white",children:"Discount Codes"}),e.jsx("p",{className:"mt-1 text-sm text-neutral-400",children:"One place for every code — percentage / fixed promos and fully-free (€0) boxes."})]}),e.jsx(Ee,{}),e.jsx(Pe,{}),e.jsxs("div",{className:"flex flex-wrap gap-3",children:[e.jsx("button",{onClick:()=>w(!0),className:P,children:"Create Code"}),e.jsx("button",{onClick:()=>N(!0),className:S,children:"Bulk Generate"}),e.jsx("button",{onClick:()=>c(!0),className:S,children:"Bulk Assign"})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"flex flex-wrap gap-2",children:["all","draft","active","expired"].map(t=>e.jsx("button",{onClick:()=>d(t),className:`rounded-lg px-3 py-2 text-sm font-medium transition ${r===t?"bg-brand text-white":"border border-surface-border text-neutral-400 hover:border-brand hover:text-white"}`,children:t.charAt(0).toUpperCase()+t.slice(1)},t))}),e.jsx("input",{type:"text",placeholder:"Search by code or description...",value:_,onChange:t=>A(t.target.value),className:n})]}),e.jsx("div",{className:"rounded-2xl border border-surface-border bg-[#111] overflow-hidden",children:je?e.jsx("div",{className:"p-8 text-center text-neutral-400",children:"Loading codes..."}):ee.length===0?e.jsx("div",{className:"p-8 text-center text-neutral-400",children:"No discount codes found"}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-surface-border bg-[#0d0d0d]",children:[e.jsx("th",{className:"px-6 py-3 text-left font-semibold text-white",children:"Code"}),e.jsx("th",{className:"px-6 py-3 text-left font-semibold text-white",children:"Type"}),e.jsx("th",{className:"px-6 py-3 text-left font-semibold text-white",children:"Value"}),e.jsx("th",{className:"px-6 py-3 text-left font-semibold text-white",children:"Status"}),e.jsx("th",{className:"px-6 py-3 text-left font-semibold text-white",children:"Usage"}),e.jsx("th",{className:"px-6 py-3 text-left font-semibold text-white",children:"Expires"}),e.jsx("th",{className:"px-6 py-3 text-right font-semibold text-white",children:"Actions"})]})}),e.jsx("tbody",{children:ee.map(t=>t.kind==="promo"?e.jsxs("tr",{className:"border-b border-surface-border hover:bg-surface-raised transition",children:[e.jsx("td",{className:"px-6 py-4 font-mono text-brand",children:t.promo.code}),e.jsx("td",{className:"px-6 py-4 text-neutral-400",children:t.promo.discount_type==="PERCENT"?"Promo %":"Promo €"}),e.jsx("td",{className:"px-6 py-4",children:t.promo.discount_type==="PERCENT"?`${t.promo.discount_value}%`:`€${t.promo.discount_value.toFixed(2)}`}),e.jsx("td",{className:"px-6 py-4",children:se(K(t))}),e.jsxs("td",{className:"px-6 py-4",children:[t.promo.used_count,"/",t.promo.max_uses??"∞"]}),e.jsx("td",{className:"px-6 py-4 text-neutral-400",children:t.promo.expires_at?new Date(t.promo.expires_at).toLocaleDateString():"—"}),e.jsx("td",{className:"px-6 py-4 text-right",children:e.jsxs("div",{className:"flex justify-end gap-2",children:[t.promo.is_draft&&e.jsx("button",{onClick:()=>J.mutate(t.promo.promo_code_id),className:"text-xs text-green-400 hover:text-green-300 transition",disabled:J.isPending,children:"Activate"}),t.promo.is_draft&&e.jsx("button",{onClick:()=>{var l;f(t.promo),F({description:t.promo.description||"",valid_until:t.promo.expires_at?t.promo.expires_at.split("T")[0]:"",max_uses:((l=t.promo.max_uses)==null?void 0:l.toString())||""})},className:"text-xs text-blue-400 hover:text-blue-300 transition",children:"Edit"}),e.jsx("button",{onClick:()=>{f(t.promo),X(!0)},className:"text-xs text-neutral-400 hover:text-neutral-300 transition",children:"Logs"}),t.promo.is_active&&e.jsx("button",{onClick:()=>H.mutate(t.promo.promo_code_id),className:"text-xs text-red-400 hover:text-red-300 transition",disabled:H.isPending,children:"Delete"})]})})]},`p${t.promo.promo_code_id}`):e.jsxs("tr",{className:"border-b border-surface-border hover:bg-surface-raised transition",children:[e.jsx("td",{className:"px-6 py-4",children:t.coupon.code?e.jsx("span",{className:"font-mono text-brand",children:t.coupon.code}):e.jsx("span",{className:"text-white",children:t.coupon.name})}),e.jsxs("td",{className:"px-6 py-4 text-neutral-400",children:["Free box",t.coupon.source==="CAMPAIGN"?"":" (wallet)"]}),e.jsxs("td",{className:"px-6 py-4",children:[t.coupon.free_box_count," box"]}),e.jsx("td",{className:"px-6 py-4",children:se(K(t))}),e.jsxs("td",{className:"px-6 py-4",children:[t.coupon.used_count,"/",t.coupon.max_uses??"∞"]}),e.jsx("td",{className:"px-6 py-4 text-neutral-400",children:t.coupon.valid_until?new Date(t.coupon.valid_until).toLocaleDateString():"—"}),e.jsx("td",{className:"px-6 py-4 text-right",children:e.jsx("button",{onClick:()=>V(t.coupon),className:"text-xs text-neutral-400 hover:text-white transition",children:"Grants"})})]},`c${t.coupon.coupon_id}`))})]})})}),p&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4",children:e.jsxs("div",{className:"w-full max-w-md rounded-2xl border border-surface-border bg-[#111] p-6 max-h-[90vh] overflow-y-auto",children:[e.jsx("h2",{className:"text-xl font-bold text-white mb-4",children:"Create Code"}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("select",{value:a.discount_type,onCh
3ange:t=>x({...a,discount_type:t.target.value}),className:n,children:[e.jsx("option",{value:"PERCENT",children:"Percentage (%)"}),e.jsx("option",{value:"FIXED_AMOUNT",children:"Fixed Amount (€)"}),e.jsx("option",{value:"FREE_BOX",children:"Free box (€0)"})]}),z?e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx("label",{className:"mb-2 block text-xs text-neutral-400",children:"Delivery"}),e.jsx("div",{className:"flex gap-2",children:["code","wallet"].map(t=>e.jsx("button",{type:"button",onClick:()=>x({...a,delivery:t}),className:`flex-1 rounded-lg px-3 py-2 text-sm font-medium transition ${a.delivery===t?"bg-brand text-white":"border border-surface-border text-neutral-400 hover:border-brand hover:text-white"}`,children:t==="code"?"Typable code":"In athlete wallet(s)"},t))})]}),a.delivery==="code"?e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"text",placeholder:"Code (e.g. FREEBOX2026)",value:a.code,onChange:t=>x({...a,code:t.target.value}),className:n}),e.jsxs("div",{children:[e.jsx("label",{className:"mb-1 block text-xs text-neutral-400",children:"Max uses (required — global redemption cap)"}),e.jsx("input",{type:"number",min:1,placeholder:"e.g. 25",value:a.max_uses,onChange:t=>x({...a,max_uses:t.target.value}),className:n})]})]}):e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"text",placeholder:"Name (internal, e.g. Beta thank-you)",value:a.name,onChange:t=>x({...a,name:t.target.value}),className:n}),e.jsx("textarea",{placeholder:"Athlete IDs (comma-separated, e.g. 1,5,23)",value:a.athlete_ids,onChange:t=>x({...a,athlete_ids:t.target.value}),className:`${n} resize-none`,rows:3}),e.jsx("input",{type:"text",placeholder:"Reason (optional, shown in grant log)",value:a.reason,onChange:t=>x({...a,reason:t.target.value}),className:n})]}),e.jsxs("div",{children:[e.jsx("label",{className:"mb-1 block text-xs text-neutral-400",children:"Number of free boxes"}),e.jsx("input",{type:"number",min:1,value:a.free_box_count,onChange:t=>x({...a,free_box_count:t.target.value}),className:n})]}),e.jsx("input",{type:"text",placeholder:"Description (optional)",value:a.description,onChange:t=>x({...a,description:t.target.value}),className:n}),e.jsxs("div",{children:[e.jsx("label",{className:"mb-1 block text-xs text-neutral-400",children:"Valid until (optional)"}),e.jsx("input",{type:"date",value:a.valid_until,onChange:t=>x({...a,valid_until:t.target.value}),className:n})]})]}):e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"text",placeholder:"Code (e.g., SUMMER2026)",value:a.code,onChange:t=>x({...a,code:t.target.value}),className:n}),e.jsx("input",{type:"text",placeholder:"Description (optional)",value:a.description,onChange:t=>x({...a,description:t.target.value}),className:n}),e.jsx("input",{type:"number",placeholder:"Discount value",step:"0.01",value:a.discount_value,onChange:t=>x({...a,discount_value:t.target.value}),className:n}),e.jsxs("div",{children:[e.jsx("label",{className:"mb-1 block text-xs text-neutral-400",children:"Valid until (optional)"}),e.jsx("input",{type:"date",value:a.valid_until,onChange:t=>x({...a,valid_until:t.target.value}),className:n})]}),e.jsx("input",{type:"number",placeholder:"Max uses (optional)",value:a.max_uses,onChange:t=>x({...a,max_uses:t.target.value}),className:n})]})]}),e.jsxs("div",{className:"mt-6 flex gap-2",children:[e.jsx("button",{onClick:()=>{w(!1),M()},className:S,children:"Cancel"}),e.jsx("button",{onClick:_e,className:P,disabled:te,children:te?"Working...":z?"Issue":"Create"})]})]})}),L&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50",children:e.jsxs("div",{className:"w-full max-w-md rounded-2xl border border-surface-border bg-[#111] p-6",children:[e.jsx("h2",{className:"text-xl font-bold text-white mb-4",children:"Bulk Generate Codes"}),e.jsx("p",{className:"mb-4 text-xs text-neutral-500",children:"Percentage / fixed promo codes only."}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("input",{type:"text",placeholder:"Prefix (e.g., BETA_)",value:i.prefix,onChange:t=>y({...i,prefix:t.target.value}),className:n}),e.jsx("input",{type:"number",placeholder:"Count (1-10000)",value:i.count,onChange:t=>y({...i,count:t.target.value}),className:n}
3),e.jsxs("select",{value:i.discount_type,onChange:t=>y({...i,discount_type:t.target.value}),className:n,children:[e.jsx("option",{value:"PERCENT",children:"Percentage (%)"}),e.jsx("option",{value:"FIXED_AMOUNT",children:"Fixed Amount (€)"})]}),e.jsx("input",{type:"number",placeholder:"Discount value",step:"0.01",value:i.discount_value,onChange:t=>y({...i,discount_value:t.target.value}),className:n}),e.jsx("input",{type:"date",value:i.valid_until,onChange:t=>y({...i,valid_until:t.target.value}),className:n}),e.jsx("input",{type:"number",placeholder:"Max uses per code (optional)",value:i.max_uses_per_code,onChange:t=>y({...i,max_uses_per_code:t.target.value}),className:n})]}),e.jsxs("div",{className:"mt-6 flex gap-2",children:[e.jsx("button",{onClick:()=>N(!1),className:S,children:"Cancel"}),e.jsx("button",{onClick:Ne,className:P,disabled:G.isPending,children:G.isPending?"Generating...":"Generate"})]})]})}),$&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50",children:e.jsxs("div",{className:"w-full max-w-md rounded-2xl border border-surface-border bg-[#111] p-6",children:[e.jsx("h2",{className:"text-xl font-bold text-white mb-4",children:"Assign to Athletes"}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("select",{value:v.promo_code_id,onChange:t=>T({...v,promo_code_id:t.target.value}),className:n,children:[e.jsx("option",{value:"",children:"Select a promo code"}),Y.map(t=>e.jsx("option",{value:t.promo_code_id,children:t.code},t.promo_code_id))]}),e.jsx("textarea",{placeholder:"Athlete IDs (comma-separated, e.g., 1,5,23)",value:v.athlete_ids,onChange:t=>T({...v,athlete_ids:t.target.value}),className:`${n} resize-none`,rows:4})]}),e.jsxs("div",{className:"mt-6 flex gap-2",children:[e.jsx("button",{onClick:()=>c(!1),className:S,children:"Cancel"}),e.jsx("button",{onClick:ye,className:P,disabled:O.isPending,children:O.isPending?"Assigning...":"Assign"})]})]})}),u&&!B&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50",children:e.jsxs("div",{className:"w-full max-w-md rounded-2xl border border-surface-border bg-[#111] p-6",children:[e.jsxs("h2",{className:"text-xl font-bold text-white mb-4",children:["Edit ",u.code]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("textarea",{placeholder:"Description",value:b.description,onChange:t=>F({...b,description:t.target.value}),className:`${n} resize-none`,rows:2}),e.jsx("input",{type:"date",value:b.valid_until,onChange:t=>F({...b,valid_until:t.target.value}),className:n}),e.jsx("input",{type:"number",placeholder:"Max uses",value:b.max_uses,onChange:t=>F({...b,max_uses:t.target.value}),className:n})]}),e.jsxs("div",{className:"mt-6 flex gap-2",children:[e.jsx("button",{onClick:()=>f(null),className:S,children:"Cancel"}),e.jsx("button",{onClick:we,className:P,disabled:U.isPending,children:U.isPending?"Saving...":"Save"})]})]})}),B&&u&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50",children:e.jsxs("div",{className:"w-full max-w-2xl rounded-2xl border border-surface-border bg-[#111] p-6 max-h-[80vh] overflow-y-auto",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("h2",{className:"text-xl font-bold text-white",children:["Usage Log: ",u.code]}),e.jsx("button",{onClick:()=>{X(!1),f(null)},className:"text-neutral-400 hover:text-white transition",children:"✕"})]}),be?e.jsx("div",{className:"text-center text-neutral-400",children:"Loading logs..."}):(k==null?void 0:k.logs.length)===0?e.jsx("div",{className:"text-center text-neutral-400",children:"No usage logs yet"}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-surface-border bg-[#0d0d0d]",children:[e.jsx("th",{className:"px-4 py-2 text-left font-semibold text-white",children:"Athlete ID"}),e.jsx("th",{className:"px-4 py-2 text-left font-semibold text-white",children:"Order ID"}),e.jsx("th",{className:"px-4 py-2 text-left font-semibold text-white",children:"Used At"}),e.jsx("th",{className:"px-4 py-2 text-left font-semibold text-white",children:"Discount"}),e.jsx("th",{className:"px-4 py-2 text-left font-semibold text-white",children:"Reason"})]})}),e.jsx("tbody",{children:k==null?void 0:k.logs.map(t=>{var l;return e.jsxs("tr",{className:"border-b border-surface-border",children:[e.jsx("td",{className:"px-4 py-2",children:t.athlete_id}),e.jsx("td",{className:"px-4 py-2",children:t.order_id||"—"}),e.jsx("td",{className:"px-4 py-2 text-neutral-400",children:t.used_at?new Date(t.used_at).toLocaleDateString():"—"}),e.jsxs("td",{className:"px-4 py-2",children:["€",((l=t.discount_amount_applied)==null?void 0:l.toFixed(2))||"—"]}
3),e.jsx("td",{className:"px-4 py-2",children:t.reason||"—"})]},t.log_id)})})]})})]})}),g&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4",children:e.jsxs("div",{className:"w-full max-w-2xl rounded-2xl border border-surface-border bg-[#111] p-6 max-h-[90vh] overflow-y-auto",children:[e.jsxs("div",{className:"mb-4 flex items-center justify-between",children:[e.jsxs("h2",{className:"text-xl font-bold text-white",children:["Grants: ",g.name]}),e.jsx("button",{onClick:()=>V(null),className:"text-neutral-400 transition hover:text-white","aria-label":"Close",children:"✕"})]}),fe?e.jsx("div",{className:"text-center text-neutral-400",children:"Loading…"}):(Q??[]).length===0?e.jsx("div",{className:"text-center text-neutral-400",children:"No grants yet"}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-surface-border bg-[#0d0d0d]",children:[e.jsx("th",{className:"px-4 py-2 text-left font-semibold text-white",children:"Athlete ID"}),e.jsx("th",{className:"px-4 py-2 text-left font-semibold text-white",children:"Status"}),e.jsx("th",{className:"px-4 py-2 text-left font-semibold text-white",children:"Left"}),e.jsx("th",{className:"px-4 py-2 text-left font-semibold text-white",children:"Consumed order"})]})}),e.jsx("tbody",{children:(Q??[]).map(t=>e.jsxs("tr",{className:"border-b border-surface-border",children:[e.jsx("td",{className:"px-4 py-2",children:t.athlete_id}),e.jsx("td",{className:"px-4 py-2",children:t.status}),e.jsx("td",{className:"px-4 py-2",children:t.uses_remaining}),e.jsx("td",{className:"px-4 py-2 text-neutral-400",children:t.consumed_order_id??"—"})]},t.grant_id))})]})})]})})]})}export{Ke as default};
4
5//# debugId=7eb173d9-a5c9-5257-b547-0ac16e4f6ec3
6
7//# chunkId=01a086e7-d7e4-71c1-809a-012fb8cacc45

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.