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-d7ee-7da1-a548-27e1b50e72ca")}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]="7fc2cf95-aa7a-588f-b973-f273bcb4fe1a")}catch(e){}}(); 3import{c as A,u as k,a as j,j as e}from"./query-vendor-Bpmm07UM.js";import{f as L}from"./format-Bkcbcnnj.js";import{S as F}from"./Spinner-DtDrZLPg.js";import{r as N,L as P}from"./router-vendor-PdvXAmya.js";import{u as T,a as d}from"./index-B4qsZXfP.js";import{C as D}from"./CsvExportButton-DotB4Ibi.js";const I={ACTIVE:"bg-green-900/30 text-green-400",TRIAL:"bg-blue-900/30 text-blue-400",PAUSED:"bg-amber-900/30 text-amber-400",CANCELLED:"bg-red-900/30 text-red-400"},i=L,y=31;function R({s}){if(s.cycle_day==null)return e.jsx("span",{className:"text-neutral-500",children:"â"});if(s.cycle_day<=0)return e.jsxs("div",{children:[e.jsx("span",{className:"text-neutral-400",children:"Starts"}),e.jsx("p",{className:"text-[11px] text-neutral-500",children:i(s.cycle_start_date)})]});const n=s.cycle_day>y;return e.jsxs("div",{children:[e.jsxs("span",{className:n?"font-semibold text-amber-400":"font-medium text-white",children:["Day ",s.cycle_day]}),e.jsxs("span",{className:n?"text-amber-400/70":"text-neutral-400",children:[" / ",y]}),n&&e.jsxs("p",{className:"text-[11px] font-medium text-amber-400/80",children:[s.cycle_day-y,"d past cycle end â no successor cycle?"]}),s.cycle_start_date&&e.jsxs("p",{className:"text-[11px] text-neutral-500",children:["since ",i(s.cycle_start_date)]})]})}const w=24;function $({s}){return s.box_status?s.box_status==="CANCELLED"?e.jsx("span",{className:"rounded-full bg-red-900/30 px-2.5 py-0.5 text-xs font-medium text-red-400",children:"Box cancelled"}):s.box_status==="FINALIZED"?e.jsxs("div",{children:[e.jsx("span",{className:"rounded-full bg-blue-900/30 px-2.5 py-0.5 text-xs font-medium text-blue-400",children:"Finalized"}),s.box_ship_date&&e.jsxs("p",{className:"mt-1 text-[11px] text-neutral-500",children:["ships ",i(s.box_ship_date)]})]}):e.jsxs("div",{className:"space-y-1",children:[e.jsx("span",{className:"rounded-full bg-amber-900/30 px-2.5 py-0.5 text-xs font-medium text-amber-400",children:"Draft"}),s.box_adjusted?e.jsx("p",{className:"text-[11px] text-green-400",children:"â adjusted by athlete"}):e.jsx("p",{className:"text-[11px] text-neutral-400",children:"not adjusted yet"}),s.box_ship_date&&e.jsxs("p",{className:"text-[11px] text-neutral-500",children:["ships ",i(s.box_ship_date)]})]}):s.cycle_day!=null&&s.cycle_day>=1&&s.cycle_day<w?e.jsxs("span",{className:"text-neutral-400",children:["Opens day ",w]}):e.jsx("span",{className:"text-neutral-500",children:"â"})}function O(){const s=A(),{toast:n}=T(),[x,c]=N.useState(null),[o,f]=N.useState(""),[E,u]=N.useState(null),{data:a,isLoading:l,isError:m}=k({queryKey:["owner-subscriptions"],queryFn:()=>d.get("/api/owner/subscriptions"),staleTime:6e4}),_=j({mutationFn:t=>d.post(`/api/owner/subscriptions/${t.subId}/pause`,{pause_until:t.until}),onSuccess:t=>{n(t!=null&&t.expected_delivery_date?`Paused â next box arrives ${i(t.expected_delivery_date)}.`:"Subscription paused.","success"),c(null),s.invalidateQueries({queryKey:["owner-subscriptions"]})},onError:t=>n(t instanceof Error?t.message:"Failed to pause.","error")}),g=j({mutationFn:t=>d.post(`/api/owner/subscriptions/${t}/resume`,{}),onSuccess:()=>{n("Subscription resumed.","success"),s.invalidateQueries({queryKey:["owner-subscriptions"]})},onError:t=>n(t instanceof Error?t.message:"Failed to resume.","error")}),v=j({mutationFn:t=>d.post(`/api/owner/subscriptions/${t}/cancel`,{reason:"admin_cancel"}),onSuccess:()=>{n("Subscription cancelled. Confirmation email sent.","success"),u(null),s.invalidateQueries({queryKey:["owner-subscriptions"]})},onError:t=>n(t instanceof Error?t.message:"Failed to cancel.","error")}),r=a==null?void 0:a.stats,p=(a==null?void 0:a.subscriptions)??[];return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mb-6 flex items-start justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs uppercase tracking-[0.3em] text-brand",children:"Admin"}),e.jsx("h1",{className:"mt-2 text-2xl font-semibold text-white",children:"Subscriptions"}),e.jsx("p",{className:"mt-1 text-sm text-neutral-400",children:l?"Loadingâ¦":`${((r==null?void 0:r.active)??0)+((r==null?void 0:r.trial)??0)} active subscribers`})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(D,{url:"/api/owner/subscriptions/export.csv"}),e.jsx("button",{className:"rounded-full border border-surface-border px-5 py-2.5 text-sm font-medium text-neutral-400 transition hover:bg-surface-raised",onClick:()=>s.invalidateQueries({queryKey:["owner-subscriptions"]}),children:"Refresh"})]})]}),e.jsxs("div",{className:"mb-6 grid gap-4 sm:grid-cols-2 xl:grid-cols-4",children:[e.jsxs("div",{className:"rounded-2xl border border-surface-border bg-[#111] p-5",children:[e.jsx("p",{className:"text-xs uppercase tracking-[0.2em] text-brand",children:"Active"}),e.jsx("p",{className:"mt-2 text-2xl font-bold text-green-400",children:l?"â":(r==null?void 0:r.active)??0}),e.jsx("p",{className:"mt-1 text-xs text-neutral-400",children:"Paid subscriptions"})]}),e.jsxs("div",{className:"rounded-2xl border border-surface-border bg-[#111] p-5",children:[e.jsx("p",{className:"text-xs uppercase tracking-[0.2em] text-brand",children:"Paused"}),e.jsx("p",{className:"mt-2 text-2xl font-bold text-amber-400",children:l?"â":(r==null?void 0:r.paused)??0}),e.jsx("p",{className:"mt-1 text-xs text-neutral-400",children:"Temporarily paused"})]}),e.jsxs("div",{className:"rounded-2xl border border-surface-border bg-[#111] p-5",children:[e.jsx("p",{className:"text-xs uppercase tracking-[0.2em] text-brand",children:"New This Month"}),e.jsx("p",{className:`mt-2 text-2xl font-bold ${((r==null?void 0:r.new_this_month)??0)>0?"text-green-400":"text-white"}`,children:l?"â":`+${(r==null?void 0:r.new_this_month)??0}`}),e.jsx("p",{className:"mt-1 text-xs text-neutral-400",children:"Started this month"})]}),e.jsxs("div",{className:"rounded-2xl border border-surface-border bg-[#111] p-5",children:[e.jsx("p",{className:"text-xs uppercase tracking-[0.2em] text-brand",children:"Cancelled This Month"}),e.jsx("p",{className:`mt-2 text-2xl font-bold ${((r==null?void 0:r.cancelled_this_month)??0)>0?"text-amber-400":"text-white"}`,children:l?"â":(r==null?void 0:r.cancelled_this_month)??0}),e.jsx("p",{className:"mt-1 text-xs text-neutral-400",children:"Churned this month"})]})]}),e.jsxs("div",{className:"rounded-2xl border border-surface-border bg-[#111]",children:[e.jsx("div",{className:"border-b border-surface-border px-6 py-4",children:e.jsx("h2",{className:"text-lg font-semibold text-white",children:"Active Subscribers"})}),l&&e.jsxs("div",{className:"flex items-center justify-center py-16",children:[e.jsx(F,{}),e.jsx("span",{className:"ml-3 text-sm text-neutral-400",children:"Loadingâ¦"})]}),m&&e.jsx("div",{className:"p-6 text-sm text-red-400",children:"Failed to load subscriptions."}),!l&&!m&&p.length===0&&e.jsxs("div",{className:"py-16 text-center",children:[e.jsx("p",{className:"text-lg font-semibold text-white",children:"No active subscriptions"}),e.jsx("p",{className:"mt-2 text-sm text-neutral-400",children:"No subscribers yet."})]}),!l&&!m&&p.length>0&&e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-left text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-surface-border bg-surface-raised text-xs uppercase tracking-wider text-neutral-400",children:[e.jsx("th",{className:"px-4 py-3",children:"Athlete"}),e.jsx("th",{className:"px-4 py-3",children:"Status"}),e.jsx("th",{className:"px-4 py-3",children:"Cycle"}),e.jsx("th",{className:"px-4 py-3",children:"Next box"}),e.jsx("th",{className:"px-4 py-3",children:"Started"}),e.jsx("th",{className:"px-4 py-3",children:"Next billing / Box arrives"}),e.jsx("th",{className:"px-4 py-3 text-right",children:"Actions"})]})}),e.jsx("tbody",{className:"divide-y divide-surface-border",children:p.map(t=>{const C=t.status==="ACTIVE",b=t.status==="PAUSED",S=b&&(t.pause_reason==="PAYMENT_FAILURE"||!t.pause_reason&&!t.pause_resumes_at);return e.jsxs("tr",{className:"hover:bg-surface-raised",children:[e.jsxs("td",{className:"px-4 py-3",children:[e.jsx(P,{to:`/admin/athletes/${t.athlete_id}`,className:"font-medium text-white no-underline hover:text-brand",children:t.athlete_name}),t.athlete_email&&e.jsx("p",{className:"text-xs text-neutral-500",children:t.athlete_email})]}),e.jsxs("td",{className:"px-4 py-3",children:[e.jsx("span",{className:`rounded-full px-2.5 py-0.5 text-xs font-medium ${I[t.status]??"bg-neutral-800 text-neutral-400"}`,children:t.status}),S&&e.jsx("p",{className:"mt-1 text-[11px] text-red-400/70",children:"Payment failure"})]}),e.jsx("td",{className:"px-4 py-3 text-neutral-400",children:e.jsx(R,{s:t})}),e.jsx("td",{className:"px-4 py-3",children:e.jsx($,{s:t})}),e.jsx("td",{className:"px-4 py-3 text-neutral-400",children:i(t.started_at)}),e.jsx("td",{className:"px-4 py-3 text-neutral-400",children:b?t.box_delivery_date?`Box arrives ${i(t.box_delivery_date)}`:"Box date unknown":t.billing_due_rolled?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-amber-400",children:i(t.billing_due_date)}),e.jsxs("p",{className:"text-[11px] text-amber-400/80",children:["Day-27 passed ",i(t.billing_due_elapsed_date)," â rolled"]})]}):i(t.billing_due_date)}),e.jsxs("td",{className:"px-4 py-3 text-right",children:[C&&x!==t.subscription_id&&e.jsx("button",{type:"button",onClick:()=>{c(t.subscription_id),f("")},className:"inline-flex min-h-[44px] items-center rounded-full border border-surface-border px-4 text-xs text-neutral-400 transition hover:border-brand/40 hover:text-white",children:"Pauseâ¦"}),C&&x===t.subscription_id&&e.jsxs("div",{className:"flex w-[15rem] flex-col items-end gap-3",onKeyDown:h=>{h.key==="Escape"&&c(null)},children:[e.jsx("p",{className:"text-right text-[11px] leading-snug text-neutral-400",children:"Their box arrives on or just before this date; the email quotes the exact estimate."}),e.jsxs("div",{className:"flex items-center justify-end gap-3",children:[e.jsx("input",{type:"date",value:o,"aria-label":"Box arrives on",min:t.earliest_delivery_date??(a==null?void 0:a.earliest_delivery_date),max:a==null?void 0:a.latest_delivery_date,onChange:h=>f(h.target.value),className:"min-h-[44px] rounded-md border border-surface-border bg-page px-2 text-xs text-white"}),e.jsx("button",{type:"button",disabled:_.isPending||!o,onClick:()=>_.mutate({subId:t.subscription_id,until:o}),className:"inline-flex min-h-[44px] items-center rounded-full bg-brand px-4 text-xs font-medium text-white transition hover:bg-[#e66e00] disabled:opacity-50",children:"Confirm"}),e.jsx("button",{type:"button",onClick:()=>c(null),className:"inline-flex min-h-[44px] items-center px-2 text-xs text-neutral-400 hover:text-neutral-300",children:"Cancel"})]})]}),b&&e.jsx("button",{type:"button",disabled:g.isPending,onClick:()=>g.mutate(t.subscription_id),className:"rounded-full border border-surface-border px-3 py-1 text-xs text-amber-400 transition hover:border-amber-400/60 disabled:opacity-50",children:"Resume"}),t.status!=="CANCELLED"&&x!==t.subscription_id&&e.jsx("div",{className:"mt-2 flex items-center justify-end gap-2",children:E===t.subscription_id?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-[11px] text-red-400/80",children:"Churn this member?"}),e.jsx("button",{type:"button",disabled:v.isPending,onClick:()=>v.mutate(t.subscription_id),className:"rounded-full bg-red-500/90 px-3 py-1 text-xs font-medium text-white transition hover:bg-red-500 disabled:opacity-50",children:"Confirm cancel"}),e.jsx("button",{type:"button",onClick:()=>u(null),className:"text-xs text-neutral-400 hover:text-neutral-300",children:"Back"})]}):e.jsx("button",{type:"button",onClick:()=>u(t.subscription_id),className:"rounded-full border border-surface-border px-3 py-1 text-xs text-red-400/80 transition hover:border-red-400/60 hover:text-red-400",children:"Cancelâ¦"})})]})]},t.subscription_id)})})]})})]})]})}export{R as CycleCell,O as default}; 4 5//# debugId=7fc2cf95-aa7a-588f-b973-f273bcb4fe1a 6 7//# chunkId=01a086e7-d7ee-7da1-a548-27e1b50e72ca
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.