@nextblock-cms/ecom 0.8.6 → 0.8.11

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.
Files changed (277) hide show
  1. package/index.cjs.js +1 -1
  2. package/index.es.js +136 -533
  3. package/lib/CurrencyProvider.cjs.js +1 -0
  4. package/lib/CurrencyProvider.es.js +99 -0
  5. package/lib/cart-store.cjs.js +1 -0
  6. package/{cart-store.es.js → lib/cart-store.es.js} +13 -13
  7. package/lib/components/AccountNavigationMenu.cjs.js +1 -0
  8. package/lib/components/AccountNavigationMenu.es.js +44 -0
  9. package/lib/components/AddToCartButton.cjs.js +1 -0
  10. package/{AddToCartButton-ffE0DhHu.js → lib/components/AddToCartButton.es.js} +14 -13
  11. package/lib/components/Cart.cjs.js +1 -0
  12. package/lib/components/Cart.es.js +148 -0
  13. package/lib/components/CartDrawer.cjs.js +1 -0
  14. package/{components → lib/components}/CartDrawer.es.js +15 -14
  15. package/{components → lib/components}/CartIcon.cjs.js +1 -1
  16. package/{components → lib/components}/CartIcon.es.js +1 -0
  17. package/lib/components/Checkout.cjs.js +1 -0
  18. package/{components → lib/components}/Checkout.es.js +330 -363
  19. package/lib/components/CouponForm.cjs.js +1 -0
  20. package/lib/components/CouponForm.es.js +136 -0
  21. package/lib/components/CurrencySwitcher.cjs.js +1 -0
  22. package/{components → lib/components}/CurrencySwitcher.es.js +5 -4
  23. package/lib/components/CustomerProfileForm.cjs.js +1 -0
  24. package/lib/components/CustomerProfileForm.es.js +355 -0
  25. package/lib/components/FeaturedProduct.cjs.js +1 -0
  26. package/{components → lib/components}/FeaturedProduct.es.js +9 -8
  27. package/lib/components/InvoiceDocument.cjs.js +1 -0
  28. package/lib/components/InvoiceDocument.es.js +196 -0
  29. package/lib/components/InvoiceViewerShell.cjs.js +29 -0
  30. package/lib/components/InvoiceViewerShell.es.js +100 -0
  31. package/lib/components/ProductCard.cjs.js +1 -0
  32. package/lib/components/ProductCard.es.js +119 -0
  33. package/lib/components/ProductDetailsLayout.cjs.js +1 -0
  34. package/lib/components/ProductDetailsLayout.es.js +361 -0
  35. package/lib/components/ProductGallery.cjs.js +1 -0
  36. package/lib/components/ProductGallery.es.js +41 -0
  37. package/lib/components/ProductGrid.cjs.js +1 -0
  38. package/lib/components/ProductGrid.es.js +19 -0
  39. package/lib/components/ShippingEstimator.cjs.js +1 -0
  40. package/lib/components/ShippingEstimator.es.js +125 -0
  41. package/lib/components/SubscriptionSelector.cjs.js +1 -0
  42. package/lib/components/SubscriptionSelector.es.js +140 -0
  43. package/lib/countries.cjs.js +1 -0
  44. package/lib/countries.es.js +77 -0
  45. package/lib/coupon-server.cjs.js +1 -0
  46. package/{coupon-server-DUKVtyYs.js → lib/coupon-server.es.js} +68 -82
  47. package/lib/coupons.cjs.js +1 -0
  48. package/lib/coupons.es.js +17 -0
  49. package/lib/currency-store.cjs.js +1 -0
  50. package/lib/currency-store.es.js +27 -0
  51. package/lib/currency-sync.cjs.js +1 -0
  52. package/lib/currency-sync.es.js +180 -0
  53. package/lib/customer-addresses.cjs.js +1 -0
  54. package/lib/customer-addresses.es.js +116 -0
  55. package/lib/customer-orders.cjs.js +1 -0
  56. package/lib/customer-orders.es.js +45 -0
  57. package/lib/customer.cjs.js +1 -0
  58. package/{customer-C3xccjUg.js → lib/customer.es.js} +15 -14
  59. package/lib/export-helpers.cjs.js +1 -0
  60. package/lib/export-helpers.es.js +56 -0
  61. package/lib/factory.cjs.js +1 -0
  62. package/lib/factory.es.js +8 -0
  63. package/lib/freemius-coupons.cjs.js +1 -0
  64. package/lib/freemius-coupons.es.js +272 -0
  65. package/lib/freemius-order-sync.cjs.js +1 -0
  66. package/lib/freemius-order-sync.es.js +284 -0
  67. package/lib/inventory-settings.cjs.js +1 -0
  68. package/lib/inventory-settings.es.js +86 -0
  69. package/lib/invoice-server.cjs.js +33 -0
  70. package/lib/invoice-server.es.js +141 -0
  71. package/lib/invoice-ui.cjs.js +1 -0
  72. package/lib/invoice-ui.es.js +71 -0
  73. package/lib/invoice.cjs.js +1 -0
  74. package/lib/invoice.es.js +102 -0
  75. package/lib/order-inventory.cjs.js +61 -0
  76. package/lib/order-inventory.es.js +128 -0
  77. package/lib/order-tax-details.cjs.js +1 -0
  78. package/lib/order-tax-details.es.js +164 -0
  79. package/lib/pages/cms/coupons/CouponEditorForm.cjs.js +1 -0
  80. package/lib/pages/cms/coupons/CouponEditorForm.es.js +189 -0
  81. package/lib/pages/cms/coupons/CouponsPage.cjs.js +5 -0
  82. package/lib/pages/cms/coupons/CouponsPage.es.js +171 -0
  83. package/lib/pages/cms/coupons/CreateCouponDialog.cjs.js +1 -0
  84. package/lib/pages/cms/coupons/CreateCouponDialog.es.js +35 -0
  85. package/lib/pages/cms/coupons/EditCouponPage.cjs.js +1 -0
  86. package/lib/pages/cms/coupons/EditCouponPage.es.js +48 -0
  87. package/lib/pages/cms/coupons/ProductScopePicker.cjs.js +1 -0
  88. package/lib/pages/cms/coupons/ProductScopePicker.es.js +120 -0
  89. package/lib/pages/cms/coupons/actions.cjs.js +1 -0
  90. package/lib/pages/cms/coupons/actions.es.js +128 -0
  91. package/lib/pages/cms/coupons/product-options.cjs.js +1 -0
  92. package/lib/pages/cms/coupons/product-options.es.js +27 -0
  93. package/lib/pages/cms/orders/ExportReportsDialog.cjs.js +1 -0
  94. package/lib/pages/cms/orders/ExportReportsDialog.es.js +130 -0
  95. package/lib/pages/cms/orders/OrderDetailPage.cjs.js +1 -0
  96. package/lib/pages/cms/orders/OrderDetailPage.es.js +137 -0
  97. package/lib/pages/cms/orders/OrderPrintButton.cjs.js +1 -0
  98. package/lib/pages/cms/orders/OrderPrintButton.es.js +22 -0
  99. package/lib/pages/cms/orders/OrderStatusForm.cjs.js +1 -0
  100. package/lib/pages/cms/orders/OrderStatusForm.es.js +71 -0
  101. package/lib/pages/cms/orders/OrdersPage.cjs.js +1 -0
  102. package/lib/pages/cms/orders/OrdersPage.es.js +104 -0
  103. package/lib/pages/cms/orders/actions.cjs.js +7 -0
  104. package/lib/pages/cms/orders/actions.es.js +71 -0
  105. package/lib/pages/cms/orders/export-actions.cjs.js +1 -0
  106. package/lib/pages/cms/orders/export-actions.es.js +27 -0
  107. package/lib/pages/cms/orders/server-actions.cjs.js +1 -0
  108. package/lib/pages/cms/orders/server-actions.es.js +55 -0
  109. package/lib/pages/cms/payments/PaymentsClient.cjs.js +1 -0
  110. package/lib/pages/cms/payments/PaymentsClient.es.js +188 -0
  111. package/lib/pages/cms/payments/PaymentsPage.cjs.js +1 -0
  112. package/lib/pages/cms/payments/PaymentsPage.es.js +29 -0
  113. package/lib/pages/cms/payments/actions.cjs.js +1 -0
  114. package/lib/pages/cms/payments/actions.es.js +23 -0
  115. package/lib/pages/cms/payments/queries.cjs.js +1 -0
  116. package/lib/pages/cms/payments/queries.es.js +30 -0
  117. package/lib/pages/cms/products/ProductsPage.cjs.js +1 -0
  118. package/lib/pages/cms/products/ProductsPage.es.js +46 -0
  119. package/lib/pages/cms/products/_id_/edit/EditProductPage.cjs.js +1 -0
  120. package/lib/pages/cms/products/_id_/edit/EditProductPage.es.js +156 -0
  121. package/lib/pages/cms/products/actions.cjs.js +44 -0
  122. package/lib/pages/cms/products/actions.es.js +175 -0
  123. package/lib/pages/cms/products/attributes/AttributeManagementPage.cjs.js +1 -0
  124. package/lib/pages/cms/products/attributes/AttributeManagementPage.es.js +48 -0
  125. package/lib/pages/cms/products/attributes/components/AttributeManager.cjs.js +1 -0
  126. package/lib/pages/cms/products/attributes/components/AttributeManager.es.js +291 -0
  127. package/lib/pages/cms/products/categories/CategoryManagementPage.cjs.js +1 -0
  128. package/lib/pages/cms/products/categories/CategoryManagementPage.es.js +36 -0
  129. package/lib/pages/cms/products/categories/components/CategoryManager.cjs.js +1 -0
  130. package/lib/pages/cms/products/categories/components/CategoryManager.es.js +263 -0
  131. package/lib/pages/cms/products/components/CopyProductFromLanguage.cjs.js +1 -0
  132. package/lib/pages/cms/products/components/CopyProductFromLanguage.es.js +114 -0
  133. package/lib/pages/cms/products/components/CurrencyPriceFields.cjs.js +1 -0
  134. package/lib/pages/cms/products/components/CurrencyPriceFields.es.js +107 -0
  135. package/lib/pages/cms/products/components/DeleteProductButton.cjs.js +1 -0
  136. package/lib/pages/cms/products/components/DeleteProductButton.es.js +48 -0
  137. package/lib/pages/cms/products/components/FreemiusPricingDashboard.cjs.js +1 -0
  138. package/lib/pages/cms/products/components/FreemiusPricingDashboard.es.js +86 -0
  139. package/lib/pages/cms/products/components/ProductCategorySelector.cjs.js +1 -0
  140. package/lib/pages/cms/products/components/ProductCategorySelector.es.js +160 -0
  141. package/lib/pages/cms/products/components/ProductForm.cjs.js +1 -0
  142. package/lib/pages/cms/products/components/ProductForm.es.js +702 -0
  143. package/lib/pages/cms/products/components/ProductMediaManager.cjs.js +1 -0
  144. package/lib/pages/cms/products/components/ProductMediaManager.es.js +104 -0
  145. package/lib/pages/cms/products/components/ProductsBulkTable.cjs.js +1 -0
  146. package/lib/pages/cms/products/components/ProductsBulkTable.es.js +228 -0
  147. package/lib/pages/cms/products/components/SaleScheduleFields.cjs.js +1 -0
  148. package/lib/pages/cms/products/components/SaleScheduleFields.es.js +137 -0
  149. package/lib/pages/cms/products/components/SyncFreemiusButton.cjs.js +1 -0
  150. package/lib/pages/cms/products/components/SyncFreemiusButton.es.js +36 -0
  151. package/lib/pages/cms/products/components/SyncFreemiusPricingButton.cjs.js +1 -0
  152. package/lib/pages/cms/products/components/SyncFreemiusPricingButton.es.js +40 -0
  153. package/lib/pages/cms/products/components/VariationsEditor.cjs.js +1 -0
  154. package/lib/pages/cms/products/components/VariationsEditor.es.js +408 -0
  155. package/lib/pages/cms/products/inventory/InventoryPage.cjs.js +1 -0
  156. package/lib/pages/cms/products/inventory/InventoryPage.es.js +16 -0
  157. package/lib/pages/cms/products/inventory/InventoryTableClient.cjs.js +2 -0
  158. package/lib/pages/cms/products/inventory/InventoryTableClient.es.js +214 -0
  159. package/lib/pages/cms/products/inventory/actions.cjs.js +3 -0
  160. package/lib/pages/cms/products/inventory/actions.es.js +95 -0
  161. package/lib/pages/cms/products/new/NewProductPage.cjs.js +1 -0
  162. package/lib/pages/cms/products/new/NewProductPage.es.js +76 -0
  163. package/lib/pages/cms/products/product-price-sync.cjs.js +1 -0
  164. package/lib/pages/cms/products/product-price-sync.es.js +98 -0
  165. package/lib/pages/cms/products/server-actions.cjs.js +1 -0
  166. package/lib/pages/cms/products/server-actions.es.js +193 -0
  167. package/lib/pages/cms/shipping/ShippingPage.cjs.js +5 -0
  168. package/lib/pages/cms/shipping/ShippingPage.es.js +211 -0
  169. package/lib/pages/cms/shipping/components/RateForm.cjs.js +1 -0
  170. package/lib/pages/cms/shipping/components/RateForm.es.js +441 -0
  171. package/lib/pages/cms/shipping/components/ZoneForm.cjs.js +1 -0
  172. package/lib/pages/cms/shipping/components/ZoneForm.es.js +228 -0
  173. package/lib/pages/cms/shipping/server-actions.cjs.js +1 -0
  174. package/lib/pages/cms/shipping/server-actions.es.js +159 -0
  175. package/lib/pages/cms/taxes/TaxesPage.cjs.js +1 -0
  176. package/lib/pages/cms/taxes/TaxesPage.es.js +172 -0
  177. package/lib/pages/cms/taxes/actions.cjs.js +1 -0
  178. package/lib/pages/cms/taxes/actions.es.js +57 -0
  179. package/lib/pages/cms/taxes/components/TaxRateForm.cjs.js +1 -0
  180. package/lib/pages/cms/taxes/components/TaxRateForm.es.js +100 -0
  181. package/lib/product-actions.cjs.js +237 -0
  182. package/lib/product-actions.es.js +524 -0
  183. package/lib/product-context.cjs.js +1 -0
  184. package/lib/product-context.es.js +16 -0
  185. package/lib/product-schema.cjs.js +1 -0
  186. package/lib/product-schema.es.js +134 -0
  187. package/lib/providers/freemius.cjs.js +5 -0
  188. package/lib/providers/freemius.es.js +538 -0
  189. package/lib/providers/stripe.cjs.js +1 -0
  190. package/lib/providers/stripe.es.js +473 -0
  191. package/lib/server-actions/coupon-actions.cjs.js +1 -0
  192. package/lib/server-actions/coupon-actions.es.js +23 -0
  193. package/lib/server-actions/customer-actions.cjs.js +1 -0
  194. package/lib/server-actions/customer-actions.es.js +30 -0
  195. package/lib/server-actions/product-actions.cjs.js +1 -0
  196. package/{server-actions → lib/server-actions}/product-actions.es.js +5 -4
  197. package/lib/server-actions/shipping-actions.cjs.js +1 -0
  198. package/{shipping-actions-BnHjlo2q.js → lib/server-actions/shipping-actions.es.js} +9 -7
  199. package/lib/server-actions/tax-actions.cjs.js +1 -0
  200. package/lib/server-actions/tax-actions.es.js +40 -0
  201. package/lib/shared-inventory.cjs.js +15 -0
  202. package/lib/shared-inventory.es.js +171 -0
  203. package/lib/shipping/resolver.cjs.js +7 -0
  204. package/lib/shipping/resolver.es.js +62 -0
  205. package/lib/shipping-rate-currency.cjs.js +1 -0
  206. package/lib/shipping-rate-currency.es.js +72 -0
  207. package/lib/states.cjs.js +1 -0
  208. package/{states-DlHJezQ1.js → lib/states.es.js} +27 -100
  209. package/lib/stripe/checkout.cjs.js +1 -0
  210. package/lib/stripe/checkout.es.js +182 -0
  211. package/lib/stripe/client.cjs.js +1 -0
  212. package/lib/stripe/client.es.js +7 -0
  213. package/lib/stripe/order-sync.cjs.js +1 -0
  214. package/lib/stripe/order-sync.es.js +130 -0
  215. package/lib/stripe/webhooks.cjs.js +1 -0
  216. package/lib/stripe/webhooks.es.js +30 -0
  217. package/lib/tax-calculation.cjs.js +1 -0
  218. package/lib/tax-calculation.es.js +101 -0
  219. package/lib/trials.cjs.js +1 -0
  220. package/{trials-RDcRAZKx.js → lib/trials.es.js} +9 -9
  221. package/{use-cart.es.js → lib/use-cart.es.js} +1 -0
  222. package/lib/zod-config.cjs.js +1 -0
  223. package/lib/zod-config.es.js +6 -0
  224. package/package.json +6 -6
  225. package/server.cjs.js +1 -110
  226. package/server.es.js +178 -6052
  227. package/AddToCartButton-DsSEH9yp.cjs +0 -1
  228. package/CouponForm-BI_5SBHQ.js +0 -152
  229. package/CouponForm-D_uu2bLP.cjs +0 -1
  230. package/CurrencyProvider-Cg-Q6ucj.cjs +0 -1
  231. package/CurrencyProvider-OzlRN96V.js +0 -120
  232. package/CurrencyProvider.cjs.js +0 -1
  233. package/CurrencyProvider.es.js +0 -10
  234. package/ProductDetailsLayout-BxJH_BxR.cjs +0 -1
  235. package/ProductDetailsLayout-Dg8dRTYp.js +0 -530
  236. package/ProductGrid-BdL7iglO.cjs +0 -1
  237. package/ProductGrid-D3AWM8sr.js +0 -130
  238. package/actions-AHmBrS5e.cjs +0 -48
  239. package/actions-j5fuSZX-.js +0 -820
  240. package/cart-store.cjs.js +0 -1
  241. package/components/Cart.cjs.js +0 -1
  242. package/components/Cart.es.js +0 -259
  243. package/components/CartDrawer.cjs.js +0 -1
  244. package/components/Checkout.cjs.js +0 -1
  245. package/components/CurrencySwitcher.cjs.js +0 -1
  246. package/components/FeaturedProduct.cjs.js +0 -1
  247. package/components/ProductDetailsLayout.cjs.js +0 -1
  248. package/components/ProductDetailsLayout.es.js +0 -19
  249. package/components/ProductGrid.cjs.js +0 -1
  250. package/components/ProductGrid.es.js +0 -6
  251. package/coupon-server-C9ySm3I5.cjs +0 -1
  252. package/customer-C-UPvrYN.cjs +0 -1
  253. package/invoice-ui-CAnJPu6n.cjs +0 -29
  254. package/invoice-ui-DtpbTJE1.js +0 -2886
  255. package/product-actions-CONBF8i6.cjs +0 -251
  256. package/product-actions-DjlIWCMH.js +0 -691
  257. package/resolver-Fz_FKsfX.cjs +0 -7
  258. package/resolver-cfrCaHpE.js +0 -128
  259. package/server-actions/product-actions.cjs.js +0 -1
  260. package/shipping-actions-D6zt20gg.cjs +0 -1
  261. package/states-CWYRxV4B.cjs +0 -1
  262. package/tax-calculation-Dab89aHd.js +0 -181
  263. package/tax-calculation-MkDKOEkL.cjs +0 -1
  264. package/trials-DvZaOtNy.cjs +0 -1
  265. /package/{components → lib/components}/SimpleTiptapRenderer.cjs.js +0 -0
  266. /package/{components → lib/components}/SimpleTiptapRenderer.es.js +0 -0
  267. /package/{currency-constants.cjs.js → lib/currency-constants.cjs.js} +0 -0
  268. /package/{currency-constants.es.js → lib/currency-constants.es.js} +0 -0
  269. /package/{currency-rest-client-uolJxUkL.cjs → lib/currency-rest-client.cjs.js} +0 -0
  270. /package/{currency-rest-client-CwoqdgAP.js → lib/currency-rest-client.es.js} +0 -0
  271. /package/{currency.cjs.js → lib/currency.cjs.js} +0 -0
  272. /package/{currency.es.js → lib/currency.es.js} +0 -0
  273. /package/{types.cjs.js → lib/types.cjs.js} +0 -0
  274. /package/{types.es.js → lib/types.es.js} +0 -0
  275. /package/{use-cart.cjs.js → lib/use-cart.cjs.js} +0 -0
  276. /package/{variation-utils.cjs.js → lib/variation-utils.cjs.js} +0 -0
  277. /package/{variation-utils.es.js → lib/variation-utils.es.js} +0 -0
