1import{r as a,j as e}from"./vendor-react-CubF7Ysi.js";import{d as Je,s as De}from"./euSize-BTrEwsvb.js";import{u as vs,a as Ns,b as _s,E as Cs}from"./vendor-stripe-BNgkNZiY.js";import{g as ws}from"./stripe-DEsubg-t.js";import{u as ie,dD as Ss,I as V,B as P,a8 as Ts,dE as Es,bR as Is,a1 as ke,E as Ke,bH as E,dF as te,dG as Ie,dH as es,X as He,e as se,b as $s,g as As,d0 as Se,dl as zs,w as qs,dI as Fs,dJ as Ps,dK as Ls,Q as Ve,dp as Rs,A as We,dn as ee,d as Ze,cS as Ms}from"./index-yVRJ_DrD.js";import{T as Os,a as Us}from"./TenantShopFooter-68UB358I.js";import{u as Bs,a as Gs,I as Ks,z as Hs}from"./InternalShopPasswordGate-BLXqdw2s.js";import{i as ss,h as ts}from"./productImageUtils-DxMcZJ5V.js";import{P as rs}from"./ProductImageWithDesign-NVc3t3BQ.js";import{L as B}from"./label-27wMobMv.js";import{C as Vs}from"./checkbox-BpTduARK.js";import{S as Ws,a as Zs,b as Qs,c as Xs,d as Ys}from"./select-BiQnKDc7.js";import{e as Js,D as Qe,n as Te,c as Ds}from"./euCountries-CGux-ZIL.js";import{B as et}from"./building-2-CMDz8xPl.js";import{Z as st}from"./zahlarten-BHXIxIUm.js";import{t as ae,u as tt,a as rt,E as ot,s as ct}from"./ExpressKauf-DaXf_DyK.js";import{e as nt}from"./expressKauf-C5C0zYNO.js";import{S as lt}from"./separator-BvmZW9lC.js";import{S as os}from"./shopping-cart-Jx5S5v-y.js";import{T as Xe}from"./tag-CnZ03BZD.js";import{a as at}from"./vendor-query-BtJS4VZ-.js";import{c as it}from"./internalPricing-CHTAnQYm.js";import{T as dt}from"./trash-2-B7ybl0kH.js";import"./vendor-supabase-C5Zeq6fY.js";import"./vendor-motion-DUPVpWKG.js";import"./award-B7jvboRv.js";import"./useActiveTenantCampaign-DN4NAjqf.js";import"./schema-CG3dLAws.js";import"./types-D44efjDd.js";import"./ColorizedMockup-B4Li3Opb.js";function ut({initialData:c,onSubmit:f,isLoading:w=!1,primaryColor:v,foregroundColor:t,accentColor:S="#f59e0b",backgroundColor:g="#ffffff"}){const{t:n,i18n:o}=ie("shop"),T=Js(o.language),p=Ss(g,v,S),[h,L]=a.useState((c==null?void 0:c.email)||""),[b,R]=a.useState((c==null?void 0:c.shippingAddress)||{name:"",street:"",zip:"",city:"",country:Qe}),[j,A]=a.useState((c==null?void 0:c.billingDifferent)||!1),[N,i]=a.useState((c==null?void 0:c.billingAddress)||{name:"",street:"",zip:"",city:"",country:Qe}),[x,m]=a.useState((c==null?void 0:c.phone)||""),[y,O]=a.useState((c==null?void 0:c.company)||""),[_,de]=a.useState((c==null?void 0:c.vatId)||""),[ue,me]=a.useState(!!(c!=null&&c.company)||!!(c!=null&&c.vatId)),[I,he]=a.useState({}),ve=()=>{const l={};return(!h||!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(h))&&(l.email=n("checkout.address.emailError")),b.name.trim()||(l["shipping.name"]=n("checkout.address.required")),b.street.trim()||(l["shipping.street"]=n("checkout.address.required")),b.zip.trim()||(l["shipping.zip"]=n("checkout.address.required")),b.city.trim()||(l["shipping.city"]=n("checkout.address.required")),Te(b.country)||(l["shipping.country"]=n("checkout.address.countryError")),j&&(N.name.trim()||(l["billing.name"]=n("checkout.address.required")),N.street.trim()||(l["billing.street"]=n("checkout.address.required")),N.zip.trim()||(l["billing.zip"]=n("checkout.address.required")),N.city.trim()||(l["billing.city"]=n("checkout.address.required")),Te(N.country)||(l["billing.country"]=n("checkout.address.countryError"))),he(l),Object.keys(l).length===0},W=l=>{l.preventDefault(),ve()&&f({email:h,shippingAddress:b,billingDifferent:j,billingAddress:j?N:void 0,phone:x||void 0,company:y||void 0,vatId:_||void 0})},U={borderColor:`${t}30`,color:t,backgroundColor:"transparent"},z={color:t},re=(l,M,Z)=>e.jsxs("div",{className:"grid gap-3",children:[e.jsxs("div",{children:[e.jsx(B,{htmlFor:`${l}-name`,style:z,children:n("checkout.address.fullName")}),e.jsx(V,{id:`${l}-name`,value:M.name,onChange:C=>Z({...M,name:C.target.value}),placeholder:n("checkout.address.fullNamePlaceholder"),style:U}),I[`${l}.name`]&&e.jsx("p",{className:"text-xs text-destructive mt-1",children:I[`${l}.name`]})]}),e.jsxs("div",{children:[e.jsx(B,{htmlFor:`${l}-street`,style:z,children:n("checkout.address.street")}),e.jsx(V,{id:`${l}-street`,value:M.street,onChange:C=>Z({...M,street:C.target.value}),placeholder:n("checkout.address.streetPlaceholder"),style:U}),I[`${l}.street`]&&e.jsx("p",{className:"text-xs text-destructive mt-1",children:I[`${l}.street`]})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[e.jsxs("div",{children:[e.jsx(B,{htmlFor:`${l}-zip`,style:z,children:n("checkout.address.zip")}),e.jsx(V,{id:`${l}-zip`,value:M.zip,onChange:C=>Z({...M,zip:C.target.value}),placeholder:n("checkout.address.zipPlaceholder"),style:U}),I[`${l}.zip`]&&e.jsx("p",{className:"text-xs text-destructive mt-1",children:I[`${l}.zip`]})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx(B,{htmlFor:`${l}-city`,style:z,children:n("checkout.address.city")}),e.jsx(V,{id:`${l}-city`,value:M.city,onChange:C=>Z({...M,city:C.target.value}),placeholder:n("checkout.address.cityPlaceholder"),style:U}),I[`${l}.city`]&&e.jsx("p",{className:"text-xs text-destructive mt-1",children:I[`${l}.city`]})]})]}),e.jsxs("div",{children:[e.jsx(B,{htmlFor:`${l}-country`,style:z,children:n("checkout.address.country")}),e.jsxs(Ws,{value:Te(M.country)??"",onValueChange:C=>Z({...M,country:C}),children:[e.jsx(Zs,{id:`${l}-country`,style:U,children:e.jsx(Qs,{placeholder:n("checkout.address.countryPlaceholder")})}),e.jsx(Xs,{children:T.map(C=>
1e.jsx(Ys,{value:C.code,children:C.label},C.code))})]}),I[`${l}.country`]&&e.jsx("p",{className:"text-xs text-destructive mt-1",children:I[`${l}.country`]})]})]});return e.jsxs("form",{onSubmit:W,className:"space-y-6",children:[e.jsxs("div",{className:"rounded-lg border p-4 space-y-3",style:{borderColor:`${t}20`},children:[e.jsx("h3",{className:"font-semibold text-sm uppercase tracking-wider",style:{color:t,opacity:.7},children:n("checkout.address.contact")}),e.jsxs("div",{children:[e.jsx(B,{htmlFor:"email",style:z,children:n("checkout.address.email")}),e.jsx(V,{id:"email",type:"email",value:h,onChange:l=>L(l.target.value),placeholder:n("checkout.address.emailPlaceholder"),style:U}),I.email&&e.jsx("p",{className:"text-xs text-destructive mt-1",children:I.email})]}),e.jsxs("div",{children:[e.jsxs(B,{htmlFor:"phone",style:z,children:[n("checkout.address.phone")," ",e.jsx("span",{className:"text-xs opacity-50",children:n("checkout.address.optional")})]}),e.jsx(V,{id:"phone",type:"tel",value:x,onChange:l=>m(l.target.value),placeholder:n("checkout.address.phonePlaceholder"),style:U})]})]}),e.jsxs("div",{className:"rounded-lg border p-4 space-y-3",style:{borderColor:`${t}20`},children:[e.jsx("h3",{className:"font-semibold text-sm uppercase tracking-wider",style:{color:t,opacity:.7},children:n("checkout.address.shippingAddress")}),re("shipping",b,R)]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Vs,{id:"billing-different",checked:j,onCheckedChange:l=>A(!!l)}),e.jsx(B,{htmlFor:"billing-different",className:"text-sm cursor-pointer",style:z,children:n("checkout.address.billingDifferent")})]}),j&&e.jsxs("div",{className:"rounded-lg border p-4 space-y-3",style:{borderColor:`${t}20`},children:[e.jsx("h3",{className:"font-semibold text-sm uppercase tracking-wider",style:{color:t,opacity:.7},children:n("checkout.address.billingAddress")}),re("billing",N,i)]}),e.jsxs("div",{className:"rounded-lg border p-4 space-y-3",style:{borderColor:`${t}20`},children:[e.jsxs("button",{type:"button",className:"flex items-center gap-2 text-sm font-medium w-full",onClick:()=>me(!ue),style:{color:t,opacity:.7},children:[e.jsx(et,{className:"h-4 w-4"}),n("checkout.address.businessCustomer"),e.jsx("span",{className:"text-xs opacity-50",children:n("checkout.address.optional")})]}),ue&&e.jsxs("div",{className:"grid gap-3 mt-2",children:[e.jsxs("div",{children:[e.jsx(B,{htmlFor:"company",style:z,children:n("checkout.address.companyName")}),e.jsx(V,{id:"company",value:y,onChange:l=>O(l.target.value),placeholder:n("checkout.address.companyPlaceholder"),style:U})]}),e.jsxs("div",{children:[e.jsx(B,{htmlFor:"vat-id",style:z,children:n("checkout.address.vatId")}),e.jsx(V,{id:"vat-id",value:_,onChange:l=>de(l.target.value),placeholder:n("checkout.address.vatIdPlaceholder"),style:U})]})]})]}),e.jsxs(P,{type:"submit",className:"w-full text-base",size:"lg",disabled:w,style:{backgroundColor:p,color:Es(p)},children:[n("checkout.address.continueToPayment"),e.jsx(Ts,{className:"h-4 w-4 ml-2"})]})]})}function mt({totalCents:c,successUrl:f,foregroundColor:w,ctaSurface:v,ctaText:t,shopName:S,tenantId:g,cartId:n=null,itemCount:o=0}){const{t:T}=ie("shop"),p=vs(),h=Ns(),[L,b]=a.useState(!1),[R,j]=a.useState(null),A=a.useRef(null),[N,i]=a.useState(!1),x=y=>{var _;const O=((_=y.value)==null?void 0:_.type)??null;O!==A.current&&(A.current=O,j(null))},m=async y=>{if(y.preventDefault(),!p||!h)return;b(!0),j(null);const O={cartId:n,itemCount:o,totalCents:c};ae(g,"payment_attempt",O);const{error:_}=await p.confirmPayment({elements:h,confirmParams:{return_url:f}});_&&(ae(g,"payment_error",{...O,errorCode:_.code||_.decline_code||_.type||"unknown"}),_.type==="card_error"?j(_.message||T("checkout.payment.cardError")):_.type!=="validation_error"&&j(T("checkout.payment.unexpectedError"))),b(!1)};return e.jsxs("form",{onSubmit:m,className:"space-y-5",children:[e.jsx(_s,{onReady:()=>i(!0),onChange:x,options:{layout:{type:"accordion",defaultCollapsed:!1,radios:"always",spacedAccordionItems:!1},business:{name:S},paymentMethodOrder:st}}),R&&e.jsxs("p",{role:"alert",className:"flex items-start gap-2 text-sm text-destructive",children:[e.jsx(Is,{className:"h-4 w-4 mt-0.5 shrink-0"}),e.jsx("span",{children:R})]}),e.jsx(P,{type:"submit",className:"w-full text-base",size:"lg",disabled:!p||!h||!N||L,style:{backgroundColor:v,color:t},children:L?e.jsxs(e.Fragment,{children:[e.jsx(ke,{className:"h-4 w-4 mr-2 animate-spin"}),T("checkout.payment.processing")]}):e.jsxs(e.Fragment,{children:[e.jsx(Ke,{className:"h-4 w-4 mr-2"}),T("checkout.payment.payNow",{price:E(c/100)})]})}),e.jsxs("p",{className:"flex items-start gap-2 text-xs leading-relaxed",style:{color:w,opacity:.6},children:[e.jsx(Ke,{className:"h-3.5 w-3.5 mt-0.5 shrink-0"}),e.jsx("span",{children:T("checkout.payment.merchantNotice")})]})]})}function Ye({items:c,total:f,shippingCents:w,foregroundColor:v,primaryColor:t,accentTextColor:S,formData:g,savings:n=0,codeDiscount:o=null,promoSlot:T}){const{t:p,i18n:h}=ie("shop"),L=!o&&n>.005,b=i=>o?es(i):i.price_at_add,R=i=>{const x=i.product;if(!x)return null;const m=x.catalog_products;return ts(x.print_file_metadata,"front",m==null?void 0:m.images_json,i.selected_variant_color??null)},j=i=>{if(!i.product)return p("common.product");const x=i.product.catalog_products;return i.product.title_override||(x==null?void 0:x.title)||p("common.product")},A=o?Math.min(o.amount,f):0,N=f-A+w/100;return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"rounded-lg border p-4 space-y-3",style:{borderColor:`${v}20`},children:[e.jsxs("h3",{className:"font-semibold text-sm uppercase tracking-wider flex items-center gap-2",style:{color:v,opacity:.7},children:[e.jsx(os,{className:"h-4 w-4"}),p("checkout.summary.orderTitle",{count:c.length,itemLabel:c.length===1?p("checkout.summary.itemSingular"):p("checkout.summary.itemPlural")})]}),c.map(i=>{var y;const x=R(i),m=ss(x??{displayMode:"product_only",productImageUrl:"/placeholder.svg"});return e.jsxs("div",{className:"flex gap-3 py-2 border-b last:border-b-0",style:{borderColor:`${v}10`},children:[x&&x.displayMode!=="product_only"?e.jsx(rs,{result:x,alt:j(i),imgClassName:"w-14 h-14 object-cover rounded"}):e.jsx("img",{src:m,alt:j(i),className:"w-14 h-14 object-cover rounded"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium truncate",children:j(i)}),(i.selected_variant_color||i.selected_variant_size)&&e.jsx("p",{className:"text-xs",style:{opacity:.5},children:[i.selected_variant_color,i.selected_variant_size?Je(i.selected_variant_size,De((y=i.product)==null?void 0:y.catalog_products)):null].filter(
1Boolean).join(" | ")}),e.jsx("p",{className:"text-xs",style:{opacity:.5},children:p("checkout.summary.quantity",{count:i.quantity})})]}),e.jsxs("span",{className:"text-sm font-medium whitespace-nowrap",children:[E(b(i)*i.quantity)," â¬"]})]},i.id)})]}),e.jsxs("div",{className:"rounded-lg border p-4 space-y-2",style:{borderColor:`${v}20`},children:[e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsx("span",{children:p("checkout.summary.subtotal")}),e.jsxs("span",{children:[E(f)," â¬"]})]}),o&&e.jsxs("div",{className:"flex justify-between text-sm font-semibold",style:{color:te},children:[e.jsx("span",{children:p("checkout.promo.discountLine",{code:o.code})}),e.jsxs("span",{children:["â",E(A)," â¬"]})]}),e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsx("span",{children:p("checkout.summary.shipping")}),e.jsxs("span",{children:[E(w/100)," â¬"]})]}),T&&e.jsx("div",{className:"pt-1",children:T}),e.jsx(lt,{}),e.jsxs("div",{className:"flex justify-between text-lg font-bold",children:[e.jsx("span",{children:p("checkout.summary.total")}),e.jsxs("span",{style:{color:S??t},children:[E(N)," â¬"]})]}),L&&e.jsxs("div",{className:"flex items-center gap-1.5 text-sm font-semibold rounded-md px-2.5 py-1.5",style:{color:te,backgroundColor:Ie},children:["ð ",p("product.youSave",{amount:E(n)})]}),e.jsx("p",{className:"text-xs",style:{opacity:.5},children:p("checkout.summary.vatNotice")})]}),g&&e.jsxs("div",{className:"rounded-lg border p-4 space-y-2 text-sm",style:{borderColor:`${v}20`},children:[e.jsx("h3",{className:"font-semibold text-xs uppercase tracking-wider",style:{opacity:.7},children:p("checkout.summary.shippingAddress")}),e.jsxs("div",{style:{opacity:.8},children:[e.jsx("p",{children:g.shippingAddress.name}),g.company&&e.jsx("p",{children:g.company}),e.jsx("p",{children:g.shippingAddress.street}),e.jsxs("p",{children:[g.shippingAddress.zip," ",g.shippingAddress.city]}),e.jsx("p",{children:Ds(g.shippingAddress.country,h.language)})]}),e.jsx("p",{className:"text-xs",style:{opacity:.5},children:g.email})]})]})}function ht({appliedCode:c,status:f,discountTotal:w,minOrderShortfallCents:v,minOrderValueCents:t,onApply:S,onRemove:g,onRetry:n,foregroundColor:o,ctaSurface:T,ctaText:p}){const{t:h}=ie("shop"),[L,b]=a.useState(c??""),R={borderColor:`${o}30`,color:o,backgroundColor:"transparent"},j=()=>{const y=L.trim().toUpperCase();y&&S(y)},A=()=>{b(""),g()};if(f==="valid"&&v<=0&&w>.005&&c)return e.jsxs("div",{className:"flex items-center justify-between gap-2 rounded-md px-2.5 py-1.5 text-sm font-semibold",style:{color:te,backgroundColor:Ie},children:[e.jsxs("span",{className:"flex items-center gap-1.5 min-w-0",children:[e.jsx(Xe,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{className:"truncate",children:h("checkout.promo.applied",{code:c})}),e.jsx("span",{className:"whitespace-nowrap",children:h("checkout.promo.appliedDiscount",{amount:E(w)})})]}),e.jsx("button",{type:"button",onClick:A,"aria-label":h("checkout.promo.remove"),title:h("checkout.promo.remove"),className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-md hover:opacity-70",style:{color:te},children:e.jsx(He,{className:"h-4 w-4"})})]});let i=null,x=!1;f==="checking"?i=h("checkout.promo.checking"):f==="valid"&&v>0?i=h("checkout.promo.minOrder",{amount:E(t/100)}):f==="valid"?i=h("checkout.promo.noCoveredItems"):f==="invalid"?(i=h("checkout.promo.invalid"),x=!0):f==="error"&&(i=h("checkout.promo.lookupFailed"),x=!0);const m=f==="checking";return e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(B,{htmlFor:"checkout-promo-code",className:"flex items-center gap-1.5 text-sm",style:{color:o},children:[e.jsx(Xe,{className:"h-3.5 w-3.5"}),h("checkout.promo.label")]}),e.jsxs("form",{className:"flex gap-2",onSubmit:y=>{y.preventDefault(),f==="error"?n():j()},children:[e.jsx(V,{id:"checkout-promo-code",value:L,onChange:y=>b(y.target.value.toUpperCase()),placeholder:h("checkout.promo.placeholder"),maxLength:50,autoComplete:"off",autoCapitalize:"characters",spellCheck:!1,disabled:m,"aria-invalid":x||void 0,style:R}),e.jsx(P,{type:"submit",disabled:m||!L.trim(),className:"shrink-0",style:{backgroundColor:T,color:p},children:m?e.jsx(ke,{className:"h-4 w-4 animate-spin"}):h("checkout.promo.apply")}),f==="valid"&&c&&e.jsx(P,{type:"button",variant:"ghost",size:"icon",onClick:A,"aria-label":h("checkout.promo.remove"),title:h("checkout.promo.remove"),className:"shrink-0 hover:bg-transparent",style:{color:o},children:e.jsx(He,{className:"h-4 w-4"})})]}),i&&e.jsx("p",{className:"text-xs",role:x?"alert":void 0,style:x?{color:"hsl(0 84% 60%)"}:{color:o,opacity:.7},children:i})]})}function pt(c,f){const w=(f??"").trim().toUpperCase(),v=!!c&&w.length>0,t=at({queryKey:["storefront_campaign_code",c,w],enabled:v,staleTime:6e4,retry:1,queryFn:async()=>{const{data:g,error:n}=await se.rpc("storefront_campaign_by_code",{p_tenant_id:c,p_code:w});if(n)throw n;const o=g==null?void 0:g[0];return o?{id:o.id,discount_type:o.discount_type,discount_value:Number(o.discount_value),funding_mode:o.funding_mode,scope:o.scope,productIds:o.product_ids??[],min_order_value_cents:o.min_order_value_cents??null}:null}});let S="idle";return v&&(t.isPending?S="checking":t.isError?S="error":S=t.data?"valid":"invalid"),{status:S,campaign:S==="valid"?t.data??null:null,retry:()=>{t.refetch()}}}const Ee=c=>`checkout:aktionscode:${c}`,xt={campaign_code_invalid:"checkout.errors.campaignCodeInvalid",campaign_code_not_applicable:"checkout.errors.campaignCodeNotApplicable"};function yt(c){switch(c){case"nicht_berechtigt":return"checkout.request.errors.notAllowed";case"kein_freigabemodus":case"nicht_verfuegbar":return"checkout.request.errors.noMode";case"budget_ueberschritten":return"checkout.request.errors.budget";case"zu_viele_anfragen":return"checkout.request.errors.tooMany";default:return"checkout.request.errors.generic"}}function Zt({subdomain:c,isLocalDevRoute:f=!1}){var Oe,Ue;const w=$s(),v=As(),{t,i18n:S}=ie("shop"),g=a.useRef(null),[n]=a.useState(()=>
1ws()),[o,T]=a.useState(null),[p,h]=a.useState(null),[L,b]=a.useState(!0),[R,j]=a.useState(!1),[A,N]=a.useState(null),[i,x]=a.useState(!1),[m,y]=a.useState("cart"),[O,_]=a.useState(null),[de,ue]=a.useState(""),[me,I]=a.useState(""),[he,ve]=a.useState(null),[W,U]=a.useState(null),[z,re]=a.useState(null),[l,M]=a.useState(0),[Z,C]=a.useState(null),[H,cs]=a.useState(()=>Se.getItem(Ee(c))),$e=s=>{cs(s),s?Se.setItem(Ee(c),s):Se.removeItem(Ee(c))},{cart:r,removeFromCart:ns,updateQuantity:Ae,clearCart:gt}=zs(),Q=qs(),oe=tt(),{zugang:ze,freischalten:ls}=Bs(o),{colors:as,actions:is,header:ds,footer:us,activeCampaign:qe}=Gs(o,p),{savingsTotal:pe}=a.useMemo(()=>Fs((r==null?void 0:r.items)??[],qe??null),[r==null?void 0:r.items,qe]),J=pt(o==null?void 0:o.id,H),ce=a.useMemo(()=>Ps((r==null?void 0:r.items)??[],J.campaign),[r==null?void 0:r.items,J.campaign]),Fe=Ls(J.campaign,ce.regularSubtotal),Ne=!!H&&J.status==="valid"&&Fe<=0&&ce.discountTotal>.005,q=Ne&&H?{code:H,amount:ce.discountTotal}:null,xe=q?ce.regularSubtotal:(r==null?void 0:r.total)??0,ms=f||v.pathname.startsWith("/shop/"),D=rt(ms?(o==null?void 0:o.slug)??null:null),Pe=a.useRef(!1),Le=a.useRef(new Set);a.useEffect(()=>{!(o!=null&&o.id)||!r||r.items.length===0||Pe.current||(Pe.current=!0,ae(o.id,"checkout_started",{cartId:r.id,itemCount:r.items.length,totalCents:Math.round(r.total*100)}))},[o==null?void 0:o.id,r]),a.useEffect(()=>{if(!(o!=null&&o.id))return;const u={address:"address_shown",payment:"payment_shown"}[m];!u||Le.current.has(m)||(Le.current.add(m),ae(o.id,u,{cartId:(r==null?void 0:r.id)??null,itemCount:(r==null?void 0:r.items.length)??0,totalCents:Math.round(((r==null?void 0:r.total)??0)*100)}))},[m,o==null?void 0:o.id,r]),a.useEffect(()=>{window.scrollTo(0,0),hs()},[c]);const hs=async()=>{try{const{data:s}=await se.from("tenants").select("*").eq("subdomain",c).maybeSingle();if(!s){N(t("checkout.errors.shopNotFound")),b(!1);return}if(oe&&!Ve(s)){N(t("checkout.errors.shopNotFound")),b(!1);return}if(!oe&&!s.subdomain_enabled){const k=await Rs(c);if(!k){N(t("checkout.errors.shopNotFound")),b(!1);return}T(s),h(k.site),x(!0);return}if(T(s),oe&&Ve(s)){const{data:k,error:$}=await se.from("tenant_internal_products").select("tenant_product_id,preis_modus,interner_preis_cents").eq("tenant_id",s.id).eq("aktiv",!0);$&&console.error("[TenantShopCheckout] Interne Angebote nicht lesbar:",$.message),_(new Map((k??[]).map(G=>[G.tenant_product_id,{preis_modus:G.preis_modus,interner_preis_cents:G.interner_preis_cents}])))}else _(new Map);const{data:u}=await se.from("tenant_sites").select("*").eq("tenant_id",s.id).maybeSingle();h(u)}catch(s){N(s.message)}finally{b(!1)}},ps=async()=>{if(!(!r||r.items.length===0||!o||!W)){j(!0);try{const s=r.items.map($=>{var be;const G=(be=$.product)==null?void 0:be.catalog_products;return{tenantProductId:$.tenant_product_id,sku:(G==null?void 0:G.sku)||"",quantity:$.quantity,variant_color:$.selected_variant_color||void 0,variant_size:$.selected_variant_size||void 0}});if(s.some($=>!$.sku))throw new Error(t("checkout.errors.productsNotIdentified"));const{data:u,error:k}=await se.functions.invoke("internal-order-request",{body:{tenantId:o.id,besteller:{name:W.shippingAddress.name,email:W.email}
1,positionen:s,lieferadresse:W.shippingAddress,kostenstelle:de.trim()||null,begruendung:me.trim()||null,zugangsNachweis:Hs(o.id)}});if(k)throw new Error(k.message);if(!(u!=null&&u.ok))throw new Error(t(yt(u==null?void 0:u.fehler)));ve(String(u.nummer??"")),y("gesendet")}catch(s){Ze.error((s==null?void 0:s.message)||t("checkout.request.errors.generic"))}finally{j(!1)}}},xs=a.useMemo(()=>!O||!r||r.items.length===0?null:it(r.items.map(s=>O.get(s.tenant_product_id??"")??null)),[O,r]),ys=async s=>{var u;if(!(!r||r.items.length===0||!o)){if(U(s),xs){y("anforderung");return}j(!0),ae(o.id,"address_submitted",{cartId:r.id,itemCount:r.items.length,totalCents:Math.round(r.total*100)});try{const k=r.items.map(K=>{var Ge;const we=(Ge=K.product)==null?void 0:Ge.catalog_products;return{tenantProductId:K.tenant_product_id,sku:(we==null?void 0:we.sku)||"",quantity:K.quantity,variant_color:K.selected_variant_color||void 0,variant_size:K.selected_variant_size||void 0}});if(k.filter(K=>!K.sku).length>0)throw new Error(t("checkout.errors.productsNotIdentified"));const G=window.location.origin,be=`${G}${ee(D,"/checkout/erfolg")}`,ks=`${G}${ee(D,"/checkout/abgebrochen")}`,{data:F,error:Be}=await se.functions.invoke("checkout-hybrid",{body:{shopId:o.id,items:k,customerEmail:s.email,customerName:s.shippingAddress.name,shippingAddress:s.shippingAddress,billingAddress:s.billingDifferent?s.billingAddress:void 0,phone:s.phone,company:s.company,vatId:s.vatId,isSampleOrder:!1,discountCode:Ne&&H?H:void 0,successUrl:be,cancelUrl:ks,internerBlick:oe}});if(Be)throw Be;if(F!=null&&F.clientSecret)re(F.clientSecret),M(F.totalGrossCents),C(typeof F.campaignDiscountCents=="number"?F.campaignDiscountCents:null),y("payment"),window.scrollTo(0,0);else if(F!=null&&F.error){const K=F.errorCode?xt[String(F.errorCode)]:void 0;throw new Error(K?t(K):F.error)}else throw new Error(t("checkout.errors.noPaymentData"))}catch(k){Ms(k,{area:"tenant-shop-checkout",tenantId:(o==null?void 0:o.id)??null,extra:{itemCount:((u=r==null?void 0:r.items)==null?void 0:u.length)??0,cartTotal:(r==null?void 0:r.total)??0,tenantSlug:(o==null?void 0:o.slug)??null}}),Ze.error(k.message||t("checkout.errors.createOrderFailed"))}finally{j(!1)}}},ye=()=>{w(ee(D,"/"))},gs=()=>{y("address"),re(null),C(null),window.scrollTo(0,0)},{primary:ne,accent:fs,background:X,foreground:d}=as,{ctaSurface:Y,ctaText:ge,accentText:le}=is,js=s=>{const u=s.product;if(!u)return null;const k=u.catalog_products;return ts(u.print_file_metadata,"front",k==null?void 0:k.images_json,s.selected_variant_color??null)},_e=s=>{if(!s.product)return t("common.product");const u=s.product.catalog_products;return s.product.title_override||(u==null?void 0:u.title)||t("common.product")};if(L)return e.jsx("div",{className:"min-h-screen flex items-center justify-center",style:{backgroundColor:X},children:e.jsx(ke,{className:"h-8 w-8 animate-spin",style:{color:le}})});if(A||!o)return e.jsx("div",{className:"min-h-screen flex items-center justify-center",style:{backgroundColor:X},children:e.jsx("p",{style:{color:d},children:A||t("checkout.errors.shopNotFound")})});if(i)return e.jsx("div",{className:"min-h-screen flex items-center justify-center px-4",style:{backgroundColor:X},children:e.jsxs("div",{className:"max-w-md text-center space-y-4",children:[e.jsx("h1",{className:"text-2xl font-bold",style:{color:d},children:t("vorschau.kasseTitel")}),e.jsx("p",{style:{color:d},children:t("vorschau.kasseText")}),e.jsxs(P,{variant:"outline",onClick:ye,children:[e.jsx(We,{className:"h-4 w-4 mr-2"}),t("checkout.backToShop")]})]})});if(ze!=="offen")return ze==="gesperrt"?e.jsx(Ks,{tenantId:o.id,shopName:o.display_name,logoUrl:p==null?void 0:p.logo_url,onUnlock:ls}):e.jsx("div",{className:"min-h-screen flex items-center justify-center",style:{backgroundColor:X},children:e.jsx(ke,{className:"h-8 w-8 animate-spin",style:{color:le}})});const bs=!r||r.items.length===0,fe=500,Re=`${window.location.origin}${ee(D,"/checkout/erfolg")}`,Me=e.jsx(ht,{appliedCode:H,status:J.status,discountTotal:ce.discountTotal,minOrderShortfallCents:Fe,minOrderValueCents:Number(((Oe=J.campaign)==null?void 0:Oe.min_order_value_cents)??0)||0,onApply:$e,onRemove:()=>$e(null),onRetry:J.retry,foregroundColor:d,ctaSurface:Y,ctaText:ge}),Ce=[{key:"cart",label:t("checkout.steps.cart")},{key:"address",label:t("checkout.steps.address")},{key:"payment",label:t("checkout.steps.payment")}],je=Ce.findIndex(s=>s.key===m);return e.jsxs("div",{ref:g,className:"min-h-screen flex flex-col",style:{backgroundColor:X,color:d},children:[e.jsx(Os,{...ds,onCartClick:()=>{y("cart"),window.scrollTo(0,0)},cartItemCount:(r==null?void 0:r.itemCount)||0,isMobile:Q,portalContainer:g.current,isPreview:!1,shopBasePath:ee(D,"/")}),e.jsxs("main",{className:"flex-1 max-w-4xl mx-auto w-full px-4 py-8",children:[e.jsxs(P,{variant:"ghost",className:"mb-4 hover:bg-transparent",onClick:m==="cart"?ye:()=>{m==="address"?y("cart"):gs(),window.scrollTo(0,0)},style:{color:d},onMouseEnter:s=>{s.currentTarget.style.backgroundColor=`${d}1a`},onMouseLeave:s=>{s.currentTarget.style.backgroundColor="transparent"},children:[e.jsx(We,{className:"h-4 w-4 mr-2"}),t(m==="cart"?"checkout.backToShop":m==="address"?"checkout.backToCart":"checkout.backToAddress")]}),e.jsx("div",{className:"flex items-center gap-2 mb-8",children:Ce.map((s,u)=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"flex items-center justify-center w-7 h-7 rounded-full text-xs font-bold transition-colors",style:{backgroundColor:u<=je?Y:`${d}15`,color:u<=je?"#fff":d},children:u+1}),e.jsx("span",{className:"text-sm font-medium hidden sm:inline",style:{color:d,opacity:u<=je?1:.4}
1,children:s.label}),u<Ce.length-1&&e.jsx("div",{className:"w-8 h-0.5 mx-1",style:{backgroundColor:u<je?Y:`${d}20`}})]},s.key))}),bs&&m==="cart"?e.jsxs("div",{className:"text-center py-16",children:[e.jsx(os,{className:"h-16 w-16 mx-auto mb-4",style:{color:d,opacity:.3}}),e.jsx("p",{className:"text-lg mb-4",style:{color:d,opacity:.6},children:t("checkout.emptyCart")}),e.jsx(P,{onClick:ye,style:{backgroundColor:Y,color:ge},children:t("checkout.continueShopping")})]}):e.jsxs(e.Fragment,{children:[m==="cart"&&e.jsxs("div",{className:"space-y-6",children:[e.jsx("h1",{className:"text-2xl font-bold",style:{color:d},children:t("checkout.cartTitle")}),e.jsx("div",{className:"rounded-lg border p-4 space-y-4",style:{borderColor:`${d}20`},children:r.items.map(s=>{var $;const u=js(s),k=ss(u??{displayMode:"product_only",productImageUrl:"/placeholder.svg"});return e.jsxs("div",{className:"flex gap-4 py-3 border-b last:border-b-0",style:{borderColor:`${d}10`},children:[u&&u.displayMode!=="product_only"?e.jsx(rs,{result:u,alt:_e(s),imgClassName:"w-20 h-20 object-cover rounded"}):e.jsx("img",{src:k,alt:_e(s),className:"w-20 h-20 object-cover rounded"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h3",{className:"font-medium truncate",children:_e(s)}),(s.selected_variant_color||s.selected_variant_size)&&e.jsxs("p",{className:"text-sm mt-0.5",style:{opacity:.6},children:[s.selected_variant_color&&t("checkout.colorLabel",{color:s.selected_variant_color}),s.selected_variant_color&&s.selected_variant_size&&" | ",s.selected_variant_size&&t("checkout.sizeLabel",{size:Je(s.selected_variant_size,De(($=s.product)==null?void 0:$.catalog_products))})]}),e.jsxs("div",{className:"flex items-center justify-between mt-2",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(P,{variant:"outline",size:"icon",className:"h-7 w-7",onClick:()=>Ae(s.id,s.quantity-1),children:"-"}),e.jsx("span",{className:"w-8 text-center text-sm",children:s.quantity}),e.jsx(P,{variant:"outline",size:"icon",className:"h-7 w-7",onClick:()=>Ae(s.id,s.quantity+1),children:"+"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"font-medium",children:[E((q?es(s):s.price_at_add)*s.quantity)," â¬"]}),e.jsx(P,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:()=>ns(s.id),children:e.jsx(dt,{className:"h-4 w-4"})})]})]})]})]},s.id)})}),e.jsxs("div",{className:"rounded-lg border p-4 space-y-2",style:{borderColor:`${d}20`},children:[e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsx("span",{children:t("checkout.subtotal")}),e.jsxs("span",{children:[E(xe)," â¬"]})]}),q&&e.jsxs("div",{className:"flex justify-between text-sm font-semibold",style:{color:te},children:[e.jsx("span",{children:t("checkout.promo.discountLine",{code:q.code})}),e.jsxs("span",{children:["â",E(q.amount)," â¬"]})]}),e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsx("span",{children:t("checkout.shipping")}),e.jsxs("span",{children:[E(fe/100)," â¬"]})]}),e.jsx("div",{className:"pt-1",children:Me}),e.jsx("div",{className:"h-px w-full",style:{backgroundColor:`${d}15`}}),e.jsxs("div",{className:"flex justify-between text-lg font-bold",children:[e.jsx("span",{children:t("checkout.total")}),e.jsxs("span",{style:{color:le},children:[E(xe-((q==null?void 0:q.amount)??0)+fe/100)," â¬"]})]}),!q&&pe>.005&&e.jsxs("div",{className:"flex items-center gap-1.5 text-sm font-semibold rounded-md px-2.5 py-1.5",style:{color:te,backgroundColor:Ie},children:["ð ",t("product.youSave",{amount:E(pe)})]}),e.jsx("p",{className:"text-xs",style:{opacity:.5},children:t("checkout.vatNotice")})]}),e.jsx(P,{className:"w-full text-base",size:"lg",onClick:()=>{y("address"),window.scrollTo(0,0)},style:{backgroundColor:Y,color:ge},children:t("checkout.continueToAddress")}),!oe&&e.jsx(ot,{tenantId:o.id,artikel:nt(r==null?void 0:r.items),discountCode:Ne&&H?H:void 0,successUrl:Re,cancelUrl:`${window.location.origin}${ee(D,"/checkout/abgebrochen")}`,backgroundColor:X,foregroundColor:d,ctaSurface:Y})]}),m==="address"&&e.jsxs("div",{className:`grid gap-8 ${Q?"":"lg:grid-cols-5"}`,children:[e.jsxs("div",{className:Q?"":"lg:col-span-3",children:[e.jsx("h1",{className:"text-2xl font-bold mb-6",style:{color:d},children:t("checkout.shippingTitle")}),e.jsx(ut,{initialData:W||void 0,onSubmit:ys,isLoading:R,primaryColor:ne,foregroundColor:d,accentColor:fs,backgroundColor:X})]}),e.jsx("div",{className:Q?"":"lg:col-span-2",children:e.jsx(Ye,{items:r.items,total:xe,shippingCents:fe,foregroundColor:d,primaryColor:ne,accentTextColor:le,savings:pe,codeDiscount:q,promoSlot:
1Me})})]}),m==="anforderung"&&e.jsxs("div",{className:"max-w-xl mx-auto",children:[e.jsx("h1",{className:"text-2xl font-bold mb-2",style:{color:d},children:t("checkout.request.title")}),e.jsx("p",{className:"mb-6",style:{color:d,opacity:.75},children:t("checkout.request.intro")}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"kostenstelle",className:"block text-sm font-medium mb-1.5",style:{color:d},children:t("checkout.request.costCenterLabel")}),e.jsx("input",{id:"kostenstelle",type:"text",value:de,maxLength:80,onChange:s=>ue(s.target.value),placeholder:t("checkout.request.costCenterPlaceholder"),className:"w-full rounded-lg border px-3 py-2.5 text-base",style:{borderColor:`${d}30`,color:d}})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"begruendung",className:"block text-sm font-medium mb-1.5",style:{color:d},children:t("checkout.request.reasonLabel")}),e.jsx("textarea",{id:"begruendung",rows:3,value:me,maxLength:500,onChange:s=>I(s.target.value),placeholder:t("checkout.request.reasonPlaceholder"),className:"w-full rounded-lg border px-3 py-2.5 text-base",style:{borderColor:`${d}30`,color:d}})]}),e.jsx(P,{type:"button",size:"lg",className:"w-full min-h-[44px]",style:{backgroundColor:ne},disabled:R,onClick:ps,children:t(R?"checkout.request.submitting":"checkout.request.submit")})]})]}),m==="gesendet"&&e.jsxs("div",{className:"max-w-xl mx-auto text-center py-8",children:[e.jsx("h1",{className:"text-2xl font-bold mb-3",style:{color:d},children:t("checkout.request.sentTitle")}),e.jsx("p",{className:"mb-6",style:{color:d,opacity:.75},children:t("checkout.request.sentBody")}),he&&e.jsxs("p",{className:"mb-8",style:{color:d},children:[t("checkout.request.sentNumber"),": ",e.jsx("strong",{children:he})]}),e.jsx(P,{type:"button",size:"lg",className:"min-h-[44px]",style:{backgroundColor:ne},onClick:ye,children:t("checkout.request.backToShop")})]}),m==="payment"&&z&&e.jsxs("div",{className:`grid gap-8 ${Q?"":"lg:grid-cols-5"}`,children:[e.jsxs("div",{className:Q?"":"lg:col-span-3",children:[e.jsx("h1",{className:"text-2xl font-bold mb-6",style:{color:d},children:t("checkout.paymentTitle")}),e.jsx(Cs,{stripe:n,options:{clientSecret:z,appearance:ct({background:X,foreground:d,ctaSurface:Y}),locale:(Ue=S.language)!=null&&Ue.startsWith("en")?"en":"de"},children:e.jsx(mt,{totalCents:l,successUrl:Re,foregroundColor:d,ctaSurface:Y,ctaText:ge,shopName:o.display_name,tenantId:o.id,cartId:(r==null?void 0:r.id)??null,itemCount:(r==null?void 0:r.items.length)??0})})]}),e.jsx("div",{className:Q?"":"lg:col-span-2",children:e.jsx(Ye,{items:r.items,total:xe,shippingCents:fe,foregroundColor:d,primaryColor:ne,accentTextColor:le,formData:W||void 0,savings:pe,codeDiscount:q&&Z!=null?{code:q.code,amount:Z/100}:q})})]})]})]}),e.jsx(Us,{...us,isMobile:Q})]})}export{Zt as default}; 2//# sourceMappingURL=TenantShopCheckout-CaBP3-vM.js.map
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.