import{c as e,d as t,f as n,h as r,l as i,t as a,u as o}from"./src-C0xjWfnx.js";import{n as s}from"./trpc-client-QrVjRqP1.js";import{t as c}from"./ticket-DHIzx079.js";var l=r(n()),u=t();function d(){let[t,n]=(0,l.useState)(``),{data:r}=s.user.coupon.getMyCoupons.useQuery(),d=s.user.coupon.redeemReservedCoupon.useMutation(),f=s.useUtils(),p=r?.data||[];return(0,u.jsxs)(a,{children:[(0,u.jsx)(o,{weight:`bold`,className:`mb-4 text-xl`,children:`My Coupons`}),(0,u.jsxs)(`div`,{className:`mb-6 flex gap-2`,children:[(0,u.jsx)(e,{placeholder:`Enter coupon code`,value:t,onChange:e=>n(e.target.value),className:`flex-1`}),(0,u.jsx)(i,{onClick:()=>{t.trim()&&d.mutate({couponCode:t.trim()},{onSuccess:()=>{n(``),f.user.coupon.getMyCoupons.invalidate()}})},disabled:d.isPending||!t.trim(),textContent:d.isPending?`Redeeming...`:`Redeem`})]}),p.length===0?(0,u.jsxs)(`div`,{className:`flex flex-col items-center gap-4 py-20`,children:[(0,u.jsx)(c,{className:`h-12 w-12 text-gray-300`}),(0,u.jsx)(o,{className:`text-gray-500`,children:`No coupons yet`})]}):(0,u.jsx)(`div`,{className:`flex flex-col gap-3`,children:p.map(e=>(0,u.jsxs)(`div`,{className:`rounded-xl border border-dashed border-brand-200 bg-brand-50 p-4`,children:[(0,u.jsx)(o,{weight:`bold`,className:`text-brand-700`,children:e.code}),(0,u.jsx)(o,{className:`text-sm text-gray-600`,children:e.description||`${e.discountPercent||0}% off`}),e.expiresAt&&(0,u.jsxs)(o,{className:`mt-1 text-xs text-gray-400`,children:[`Expires: `,new Date(e.expiresAt).toLocaleDateString()]})]},e.id))})]})}export{d as component};