1var e=Object.defineProperty,s=Object.defineProperties,t=Object.getOwnPropertyDescriptors,r=Object.getOwnPropertySymbols,i=Object.prototype.hasOwnProperty,a=Object.prototype.propertyIsEnumerable,n=(s,t,r)=>t in s?e(s,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):s[t]=r,l=(e,s)=>{for(var t in s||(s={}))i.call(s,t)&&n(e,t,s[t]);if(r)for(var t of r(s))a.call(s,t)&&n(e,t,s[t]);return e};import{j as o}from"./unknown-B8sTZm28.js";import{c}from"./unknown-BaTnxVZb.js";import{r as d}from"./unknown-D4Lh-9cT.js";import{u as m}from"./unknown-BoH9qytf.js";import{D as u,a as p,b as x,c as h}from"./unknown-nSdPOvXs.js";import{B as v}from"./unknown-C53ez6Cm.js";import{I as j}from"./unknown-DzI4nldS.js";import{L as b}from"./unknown-fzpodmot.js";import{d as f,W as y,w as g,C as w,a5 as N,ak as _,V as k,M as S,s as P,aR as C}from"./index-Cjf4_mTK.js";import{S as F}from"./unknown-DFI7Nu9-.js";import{A as E}from"./unknown-UCi2AL4E.js";import{b as q,r as D}from"./unknown-Dapf8UP8.js";import{R as O}from"./unknown-cYtlYKhd.js";import{D as T}from"./unknown-DsC9rQRj.js";import{B as I}from"./unknown-BysKt69l.js";import"./unknown-6nyZxgq7.js";import"./unknown-DfefiCyb.js";import"./unknown-Bs4EVO4p.js";import"./unknown-dPNSFJGi.js";import"./unknown-bEcWCdRz.js";import"./unknown-me76ibQb.js";import"./unknown-CO3jXE76.js";const A=({isOpen:e,onClose:r,subscription:i,selectedFrequency:a,price:n,businessId:A,businessName:U})=>{var Y,$,W,B,R,z,L,M,V;const{toast:Z}=f(),[G,J]=d.useState(""),[Q,H]=d.useState(""),[K,X]=d.useState(""),[ee,se]=d.useState(),[te,re]=d.useState({street_address:"",city:"",state_province:"",postal_code:"",country:"US"}),[ie,ae]=d.useState(""),[ne,le]=d.useState(""),[oe,ce]=d.useState(""),de=i.payment_method||"in_person",[me,ue]=d.useState("stripe"===de?"stripe":"in_person"),[pe,xe]=d.useState(!1),[he,ve]=d.useState(!1),[je,be]=d.useState(null),fe=m(A,i.id,a,e),ye=q(fe.data||{}),ge=!!(null==(Y=fe.data)?void 0:Y.service_id)&&"mobile"===ye,we=(null==($=fe.data)?void 0:$.payment_method)||de,Ne=null!=(B=null==(W=fe.data)?void 0:W.total_price)?B:n,_e=0===Ne?"in_person":"stripe"===we?"stripe":"in_person"===we?"in_person":me,ke={weekly:"Weekly","bi-weekly":"Bi-Weekly",monthly:"Monthly",quarterly:"Quarterly",yearly:"Yearly"},Se=()=>{ve(!1),be(null),J(""),H(""),X(""),re({street_address:"",city:"",state_province:"",postal_code:"",country:"US"}),ae(""),le(""),ce(""),r()},Pe=(null==(R=i.service)?void 0:R.name)||i.name||"Subscription Service";return o.jsx(u,{open:e,onOpenChange:he?Se:r,children:o.jsx(p,{className:"max-w-2xl max-h-[90vh] overflow-y-auto light bg-white",children:he&&je?o.jsxs("div",{className:"text-center py-8 space-y-6",children:[o.jsx("div",{className:"mx-auto w-20 h-20 bg-green-100 rounded-full flex items-center justify-center",children:o.jsx(y,{className:"h-10 w-10 text-green-600"})}),o.jsxs("div",{children:[o.jsx("h3",{className:"text-2xl font-bold text-green-800 mb-2",children:"pending"===je.status?"Subscription request received":"Subscription saved"}),o.jsx("p",{className:"text-gray-600",children:"pending"===je.status?"Your requested visits await business approval.":`Your subscription to ${Pe} is saved.`})]}),o.jsxs("div",{className:"bg-green-50 border border-green-200 rounded-lg p-5 text-left space-y-3",children:[o.jsxs("div",{className:"flex items-center gap-3",children:[o.jsx(O,{className:"w-5 h-5 text-purple-600"}),o.jsxs("div",{children:[o.jsx("p",{className:"text-sm text-gray-500",children:"Frequency"}),o.jsx("p",{className:"font-semibold text-gray-900",children:ke[a]})]})]}),o.jsxs("div",{className:"flex items-center gap-3",children:[o.jsx(T,{className:"w-5 h-5 text-green-600"}),o.jsxs("div",{children:[o.jsx("p",{className:"text-sm text-gray-500",children:"Price"}),o.jsxs("p",{className:"font-semibold text-gray-900",children:["$",je.price.toFixed(2)," per ","bi-weekly"===a?"two weeks":a.replace("-"," ")]})]})]}),!!je.count&&o.jsxs(o.Fragment,{children:[o.jsxs("div",{className:"flex items-center gap-3",children:[o.jsx(g,{className:"w-5 h-5 text-blue-600"}),o.jsxs("div",{children:[o.jsx("p",{className:"text-sm text-gray-500",children:"First Appointment"}),o.jsx("p",{className:"font-semibold text-gray-900",children:je.date})]})]}),o.jsxs("div",{className:"flex items-center gap-3",children:[o.jsx(w,{className:"w-5 h-5 text-blue-600"}),o.jsxs("div",{children:[o.jsx("p",{className:"text-sm text-gray-500",children:"Time"}),o.jsx("p",{className:"font-semibold text-gray-900",children:je.time})]})]})]})]}),o.jsx("div",{className:"text-sm text-gray-500",children:je.count?`${je.count} visits are saved. Notification delivery is tracked separately.`:"No appointment was created for this subscription."}),o.jsxs(v,{onClick:Se,className:"w-full bg-gradient-to-r from-green-500 to-emerald-600 hover:from-green-600 hover:to-emerald-700 text-white py-3 font-semibold",children:[o.jsx(y,{className:"h-4 w-4 mr-2"}),"Done"]})]}):o.jsxs(o.Fragment,{children:[o.jsx(x,{children:o.jsxs(h,{children:["Subscribe to ",Pe]}
1)}),o.jsxs("div",{className:"space-y-6",children:[o.jsxs("div",{className:"bg-purple-50 border border-purple-200 rounded-lg p-4 space-y-2",children:[o.jsxs("div",{className:"flex items-center gap-2 text-purple-900",children:[o.jsx(O,{className:"w-5 h-5"}),o.jsxs("span",{className:"font-semibold",children:[ke[a]," Subscription"]})]}),o.jsxs("div",{className:"flex items-center gap-2 text-purple-900",children:[o.jsx(T,{className:"w-5 h-5"}),o.jsxs("span",{className:"text-2xl font-bold",children:["$",Ne.toFixed(2)]}),o.jsxs("span",{className:"text-sm text-purple-700",children:["per ","bi-weekly"===a?"two weeks":a.replace("-"," ")]})]}),(null==(z=fe.data)?void 0:z.duration_minutes)&&o.jsxs("div",{className:"flex items-center gap-2 text-purple-700 text-sm",children:[o.jsx(w,{className:"w-4 h-4"}),o.jsxs("span",{children:[fe.data.duration_minutes," minutes per session"]})]})]}),fe.isError&&o.jsxs("div",{role:"alert",children:[o.jsx("p",{children:fe.error.message}),o.jsx(v,{variant:"outline",onClick:()=>{fe.refetch()},children:"Reload subscription details"})]}),fe.isPending&&o.jsx("p",{role:"status",children:"Loading subscription detailsâ¦"}),!!(null==(L=fe.data)?void 0:L.service_id)&&o.jsx("div",{className:"space-y-4",children:o.jsxs("div",{children:[o.jsxs("h3",{className:"text-lg font-semibold mb-3 flex items-center gap-2",children:[o.jsx(g,{className:"w-5 h-5"}),"Select Your First Appointment"]}),o.jsx(F,{businessId:A,onDateTimeSelect:(e,s,t)=>{ae(e),le(s),ce(t)},selectedDate:ie,selectedStartTime:ne,selectedService:(null==(M=fe.data)?void 0:M.service_id)?{id:fe.data.service_id,name:fe.data.service_name,duration_minutes:fe.data.duration_minutes||60,has_fixed_duration:!0}:void 0})]})}),o.jsxs("form",{noValidate:!0,onSubmit:e=>{return r=void 0,n=null,o=function*(){var r,n,o,d;if(e.preventDefault(),!G.trim()||!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(Q.trim()))return void Z({title:"Error",description:"Please enter your name and a valid email address",variant:"destructive"});const m=c(K);if(se(m),m)null==(r=document.getElementById("customerPhone"))||r.focus();else if(!fe.data||fe.isError||fe.isFetching)Z({title:"Subscription details unavailable",description:"Reload the current details before continuing.",variant:"destructive"});else if(!fe.data.service_id||ie&&ne){try{ge&&D(ye,te)}catch(x){return void Z({title:"Address required",description:x instanceof Error?x.message:"Provide the service address.",variant:"destructive"})}var u,p;if(xe(!0),"stripe"!==_e)try{const e=yield C(l((u=l({business_id:A,service_subscription_id:i.id,frequency:a,customer_name:G.trim(),customer_email:Q.trim(),customer_phone:K.trim()||null},fe.data.service_id?{requested_date:ie,requested_start_time:ne}:{}),p={total_price:Ne},s(u,t(p))),ge?te:{})),r=e.bookings[0];be({date:r?new Intl.DateTimeFormat("en-US",{dateStyle:"full",timeZone:e.scheduled_tz}).format(new Date(r.scheduled_at)):"",time:r?new Intl.DateTimeFormat("en-US",{timeStyle:"short",timeZone:e.scheduled_tz}).format(new Date(r.scheduled_at)):"",status:e.status,count:e.bookings.length,price:e.total_price}),ve(!0)}catch(x){Z({title:"Subscription could not be saved",description:x instanceof Error?x.message:"Please try again.",variant:"destructive"})}finally{xe(!1)}else try{const e=window.location.href.split("?")[0],{data:s,error:t}=yield P.functions.invoke("create-service-subscription-checkout",{body:{subscriptionId:i.id,customerName:G.trim(),customerEmail:Q.trim(),customerPhone:K.trim()||null,price:Ne,frequency:a,selectedDate:ie,selectedStartTime:ne,selectedEndTime:oe,serviceAddress:ge&&(null==(n=null==te?void 0:te.street_address)?void 0:n.trim())?te:null,successUrl:`${e}?subscription_success=true`,cancelUrl:e}});if(t||!(null==s?void 0:s.url)){let e=(null==s?void 0:s.error)||"Failed to start checkout";if(t)try{const s=yield null==(d=null==(o=t.context)?void 0:o.json)?void 0:d.call(o);e=(null==s?void 0:s.error)||t.message||e}catch(h){e=t.message||e}throw new Error(e)}window.location.href=s.url}catch(v){Z({title:"Error",description:v instanceof Error?v.message:"Could not start checkout",variant:"destructive"}),xe(!1)}}else Z({title:"Error",description:"Please select a date and time for your first appointment",variant:"destructive"})},new Promise((s,t)=>{var i=s=>{try{l(o.next(s))}catch(e){t(e)}},a=s=>{try{l(o.throw(s))}catch(e){t(e)}},l=e=>e.done?s(e.value):Promise.resolve(e.value).then(i,a);l((o=o.apply(r,n)).next())});var r,n,o},className:"space-y-4",children:[o.jsx("h3",{className:"text-lg font-semibold",children:"Your Information"}),o.jsxs("div",{children:[o.jsxs(b,{htmlFor:"customerName",className:"flex items-center gap-2",children:[o.jsx(N,{className:"w-4 h-4"}),"Full Name *"]}),o.jsx(j,{id:"customerName",type:"text",value:G,onChange:e=>J(e.target.value),placeholder:"John Doe",required:!0,disabled:pe})]}),o.jsxs("div",{children:[o.jsxs(b,{htmlFor:"customerEmail",className:"flex items-center gap-2",children:[o.jsx(_,{className:"w-4 h-4"}),"Email *"]}),o.jsx(j,{id:"customerEmail",type:"email",value:Q,onChange:e=>H(e.target.value),placeholder:"[email protected]",required:!0,disabled:pe})]}),o.jsxs("div",{children:[o.jsxs(b,{htmlFor:"customerPhone",className:"flex items-center gap-2",children:[o.jsx(k,{className:"w-4 h-4"}),"Phone *"]}),o.jsx(j,{id:"customerPhone",autoComplete:"tel",required:!0,"aria-invalid":!!ee,"aria-describedby":ee?"subscription-phone-error":void 0,type:"tel",value:K,onChange:e=>{X(e.target.value),ee&&se(c(e.target.value))},placeholder:"+1 (555) 123-4567",disabled:pe}),ee&&o.jsx("p",{id:"subscription-phone-error",role:"alert",className:"text-sm text-red-600",children:ee})]}),ge&&o.jsxs("div",{children:[o.jsxs(b,{className:"flex items-center gap-2",children:[o.jsx(S,{className:"w-4 h-4"}),"Service Address *"]}),o.jsx(E,{address:te,onChange:re,required:!0}),o.jsx("p",{className:"text-sm text-slate-500 mt-1",children:"Where should we provide the service?"})]}),Ne>0&&"customer_choice"===we&&o.jsxs("div",{className:"flex gap-2","aria-label":"Payment method",children:[o.jsx(v,{type:"button",variant:"in_person"===me?"default":"outline",onClick:()=>ue("in_person"),children:"Pay in person"}),o.jsx(v,{type:"button",variant:"stripe"===me?"default":"outline",onClick:()=>ue("stripe"),children:"Pay online"})]}),"stripe"===_e&&fe.data&&!fe.data.service_id&&o.jsx("p",{role:"alert",children:"This plan needs a linked service before online payment is available. Contact the business."}),o.jsxs("div",{className:"flex items-center gap-2 p-3 rounded-lg bg-gray-50 border border-gray-200 text-sm text-gray-600",children:[o.jsx(I,{className:"w-4 h-4 text-gray-500"}),o.jsx("span",{children:0===Ne?"No payment is required.":"stripe"===_e?"Continue to secure payment. Payment and appointment approval are separate.":"Payment is collected in person."})]}),o.jsxs("div",{className:"bg-blue-50 border border-blue-200 rounded-lg p-3 text-sm text-blue-900",children:[o.jsx("p",{className:"font-semibold mb-1",children:"What happens next?"}),o.jsxs("ul",{className:"list-disc list-inside space-y-1 text-blue-800",children:[(null==(V=fe.data)?void 0:V.service_id)?o.jsxs(o.Fragment,{children:[o.jsx("li",{children:"Your first four visits are saved together, subject to availability."}),o.jsx("li",{children:"The business confirmation preference applies to your requested visits."})]}):o.jsx("li",{children:"This subscription does not include a scheduled appointment."}),o.jsx("li",{children:"Contact the business to manage or cancel your subscription."})]})]}),o.jsxs("div",{className:"flex gap-2 pt-4",children:[o.jsx(v,{type:"button",variant:"outline",onClick:r,disabled:pe,className:"flex-1",children:"Cancel"}),o.jsx(v,{type:"submit",disabled:pe||!fe.data||fe.isError||fe.isFetching||"stripe"===_e&&!fe.data.service_id,className:"flex-1 bg-purple-600 hover:bg-purple-700",children:pe?"Subscribing...":"Subscribe Now"})]})]})]})]})})})};export{A 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.