package/cart-store.cjs.js DELETED
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=require("zustand"),p=require("zustand/middleware"),o=require("./types.cjs.js"),k=require("./CurrencyProvider-Cg-Q6ucj.cjs"),S=require("./currency.cjs.js");function a(r,c,e){return r.reduce((t,s)=>o.isDigitalItem(s)||s.sku!==c||e&&s.id===e?t:t+s.quantity,0)}const l=y.create()(p.persist((r,c)=>({items:[],appliedCoupon:null,isOpen:!1,addItem:e=>{const{items:t}=c(),s=e.quantity??1,i=typeof e.stock=="number"?e.stock:null,u=i!==null?a(t,e.sku):0;if(o.isDigitalItem(e))return t.find(d=>d.product_id===e.product_id&&o.isDigitalItem(d))?{success:!1,error:"This software license is already in your cart."}:(r({items:[...t,{...e,quantity:1}],isOpen:!0}),{success:!0});const C=t.find(n=>n.id===e.id);return i!==null&&i<=0?{success:!1,error:"This item is out of stock."}:i!==null&&u+s>i?{success:!1,error:`Only ${i} available for this SKU.`}:(r(C?{items:t.map(n=>n.id===e.id?{...n,...e,quantity:n.quantity+s}:n),isOpen:!0}:{items:[...t,{...e,quantity:s}],isOpen:!0}),{success:!0})},removeItem:e=>{const{items:t}=c();r({items:t.filter(s=>s.id!==e)})},updateQuantity:(e,t)=>{const{items:s}=c(),i=s.find(u=>u.id===e);i&&o.isDigitalItem(i)||(i&&typeof i.stock=="number"&&t+a(s,i.sku,e)>i.stock&&(t=Math.max(i.stock-a(s,i.sku,e),0)),t<=0?r({items:s.filter(u=>u.id!==e)}):r({items:s.map(u=>u.id===e?{...u,quantity:t}:u)}))},setAppliedCoupon:e=>{const t=c().appliedCoupon;t?.code===e?.code&&t?.couponId===e?.couponId||r({appliedCoupon:e})},removeCoupon:()=>{c().appliedCoupon&&r({appliedCoupon:null})},clearCart:()=>r({items:[],appliedCoupon:null}),toggleCart:()=>r(e=>({isOpen:!e.isOpen})),setIsOpen:e=>r({isOpen:e}),setItems:e=>r({items:e})}),{name:"cart-storage",storage:p.createJSONStorage(()=>localStorage),skipHydration:!0})),g=()=>l(c=>c.items).reduce((c,e)=>c+e.quantity,0);function f(r,c){return S.resolveEffectivePriceForCurrency({prices:r.prices,salePrices:r.sale_prices,fallbackPrice:r.price,fallbackSalePrice:r.sale_price,saleStartAt:r.sale_start_at,saleEndAt:r.sale_end_at,scheduledPrice:r.scheduled_price,scheduledPrices:r.scheduled_prices,scheduledPriceAt:r.scheduled_price_at,currencyCode:c.currencyCode,currencies:c.currencies})}const _=()=>{const r=l(t=>t.items),{activeCurrencyCode:c,currencies:e}=k.useCurrency();return r.reduce((t,s)=>{const{price:i,sale_price:u}=f(s,{currencyCode:c,currencies:e});return t+(u??i)*s.quantity},0)};exports.getCartItemActivePrice=f;exports.useCartStore=l;exports.useCartSubtotal=_;exports.useCartTotalItems=g;
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),u=require("react"),z=require("@nextblock-cms/ui/badge"),g=require("@nextblock-cms/ui/button"),l=require("@nextblock-cms/ui/table"),x=require("lucide-react"),k=require("../cart-store.cjs.js"),H=require("../use-cart.cjs.js"),f=require("../types.cjs.js"),D=require("next/navigation"),m=require("@nextblock-cms/utils"),E=require("@nextblock-cms/ui/input"),T=require("@nextblock-cms/ui/label"),_=require("../states-CWYRxV4B.cjs"),M=require("../shipping-actions-D6zt20gg.cjs"),P=require("../CurrencyProvider-Cg-Q6ucj.cjs"),O=require("../trials-DvZaOtNy.cjs"),Q=require("../CouponForm-D_uu2bLP.cjs"),K=({physicalSubtotal:S})=>{const[o,w]=u.useState("CA"),[a,n]=u.useState(""),[h,i]=u.useState(""),[N,j]=u.useState(!1),[d,v]=u.useState(null),[b,s]=u.useState(null),{t:r,lang:c}=m.useTranslations(),{activeCurrencyCode:p}=P.useCurrency(),q=(t,y)=>{const C=r(t);return C===t?y:C},A=_.getStatesForCountry(o),B=_.countryUsesStructuredStates(o),F=q("select_an_option","Select an option"),I=q("state_province","State / Province"),R=async()=>{j(!0),s(null),v(null);const t=await M.getShippingEstimates(S,{country:o,state:a||void 0,postal_code:h},c,p);t.success&&t.methods?v(t.methods):s(t.errorKey?q(t.errorKey,t.error||r("ecommerce.no_rates_found")):t.error||r("ecommerce.no_rates_found")),j(!1)};return e.jsxs("div",{className:"space-y-4 rounded-lg border bg-muted/30 p-4 mt-6",children:[e.jsxs("div",{className:"flex items-center gap-2 font-semibold text-sm",children:[e.jsx(x.Truck,{className:"h-4 w-4"}),e.jsx("span",{children:r("ecommerce.estimate_shipping")})]}),e.jsxs("div",{className:"grid gap-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(T.Label,{htmlFor:"estimate-country",className:"text-xs uppercase tracking-wider text-muted-foreground",children:r("ecommerce.country")}),e.jsx("select",{id:"estimate-country",value:o,onChange:t=>{const y=t.target.value,C=_.getStatesForCountry(y);w(y),n(C.some(L=>L.code===a)?a:"")},className:"flex h-9 w-full rounded-md border border-input bg-background px-3 py-2 text-sm",children:_.countries.map(t=>e.jsx("option",{value:t.code,children:t.name},t.code))})]}),B&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(T.Label,{htmlFor:"estimate-state",className:"text-xs uppercase tracking-wider text-muted-foreground",children:r("state_province")}),e.jsxs("select",{id:"estimate-state",value:a,onChange:t=>n(t.target.value),className:"flex h-9 w-full rounded-md border border-input bg-background px-3 py-2 text-sm",children:[e.jsx("option",{value:"",children:`${F}: ${I}`}),A.map(t=>e.jsx("option",{value:t.code,children:t.name},t.code))]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(T.Label,{htmlFor:"estimate-postal",className:"text-xs uppercase tracking-wider text-muted-foreground",children:r("ecommerce.postal_code")}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(E.Input,{id:"estimate-postal",placeholder:"A1A 1A1",value:h,onChange:t=>i(t.target.value),className:"h-9 text-sm bg-background"}),e.jsxs(g.Button,{size:"sm",variant:"secondary",onClick:R,disabled:N,className:"shrink-0",children:[N?e.jsx(x.Loader2,{className:"h-4 w-4 animate-spin"}):e.jsx(x.Calculator,{className:"h-4 w-4 mr-1.5"}),r("ecommerce.calculate")]})]})]})]}),b&&e.jsx("p",{className:"text-xs text-destructive mt-2",children:b}),d&&d.length>0&&e.jsxs("div",{className:"mt-4 space-y-2 border-t pt-3",children:[e.jsxs("p",{className:"text-xs font-medium text-muted-foreground uppercase",children:[r("ecommerce.available_rates"),":"]}),d.map(t=>e.jsxs("div",{className:"flex justify-between items-center p-3 border rounded-lg bg-muted/30",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(x.Truck,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"text-sm font-medium",children:t.name})]}),e.jsx("span",{className:"text-sm font-bold",children:t.amount===0?r("ecommerce.free"):m.formatPrice(t.amount,p)})]},t.id))]}),d&&d.length===0&&!b&&e.jsx("p",{className:"text-xs text-muted-foreground mt-2 italic",children:r("ecommerce.no_rates_found")})]})},$=()=>{const S=D.useRouter(),o=H.useCart(s=>s),w=k.useCartSubtotal(),{t:a}=m.useTranslations(),{activeCurrencyCode:n,currencies:h}=P.useCurrency(),i=o?.items??[],N=u.useMemo(()=>i.reduce((s,r)=>{if(f.isDigitalItem(r))return s;const c=k.getCartItemActivePrice(r,{currencyCode:n,currencies:h});return s+(c.sale_price??c.price)*r.quantity},0),[n,h,i]);if(!o)return null;const{updateQuantity:j,removeItem:d}=o,v=s=>i.reduce((r,c)=>f.isDigitalItem(c)||c.sku!==s?r:r+c.quantity,0),b=()=>{S.push("/checkout")};return i.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center space-y-4 py-12",children:[e.jsx("h2",{className:"text-2xl font-bold",children:a("ecommerce.cart_empty")}),e.jsx("p",{className:"text-muted-foreground",children:a("ecommerce.cart_empty_description")}),e.jsx(g.Button,{asChild:!0,children:e.jsx("a",{href:"/shop",children:a("ecommerce.continue_shopping")})})]}):e.jsxs("div",{className:"container mx-auto py-12",children:[e.jsx("h1",{className:"mb-8 text-3xl font-bold",children:a("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(l.Table,{children:[e.jsx(l.TableHeader,{children:e.jsxs(l.TableRow,{children:[e.jsx(l.TableHead,{children:a("ecommerce.product")}),e.jsx(l.TableHead,{children:a("ecommerce.quantity")}),e.jsx(l.TableHead,{className:"text-right",children:a("ecommerce.price")}),e.jsx(l.TableHead,{className:"text-right",children:a("ecommerce.total")}),e.jsx(l.TableHead,{className:"w-[50px]"})]})}),e.jsx(l.TableBody,{children:i.map(s=>{const r=v(s.sku),c=k.getCartItemActivePrice(s,{currencyCode:n,currencies:h}),p=O.getTrialSummary(s);return e.jsxs(l.TableRow,{children:[e.jsx(l.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:a("ecommerce.no_image")})}),e.jsxs("div",{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}),f.isDigitalItem(s)&&s.billing_cycle&&e.jsxs("div",{className:"mt-1 text-xs capitalize text-muted-foreground",children:[s.billing_cycle," Subscription"]}),p&&e.jsxs("div",{className:"mt-1 text-xs font-medium text-emerald-700",children:[p.label," - ",p.paymentRequirementLabel]})]})]})}),e.jsx(l.TableCell,{children:f.isDigitalItem(s)?e.jsx(z.Badge,{variant:"secondary",className:"font-normal text-xs",children:"1 (License)"}):e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(g.Button,{variant:"outline",size:"icon",className:"h-8 w-8",onClick:()=>j(s.id,s.quantity-1),children:e.jsx(x.Minus,{className:"h-4 w-4"})}),e.jsx("span",{className:"w-8 text-center",children:s.quantity}),e.jsx(g.Button,{variant:"outline",size:"icon",className:"h-8 w-8",onClick:()=>j(s.id,s.quantity+1),disabled:typeof s.stock=="number"&&r>=s.stock,children:e.jsx(x.Plus,{className:"h-4 w-4"})})]})}),e.jsx(l.TableCell,{className:"text-right",children:e.jsxs("div",{className:"flex flex-col items-end",children:[e.jsx("span",{className:"font-medium",children:m.formatPrice(c.sale_price??c.price,n)}),c.sale_price&&e.jsx("span",{className:"text-xs text-muted-foreground line-through",children:m.formatPrice(c.price,n)})]})}),e.jsx(l.TableCell,{className:"text-right font-medium",children:m.formatPrice((c.sale_price??c.price)*s.quantity,n)}),e.jsx(l.TableCell,{children:e.jsx(g.Button,{variant:"ghost",size:"icon",onClick:()=>d(s.id),className:"text-muted-foreground hover:text-destructive",children:e.jsx(x.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:a("ecommerce.order_summary")}),e.jsxs("div",{className:"flex justify-between border-b pb-4",children:[e.jsx("span",{children:a("ecommerce.subtotal")}),e.jsx("span",{className:"font-medium",children:m.formatPrice(w,n)})]}),e.jsxs("div",{className:"mt-4 flex flex-col gap-4",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:a("ecommerce.shipping_taxes_calculated")}),i.some(s=>!f.isDigitalItem(s))&&e.jsx(K,{physicalSubtotal:N}),e.jsx(Q.CouponForm,{items:i,currencyCode:n,compact:!0}),e.jsx(g.Button,{className:"w-full mt-4",size:"lg",onClick:b,children:a("ecommerce.proceed_to_checkout")})]})]})})]})]})};exports.Cart=$;
@@ -1,259 +0,0 @@
1
- import { jsxs as a, jsx as e } from "react/jsx-runtime";
2
- import { useState as h, useMemo as K } from "react";
3
- import { Badge as M } from "@nextblock-cms/ui/badge";
4
- import { Button as p } from "@nextblock-cms/ui/button";
5
- import { Table as O, TableHeader as $, TableRow as P, TableHead as x, TableBody as D, TableCell as N } from "@nextblock-cms/ui/table";
6
- import { Truck as j, Loader2 as U, Calculator as G, Minus as J, Plus as V, Trash2 as W } from "lucide-react";
7
- import { useCartSubtotal as X, getCartItemActivePrice as z } from "../cart-store.es.js";
8
- import { useCart as Y } from "../use-cart.es.js";
9
- import { isDigitalItem as v } from "../types.es.js";
10
- import { useRouter as Z } from "next/navigation";
11
- import { useTranslations as F, formatPrice as b } from "@nextblock-cms/utils";
12
- import { Input as ee } from "@nextblock-cms/ui/input";
13
- import { Label as q } from "@nextblock-cms/ui/label";
14
- import { g as A, a as te, c as re } from "../states-DlHJezQ1.js";
15
- import { g as ae } from "../shipping-actions-BnHjlo2q.js";
16
- import { u as L } from "../CurrencyProvider-OzlRN96V.js";
17
- import { d as ce } from "../trials-RDcRAZKx.js";
18
- import { C as se } from "../CouponForm-BI_5SBHQ.js";
19
- const le = ({ physicalSubtotal: k }) => {
20
- const [i, S] = h("CA"), [s, n] = h(""), [m, o] = h(""), [y, g] = h(!1), [d, C] = h(null), [f, t] = h(null), { t: c, lang: l } = F(), { activeCurrencyCode: u } = L(), T = (r, _) => {
21
- const w = c(r);
22
- return w === r ? _ : w;
23
- }, R = A(i), B = te(i), E = T("select_an_option", "Select an option"), I = T("state_province", "State / Province"), Q = async () => {
24
- g(!0), t(null), C(null);
25
- const r = await ae(
26
- k,
27
- {
28
- country: i,
29
- state: s || void 0,
30
- postal_code: m
31
- },
32
- l,
33
- u
34
- );
35
- r.success && r.methods ? C(r.methods) : t(
36
- r.errorKey ? T(
37
- r.errorKey,
38
- r.error || c("ecommerce.no_rates_found")
39
- ) : r.error || c("ecommerce.no_rates_found")
40
- ), g(!1);
41
- };
42
- return /* @__PURE__ */ a("div", { className: "space-y-4 rounded-lg border bg-muted/30 p-4 mt-6", children: [
43
- /* @__PURE__ */ a("div", { className: "flex items-center gap-2 font-semibold text-sm", children: [
44
- /* @__PURE__ */ e(j, { className: "h-4 w-4" }),
45
- /* @__PURE__ */ e("span", { children: c("ecommerce.estimate_shipping") })
46
- ] }),
47
- /* @__PURE__ */ a("div", { className: "grid gap-3", children: [
48
- /* @__PURE__ */ a("div", { className: "space-y-1.5", children: [
49
- /* @__PURE__ */ e(q, { htmlFor: "estimate-country", className: "text-xs uppercase tracking-wider text-muted-foreground", children: c("ecommerce.country") }),
50
- /* @__PURE__ */ e(
51
- "select",
52
- {
53
- id: "estimate-country",
54
- value: i,
55
- onChange: (r) => {
56
- const _ = r.target.value, w = A(_);
57
- S(_), n(
58
- w.some((H) => H.code === s) ? s : ""
59
- );
60
- },
61
- className: "flex h-9 w-full rounded-md border border-input bg-background px-3 py-2 text-sm",
62
- children: re.map((r) => /* @__PURE__ */ e("option", { value: r.code, children: r.name }, r.code))
63
- }
64
- )
65
- ] }),
66
- B && /* @__PURE__ */ a("div", { className: "space-y-1.5", children: [
67
- /* @__PURE__ */ e(q, { htmlFor: "estimate-state", className: "text-xs uppercase tracking-wider text-muted-foreground", children: c("state_province") }),
68
- /* @__PURE__ */ a(
69
- "select",
70
- {
71
- id: "estimate-state",
72
- value: s,
73
- onChange: (r) => n(r.target.value),
74
- className: "flex h-9 w-full rounded-md border border-input bg-background px-3 py-2 text-sm",
75
- children: [
76
- /* @__PURE__ */ e("option", { value: "", children: `${E}: ${I}` }),
77
- R.map((r) => /* @__PURE__ */ e("option", { value: r.code, children: r.name }, r.code))
78
- ]
79
- }
80
- )
81
- ] }),
82
- /* @__PURE__ */ a("div", { className: "space-y-1.5", children: [
83
- /* @__PURE__ */ e(q, { htmlFor: "estimate-postal", className: "text-xs uppercase tracking-wider text-muted-foreground", children: c("ecommerce.postal_code") }),
84
- /* @__PURE__ */ a("div", { className: "flex gap-2", children: [
85
- /* @__PURE__ */ e(
86
- ee,
87
- {
88
- id: "estimate-postal",
89
- placeholder: "A1A 1A1",
90
- value: m,
91
- onChange: (r) => o(r.target.value),
92
- className: "h-9 text-sm bg-background"
93
- }
94
- ),
95
- /* @__PURE__ */ a(
96
- p,
97
- {
98
- size: "sm",
99
- variant: "secondary",
100
- onClick: Q,
101
- disabled: y,
102
- className: "shrink-0",
103
- children: [
104
- y ? /* @__PURE__ */ e(U, { className: "h-4 w-4 animate-spin" }) : /* @__PURE__ */ e(G, { className: "h-4 w-4 mr-1.5" }),
105
- c("ecommerce.calculate")
106
- ]
107
- }
108
- )
109
- ] })
110
- ] })
111
- ] }),
112
- f && /* @__PURE__ */ e("p", { className: "text-xs text-destructive mt-2", children: f }),
113
- d && d.length > 0 && /* @__PURE__ */ a("div", { className: "mt-4 space-y-2 border-t pt-3", children: [
114
- /* @__PURE__ */ a("p", { className: "text-xs font-medium text-muted-foreground uppercase", children: [
115
- c("ecommerce.available_rates"),
116
- ":"
117
- ] }),
118
- d.map((r) => /* @__PURE__ */ a("div", { className: "flex justify-between items-center p-3 border rounded-lg bg-muted/30", children: [
119
- /* @__PURE__ */ a("div", { className: "flex items-center gap-2", children: [
120
- /* @__PURE__ */ e(j, { className: "h-4 w-4 text-muted-foreground" }),
121
- /* @__PURE__ */ e("span", { className: "text-sm font-medium", children: r.name })
122
- ] }),
123
- /* @__PURE__ */ e("span", { className: "text-sm font-bold", children: r.amount === 0 ? c("ecommerce.free") : b(r.amount, u) })
124
- ] }, r.id))
125
- ] }),
126
- d && d.length === 0 && !f && /* @__PURE__ */ e("p", { className: "text-xs text-muted-foreground mt-2 italic", children: c("ecommerce.no_rates_found") })
127
- ] });
128
- }, ke = () => {
129
- const k = Z(), i = Y((t) => t), S = X(), { t: s } = F(), { activeCurrencyCode: n, currencies: m } = L(), o = i?.items ?? [], y = K(
130
- () => o.reduce((t, c) => {
131
- if (v(c))
132
- return t;
133
- const l = z(c, {
134
- currencyCode: n,
135
- currencies: m
136
- });
137
- return t + (l.sale_price ?? l.price) * c.quantity;
138
- }, 0),
139
- [n, m, o]
140
- );
141
- if (!i) return null;
142
- const { updateQuantity: g, removeItem: d } = i, C = (t) => o.reduce((c, l) => v(l) || l.sku !== t ? c : c + l.quantity, 0), f = () => {
143
- k.push("/checkout");
144
- };
145
- return o.length === 0 ? /* @__PURE__ */ a("div", { className: "flex flex-col items-center justify-center space-y-4 py-12", children: [
146
- /* @__PURE__ */ e("h2", { className: "text-2xl font-bold", children: s("ecommerce.cart_empty") }),
147
- /* @__PURE__ */ e("p", { className: "text-muted-foreground", children: s("ecommerce.cart_empty_description") }),
148
- /* @__PURE__ */ e(p, { asChild: !0, children: /* @__PURE__ */ e("a", { href: "/shop", children: s("ecommerce.continue_shopping") }) })
149
- ] }) : /* @__PURE__ */ a("div", { className: "container mx-auto py-12", children: [
150
- /* @__PURE__ */ e("h1", { className: "mb-8 text-3xl font-bold", children: s("ecommerce.shopping_cart") }),
151
- /* @__PURE__ */ a("div", { className: "grid gap-12 lg:grid-cols-12 lg:items-start", children: [
152
- /* @__PURE__ */ e("div", { className: "lg:col-span-8", children: /* @__PURE__ */ e("div", { className: "rounded-lg border overflow-hidden", children: /* @__PURE__ */ a(O, { children: [
153
- /* @__PURE__ */ e($, { children: /* @__PURE__ */ a(P, { children: [
154
- /* @__PURE__ */ e(x, { children: s("ecommerce.product") }),
155
- /* @__PURE__ */ e(x, { children: s("ecommerce.quantity") }),
156
- /* @__PURE__ */ e(x, { className: "text-right", children: s("ecommerce.price") }),
157
- /* @__PURE__ */ e(x, { className: "text-right", children: s("ecommerce.total") }),
158
- /* @__PURE__ */ e(x, { className: "w-[50px]" })
159
- ] }) }),
160
- /* @__PURE__ */ e(D, { children: o.map((t) => {
161
- const c = C(t.sku), l = z(t, {
162
- currencyCode: n,
163
- currencies: m
164
- }), u = ce(t);
165
- return /* @__PURE__ */ a(P, { children: [
166
- /* @__PURE__ */ e(N, { children: /* @__PURE__ */ a("div", { className: "flex items-center gap-4", children: [
167
- t.image_url ? /* @__PURE__ */ e("div", { className: "h-16 w-16 overflow-hidden rounded border bg-neutral-100", children: /* @__PURE__ */ e(
168
- "img",
169
- {
170
- src: t.image_url,
171
- alt: t.title,
172
- className: "h-full w-full object-cover"
173
- }
174
- ) }) : /* @__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: s("ecommerce.no_image") }) }),
175
- /* @__PURE__ */ a("div", { children: [
176
- /* @__PURE__ */ e("div", { className: "font-medium", children: t.title }),
177
- t.variant_label && /* @__PURE__ */ e("div", { className: "mt-1 text-xs text-muted-foreground", children: t.variant_label }),
178
- v(t) && t.billing_cycle && /* @__PURE__ */ a("div", { className: "mt-1 text-xs capitalize text-muted-foreground", children: [
179
- t.billing_cycle,
180
- " Subscription"
181
- ] }),
182
- u && /* @__PURE__ */ a("div", { className: "mt-1 text-xs font-medium text-emerald-700", children: [
183
- u.label,
184
- " - ",
185
- u.paymentRequirementLabel
186
- ] })
187
- ] })
188
- ] }) }),
189
- /* @__PURE__ */ e(N, { children: v(t) ? /* @__PURE__ */ e(M, { variant: "secondary", className: "font-normal text-xs", children: "1 (License)" }) : /* @__PURE__ */ a("div", { className: "flex items-center gap-2", children: [
190
- /* @__PURE__ */ e(
191
- p,
192
- {
193
- variant: "outline",
194
- size: "icon",
195
- className: "h-8 w-8",
196
- onClick: () => g(t.id, t.quantity - 1),
197
- children: /* @__PURE__ */ e(J, { className: "h-4 w-4" })
198
- }
199
- ),
200
- /* @__PURE__ */ e("span", { className: "w-8 text-center", children: t.quantity }),
201
- /* @__PURE__ */ e(
202
- p,
203
- {
204
- variant: "outline",
205
- size: "icon",
206
- className: "h-8 w-8",
207
- onClick: () => g(t.id, t.quantity + 1),
208
- disabled: typeof t.stock == "number" && c >= t.stock,
209
- children: /* @__PURE__ */ e(V, { className: "h-4 w-4" })
210
- }
211
- )
212
- ] }) }),
213
- /* @__PURE__ */ e(N, { className: "text-right", children: /* @__PURE__ */ a("div", { className: "flex flex-col items-end", children: [
214
- /* @__PURE__ */ e("span", { className: "font-medium", children: b(l.sale_price ?? l.price, n) }),
215
- l.sale_price && /* @__PURE__ */ e("span", { className: "text-xs text-muted-foreground line-through", children: b(l.price, n) })
216
- ] }) }),
217
- /* @__PURE__ */ e(N, { className: "text-right font-medium", children: b(
218
- (l.sale_price ?? l.price) * t.quantity,
219
- n
220
- ) }),
221
- /* @__PURE__ */ e(N, { children: /* @__PURE__ */ e(
222
- p,
223
- {
224
- variant: "ghost",
225
- size: "icon",
226
- onClick: () => d(t.id),
227
- className: "text-muted-foreground hover:text-destructive",
228
- children: /* @__PURE__ */ e(W, { className: "h-4 w-4" })
229
- }
230
- ) })
231
- ] }, t.id);
232
- }) })
233
- ] }) }) }),
234
- /* @__PURE__ */ e("div", { className: "lg:col-span-4", children: /* @__PURE__ */ a("div", { className: "rounded-lg border bg-card p-6 shadow-sm", children: [
235
- /* @__PURE__ */ e("h2", { className: "mb-4 text-lg font-semibold", children: s("ecommerce.order_summary") }),
236
- /* @__PURE__ */ a("div", { className: "flex justify-between border-b pb-4", children: [
237
- /* @__PURE__ */ e("span", { children: s("ecommerce.subtotal") }),
238
- /* @__PURE__ */ e("span", { className: "font-medium", children: b(S, n) })
239
- ] }),
240
- /* @__PURE__ */ a("div", { className: "mt-4 flex flex-col gap-4", children: [
241
- /* @__PURE__ */ e("p", { className: "text-sm text-muted-foreground", children: s("ecommerce.shipping_taxes_calculated") }),
242
- o.some((t) => !v(t)) && /* @__PURE__ */ e(le, { physicalSubtotal: y }),
243
- /* @__PURE__ */ e(
244
- se,
245
- {
246
- items: o,
247
- currencyCode: n,
248
- compact: !0
249
- }
250
- ),
251
- /* @__PURE__ */ e(p, { className: "w-full mt-4", size: "lg", onClick: f, children: s("ecommerce.proceed_to_checkout") })
252
- ] })
253
- ] }) })
254
- ] })
255
- ] });
256
- };
257
- export {
258
- ke as Cart
259
- };
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),l=require("@nextblock-cms/ui/sheet"),q=require("@nextblock-cms/ui/badge"),d=require("@nextblock-cms/ui/button"),_=require("next/navigation"),m=require("lucide-react"),j=require("../cart-store.cjs.js"),k=require("../use-cart.cjs.js"),o=require("@nextblock-cms/utils"),p=require("../types.cjs.js"),S=require("../CurrencyProvider-Cg-Q6ucj.cjs"),P=require("../trials-DvZaOtNy.cjs"),D=require("../CouponForm-D_uu2bLP.cjs"),T=()=>{const x=_.useRouter(),h=k.useCart(t=>t),g=j.useCartSubtotal(),{t:s}=o.useTranslations(),{activeCurrencyCode:c,currencies:y}=S.useCurrency();if(!h)return null;const{isOpen:b,setIsOpen:a,items:n,updateQuantity:f,removeItem:v}=h,N=t=>n.reduce((i,r)=>p.isDigitalItem(r)||r.sku!==t?i:i+r.quantity,0),w=()=>{a(!1),x.push("/cart")},C=()=>{a(!1),x.push("/checkout")};return e.jsx(l.Sheet,{open:b,onOpenChange:a,children:e.jsxs(l.SheetContent,{className:"flex w-full flex-col pr-0 sm:max-w-lg",children:[e.jsxs(l.SheetHeader,{className:"px-1 text-left",children:[e.jsxs(l.SheetTitle,{children:[s("ecommerce.shopping_cart")," (",n.length,")"]}),e.jsx(l.SheetDescription,{className:"sr-only",children:s("ecommerce.shopping_cart")})]}),n.length>0?e.jsx("div",{className:"flex flex-1 flex-col gap-5 overflow-y-auto p-1 pr-6 pt-4",children:n.map(t=>{const i=N(t.sku);return e.jsx("div",{className:"flex gap-4",children:(()=>{const r=j.getCartItemActivePrice(t,{currencyCode:c,currencies:y}),u=P.getTrialSummary(t);return e.jsxs(e.Fragment,{children:[t.image_url?e.jsx("div",{className:"relative aspect-square h-20 w-20 min-w-fit 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"})}):e.jsx("div",{className:"flex h-20 w-20 items-center justify-center rounded bg-secondary",children:e.jsx("span",{className:"text-xs text-muted-foreground",children:s("ecommerce.no_image")})}),e.jsxs("div",{className:"flex flex-1 flex-col justify-between",children:[e.jsxs("div",{className:"flex justify-between gap-2",children:[e.jsxs("div",{children:[e.jsx("span",{className:"line-clamp-2 text-sm font-medium leading-tight",children:t.title}),t.variant_label&&e.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:t.variant_label}),u&&e.jsxs("div",{className:"mt-1 text-xs font-medium text-emerald-700",children:[u.label," - ",u.paymentRequirementLabel]})]}),e.jsxs("span",{className:"text-sm font-semibold",children:[r.sale_price&&e.jsx("span",{className:"mr-1.5 text-xs font-normal text-muted-foreground line-through",children:o.formatPrice(r.price,c)}),o.formatPrice(r.sale_price??r.price,c)]})]}),e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[p.isDigitalItem(t)?e.jsx(q.Badge,{variant:"secondary",className:"font-normal text-xs",children:"1 (License)"}):e.jsxs("div",{className:"flex items-center rounded-md border text-xs",children:[e.jsx("button",{onClick:()=>f(t.id,t.quantity-1),className:"flex h-7 w-7 items-center justify-center border-r",type:"button",children:e.jsx(m.Minus,{className:"h-3 w-3"})}),e.jsx("span",{className:"flex h-7 w-8 items-center justify-center",children:t.quantity}),e.jsx("button",{onClick:()=>f(t.id,t.quantity+1),className:"flex h-7 w-7 items-center justify-center border-l",type:"button",disabled:typeof t.stock=="number"&&i>=t.stock,children:e.jsx(m.Plus,{className:"h-3 w-3"})})]}),e.jsx("button",{onClick:()=>v(t.id),className:"text-muted-foreground hover:text-destructive",type:"button",children:e.jsx(m.Trash2,{className:"h-4 w-4"})})]})]})]})})()},t.id)})}):e.jsxs("div",{className:"flex h-full flex-col items-center justify-center space-y-2",children:[e.jsx("span",{className:"text-muted-foreground",children:s("ecommerce.cart_empty")}),e.jsx(d.Button,{variant:"outline",onClick:()=>a(!1),children:s("ecommerce.continue_shopping")})]}),n.length>0&&e.jsxs("div",{className:"border-t pr-6 pt-4",children:[e.jsxs("div",{className:"flex items-center justify-between text-base font-medium",children:[e.jsx("span",{children:s("ecommerce.subtotal")}),e.jsx("span",{children:o.formatPrice(g,c)})]}),e.jsx("p",{className:"mb-4 mt-1 text-xs text-muted-foreground",children:s("ecommerce.shipping_taxes_calculated")}),e.jsx("div",{className:"mb-4",children:e.jsx(D.CouponForm,{items:n,currencyCode:c,compact:!0})}),e.jsx(d.Button,{variant:"outline",className:"w-full mb-3",onClick:w,children:s("ecommerce.view_full_cart")}),e.jsx(d.Button,{className:"w-full",onClick:C,children:s("ecommerce.ready_to_checkout")})]})]})})};exports.CartDrawer=T;
@@ -1 +0,0 @@
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;
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),r=require("@nextblock-cms/ui/select"),i=require("../CurrencyProvider-Cg-Q6ucj.cjs");function s(){const{activeCurrencyCode:c,currencies:n,setActiveCurrencyCode:l}=i.useCurrency();return n.length<=1?null:e.jsxs(r.Select,{value:c,onValueChange:l,children:[e.jsx(r.SelectTrigger,{className:"h-9 w-[88px] text-xs font-semibold",children:e.jsx(r.SelectValue,{placeholder:c})}),e.jsx(r.SelectContent,{children:n.map(t=>e.jsx(r.SelectItem,{value:t.code,children:t.code},t.code))})]})}exports.CurrencySwitcher=s;
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react/jsx-runtime"),h=require("../AddToCartButton-DsSEH9yp.cjs"),s=require("@nextblock-cms/utils"),o=require("next/link"),g=require("../CurrencyProvider-Cg-Q6ucj.cjs"),m=require("../currency.cjs.js"),v=require("../trials-DvZaOtNy.cjs"),b=({product:e,className:x,imagePosition:u="left"})=>{const{t:c}=s.useTranslations(),{activeCurrencyCode:l,currencies:n}=g.useCurrency(),a=m.resolvePriceRangeForCurrency({entries:e.variants?.length?e.variants:e.product_variants?.length?e.product_variants:[],currencyCode:l,currencies:n}),d=!!(e.has_variants&&a),t=m.resolveEffectivePriceForCurrency({prices:e.prices,salePrices:e.sale_prices,fallbackPrice:e.price,fallbackSalePrice:e.sale_price,saleStartAt:e.sale_start_at,saleEndAt:e.sale_end_at,scheduledPrice:e.scheduled_price,scheduledPrices:e.scheduled_prices,scheduledPriceAt:e.scheduled_price_at,currencyCode:l,currencies:n}),f=d&&a?a.min===a.max?s.formatPrice(a.min,l):`${s.formatPrice(a.min,l)} - ${s.formatPrice(a.max,l)}`:s.formatPrice(t.sale_price??t.price,l),i=v.getTrialSummary(e);return r.jsx("div",{className:s.cn("overflow-hidden rounded-xl border bg-card shadow-sm",x),children:r.jsxs("div",{className:s.cn("flex flex-col gap-8 md:flex-row",u==="right"&&"md:flex-row-reverse"),children:[r.jsx("div",{className:"relative aspect-square w-full md:w-1/2",children:e.image_url?r.jsx("img",{src:e.image_url,alt:e.title,className:"h-full w-full object-cover"}):r.jsx("div",{className:"flex h-full w-full items-center justify-center bg-secondary text-muted-foreground",children:c("ecommerce.no_image")})}),r.jsxs("div",{className:"flex flex-1 flex-col justify-center p-6 md:p-12",children:[r.jsx(o,{href:`/product/${e.slug}`,children:r.jsx("h2",{className:"mb-4 text-3xl font-bold tracking-tight hover:underline md:text-4xl",children:e.title})}),r.jsxs("div",{className:"mb-6 flex items-baseline gap-3",children:[r.jsx("span",{className:"text-3xl font-bold text-primary",children:f}),!d&&t.sale_price&&r.jsx("span",{className:"text-lg text-muted-foreground line-through",children:s.formatPrice(t.price,l)})]}),i&&r.jsxs("div",{className:"mb-6 inline-flex w-fit flex-col rounded-md border border-emerald-200 bg-emerald-50 px-3 py-2 text-sm text-emerald-900",children:[r.jsx("span",{className:"font-semibold",children:i.label}),r.jsx("span",{className:"text-emerald-700",children:i.paymentRequirementLabel})]}),e.short_description&&r.jsx("p",{className:"mb-8 text-lg text-muted-foreground",children:e.short_description}),r.jsxs("div",{className:"flex flex-col gap-4 sm:flex-row",children:[r.jsx(h.AddToCartButton,{product:e,className:"h-12 w-full px-8 text-lg sm:w-auto"}),r.jsx(o,{href:`/product/${e.slug}`,className:"inline-flex h-12 items-center justify-center rounded-md border border-input bg-background px-8 text-sm font-medium transition-colors hover:bg-accent hover:text-accent-foreground",children:c("ecommerce.view_details")})]})]})]})})};exports.FeaturedProduct=b;
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("react/jsx-runtime");require("react");require("lucide-react");require("@nextblock-cms/ui/badge");require("@nextblock-cms/ui/button");require("@nextblock-cms/ui/label");require("@nextblock-cms/ui/separator");require("@nextblock-cms/utils");const e=require("../ProductDetailsLayout-BxJH_BxR.cjs");require("../AddToCartButton-DsSEH9yp.cjs");require("./SimpleTiptapRenderer.cjs.js");require("../variation-utils.cjs.js");require("../CurrencyProvider-Cg-Q6ucj.cjs");require("../currency.cjs.js");require("../types.cjs.js");require("../trials-DvZaOtNy.cjs");exports.ProductDetailsLayout=e.ProductDetailsLayout;
@@ -1,19 +0,0 @@
1
- import "react/jsx-runtime";
2
- import "react";
3
- import "lucide-react";
4
- import "@nextblock-cms/ui/badge";
5
- import "@nextblock-cms/ui/button";
6
- import "@nextblock-cms/ui/label";
7
- import "@nextblock-cms/ui/separator";
8
- import "@nextblock-cms/utils";
9
- import { P as D } from "../ProductDetailsLayout-Dg8dRTYp.js";
10
- import "../AddToCartButton-ffE0DhHu.js";
11
- import "./SimpleTiptapRenderer.es.js";
12
- import "../variation-utils.es.js";
13
- import "../CurrencyProvider-OzlRN96V.js";
14
- import "../currency.es.js";
15
- import "../types.es.js";
16
- import "../trials-RDcRAZKx.js";
17
- export {
18
- D as ProductDetailsLayout
19
- };
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("react/jsx-runtime");const r=require("../ProductGrid-BdL7iglO.cjs");require("@nextblock-cms/utils");exports.ProductGrid=r.ProductGrid;
@@ -1,6 +0,0 @@
1
- import "react/jsx-runtime";
2
- import { a as m } from "../ProductGrid-D3AWM8sr.js";
3
- import "@nextblock-cms/utils";
4
- export {
5
- m as ProductGrid
6
- };
@@ -1 +0,0 @@
1
- "use strict";const f=require("./currency.cjs.js");function P(e){return(e||"").trim().replace(/\s+/g,"").toUpperCase()}function q(e){return`${e.product_id}:${e.variant_id||"base"}`}function S(){return{stripe:0,freemius:0}}function M(e){if(!e)return null;const t=new Date(e);return Number.isNaN(t.getTime())?null:t}function D(e,t){return e==="all"||e===t}function x(e){return e==="stripe"||e==="freemius"?e:null}async function A(e){const{data:t,error:c}=await e.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});if(c)throw new Error(c.message);return(t||[]).map(i=>f.normalizeCurrencyRecord(i))}async function K(e){const{client:t,items:c}=e,i=await A(t);if(i.length===0)throw new Error("No active currencies are configured.");const r=i.find(n=>n.code===(e.currencyCode||"").toUpperCase())??f.getDefaultCurrency(i),d=[...new Set(c.map(n=>n.product_id).filter(Boolean))],s=[...new Set(c.map(n=>n.variant_id).filter(n=>!!n))];if(d.length===0)return{lines:[],currencies:i,selectedCurrency:r};const[{data:p,error:y},a]=await Promise.all([t.from("products").select("id, title, price, prices, sale_price, sale_prices, sale_start_at, sale_end_at, scheduled_price, scheduled_prices, scheduled_price_at, product_type, payment_provider, freemius_product_id, freemius_plan_id").in("id",d),s.length?t.from("product_variants").select("id, product_id, price, prices, sale_price, sale_prices, sale_start_at, sale_end_at, scheduled_price, scheduled_prices, scheduled_price_at").in("id",s):Promise.resolve({data:[],error:null})]);if(y)throw new Error(y.message);if(a.error)throw new Error(a.error.message);const v=p||[],_=a.data||[],w=new Map(v.map(n=>[n.id,n])),m=new Map(_.map(n=>[n.id,n])),h=[];for(const n of c){const o=w.get(n.product_id);if(!o)continue;const l=x(o.payment_provider)??(o.product_type==="digital"?"freemius":"stripe"),g=n.variant_id?m.get(n.variant_id):null,u=g&&g.product_id===o.id?g:o,b=f.resolveEffectivePriceForCurrency({prices:f.normalizePriceMap(u.prices),salePrices:f.normalizeSalePriceMap(u.sale_prices),fallbackPrice:u.price,fallbackSalePrice:u.sale_price,saleStartAt:u.sale_start_at,saleEndAt:u.sale_end_at,scheduledPrice:u.scheduled_price,scheduledPrices:f.normalizePriceMap(u.scheduled_prices),scheduledPriceAt:u.scheduled_price_at,currencyCode:r.code,currencies:i}),C=l==="freemius"?1:Math.max(1,Number(n.quantity)||1),E=Math.max(0,b.sale_price??b.price);h.push({key:q(n),product_id:o.id,variant_id:g?.id??null,title:o.title,quantity:C,provider:l,subtotal:E*C,freemius_product_id:o.freemius_product_id??null,freemius_plan_id:o.freemius_plan_id??null})}return{lines:h,currencies:i,selectedCurrency:r}}async function T(e,t){const{data:c,error:i}=await e.from("coupon_products").select("product_id").eq("coupon_id",t);if(i)throw new Error(i.message);return new Set((c||[]).map(r=>r.product_id))}function k(e,t){const c=e.reduce((s,p)=>s+p.subtotal,0),i=Math.min(t,c);if(c<=0||i<=0)return new Map;const r=new Map;let d=0;return e.forEach((s,p)=>{const a=p===e.length-1?i-d:Math.min(s.subtotal,Math.floor(i*s.subtotal/c));d+=a,r.set(s.key,a)}),r}async function I(e){const t=P(e.code);if(!t)return{success:!1,error:"Enter a coupon code.",errorKey:"ecommerce.coupon_code_required"};if(!e.items.length)return{success:!1,error:"Add an item to your cart before applying a coupon.",errorKey:"ecommerce.coupon_cart_empty"};const{data:c,error:i}=await e.client.from("coupons").select("id, code, name, provider_scope, discount_type, discount_amount, is_active, starts_at, ends_at, redemption_limit, redemptions_count").ilike("code",t).maybeSingle();if(i)throw new Error(i.message);if(!c)return{success:!1,error:"Coupon code not found.",errorKey:"ecommerce.coupon_not_found"};const r=c,d=new Date,s=M(r.starts_at),p=M(r.ends_at);if(!r.is_active)return{success:!1,error:"This coupon is not active.",errorKey:"ecommerce.coupon_inactive"};if(s&&s>d)return{success:!1,error:"This coupon is not active yet.",errorKey:"ecommerce.coupon_not_started"};if(p&&p<=d)return{success:!1,error:"This coupon has expired.",errorKey:"ecommerce.coupon_expired"};if(r.redemption_limit!==null&&(r.redemptions_count??0)>=r.redemption_limit)return{success:!1,error:"This coupon has reached its redemption limit.",errorKey:"ecommerce.coupon_limit_reached"};const[{lines:y},a]=await Promise.all([K({client:e.client,items:e.items,currencyCode:e.currencyCode}),T(e.client,r.id)]),v=a.size>0,_=y.filter(o=>o.subtotal>0&&D(r.provider_scope,o.provider)&&(!v||a.has(o.product_id)));if(_.length===0)return{success:!1,error:"This coupon does not apply to the items in your cart.",errorKey:"ecommerce.coupon_not_applicable"};const w=r.discount_type==="fixed"?k(_,r.discount_amount):null,m=S(),h=_.map(o=>{const l=r.discount_type==="percent"?Math.min(o.subtotal,Math.round(o.subtotal*r.discount_amount/100)):w?.get(o.key)??0;return m[o.provider]+=l,{key:o.key,product_id:o.product_id,variant_id:o.variant_id,provider:o.provider,title:o.title,quantity:o.quantity,subtotal:o.subtotal,discount:l}});return{success:!0,quote:{couponId:r.id,code:r.code,name:r.name,discountType:r.discount_type,discountAmount:r.discount_amount,providerScope:r.provider_scope,eligibleSubtotal:_.reduce((o,l)=>o+l.subtotal,0),discountTotal:m.stripe+m.freemius,providerDiscounts:m,lineDiscounts:h}}}function L(e){const t=new Map;for(const c of e?.lineDiscounts??[])t.set(c.key,c.discount);return t}async function z(e){const{error:t}=await e.client.from("coupon_redemptions").insert({coupon_id:e.quote.couponId,order_id:e.orderId,coupon_code:e.quote.code,provider:e.provider,discount_total:Math.max(0,e.discountTotal),user_id:e.userId||null,customer_email:e.customerEmail||null,metadata:e.metadata||{}});if(t){console.error("Failed to record coupon redemption:",t);return}const{data:c}=await e.client.from("coupons").select("redemptions_count").eq("id",e.quote.couponId).single();await e.client.from("coupons").update({redemptions_count:(c?.redemptions_count??0)+1,updated_at:new Date().toISOString()}).eq("id",e.quote.couponId)}exports.emptyProviderDiscounts=S;exports.getCartLineCouponKey=q;exports.getCouponQuote=I;exports.getQuoteLineDiscountMap=L;exports.normalizeCouponCode=P;exports.recordCouponRedemption=z;
@@ -1 +0,0 @@
1
- "use strict";const c=require("./states-CWYRxV4B.cjs"),a=()=>({company_name:"",recipient_name:"",line1:"",line2:"",city:"",state:"",postal_code:"",country_code:"CA"});function t(e){const n=e?.trim();return n||null}function o(e){if(!e)return null;const n={company_name:t(e.company_name),recipient_name:t(e.recipient_name),line1:t(e.line1),line2:t(e.line2),city:t(e.city),postal_code:t(e.postal_code),country_code:c.normalizeCountryCode(e.country_code)};return n.state=c.normalizeSubdivisionCode(n.country_code,t(e.state)),Object.values(n).some(Boolean)?n:null}function m(e){const n=o(e);return n?!!(n.recipient_name&&n.line1&&n.city&&n.postal_code&&n.country_code&&(!c.countryUsesStructuredStates(n.country_code)||n.state)):!1}function u(e){const n=o(e.billing),i=o(e.shipping),r=t(e.email)?.toLowerCase()??null,s=t(e.phone),l=t(e.name)??n?.recipient_name??i?.recipient_name??null;return{email:r,name:l,phone:s,billing:n,shipping:i}}function d(e,n){const i=o(e),r=o(n);return JSON.stringify(i)===JSON.stringify(r)}exports.addressesMatch=d;exports.emptyCustomerAddress=a;exports.isCustomerAddressComplete=m;exports.normalizeCustomerAddress=o;exports.normalizeOrderCustomerDetails=u;