1import{r as p,j as r}from"./react-vendor-CU6Sz31W.js";import{au as A,t as f,R as N,gq as M,ax as U,S as C,b as $,gr as v,g as h}from"./index-DEXJEDAi.js";import{V}from"./PatientBookingForm-CF9FKzmx.js";import"./firebase-w6DYUbFN.js";import"./payment-icons-Daq1K3F1.js";import"./IdAndPhotoUploadSection-CVePkTk1.js";import"./ContactInfoSection-2PBmPpSi.js";import"./collapsible-JRJGT2Lx.js";import"./cloud-upload-DO_CTloa.js";import"./CameraCapture-C4ah5pn_.js";import"./monitor-CzX6E2vl.js";import"./circle-dashed-BpzaptvF.js";import"./user-round-c4EWOTq5.js";import"./use-unsaved-changes-B6nL5Xdd.js";import"./alert-WsBxL0qd.js";import"./providerAssignments-C7MWOvAk.js";import"./visitIcons-CG7YiClb.js";import"./badge-check-DS4dztDB.js";import"./CheckoutShell-DPiImp5d.js";import"./checkoutDisplay-6C7UrTTD.js";import"./useAuthorizeHostedToken-CiwlhvjR.js";import"./VisitSchedulePicker-4J6xpsxo.js";import"./addWeeks-1hrFjz19.js";import"./patientAddress-D6GhuKXS.js";import"./CustomPaymentInstructionsPanel-wIf9paY9.js";import"./EmbeddedWhopCheckout-exs5FPDQ.js";import"./networkLicensurePolicy-Ct3PZM4V.js";const z=h("initializeBusinessAppointmentCheckout"),F=h("completeBusinessAppointmentPayment");function fs({open:y,onOpenChange:I,order:s,accentColor:j=$,onPaymentComplete:P}){const[E,b]=p.useState(!1),[t,d]=p.useState(null),[x,g]=p.useState(!1),m=p.useRef(I);m.current=I;const u=p.useRef(P);u.current=P;const O=p.useCallback(()=>{d(null),g(!1),b(!1)},[]);p.useEffect(()=>{if(!y||!(s!=null&&s.businessId)||!(s!=null&&s.businessOrderId||s!=null&&s.id)){O();return}let i=!1;async function a(){var o,c,l;b(!0);try{const e=A.currentUser;if(!e)throw new Error("Not authenticated");const w=await e.getIdToken(),n=await(await fetch(z,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${w}`},body:JSON.stringify({businessId:s.businessId,orderId:s.businessOrderId||s.id})})).json();if(!(n!=null&&n.success))throw new Error((n==null?void 0:n.error)||"Unable to open payment");if(n.duplicate){f.success("This appointment is already paid."),(o=u.current)==null||o.call(u),(c=m.current)==null||c.call(m,!1);return}i||d(n)}catch(e){N(e,{area:"checkout",surface:"frontend/src/pages/orders/OrdersPatientView/BusinessAppointmentOrderPaymentModal.jsx",operation:"frontend/src/pages/orders/OrdersPatientView/BusinessAppointmentOrderPaymentModal.jsx:78"}),i||(console.error("Initialize business appointment checkout:",e),f.error("Unable to open payment. Please try again."),(l=m.current)==null||l.call(m,!1))}finally{i||b(!1)}}return a(),()=>{i=!0}},[y,s==null?void 0:s.id,s==null?void 0:s.businessId,s==null?void 0:s.businessOrderId,O]);const T=p.useCallback(async(i,a)=>{var c,l;if(!(s!=null&&s.businessId)||!(s!=null&&s.businessOrderId||s!=null&&s.id))return;const o=a||(t==null?void 0:t.mode)||"demo";try{g(!0);const e=A.currentUser;if(!e)throw new Error("Not authenticated");const w=await e.getIdToken(),n=await(await fetch(F,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${w}`},body:JSON.stringify({businessId:s.businessId,orderId:s.businessOrderId||s.id,paymentData:i||{},mode:o,...o==="demo"?{confirmDemo:!0}:{},paymentIntentId:(i==null?void 0:i.paymentIntentId)||(t==null?void 0:t.paymentIntentId)||null})})).json();if(!(n!=null&&n.success))throw new Error((n==null?void 0:n.error)||"Payment failed");f.success("Payment completed."),(c=u.current)==null||c.call(u),(l=m.current)==null||l.call(m,!1)}catch(e){N(e,{area:"checkout",surface:"frontend/src/pages/orders/OrdersPatientView/BusinessAppointmentOrderPaymentModal.jsx",operation:"frontend/src/pages/orders/OrdersPatientView/BusinessAppointmentOrderPaymentModal.jsx:127"}),console.error("Complete business appointment payment:",e),f.error(M(e==null?void 0:e.message,"Payment could not be completed. Please try again."))}finally{g(!1)}},[t==null?void 0:t.mode,t==null?void 0:t.paymentIntentId,s==null?void 0:s.id,s==null?void 0:s.businessId,s==null?void 0:s.businessOrderId]),L=(t==null?void 0:t.amount)!=null?`$${Number(t.amount).toFixed(2)}`:(s==null?void 0:s.amountDue)!=null?`$${Number(s.amountDue).toFixed(2)}`:"",S=p.useMemo(()=>(Array.isArray(s==null?void 0:s.lineItems)?s.lineItems:[]).filter(a=>Number(a==null?void 0:a.price)>0).map((a,o)=>({id:a.id||`line-${o}`,name:a.serviceName||a.description||`Item ${o+1}`,quantity:1,amount:Math.round((Number(a.price)||0)*100)})),[s==null?void 0:s.lineItems]);return r.jsx(U,{open:y,onOpenChange:i=>{x||I(i)},title:"Pay for appointment",description:"Complete payment for your business appointment order.",contentClassName:"max-w-lg",bodyClassName:"p-4 sm:p-6",contentTestId:"dialog-business-appointment-payment",children:E?r.jsx("div",{className:"flex min-h-[220px] items-center justify-center",children:r.jsx(C,{size:"lg",label:"Loading payment",className:"text-muted-foreground"})}):t?r.jsx(V,{visitCheckoutData:t,amount:L,visitLabel:v(s),accentColor:j,lineItems:S,paymentProcessing:x,submitLabel:"Pay appointment balance",onComplete:T}):null})}export{fs 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.