1import{j as s}from"./ui-mIsmOCDt.js";import{c as b,r as o,L as h}from"./vendor-BC_bxrvE.js";import{B as f,s as c}from"./index-c_IvmVOc.js";import{P as w}from"./PortalShell-3EWFtNyj.js";import{C as n}from"./card-1bMvJyyE.js";import{B as g}from"./badge-BbLK-raY.js";import{P}from"./progress-DdipuUgX.js";import{P as M}from"./trophy-DxtupDCS.js";import{T as S}from"./ticket-CWwXO5Vk.js";import{C}from"./calendar-plus-CDFmlCJc.js";import{f as m}from"./format-CVrBi9El.js";import{p as d}from"./parseISO-CLLpGR62.js";import{i as B}from"./isBefore-B0jZbgrL.js";import"./supabase-BopLTUAJ.js";import"./sheet-xKJgL2KR.js";import"./image-C8O0YVxp.js";import"./useNotifications-BSv1ys-o.js";import"./message-circle-heart-4SDzNOPo.js";import"./en-US-SgDV8MQn.js";const V=()=>{const x=b(),[j,y]=o.useState(!0),[l,_]=o.useState([]),[N,k]=o.useState([]);o.useEffect(()=>{(async()=>{const{data:{session:t}}=await c.auth.getSession();if(!t){x("/auth?redirect=/portal/packages");return}const[r,a]=await Promise.all([c.from("client_packages").select("id,plan_name,service,sessions_total,sessions_used,status,purchased_at,expires_at").eq("user_id",t.user.id).order("purchased_at",{ascending:!1}),c.from("package_redemptions").select("id,client_package_id,sessions_delta,note,redeemed_at").order("redeemed_at",{ascending:!1})]);_(r.data||[]),k(a.data||[]),y(!1)})()},[x]);const p=e=>!!e.expires_at&&B(d(e.expires_at),new Date)&&e.sessions_used<e.sessions_total,i=l.filter(e=>e.status==="active"&&!p(e)),u=l.filter(e=>!i.includes(e)),v=i.reduce((e,t)=>e+Math.max(t.sessions_total-t.sessions_used,0),0);return s.jsx(w,{eyebrow:"Your account",title:"Session Packages",subtitle:"Your prepaid sessions, how many you have left, and when they expire.",children:j?s.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading your packagesâ¦"}):l.length===0?s.jsxs(n,{className:"p-8 text-center",children:[s.jsx(M,{className:"mx-auto h-8 w-8 text-muted-foreground"}),s.jsx("h2",{className:"mt-3 font-display text-xl",children:"No packages yet"}),s.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"Ask about multi-session packages next time we talk â they save you money per session."}),s.jsx(f,{asChild:!0,className:"mt-4",children:s.jsx(h,{to:"/portal/bookings",children:"Book a session"})})]}):s.jsxs("div",{className:"space-y-6",children:[s.jsxs(n,{className:"flex flex-wrap items-center justify-between gap-3 p-4",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx(S,{className:"h-5 w-5 text-primary"}),s.jsxs("div",{children:[s.jsx("p",{className:"font-display text-2xl leading-none",children:v}),s.jsx("p",{className:"text-xs text-muted-foreground",children:"sessions available to book"})]})]}),s.jsx(f,{asChild:!0,size:"sm",children:s.jsxs(h,{to:"/portal/bookings",children:[s.jsx(C,{className:"mr-2 h-4 w-4"})," Use a session"]})})]}),i.length>0&&s.jsxs("section",{className:"space-y-3",children:[s.jsx("h2",{className:"font-display text-lg",children:"Active packages"}),i.map(e=>{const t=Math.max(e.sessions_total-e.sessions_used,0),r=N.filter(a=>a.client_package_id===e.id);return s.jsxs(n,{className:"p-4",children:[s.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-2",children:[s.jsxs("div",{children:[s.jsx("p",{className:"font-semibold text-foreground",children:e.plan_name}),s.jsx("p",{className:"text-xs text-muted-foreground",children:e.service})]}),s.jsxs(g,{children:[t," left"]})]}),s.jsxs("div",{className:"mt-3",children:[s.jsxs("div",{className:"flex items-center justify-between text-xs text-muted-foreground",children:[s.jsxs("span",{children:[e.sessions_used," of ",e.sessions_total," used"]}),s.jsx("span",{children:e.expires_at?`Use by ${m(d(e.expires_at),"MMM d, yyyy")}`:"No expiry"})]}),s.jsx(P,{value:Math.round(e.sessions_used/e.sessions_total*100),className:"mt-1 h-2"})]}),r.length>0&&s.jsx("div",{className:"mt-3 space-y-1 border-t border-border pt-3",children:r.slice(0,4).map(a=>s.jsxs("div",{className:"flex justify-between text-xs text-muted-foreground",children:[s.jsx("span",{children:a.sessions_delta>0?"Session used":"Session credited back"}),s.jsx("span",{children:m(d(a.redeemed_at),"MMM d")})]},a.id))})]},e.id)})]}),u.length>0&&s.jsxs("section",{className:"space-y-3",children:[s.jsx("h2",{className:"font-display text-lg",children:"Past packages"}),u.map(e=>s.jsxs(n,{className:"flex flex-wrap items-center justify-between gap-2 p-4 opacity-80",children:[s.jsxs("div",{children:[s.jsx("p",{className:"font-medium text-foreground",children:e.plan_name}),s.jsxs("p",{className:"text-xs text-muted-foreground",children:[e.sessions_used," of ",e.sessions_total," used ·"," ",m(d(e.purchased_at),"MMM d, yyyy")]})]}),s.jsx(g,{variant:"secondary",children:p(e)?"Expired":e.status==="refunded"?"Refunded":"Complete"})]},e.id))]})]})})};export{V 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.