@nextblock-cms/ecom 0.8.1 → 0.8.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AddToCartButton-DsSEH9yp.cjs +1 -0
- package/AddToCartButton-ffE0DhHu.js +59 -0
- package/CouponForm-BI_5SBHQ.js +152 -0
- package/CouponForm-D_uu2bLP.cjs +1 -0
- package/CurrencyProvider-Cg-Q6ucj.cjs +1 -0
- package/CurrencyProvider-OzlRN96V.js +120 -0
- package/CurrencyProvider.cjs.js +1 -0
- package/CurrencyProvider.es.js +10 -0
- package/ProductDetailsLayout-BxJH_BxR.cjs +1 -0
- package/ProductDetailsLayout-Dg8dRTYp.js +530 -0
- package/ProductGrid-BdL7iglO.cjs +1 -0
- package/ProductGrid-D3AWM8sr.js +130 -0
- package/actions-AHmBrS5e.cjs +48 -0
- package/actions-j5fuSZX-.js +820 -0
- package/cart-store.cjs.js +1 -0
- package/cart-store.es.js +116 -0
- package/components/Cart.cjs.js +1 -0
- package/components/Cart.es.js +259 -0
- package/components/CartDrawer.cjs.js +1 -0
- package/components/CartDrawer.es.js +118 -0
- package/components/CartIcon.cjs.js +1 -0
- package/components/CartIcon.es.js +33 -0
- package/components/Checkout.cjs.js +1 -0
- package/components/Checkout.es.js +1020 -0
- package/components/CurrencySwitcher.cjs.js +1 -0
- package/components/CurrencySwitcher.es.js +17 -0
- package/components/FeaturedProduct.cjs.js +1 -0
- package/components/FeaturedProduct.es.js +71 -0
- package/components/ProductDetailsLayout.cjs.js +1 -0
- package/components/ProductDetailsLayout.es.js +19 -0
- package/components/ProductGrid.cjs.js +1 -0
- package/components/ProductGrid.es.js +6 -0
- package/components/SimpleTiptapRenderer.cjs.js +1 -0
- package/components/SimpleTiptapRenderer.es.js +187 -0
- package/coupon-server-C9ySm3I5.cjs +1 -0
- package/coupon-server-DUKVtyYs.js +248 -0
- package/currency-constants.cjs.js +1 -0
- package/currency-constants.es.js +4 -0
- package/currency.cjs.js +1 -0
- package/currency.es.js +312 -0
- package/customer-C-UPvrYN.cjs +1 -0
- package/customer-C3xccjUg.js +57 -0
- package/index.cjs.js +1 -1
- package/index.es.js +414 -3105
- package/invoice-ui-CAnJPu6n.cjs +29 -0
- package/invoice-ui-DtpbTJE1.js +2886 -0
- package/package.json +10 -5
- package/product-actions-CONBF8i6.cjs +251 -0
- package/product-actions-DjlIWCMH.js +691 -0
- package/resolver-Fz_FKsfX.cjs +7 -0
- package/resolver-cfrCaHpE.js +128 -0
- package/server-actions/product-actions.cjs.js +1 -0
- package/server-actions/product-actions.es.js +15 -0
- package/server.cjs.js +27 -27
- package/server.es.js +478 -463
- package/shipping-actions-BnHjlo2q.js +25 -0
- package/shipping-actions-D6zt20gg.cjs +1 -0
- package/states-CWYRxV4B.cjs +1 -0
- package/states-DlHJezQ1.js +200 -0
- package/tax-calculation-Dab89aHd.js +181 -0
- package/tax-calculation-MkDKOEkL.cjs +1 -0
- package/trials-DvZaOtNy.cjs +1 -0
- package/trials-RDcRAZKx.js +29 -0
- package/types.cjs.js +1 -0
- package/types.es.js +33 -0
- package/use-cart.cjs.js +1 -0
- package/use-cart.es.js +43 -0
- package/variation-utils.cjs.js +1 -0
- package/variation-utils.es.js +246 -0
- package/invoice-ui-BJZfedDd.cjs +0 -332
- package/invoice-ui-GJ1ADAjn.js +0 -5759
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),Me=require("@nextblock-cms/ui/badge"),he=require("@nextblock-cms/ui/button"),g=require("@nextblock-cms/ui/card"),Ze=require("@nextblock-cms/ui/checkbox"),L=require("@nextblock-cms/ui/input"),N=require("@nextblock-cms/ui/label"),es=require("@nextblock-cms/ui/separator"),xe=require("@nextblock-cms/ui/radio-group"),ss=require("@freemius/checkout"),_e=require("../cart-store.cjs.js"),ts=require("../use-cart.cjs.js"),o=require("react"),A=require("lucide-react"),f=require("@nextblock-cms/utils"),U=require("../states-CWYRxV4B.cjs"),rs=require("../shipping-actions-D6zt20gg.cjs"),Fe=require("@nextblock-cms/db/server"),Ae=require("../tax-calculation-MkDKOEkL.cjs"),qe=require("../coupon-server-C9ySm3I5.cjs"),ge=require("../types.cjs.js"),K=require("../customer-C-UPvrYN.cjs"),cs=require("../CurrencyProvider-Cg-Q6ucj.cjs"),Ie=require("../trials-DvZaOtNy.cjs"),ns=require("../CouponForm-D_uu2bLP.cjs");async function as(t,_,k="USD",n,x){try{const u=Fe.createClient(),P=Fe.getServiceRoleSupabaseClient(),{data:T}=await u.from("currencies").select("code, symbol, exchange_rate, is_default, is_active, auto_sync_product_prices, auto_update_exchange_rate, exchange_rate_source, exchange_rate_updated_at, rounding_mode, rounding_increment, rounding_charm_amount").eq("is_active",!0).order("code",{ascending:!0}),H=T??[];let $;if(n){const M=await qe.getCouponQuote({client:P,code:n,items:x&&x.length>0?x:t,currencyCode:k});M.success&&($=qe.getQuoteLineDiscountMap(M.quote))}const R=await Ae.buildCheckoutTaxableItemsFromCart(u,t,k,H,$);return{success:!0,tax:await Ae.calculateCheckoutTaxes(u,{items:R,destination:_})}}catch(u){return console.error("Failed to estimate taxes:",u),{success:!1,error:u.message||"Failed to calculate taxes"}}}const is=process.env.NEXT_PUBLIC_IS_SANDBOX==="true",ne="nextblock-checkout-draft-v1";function ae(t,_){return{...K.emptyCustomerAddress(),company_name:t?.company_name||"",recipient_name:t?.recipient_name||_||"",line1:t?.line1||"",line2:t?.line2||"",city:t?.city||"",state:t?.state||"",postal_code:t?.postal_code||"",country_code:U.normalizeCountryCode(t?.country_code)||"CA"}}function ls(t){const _=K.normalizeCustomerAddress(t);return!(!_?.country_code||!_.postal_code||U.countryUsesStructuredStates(_.country_code)&&!_.state)}function fe(t,_,k){return t.reduce((n,x)=>{const{price:u,sale_price:P}=_e.getCartItemActivePrice(x,{currencyCode:_,currencies:k});return n+(P??u)*x.quantity},0)}function Le({idPrefix:t,title:_,description:k,value:n,onChange:x}){const{t:u}=f.useTranslations(),P=u("company_name")==="company_name"?"Company name":u("company_name"),T=u("select_an_option")==="select_an_option"?"Select an option":u("select_an_option"),H=u("state_province")==="state_province"?"State / Province":u("state_province"),$=U.getStatesForCountry(n.country_code),R=U.countryUsesStructuredStates(n.country_code);return e.jsxs(g.Card,{children:[e.jsxs(g.CardHeader,{children:[e.jsxs(g.CardTitle,{className:"flex items-center gap-2",children:[e.jsx(A.MapPin,{className:"w-5 h-5"}),_]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:k})]}),e.jsxs(g.CardContent,{className:"space-y-4",children:[e.jsxs("div",{className:"grid gap-4 sm:grid-cols-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(N.Label,{htmlFor:`${t}-company`,children:P}),e.jsx(L.Input,{id:`${t}-company`,value:n.company_name,onChange:i=>x({...n,company_name:i.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(N.Label,{htmlFor:`${t}-name`,children:u("full_name")}),e.jsx(L.Input,{id:`${t}-name`,value:n.recipient_name,onChange:i=>x({...n,recipient_name:i.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(N.Label,{htmlFor:`${t}-country`,children:u("country")}),e.jsx("select",{id:`${t}-country`,className:"flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm",value:n.country_code,onChange:i=>{const M=i.target.value,ie=U.getStatesForCountry(M);x({...n,country_code:M,state:ie.some(V=>V.code===n.state)?n.state:""})},children:U.countries.map(i=>e.jsx("option",{value:i.code,children:i.name},i.code))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(N.Label,{htmlFor:`${t}-line1`,children:u("address_line_1")}),e.jsx(L.Input,{id:`${t}-line1`,value:n.line1,onChange:i=>x({...n,line1:i.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(N.Label,{htmlFor:`${t}-line2`,children:u("address_line_2")}),e.jsx(L.Input,{id:`${t}-line2`,value:n.line2,onChange:i=>x({...n,line2:i.target.value})})]}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(N.Label,{htmlFor:`${t}-city`,children:u("city")}),e.jsx(L.Input,{id:`${t}-city`,value:n.city,onChange:i=>x({...n,city:i.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(N.Label,{htmlFor:`${t}-state`,children:u("state_province")}),R?e.jsxs("select",{id:`${t}-state`,className:"flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm",value:n.state,onChange:i=>x({...n,state:i.target.value}),children:[e.jsx("option",{value:"",children:`${T}: ${H}`}),$.map(i=>e.jsx("option",{value:i.code,children:i.name},i.code))]}):e.jsx(L.Input,{id:`${t}-state`,value:n.state,onChange:i=>x({...n,state:i.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(N.Label,{htmlFor:`${t}-postal`,children:u("postal_zip_code")}),e.jsx(L.Input,{id:`${t}-postal`,value:n.postal_code,onChange:i=>x({...n,postal_code:i.target.value})})]})]})]})]})}function $e({title:t,description:_,badgeLabel:k,children:n}){return e.jsxs(g.Card,{children:[e.jsx(g.CardHeader,{children:e.jsxs("div",{className:"flex items-center justify-between gap-3 flex-wrap",children:[e.jsxs("div",{children:[e.jsx(g.CardTitle,{children:t}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:_})]}),k?e.jsx(Me.Badge,{variant:"secondary",children:k}):null]})}),e.jsx(g.CardContent,{className:"space-y-4",children:n})]})}const os=({initialCustomer:t})=>{const[_,k]=o.useState({}),[n,x]=o.useState(null),[u,P]=o.useState({}),[T,H]=o.useState(t?.email||""),[$,R]=o.useState(""),[i,M]=o.useState(t?.phone||""),[ie,V]=o.useState(!1),[Ee,je]=o.useState(null),[ye,W]=o.useState(!1),[De,Z]=o.useState(!1),[J,ee]=o.useState([]),[y,G]=o.useState(null),[w,se]=o.useState(null),[E,Re]=o.useState(null),[q,be]=o.useState(()=>ae(t?.billingAddress,t?.fullName)),[Q,Ne]=o.useState(()=>ae(t?.shippingAddress??t?.billingAddress,t?.fullName)),[B,ve]=o.useState(!t?.shippingAddress||K.addressesMatch(t?.billingAddress,t?.shippingAddress)),X=ts.useCart(s=>s),{t:c,lang:le}=f.useTranslations(),{activeCurrencyCode:l,currencies:D}=cs.useCurrency(),b=X?.items??[],v=o.useMemo(()=>b.filter(s=>!ge.isDigitalItem(s)),[b]),C=o.useMemo(()=>b.filter(s=>ge.isDigitalItem(s)),[b]),z=t?.isAuthenticated??!1,r=(s,a,p)=>{const m=c(s,p);if(m!==s)return m;if(!p)return a;let j=a;return Object.entries(p).forEach(([h,d])=>{j=j.replace(new RegExp(`\\{${h}\\}`,"g"),String(d))}),j},S=v.length>0,Be=o.useMemo(()=>fe(b,l,D),[l,D,b]),oe=o.useMemo(()=>fe(v,l,D),[l,D,v]),de=o.useMemo(()=>fe(C,l,D),[l,D,C]),ue=E?.providerDiscounts.stripe??0,me=E?.providerDiscounts.freemius??0,te=Math.max(0,oe-ue),ze=Math.max(0,de-me),F=o.useMemo(()=>B?q:Q,[q,Q,B]),O=o.useMemo(()=>S?F:q,[q,S,F]),re=!S||ls(F),ce=o.useMemo(()=>J.find(s=>s.id===y),[J,y]),Ce=o.useMemo(()=>te+(ce?.amount??0)+(w&&!w.isPendingExternalCalculation?w.amount:0),[te,ce,w]),Oe=Ce+ze;if(o.useEffect(()=>{if(!(z||typeof window>"u"))try{const s=window.localStorage.getItem(ne);if(!s)return;const a=JSON.parse(s);a.email&&H(a.email),a.phone&&M(a.phone),a.billingAddress&&be(ae(a.billingAddress)),a.shippingAddress&&Ne(ae(a.shippingAddress)),typeof a.useBillingForShipping=="boolean"&&ve(a.useBillingForShipping),(typeof a.selectedMethodId=="string"||a.selectedMethodId===null)&&G(a.selectedMethodId)}catch(s){console.error("[Checkout] Failed to restore checkout draft:",s)}},[z]),o.useEffect(()=>{if(!(typeof window>"u")){if(z){window.localStorage.removeItem(ne);return}window.localStorage.setItem(ne,JSON.stringify({email:T,phone:i,billingAddress:q,shippingAddress:Q,useBillingForShipping:B,selectedMethodId:y}))}},[q,T,z,i,y,Q,B]),o.useEffect(()=>{if(!S){ee([]),G(null),W(!1);return}if(!re){ee([]),G(null),W(!1);return}let s=!1;const p=setTimeout(async()=>{if(!F.country_code)return;W(!0);const m=await rs.getShippingEstimates(te,{country:F.country_code,state:F.state,postal_code:F.postal_code},le,l);s||(m.success&&m.methods?(ee(m.methods),m.methods.length>0&&(!y||!m.methods.find(j=>j.id===y))&&G(m.methods[0].id)):(ee([]),G(null)),W(!1))},400);return()=>{s=!0,clearTimeout(p)}},[l,S,re,le,y,F.country_code,F.postal_code,F.state,te]),o.useEffect(()=>{const a=setTimeout(async()=>{if(!S||!O.country_code){Z(!1),se(null);return}if(U.countryUsesStructuredStates(O.country_code)&&!O.state){Z(!1),se(null);return}Z(!0);const p=await as(v,{country_code:O.country_code,state:O.state},l,E?.code??null,b);p.success&&p.tax?se(p.tax):se(null),Z(!1)},300);return()=>clearTimeout(a)},[l,S,v,O.country_code,O.state,E?.code,b]),!X)return null;const Se=()=>{V(!1),je(null)},ke=ie?e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",onClick:Se,children:e.jsxs("div",{className:"relative bg-background border rounded-xl shadow-2xl p-8 max-w-md mx-4",onClick:s=>s.stopPropagation(),children:[e.jsx("button",{onClick:Se,className:"absolute top-4 right-4 text-muted-foreground hover:text-foreground transition-colors",children:e.jsx(A.X,{className:"w-5 h-5"})}),e.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[e.jsx("div",{className:"p-2 rounded-full bg-amber-100 dark:bg-amber-900/20",children:e.jsx(A.FlaskConical,{className:"h-6 w-6 text-amber-600 dark:text-amber-400"})}),e.jsx("h2",{className:"text-xl font-semibold",children:c("ecommerce.checkout_successful")})]}),e.jsx("p",{className:"text-muted-foreground mb-2",children:c("ecommerce.sandbox_notice")}),e.jsx("p",{className:"text-muted-foreground mb-2",children:Ee==="stripe"?r("ecommerce.sandbox_checkout_stripe_description","This simulated step represents the Stripe checkout for physical products."):r("ecommerce.sandbox_checkout_freemius_description","This simulated step represents the Freemius checkout for digital products.")}),e.jsx("p",{className:"text-muted-foreground mb-6",children:c("ecommerce.license_notice")}),e.jsx("a",{href:"https://nextblock.ca",target:"_blank",rel:"noopener noreferrer",className:"block w-full text-center py-3 px-4 rounded-lg bg-primary text-primary-foreground font-semibold hover:opacity-90 transition-opacity",children:c("ecommerce.purchase_at")})]})}):null,Ke=s=>{if(!z&&(!T||!/^\S+@\S+\.\S+$/.test(T)))return R(c("ecommerce.invalid_email")),null;const a=K.normalizeCustomerAddress(q);if(!K.isCustomerAddressComplete(a))return alert(c("checkout_complete_billing_address")),null;const p=S?K.normalizeCustomerAddress(B?q:Q):null;if(s==="stripe"){if(!K.isCustomerAddressComplete(p))return alert(c("checkout_complete_shipping_address")),null;if(!y)return alert(r("ecommerce.shipping_method_required","Please select a shipping method before continuing.")),null}return R(""),{normalizedBillingAddress:a,normalizedShippingAddress:p}},we=async(s,a,p)=>{P(j=>({...j,[s]:""}));const m=Ke(s);if(m){if(is){const j=new Set(a.map(d=>d.id)),h=b.filter(d=>!j.has(d.id));X.setItems(h),h.length===0&&X.removeCoupon(),je(s),V(!0),typeof window<"u"&&h.length===0&&window.localStorage.removeItem(ne);return}x(p);try{const j=await fetch("/api/checkout",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({items:a,customerEmail:z?void 0:T,customerPhone:i||null,billingAddress:m.normalizedBillingAddress,shippingAddress:s==="stripe"?m.normalizedShippingAddress:null,shippingMethodId:s==="stripe"?y:null,locale:le,currencyCode:l,couponCode:E?.code??X.appliedCoupon?.code??null,couponContextItems:b})}),h=await j.json();if(!j.ok){const d=h?.errorKey&&typeof h.errorKey=="string"?r(h.errorKey,h?.error||r("ecommerce.generic_error","Something went wrong."),h.errorParams):h?.error||c("ecommerce.generic_error");P(Y=>({...Y,[s]:d})),x(null);return}if(h.customProps&&h.customProps.provider==="freemius"){const d=h.customProps;let Y=null;const Xe=()=>{window.location.href=`/checkout/success?session_id=${d.order_id}`},Pe=I=>(Y||(Y=fetch("/api/checkout/freemius/sync",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({orderId:d.order_id,checkoutResponse:I})}).then(async Te=>{if(!Te.ok){const We=await Te.json().catch(()=>null);console.error("Freemius checkout sync failed:",We)}})),Y),Ye={product_id:d.plugin_id,public_key:d.public_key,sandbox:d.sandbox},Ve={name:c("ecommerce.checkout_overlay_title"),plan_id:d.plan_id,...d.billing_cycle?{billing_cycle:d.billing_cycle}:{},...d.trial?{trial:d.trial}:{},...d.coupon?{coupon:d.coupon}:{},user_email:d.user_email,user_firstname:d.user_firstname,user_lastname:d.user_lastname,sandbox:d.sandbox,purchaseCompleted:function(I){Pe(I)},success:function(I){(async()=>{try{await Pe(I)}finally{Xe()}})()}};try{new ss.Checkout(Ye).open(Ve),x(null)}catch(I){alert(c("ecommerce.checkout_popup_blocked")+" "+(I.message||String(I))),h.url&&(window.location.href=h.url),x(null)}}else h.url?window.location.href=h.url:(P(d=>({...d,[s]:c("ecommerce.checkout_failed")+(h.error||r("ecommerce.unknown_error","Unknown error"))})),x(null))}catch(j){console.error(j),P(h=>({...h,[s]:c("ecommerce.generic_error")})),x(null)}}};if(b.length===0)return e.jsxs(e.Fragment,{children:[ke,e.jsxs("div",{className:"container mx-auto flex min-h-[50vh] flex-col items-center justify-center p-8 text-center",children:[e.jsx("h1",{className:"mb-4 text-2xl font-bold",children:c("ecommerce.cart_empty")}),e.jsx("p",{className:"mb-8 text-muted-foreground",children:c("ecommerce.cart_empty_description")}),e.jsx(he.Button,{asChild:!0,children:e.jsx("a",{href:"/shop",children:c("ecommerce.go_to_shop")})})]})]});const pe=S?re?ye?r("ecommerce.calculating_shipping","Calculating shipping..."):y?null:J.length>0?c("ecommerce.select_rate"):c("ecommerce.no_rates_for_region"):r("ecommerce.waiting_on_address_info","Complete your shipping address to view available shipping options."):null,Ue=n!==null||pe!==null,He=v.length===1?r("ecommerce.item_count_one","{count} item",{count:v.length}):r("ecommerce.item_count_other","{count} items",{count:v.length}),Ge=C.length===1?r("ecommerce.license_count_one","{count} license",{count:C.length}):r("ecommerce.license_count_other","{count} licenses",{count:C.length}),Qe=s=>ge.isDigitalItem(s)?r("ecommerce.digital_label","Digital"):r("ecommerce.physical_label","Physical"),Je=s=>s==="monthly"?r("ecommerce.checkout_billing_cycle_monthly","Monthly subscription"):s==="annual"?r("ecommerce.checkout_billing_cycle_annual","Annual subscription"):s==="lifetime"?r("ecommerce.checkout_billing_cycle_lifetime","Lifetime subscription"):null;return e.jsxs("div",{className:"container mx-auto px-4 py-12 md:px-6",children:[ke,e.jsxs("div",{className:"mx-auto max-w-6xl",children:[e.jsx("h1",{className:"mb-8 text-3xl font-bold",children:c("ecommerce.checkout")}),e.jsxs("div",{className:"grid gap-8 lg:grid-cols-12 lg:items-start",children:[e.jsxs("div",{className:"lg:col-span-8 space-y-6",children:[e.jsxs(g.Card,{children:[e.jsx(g.CardHeader,{children:e.jsxs(g.CardTitle,{className:"flex items-center gap-2",children:[e.jsx(A.CreditCard,{className:"w-5 h-5"}),c("ecommerce.contact_information")]})}),e.jsxs(g.CardContent,{className:"space-y-4",children:[z?e.jsx("div",{className:"rounded-xl border bg-muted/20 p-4 text-sm text-muted-foreground",children:c("checkout_prefill_notice",{email:t?.email||""})}):e.jsxs("div",{className:"space-y-2",children:[e.jsxs(N.Label,{htmlFor:"checkout-email",children:[c("ecommerce.email_address")," ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(L.Input,{id:"checkout-email",type:"email",placeholder:c("ecommerce.email_placeholder"),value:T,onChange:s=>{H(s.target.value),$&&R("")},required:!0}),$?e.jsx("p",{className:"text-xs text-destructive mt-1",children:$}):null]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(N.Label,{htmlFor:"checkout-phone",children:c("phone_number")}),e.jsx(L.Input,{id:"checkout-phone",placeholder:c("optional"),value:i,onChange:s=>M(s.target.value)})]})]})]}),e.jsx(Le,{idPrefix:"billing",title:c("billing_address"),description:c("checkout_billing_address_help"),value:q,onChange:be}),S?e.jsxs("div",{className:"flex items-center space-x-3 rounded-xl border bg-muted/20 p-4",children:[e.jsx(Ze.Checkbox,{id:"use-billing-for-shipping",checked:B,onCheckedChange:s=>ve(!!s)}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(N.Label,{htmlFor:"use-billing-for-shipping",className:"cursor-pointer",children:c("use_billing_for_shipping")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:c("checkout_use_billing_for_shipping_help")})]})]}):null,S&&!B?e.jsx(Le,{idPrefix:"shipping",title:c("shipping_address"),description:c("checkout_shipping_address_help"),value:Q,onChange:Ne}):null,S?e.jsxs(g.Card,{children:[e.jsx(g.CardHeader,{children:e.jsxs(g.CardTitle,{className:"flex items-center gap-2",children:[e.jsx(A.ChevronRight,{className:"w-5 h-5 text-primary"}),c("ecommerce.shipping_method")]})}),e.jsx(g.CardContent,{children:ye?e.jsx("div",{className:"flex items-center justify-center py-6",children:e.jsx(A.Loader2,{className:"w-6 h-6 animate-spin text-muted-foreground"})}):J.length>0?e.jsx("div",{className:"space-y-3",children:J.map(s=>e.jsxs("div",{onClick:()=>G(s.id),className:`flex items-center justify-between p-4 rounded-lg border-2 cursor-pointer transition-all ${y===s.id?"border-primary bg-primary/5":"border-neutral-100 hover:border-neutral-200"}`,children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:`w-4 h-4 rounded-full border flex items-center justify-center ${y===s.id?"border-primary":"border-neutral-300"}`,children:y===s.id?e.jsx("div",{className:"w-2 h-2 rounded-full bg-primary"}):null}),e.jsx("span",{className:"font-medium",children:s.name})]}),e.jsx("span",{className:"font-bold",children:f.formatPrice(s.amount,l)})]},s.id))}):e.jsx("div",{className:"py-4 text-center text-muted-foreground bg-muted/30 rounded-lg italic",children:re?c("ecommerce.no_rates_for_region"):r("ecommerce.waiting_on_address_info","Complete your shipping address to view available shipping options.")})})]}):null]}),e.jsxs("div",{className:"lg:col-span-4 space-y-6",children:[e.jsxs(g.Card,{className:"top-6",children:[e.jsx(g.CardHeader,{children:e.jsx(g.CardTitle,{children:c("ecommerce.order_summary")})}),e.jsxs(g.CardContent,{className:"space-y-4",children:[e.jsx("div",{className:"space-y-3 max-h-[260px] overflow-y-auto pr-2",children:b.map(s=>{const a=_e.getCartItemActivePrice(s,{currencyCode:l,currencies:D}),p=Ie.getTrialSummary(s);return e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"flex gap-3",children:[s.image_url?e.jsx("div",{className:"h-10 w-10 shrink-0 overflow-hidden rounded border bg-neutral-100",children:e.jsx("img",{src:s.image_url,alt:s.title,className:"h-full w-full object-cover"})}):null,e.jsxs("div",{className:"grid gap-0.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-medium text-xs line-clamp-1",children:s.title}),e.jsx(Me.Badge,{variant:"outline",className:"text-[9px] uppercase",children:Qe(s)})]}),s.variant_label?e.jsx("span",{className:"text-[10px] text-muted-foreground line-clamp-1",children:s.variant_label}):null,e.jsxs("span",{className:"text-[10px] text-muted-foreground",children:[c("ecommerce.qty"),": ",s.quantity]}),p?e.jsxs("span",{className:"text-[10px] font-medium text-emerald-700",children:[p.label," - ",p.paymentRequirementLabel]}):null]})]}),e.jsxs("div",{className:"flex flex-col items-end gap-0.5 shrink-0",children:[e.jsx("span",{className:"font-medium text-xs",children:f.formatPrice((a.sale_price??a.price)*s.quantity,l)}),a.sale_price?e.jsx("span",{className:"text-[9px] text-muted-foreground line-through",children:f.formatPrice(a.price*s.quantity,l)}):null]})]},`${s.id}-${s.variant_id||"base"}`)})}),e.jsx(es.Separator,{}),e.jsx(ns.CouponForm,{items:b,currencyCode:l,onQuoteChange:Re}),e.jsxs("div",{className:"space-y-2 text-sm",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{children:c("ecommerce.subtotal")}),e.jsx("span",{children:f.formatPrice(Be,l)})]}),v.length>0?e.jsxs("div",{className:"flex justify-between text-muted-foreground",children:[e.jsx("span",{children:r("ecommerce.physical_products","Physical products")}),e.jsx("span",{children:f.formatPrice(oe,l)})]}):null,C.length>0?e.jsxs("div",{className:"flex justify-between text-muted-foreground",children:[e.jsx("span",{children:r("ecommerce.digital_products","Digital products")}),e.jsx("span",{children:f.formatPrice(de,l)})]}):null,E?e.jsxs("div",{className:"flex justify-between text-emerald-600",children:[e.jsxs("span",{children:[r("ecommerce.discount","Discount")," (",E.code,")"]}),e.jsxs("span",{children:["-",f.formatPrice(E.discountTotal,l)]})]}):null,(v.length>0||C.length>0)&&e.jsxs("div",{className:"flex justify-between font-bold text-lg pt-2 border-t mt-2",children:[e.jsx("span",{children:r("ecommerce.estimated_total","Estimated total")}),e.jsx("span",{className:"text-primary",children:f.formatPrice(Oe,l)})]})]})]})]}),v.length>0?e.jsxs($e,{title:r("ecommerce.stripe_checkout_title","Stripe Checkout"),description:r("ecommerce.stripe_checkout_description","Pay for physical products in one Stripe checkout session."),badgeLabel:He,children:[e.jsxs("div",{className:"space-y-2 text-sm",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{children:r("ecommerce.physical_subtotal","Physical subtotal")}),e.jsx("span",{children:f.formatPrice(oe,l)})]}),ue>0?e.jsxs("div",{className:"flex justify-between text-emerald-600",children:[e.jsx("span",{children:r("ecommerce.discount","Discount")}),e.jsxs("span",{children:["-",f.formatPrice(ue,l)]})]}):null,e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{children:c("ecommerce.shipping")}),e.jsx("span",{children:ce?f.formatPrice(ce.amount,l):"-"})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{children:r("ecommerce.tax","Tax")}),e.jsx("span",{children:De?"...":w?.isPendingExternalCalculation?r("ecommerce.tax_calculated_on_stripe","Calculated on Stripe"):w?f.formatPrice(w.amount,l):"-"})]}),w&&w.lines.length>0?e.jsx("div",{className:"rounded-lg bg-muted/20 px-3 py-2 text-xs text-muted-foreground",children:w.lines.map(s=>e.jsxs("div",{className:"flex justify-between gap-3",children:[e.jsxs("span",{children:[s.name," (",s.rate.toFixed(4),"%)"]}),e.jsx("span",{children:f.formatPrice(s.amount,l)})]},s.id||`${s.name}-${s.rate}`))}):null,e.jsxs("div",{className:"flex justify-between font-semibold pt-2 border-t",children:[e.jsx("span",{children:r("ecommerce.total_on_stripe","Total on Stripe")}),e.jsx("span",{children:f.formatPrice(Ce,l)})]})]}),e.jsxs(he.Button,{className:"w-full",size:"lg",onClick:()=>we("stripe",v,"stripe"),disabled:Ue,children:[n==="stripe"?e.jsx(A.Loader2,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(A.Package,{className:"mr-2 h-4 w-4"}),n==="stripe"?c("ecommerce.processing"):r("ecommerce.checkout_physical_products","Checkout Physical Products")]}),pe&&n===null?e.jsx("p",{className:"text-[11px] text-muted-foreground",children:pe}):null,u.stripe?e.jsx("div",{className:"rounded-lg border border-destructive/20 bg-destructive/10 px-3 py-2 text-xs text-destructive",children:u.stripe}):null,e.jsx("p",{className:"text-[11px] text-muted-foreground",children:w?.isPendingExternalCalculation?r("checkout_stripe_tax_finalized_notice","Tax will be finalized by Stripe Tax on the payment step."):r("ecommerce.shipping_taxes_collected_on_stripe","Shipping and taxes are only collected during the Stripe step for physical products.")})]}):null,C.length>0?e.jsxs($e,{title:r("ecommerce.freemius_checkout_title","Freemius Checkout"),description:r("ecommerce.freemius_checkout_description","Digital products use the Freemius checkout flow."),badgeLabel:Ge,children:[e.jsx("div",{className:"space-y-3",children:C.map(s=>{const a=_e.getCartItemActivePrice(s,{currencyCode:l,currencies:D}),p=Ie.getTrialSummary(s),m=`freemius:${s.id}`,j=p?_[m]||"paid":void 0;return e.jsxs("div",{className:"rounded-lg border p-3 space-y-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:s.title}),s.billing_cycle?e.jsx("p",{className:"text-xs text-muted-foreground capitalize",children:Je(s.billing_cycle)}):null,p?e.jsxs("p",{className:"text-xs font-medium text-emerald-700",children:[p.label," - ",p.paymentRequirementLabel]}):null]}),e.jsx("span",{className:"font-medium",children:f.formatPrice(a.sale_price??a.price,l)})]}),p&&!s.trial_requires_payment_method&&e.jsxs("div",{className:"bg-muted/30 p-3 rounded-md border text-sm mt-2 mb-3",children:[e.jsx("p",{className:"font-medium mb-3",children:r("ecommerce.freemius_trial_preference_title","How would you like to start your trial?")}),e.jsxs(xe.RadioGroup,{value:_[m]||"paid",onValueChange:h=>k(d=>({...d,[m]:h})),className:"gap-3",children:[e.jsxs("div",{className:"flex items-start space-x-3",children:[e.jsx(xe.RadioGroupItem,{value:"paid",id:`${m}-paid`,className:"mt-1"}),e.jsxs("div",{className:"grid gap-1.5",children:[e.jsx(N.Label,{htmlFor:`${m}-paid`,className:"font-medium leading-none cursor-pointer",children:r("ecommerce.freemius_trial_with_card","Enter Payment Details Now (Still get full trial length free)")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:r("ecommerce.freemius_trial_with_card_help","You will not be billed until the trial ends. Cancel anytime.")})]})]}),e.jsxs("div",{className:"flex items-start space-x-3",children:[e.jsx(xe.RadioGroupItem,{value:"free",id:`${m}-free`,className:"mt-1"}),e.jsx("div",{className:"grid gap-1.5",children:e.jsx(N.Label,{htmlFor:`${m}-free`,className:"font-medium leading-none cursor-pointer",children:r("ecommerce.freemius_trial_no_card","Start Free Trial (No card required)")})})]})]})]}),e.jsxs(he.Button,{className:"w-full h-auto min-h-[2.75rem] py-2",variant:C.length>1?"outline":"default",onClick:()=>we("freemius",[{...s,...j?{trial_preference:j}:{}}],m),disabled:n!==null,children:[n===m?e.jsx(A.Loader2,{className:"mr-2 h-4 w-4 shrink-0 animate-spin"}):e.jsx(A.Download,{className:"mr-2 h-4 w-4 shrink-0"}),e.jsx("span",{className:"whitespace-normal text-left",children:n===m?c("ecommerce.processing"):C.length>1?r("ecommerce.checkout_product","Checkout {title}",{title:s.title}):r("ecommerce.checkout_digital_product","Checkout Digital Product")})]})]},m)})}),e.jsxs("div",{className:"flex justify-between text-sm font-semibold border-t pt-3",children:[e.jsx("span",{children:r("ecommerce.digital_subtotal","Digital subtotal")}),e.jsx("span",{children:f.formatPrice(de,l)})]}),me>0?e.jsxs("div",{className:"flex justify-between text-sm font-semibold text-emerald-600",children:[e.jsx("span",{children:r("ecommerce.discount","Discount")}),e.jsxs("span",{children:["-",f.formatPrice(me,l)]})]}):null,u.freemius?e.jsx("div",{className:"rounded-lg border border-destructive/20 bg-destructive/10 px-3 py-2 text-xs text-destructive",children:u.freemius}):null,e.jsx("p",{className:"text-[11px] text-muted-foreground",children:C.length>1?r("ecommerce.freemius_multi_checkout_notice","Freemius licenses are completed one at a time, so each digital product gets its own checkout action."):r("ecommerce.freemius_tax_notice","Taxes and compliance for digital products are handled inside the Freemius checkout.")})]}):null]})]})]})]})};exports.Checkout=os;
|