import{j as e}from"./vendor-query-DoyCFZ4O.js";import{c as K,f as Q,r,L as i}from"./vendor-react-Rhy2aEWQ.js";import{u as W,f as Y,d as M,b as Z,S as ee,e as f}from"./index-CwDwxmPI.js";import{c as se}from"./pricing-DSfs6YQt.js";import{aX as $,a3 as k,a0 as T,ao as O,a_ as q,g as te,P as ae,aA as I,q as re,a$ as ce,s as le}from"./vendor-utils-BOMyae96.js";import"./vendor-motion-D3eh3-LB.js";function ne(s){if(!s)return[];try{const o=JSON.parse(s);return Array.isArray(o)?o.filter(l=>typeof l=="string"):[]}catch{return[]}}const d=s=>s==="gbp"?"£":s==="eur"?"€":"$",x=s=>s==="eur"?"de-DE":"en-GB";function ue(){const{t:s,i18n:o}=W("legal"),l=se(o.language),{user:c}=Y(),J=K(),[B]=Q(),h=B.get("package"),[t,G]=r.useState(null),[R,u]=r.useState(!0),[N,y]=r.useState(null),[m,v]=r.useState((c==null?void 0:c.full_name)||""),[n,w]=r.useState((c==null?void 0:c.email)||""),[_,U]=r.useState(""),[S,H]=r.useState(!1),[p,F]=r.useState(!1),[C,L]=r.useState(null);r.useEffect(()=>{c&&(m||v(c.full_name||""),n||w(c.email||""))},[c]),r.useEffect(()=>{if(!h){y(s("checkout.noPackage")),u(!1);return}u(!0),M.get(`/public/packages/${h}`,{params:{currency:l}}).then(a=>G(a.data)).catch(()=>y(s("checkout.packageNotFound"))).finally(()=>u(!1))},[h,l]);const P=r.useMemo(()=>ne((t==null?void 0:t.includes)??null),[t]),E=t?Z[t.service_category_id]:null,V=r.useMemo(()=>t?t.price_label?t.price_label:t.price_cents?`${d(t.currency||l)}${(t.price_cents/100).toFixed(2)}`:null:null,[t]),b=/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(n),g=m.trim().length>=2&&b&&S&&(t==null?void 0:t.can_buy),X=async a=>{var A,D;if(a.preventDefault(),!(!g||!t)){L(null),F(!0);try{const j=await M.post("/public/checkout",{package_id:t.id,customer_name:m.trim(),customer_email:n.trim(),customer_phone:_.trim()||null,currency:l});window.location.href=j.data.checkout_url}catch(j){const z=((D=(A=j.response)==null?void 0:A.data)==null?void 0:D.detail)||s("checkout.paymentError");L(z),F(!1)}}};return R?e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-gray-50",children:e.jsx($,{className:"w-8 h-8 animate-spin text-primary-500"})}):N||!t?e.jsx("div",{className:"min-h-screen bg-gray-50 flex items-center justify-center px-4",children:e.jsxs("div",{className:"max-w-md w-full text-center space-y-6",children:[e.jsx("div",{className:"w-16 h-16 bg-red-100 rounded-full flex items-center justify-center mx-auto",children:e.jsx(k,{className:"w-8 h-8 text-red-600"})}),e.jsx("h1",{className:"text-2xl font-bold text-dark-900",children:N||s("checkout.packageNotFound")}),e.jsx("p",{className:"text-dark-500",children:s("checkout.packageNotAvailable")}),e.jsxs(i,{to:"/services",className:"inline-flex items-center gap-2 px-6 py-3 bg-primary-600 text-white rounded-xl font-medium hover:bg-primary-700 transition-colors",children:[e.jsx(T,{className:"w-4 h-4"})," ",s("checkout.browseServices")]})]})}):e.jsxs("div",{className:"min-h-screen bg-gradient-to-b from-gray-50 to-white",children:[e.jsx(ee,{title:"Checkout",canonical:"/checkout",no_index:!0}),e.jsx("div",{className:"bg-white border-b border-dark-100",children:e.jsxs("div",{className:"max-w-5xl mx-auto px-4 sm:px-6 lg:px-8 py-4 flex items-center gap-4",children:[e.jsx("button",{onClick:()=>J(-1),className:"text-dark-400 hover:text-dark-600 transition-colors",children:e.jsx(T,{className:"w-5 h-5"})}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(O,{className:"w-4 h-4 text-green-600"}),e.jsx("span",{className:"text-sm font-medium text-dark-700",children:s("checkout.secureCheckout")})]})]})}),e.jsx("div",{className:"max-w-5xl mx-auto px-4 sm:px-6 lg:px-8 py-8 lg:py-12",children:e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-5 gap-8 lg:gap-12",children:[e.jsxs("div",{className:"lg:col-span-3 space-y-8",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl sm:text-3xl font-bold text-dark-900",children:s("checkout.completeOrder")}),e.jsx("p",{className:"mt-2 text-dark-500",children:s("checkout.fillDetails")})]}),e.jsxs("form",{onSubmit:X,className:"space-y-6",children:[e.jsxs("div",{className:"bg-white rounded-2xl border border-dark-100 p-6 space-y-5",children:[e.jsxs("h2",{className:"text-lg font-semibold text-dark-900 flex items-center gap-2",children:[e.jsx(q,{className:"w-5 h-5 text-primary-500"}),s("checkout.contactInfo")]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsxs("label",{htmlFor:"name",className:"block text-sm font-medium text-dark-700 mb-1.5",children:[s("checkout.fullName")," ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsxs("div",{className:"relative",children:[e.jsx(q,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-dark-400"}),e.jsx("input",{id:"name",type:"text",required:!0,minLength:2,maxLength:255,value:m,onChange:a=>v(a.target.value),placeholder:"John Smith",className:"w-full pl-10 pr-4 py-3 bg-dark-50 border border-dark-200 rounded-xl text-sm focus:outline-none focus:ring-2 focus:ring-primary-500 focus:border-transparent transition"})]})]}),e.jsxs("div",{children:[e.jsxs("label",{htmlFor:"email",className:"block text-sm font-medium text-dark-700 mb-1.5",children:[s("checkout.emailAddress")," ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsxs("div",{className:"relative",children:[e.jsx(te,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-dark-400"}),e.jsx("input",{id:"email",type:"email",required:!0,value:n,onChange:a=>w(a.target.value),placeholder:"john@example.com",className:f("w-full pl-10 pr-4 py-3 bg-dark-50 border rounded-xl text-sm focus:outline-none focus:ring-2 focus:ring-primary-500 focus:border-transparent transition",n&&!b?"border-red-300":"border-dark-200")})]}),n&&!b&&e.jsx("p",{className:"mt-1 text-xs text-red-500",children:s("checkout.invalidEmail")})]}),e.jsxs("div",{children:[e.jsxs("label",{htmlFor:"phone",className:"block text-sm font-medium text-dark-700 mb-1.5",children:[s("checkout.phone")," ",e.jsx("span",{className:"text-dark-400 font-normal",children:s("checkout.optional")})]}),e.jsxs("div",{className:"relative",children:[e.jsx(ae,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-dark-400"}),e.jsx("input",{id:"phone",type:"tel",value:_,onChange:a=>U(a.target.value),placeholder:"+44 7123 456789",className:"w-full pl-10 pr-4 py-3 bg-dark-50 border border-dark-200 rounded-xl text-sm focus:outline-none focus:ring-2 focus:ring-primary-500 focus:border-transparent transition"})]})]})]})]}),e.jsx("div",{className:"bg-white rounded-2xl border border-dark-100 p-6",children:e.jsxs("label",{className:"flex items-start gap-3 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:S,onChange:a=>H(a.target.checked),className:"mt-1 w-4 h-4 rounded border-dark-300 text-primary-600 focus:ring-primary-500"}),e.jsxs("span",{className:"text-sm text-dark-600 leading-relaxed",children:[s("checkout.agreeTerms")," ",e.jsx(i,{to:"/terms",target:"_blank",className:"text-primary-600 underline hover:text-primary-700",children:s("checkout.termsOfService")})," ",s("checkout.and")," ",e.jsx(i,{to:"/privacy",target:"_blank",className:"text-primary-600 underline hover:text-primary-700",children:s("checkout.privacyPolicy")}),". ",s("checkout.stripeRedirect"),(t==null?void 0:t.is_subscription)&&e.jsx("span",{className:"block mt-2 text-dark-500",children:s("checkout.subscriptionNotice",{price:t.price_label})})]})]})}),C&&e.jsxs("div",{className:"flex items-center gap-3 bg-red-50 border border-red-200 rounded-xl p-4",children:[e.jsx(k,{className:"w-5 h-5 text-red-600 shrink-0"}),e.jsx("p",{className:"text-sm text-red-700",children:C})]}),e.jsx("button",{type:"submit",disabled:!g||p,className:f("w-full flex items-center justify-center gap-3 py-4 rounded-xl text-base font-semibold transition-all",g&&!p?"bg-primary-600 text-white hover:bg-primary-700 shadow-lg shadow-primary-600/25 hover:shadow-xl":"bg-dark-200 text-dark-400 cursor-not-allowed"),children:p?e.jsxs(e.Fragment,{children:[e.jsx($,{className:"w-5 h-5 animate-spin"}),s("checkout.redirecting")]}):e.jsxs(e.Fragment,{children:[e.jsx(I,{className:"w-5 h-5"}),t!=null&&t.is_subscription?s("checkout.subscribeNow"):s("checkout.proceedPayment")]})}),e.jsxs("div",{className:"flex flex-wrap items-center justify-center gap-6 text-xs text-dark-400 pt-2",children:[e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(O,{className:"w-3.5 h-3.5"})," ",s("checkout.sslEncrypted")]}),e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(re,{className:"w-3.5 h-3.5"})," ",s("checkout.poweredByStripe")]}),e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(I,{className:"w-3.5 h-3.5"})," ",s("checkout.visaMastercard")]})]})]})]}),e.jsx("div",{className:"lg:col-span-2",children:e.jsxs("div",{className:"sticky top-24 space-y-6",children:[e.jsxs("div",{className:"bg-white rounded-2xl border border-dark-100 overflow-hidden",children:[e.jsxs("div",{className:f("p-6",E?`bg-gradient-to-br ${E.gradient} text-white`:"bg-dark-900 text-white"),children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(ce,{className:"w-5 h-5 opacity-80"}),e.jsx("span",{className:"text-sm font-medium opacity-80",children:s("checkout.orderSummary")})]}),e.jsx("h3",{className:"text-xl font-bold",children:t.title}),e.jsxs("div",{className:"flex flex-wrap gap-2 mt-2",children:[t.is_subscription&&e.jsx("span",{className:"inline-block bg-white/20 backdrop-blur-sm rounded-full px-3 py-1 text-xs font-semibold",children:s("checkout.monthlySubscription")}),t.badge&&e.jsx("span",{className:"inline-block bg-white/20 backdrop-blur-sm rounded-full px-3 py-1 text-xs font-semibold",children:t.badge})]})]}),e.jsxs("div",{className:"p-6 space-y-5",children:[e.jsx("p",{className:"text-sm text-dark-500 leading-relaxed",children:t.short_description}),P.length>0&&e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-widest text-dark-400 mb-3",children:s("checkout.whatsIncluded")}),e.jsx("div",{className:"space-y-2",children:P.map(a=>e.jsxs("div",{className:"flex items-start gap-2 text-sm text-dark-600",children:[e.jsx(le,{className:"w-4 h-4 text-green-500 shrink-0 mt-0.5"}),e.jsx("span",{children:a})]},a))})]}),e.jsxs("div",{className:"border-t border-dark-100 pt-5",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm text-dark-500",children:s("checkout.package")}),e.jsx("span",{className:"text-sm font-medium text-dark-700",children:t.title})]}),t.setup_cents!=null&&t.monthly_cents!=null?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between mt-3",children:[e.jsx("span",{className:"text-sm text-dark-500",children:s("checkout.setupFee")}),e.jsxs("span",{className:"text-sm font-medium text-dark-700",children:[d(t.currency||"gbp"),(t.setup_cents/100).toLocaleString(x(t.currency||"gbp"),{minimumFractionDigits:2})]})]}),e.jsxs("div",{className:"flex items-center justify-between mt-2",children:[e.jsx("span",{className:"text-sm text-dark-500",children:s("checkout.firstMonth")}),e.jsxs("span",{className:"text-sm font-medium text-dark-700",children:[d(t.currency||"gbp"),(t.monthly_cents/100).toLocaleString(x(t.currency||"gbp"),{minimumFractionDigits:2})]})]}),e.jsxs("div",{className:"flex items-center justify-between mt-4 pt-4 border-t border-dark-100",children:[e.jsx("span",{className:"text-base font-semibold text-dark-900",children:s("checkout.dueToday")}),e.jsxs("span",{className:"text-2xl font-bold text-dark-900",children:[d(t.currency||"gbp"),((t.due_today_cents??0)/100).toLocaleString(x(t.currency||"gbp"),{minimumFractionDigits:2})]})]}),e.jsxs("div",{className:"flex items-center justify-between mt-2 text-dark-400",children:[e.jsx("span",{className:"text-xs",children:s("checkout.thenMonthly")}),e.jsxs("span",{className:"text-xs font-medium",children:[d(t.currency||"gbp"),(t.monthly_cents/100).toLocaleString(x(t.currency||"gbp"),{minimumFractionDigits:2}),"/",s("checkout.month")]})]})]}):e.jsxs(e.Fragment,{children:[t.billing_period&&e.jsxs("div",{className:"flex items-center justify-between mt-2",children:[e.jsx("span",{className:"text-sm text-dark-500",children:s("checkout.billing")}),e.jsx("span",{className:"text-sm font-medium text-dark-700",children:t.billing_period})]}),e.jsxs("div",{className:"flex items-center justify-between mt-4 pt-4 border-t border-dark-100",children:[e.jsx("span",{className:"text-base font-semibold text-dark-900",children:t.is_subscription?s("checkout.monthlyTotal"):s("checkout.total")}),e.jsxs("div",{className:"text-right",children:[e.jsx("span",{className:"text-2xl font-bold text-dark-900",children:V||s("checkout.custom")}),t.is_subscription&&e.jsx("span",{className:"block text-xs text-dark-400",children:s("checkout.perMonth")})]})]})]})]})]})]}),!t.can_buy&&e.jsxs("div",{className:"bg-amber-50 border border-amber-200 rounded-xl p-4 flex items-start gap-3",children:[e.jsx(k,{className:"w-5 h-5 text-amber-600 shrink-0 mt-0.5"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-amber-800",children:s("checkout.customPricing")}),e.jsxs("p",{className:"text-sm text-amber-600 mt-1",children:[s("checkout.customPricingDesc")," ",e.jsx(i,{to:`/contact?package=${t.slug}`,className:"underline font-medium",children:s("checkout.contactUs")})," ",s("checkout.toGetStarted")]})]})]}),e.jsxs("div",{className:"text-center text-sm text-dark-400",children:[s("checkout.needHelp")," ",e.jsx(i,{to:"/contact",className:"text-primary-600 underline",children:s("checkout.contactTeam")})]})]})})]})})]})}export{ue as default};