@nextblock-cms/ecom 0.19.2 → 0.19.3

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.
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),q=require("react"),C=require("@nextblock-cms/ui/badge"),d=require("@nextblock-cms/ui/button"),t=require("@nextblock-cms/ui/table"),j=require("lucide-react"),p=require("../cart-store.cjs.js"),w=require("../use-cart.cjs.js"),u=require("../types.cjs.js"),g=require("next/link"),T=require("@nextblock-cms/utils"),k=require("../use-price-formatter.cjs.js"),S=require("./ShippingEstimator.cjs.js"),P=require("../CurrencyProvider.cjs.js"),R=require("../trials.cjs.js"),B=require("./CouponForm.cjs.js"),H=()=>{const m=k.usePriceFormatter(),x=w.useCart(s=>s),y=p.useCartSubtotal(),{t:c}=T.useTranslations(),l=(s,a,r)=>{const o=c(s,r);return o===s?a:o},N="/shop",{activeCurrencyCode:i,currencies:h}=P.useCurrency(),n=x?.items??[],f=q.useMemo(()=>n.reduce((s,a)=>{if(u.isDigitalItem(a))return s;const r=p.getCartItemActivePrice(a,{currencyCode:i,currencies:h});return s+(r.sale_price??r.price)*a.quantity},0),[i,h,n]);if(!x)return null;const{updateQuantity:b,removeItem:v}=x,_=s=>n.reduce((a,r)=>u.isDigitalItem(r)||r.sku!==s?a:a+r.quantity,0);return n.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center space-y-4 py-12",children:[e.jsx("h1",{className:"text-2xl font-bold",children:c("ecommerce.cart_empty")}),e.jsx("p",{className:"text-muted-foreground",children:c("ecommerce.cart_empty_description")}),e.jsx(d.Button,{asChild:!0,children:e.jsx(g,{href:N,children:c("ecommerce.continue_shopping")})})]}):e.jsxs("div",{className:"container mx-auto py-12",children:[e.jsx("h1",{className:"mb-8 text-3xl font-bold",children:c("ecommerce.shopping_cart")}),e.jsxs("div",{className:"grid gap-12 lg:grid-cols-12 lg:items-start",children:[e.jsx("div",{className:"lg:col-span-8",children:e.jsx("div",{className:"rounded-lg border overflow-hidden",children:e.jsxs(t.Table,{children:[e.jsx(t.TableHeader,{children:e.jsxs(t.TableRow,{children:[e.jsx(t.TableHead,{children:c("ecommerce.product")}),e.jsx(t.TableHead,{children:c("ecommerce.quantity")}),e.jsx(t.TableHead,{className:"text-right",children:c("ecommerce.price")}),e.jsx(t.TableHead,{className:"text-right",children:c("ecommerce.total")}),e.jsx(t.TableHead,{className:"w-[50px]",children:e.jsx("span",{className:"sr-only",children:l("ecommerce.actions","Actions")})})]})}),e.jsx(t.TableBody,{children:n.map(s=>{const a=_(s.sku),r=p.getCartItemActivePrice(s,{currencyCode:i,currencies:h}),o=R.getTrialSummary(s,c);return e.jsxs(t.TableRow,{children:[e.jsx(t.TableCell,{children:e.jsxs("div",{className:"flex items-center gap-4",children:[s.image_url?e.jsx("div",{className:"h-16 w-16 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"})}):e.jsx("div",{className:"flex h-16 w-16 items-center justify-center rounded bg-secondary",children:e.jsx("span",{className:"text-[10px] text-muted-foreground",children:c("ecommerce.no_image")})}),e.jsxs("div",{className:"min-w-0 break-words",children:[e.jsx("div",{className:"font-medium",children:s.title}),s.variant_label&&e.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:s.variant_label}),u.isDigitalItem(s)&&s.billing_cycle&&e.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:l(`ecommerce.checkout_billing_cycle_${s.billing_cycle}`,`${s.billing_cycle} subscription`)}),o&&e.jsxs("div",{className:"mt-1 text-xs font-medium text-emerald-700",children:[o.label," - ",o.paymentRequirementLabel]})]})]})}),e.jsx(t.TableCell,{children:u.isDigitalItem(s)?e.jsx(C.Badge,{variant:"secondary",className:"font-normal text-xs",children:l("ecommerce.license_count_one","1 license",{count:1})}):e.jsxs("div",{role:"group","aria-label":`${l("ecommerce.quantity","Quantity")}: ${s.title}`,className:"flex items-center gap-2",children:[e.jsx(d.Button,{variant:"outline",size:"icon",className:"h-8 w-8","aria-label":l("ecommerce.decrease_quantity","Decrease quantity"),onClick:()=>b(s.id,s.quantity-1),children:e.jsx(j.Minus,{className:"h-4 w-4"})}),e.jsx("span",{"aria-live":"polite","aria-atomic":"true",className:"w-8 text-center tabular-nums",children:s.quantity}),e.jsx(d.Button,{variant:"outline",size:"icon",className:"h-8 w-8","aria-label":l("ecommerce.increase_quantity","Increase quantity"),onClick:()=>b(s.id,s.quantity+1),disabled:typeof s.stock=="number"&&a>=s.stock,children:e.jsx(j.Plus,{className:"h-4 w-4"})})]})}),e.jsx(t.TableCell,{className:"text-right",children:e.jsxs("div",{className:"flex flex-col items-end tabular-nums",children:[e.jsxs("span",{className:"font-medium",children:[r.sale_price&&e.jsxs("span",{className:"sr-only",children:[l("ecommerce.sale_price","Sale price")," "]}),m(r.sale_price??r.price,i)]}),r.sale_price&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:[e.jsxs("span",{className:"sr-only",children:[l("ecommerce.regular_price","Regular price")," "]}),e.jsx("s",{children:m(r.price,i)})]})]})}),e.jsx(t.TableCell,{className:"text-right font-medium tabular-nums",children:m((r.sale_price??r.price)*s.quantity,i)}),e.jsx(t.TableCell,{children:e.jsx(d.Button,{variant:"ghost",size:"icon",onClick:()=>v(s.id),"aria-label":l("ecommerce.remove_item",`Remove ${s.title} from cart`,{item:s.title}),className:"text-muted-foreground hover:text-destructive",children:e.jsx(j.Trash2,{className:"h-4 w-4"})})})]},s.id)})})]})})}),e.jsx("div",{className:"lg:col-span-4",children:e.jsxs("div",{className:"rounded-lg border bg-card p-6 shadow-sm",children:[e.jsx("h2",{className:"mb-4 text-lg font-semibold",children:c("ecommerce.order_summary")}),e.jsxs("div",{className:"flex justify-between border-b pb-4",children:[e.jsx("span",{children:c("ecommerce.subtotal")}),e.jsx("span",{className:"font-medium tabular-nums",children:m(y,i)})]}),e.jsxs("div",{className:"mt-4 flex flex-col gap-4",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:c("ecommerce.shipping_taxes_calculated")}),n.some(s=>!u.isDigitalItem(s))&&e.jsx(S.ShippingEstimator,{physicalSubtotal:f}),e.jsx(B.CouponForm,{items:n,currencyCode:i,compact:!0}),e.jsx(d.Button,{asChild:!0,className:"w-full mt-4",size:"lg",children:e.jsx(g,{href:"/checkout",children:c("ecommerce.proceed_to_checkout")})})]})]})})]})]})};exports.Cart=H;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),q=require("react"),C=require("@nextblock-cms/ui/badge"),d=require("@nextblock-cms/ui/button"),a=require("@nextblock-cms/ui/table"),g=require("lucide-react"),j=require("../cart-store.cjs.js"),w=require("../use-cart.cjs.js"),m=require("../types.cjs.js"),b=require("next/link"),T=require("@nextblock-cms/utils"),k=require("../use-price-formatter.cjs.js"),S=require("./ShippingEstimator.cjs.js"),P=require("../CurrencyProvider.cjs.js"),R=require("../trials.cjs.js"),B=require("./CouponForm.cjs.js"),H=()=>{const u=k.usePriceFormatter(),x=w.useCart(s=>s),N=j.useCartSubtotal(),{t:r}=T.useTranslations(),l=(s,t,c)=>{const o=r(s,c);return o===s?t:o},y="/shop",{activeCurrencyCode:i,currencies:h}=P.useCurrency(),n=x?.items??[],v=q.useMemo(()=>n.reduce((s,t)=>{if(m.isDigitalItem(t))return s;const c=j.getCartItemActivePrice(t,{currencyCode:i,currencies:h});return s+(c.sale_price??c.price)*t.quantity},0),[i,h,n]);if(!x)return e.jsxs("div",{role:"status","aria-busy":"true",className:"container mx-auto py-12",children:[e.jsx("span",{className:"sr-only",children:r("loading")==="loading"?"Loading…":r("loading")}),e.jsx("div",{className:"mb-8 h-9 w-56 rounded-md bg-muted"}),e.jsxs("div",{className:"grid gap-12 lg:grid-cols-12 lg:items-start",children:[e.jsx("div",{className:"h-64 rounded-lg border bg-muted/40 lg:col-span-8"}),e.jsx("div",{className:"h-64 rounded-lg border bg-muted/40 lg:col-span-4"})]})]});const{updateQuantity:p,removeItem:f}=x,_=s=>n.reduce((t,c)=>m.isDigitalItem(c)||c.sku!==s?t:t+c.quantity,0);return n.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center space-y-4 py-12",children:[e.jsx("h1",{className:"text-2xl font-bold",children:r("ecommerce.cart_empty")}),e.jsx("p",{className:"text-muted-foreground",children:r("ecommerce.cart_empty_description")}),e.jsx(d.Button,{asChild:!0,children:e.jsx(b,{href:y,children:r("ecommerce.continue_shopping")})})]}):e.jsxs("div",{className:"container mx-auto py-12",children:[e.jsx("h1",{className:"mb-8 text-3xl font-bold",children:r("ecommerce.shopping_cart")}),e.jsxs("div",{className:"grid gap-12 lg:grid-cols-12 lg:items-start",children:[e.jsx("div",{className:"lg:col-span-8",children:e.jsx("div",{className:"rounded-lg border overflow-hidden",children:e.jsxs(a.Table,{children:[e.jsx(a.TableHeader,{children:e.jsxs(a.TableRow,{children:[e.jsx(a.TableHead,{children:r("ecommerce.product")}),e.jsx(a.TableHead,{children:r("ecommerce.quantity")}),e.jsx(a.TableHead,{className:"text-right",children:r("ecommerce.price")}),e.jsx(a.TableHead,{className:"text-right",children:r("ecommerce.total")}),e.jsx(a.TableHead,{className:"w-[50px]",children:e.jsx("span",{className:"sr-only",children:l("ecommerce.actions","Actions")})})]})}),e.jsx(a.TableBody,{children:n.map(s=>{const t=_(s.sku),c=j.getCartItemActivePrice(s,{currencyCode:i,currencies:h}),o=R.getTrialSummary(s,r);return e.jsxs(a.TableRow,{children:[e.jsx(a.TableCell,{children:e.jsxs("div",{className:"flex items-center gap-4",children:[s.image_url?e.jsx("div",{className:"h-16 w-16 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"})}):e.jsx("div",{className:"flex h-16 w-16 items-center justify-center rounded bg-secondary",children:e.jsx("span",{className:"text-[10px] text-muted-foreground",children:r("ecommerce.no_image")})}),e.jsxs("div",{className:"min-w-0 break-words",children:[e.jsx("div",{className:"font-medium",children:s.title}),s.variant_label&&e.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:s.variant_label}),m.isDigitalItem(s)&&s.billing_cycle&&e.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:l(`ecommerce.checkout_billing_cycle_${s.billing_cycle}`,`${s.billing_cycle} subscription`)}),o&&e.jsxs("div",{className:"mt-1 text-xs font-medium text-emerald-700",children:[o.label," - ",o.paymentRequirementLabel]})]})]})}),e.jsx(a.TableCell,{children:m.isDigitalItem(s)?e.jsx(C.Badge,{variant:"secondary",className:"font-normal text-xs",children:l("ecommerce.license_count_one","1 license",{count:1})}):e.jsxs("div",{role:"group","aria-label":`${l("ecommerce.quantity","Quantity")}: ${s.title}`,className:"flex items-center gap-2",children:[e.jsx(d.Button,{variant:"outline",size:"icon",className:"h-8 w-8","aria-label":l("ecommerce.decrease_quantity","Decrease quantity"),onClick:()=>p(s.id,s.quantity-1),children:e.jsx(g.Minus,{className:"h-4 w-4"})}),e.jsx("span",{"aria-live":"polite","aria-atomic":"true",className:"w-8 text-center tabular-nums",children:s.quantity}),e.jsx(d.Button,{variant:"outline",size:"icon",className:"h-8 w-8","aria-label":l("ecommerce.increase_quantity","Increase quantity"),onClick:()=>p(s.id,s.quantity+1),disabled:typeof s.stock=="number"&&t>=s.stock,children:e.jsx(g.Plus,{className:"h-4 w-4"})})]})}),e.jsx(a.TableCell,{className:"text-right",children:e.jsxs("div",{className:"flex flex-col items-end tabular-nums",children:[e.jsxs("span",{className:"font-medium",children:[c.sale_price&&e.jsxs("span",{className:"sr-only",children:[l("ecommerce.sale_price","Sale price")," "]}),u(c.sale_price??c.price,i)]}),c.sale_price&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:[e.jsxs("span",{className:"sr-only",children:[l("ecommerce.regular_price","Regular price")," "]}),e.jsx("s",{children:u(c.price,i)})]})]})}),e.jsx(a.TableCell,{className:"text-right font-medium tabular-nums",children:u((c.sale_price??c.price)*s.quantity,i)}),e.jsx(a.TableCell,{children:e.jsx(d.Button,{variant:"ghost",size:"icon",onClick:()=>f(s.id),"aria-label":l("ecommerce.remove_item",`Remove ${s.title} from cart`,{item:s.title}),className:"text-muted-foreground hover:text-destructive",children:e.jsx(g.Trash2,{className:"h-4 w-4"})})})]},s.id)})})]})})}),e.jsx("div",{className:"lg:col-span-4",children:e.jsxs("div",{className:"rounded-lg border bg-card p-6 shadow-sm",children:[e.jsx("h2",{className:"mb-4 text-lg font-semibold",children:r("ecommerce.order_summary")}),e.jsxs("div",{className:"flex justify-between border-b pb-4",children:[e.jsx("span",{children:r("ecommerce.subtotal")}),e.jsx("span",{className:"font-medium tabular-nums",children:u(N,i)})]}),e.jsxs("div",{className:"mt-4 flex flex-col gap-4",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:r("ecommerce.shipping_taxes_calculated")}),n.some(s=>!m.isDigitalItem(s))&&e.jsx(S.ShippingEstimator,{physicalSubtotal:v}),e.jsx(B.CouponForm,{items:n,currencyCode:i,compact:!0}),e.jsx(d.Button,{asChild:!0,className:"w-full mt-4",size:"lg",children:e.jsx(b,{href:"/checkout",children:r("ecommerce.proceed_to_checkout")})})]})]})})]})]})};exports.Cart=H;
@@ -1 +1 @@
1
- export declare const Cart: () => import("react").JSX.Element | null;
1
+ export declare const Cart: () => import("react").JSX.Element;
@@ -3,57 +3,65 @@ import { jsxs as c, jsx as e } from "react/jsx-runtime";
3
3
  import { useMemo as q } from "react";
