1import{j as e,r as o,D as ie,I,L as U,U as Z,A as le,m as ee,B as L,q as de,t as oe,v as ce,w as me,_ as ue,x as pe,as as xe,s as w,f as $,g as he,b as se,d as ge,X as fe,at as F,h as be,au as je}from"./index-B9m0jA0r.js";import{T as te,b as ae,c as M,a as B}from"./tabs-ng7jIZ-f.js";import{P as ve,a as Ne,i as _e}from"./AppleLayout-BjeCGb72.js";import{P as ye,f as we,R as Ce}from"./ResolveStripeCancelButton-DoaZxIAo.js";import{C as ke}from"./CancelMembershipModal-DwRPibgE.js";import{C as G}from"./clock-CchIC7LV.js";import{C as H}from"./circle-check-KSfehY7a.js";import{C as O}from"./circle-x-CFoGnSL1.js";import{S as Se}from"./search-DNBvS_5l.js";import{M as Pe}from"./mail-WIsOkhn3.js";import{P as Me}from"./phone-l6RA8FW3.js";import{C as Le}from"./chevron-right-bf18FZXn.js";import{t as Ee}from"./errorMessage-Bhf4purx.js";import{L as y}from"./label-CHLwbswP.js";import{G as ne}from"./globe-BlDqXFCJ.js";import{C as Ie}from"./copy-DRTPF0kX.js";import{E as qe}from"./external-link-CIFw3FTT.js";import{P as De}from"./pencil-BD51ZwMV.js";import{T as Y}from"./textarea-BiKqfYGa.js";import{S as X}from"./switch-Bl3yXVPn.js";import{S as Re}from"./save-Ct4J--5S.js";import"./index-sPIgdySf.js";import"./checkbox-B9G3g3S2.js";import"./index-CjHmcE51.js";import"./select-CZUNzdpL.js";import"./index-BdQq_4o_.js";import"./chevron-up-D50tYA58.js";import"./badge-Deq2Zmk0.js";import"./plus-CRAt7_0T.js";import"./grip-vertical-Cu2athBT.js";import"./trash-2-CcAwnd5v.js";import"./radio-group-CshBezdo.js";import"./circle-Dx2aIOyl.js";const Ae={logTag:"Memberships",plansTable:"membership_plans",servicesTable:"membership_plan_services",planFk:"membership_plan_id",priceColumn:"monthly_price",serviceFk:"fee_schedule_id",orderColumn:"sort_order",servicesHaveProviderId:!0,showDiagnoses:!1,deleteConfirm:"Delete this membership plan? This will also remove its included services.",headerTitle:"Membership plans",presetIntro:"Example plans â adjust pricing and services to fit your practice.",presets:[{name:"Relief",price:99,display_order:0,services:[{custom_label:"1 chiropractic adjustment per month",quantity:1}]},{name:"Restore",price:179,display_order:1,services:[{custom_label:"2 chiropractic adjustments per month",quantity:1},{custom_label:"Priority scheduling",quantity:1}]},{name:"Performance",price:299,display_order:2,services:[{custom_label:"4 chiropractic adjustments per month",quantity:1},{custom_label:"Priority scheduling",quantity:1},{custom_label:"One complimentary re-exam per year",quantity:1}]}],defaultCancellation:"",namePlaceholder:"e.g. Wellness",subtitlePlaceholder:"e.g. Stay aligned, stay strong",descriptionPlaceholder:"Who this plan is for and what makes it a good fit...",customItemPlaceholder:"e.g. 1 free massage",loadErrorMessage:"Failed to load membership data"};function Te(){return e.jsx(ye,{config:Ae})}const J={pending:{label:"Awaiting payment",cls:"bg-amber-50 text-amber-700 border-amber-200 dark:bg-amber-950/40 dark:text-amber-400 dark:border-amber-800",Icon:G},active:{label:"Active",cls:"bg-emerald-50 text-emerald-700 border-emerald-200 dark:bg-emerald-950/40 dark:text-emerald-400 dark:border-emerald-800",Icon:H},cancelled:{label:"Cancelled",cls:"bg-red-50 text-red-700 border-red-200 dark:bg-red-950/40 dark:text-red-400 dark:border-red-800",Icon:O}},K={weekly:"/week",monthly:"/month",quarterly:"/quarter",annual:"/year"};function re({status:t}){const r=J[t]||J.pending,p=r.Icon;return e.jsxs("span",{className:`inline-flex items-center gap-1 px-2.5 py-1 rounded-full text-xs font-medium border ${r.cls}`,children:[e.jsx(p,{className:"w-3 h-3"}),r.label]})}function z(t){return new Intl.NumberFormat("en-US",{style:"currency",currency:"USD",maximumFractionDigits:0}).format(t||0)}function _(t){if(!t)return"â";try{return we(new Date(t),"MMM d, yyyy")}catch{return"â"}}function $e(){var f,j,D,R,A,q;const[t,r]=o.useState([]),[p,x]=o.useState(!0),[c,N]=o.useState(""),[i,P]=o.useState("all"),[a,h]=o.useState(null),[l,n]=o.useState(null);async function m(){var V;x(!0);const{data:s}=await w.auth.getUser(),d=(V=s==null?void 0:s.user)==null?void 0:V.id;if(!d){r([]),x(!1);return}const{data:u,error:b}=await w.from("patient_memberships").select("*").eq("provider_id",d).order("created_at",{ascending:!1});if(b){console.error(b),$.error("Failed to load membership sign-ups"),r([]),x(!1);return}const v=u||[],k=Array.from(new Set(v.map(E=>
1E.patient_id).filter(Boolean)));let S={};if(k.length>0){const{data:E}=await w.from("patients").select("id, first_name, last_name, email, phone, date_of_birth, notes").in("id",k);(E||[]).forEach(W=>{S[W.id]=W})}const T=v.map(E=>({...E,patient:S[E.patient_id]||null}));r(T),x(!1)}o.useEffect(()=>{m()},[]);const g=o.useMemo(()=>{const s={pending:0,active:0,cancelled:0,monthlyRevenue:0};return t.forEach(d=>{d.status in s&&(s[d.status]+=1),d.status==="active"&&(s.monthlyRevenue+=Number(d.monthly_price_snapshot)||0)}),s},[t]),C=o.useMemo(()=>{const s=c.trim().toLowerCase();return t.filter(d=>{var b,v,k,S;return i!=="all"&&d.status!==i?!1:s?`${((b=d.patient)==null?void 0:b.first_name)||""} ${((v=d.patient)==null?void 0:v.last_name)||""}`.toLowerCase().includes(s)||(((k=d.patient)==null?void 0:k.email)||"").toLowerCase().includes(s)||(((S=d.patient)==null?void 0:S.phone)||"").toLowerCase().includes(s)||(d.plan_name_snapshot||"").toLowerCase().includes(s):!0})},[t,i,c]);return e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[{key:"pending",label:"Awaiting payment",value:g.pending,Icon:G,tone:"text-amber-700 dark:text-amber-400"},{key:"active",label:"Active",value:g.active,Icon:H,tone:"text-emerald-700 dark:text-emerald-400"},{key:"cancelled",label:"Cancelled",value:g.cancelled,Icon:O,tone:"text-red-700 dark:text-red-400"},{key:"revenue",label:"Monthly Revenue",value:z(g.monthlyRevenue),Icon:ie,tone:"text-foreground"}].map(s=>{const d=s.Icon;return e.jsxs("div",{className:"rounded-xl border border-border bg-card p-4 shadow-[0_1px_2px_rgba(0,0,0,0.04)]",children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:s.label}),e.jsx(d,{className:`w-4 h-4 ${s.tone}`})]}),e.jsx("div",{className:"text-2xl font-light text-foreground",children:s.value})]},s.key)})}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-3 sm:items-center sm:justify-between",children:[e.jsx(te,{value:i,onValueChange:s=>P(s),children:e.jsxs(ae,{children:[e.jsx(M,{value:"all",children:"All"}),e.jsxs(M,{value:"pending",children:["Awaiting payment ",g.pending>0&&e.jsxs("span",{className:"ml-1 text-[10px] opacity-70",children:["(",g.pending,")"]})]}),e.jsx(M,{value:"active",children:"Active"}),e.jsx(M,{value:"cancelled",children:"Cancelled"})]})}),e.jsxs("div",{className:"relative w-full sm:w-72",children:[e.jsx(Se,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx(I,{placeholder:"Search name, email, planâ¦",value:c,onChange:s=>N(s.target.value),className:"pl-9"})]})]}),p?e.jsxs("div",{className:"flex items-center justify-center py-16 text-muted-foreground",children:[e.jsx(U,{className:"w-5 h-5 animate-spin mr-2"})," Loading sign-upsâ¦"]}):C.length===0?e.jsxs("div",{className:"rounded-xl border border-dashed border-border bg-card/40 p-10 text-center",children:[e.jsx(Z,{className:"w-8 h-8 mx-auto text-muted-foreground mb-2"}),e.jsx("h3",{className:"text-sm font-medium text-foreground",children:"No sign-ups yet"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"When patients submit a membership request, they'll appear here."})]}):e.jsx("div",{className:"rounded-xl border border-border bg-card overflow-hidden divide-y divide-border",children:e.jsx(le,{initial:!1,children:C.map(s=>{var v,k,S,T;const d=`${((v=s.patient)==null?void 0:v.first_name)||""} ${((k=s.patient)==null?void 0:k.last_name)||""}`.trim()||"Unknown patient",u=s.status,b=s.canceled_at;return e.jsx(ee.div,{layout:!0,initial:{opacity:0}
1,animate:{opacity:1},exit:{opacity:0},className:"p-4 sm:p-5 hover:bg-muted/30 transition-colors",children:e.jsxs("div",{className:"flex flex-col md:flex-row md:items-center md:justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("h3",{className:"text-sm font-medium text-foreground truncate",children:d}),e.jsx(Fe,{row:s,onResolved:()=>void m()})]}),e.jsxs("div",{className:"mt-1 text-xs text-muted-foreground flex flex-wrap items-center gap-x-4 gap-y-1",children:[((S=s.patient)==null?void 0:S.email)&&e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Pe,{className:"w-3 h-3"}),s.patient.email]}),((T=s.patient)==null?void 0:T.phone)&&e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Me,{className:"w-3 h-3"}),s.patient.phone]}),e.jsxs("span",{children:["Submitted ",_(s.created_at)]}),s.start_date&&e.jsxs("span",{children:["Started ",_(s.start_date)]}),u==="cancelled"&&b&&e.jsxs("span",{children:["Cancelled ",_(b)]})]}),e.jsxs("div",{className:"mt-2 text-sm text-foreground",children:[e.jsx("span",{className:"font-medium",children:s.plan_name_snapshot||"Membership"}),e.jsxs("span",{className:"text-muted-foreground",children:[" · ",z(s.monthly_price_snapshot),K[s.billing_frequency_snapshot]||`/${s.billing_frequency_snapshot}`]})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[(u==="pending"||u==="active"&&s.cancel_at_period_end!==!0)&&e.jsxs(L,{size:"sm",variant:"outline",onClick:()=>n(s),className:"text-red-600 hover:text-red-700 dark:text-red-400",children:[e.jsx(O,{className:"w-3.5 h-3.5 mr-1.5"})," Cancel Membership"]}),e.jsxs(L,{size:"sm",variant:"ghost",onClick:()=>h(s),children:["Details ",e.jsx(Le,{className:"w-3.5 h-3.5 ml-1"})]})]})]})},s.id)})})}),e.jsx(de,{open:!!a,onOpenChange:s=>!s&&h(null),children:e.jsx(oe,{className:"max-w-2xl max-h-[85vh] overflow-y-auto",children:a&&e.jsxs(e.Fragment,{children:[e.jsxs(ce,{children:[e.jsxs(me,{className:"flex items-center gap-2 text-lg",children:[e.jsx(ue,{className:"w-4 h-4 text-primary"}),"Membership details"]}),e.jsx(pe,{children:"Snapshot captured at the time of signing."})]}),e.jsxs("div",{className:"space-y-5 py-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold",children:`${((f=a.patient)==null?void 0:f.first_name)||""} ${((j=a.patient)==null?void 0:j.last_name)||""}`.trim()||"Unknown patient"}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-0.5",children:["Membership ID: ",a.id]})]}),e.jsx(re,{status:a.status})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3 text-xs",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Email:"})," ",e.jsx("span",{className:"text-foreground",children:((D=a.patient)==null?void 0:D.email)||"â"})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Phone:"})," ",e.jsx("span",{className:"text-foreground",children:((R=a.patient)==null?void 0:R.phone)||"â"})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"DOB:"})," ",e.jsx("span",{className:"text-foreground",children:_((A=a.patient)==null?void 0:A.date_of_birth)})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Submitted:"})," ",e.jsx("span",{className:"text-foreground",children:_(a.created_at)})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Signed:"})," ",e.jsx("span",{className:"text-foreground",children:_(a.signed_at)})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Start date:"})," ",e.jsx("span",{className:"text-foreground",children:_(a.start_date)})]}),a.current_period_start&&e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Period start:"})," ",e.jsx("span",{className:"text-foreground",children:_(a.current_period_start)})]}),a.current_period_end&&e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Next billing:"})," ",e.jsx("span",{className:"text-foreground",children:_(a.current_period_end)})]}),a.canceled_at&&e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Cancelled:"})," ",e.jsx("span",{className:"text-foreground",children:_(a.canceled_at)})]})]}),e.jsxs("div",{className:"rounded-lg border border-border p-4 bg-muted/30",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("span",{className:"text-xs uppercase tracking-wide text-muted-foreground",children:"Plan"}),e.jsxs("span",{className:"text-sm font-medium",children:[z(a.monthly_price_snapshot),K[a.billing_frequency_snapshot]||`/${a.billing_frequency_snapshot}`]})]}),e.jsx("div",{className:"text-sm font-semibold",children:a.plan_name_snapshot}),a.plan_subtitle_snapshot&&e.jsx("div",{className:"text-xs text-muted-foreground mt-0.5",children:a.plan_
1subtitle_snapshot}),Array.isArray(a.services_snapshot)&&a.services_snapshot.length>0&&e.jsx("ul",{className:"mt-3 space-y-1",children:a.services_snapshot.map((s,d)=>e.jsxs("li",{className:"text-xs text-foreground flex items-start gap-2",children:[e.jsx(H,{className:"w-3 h-3 text-primary mt-0.5 shrink-0"}),(s.quantity??1)>1?`${s.label} (${s.quantity})`:s.label]},d))}),a.cancellation_policy_snapshot&&e.jsx("p",{className:"text-[11px] text-muted-foreground mt-3 pt-3 border-t border-border leading-relaxed",children:a.cancellation_policy_snapshot})]}),a.terms_text_snapshot&&e.jsxs("div",{children:[e.jsx("span",{className:"text-xs uppercase tracking-wide text-muted-foreground",children:"Terms accepted"}),e.jsx("div",{className:"mt-1 max-h-40 overflow-y-auto rounded-lg border border-border bg-background p-3 text-xs text-foreground/90 whitespace-pre-wrap leading-relaxed",children:a.terms_text_snapshot})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-xs uppercase tracking-wide text-muted-foreground",children:"Signature"}),e.jsx("div",{className:"mt-1 rounded-lg border border-border bg-background p-3 font-serif text-base text-foreground",children:a.signature_name||"â"})]}),((q=a.patient)==null?void 0:q.notes)&&e.jsxs("div",{children:[e.jsx("span",{className:"text-xs uppercase tracking-wide text-muted-foreground",children:"Patient notes"}),e.jsx("div",{className:"mt-1 rounded-lg border border-border bg-background p-3 text-xs text-foreground/90 whitespace-pre-wrap",children:a.patient.notes})]})]}),e.jsx(xe,{children:e.jsx(L,{variant:"outline",onClick:()=>h(null),children:"Close"})})]})})}),e.jsx(ke,{open:!!l,onClose:()=>n(null),patientMembershipId:(l==null?void 0:l.id)??null,patientName:l!=null&&l.patient?`${l.patient.first_name} ${l.patient.last_name}`.trim():null,planName:(l==null?void 0:l.plan_name_snapshot)??null,monthlyPrice:(l==null?void 0:l.monthly_price_snapshot)??null,billingFrequency:(l==null?void 0:l.billing_frequency_snapshot)??null,stripeSubscriptionId:(l==null?void 0:l.stripe_subscription_id)??null,currentPeriodEnd:(l==null?void 0:l.current_period_end)??null,onCancelled:()=>{m()}})]})}function Ue(t){if(!t)return null;const r=new Date(t);return isNaN(r.getTime())?null:r.toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"})}function Fe({row:t,onResolved:r}){const p=t==null?void 0:t.status,x=Ue(t==null?void 0:t.current_period_end),c=typeof(t==null?void 0:t.stripe_subscription_id)=="string"?t.stripe_subscription_id:null,N=p==="active"&&(t==null?void 0:t.cancel_at_period_end)===!0,i=c?`Cancel subscription ${c} in your Stripe dashboard to stop billing.`:"Cancel the subscription in your Stripe dashboard to stop billing.";return e.jsxs(e.Fragment,{children:[N?e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full border px-2 py-0.5 text-[11px] font-medium bg-amber-50 text-amber-700 border-amber-200 dark:bg-amber-950/40 dark:text-amber-400 dark:border-amber-800",children:[e.jsx(G,{className:"w-3 h-3"}),x?`Cancels ${x}`:"Cancels at period end"]}):e.jsx(re,{status:p}),(t==null?void 0:t.stripe_manual_cancel_required)===!0&&e.jsxs(e.Fragment,{children:[e.jsxs("span",{title:i,"aria-label":i,className:"inline-flex items-center gap-1 rounded-full border px-2 py-0.5 text-[11px] font-medium bg-amber-50 text-amber-800 border-amber-300 dark:bg-amber-950/40 dark:text-amber-300 dark:border-amber-700 cursor-help",children:[e.jsx(he,{className:"w-3 h-3"})," Action needed in Stripe"]}),r&&(t==null?void 0:t.id)&&e.jsx(Ce,{kind:"membership",id:t.id,subscriptionId:c,onResolved:r})]})]})}const Be="https://careplanpro.ai";function Q(t){return t.toLowerCase().replace(/[^a-z0-9\s-]/g,"").replace(/\s+/g,"-").replace(/-+/g,"-").replace(/^-+|-+$/g,"")}function ze(){const{user:t}=se(),[r,p]=o.useState(null),[x,c]=o.useState(""),[N,i]=o.useState(!0),[P,a]=o.useState(!1),[h,l]=o.useState(!1),[n,m]=o.useState(null),[g,C]=o.useState(!1);o.useEffect(()=>{let s=!1;async function d(){if(!(t!=null&&t.id)){i(!1);return}const{data:u}=await w.from("profiles").select("slug, practice_name, doctor_name").eq("id",t.id).maybeSingle();if(s)return;const b=(u==null?void 0:u.slug)??null;if(p(b),b)c(b);else{const v=(u==null?void 0:u.practice_name)||(u==null?void 0:u.doctor_name)||"";v&&c(Q(v))}i(!1)}return d(),()=>{s=!0}},[t==null?void 0:t.id]);const f=o.useMemo(()=>Q(x),[x]),j=r?`${Be}/memberships/share/${r}`:null,D=f!==(r??""),R=async()=>
1{if(t!=null&&t.id){if(!f){m("Please enter a page link.");return}a(!0),m(null);try{const{data:s,error:d}=await w.from("profiles").select("id, slug").ilike("slug",f).neq("id",t.id).limit(1);if(d)throw d;if(s&&s.length>0){m("That URL is already taken. Try another."),a(!1);return}const{error:u}=await w.from("profiles").update({slug:f}).eq("id",t.id);if(u)throw u;p(f),C(!1),F({title:"Page link saved",description:"Your public membership page is live."})}catch(s){(s==null?void 0:s.code)==="23505"?m("That URL is already taken. Try another."):m(Ee(s,"Could not save your page link."))}finally{a(!1)}}},A=async()=>{if(j)try{await navigator.clipboard.writeText(j),l(!0),F({title:"Link copied",description:"Public membership URL copied to clipboard."}),setTimeout(()=>l(!1),2e3)}catch{F({title:"Copy failed",description:"Could not copy to clipboard.",variant:"destructive"})}},q=s=>e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2",children:[e.jsxs("div",{className:"flex-1 flex items-center rounded-md border bg-background overflow-hidden focus-within:ring-2 focus-within:ring-ring",children:[e.jsx("span",{className:"px-2.5 py-2 text-[11px] text-muted-foreground bg-muted/50 border-r font-mono whitespace-nowrap hidden sm:inline",children:"/memberships/share/"}),e.jsx(I,{id:`${s}-slug`,value:x,onChange:d=>{c(d.target.value),m(null)},onBlur:()=>c(f),placeholder:"your-practice-name",className:"border-0 focus-visible:ring-0 focus-visible:ring-offset-0 h-9 font-mono text-sm"})]}),e.jsx(L,{type:"button",onClick:R,disabled:P||!f||!!r&&!D,size:"sm",className:"h-9",children:P?e.jsx(U,{className:"h-3.5 w-3.5 animate-spin"}):"Save URL"})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"This URL is shared by both your membership and concierge pages â changing it changes both program URLs and breaks any link you've already shared with patients."}),n&&e.jsx("p",{className:"text-xs text-destructive",children:n})]});return e.jsx("div",{className:"rounded-2xl border bg-card p-5 mb-6",style:{boxShadow:"0 1px 2px hsl(var(--foreground) / 0.04)"},children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"h-9 w-9 rounded-full bg-primary/10 flex items-center justify-center shrink-0",children:e.jsx(ne,{className:"h-4 w-4 text-primary"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h3",{className:"text-sm font-semibold text-foreground",children:"Public Membership Page"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:"This is the link you'll share with patients so they can review and request a membership online."}),N?e.jsxs("div",{className:"mt-4 space-y-2",children:[e.jsx("div",{className:"h-4 w-40 rounded bg-muted/50 animate-pulse"}),e.jsx("div",{className:"h-14 rounded-lg bg-muted/50 animate-pulse"})]}):j?e.jsxs("div",{className:"mt-4 space-y-3",children:[e.jsxs("div",{children:[e.jsx(y,{className:"text-xs text-muted-foreground",children:"Your Live Membership Page"}),e.jsxs("div",{className:"mt-1.5 flex flex-col sm:flex-row gap-2",children:[e.jsx("div",{className:"flex-1 flex items-center rounded-md border bg-muted/40 px-3 py-2 min-w-0",children:e.jsx("span",{className:"text-xs sm:text-sm font-mono text-foreground truncate",children:j})}),e.jsxs("div",{className:"flex gap-2 shrink-0",children:[e.jsxs(L,{type:"button",variant:"outline",size:"sm",onClick:A,className:"gap-1.5 h-10",children:[h?e.jsx(ge,{className:"h-3.5 w-3.5"}):e.jsx(Ie,{className:"h-3.5 w-3.5"}),h?"Copied":"Copy Link"]}),e.jsxs(L,{type:"button",size:"sm",onClick:()=>window.open(j,"_blank","noopener,noreferrer"),className:"gap-1.5 h-10",children:[e.jsx(qe,{className:"h-3.5 w-3.5"}),"Open Page"]})]})]})]}),e.jsx("div",{className:"pt-1",children:g?e.jsxs("div",{className:"rounded-lg border bg-background/50 p-3 space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(y,{htmlFor:"membership-edit-slug",className:"text-xs text-muted-foreground",children:"Page URL slug"}),e.jsx("button",{type:"button",onClick:()=>{C(!1),c(r??""),m(null)},className:"text-muted-foreground hover:text-foreground","aria-label":"Cancel edit",children:e.jsx(fe,{className:"h-3.5 w-3.5"})})]}),q("membership-edit")]}):e.jsxs("button",{type:"button",onClick:()=>{C(!0),c(r??""),m(null)},className:"inline-flex items-center gap-1.5 text-xs text-muted-foreground hover:text-foreground transition-colors",children:[e.jsx(De,{className:"h-3 w-3"}),"Edit page URL (optional)"]})})]}):e.jsxs("div",{className:"mt-4 rounded-lg border border-dashed bg-muted/30 px-4 py-6",children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:"Set up your page link"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1 mb-3",children:"Choose a short, memorable URL for your membership page."}),q("membership-setup")]})]})]})})}function He(){const{user:t}
1=se(),r=t==null?void 0:t.id,[p,x]=o.useState(!0),[c,N]=o.useState(!1),[i,P]=o.useState(null);o.useEffect(()=>{r&&a()},[r]);async function a(){if(r){x(!0);try{let{data:n,error:m}=await w.from("membership_settings").select("*").eq("provider_id",r).maybeSingle();if(m)throw m;if(!n){const{data:g}=await w.from("profiles").select("phone, email").eq("id",r).maybeSingle(),C={provider_id:r,enabled:!0,public_page_enabled:!1,page_headline:"Consistent care, one simple monthly investment.",page_subheadline:"Skip the per-visit fees. Get the chiropractic care you need, on a schedule that works for you.",cta_headline:"Ready to get started?",cta_subheadline:"Choose a plan and we will reach out to get you scheduled. Your first visit is just the beginning.",contact_phone:(g==null?void 0:g.phone)||"",contact_email:(g==null?void 0:g.email)||""},{data:f,error:j}=await w.from("membership_settings").insert(C).select().single();if(j)throw j;n=f}P(n)}catch(n){console.error("[Memberships] load settings error",n),$.error((n==null?void 0:n.message)||"Failed to load membership data")}finally{x(!1)}}}function h(n){P(m=>m&&{...m,...n})}async function l(){if(!(!i||!r)){N(!0);try{const{error:n}=await w.from("membership_settings").update({enabled:i.enabled,public_page_enabled:i.public_page_enabled,page_headline:i.page_headline,page_subheadline:i.page_subheadline,cta_headline:i.cta_headline,cta_subheadline:i.cta_subheadline,contact_phone:i.contact_phone,contact_email:i.contact_email}).eq("provider_id",r);if(n)throw n;$.success("Settings saved")}catch(n){console.error("[Memberships] save settings error",n),$.error((n==null?void 0:n.message)||"Failed to save settings")}finally{N(!1)}}}return p?e.jsx("div",{className:"flex items-center justify-center py-20",children:e.jsx(U,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):i?e.jsxs("section",{className:"rounded-2xl border border-border bg-card p-6 space-y-5",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-semibold text-foreground",children:"Membership settings"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:"Practice-wide membership configuration and public page content."})]}),e.jsxs(L,{size:"sm",onClick:l,disabled:c,className:"rounded-full gap-1.5",children:[c?e.jsx(U,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(Re,{className:"h-3.5 w-3.5"}),"Save settings"]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-5",children:[e.jsxs("div",{className:"flex items-center justify-between rounded-xl border border-border bg-muted/30 px-4 py-3",children:[e.jsxs("div",{children:[e.jsx(y,{className:"text-sm font-medium",children:"Memberships enabled"}),e.jsx("p",{className:"text-[11px] text-muted-foreground mt-0.5",children:"Master switch for the membership program."})]}),e.jsx(X,{checked:i.enabled,onCheckedChange:n=>h({enabled:n})})]}),e.jsxs("div",{className:"flex items-center justify-between rounded-xl border border-border bg-muted/30 px-4 py-3",children:[e.jsxs("div",{children:[e.jsx(y,{className:"text-sm font-medium",children:"Public page enabled"}),e.jsx("p",{className:"text-[11px] text-muted-foreground mt-0.5",children:"Allow patients to view your shareable membership page."})]}),e.jsx(X,{checked:i.public_page_enabled,onCheckedChange:n=>h({public_page_enabled:n})})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-5",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(y,{className:"text-xs text-muted-foreground",children:"Page headline"}),e.jsx(I,{value:i.page_headline,onChange:n=>h({page_headline:n.target.value}),className:"rounded-xl"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(y,{className:"text-xs text-muted-foreground",children:"CTA headline"}),e.jsx(I,{value:i.cta_headline,onChange:n=>h({cta_headline:n.target.value}),className:"rounded-xl"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(y,{className:"text-xs text-muted-foreground",children:"Page subheadline"}),e.jsx(Y,{value:i.page_subheadline,onChange:n=>h({page_subheadline:n.target.value}),className:"rounded-xl resize-none",rows:2})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(y,{className:"text-xs text-muted-foreground",children:"CTA subheadline"}),e.jsx(Y,{value:i.cta_subheadline,onChange:n=>h({cta_subheadline:n.target.value}),className:"rounded-xl resize-none",rows:2})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(y,{className:"text-xs text-muted-foreground",children:"Contact phone"}),e.jsx(I,{value:i.contact_phone,onChange:n=>h({contact_phone:n.target.value}),className:"rounded-xl"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(y,{className:"text-xs text-muted-foreground",children:"Contact email"}
1),e.jsx(I,{type:"email",value:i.contact_email,onChange:n=>h({contact_email:n.target.value}),className:"rounded-xl"})]})]})]}):null}function ys(){const[t,r]=be(),p=t.get("tab")||"plans",c=p==="signups"?"enrollments":["plans","public","enrollments"].includes(p)?p:"plans";return e.jsxs(ve,{children:[e.jsx(Ne,{title:"Memberships",subtitle:"For patients who want ongoing care at a predictable monthly rate. Best for wellness and maintenance visits after active care ends â a lower price point, sold at volume."}),e.jsx(ee.div,{variants:_e,children:e.jsxs(te,{value:c,onValueChange:N=>r({tab:N}),children:[e.jsxs(ae,{className:"backdrop-blur-xl rounded-full p-1 h-auto",style:{background:"hsl(var(--muted) / 0.5)",boxShadow:"0 1px 3px hsl(var(--foreground) / 0.04)"},children:[e.jsxs(M,{value:"plans",className:"gap-1.5 text-xs rounded-full data-[state=active]:bg-background data-[state=active]:shadow-sm",children:[e.jsx(je,{className:"h-3.5 w-3.5"})," Plans & Pricing"]}),e.jsxs(M,{value:"public",className:"gap-1.5 text-xs rounded-full data-[state=active]:bg-background data-[state=active]:shadow-sm",children:[e.jsx(ne,{className:"h-3.5 w-3.5"})," Public Page"]}),e.jsxs(M,{value:"enrollments",className:"gap-1.5 text-xs rounded-full data-[state=active]:bg-background data-[state=active]:shadow-sm",children:[e.jsx(Z,{className:"h-3.5 w-3.5"})," Enrollments"]})]}),e.jsx(B,{value:"plans",className:"mt-6",children:e.jsx(Te,{})}),e.jsxs(B,{value:"public",className:"mt-6 space-y-6",children:[e.jsx(ze,{}),e.jsx(He,{})]}),e.jsx(B,{value:"enrollments",className:"mt-6",children:e.jsx($e,{})})]})})]})}export{ys 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.