4
4
  import { Badge as T } from "@nextblock-cms/ui/badge";
5
5
  import { Button as m } from "@nextblock-cms/ui/button";
6
- import { Table as S, TableHeader as j, TableRow as b, TableHead as d, TableBody as P, TableCell as u } from "@nextblock-cms/ui/table";
6
+ import { Table as S, TableHeader as j, TableRow as N, TableHead as d, TableBody as P, TableCell as u } from "@nextblock-cms/ui/table";
7
7
  import { Minus as $, Plus as z, Trash2 as Q } from "lucide-react";
8
- import { useCartSubtotal as R, getCartItemActivePrice as N } from "../cart-store.es.js";
8
+ import { useCartSubtotal as R, getCartItemActivePrice as x } from "../cart-store.es.js";
9
9
  import { useCart as A } from "../use-cart.es.js";
10
10
  import { isDigitalItem as h } from "../types.es.js";
11
11
  import y from "next/link";
12
12
  import { useTranslations as B } from "@nextblock-cms/utils";
13
13
  import { usePriceFormatter as H } from "../use-price-formatter.es.js";
14
- import { ShippingEstimator as D } from "./ShippingEstimator.es.js";
15
- import { useCurrency as F } from "../CurrencyProvider.es.js";
16
- import { getTrialSummary as I } from "../trials.es.js";
17
- import { CouponForm as L } from "./CouponForm.es.js";
18
- const te = () => {
19
- const p = H(), f = A((r) => r), v = R(), { t } = B(), i = (r, l, a) => {
20
- const o = t(r, a);
21
- return o === r ? l : o;
22
- }, _ = "/shop", { activeCurrencyCode: s, currencies: g } = F(), n = f?.items ?? [], w = q(
23
- () => n.reduce((r, l) => {
24
- if (h(l))
14
+ import { ShippingEstimator as L } from "./ShippingEstimator.es.js";
15
+ import { useCurrency as D } from "../CurrencyProvider.es.js";
16
+ import { getTrialSummary as F } from "../trials.es.js";
17
+ import { CouponForm as I } from "./CouponForm.es.js";
18
+ const le = () => {
19
+ const p = H(), g = A((r) => r), v = R(), { t: a } = B(), s = (r, t, l) => {
20
+ const o = a(r, l);
21
+ return o === r ? t : o;
22
+ }, _ = "/shop", { activeCurrencyCode: i, currencies: f } = D(), n = g?.items ?? [], w = q(
23
+ () => n.reduce((r, t) => {
24
+ if (h(t))
25
25
  return r;
26
- const a = N(l, {
27
- currencyCode: s,
28
- currencies: g
26
+ const l = x(t, {
27
+ currencyCode: i,
28
+ currencies: f
29
29
  });
30
- return r + (a.sale_price ?? a.price) * l.quantity;
30
+ return r + (l.sale_price ?? l.price) * t.quantity;
31
31
  }, 0),
32
- [s, g, n]
32
+ [i, f, n]
33
33
  );
34
- if (!f) return null;
35
- const { updateQuantity: x, removeItem: C } = f, k = (r) => n.reduce((l, a) => h(a) || a.sku !== r ? l : l + a.quantity, 0);
34
+ if (!g)
35
+ return /* @__PURE__ */ c("div", { role: "status", "aria-busy": "true", className: "container mx-auto py-12", children: [
36
+ /* @__PURE__ */ e("span", { className: "sr-only", children: a("loading") === "loading" ? "Loading…" : a("loading") }),
37
+ /* @__PURE__ */ e("div", { className: "mb-8 h-9 w-56 rounded-md bg-muted" }),
38
+ /* @__PURE__ */ c("div", { className: "grid gap-12 lg:grid-cols-12 lg:items-start", children: [
39
+ /* @__PURE__ */ e("div", { className: "h-64 rounded-lg border bg-muted/40 lg:col-span-8" }),
40
+ /* @__PURE__ */ e("div", { className: "h-64 rounded-lg border bg-muted/40 lg:col-span-4" })
41
+ ] })
42
+ ] });
43
+ const { updateQuantity: b, removeItem: C } = g, k = (r) => n.reduce((t, l) => h(l) || l.sku !== r ? t : t + l.quantity, 0);
36
44
  return n.length === 0 ? /* @__PURE__ */ c("div", { className: "flex flex-col items-center justify-center space-y-4 py-12", children: [
37
- /* @__PURE__ */ e("h1", { className: "text-2xl font-bold", children: t("ecommerce.cart_empty") }),
38
- /* @__PURE__ */ e("p", { className: "text-muted-foreground", children: t("ecommerce.cart_empty_description") }),
39
- /* @__PURE__ */ e(m, { asChild: !0, children: /* @__PURE__ */ e(y, { href: _, children: t("ecommerce.continue_shopping") }) })
45
+ /* @__PURE__ */ e("h1", { className: "text-2xl font-bold", children: a("ecommerce.cart_empty") }),
46
+ /* @__PURE__ */ e("p", { className: "text-muted-foreground", children: a("ecommerce.cart_empty_description") }),
47
+ /* @__PURE__ */ e(m, { asChild: !0, children: /* @__PURE__ */ e(y, { href: _, children: a("ecommerce.continue_shopping") }) })
40
48
  ] }) : /* @__PURE__ */ c("div", { className: "container mx-auto py-12", children: [
41
- /* @__PURE__ */ e("h1", { className: "mb-8 text-3xl font-bold", children: t("ecommerce.shopping_cart") }),
49
+ /* @__PURE__ */ e("h1", { className: "mb-8 text-3xl font-bold", children: a("ecommerce.shopping_cart") }),
42
50
  /* @__PURE__ */ c("div", { className: "grid gap-12 lg:grid-cols-12 lg:items-start", children: [
43
51
  /* @__PURE__ */ e("div", { className: "lg:col-span-8", children: /* @__PURE__ */ e("div", { className: "rounded-lg border overflow-hidden", children: /* @__PURE__ */ c(S, { children: [
44
- /* @__PURE__ */ e(j, { children: /* @__PURE__ */ c(b, { children: [
45
- /* @__PURE__ */ e(d, { children: t("ecommerce.product") }),
46
- /* @__PURE__ */ e(d, { children: t("ecommerce.quantity") }),
47
- /* @__PURE__ */ e(d, { className: "text-right", children: t("ecommerce.price") }),
48
- /* @__PURE__ */ e(d, { className: "text-right", children: t("ecommerce.total") }),
49
- /* @__PURE__ */ e(d, { className: "w-[50px]", children: /* @__PURE__ */ e("span", { className: "sr-only", children: i("ecommerce.actions", "Actions") }) })
52
+ /* @__PURE__ */ e(j, { children: /* @__PURE__ */ c(N, { children: [
53
+ /* @__PURE__ */ e(d, { children: a("ecommerce.product") }),
54
+ /* @__PURE__ */ e(d, { children: a("ecommerce.quantity") }),
55
+ /* @__PURE__ */ e(d, { className: "text-right", children: a("ecommerce.price") }),
56
+ /* @__PURE__ */ e(d, { className: "text-right", children: a("ecommerce.total") }),
57
+ /* @__PURE__ */ e(d, { className: "w-[50px]", children: /* @__PURE__ */ e("span", { className: "sr-only", children: s("ecommerce.actions", "Actions") }) })
50
58
  ] }) }),
51
59
  /* @__PURE__ */ e(P, { children: n.map((r) => {
52
- const l = k(r.sku), a = N(r, {
53
- currencyCode: s,
54
- currencies: g
55
- }), o = I(r, t);
56
- return /* @__PURE__ */ c(b, { children: [
60
+ const t = k(r.sku), l = x(r, {
61
+ currencyCode: i,
62
+ currencies: f
63
+ }), o = F(r, a);
64
+ return /* @__PURE__ */ c(N, { children: [
57
65
  /* @__PURE__ */ e(u, { children: /* @__PURE__ */ c("div", { className: "flex items-center gap-4", children: [
58
66
  r.image_url ? /* @__PURE__ */ e("div", { className: "h-16 w-16 overflow-hidden rounded border bg-neutral-100", children: /* @__PURE__ */ e(
59
67
  "img",
@@ -62,11 +70,11 @@ const te = () => {
62
70
  alt: r.title,
63
71
  className: "h-full w-full object-cover"
64
72
  }
65
- ) }) : /* @__PURE__ */ e("div", { className: "flex h-16 w-16 items-center justify-center rounded bg-secondary", children: /* @__PURE__ */ e("span", { className: "text-[10px] text-muted-foreground", children: t("ecommerce.no_image") }) }),
73
+ ) }) : /* @__PURE__ */ e("div", { className: "flex h-16 w-16 items-center justify-center rounded bg-secondary", children: /* @__PURE__ */ e("span", { className: "text-[10px] text-muted-foreground", children: a("ecommerce.no_image") }) }),
66
74
  /* @__PURE__ */ c("div", { className: "min-w-0 break-words", children: [
67
75
  /* @__PURE__ */ e("div", { className: "font-medium", children: r.title }),
68
76
  r.variant_label && /* @__PURE__ */ e("div", { className: "mt-1 text-xs text-muted-foreground", children: r.variant_label }),
69
- h(r) && r.billing_cycle && /* @__PURE__ */ e("div", { className: "mt-1 text-xs text-muted-foreground", children: i(
77
+ h(r) && r.billing_cycle && /* @__PURE__ */ e("div", { className: "mt-1 text-xs text-muted-foreground", children: s(
70
78
  `ecommerce.checkout_billing_cycle_${r.billing_cycle}`,
71
79
  `${r.billing_cycle} subscription`
72
80
  ) }),
@@ -77,11 +85,11 @@ const te = () => {
77
85
  ] })
78
86
  ] })
79
87
  ] }) }),
80
- /* @__PURE__ */ e(u, { children: h(r) ? /* @__PURE__ */ e(T, { variant: "secondary", className: "font-normal text-xs", children: i("ecommerce.license_count_one", "1 license", { count: 1 }) }) : /* @__PURE__ */ c(
88
+ /* @__PURE__ */ e(u, { children: h(r) ? /* @__PURE__ */ e(T, { variant: "secondary", className: "font-normal text-xs", children: s("ecommerce.license_count_one", "1 license", { count: 1 }) }) : /* @__PURE__ */ c(
81
89
  "div",
82
90
  {
83
91
  role: "group",
84
- "aria-label": `${i("ecommerce.quantity", "Quantity")}: ${r.title}`,
92
+ "aria-label": `${s("ecommerce.quantity", "Quantity")}: ${r.title}`,
85
93
  className: "flex items-center gap-2",
86
94
  children: [
87
95
  /* @__PURE__ */ e(
@@ -90,8 +98,8 @@ const te = () => {
90
98
  variant: "outline",
91
99
  size: "icon",
92
100
  className: "h-8 w-8",
93
- "aria-label": i("ecommerce.decrease_quantity", "Decrease quantity"),
94
- onClick: () => x(r.id, r.quantity - 1),
101
+ "aria-label": s("ecommerce.decrease_quantity", "Decrease quantity"),
102
+ onClick: () => b(r.id, r.quantity - 1),
95
103
  children: /* @__PURE__ */ e($, { className: "h-4 w-4" })
96
104
  }
97
105
  ),
@@ -102,9 +110,9 @@ const te = () => {
102
110
  variant: "outline",
103
111
  size: "icon",
104
112
  className: "h-8 w-8",
105
- "aria-label": i("ecommerce.increase_quantity", "Increase quantity"),
106
- onClick: () => x(r.id, r.quantity + 1),
107
- disabled: typeof r.stock == "number" && l >= r.stock,
113
+ "aria-label": s("ecommerce.increase_quantity", "Increase quantity"),
114
+ onClick: () => b(r.id, r.quantity + 1),
115
+ disabled: typeof r.stock == "number" && t >= r.stock,
108
116
  children: /* @__PURE__ */ e(z, { className: "h-4 w-4" })
109
117
  }
110
118
  )
@@ -113,23 +121,23 @@ const te = () => {
113
121
  ) }),
114
122
  /* @__PURE__ */ e(u, { className: "text-right", children: /* @__PURE__ */ c("div", { className: "flex flex-col items-end tabular-nums", children: [
115
123
  /* @__PURE__ */ c("span", { className: "font-medium", children: [
116
- a.sale_price && /* @__PURE__ */ c("span", { className: "sr-only", children: [
117
- i("ecommerce.sale_price", "Sale price"),
124
+ l.sale_price && /* @__PURE__ */ c("span", { className: "sr-only", children: [
125
+ s("ecommerce.sale_price", "Sale price"),
118
126
  " "
119
127
  ] }),
120
- p(a.sale_price ?? a.price, s)
128
+ p(l.sale_price ?? l.price, i)
121
129
  ] }),
122
- a.sale_price && /* @__PURE__ */ c("span", { className: "text-xs text-muted-foreground", children: [
130
+ l.sale_price && /* @__PURE__ */ c("span", { className: "text-xs text-muted-foreground", children: [
123
131
  /* @__PURE__ */ c("span", { className: "sr-only", children: [
124
- i("ecommerce.regular_price", "Regular price"),
132
+ s("ecommerce.regular_price", "Regular price"),
125
133
  " "
126
134
  ] }),
127
- /* @__PURE__ */ e("s", { children: p(a.price, s) })
135
+ /* @__PURE__ */ e("s", { children: p(l.price, i) })
128
136
  ] })
129
137
  ] }) }),
130
138
  /* @__PURE__ */ e(u, { className: "text-right font-medium tabular-nums", children: p(
131
- (a.sale_price ?? a.price) * r.quantity,
132
- s
139
+ (l.sale_price ?? l.price) * r.quantity,
140
+ i
133
141
  ) }),
134
142
  /* @__PURE__ */ e(u, { children: /* @__PURE__ */ e(
135
143
  m,
@@ -137,7 +145,7 @@ const te = () => {
137
145
  variant: "ghost",
138
146
  size: "icon",
139
147
  onClick: () => C(r.id),
140
- "aria-label": i("ecommerce.remove_item", `Remove ${r.title} from cart`, { item: r.title }),
148
+ "aria-label": s("ecommerce.remove_item", `Remove ${r.title} from cart`, { item: r.title }),
141
149
  className: "text-muted-foreground hover:text-destructive",
142
150
  children: /* @__PURE__ */ e(Q, { className: "h-4 w-4" })
143
151
  }
@@ -146,28 +154,28 @@ const te = () => {
146
154
  }) })
147
155
  ] }) }) }),
148
156
  /* @__PURE__ */ e("div", { className: "lg:col-span-4", children: /* @__PURE__ */ c("div", { className: "rounded-lg border bg-card p-6 shadow-sm", children: [
149
- /* @__PURE__ */ e("h2", { className: "mb-4 text-lg font-semibold", children: t("ecommerce.order_summary") }),
157
+ /* @__PURE__ */ e("h2", { className: "mb-4 text-lg font-semibold", children: a("ecommerce.order_summary") }),
150
158
  /* @__PURE__ */ c("div", { className: "flex justify-between border-b pb-4", children: [
151
- /* @__PURE__ */ e("span", { children: t("ecommerce.subtotal") }),
152
- /* @__PURE__ */ e("span", { className: "font-medium tabular-nums", children: p(v, s) })
159
+ /* @__PURE__ */ e("span", { children: a("ecommerce.subtotal") }),
160
+ /* @__PURE__ */ e("span", { className: "font-medium tabular-nums", children: p(v, i) })
153
161
  ] }),
154
162
  /* @__PURE__ */ c("div", { className: "mt-4 flex flex-col gap-4", children: [
155
- /* @__PURE__ */ e("p", { className: "text-sm text-muted-foreground", children: t("ecommerce.shipping_taxes_calculated") }),
156
- n.some((r) => !h(r)) && /* @__PURE__ */ e(D, { physicalSubtotal: w }),
163
+ /* @__PURE__ */ e("p", { className: "text-sm text-muted-foreground", children: a("ecommerce.shipping_taxes_calculated") }),
164
+ n.some((r) => !h(r)) && /* @__PURE__ */ e(L, { physicalSubtotal: w }),
157
165
  /* @__PURE__ */ e(
158
- L,
166
+ I,
159
167
  {
160
168
  items: n,
161
- currencyCode: s,
169
+ currencyCode: i,
162
170
  compact: !0
163
171
  }
164
172
  ),
165
- /* @__PURE__ */ e(m, { asChild: !0, className: "w-full mt-4", size: "lg", children: /* @__PURE__ */ e(y, { href: "/checkout", children: t("ecommerce.proceed_to_checkout") }) })
173
+ /* @__PURE__ */ e(m, { asChild: !0, className: "w-full mt-4", size: "lg", children: /* @__PURE__ */ e(y, { href: "/checkout", children: a("ecommerce.proceed_to_checkout") }) })
166
174
  ] })
167
175
  ] }) })
168
176
  ] })
169
177
  ] });
170
178
  };
171
179
  export {
172
- te as Cart
180
+ le as Cart
173
181
  };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),ze=require("@nextblock-cms/ui/badge"),je=require("@nextblock-cms/ui/button"),f=require("@nextblock-cms/ui/card"),lt=require("@nextblock-cms/ui/checkbox"),T=require("@nextblock-cms/ui/input"),y=require("@nextblock-cms/ui/label"),at=require("@nextblock-cms/ui/separator"),Y=require("@nextblock-cms/ui/radio-group"),it=require("@freemius/checkout"),Ce=require("../cart-store.cjs.js"),ot=require("../use-cart.cjs.js"),l=require("react"),S=require("lucide-react"),Oe=require("@nextblock-cms/utils"),dt=require("../use-price-formatter.cjs.js"),Ue=require("../countries.cjs.js"),ut=require("../PaymentReadinessProvider.cjs.js"),mt=require("../server-actions/shipping-actions.cjs.js"),pt=require("../server-actions/tax-actions.cjs.js"),ve=require("../types.cjs.js"),G=require("../states.cjs.js"),U=require("../customer.cjs.js"),ht=require("../CurrencyProvider.cjs.js"),De=require("../trials.cjs.js"),xt=require("./CouponForm.cjs.js"),gt=process.env.NEXT_PUBLIC_IS_SANDBOX==="true",oe="nextblock-checkout-draft-v1";function de(s,o){return{...U.emptyCustomerAddress(),company_name:s?.company_name||"",recipient_name:s?.recipient_name||o||"",line1:s?.line1||"",line2:s?.line2||"",city:s?.city||"",state:s?.state||"",postal_code:s?.postal_code||"",country_code:Ue.normalizeCountryCode(s?.country_code)||"CA"}}function ft(s){const o=U.normalizeCustomerAddress(s);return!(!o?.country_code||!o.postal_code||G.countryUsesStructuredStates(o.country_code)&&!o.state)}function Ne(s,o,$){return s.reduce((m,g)=>{const{price:x,sale_price:F}=Ce.getCartItemActivePrice(g,{currencyCode:o,currencies:$});return m+(F??x)*g.quantity},0)}function Pe({idPrefix:s,title:o,description:$,value:m,onChange:g}){const{t:x,lang:F}=Oe.useTranslations(),q=l.useMemo(()=>{try{return new Intl.DisplayNames([F],{type:"region"})}catch{return null}},[F]),I=x("company_name")==="company_name"?"Company name":x("company_name"),W=x("select_an_option")==="select_an_option"?"Select an option":x("select_an_option"),D=x("state_province")==="state_province"?"State / Province":x("state_province"),H=G.getStatesForCountry(m.country_code),K=G.countryUsesStructuredStates(m.country_code);return e.jsxs(f.Card,{children:[e.jsxs(f.CardHeader,{children:[e.jsxs(f.CardTitle,{role:"heading","aria-level":2,className:"flex items-center gap-2",children:[e.jsx(S.MapPin,{className:"w-5 h-5"}),o]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:$})]}),e.jsxs(f.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(y.Label,{htmlFor:`${s}-company`,children:I}),e.jsx(T.Input,{id:`${s}-company`,name:`${s}-company`,autoComplete:`${s} organization`,value:m.company_name,onChange:u=>g({...m,company_name:u.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(y.Label,{htmlFor:`${s}-name`,children:x("full_name")}),e.jsx(T.Input,{id:`${s}-name`,name:`${s}-name`,autoComplete:`${s} name`,required:!0,value:m.recipient_name,onChange:u=>g({...m,recipient_name:u.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(y.Label,{htmlFor:`${s}-country`,children:x("country")}),e.jsx("select",{id:`${s}-country`,name:`${s}-country`,autoComplete:`${s} country`,required:!0,className:"flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",value:m.country_code,onChange:u=>{const Z=u.target.value,ee=G.getStatesForCountry(Z);g({...m,country_code:Z,state:ee.some(ue=>ue.code===m.state)?m.state:""})},children:Ue.countries.map(u=>e.jsx("option",{value:u.code,children:q?.of(u.code)??u.name},u.code))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(y.Label,{htmlFor:`${s}-line1`,children:x("address_line_1")}),e.jsx(T.Input,{id:`${s}-line1`,name:`${s}-line1`,autoComplete:`${s} address-line1`,required:!0,value:m.line1,onChange:u=>g({...m,line1:u.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(y.Label,{htmlFor:`${s}-line2`,children:x("address_line_2")}),e.jsx(T.Input,{id:`${s}-line2`,name:`${s}-line2`,autoComplete:`${s} address-line2`,value:m.line2,onChange:u=>g({...m,line2:u.target.value})})]}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(y.Label,{htmlFor:`${s}-city`,children:x("city")}),e.jsx(T.Input,{id:`${s}-city`,name:`${s}-city`,autoComplete:`${s} address-level2`,required:!0,value:m.city,onChange:u=>g({...m,city:u.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(y.Label,{htmlFor:`${s}-state`,children:x("state_province")}),K?e.jsxs("select",{id:`${s}-state`,name:`${s}-state`,autoComplete:`${s} address-level1`,required:!0,className:"flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",value:m.state,onChange:u=>g({...m,state:u.target.value}),children:[e.jsx("option",{value:"",children:`${W}: ${D}`}),H.map(u=>e.jsx("option",{value:u.code,children:u.name},u.code))]}):e.jsx(T.Input,{id:`${s}-state`,name:`${s}-state`,autoComplete:`${s} address-level1`,value:m.state,onChange:u=>g({...m,state:u.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(y.Label,{htmlFor:`${s}-postal`,children:x("postal_zip_code")}),e.jsx(T.Input,{id:`${s}-postal`,name:`${s}-postal`,autoComplete:`${s} postal-code`,required:!0,value:m.postal_code,onChange:u=>g({...m,postal_code:u.target.value})})]})]})]})]})}function Be({title:s,description:o,badgeLabel:$,children:m}){return e.jsxs(f.Card,{children:[e.jsx(f.CardHeader,{children:e.jsxs("div",{className:"flex items-center justify-between gap-3 flex-wrap",children:[e.jsxs("div",{children:[e.jsx(f.CardTitle,{role:"heading","aria-level":2,children:s}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:o})]}),$?e.jsx(ze.Badge,{variant:"secondary",children:$}):null]})}),e.jsx(f.CardContent,{className:"space-y-4",children:m})]})}const _t=({initialCustomer:s})=>{const o=dt.usePriceFormatter(),[$,m]=l.useState({}),[g,x]=l.useState(null),[F,q]=l.useState({}),[I,W]=l.useState(s?.email||""),[D,H]=l.useState(""),[K,u]=l.useState(s?.phone||""),[Z,ee]=l.useState(!1),[ue,ke]=l.useState(null),[we,te]=l.useState(!1),[Ke,Se]=l.useState(!1),[Ge,se]=l.useState(!1),[J,Q]=l.useState([]),[A,P]=l.useState(null),[N,re]=l.useState(null),[L,He]=l.useState(null),[C,$e]=l.useState(()=>de(s?.billingAddress,s?.fullName)),[B,Fe]=l.useState(()=>de(s?.shippingAddress??s?.billingAddress,s?.fullName)),[M,Ae]=l.useState(!s?.shippingAddress||U.addressesMatch(s?.billingAddress,s?.shippingAddress)),V=ot.useCart(t=>t),{t:n,lang:me}=Oe.useTranslations(),{activeCurrencyCode:i,currencies:E}=ht.useCurrency(),Te=ut.usePaymentReadiness(),b=V?.items??[],j=l.useMemo(()=>b.filter(t=>!ve.isDigitalItem(t)),[b]),k=l.useMemo(()=>b.filter(t=>ve.isDigitalItem(t)),[b]),z=s?.isAuthenticated??!1,r=(t,c,h)=>{const a=n(t,h);if(a!==t)return a;if(!h)return c;let _=c;return Object.entries(h).forEach(([p,d])=>{_=_.replace(new RegExp(`\\{${p}\\}`,"g"),String(d))}),_},v=j.length>0,Je=l.useMemo(()=>Ne(b,i,E),[i,E,b]),pe=l.useMemo(()=>Ne(j,i,E),[i,E,j]),he=l.useMemo(()=>Ne(k,i,E),[i,E,k]),xe=L?.providerDiscounts.stripe??0,ge=L?.providerDiscounts.freemius??0,ne=Math.max(0,pe-xe),Qe=Math.max(0,he-ge),w=l.useMemo(()=>M?C:B,[C,B,M]),O=l.useMemo(()=>v?w:C,[C,v,w]),ce=!v||ft(w),le=l.useMemo(()=>J.find(t=>t.id===A),[J,A]),qe=l.useMemo(()=>ne+(le?.amount??0)+(N&&!N.isPendingExternalCalculation?N.amount:0),[ne,le,N]),Ve=qe+Qe;if(l.useEffect(()=>{if(!(z||typeof window>"u"))try{const t=window.localStorage.getItem(oe);if(!t)return;const c=JSON.parse(t);c.email&&W(c.email),c.phone&&u(c.phone),c.billingAddress&&$e(de(c.billingAddress)),c.shippingAddress&&Fe(de(c.shippingAddress)),typeof c.useBillingForShipping=="boolean"&&Ae(c.useBillingForShipping),(typeof c.selectedMethodId=="string"||c.selectedMethodId===null)&&P(c.selectedMethodId)}catch(t){console.error("[Checkout] Failed to restore checkout draft:",t)}},[z]),l.useEffect(()=>{if(!(typeof window>"u"))try{if(z){window.localStorage.removeItem(oe);return}window.localStorage.setItem(oe,JSON.stringify({email:I,phone:K,billingAddress:C,shippingAddress:B,useBillingForShipping:M,selectedMethodId:A}))}catch{}},[C,I,z,K,A,B,M]),l.useEffect(()=>{if(!v){Q([]),P(null),te(!1);return}if(!ce){Q([]),P(null),te(!1);return}let t=!1;const h=setTimeout(async()=>{if(w.country_code){te(!0),Se(!1);try{const a=await mt.getShippingEstimates(ne,{country:w.country_code,state:w.state,postal_code:w.postal_code},me,i);if(t)return;if(a.success&&a.methods){const _=a.methods;Q(_),P(p=>p&&_.some(d=>d.id===p)?p:_[0]?.id??null)}else Q([]),P(null)}catch(a){if(t)return;console.error("[Checkout] Failed to load shipping rates:",a),Q([]),P(null),Se(!0)}finally{t||te(!1)}}},400);return()=>{t=!0,clearTimeout(h)}},[i,v,ce,me,w.country_code,w.postal_code,w.state,ne]),l.useEffect(()=>{let t=!1;const h=setTimeout(async()=>{if(!v||!O.country_code){se(!1),re(null);return}if(G.countryUsesStructuredStates(O.country_code)&&!O.state){se(!1),re(null);return}se(!0);try{const a=await pt.getTaxEstimate(j,{country_code:O.country_code,state:O.state},i,L?.code??null,b);if(t)return;re(a.success&&a.tax?a.tax:null)}catch(a){if(t)return;console.error("[Checkout] Failed to load the tax estimate:",a),re(null)}finally{t||se(!1)}},300);return()=>{t=!0,clearTimeout(h)}},[i,v,j,O.country_code,O.state,L?.code,b]),l.useEffect(()=>{const t=c=>{c.persisted&&x(null)};return window.addEventListener("pageshow",t),()=>window.removeEventListener("pageshow",t)},[]),!V)return null;const fe=()=>{ee(!1),ke(null)},Ie=Z?e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center overscroll-contain bg-black/60 backdrop-blur-sm",onClick:fe,onKeyDown:t=>{t.key==="Escape"&&fe()},children:e.jsxs("div",{role:"dialog","aria-modal":"true","aria-labelledby":"sandbox-checkout-title",className:"relative bg-background border rounded-xl shadow-2xl p-8 max-w-md mx-4",onClick:t=>t.stopPropagation(),children:[e.jsx("button",{type:"button",autoFocus:!0,onClick:fe,"aria-label":r("close","Close"),className:"absolute top-4 right-4 inline-flex h-8 w-8 items-center justify-center rounded-md text-muted-foreground hover:text-foreground transition-colors focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring",children:e.jsx(S.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(S.FlaskConical,{className:"h-6 w-6 text-amber-600 dark:text-amber-400"})}),e.jsx("h2",{id:"sandbox-checkout-title",className:"text-xl font-semibold",children:n("ecommerce.checkout_successful")})]}),e.jsx("p",{className:"text-muted-foreground mb-2",children:n("ecommerce.sandbox_notice")}),e.jsx("p",{className:"text-muted-foreground mb-2",children:ue==="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:n("ecommerce.license_notice")}),e.jsx("a",{href:"https://nextblock.dev",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:n("ecommerce.purchase_at")})]})}):null,ae=(t,c,h)=>(q(a=>({...a,[t]:c})),h&&document.getElementById(h)?.focus(),null),_e=(t,c)=>c.recipient_name.trim()?c.line1.trim()?c.city.trim()?G.countryUsesStructuredStates(c.country_code)&&!c.state?`${t}-state`:c.postal_code.trim()?`${t}-line1`:`${t}-postal`:`${t}-city`:`${t}-line1`:`${t}-name`,Xe=t=>{if(!z&&(!I||!/^\S+@\S+\.\S+$/.test(I)))return H(n("ecommerce.invalid_email")),ae(t,n("ecommerce.invalid_email"),"checkout-email");const c=U.normalizeCustomerAddress(C);if(!U.isCustomerAddressComplete(c))return ae(t,n("checkout_complete_billing_address"),_e("billing",C));const h=v?U.normalizeCustomerAddress(M?C:B):null;if(t==="stripe"){if(!U.isCustomerAddressComplete(h))return ae(t,n("checkout_complete_shipping_address"),M?_e("billing",C):_e("shipping",B));if(!A)return ae(t,r("ecommerce.shipping_method_required","Please select a shipping method before continuing."))}return H(""),{normalizedBillingAddress:c,normalizedShippingAddress:h}},Le=async(t,c,h)=>{q(_=>({..._,[t]:""}));const a=Xe(t);if(a){if(gt){const _=new Set(c.map(d=>d.id)),p=b.filter(d=>!_.has(d.id));if(V.setItems(p),p.length===0&&V.removeCoupon(),ke(t),ee(!0),typeof window<"u"&&p.length===0)try{window.localStorage.removeItem(oe)}catch{}return}x(h);try{const _=await fetch("/api/checkout",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({items:c,customerEmail:z?void 0:I,customerPhone:K||null,billingAddress:a.normalizedBillingAddress,shippingAddress:t==="stripe"?a.normalizedShippingAddress:null,shippingMethodId:t==="stripe"?A:null,locale:me,currencyCode:i,couponCode:L?.code??V.appliedCoupon?.code??null,couponContextItems:b})}),p=await _.json();if(!_.ok){const d=p?.errorKey&&typeof p.errorKey=="string"?r(p.errorKey,p?.error||r("ecommerce.generic_error","Something went wrong."),p.errorParams):p?.error||n("ecommerce.generic_error");q(X=>({...X,[t]:d})),x(null);return}if(p.customProps&&p.customProps.provider==="freemius"){const d=p.customProps;let X=null;const st=()=>{window.location.href=`/checkout/success?session_id=${d.order_id}`},Re=R=>(X||(X=fetch("/api/checkout/freemius/sync",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({orderId:d.order_id,checkoutResponse:R})}).then(async ie=>{if(!ie.ok){const ct=await ie.json().catch(()=>null);console.error("Freemius checkout sync failed:",ct)}})),X),rt={product_id:d.plugin_id,public_key:d.public_key,sandbox:d.sandbox},nt={name:n("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(R){Re(R)},success:function(R){(async()=>{try{await Re(R)}finally{st()}})()}};try{new it.Checkout(rt).open(nt),x(null)}catch(R){console.error("[Checkout] Freemius overlay failed to open:",R),q(ie=>({...ie,[t]:n("ecommerce.checkout_popup_blocked")})),p.url&&(window.location.href=p.url),x(null)}}else p.url?window.location.href=p.url:(q(d=>({...d,[t]:n("ecommerce.checkout_failed")+(p.error||r("ecommerce.unknown_error","Unknown error"))})),x(null))}catch(_){console.error(_),q(p=>({...p,[t]:n("ecommerce.generic_error")})),x(null)}}};if(b.length===0)return e.jsxs(e.Fragment,{children:[Ie,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:n("ecommerce.cart_empty")}),e.jsx("p",{className:"mb-8 text-muted-foreground",children:n("ecommerce.cart_empty_description")}),e.jsx(je.Button,{asChild:!0,children:e.jsx("a",{href:"/shop",children:n("ecommerce.go_to_shop")})})]})]});const Me=r("ecommerce.checkout_payments_unavailable","This store is not able to take payments right now. Please contact the seller to complete your purchase."),Ee=Te.stripe?null:Me,ye=Te.freemius?null:Me,be=Ee||(v?ce?we?r("ecommerce.calculating_shipping","Calculating shipping..."):A?null:J.length>0?n("ecommerce.select_rate"):n("ecommerce.no_rates_for_region"):r("ecommerce.waiting_on_address_info","Complete your shipping address to view available shipping options."):null),Ye=g!==null||be!==null,We=j.length===1?r("ecommerce.item_count_one","{count} item",{count:j.length}):r("ecommerce.item_count_other","{count} items",{count:j.length}),Ze=k.length===1?r("ecommerce.license_count_one","{count} license",{count:k.length}):r("ecommerce.license_count_other","{count} licenses",{count:k.length}),et=t=>ve.isDigitalItem(t)?r("ecommerce.digital_label","Digital"):r("ecommerce.physical_label","Physical"),tt=t=>t==="monthly"?r("ecommerce.checkout_billing_cycle_monthly","Monthly subscription"):t==="annual"?r("ecommerce.checkout_billing_cycle_annual","Annual subscription"):t==="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:[Ie,e.jsxs("div",{className:"mx-auto max-w-6xl",children:[e.jsx("h1",{className:"mb-8 text-3xl font-bold",children:n("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(f.Card,{children:[e.jsx(f.CardHeader,{children:e.jsxs(f.CardTitle,{role:"heading","aria-level":2,className:"flex items-center gap-2",children:[e.jsx(S.CreditCard,{className:"w-5 h-5"}),n("ecommerce.contact_information")]})}),e.jsxs(f.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:n("checkout_prefill_notice",{email:s?.email||""})}):e.jsxs("div",{className:"space-y-2",children:[e.jsxs(y.Label,{htmlFor:"checkout-email",children:[n("ecommerce.email_address")," ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(T.Input,{id:"checkout-email",name:"email",type:"email",autoComplete:"email",spellCheck:!1,"aria-invalid":D?!0:void 0,"aria-describedby":D?"checkout-email-error":void 0,placeholder:n("ecommerce.email_placeholder"),value:I,onChange:t=>{W(t.target.value),D&&H("")},required:!0}),D?e.jsx("p",{id:"checkout-email-error",role:"alert",className:"text-xs text-destructive mt-1",children:D}):null]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(y.Label,{htmlFor:"checkout-phone",children:n("phone_number")}),e.jsx(T.Input,{id:"checkout-phone",name:"phone",type:"tel",inputMode:"tel",autoComplete:"tel",placeholder:n("optional"),value:K,onChange:t=>u(t.target.value)})]})]})]}),e.jsx(Pe,{idPrefix:"billing",title:n("billing_address"),description:n("checkout_billing_address_help"),value:C,onChange:$e}),v?e.jsxs("div",{className:"flex items-center space-x-3 rounded-xl border bg-muted/20 p-4",children:[e.jsx(lt.Checkbox,{id:"use-billing-for-shipping",checked:M,onCheckedChange:t=>Ae(!!t)}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(y.Label,{htmlFor:"use-billing-for-shipping",className:"cursor-pointer",children:n("use_billing_for_shipping")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:n("checkout_use_billing_for_shipping_help")})]})]}):null,v&&!M?e.jsx(Pe,{idPrefix:"shipping",title:n("shipping_address"),description:n("checkout_shipping_address_help"),value:B,onChange:Fe}):null,v?e.jsxs(f.Card,{children:[e.jsx(f.CardHeader,{children:e.jsxs(f.CardTitle,{role:"heading","aria-level":2,className:"flex items-center gap-2",children:[e.jsx(S.ChevronRight,{className:"w-5 h-5 text-primary"}),n("ecommerce.shipping_method")]})}),e.jsx(f.CardContent,{children:we?e.jsxs("div",{role:"status",className:"flex items-center justify-center py-6",children:[e.jsx(S.Loader2,{className:"w-6 h-6 animate-spin text-muted-foreground"}),e.jsx("span",{className:"sr-only",children:r("ecommerce.calculating_shipping","Calculating shipping…")})]}):Ke?e.jsx("div",{role:"alert",className:"rounded-lg bg-destructive/10 px-4 py-3 text-center text-sm text-destructive",children:r("ecommerce.shipping_calculation_failed","We couldn't calculate shipping right now. Please try again.")}):J.length>0?e.jsx(Y.RadioGroup,{value:A??"",onValueChange:P,"aria-label":n("ecommerce.shipping_method"),className:"space-y-3",children:J.map(t=>e.jsxs(y.Label,{htmlFor:`shipping-method-${t.id}`,className:`flex items-center justify-between gap-3 p-4 rounded-lg border-2 cursor-pointer transition-colors ${A===t.id?"border-primary bg-primary/5":"border-border hover:border-muted-foreground/40"}`,children:[e.jsxs("span",{className:"flex min-w-0 items-center gap-3",children:[e.jsx(Y.RadioGroupItem,{id:`shipping-method-${t.id}`,value:t.id}),e.jsx("span",{className:"font-medium break-words",children:t.name})]}),e.jsx("span",{className:"font-bold tabular-nums",children:o(t.amount,i)})]},t.id))}):e.jsx("div",{className:"py-4 text-center text-muted-foreground bg-muted/30 rounded-lg italic",children:ce?n("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(f.Card,{className:"top-6",children:[e.jsx(f.CardHeader,{children:e.jsx(f.CardTitle,{role:"heading","aria-level":2,children:n("ecommerce.order_summary")})}),e.jsxs(f.CardContent,{className:"space-y-4",children:[e.jsx("div",{className:"space-y-3 max-h-[260px] overflow-y-auto pr-2",children:b.map(t=>{const c=Ce.getCartItemActivePrice(t,{currencyCode:i,currencies:E}),h=De.getTrialSummary(t,n);return e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"flex gap-3",children:[t.image_url?e.jsx("div",{className:"h-10 w-10 shrink-0 overflow-hidden rounded border bg-neutral-100",children:e.jsx("img",{src:t.image_url,alt:t.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:t.title}),e.jsx(ze.Badge,{variant:"outline",className:"text-[9px] uppercase",children:et(t)})]}),t.variant_label?e.jsx("span",{className:"text-[10px] text-muted-foreground line-clamp-1",children:t.variant_label}):null,e.jsxs("span",{className:"text-[10px] text-muted-foreground",children:[n("ecommerce.qty"),": ",t.quantity]}),h?e.jsxs("span",{className:"text-[10px] font-medium text-emerald-700",children:[h.label," - ",h.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:o((c.sale_price??c.price)*t.quantity,i)}),c.sale_price?e.jsx("span",{className:"text-[9px] text-muted-foreground line-through",children:o(c.price*t.quantity,i)}):null]})]},`${t.id}-${t.variant_id||"base"}`)})}),e.jsx(at.Separator,{}),e.jsx(xt.CouponForm,{items:b,currencyCode:i,onQuoteChange:He}),e.jsxs("div",{className:"space-y-2 text-sm",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{children:n("ecommerce.subtotal")}),e.jsx("span",{children:o(Je,i)})]}),j.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:o(pe,i)})]}):null,k.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:o(he,i)})]}):null,L?e.jsxs("div",{className:"flex justify-between text-emerald-600",children:[e.jsxs("span",{children:[r("ecommerce.discount","Discount")," (",L.code,")"]}),e.jsxs("span",{children:["-",o(L.discountTotal,i)]})]}):null,(j.length>0||k.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:o(Ve,i)})]})]})]})]}),j.length>0?e.jsxs(Be,{title:r("ecommerce.stripe_checkout_title","Stripe Checkout"),description:r("ecommerce.stripe_checkout_description","Pay for physical products in one Stripe checkout session."),badgeLabel:We,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:o(pe,i)})]}),xe>0?e.jsxs("div",{className:"flex justify-between text-emerald-600",children:[e.jsx("span",{children:r("ecommerce.discount","Discount")}),e.jsxs("span",{children:["-",o(xe,i)]})]}):null,e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{children:n("ecommerce.shipping")}),e.jsx("span",{children:le?o(le.amount,i):"-"})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{children:r("ecommerce.tax","Tax")}),e.jsx("span",{children:Ge?"...":N?.isPendingExternalCalculation?r("ecommerce.tax_calculated_on_stripe","Calculated on Stripe"):N?o(N.amount,i):"-"})]}),N&&N.lines.length>0?e.jsx("div",{className:"rounded-lg bg-muted/20 px-3 py-2 text-xs text-muted-foreground",children:N.lines.map(t=>e.jsxs("div",{className:"flex justify-between gap-3",children:[e.jsxs("span",{children:[t.name," (",t.rate.toFixed(4),"%)"]}),e.jsx("span",{children:o(t.amount,i)})]},t.id||`${t.name}-${t.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:o(qe,i)})]})]}),e.jsxs(je.Button,{className:"w-full",size:"lg",onClick:()=>Le("stripe",j,"stripe"),disabled:Ye,children:[g==="stripe"?e.jsx(S.Loader2,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(S.Package,{className:"mr-2 h-4 w-4"}),g==="stripe"?n("ecommerce.processing"):r("ecommerce.checkout_physical_products","Checkout Physical Products")]}),be&&g===null?e.jsx("p",{className:"text-[11px] text-muted-foreground",children:be}):null,F.stripe?e.jsx("div",{role:"alert",className:"rounded-lg border border-destructive/20 bg-destructive/10 px-3 py-2 text-xs text-destructive",children:F.stripe}):null,e.jsx("p",{className:"text-[11px] text-muted-foreground",children:N?.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,k.length>0?e.jsxs(Be,{title:r("ecommerce.freemius_checkout_title","Freemius Checkout"),description:r("ecommerce.freemius_checkout_description","Digital products use the Freemius checkout flow."),badgeLabel:Ze,children:[e.jsx("div",{className:"space-y-3",children:k.map(t=>{const c=Ce.getCartItemActivePrice(t,{currencyCode:i,currencies:E}),h=De.getTrialSummary(t,n),a=`freemius:${t.id}`,_=h?$[a]||"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:t.title}),t.billing_cycle?e.jsx("p",{className:"text-xs text-muted-foreground capitalize",children:tt(t.billing_cycle)}):null,h?e.jsxs("p",{className:"text-xs font-medium text-emerald-700",children:[h.label," - ",h.paymentRequirementLabel]}):null]}),e.jsx("span",{className:"font-medium",children:o(c.sale_price??c.price,i)})]}),h&&!t.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(Y.RadioGroup,{value:$[a]||"paid",onValueChange:p=>m(d=>({...d,[a]:p})),className:"gap-3",children:[e.jsxs("div",{className:"flex items-start space-x-3",children:[e.jsx(Y.RadioGroupItem,{value:"paid",id:`${a}-paid`,className:"mt-1"}),e.jsxs("div",{className:"grid gap-1.5",children:[e.jsx(y.Label,{htmlFor:`${a}-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(Y.RadioGroupItem,{value:"free",id:`${a}-free`,className:"mt-1"}),e.jsx("div",{className:"grid gap-1.5",children:e.jsx(y.Label,{htmlFor:`${a}-free`,className:"font-medium leading-none cursor-pointer",children:r("ecommerce.freemius_trial_no_card","Start Free Trial (No card required)")})})]})]})]}),e.jsxs(je.Button,{className:"w-full h-auto min-h-[2.75rem] py-2",onClick:()=>Le("freemius",[{...t,..._?{trial_preference:_}:{}}],a),disabled:g!==null||ye!==null,children:[g===a?e.jsx(S.Loader2,{className:"mr-2 h-4 w-4 shrink-0 animate-spin"}):e.jsx(S.Download,{className:"mr-2 h-4 w-4 shrink-0"}),e.jsx("span",{className:"whitespace-normal text-left",children:g===a?n("ecommerce.processing"):k.length>1?r("ecommerce.checkout_product","Checkout {title}",{title:t.title}):r("ecommerce.checkout_digital_product","Checkout Digital Product")})]})]},a)})}),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:o(he,i)})]}),ge>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:["-",o(ge,i)]})]}):null,ye?e.jsx("div",{className:"rounded-lg border border-amber-500/40 bg-amber-500/10 px-3 py-2 text-xs",children:ye}):null,F.freemius?e.jsx("div",{role:"alert",className:"rounded-lg border border-destructive/20 bg-destructive/10 px-3 py-2 text-xs text-destructive",children:F.freemius}):null,e.jsx("p",{className:"text-[11px] text-muted-foreground",children:k.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=_t;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),ze=require("@nextblock-cms/ui/badge"),je=require("@nextblock-cms/ui/button"),f=require("@nextblock-cms/ui/card"),as=require("@nextblock-cms/ui/checkbox"),T=require("@nextblock-cms/ui/input"),y=require("@nextblock-cms/ui/label"),ls=require("@nextblock-cms/ui/separator"),Y=require("@nextblock-cms/ui/radio-group"),is=require("@freemius/checkout"),Ce=require("../cart-store.cjs.js"),os=require("../use-cart.cjs.js"),a=require("react"),$=require("lucide-react"),Oe=require("@nextblock-cms/utils"),ds=require("../use-price-formatter.cjs.js"),Ue=require("../countries.cjs.js"),us=require("../PaymentReadinessProvider.cjs.js"),ms=require("../server-actions/shipping-actions.cjs.js"),ps=require("../server-actions/tax-actions.cjs.js"),ve=require("../types.cjs.js"),K=require("../states.cjs.js"),U=require("../customer.cjs.js"),hs=require("../CurrencyProvider.cjs.js"),De=require("../trials.cjs.js"),xs=require("./CouponForm.cjs.js"),gs=process.env.NEXT_PUBLIC_IS_SANDBOX==="true",oe="nextblock-checkout-draft-v1";function de(t,o){return{...U.emptyCustomerAddress(),company_name:t?.company_name||"",recipient_name:t?.recipient_name||o||"",line1:t?.line1||"",line2:t?.line2||"",city:t?.city||"",state:t?.state||"",postal_code:t?.postal_code||"",country_code:Ue.normalizeCountryCode(t?.country_code)||"CA"}}function fs(t){const o=U.normalizeCustomerAddress(t);return!(!o?.country_code||!o.postal_code||K.countryUsesStructuredStates(o.country_code)&&!o.state)}function Ne(t,o,F){return t.reduce((u,g)=>{const{price:x,sale_price:w}=Ce.getCartItemActivePrice(g,{currencyCode:o,currencies:F});return u+(w??x)*g.quantity},0)}function Pe({idPrefix:t,title:o,description:F,value:u,onChange:g}){const{t:x,lang:w}=Oe.useTranslations(),q=a.useMemo(()=>{try{return new Intl.DisplayNames([w],{type:"region"})}catch{return null}},[w]),I=x("company_name")==="company_name"?"Company name":x("company_name"),W=x("select_an_option")==="select_an_option"?"Select an option":x("select_an_option"),D=x("state_province")==="state_province"?"State / Province":x("state_province"),H=K.getStatesForCountry(u.country_code),G=K.countryUsesStructuredStates(u.country_code);return e.jsxs(f.Card,{children:[e.jsxs(f.CardHeader,{children:[e.jsxs(f.CardTitle,{role:"heading","aria-level":2,className:"flex items-center gap-2",children:[e.jsx($.MapPin,{className:"w-5 h-5"}),o]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:F})]}),e.jsxs(f.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(y.Label,{htmlFor:`${t}-company`,children:I}),e.jsx(T.Input,{id:`${t}-company`,name:`${t}-company`,autoComplete:`${t} organization`,value:u.company_name,onChange:m=>g({...u,company_name:m.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(y.Label,{htmlFor:`${t}-name`,children:x("full_name")}),e.jsx(T.Input,{id:`${t}-name`,name:`${t}-name`,autoComplete:`${t} name`,required:!0,value:u.recipient_name,onChange:m=>g({...u,recipient_name:m.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(y.Label,{htmlFor:`${t}-country`,children:x("country")}),e.jsx("select",{id:`${t}-country`,name:`${t}-country`,autoComplete:`${t} country`,required:!0,className:"flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",value:u.country_code,onChange:m=>{const Z=m.target.value,ee=K.getStatesForCountry(Z);g({...u,country_code:Z,state:ee.some(ue=>ue.code===u.state)?u.state:""})},children:Ue.countries.map(m=>e.jsx("option",{value:m.code,children:q?.of(m.code)??m.name},m.code))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(y.Label,{htmlFor:`${t}-line1`,children:x("address_line_1")}),e.jsx(T.Input,{id:`${t}-line1`,name:`${t}-line1`,autoComplete:`${t} address-line1`,required:!0,value:u.line1,onChange:m=>g({...u,line1:m.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(y.Label,{htmlFor:`${t}-line2`,children:x("address_line_2")}),e.jsx(T.Input,{id:`${t}-line2`,name:`${t}-line2`,autoComplete:`${t} address-line2`,value:u.line2,onChange:m=>g({...u,line2:m.target.value})})]}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(y.Label,{htmlFor:`${t}-city`,children:x("city")}),e.jsx(T.Input,{id:`${t}-city`,name:`${t}-city`,autoComplete:`${t} address-level2`,required:!0,value:u.city,onChange:m=>g({...u,city:m.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(y.Label,{htmlFor:`${t}-state`,children:x("state_province")}),G?e.jsxs("select",{id:`${t}-state`,name:`${t}-state`,autoComplete:`${t} address-level1`,required:!0,className:"flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",value:u.state,onChange:m=>g({...u,state:m.target.value}),children:[e.jsx("option",{value:"",children:`${W}: ${D}`}),H.map(m=>e.jsx("option",{value:m.code,children:K.getSubdivisionLabel(u.country_code,m,w)},m.code))]}):e.jsx(T.Input,{id:`${t}-state`,name:`${t}-state`,autoComplete:`${t} address-level1`,value:u.state,onChange:m=>g({...u,state:m.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(y.Label,{htmlFor:`${t}-postal`,children:x("postal_zip_code")}),e.jsx(T.Input,{id:`${t}-postal`,name:`${t}-postal`,autoComplete:`${t} postal-code`,required:!0,value:u.postal_code,onChange:m=>g({...u,postal_code:m.target.value})})]})]})]})]})}function Be({title:t,description:o,badgeLabel:F,children:u}){return e.jsxs(f.Card,{children:[e.jsx(f.CardHeader,{children:e.jsxs("div",{className:"flex items-center justify-between gap-3 flex-wrap",children:[e.jsxs("div",{children:[e.jsx(f.CardTitle,{role:"heading","aria-level":2,children:t}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:o})]}),F?e.jsx(ze.Badge,{variant:"secondary",children:F}):null]})}),e.jsx(f.CardContent,{className:"space-y-4",children:u})]})}const bs=({initialCustomer:t})=>{const o=ds.usePriceFormatter(),[F,u]=a.useState({}),[g,x]=a.useState(null),[w,q]=a.useState({}),[I,W]=a.useState(t?.email||""),[D,H]=a.useState(""),[G,m]=a.useState(t?.phone||""),[Z,ee]=a.useState(!1),[ue,ke]=a.useState(null),[we,se]=a.useState(!1),[Ke,Se]=a.useState(!1),[Ge,te]=a.useState(!1),[J,Q]=a.useState([]),[A,P]=a.useState(null),[N,re]=a.useState(null),[L,He]=a.useState(null),[C,$e]=a.useState(()=>de(t?.billingAddress,t?.fullName)),[B,Fe]=a.useState(()=>de(t?.shippingAddress??t?.billingAddress,t?.fullName)),[M,Ae]=a.useState(!t?.shippingAddress||U.addressesMatch(t?.billingAddress,t?.shippingAddress)),V=os.useCart(s=>s),{t:n,lang:me}=Oe.useTranslations(),{activeCurrencyCode:i,currencies:E}=hs.useCurrency(),Te=us.usePaymentReadiness(),_=V?.items??[],j=a.useMemo(()=>_.filter(s=>!ve.isDigitalItem(s)),[_]),k=a.useMemo(()=>_.filter(s=>ve.isDigitalItem(s)),[_]),z=t?.isAuthenticated??!1,r=(s,c,h)=>{const l=n(s,h);if(l!==s)return l;if(!h)return c;let b=c;return Object.entries(h).forEach(([p,d])=>{b=b.replace(new RegExp(`\\{${p}\\}`,"g"),String(d))}),b},v=j.length>0,Je=a.useMemo(()=>Ne(_,i,E),[i,E,_]),pe=a.useMemo(()=>Ne(j,i,E),[i,E,j]),he=a.useMemo(()=>Ne(k,i,E),[i,E,k]),xe=L?.providerDiscounts.stripe??0,ge=L?.providerDiscounts.freemius??0,ne=Math.max(0,pe-xe),Qe=Math.max(0,he-ge),S=a.useMemo(()=>M?C:B,[C,B,M]),O=a.useMemo(()=>v?S:C,[C,v,S]),ce=!v||fs(S),ae=a.useMemo(()=>J.find(s=>s.id===A),[J,A]),qe=a.useMemo(()=>ne+(ae?.amount??0)+(N&&!N.isPendingExternalCalculation?N.amount:0),[ne,ae,N]),Ve=qe+Qe;if(a.useEffect(()=>{if(!(z||typeof window>"u"))try{const s=window.localStorage.getItem(oe);if(!s)return;const c=JSON.parse(s);c.email&&W(c.email),c.phone&&m(c.phone),c.billingAddress&&$e(de(c.billingAddress)),c.shippingAddress&&Fe(de(c.shippingAddress)),typeof c.useBillingForShipping=="boolean"&&Ae(c.useBillingForShipping),(typeof c.selectedMethodId=="string"||c.selectedMethodId===null)&&P(c.selectedMethodId)}catch(s){console.error("[Checkout] Failed to restore checkout draft:",s)}},[z]),a.useEffect(()=>{if(!(typeof window>"u"))try{if(z){window.localStorage.removeItem(oe);return}window.localStorage.setItem(oe,JSON.stringify({email:I,phone:G,billingAddress:C,shippingAddress:B,useBillingForShipping:M,selectedMethodId:A}))}catch{}},[C,I,z,G,A,B,M]),a.useEffect(()=>{if(!v){Q([]),P(null),se(!1);return}if(!ce){Q([]),P(null),se(!1);return}let s=!1;const h=setTimeout(async()=>{if(S.country_code){se(!0),Se(!1);try{const l=await ms.getShippingEstimates(ne,{country:S.country_code,state:S.state,postal_code:S.postal_code},me,i);if(s)return;if(l.success&&l.methods){const b=l.methods;Q(b),P(p=>p&&b.some(d=>d.id===p)?p:b[0]?.id??null)}else Q([]),P(null)}catch(l){if(s)return;console.error("[Checkout] Failed to load shipping rates:",l),Q([]),P(null),Se(!0)}finally{s||se(!1)}}},400);return()=>{s=!0,clearTimeout(h)}},[i,v,ce,me,S.country_code,S.postal_code,S.state,ne]),a.useEffect(()=>{let s=!1;const h=setTimeout(async()=>{if(!v||!O.country_code){te(!1),re(null);return}if(K.countryUsesStructuredStates(O.country_code)&&!O.state){te(!1),re(null);return}te(!0);try{const l=await ps.getTaxEstimate(j,{country_code:O.country_code,state:O.state},i,L?.code??null,_);if(s)return;re(l.success&&l.tax?l.tax:null)}catch(l){if(s)return;console.error("[Checkout] Failed to load the tax estimate:",l),re(null)}finally{s||te(!1)}},300);return()=>{s=!0,clearTimeout(h)}},[i,v,j,O.country_code,O.state,L?.code,_]),a.useEffect(()=>{const s=c=>{c.persisted&&x(null)};return window.addEventListener("pageshow",s),()=>window.removeEventListener("pageshow",s)},[]),!V)return e.jsxs("div",{role:"status","aria-busy":"true",className:"container mx-auto px-4 py-12 md:px-6",children:[e.jsx("span",{className:"sr-only",children:n("loading")==="loading"?"Loading…":n("loading")}),e.jsxs("div",{className:"mx-auto max-w-6xl",children:[e.jsx("div",{className:"mb-8 h-9 w-48 rounded-md bg-muted"}),e.jsxs("div",{className:"grid gap-8 lg:grid-cols-12 lg:items-start",children:[e.jsxs("div",{className:"space-y-6 lg:col-span-8",children:[e.jsx("div",{className:"h-56 rounded-xl border bg-muted/40"}),e.jsx("div",{className:"h-96 rounded-xl border bg-muted/40"})]}),e.jsx("div",{className:"lg:col-span-4",children:e.jsx("div",{className:"h-72 rounded-xl border bg-muted/40"})})]})]})]});const fe=()=>{ee(!1),ke(null)},Ie=Z?e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center overscroll-contain bg-black/60 backdrop-blur-sm",onClick:fe,onKeyDown:s=>{s.key==="Escape"&&fe()},children:e.jsxs("div",{role:"dialog","aria-modal":"true","aria-labelledby":"sandbox-checkout-title",className:"relative bg-background border rounded-xl shadow-2xl p-8 max-w-md mx-4",onClick:s=>s.stopPropagation(),children:[e.jsx("button",{type:"button",autoFocus:!0,onClick:fe,"aria-label":r("close","Close"),className:"absolute top-4 right-4 inline-flex h-8 w-8 items-center justify-center rounded-md text-muted-foreground hover:text-foreground transition-colors focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring",children:e.jsx($.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($.FlaskConical,{className:"h-6 w-6 text-amber-600 dark:text-amber-400"})}),e.jsx("h2",{id:"sandbox-checkout-title",className:"text-xl font-semibold",children:n("ecommerce.checkout_successful")})]}),e.jsx("p",{className:"text-muted-foreground mb-2",children:n("ecommerce.sandbox_notice")}),e.jsx("p",{className:"text-muted-foreground mb-2",children:ue==="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:n("ecommerce.license_notice")}),e.jsx("a",{href:"https://nextblock.dev",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:n("ecommerce.purchase_at")})]})}):null,le=(s,c,h)=>(q(l=>({...l,[s]:c})),h&&document.getElementById(h)?.focus(),null),be=(s,c)=>c.recipient_name.trim()?c.line1.trim()?c.city.trim()?K.countryUsesStructuredStates(c.country_code)&&!c.state?`${s}-state`:c.postal_code.trim()?`${s}-line1`:`${s}-postal`:`${s}-city`:`${s}-line1`:`${s}-name`,Xe=s=>{if(!z&&(!I||!/^\S+@\S+\.\S+$/.test(I)))return H(n("ecommerce.invalid_email")),le(s,n("ecommerce.invalid_email"),"checkout-email");const c=U.normalizeCustomerAddress(C);if(!U.isCustomerAddressComplete(c))return le(s,n("checkout_complete_billing_address"),be("billing",C));const h=v?U.normalizeCustomerAddress(M?C:B):null;if(s==="stripe"){if(!U.isCustomerAddressComplete(h))return le(s,n("checkout_complete_shipping_address"),M?be("billing",C):be("shipping",B));if(!A)return le(s,r("ecommerce.shipping_method_required","Please select a shipping method before continuing."))}return H(""),{normalizedBillingAddress:c,normalizedShippingAddress:h}},Le=async(s,c,h)=>{q(b=>({...b,[s]:""}));const l=Xe(s);if(l){if(gs){const b=new Set(c.map(d=>d.id)),p=_.filter(d=>!b.has(d.id));if(V.setItems(p),p.length===0&&V.removeCoupon(),ke(s),ee(!0),typeof window<"u"&&p.length===0)try{window.localStorage.removeItem(oe)}catch{}return}x(h);try{const b=await fetch("/api/checkout",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({items:c,customerEmail:z?void 0:I,customerPhone:G||null,billingAddress:l.normalizedBillingAddress,shippingAddress:s==="stripe"?l.normalizedShippingAddress:null,shippingMethodId:s==="stripe"?A:null,locale:me,currencyCode:i,couponCode:L?.code??V.appliedCoupon?.code??null,couponContextItems:_})}),p=await b.json();if(!b.ok){const d=p?.errorKey&&typeof p.errorKey=="string"?r(p.errorKey,p?.error||r("ecommerce.generic_error","Something went wrong."),p.errorParams):p?.error||n("ecommerce.generic_error");q(X=>({...X,[s]:d})),x(null);return}if(p.customProps&&p.customProps.provider==="freemius"){const d=p.customProps;let X=null;const ts=()=>{window.location.href=`/checkout/success?session_id=${d.order_id}`},Re=R=>(X||(X=fetch("/api/checkout/freemius/sync",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({orderId:d.order_id,checkoutResponse:R})}).then(async ie=>{if(!ie.ok){const cs=await ie.json().catch(()=>null);console.error("Freemius checkout sync failed:",cs)}})),X),rs={product_id:d.plugin_id,public_key:d.public_key,sandbox:d.sandbox},ns={name:n("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(R){Re(R)},success:function(R){(async()=>{try{await Re(R)}finally{ts()}})()}};try{new is.Checkout(rs).open(ns),x(null)}catch(R){console.error("[Checkout] Freemius overlay failed to open:",R),q(ie=>({...ie,[s]:n("ecommerce.checkout_popup_blocked")})),p.url&&(window.location.href=p.url),x(null)}}else p.url?window.location.href=p.url:(q(d=>({...d,[s]:n("ecommerce.checkout_failed")+(p.error||r("ecommerce.unknown_error","Unknown error"))})),x(null))}catch(b){console.error(b),q(p=>({...p,[s]:n("ecommerce.generic_error")})),x(null)}}};if(_.length===0)return e.jsxs(e.Fragment,{children:[Ie,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:n("ecommerce.cart_empty")}),e.jsx("p",{className:"mb-8 text-muted-foreground",children:n("ecommerce.cart_empty_description")}),e.jsx(je.Button,{asChild:!0,children:e.jsx("a",{href:"/shop",children:n("ecommerce.go_to_shop")})})]})]});const Me=r("ecommerce.checkout_payments_unavailable","This store is not able to take payments right now. Please contact the seller to complete your purchase."),Ee=Te.stripe?null:Me,ye=Te.freemius?null:Me,_e=Ee||(v?ce?we?r("ecommerce.calculating_shipping","Calculating shipping..."):A?null:J.length>0?n("ecommerce.select_rate"):n("ecommerce.no_rates_for_region"):r("ecommerce.waiting_on_address_info","Complete your shipping address to view available shipping options."):null),Ye=g!==null||_e!==null,We=j.length===1?r("ecommerce.item_count_one","{count} item",{count:j.length}):r("ecommerce.item_count_other","{count} items",{count:j.length}),Ze=k.length===1?r("ecommerce.license_count_one","{count} license",{count:k.length}):r("ecommerce.license_count_other","{count} licenses",{count:k.length}),es=s=>ve.isDigitalItem(s)?r("ecommerce.digital_label","Digital"):r("ecommerce.physical_label","Physical"),ss=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:[Ie,e.jsxs("div",{className:"mx-auto max-w-6xl",children:[e.jsx("h1",{className:"mb-8 text-3xl font-bold",children:n("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(f.Card,{children:[e.jsx(f.CardHeader,{children:e.jsxs(f.CardTitle,{role:"heading","aria-level":2,className:"flex items-center gap-2",children:[e.jsx($.CreditCard,{className:"w-5 h-5"}),n("ecommerce.contact_information")]})}),e.jsxs(f.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:n("checkout_prefill_notice",{email:t?.email||""})}):e.jsxs("div",{className:"space-y-2",children:[e.jsxs(y.Label,{htmlFor:"checkout-email",children:[n("ecommerce.email_address")," ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(T.Input,{id:"checkout-email",name:"email",type:"email",autoComplete:"email",spellCheck:!1,"aria-invalid":D?!0:void 0,"aria-describedby":D?"checkout-email-error":void 0,placeholder:n("ecommerce.email_placeholder"),value:I,onChange:s=>{W(s.target.value),D&&H("")},required:!0}),D?e.jsx("p",{id:"checkout-email-error",role:"alert",className:"text-xs text-destructive mt-1",children:D}):null]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(y.Label,{htmlFor:"checkout-phone",children:n("phone_number")}),e.jsx(T.Input,{id:"checkout-phone",name:"phone",type:"tel",inputMode:"tel",autoComplete:"tel",placeholder:n("optional"),value:G,onChange:s=>m(s.target.value)})]})]})]}),e.jsx(Pe,{idPrefix:"billing",title:n("billing_address"),description:n("checkout_billing_address_help"),value:C,onChange:$e}),v?e.jsxs("div",{className:"flex items-center space-x-3 rounded-xl border bg-muted/20 p-4",children:[e.jsx(as.Checkbox,{id:"use-billing-for-shipping",checked:M,onCheckedChange:s=>Ae(!!s)}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(y.Label,{htmlFor:"use-billing-for-shipping",className:"cursor-pointer",children:n("use_billing_for_shipping")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:n("checkout_use_billing_for_shipping_help")})]})]}):null,v&&!M?e.jsx(Pe,{idPrefix:"shipping",title:n("shipping_address"),description:n("checkout_shipping_address_help"),value:B,onChange:Fe}):null,v?e.jsxs(f.Card,{children:[e.jsx(f.CardHeader,{children:e.jsxs(f.CardTitle,{role:"heading","aria-level":2,className:"flex items-center gap-2",children:[e.jsx($.ChevronRight,{className:"w-5 h-5 text-primary"}),n("ecommerce.shipping_method")]})}),e.jsx(f.CardContent,{children:we?e.jsxs("div",{role:"status",className:"flex items-center justify-center py-6",children:[e.jsx($.Loader2,{className:"w-6 h-6 animate-spin text-muted-foreground"}),e.jsx("span",{className:"sr-only",children:r("ecommerce.calculating_shipping","Calculating shipping…")})]}):Ke?e.jsx("div",{role:"alert",className:"rounded-lg bg-destructive/10 px-4 py-3 text-center text-sm text-destructive",children:r("ecommerce.shipping_calculation_failed","We couldn't calculate shipping right now. Please try again.")}):J.length>0?e.jsx(Y.RadioGroup,{value:A??"",onValueChange:P,"aria-label":n("ecommerce.shipping_method"),className:"space-y-3",children:J.map(s=>e.jsxs(y.Label,{htmlFor:`shipping-method-${s.id}`,className:`flex items-center justify-between gap-3 p-4 rounded-lg border-2 cursor-pointer transition-colors ${A===s.id?"border-primary bg-primary/5":"border-border hover:border-muted-foreground/40"}`,children:[e.jsxs("span",{className:"flex min-w-0 items-center gap-3",children:[e.jsx(Y.RadioGroupItem,{id:`shipping-method-${s.id}`,value:s.id}),e.jsx("span",{className:"font-medium break-words",children:s.name})]}),e.jsx("span",{className:"font-bold tabular-nums",children:o(s.amount,i)})]},s.id))}):e.jsx("div",{className:"py-4 text-center text-muted-foreground bg-muted/30 rounded-lg italic",children:ce?n("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(f.Card,{className:"top-6",children:[e.jsx(f.CardHeader,{children:e.jsx(f.CardTitle,{role:"heading","aria-level":2,children:n("ecommerce.order_summary")})}),e.jsxs(f.CardContent,{className:"space-y-4",children:[e.jsx("div",{className:"space-y-3 max-h-[260px] overflow-y-auto pr-2",children:_.map(s=>{const c=Ce.getCartItemActivePrice(s,{currencyCode:i,currencies:E}),h=De.getTrialSummary(s,n);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(ze.Badge,{variant:"outline",className:"text-[9px] uppercase",children:es(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:[n("ecommerce.qty"),": ",s.quantity]}),h?e.jsxs("span",{className:"text-[10px] font-medium text-emerald-700",children:[h.label," - ",h.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:o((c.sale_price??c.price)*s.quantity,i)}),c.sale_price?e.jsx("span",{className:"text-[9px] text-muted-foreground line-through",children:o(c.price*s.quantity,i)}):null]})]},`${s.id}-${s.variant_id||"base"}`)})}),e.jsx(ls.Separator,{}),e.jsx(xs.CouponForm,{items:_,currencyCode:i,onQuoteChange:He}),e.jsxs("div",{className:"space-y-2 text-sm",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{children:n("ecommerce.subtotal")}),e.jsx("span",{children:o(Je,i)})]}),j.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:o(pe,i)})]}):null,k.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:o(he,i)})]}):null,L?e.jsxs("div",{className:"flex justify-between text-emerald-600",children:[e.jsxs("span",{children:[r("ecommerce.discount","Discount")," (",L.code,")"]}),e.jsxs("span",{children:["-",o(L.discountTotal,i)]})]}):null,(j.length>0||k.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:o(Ve,i)})]})]})]})]}),j.length>0?e.jsxs(Be,{title:r("ecommerce.stripe_checkout_title","Stripe Checkout"),description:r("ecommerce.stripe_checkout_description","Pay for physical products in one Stripe checkout session."),badgeLabel:We,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:o(pe,i)})]}),xe>0?e.jsxs("div",{className:"flex justify-between text-emerald-600",children:[e.jsx("span",{children:r("ecommerce.discount","Discount")}),e.jsxs("span",{children:["-",o(xe,i)]})]}):null,e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{children:n("ecommerce.shipping")}),e.jsx("span",{children:ae?o(ae.amount,i):"-"})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{children:r("ecommerce.tax","Tax")}),e.jsx("span",{children:Ge?"...":N?.isPendingExternalCalculation?r("ecommerce.tax_calculated_on_stripe","Calculated on Stripe"):N?o(N.amount,i):"-"})]}),N&&N.lines.length>0?e.jsx("div",{className:"rounded-lg bg-muted/20 px-3 py-2 text-xs text-muted-foreground",children:N.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:o(s.amount,i)})]},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:o(qe,i)})]})]}),e.jsxs(je.Button,{className:"w-full",size:"lg",onClick:()=>Le("stripe",j,"stripe"),disabled:Ye,children:[g==="stripe"?e.jsx($.Loader2,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx($.Package,{className:"mr-2 h-4 w-4"}),g==="stripe"?n("ecommerce.processing"):r("ecommerce.checkout_physical_products","Checkout Physical Products")]}),_e&&g===null?e.jsx("p",{className:"text-[11px] text-muted-foreground",children:_e}):null,w.stripe?e.jsx("div",{role:"alert",className:"rounded-lg border border-destructive/20 bg-destructive/10 px-3 py-2 text-xs text-destructive",children:w.stripe}):null,e.jsx("p",{className:"text-[11px] text-muted-foreground",children:N?.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,k.length>0?e.jsxs(Be,{title:r("ecommerce.freemius_checkout_title","Freemius Checkout"),description:r("ecommerce.freemius_checkout_description","Digital products use the Freemius checkout flow."),badgeLabel:Ze,children:[e.jsx("div",{className:"space-y-3",children:k.map(s=>{const c=Ce.getCartItemActivePrice(s,{currencyCode:i,currencies:E}),h=De.getTrialSummary(s,n),l=`freemius:${s.id}`,b=h?F[l]||"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:ss(s.billing_cycle)}):null,h?e.jsxs("p",{className:"text-xs font-medium text-emerald-700",children:[h.label," - ",h.paymentRequirementLabel]}):null]}),e.jsx("span",{className:"font-medium",children:o(c.sale_price??c.price,i)})]}),h&&!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(Y.RadioGroup,{value:F[l]||"paid",onValueChange:p=>u(d=>({...d,[l]:p})),className:"gap-3",children:[e.jsxs("div",{className:"flex items-start space-x-3",children:[e.jsx(Y.RadioGroupItem,{value:"paid",id:`${l}-paid`,className:"mt-1"}),e.jsxs("div",{className:"grid gap-1.5",children:[e.jsx(y.Label,{htmlFor:`${l}-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(Y.RadioGroupItem,{value:"free",id:`${l}-free`,className:"mt-1"}),e.jsx("div",{className:"grid gap-1.5",children:e.jsx(y.Label,{htmlFor:`${l}-free`,className:"font-medium leading-none cursor-pointer",children:r("ecommerce.freemius_trial_no_card","Start Free Trial (No card required)")})})]})]})]}),e.jsxs(je.Button,{className:"w-full h-auto min-h-[2.75rem] py-2",onClick:()=>Le("freemius",[{...s,...b?{trial_preference:b}:{}}],l),disabled:g!==null||ye!==null,children:[g===l?e.jsx($.Loader2,{className:"mr-2 h-4 w-4 shrink-0 animate-spin"}):e.jsx($.Download,{className:"mr-2 h-4 w-4 shrink-0"}),e.jsx("span",{className:"whitespace-normal text-left",children:g===l?n("ecommerce.processing"):k.length>1?r("ecommerce.checkout_product","Checkout {title}",{title:s.title}):r("ecommerce.checkout_digital_product","Checkout Digital Product")})]})]},l)})}),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:o(he,i)})]}),ge>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:["-",o(ge,i)]})]}):null,ye?e.jsx("div",{className:"rounded-lg border border-amber-500/40 bg-amber-500/10 px-3 py-2 text-xs",children:ye}):null,w.freemius?e.jsx("div",{role:"alert",className:"rounded-lg border border-destructive/20 bg-destructive/10 px-3 py-2 text-xs text-destructive",children:w.freemius}):null,e.jsx("p",{className:"text-[11px] text-muted-foreground",children:k.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=bs;
@@ -2,5 +2,5 @@ import { CheckoutCustomerDefaults } from '../customer';
2
2
  interface CheckoutProps {
3
3
  initialCustomer?: CheckoutCustomerDefaults;
4
4
  }
5
- export declare const Checkout: ({ initialCustomer }: CheckoutProps) => import("react").JSX.Element | null;
5
+ export declare const Checkout: ({ initialCustomer }: CheckoutProps) => import("react").JSX.Element;
6
6
  export {};