@nextblock-cms/ecom 0.8.1 → 0.8.7

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 (241) hide show
  1. package/index.cjs.js +1 -1
  2. package/index.es.js +136 -3224
  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/lib/cart-store.es.js +116 -0
  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/lib/components/AddToCartButton.es.js +60 -0
  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/lib/components/CartDrawer.es.js +119 -0
  15. package/lib/components/CartIcon.cjs.js +1 -0
  16. package/lib/components/CartIcon.es.js +34 -0
  17. package/lib/components/Checkout.cjs.js +1 -0
  18. package/lib/components/Checkout.es.js +987 -0
  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/lib/components/CurrencySwitcher.es.js +18 -0
  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/lib/components/FeaturedProduct.es.js +72 -0
  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/SimpleTiptapRenderer.cjs.js +1 -0
  42. package/lib/components/SimpleTiptapRenderer.es.js +187 -0
  43. package/lib/components/SubscriptionSelector.cjs.js +1 -0
  44. package/lib/components/SubscriptionSelector.es.js +140 -0
  45. package/lib/countries.cjs.js +1 -0
  46. package/lib/countries.es.js +77 -0
  47. package/lib/coupon-server.cjs.js +1 -0
  48. package/lib/coupon-server.es.js +234 -0
  49. package/lib/coupons.cjs.js +1 -0
  50. package/lib/coupons.es.js +17 -0
  51. package/lib/currency-constants.cjs.js +1 -0
  52. package/lib/currency-constants.es.js +4 -0
  53. package/lib/currency-store.cjs.js +1 -0
  54. package/lib/currency-store.es.js +27 -0
  55. package/lib/currency-sync.cjs.js +1 -0
  56. package/lib/currency-sync.es.js +180 -0
  57. package/lib/currency.cjs.js +1 -0
  58. package/lib/currency.es.js +312 -0
  59. package/lib/customer-addresses.cjs.js +1 -0
  60. package/lib/customer-addresses.es.js +116 -0
  61. package/lib/customer-orders.cjs.js +1 -0
  62. package/lib/customer-orders.es.js +45 -0
  63. package/lib/customer.cjs.js +1 -0
  64. package/lib/customer.es.js +58 -0
  65. package/lib/export-helpers.cjs.js +1 -0
  66. package/lib/export-helpers.es.js +56 -0
  67. package/lib/factory.cjs.js +1 -0
  68. package/lib/factory.es.js +8 -0
  69. package/lib/freemius-coupons.cjs.js +1 -0
  70. package/lib/freemius-coupons.es.js +272 -0
  71. package/lib/freemius-order-sync.cjs.js +1 -0
  72. package/lib/freemius-order-sync.es.js +284 -0
  73. package/lib/inventory-settings.cjs.js +1 -0
  74. package/lib/inventory-settings.es.js +86 -0
  75. package/lib/invoice-server.cjs.js +33 -0
  76. package/lib/invoice-server.es.js +141 -0
  77. package/lib/invoice-ui.cjs.js +1 -0
  78. package/lib/invoice-ui.es.js +71 -0
  79. package/lib/invoice.cjs.js +1 -0
  80. package/lib/invoice.es.js +102 -0
  81. package/lib/order-inventory.cjs.js +61 -0
  82. package/lib/order-inventory.es.js +128 -0
  83. package/lib/order-tax-details.cjs.js +1 -0
  84. package/lib/order-tax-details.es.js +164 -0
  85. package/lib/pages/cms/coupons/CouponEditorForm.cjs.js +1 -0
  86. package/lib/pages/cms/coupons/CouponEditorForm.es.js +189 -0
  87. package/lib/pages/cms/coupons/CouponsPage.cjs.js +5 -0
  88. package/lib/pages/cms/coupons/CouponsPage.es.js +171 -0
  89. package/lib/pages/cms/coupons/CreateCouponDialog.cjs.js +1 -0
  90. package/lib/pages/cms/coupons/CreateCouponDialog.es.js +35 -0
  91. package/lib/pages/cms/coupons/EditCouponPage.cjs.js +1 -0
  92. package/lib/pages/cms/coupons/EditCouponPage.es.js +48 -0
  93. package/lib/pages/cms/coupons/ProductScopePicker.cjs.js +1 -0
  94. package/lib/pages/cms/coupons/ProductScopePicker.es.js +120 -0
  95. package/lib/pages/cms/coupons/actions.cjs.js +1 -0
  96. package/lib/pages/cms/coupons/actions.es.js +128 -0
  97. package/lib/pages/cms/coupons/product-options.cjs.js +1 -0
  98. package/lib/pages/cms/coupons/product-options.es.js +27 -0
  99. package/lib/pages/cms/orders/ExportReportsDialog.cjs.js +1 -0
  100. package/lib/pages/cms/orders/ExportReportsDialog.es.js +130 -0
  101. package/lib/pages/cms/orders/OrderDetailPage.cjs.js +1 -0
  102. package/lib/pages/cms/orders/OrderDetailPage.es.js +137 -0
  103. package/lib/pages/cms/orders/OrderPrintButton.cjs.js +1 -0
  104. package/lib/pages/cms/orders/OrderPrintButton.es.js +22 -0
  105. package/lib/pages/cms/orders/OrderStatusForm.cjs.js +1 -0
  106. package/lib/pages/cms/orders/OrderStatusForm.es.js +71 -0
  107. package/lib/pages/cms/orders/OrdersPage.cjs.js +1 -0
  108. package/lib/pages/cms/orders/OrdersPage.es.js +104 -0
  109. package/lib/pages/cms/orders/actions.cjs.js +7 -0
  110. package/lib/pages/cms/orders/actions.es.js +71 -0
  111. package/lib/pages/cms/orders/export-actions.cjs.js +1 -0
  112. package/lib/pages/cms/orders/export-actions.es.js +27 -0
  113. package/lib/pages/cms/orders/server-actions.cjs.js +1 -0
  114. package/lib/pages/cms/orders/server-actions.es.js +55 -0
  115. package/lib/pages/cms/payments/PaymentsClient.cjs.js +1 -0
  116. package/lib/pages/cms/payments/PaymentsClient.es.js +188 -0
  117. package/lib/pages/cms/payments/PaymentsPage.cjs.js +1 -0
  118. package/lib/pages/cms/payments/PaymentsPage.es.js +29 -0
  119. package/lib/pages/cms/payments/actions.cjs.js +1 -0
  120. package/lib/pages/cms/payments/actions.es.js +23 -0
  121. package/lib/pages/cms/payments/queries.cjs.js +1 -0
  122. package/lib/pages/cms/payments/queries.es.js +30 -0
  123. package/lib/pages/cms/products/ProductsPage.cjs.js +1 -0
  124. package/lib/pages/cms/products/ProductsPage.es.js +46 -0
  125. package/lib/pages/cms/products/_id_/edit/EditProductPage.cjs.js +1 -0
  126. package/lib/pages/cms/products/_id_/edit/EditProductPage.es.js +156 -0
  127. package/lib/pages/cms/products/actions.cjs.js +44 -0
  128. package/lib/pages/cms/products/actions.es.js +175 -0
  129. package/lib/pages/cms/products/attributes/AttributeManagementPage.cjs.js +1 -0
  130. package/lib/pages/cms/products/attributes/AttributeManagementPage.es.js +48 -0
  131. package/lib/pages/cms/products/attributes/components/AttributeManager.cjs.js +1 -0
  132. package/lib/pages/cms/products/attributes/components/AttributeManager.es.js +291 -0
  133. package/lib/pages/cms/products/categories/CategoryManagementPage.cjs.js +1 -0
  134. package/lib/pages/cms/products/categories/CategoryManagementPage.es.js +36 -0
  135. package/lib/pages/cms/products/categories/components/CategoryManager.cjs.js +1 -0
  136. package/lib/pages/cms/products/categories/components/CategoryManager.es.js +263 -0
  137. package/lib/pages/cms/products/components/CopyProductFromLanguage.cjs.js +1 -0
  138. package/lib/pages/cms/products/components/CopyProductFromLanguage.es.js +114 -0
  139. package/lib/pages/cms/products/components/CurrencyPriceFields.cjs.js +1 -0
  140. package/lib/pages/cms/products/components/CurrencyPriceFields.es.js +107 -0
  141. package/lib/pages/cms/products/components/DeleteProductButton.cjs.js +1 -0
  142. package/lib/pages/cms/products/components/DeleteProductButton.es.js +48 -0
  143. package/lib/pages/cms/products/components/FreemiusPricingDashboard.cjs.js +1 -0
  144. package/lib/pages/cms/products/components/FreemiusPricingDashboard.es.js +86 -0
  145. package/lib/pages/cms/products/components/ProductCategorySelector.cjs.js +1 -0
  146. package/lib/pages/cms/products/components/ProductCategorySelector.es.js +160 -0
  147. package/lib/pages/cms/products/components/ProductForm.cjs.js +1 -0
  148. package/lib/pages/cms/products/components/ProductForm.es.js +702 -0
  149. package/lib/pages/cms/products/components/ProductMediaManager.cjs.js +1 -0
  150. package/lib/pages/cms/products/components/ProductMediaManager.es.js +104 -0
  151. package/lib/pages/cms/products/components/ProductsBulkTable.cjs.js +1 -0
  152. package/lib/pages/cms/products/components/ProductsBulkTable.es.js +228 -0
  153. package/lib/pages/cms/products/components/SaleScheduleFields.cjs.js +1 -0
  154. package/lib/pages/cms/products/components/SaleScheduleFields.es.js +137 -0
  155. package/lib/pages/cms/products/components/SyncFreemiusButton.cjs.js +1 -0
  156. package/lib/pages/cms/products/components/SyncFreemiusButton.es.js +36 -0
  157. package/lib/pages/cms/products/components/SyncFreemiusPricingButton.cjs.js +1 -0
  158. package/lib/pages/cms/products/components/SyncFreemiusPricingButton.es.js +40 -0
  159. package/lib/pages/cms/products/components/VariationsEditor.cjs.js +1 -0
  160. package/lib/pages/cms/products/components/VariationsEditor.es.js +408 -0
  161. package/lib/pages/cms/products/inventory/InventoryPage.cjs.js +1 -0
  162. package/lib/pages/cms/products/inventory/InventoryPage.es.js +16 -0
  163. package/lib/pages/cms/products/inventory/InventoryTableClient.cjs.js +2 -0
  164. package/lib/pages/cms/products/inventory/InventoryTableClient.es.js +214 -0
  165. package/lib/pages/cms/products/inventory/actions.cjs.js +3 -0
  166. package/lib/pages/cms/products/inventory/actions.es.js +95 -0
  167. package/lib/pages/cms/products/new/NewProductPage.cjs.js +1 -0
  168. package/lib/pages/cms/products/new/NewProductPage.es.js +76 -0
  169. package/lib/pages/cms/products/product-price-sync.cjs.js +1 -0
  170. package/lib/pages/cms/products/product-price-sync.es.js +98 -0
  171. package/lib/pages/cms/products/server-actions.cjs.js +1 -0
  172. package/lib/pages/cms/products/server-actions.es.js +193 -0
  173. package/lib/pages/cms/shipping/ShippingPage.cjs.js +5 -0
  174. package/lib/pages/cms/shipping/ShippingPage.es.js +211 -0
  175. package/lib/pages/cms/shipping/components/RateForm.cjs.js +1 -0
  176. package/lib/pages/cms/shipping/components/RateForm.es.js +441 -0
  177. package/lib/pages/cms/shipping/components/ZoneForm.cjs.js +1 -0
  178. package/lib/pages/cms/shipping/components/ZoneForm.es.js +228 -0
  179. package/lib/pages/cms/shipping/server-actions.cjs.js +1 -0
  180. package/lib/pages/cms/shipping/server-actions.es.js +159 -0
  181. package/lib/pages/cms/taxes/TaxesPage.cjs.js +1 -0
  182. package/lib/pages/cms/taxes/TaxesPage.es.js +172 -0
  183. package/lib/pages/cms/taxes/actions.cjs.js +1 -0
  184. package/lib/pages/cms/taxes/actions.es.js +57 -0
  185. package/lib/pages/cms/taxes/components/TaxRateForm.cjs.js +1 -0
  186. package/lib/pages/cms/taxes/components/TaxRateForm.es.js +100 -0
  187. package/lib/product-actions.cjs.js +237 -0
  188. package/lib/product-actions.es.js +524 -0
  189. package/lib/product-context.cjs.js +1 -0
  190. package/lib/product-context.es.js +16 -0
  191. package/lib/product-schema.cjs.js +1 -0
  192. package/lib/product-schema.es.js +134 -0
  193. package/lib/providers/freemius.cjs.js +5 -0
  194. package/lib/providers/freemius.es.js +538 -0
  195. package/lib/providers/stripe.cjs.js +1 -0
  196. package/lib/providers/stripe.es.js +473 -0
  197. package/lib/server-actions/coupon-actions.cjs.js +1 -0
  198. package/lib/server-actions/coupon-actions.es.js +23 -0
  199. package/lib/server-actions/customer-actions.cjs.js +1 -0
  200. package/lib/server-actions/customer-actions.es.js +30 -0
  201. package/lib/server-actions/product-actions.cjs.js +1 -0
  202. package/lib/server-actions/product-actions.es.js +16 -0
  203. package/lib/server-actions/shipping-actions.cjs.js +1 -0
  204. package/lib/server-actions/shipping-actions.es.js +27 -0
  205. package/lib/server-actions/tax-actions.cjs.js +1 -0
  206. package/lib/server-actions/tax-actions.es.js +40 -0
  207. package/lib/shared-inventory.cjs.js +15 -0
  208. package/lib/shared-inventory.es.js +171 -0
  209. package/lib/shipping/resolver.cjs.js +7 -0
  210. package/lib/shipping/resolver.es.js +62 -0
  211. package/lib/shipping-rate-currency.cjs.js +1 -0
  212. package/lib/shipping-rate-currency.es.js +72 -0
  213. package/lib/states.cjs.js +1 -0
  214. package/lib/states.es.js +127 -0
  215. package/lib/stripe/checkout.cjs.js +1 -0
  216. package/lib/stripe/checkout.es.js +182 -0
  217. package/lib/stripe/client.cjs.js +1 -0
  218. package/lib/stripe/client.es.js +7 -0
  219. package/lib/stripe/order-sync.cjs.js +1 -0
  220. package/lib/stripe/order-sync.es.js +130 -0
  221. package/lib/stripe/webhooks.cjs.js +1 -0
  222. package/lib/stripe/webhooks.es.js +30 -0
  223. package/lib/tax-calculation.cjs.js +1 -0
  224. package/lib/tax-calculation.es.js +101 -0
  225. package/lib/trials.cjs.js +1 -0
  226. package/lib/trials.es.js +29 -0
  227. package/lib/types.cjs.js +1 -0
  228. package/lib/types.es.js +33 -0
  229. package/lib/use-cart.cjs.js +1 -0
  230. package/lib/use-cart.es.js +44 -0
  231. package/lib/variation-utils.cjs.js +1 -0
  232. package/lib/variation-utils.es.js +246 -0
  233. package/lib/zod-config.cjs.js +1 -0
  234. package/lib/zod-config.es.js +6 -0
  235. package/package.json +10 -5
  236. package/server.cjs.js +1 -110
  237. package/server.es.js +178 -6037
  238. package/invoice-ui-BJZfedDd.cjs +0 -332
  239. package/invoice-ui-GJ1ADAjn.js +0 -5759
  240. /package/{currency-rest-client-uolJxUkL.cjs → lib/currency-rest-client.cjs.js} +0 -0
  241. /package/{currency-rest-client-CwoqdgAP.js → lib/currency-rest-client.es.js} +0 -0
package/index.cjs.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),be=require("@nextblock-cms/ui/sheet"),ie=require("@nextblock-cms/ui/badge"),H=require("@nextblock-cms/ui/button"),We=require("next/navigation"),S=require("D:/Websites/nextblock-sandbox/node_modules/lucide-react/dist/esm/lucide-react.js"),ps=require("D:/Websites/nextblock-sandbox/node_modules/zustand/esm/index.mjs"),Ae=require("D:/Websites/nextblock-sandbox/node_modules/zustand/esm/middleware.mjs"),l=require("./invoice-ui-BJZfedDd.cjs"),u=require("react"),h=require("@nextblock-cms/utils"),U=require("@nextblock-cms/ui/input"),T=require("@nextblock-cms/ui/label"),Ie=require("@nextblock-cms/db/server"),X=require("@nextblock-cms/ui/table"),$=require("@nextblock-cms/ui/card"),hs=require("@nextblock-cms/ui/checkbox"),Qe=require("@nextblock-cms/ui/separator"),Be=require("@nextblock-cms/ui/radio-group"),Bs=require("D:/Websites/nextblock-sandbox/node_modules/@freemius/checkout/lib/module/checkout.js"),ae=require("@nextblock-cms/ui/select"),Ee=require("D:/Websites/nextblock-sandbox/node_modules/sonner/dist/index.mjs"),ge=require("next/link"),Us=require("react-hook-form"),Ue=require("@nextblock-cms/ui/avatar"),ns=require("next/cache"),ls=require("@nextblock-cms/db"),cs=require("@nextblock-cms/ui/Skeleton"),je=ps.create()(Ae.persist(s=>({activeCurrencyCode:null,hasHydrated:!1,setActiveCurrencyCode:a=>s({activeCurrencyCode:h.normalizeCurrencyCode(a)}),setHasHydrated:a=>s({hasHydrated:a})}),{name:"currency-preference-storage",storage:Ae.createJSONStorage(()=>localStorage),skipHydration:!0,partialize:s=>({activeCurrencyCode:s.activeCurrencyCode}),onRehydrateStorage:()=>s=>{s?.setHasHydrated(!0)}})),xs=u.createContext(null);function Ve(s){return l.sortCurrencies(s.filter(a=>a.is_active!==!1))}function Vs(s){const{currencies:a,storedCurrencyCode:t,hasHydrated:r,initialCurrencyCode:n,locale:c}=s,o=new Set(a.map(x=>h.normalizeCurrencyCode(x.code))),p=l.getDefaultCurrency(a),y=n?h.normalizeCurrencyCode(n):null,b=t?h.normalizeCurrencyCode(t):null;if(r&&b&&o.has(b))return b;if(y&&o.has(y))return y;const f=l.inferCurrencyCodeFromLocale(c,a);return o.has(f)?f:p.code}function Hs({children:s,initialCurrencies:a,initialCurrencyCode:t,locale:r}){const[n,c]=u.useState(()=>Ve(a)),o=je(j=>j.activeCurrencyCode),p=je(j=>j.hasHydrated),y=je(j=>j.setActiveCurrencyCode);u.useEffect(()=>{je.persist.rehydrate()},[]),u.useEffect(()=>{a.length>0&&c(Ve(a))},[a]),u.useEffect(()=>{if(a.length>0)return;async function j(){const{fetchActiveCurrenciesFromRest:d}=await Promise.resolve().then(()=>require("./currency-rest-client-uolJxUkL.cjs")),A=await d();A.length>0&&c(Ve(A.map(N=>l.normalizeCurrencyRecord(N))))}j()},[a.length]);const b=u.useMemo(()=>Vs({currencies:n,storedCurrencyCode:o,hasHydrated:p,initialCurrencyCode:t,locale:r}),[n,o,p,t,r]);u.useEffect(()=>{b&&o!==b&&y(b)},[b,y,o]),u.useEffect(()=>{!b||typeof document>"u"||(document.cookie=`${l.CURRENCY_COOKIE_NAME}=${b}; Path=/; Max-Age=31536000; SameSite=Lax`)},[b]);const f=u.useMemo(()=>l.getDefaultCurrency(n),[n]),x=u.useMemo(()=>n.find(j=>j.code===b)??f,[n,f,b]),g=u.useMemo(()=>({currencies:n,defaultCurrency:f,activeCurrency:x,activeCurrencyCode:x.code,isHydrated:p,setActiveCurrencyCode:j=>{const d=h.normalizeCurrencyCode(j);n.some(N=>N.code===d)&&y(d)}}),[x,n,f,p,y]);return e.jsx(xs.Provider,{value:g,children:s})}function ne(){const s=u.useContext(xs);if(!s)throw new Error("useCurrency must be used inside a CurrencyProvider");return s}function He(s,a,t){return s.reduce((r,n)=>l.isDigitalItem(n)||n.sku!==a||t&&n.id===t?r:r+n.quantity,0)}const _e=ps.create()(Ae.persist((s,a)=>({items:[],appliedCoupon:null,isOpen:!1,addItem:t=>{const{items:r}=a(),n=t.quantity??1,c=typeof t.stock=="number"?t.stock:null,o=c!==null?He(r,t.sku):0;if(l.isDigitalItem(t))return r.find(b=>b.product_id===t.product_id&&l.isDigitalItem(b))?{success:!1,error:"This software license is already in your cart."}:(s({items:[...r,{...t,quantity:1}],isOpen:!0}),{success:!0});const p=r.find(y=>y.id===t.id);return c!==null&&c<=0?{success:!1,error:"This item is out of stock."}:c!==null&&o+n>c?{success:!1,error:`Only ${c} available for this SKU.`}:(s(p?{items:r.map(y=>y.id===t.id?{...y,...t,quantity:y.quantity+n}:y),isOpen:!0}:{items:[...r,{...t,quantity:n}],isOpen:!0}),{success:!0})},removeItem:t=>{const{items:r}=a();s({items:r.filter(n=>n.id!==t)})},updateQuantity:(t,r)=>{const{items:n}=a(),c=n.find(o=>o.id===t);c&&l.isDigitalItem(c)||(c&&typeof c.stock=="number"&&r+He(n,c.sku,t)>c.stock&&(r=Math.max(c.stock-He(n,c.sku,t),0)),r<=0?s({items:n.filter(o=>o.id!==t)}):s({items:n.map(o=>o.id===t?{...o,quantity:r}:o)}))},setAppliedCoupon:t=>{const r=a().appliedCoupon;r?.code===t?.code&&r?.couponId===t?.couponId||s({appliedCoupon:t})},removeCoupon:()=>{a().appliedCoupon&&s({appliedCoupon:null})},clearCart:()=>s({items:[],appliedCoupon:null}),toggleCart:()=>s(t=>({isOpen:!t.isOpen})),setIsOpen:t=>s({isOpen:t}),setItems:t=>s({items:t})}),{name:"cart-storage",storage:Ae.createJSONStorage(()=>localStorage),skipHydration:!0})),fs=()=>_e(a=>a.items).reduce((a,t)=>a+t.quantity,0);function me(s,a){return l.resolveEffectivePriceForCurrency({prices:s.prices,salePrices:s.sale_prices,fallbackPrice:s.price,fallbackSalePrice:s.sale_price,saleStartAt:s.sale_start_at,saleEndAt:s.sale_end_at,scheduledPrice:s.scheduled_price,scheduledPrices:s.scheduled_prices,scheduledPriceAt:s.scheduled_price_at,currencyCode:a.currencyCode,currencies:a.currencies})}const Xe=()=>{const s=_e(r=>r.items),{activeCurrencyCode:a,currencies:t}=ne();return s.reduce((r,n)=>{const{price:c,sale_price:o}=me(n,{currencyCode:a,currencies:t});return r+(o??c)*n.quantity},0)};let Se=null;function Le(){return _e.persist}function Je(){return Le()?.hasHydrated?.()??!1}function gs(){if(typeof window>"u")return Promise.resolve();const s=Le();return!s||s.hasHydrated()?Promise.resolve():(Se||(Se=Promise.resolve().then(()=>s.rehydrate()).finally(()=>{Se=null})),Se)}const oe=s=>{const a=_e(s),[t,r]=u.useState(!1);return u.useEffect(()=>{const n=Le();if(Je()){r(!0);return}const c=n?.onFinishHydration(()=>r(!0));return gs(),()=>{c?.()}},[]),t?a:void 0},Ks=()=>{const[s,a]=u.useState(!1);return u.useEffect(()=>{const r=Le()?.onFinishHydration(()=>a(!0));return a(Je()),Je()||gs(),()=>{r?.()}},[]),s};function Fe(s){const a=Number(s?.trial_period_days??0);return!Number.isFinite(a)||a<=0?0:Math.round(a)}function _s(s){return Fe(s)===0?null:s?.trial_requires_payment_method?"paid":"free"}function ys(s){const a=Fe(typeof s=="number"?{trial_period_days:s}:s);return a>0?`${a}-day free trial`:null}function bs(s){return s?.trial_requires_payment_method?"Payment method required":"No credit card required"}function ue(s){const a=ys(s);return a?{label:a,paymentRequirementLabel:bs(s),checkoutMode:_s(s)}:null}async function Gs(s){try{const a=Ie.getServiceRoleSupabaseClient();return await l.getCouponQuote({client:a,code:s.code,items:Array.isArray(s.items)?s.items:[],currencyCode:s.currencyCode})}catch(a){return console.error("Failed to validate coupon:",a),{success:!1,error:a.message||"Failed to validate coupon.",errorKey:"ecommerce.coupon_validation_failed"}}}function Re({items:s,currencyCode:a,onQuoteChange:t,compact:r=!1}){const n=oe(i=>i.appliedCoupon),c=oe(i=>i.setAppliedCoupon),o=oe(i=>i.removeCoupon),{t:p}=h.useTranslations(),[y,b]=u.useState(""),[f,x]=u.useState(null),[g,j]=u.useState(""),[d,A]=u.useState(!1),N=u.useRef(null),I=u.useMemo(()=>s.map(i=>`${i.product_id}:${i.variant_id||"base"}:${i.quantity}`).sort().join("|"),[s]),O=u.useCallback((i,L)=>{const D=p(i);return D===i?L:D},[p]),F=u.useCallback(i=>`${l.normalizeCouponCode(i)}:${a}:${I}`,[I,a]),R=u.useCallback(async(i,L)=>{const D=l.normalizeCouponCode(i);if(!D){j(O("ecommerce.coupon_code_required","Enter a coupon code."));return}A(!0),j("");try{const P=await Gs({code:D,items:s,currencyCode:a});if(!P.success){x(null),t?.(null),o?.(),j(P.errorKey?O(P.errorKey,P.error):P.error);return}N.current=F(P.quote.code),x(P.quote),t?.(P.quote),L?.silent||(c?.({code:P.quote.code,couponId:P.quote.couponId}),b("")),L?.silent||j("")}catch(P){console.error("Failed to validate coupon:",P),x(null),t?.(null),j(O("ecommerce.coupon_validation_failed","Failed to validate coupon."))}finally{A(!1)}},[o,a,F,s,t,c,O]);if(u.useEffect(()=>{if(!c||!o)return;if(!n||s.length===0){N.current=null,x(null),t?.(null);return}const i=F(n.code);N.current!==i&&(N.current=i,R(n.code,{silent:!0}))},[n?.code,R,o,F,s.length,t,c]),!c||!o)return null;const k=()=>{o(),x(null),t?.(null),j("")};return e.jsxs("div",{className:r?"space-y-2":"rounded-lg border bg-muted/10 p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs(T.Label,{htmlFor:r?"coupon-code-compact":"coupon-code",className:"flex items-center gap-2 text-sm font-medium",children:[e.jsx(S.Tag,{className:"h-4 w-4"}),O("ecommerce.coupon","Coupon")]}),f?e.jsxs(ie.Badge,{variant:"secondary",className:"gap-1",children:[f.code,e.jsx("button",{type:"button",onClick:k,"aria-label":`Remove coupon ${f.code}`,children:e.jsx(S.X,{className:"h-3 w-3"})})]}):null]}),f?e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:f.name}),e.jsxs("span",{className:"font-medium text-emerald-600",children:["-",h.formatPrice(f.discountTotal,a)]})]}):e.jsxs("div",{className:"flex gap-2",children:[e.jsx(U.Input,{id:r?"coupon-code-compact":"coupon-code",value:y,onChange:i=>b(i.target.value.toUpperCase()),placeholder:O("ecommerce.coupon_placeholder","Code"),className:"uppercase",onKeyDown:i=>{i.key==="Enter"&&(i.preventDefault(),R(y))}}),e.jsx(H.Button,{type:"button",variant:"outline",disabled:d||s.length===0,onClick:()=>{R(y)},children:d?O("ecommerce.applying","Applying..."):O("ecommerce.apply","Apply")})]}),g?e.jsx("p",{className:"text-xs text-destructive",children:g}):null]})}const Js=()=>{const s=We.useRouter(),a=oe(d=>d),t=Xe(),{t:r}=h.useTranslations(),{activeCurrencyCode:n,currencies:c}=ne();if(!a)return null;const{isOpen:o,setIsOpen:p,items:y,updateQuantity:b,removeItem:f}=a,x=d=>y.reduce((A,N)=>l.isDigitalItem(N)||N.sku!==d?A:A+N.quantity,0),g=()=>{p(!1),s.push("/cart")},j=()=>{p(!1),s.push("/checkout")};return e.jsx(be.Sheet,{open:o,onOpenChange:p,children:e.jsxs(be.SheetContent,{className:"flex w-full flex-col pr-0 sm:max-w-lg",children:[e.jsxs(be.SheetHeader,{className:"px-1 text-left",children:[e.jsxs(be.SheetTitle,{children:[r("ecommerce.shopping_cart")," (",y.length,")"]}),e.jsx(be.SheetDescription,{className:"sr-only",children:r("ecommerce.shopping_cart")})]}),y.length>0?e.jsx("div",{className:"flex flex-1 flex-col gap-5 overflow-y-auto p-1 pr-6 pt-4",children:y.map(d=>{const A=x(d.sku);return e.jsx("div",{className:"flex gap-4",children:(()=>{const N=me(d,{currencyCode:n,currencies:c}),I=ue(d);return e.jsxs(e.Fragment,{children:[d.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:d.image_url,alt:d.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:r("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:d.title}),d.variant_label&&e.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:d.variant_label}),I&&e.jsxs("div",{className:"mt-1 text-xs font-medium text-emerald-700",children:[I.label," - ",I.paymentRequirementLabel]})]}),e.jsxs("span",{className:"text-sm font-semibold",children:[N.sale_price&&e.jsx("span",{className:"mr-1.5 text-xs font-normal text-muted-foreground line-through",children:h.formatPrice(N.price,n)}),h.formatPrice(N.sale_price??N.price,n)]})]}),e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[l.isDigitalItem(d)?e.jsx(ie.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:()=>b(d.id,d.quantity-1),className:"flex h-7 w-7 items-center justify-center border-r",type:"button",children:e.jsx(S.Minus,{className:"h-3 w-3"})}),e.jsx("span",{className:"flex h-7 w-8 items-center justify-center",children:d.quantity}),e.jsx("button",{onClick:()=>b(d.id,d.quantity+1),className:"flex h-7 w-7 items-center justify-center border-l",type:"button",disabled:typeof d.stock=="number"&&A>=d.stock,children:e.jsx(S.Plus,{className:"h-3 w-3"})})]}),e.jsx("button",{onClick:()=>f(d.id),className:"text-muted-foreground hover:text-destructive",type:"button",children:e.jsx(S.Trash2,{className:"h-4 w-4"})})]})]})]})})()},d.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:r("ecommerce.cart_empty")}),e.jsx(H.Button,{variant:"outline",onClick:()=>p(!1),children:r("ecommerce.continue_shopping")})]}),y.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:r("ecommerce.subtotal")}),e.jsx("span",{children:h.formatPrice(t,n)})]}),e.jsx("p",{className:"mb-4 mt-1 text-xs text-muted-foreground",children:r("ecommerce.shipping_taxes_calculated")}),e.jsx("div",{className:"mb-4",children:e.jsx(Re,{items:y,currencyCode:n,compact:!0})}),e.jsx(H.Button,{variant:"outline",className:"w-full mb-3",onClick:g,children:r("ecommerce.view_full_cart")}),e.jsx(H.Button,{className:"w-full",onClick:j,children:r("ecommerce.ready_to_checkout")})]})]})})};async function js(s,a,t,r){try{const n=l.normalizeCountryCode(a.country);return n?{success:!0,methods:await l.resolveShippingOptions(s,{...a,country:n,state:l.normalizeSubdivisionCode(n,a.state)||void 0},t,r)}:{success:!1,error:"Country is required for shipping calculation",errorKey:"ecommerce.shipping_country_required"}}catch(n){return console.error("Failed to resolve shipping options:",n),{success:!1,error:n.message||"Failed to calculate shipping",errorKey:"ecommerce.shipping_calculation_failed"}}}const Ws=({physicalSubtotal:s})=>{const[a,t]=u.useState("CA"),[r,n]=u.useState(""),[c,o]=u.useState(""),[p,y]=u.useState(!1),[b,f]=u.useState(null),[x,g]=u.useState(null),{t:j,lang:d}=h.useTranslations(),{activeCurrencyCode:A}=ne(),N=(i,L)=>{const D=j(i);return D===i?L:D},I=l.getStatesForCountry(a),O=l.countryUsesStructuredStates(a),F=N("select_an_option","Select an option"),R=N("state_province","State / Province"),k=async()=>{y(!0),g(null),f(null);const i=await js(s,{country:a,state:r||void 0,postal_code:c},d,A);i.success&&i.methods?f(i.methods):g(i.errorKey?N(i.errorKey,i.error||j("ecommerce.no_rates_found")):i.error||j("ecommerce.no_rates_found")),y(!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(S.Truck,{className:"h-4 w-4"}),e.jsx("span",{children:j("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:j("ecommerce.country")}),e.jsx("select",{id:"estimate-country",value:a,onChange:i=>{const L=i.target.value,D=l.getStatesForCountry(L);t(L),n(D.some(P=>P.code===r)?r:"")},className:"flex h-9 w-full rounded-md border border-input bg-background px-3 py-2 text-sm",children:l.countries.map(i=>e.jsx("option",{value:i.code,children:i.name},i.code))})]}),O&&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:j("state_province")}),e.jsxs("select",{id:"estimate-state",value:r,onChange:i=>n(i.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}: ${R}`}),I.map(i=>e.jsx("option",{value:i.code,children:i.name},i.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:j("ecommerce.postal_code")}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(U.Input,{id:"estimate-postal",placeholder:"A1A 1A1",value:c,onChange:i=>o(i.target.value),className:"h-9 text-sm bg-background"}),e.jsxs(H.Button,{size:"sm",variant:"secondary",onClick:k,disabled:p,className:"shrink-0",children:[p?e.jsx(S.Loader2,{className:"h-4 w-4 animate-spin"}):e.jsx(S.Calculator,{className:"h-4 w-4 mr-1.5"}),j("ecommerce.calculate")]})]})]})]}),x&&e.jsx("p",{className:"text-xs text-destructive mt-2",children:x}),b&&b.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:[j("ecommerce.available_rates"),":"]}),b.map(i=>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(S.Truck,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"text-sm font-medium",children:i.name})]}),e.jsx("span",{className:"text-sm font-bold",children:i.amount===0?j("ecommerce.free"):h.formatPrice(i.amount,A)})]},i.id))]}),b&&b.length===0&&!x&&e.jsx("p",{className:"text-xs text-muted-foreground mt-2 italic",children:j("ecommerce.no_rates_found")})]})},Qs=()=>{const s=We.useRouter(),a=oe(g=>g),t=Xe(),{t:r}=h.useTranslations(),{activeCurrencyCode:n,currencies:c}=ne(),o=a?.items??[],p=u.useMemo(()=>o.reduce((g,j)=>{if(l.isDigitalItem(j))return g;const d=me(j,{currencyCode:n,currencies:c});return g+(d.sale_price??d.price)*j.quantity},0),[n,c,o]);if(!a)return null;const{updateQuantity:y,removeItem:b}=a,f=g=>o.reduce((j,d)=>l.isDigitalItem(d)||d.sku!==g?j:j+d.quantity,0),x=()=>{s.push("/checkout")};return o.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:r("ecommerce.cart_empty")}),e.jsx("p",{className:"text-muted-foreground",children:r("ecommerce.cart_empty_description")}),e.jsx(H.Button,{asChild:!0,children:e.jsx("a",{href:"/shop",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(X.Table,{children:[e.jsx(X.TableHeader,{children:e.jsxs(X.TableRow,{children:[e.jsx(X.TableHead,{children:r("ecommerce.product")}),e.jsx(X.TableHead,{children:r("ecommerce.quantity")}),e.jsx(X.TableHead,{className:"text-right",children:r("ecommerce.price")}),e.jsx(X.TableHead,{className:"text-right",children:r("ecommerce.total")}),e.jsx(X.TableHead,{className:"w-[50px]"})]})}),e.jsx(X.TableBody,{children:o.map(g=>{const j=f(g.sku),d=me(g,{currencyCode:n,currencies:c}),A=ue(g);return e.jsxs(X.TableRow,{children:[e.jsx(X.TableCell,{children:e.jsxs("div",{className:"flex items-center gap-4",children:[g.image_url?e.jsx("div",{className:"h-16 w-16 overflow-hidden rounded border bg-neutral-100",children:e.jsx("img",{src:g.image_url,alt:g.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",{children:[e.jsx("div",{className:"font-medium",children:g.title}),g.variant_label&&e.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:g.variant_label}),l.isDigitalItem(g)&&g.billing_cycle&&e.jsxs("div",{className:"mt-1 text-xs capitalize text-muted-foreground",children:[g.billing_cycle," Subscription"]}),A&&e.jsxs("div",{className:"mt-1 text-xs font-medium text-emerald-700",children:[A.label," - ",A.paymentRequirementLabel]})]})]})}),e.jsx(X.TableCell,{children:l.isDigitalItem(g)?e.jsx(ie.Badge,{variant:"secondary",className:"font-normal text-xs",children:"1 (License)"}):e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(H.Button,{variant:"outline",size:"icon",className:"h-8 w-8",onClick:()=>y(g.id,g.quantity-1),children:e.jsx(S.Minus,{className:"h-4 w-4"})}),e.jsx("span",{className:"w-8 text-center",children:g.quantity}),e.jsx(H.Button,{variant:"outline",size:"icon",className:"h-8 w-8",onClick:()=>y(g.id,g.quantity+1),disabled:typeof g.stock=="number"&&j>=g.stock,children:e.jsx(S.Plus,{className:"h-4 w-4"})})]})}),e.jsx(X.TableCell,{className:"text-right",children:e.jsxs("div",{className:"flex flex-col items-end",children:[e.jsx("span",{className:"font-medium",children:h.formatPrice(d.sale_price??d.price,n)}),d.sale_price&&e.jsx("span",{className:"text-xs text-muted-foreground line-through",children:h.formatPrice(d.price,n)})]})}),e.jsx(X.TableCell,{className:"text-right font-medium",children:h.formatPrice((d.sale_price??d.price)*g.quantity,n)}),e.jsx(X.TableCell,{children:e.jsx(H.Button,{variant:"ghost",size:"icon",onClick:()=>b(g.id),className:"text-muted-foreground hover:text-destructive",children:e.jsx(S.Trash2,{className:"h-4 w-4"})})})]},g.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",children:h.formatPrice(t,n)})]}),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")}),o.some(g=>!l.isDigitalItem(g))&&e.jsx(Ws,{physicalSubtotal:p}),e.jsx(Re,{items:o,currencyCode:n,compact:!0}),e.jsx(H.Button,{className:"w-full mt-4",size:"lg",onClick:x,children:r("ecommerce.proceed_to_checkout")})]})]})})]})]})};async function Xs(s,a,t="USD",r,n){try{const c=Ie.createClient(),o=Ie.getServiceRoleSupabaseClient(),{data:p}=await c.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}),y=p??[];let b;if(r){const g=await l.getCouponQuote({client:o,code:r,items:n&&n.length>0?n:s,currencyCode:t});g.success&&(b=l.getQuoteLineDiscountMap(g.quote))}const f=await l.buildCheckoutTaxableItemsFromCart(c,s,t,y,b);return{success:!0,tax:await l.calculateCheckoutTaxes(c,{items:f,destination:a})}}catch(c){return console.error("Failed to estimate taxes:",c),{success:!1,error:c.message||"Failed to calculate taxes"}}}const Ys=process.env.NEXT_PUBLIC_IS_SANDBOX==="true",ke="nextblock-checkout-draft-v1";function Pe(s,a){return{...l.emptyCustomerAddress(),company_name:s?.company_name||"",recipient_name:s?.recipient_name||a||"",line1:s?.line1||"",line2:s?.line2||"",city:s?.city||"",state:s?.state||"",postal_code:s?.postal_code||"",country_code:l.normalizeCountryCode(s?.country_code)||"CA"}}function Zs(s){const a=l.normalizeCustomerAddress(s);return!(!a?.country_code||!a.postal_code||l.countryUsesStructuredStates(a.country_code)&&!a.state)}function Ke(s,a,t){return s.reduce((r,n)=>{const{price:c,sale_price:o}=me(n,{currencyCode:a,currencies:t});return r+(o??c)*n.quantity},0)}function is({idPrefix:s,title:a,description:t,value:r,onChange:n}){const{t:c}=h.useTranslations(),o=c("company_name")==="company_name"?"Company name":c("company_name"),p=c("select_an_option")==="select_an_option"?"Select an option":c("select_an_option"),y=c("state_province")==="state_province"?"State / Province":c("state_province"),b=l.getStatesForCountry(r.country_code),f=l.countryUsesStructuredStates(r.country_code);return e.jsxs($.Card,{children:[e.jsxs($.CardHeader,{children:[e.jsxs($.CardTitle,{className:"flex items-center gap-2",children:[e.jsx(S.MapPin,{className:"w-5 h-5"}),a]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t})]}),e.jsxs($.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(T.Label,{htmlFor:`${s}-company`,children:o}),e.jsx(U.Input,{id:`${s}-company`,value:r.company_name,onChange:x=>n({...r,company_name:x.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T.Label,{htmlFor:`${s}-name`,children:c("full_name")}),e.jsx(U.Input,{id:`${s}-name`,value:r.recipient_name,onChange:x=>n({...r,recipient_name:x.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T.Label,{htmlFor:`${s}-country`,children:c("country")}),e.jsx("select",{id:`${s}-country`,className:"flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm",value:r.country_code,onChange:x=>{const g=x.target.value,j=l.getStatesForCountry(g);n({...r,country_code:g,state:j.some(d=>d.code===r.state)?r.state:""})},children:l.countries.map(x=>e.jsx("option",{value:x.code,children:x.name},x.code))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T.Label,{htmlFor:`${s}-line1`,children:c("address_line_1")}),e.jsx(U.Input,{id:`${s}-line1`,value:r.line1,onChange:x=>n({...r,line1:x.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T.Label,{htmlFor:`${s}-line2`,children:c("address_line_2")}),e.jsx(U.Input,{id:`${s}-line2`,value:r.line2,onChange:x=>n({...r,line2:x.target.value})})]}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(T.Label,{htmlFor:`${s}-city`,children:c("city")}),e.jsx(U.Input,{id:`${s}-city`,value:r.city,onChange:x=>n({...r,city:x.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T.Label,{htmlFor:`${s}-state`,children:c("state_province")}),f?e.jsxs("select",{id:`${s}-state`,className:"flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm",value:r.state,onChange:x=>n({...r,state:x.target.value}),children:[e.jsx("option",{value:"",children:`${p}: ${y}`}),b.map(x=>e.jsx("option",{value:x.code,children:x.name},x.code))]}):e.jsx(U.Input,{id:`${s}-state`,value:r.state,onChange:x=>n({...r,state:x.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T.Label,{htmlFor:`${s}-postal`,children:c("postal_zip_code")}),e.jsx(U.Input,{id:`${s}-postal`,value:r.postal_code,onChange:x=>n({...r,postal_code:x.target.value})})]})]})]})]})}function os({title:s,description:a,badgeLabel:t,children:r}){return e.jsxs($.Card,{children:[e.jsx($.CardHeader,{children:e.jsxs("div",{className:"flex items-center justify-between gap-3 flex-wrap",children:[e.jsxs("div",{children:[e.jsx($.CardTitle,{children:s}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:a})]}),t?e.jsx(ie.Badge,{variant:"secondary",children:t}):null]})}),e.jsx($.CardContent,{className:"space-y-4",children:r})]})}const et=({initialCustomer:s})=>{const[a,t]=u.useState({}),[r,n]=u.useState(null),[c,o]=u.useState({}),[p,y]=u.useState(s?.email||""),[b,f]=u.useState(""),[x,g]=u.useState(s?.phone||""),[j,d]=u.useState(!1),[A,N]=u.useState(null),[I,O]=u.useState(!1),[F,R]=u.useState(!1),[k,i]=u.useState([]),[L,D]=u.useState(null),[P,W]=u.useState(null),[w,Y]=u.useState(null),[V,K]=u.useState(()=>Pe(s?.billingAddress,s?.fullName)),[Q,pe]=u.useState(()=>Pe(s?.shippingAddress??s?.billingAddress,s?.fullName)),[J,ve]=u.useState(!s?.shippingAddress||l.addressesMatch(s?.billingAddress,s?.shippingAddress)),he=oe(m=>m),{t:_,lang:Z}=h.useTranslations(),{activeCurrencyCode:v,currencies:le}=ne(),ee=he?.items??[],se=u.useMemo(()=>ee.filter(m=>!l.isDigitalItem(m)),[ee]),te=u.useMemo(()=>ee.filter(m=>l.isDigitalItem(m)),[ee]),xe=s?.isAuthenticated??!1,C=(m,E,z)=>{const M=_(m,z);if(M!==m)return M;if(!z)return E;let G=E;return Object.entries(z).forEach(([B,q])=>{G=G.replace(new RegExp(`\\{${B}\\}`,"g"),String(q))}),G},re=se.length>0,Ts=u.useMemo(()=>Ke(ee,v,le),[v,le,ee]),qe=u.useMemo(()=>Ke(se,v,le),[v,le,se]),Oe=u.useMemo(()=>Ke(te,v,le),[v,le,te]),Me=w?.providerDiscounts.stripe??0,De=w?.providerDiscounts.freemius??0,Ne=Math.max(0,qe-Me),As=Math.max(0,Oe-De),ce=u.useMemo(()=>J?V:Q,[V,Q,J]),fe=u.useMemo(()=>re?ce:V,[V,re,ce]),Ce=!re||Zs(ce),we=u.useMemo(()=>k.find(m=>m.id===L),[k,L]),Ze=u.useMemo(()=>Ne+(we?.amount??0)+(P&&!P.isPendingExternalCalculation?P.amount:0),[Ne,we,P]),Is=Ze+As;if(u.useEffect(()=>{if(!(xe||typeof window>"u"))try{const m=window.localStorage.getItem(ke);if(!m)return;const E=JSON.parse(m);E.email&&y(E.email),E.phone&&g(E.phone),E.billingAddress&&K(Pe(E.billingAddress)),E.shippingAddress&&pe(Pe(E.shippingAddress)),typeof E.useBillingForShipping=="boolean"&&ve(E.useBillingForShipping),(typeof E.selectedMethodId=="string"||E.selectedMethodId===null)&&D(E.selectedMethodId)}catch(m){console.error("[Checkout] Failed to restore checkout draft:",m)}},[xe]),u.useEffect(()=>{if(!(typeof window>"u")){if(xe){window.localStorage.removeItem(ke);return}window.localStorage.setItem(ke,JSON.stringify({email:p,phone:x,billingAddress:V,shippingAddress:Q,useBillingForShipping:J,selectedMethodId:L}))}},[V,p,xe,x,L,Q,J]),u.useEffect(()=>{if(!re){i([]),D(null),O(!1);return}if(!Ce){i([]),D(null),O(!1);return}let m=!1;const z=setTimeout(async()=>{if(!ce.country_code)return;O(!0);const M=await js(Ne,{country:ce.country_code,state:ce.state,postal_code:ce.postal_code},Z,v);m||(M.success&&M.methods?(i(M.methods),M.methods.length>0&&(!L||!M.methods.find(G=>G.id===L))&&D(M.methods[0].id)):(i([]),D(null)),O(!1))},400);return()=>{m=!0,clearTimeout(z)}},[v,re,Ce,Z,L,ce.country_code,ce.postal_code,ce.state,Ne]),u.useEffect(()=>{const E=setTimeout(async()=>{if(!re||!fe.country_code){R(!1),W(null);return}if(l.countryUsesStructuredStates(fe.country_code)&&!fe.state){R(!1),W(null);return}R(!0);const z=await Xs(se,{country_code:fe.country_code,state:fe.state},v,w?.code??null,ee);z.success&&z.tax?W(z.tax):W(null),R(!1)},300);return()=>clearTimeout(E)},[v,re,se,fe.country_code,fe.state,w?.code,ee]),!he)return null;const es=()=>{d(!1),N(null)},ss=j?e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",onClick:es,children:e.jsxs("div",{className:"relative bg-background border rounded-xl shadow-2xl p-8 max-w-md mx-4",onClick:m=>m.stopPropagation(),children:[e.jsx("button",{onClick:es,className:"absolute top-4 right-4 text-muted-foreground hover:text-foreground transition-colors",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",{className:"text-xl font-semibold",children:_("ecommerce.checkout_successful")})]}),e.jsx("p",{className:"text-muted-foreground mb-2",children:_("ecommerce.sandbox_notice")}),e.jsx("p",{className:"text-muted-foreground mb-2",children:A==="stripe"?C("ecommerce.sandbox_checkout_stripe_description","This simulated step represents the Stripe checkout for physical products."):C("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:_("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:_("ecommerce.purchase_at")})]})}):null,Es=m=>{if(!xe&&(!p||!/^\S+@\S+\.\S+$/.test(p)))return f(_("ecommerce.invalid_email")),null;const E=l.normalizeCustomerAddress(V);if(!l.isCustomerAddressComplete(E))return alert(_("checkout_complete_billing_address")),null;const z=re?l.normalizeCustomerAddress(J?V:Q):null;if(m==="stripe"){if(!l.isCustomerAddressComplete(z))return alert(_("checkout_complete_shipping_address")),null;if(!L)return alert(C("ecommerce.shipping_method_required","Please select a shipping method before continuing.")),null}return f(""),{normalizedBillingAddress:E,normalizedShippingAddress:z}},ts=async(m,E,z)=>{o(G=>({...G,[m]:""}));const M=Es(m);if(M){if(Ys){const G=new Set(E.map(q=>q.id)),B=ee.filter(q=>!G.has(q.id));he.setItems(B),B.length===0&&he.removeCoupon(),N(m),d(!0),typeof window<"u"&&B.length===0&&window.localStorage.removeItem(ke);return}n(z);try{const G=await fetch("/api/checkout",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({items:E,customerEmail:xe?void 0:p,customerPhone:x||null,billingAddress:M.normalizedBillingAddress,shippingAddress:m==="stripe"?M.normalizedShippingAddress:null,shippingMethodId:m==="stripe"?L:null,locale:Z,currencyCode:v,couponCode:w?.code??he.appliedCoupon?.code??null,couponContextItems:ee})}),B=await G.json();if(!G.ok){const q=B?.errorKey&&typeof B.errorKey=="string"?C(B.errorKey,B?.error||C("ecommerce.generic_error","Something went wrong."),B.errorParams):B?.error||_("ecommerce.generic_error");o(ye=>({...ye,[m]:q})),n(null);return}if(B.customProps&&B.customProps.provider==="freemius"){const q=B.customProps;let ye=null;const Os=()=>{window.location.href=`/checkout/success?session_id=${q.order_id}`},rs=de=>(ye||(ye=fetch("/api/checkout/freemius/sync",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({orderId:q.order_id,checkoutResponse:de})}).then(async as=>{if(!as.ok){const zs=await as.json().catch(()=>null);console.error("Freemius checkout sync failed:",zs)}})),ye),Ms={product_id:q.plugin_id,public_key:q.public_key,sandbox:q.sandbox},Ds={name:_("ecommerce.checkout_overlay_title"),plan_id:q.plan_id,...q.billing_cycle?{billing_cycle:q.billing_cycle}:{},...q.trial?{trial:q.trial}:{},...q.coupon?{coupon:q.coupon}:{},user_email:q.user_email,user_firstname:q.user_firstname,user_lastname:q.user_lastname,sandbox:q.sandbox,purchaseCompleted:function(de){rs(de)},success:function(de){(async()=>{try{await rs(de)}finally{Os()}})()}};try{new Bs.Checkout(Ms).open(Ds),n(null)}catch(de){alert(_("ecommerce.checkout_popup_blocked")+" "+(de.message||String(de))),B.url&&(window.location.href=B.url),n(null)}}else B.url?window.location.href=B.url:(o(q=>({...q,[m]:_("ecommerce.checkout_failed")+(B.error||C("ecommerce.unknown_error","Unknown error"))})),n(null))}catch(G){console.error(G),o(B=>({...B,[m]:_("ecommerce.generic_error")})),n(null)}}};if(ee.length===0)return e.jsxs(e.Fragment,{children:[ss,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:_("ecommerce.cart_empty")}),e.jsx("p",{className:"mb-8 text-muted-foreground",children:_("ecommerce.cart_empty_description")}),e.jsx(H.Button,{asChild:!0,children:e.jsx("a",{href:"/shop",children:_("ecommerce.go_to_shop")})})]})]});const ze=re?Ce?I?C("ecommerce.calculating_shipping","Calculating shipping..."):L?null:k.length>0?_("ecommerce.select_rate"):_("ecommerce.no_rates_for_region"):C("ecommerce.waiting_on_address_info","Complete your shipping address to view available shipping options."):null,Fs=r!==null||ze!==null,Ls=se.length===1?C("ecommerce.item_count_one","{count} item",{count:se.length}):C("ecommerce.item_count_other","{count} items",{count:se.length}),Rs=te.length===1?C("ecommerce.license_count_one","{count} license",{count:te.length}):C("ecommerce.license_count_other","{count} licenses",{count:te.length}),$s=m=>l.isDigitalItem(m)?C("ecommerce.digital_label","Digital"):C("ecommerce.physical_label","Physical"),qs=m=>m==="monthly"?C("ecommerce.checkout_billing_cycle_monthly","Monthly subscription"):m==="annual"?C("ecommerce.checkout_billing_cycle_annual","Annual subscription"):m==="lifetime"?C("ecommerce.checkout_billing_cycle_lifetime","Lifetime subscription"):null;return e.jsxs("div",{className:"container mx-auto px-4 py-12 md:px-6",children:[ss,e.jsxs("div",{className:"mx-auto max-w-6xl",children:[e.jsx("h1",{className:"mb-8 text-3xl font-bold",children:_("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($.Card,{children:[e.jsx($.CardHeader,{children:e.jsxs($.CardTitle,{className:"flex items-center gap-2",children:[e.jsx(S.CreditCard,{className:"w-5 h-5"}),_("ecommerce.contact_information")]})}),e.jsxs($.CardContent,{className:"space-y-4",children:[xe?e.jsx("div",{className:"rounded-xl border bg-muted/20 p-4 text-sm text-muted-foreground",children:_("checkout_prefill_notice",{email:s?.email||""})}):e.jsxs("div",{className:"space-y-2",children:[e.jsxs(T.Label,{htmlFor:"checkout-email",children:[_("ecommerce.email_address")," ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(U.Input,{id:"checkout-email",type:"email",placeholder:_("ecommerce.email_placeholder"),value:p,onChange:m=>{y(m.target.value),b&&f("")},required:!0}),b?e.jsx("p",{className:"text-xs text-destructive mt-1",children:b}):null]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T.Label,{htmlFor:"checkout-phone",children:_("phone_number")}),e.jsx(U.Input,{id:"checkout-phone",placeholder:_("optional"),value:x,onChange:m=>g(m.target.value)})]})]})]}),e.jsx(is,{idPrefix:"billing",title:_("billing_address"),description:_("checkout_billing_address_help"),value:V,onChange:K}),re?e.jsxs("div",{className:"flex items-center space-x-3 rounded-xl border bg-muted/20 p-4",children:[e.jsx(hs.Checkbox,{id:"use-billing-for-shipping",checked:J,onCheckedChange:m=>ve(!!m)}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(T.Label,{htmlFor:"use-billing-for-shipping",className:"cursor-pointer",children:_("use_billing_for_shipping")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:_("checkout_use_billing_for_shipping_help")})]})]}):null,re&&!J?e.jsx(is,{idPrefix:"shipping",title:_("shipping_address"),description:_("checkout_shipping_address_help"),value:Q,onChange:pe}):null,re?e.jsxs($.Card,{children:[e.jsx($.CardHeader,{children:e.jsxs($.CardTitle,{className:"flex items-center gap-2",children:[e.jsx(S.ChevronRight,{className:"w-5 h-5 text-primary"}),_("ecommerce.shipping_method")]})}),e.jsx($.CardContent,{children:I?e.jsx("div",{className:"flex items-center justify-center py-6",children:e.jsx(S.Loader2,{className:"w-6 h-6 animate-spin text-muted-foreground"})}):k.length>0?e.jsx("div",{className:"space-y-3",children:k.map(m=>e.jsxs("div",{onClick:()=>D(m.id),className:`flex items-center justify-between p-4 rounded-lg border-2 cursor-pointer transition-all ${L===m.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 ${L===m.id?"border-primary":"border-neutral-300"}`,children:L===m.id?e.jsx("div",{className:"w-2 h-2 rounded-full bg-primary"}):null}),e.jsx("span",{className:"font-medium",children:m.name})]}),e.jsx("span",{className:"font-bold",children:h.formatPrice(m.amount,v)})]},m.id))}):e.jsx("div",{className:"py-4 text-center text-muted-foreground bg-muted/30 rounded-lg italic",children:Ce?_("ecommerce.no_rates_for_region"):C("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($.Card,{className:"top-6",children:[e.jsx($.CardHeader,{children:e.jsx($.CardTitle,{children:_("ecommerce.order_summary")})}),e.jsxs($.CardContent,{className:"space-y-4",children:[e.jsx("div",{className:"space-y-3 max-h-[260px] overflow-y-auto pr-2",children:ee.map(m=>{const E=me(m,{currencyCode:v,currencies:le}),z=ue(m);return e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"flex gap-3",children:[m.image_url?e.jsx("div",{className:"h-10 w-10 shrink-0 overflow-hidden rounded border bg-neutral-100",children:e.jsx("img",{src:m.image_url,alt:m.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:m.title}),e.jsx(ie.Badge,{variant:"outline",className:"text-[9px] uppercase",children:$s(m)})]}),m.variant_label?e.jsx("span",{className:"text-[10px] text-muted-foreground line-clamp-1",children:m.variant_label}):null,e.jsxs("span",{className:"text-[10px] text-muted-foreground",children:[_("ecommerce.qty"),": ",m.quantity]}),z?e.jsxs("span",{className:"text-[10px] font-medium text-emerald-700",children:[z.label," - ",z.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:h.formatPrice((E.sale_price??E.price)*m.quantity,v)}),E.sale_price?e.jsx("span",{className:"text-[9px] text-muted-foreground line-through",children:h.formatPrice(E.price*m.quantity,v)}):null]})]},`${m.id}-${m.variant_id||"base"}`)})}),e.jsx(Qe.Separator,{}),e.jsx(Re,{items:ee,currencyCode:v,onQuoteChange:Y}),e.jsxs("div",{className:"space-y-2 text-sm",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{children:_("ecommerce.subtotal")}),e.jsx("span",{children:h.formatPrice(Ts,v)})]}),se.length>0?e.jsxs("div",{className:"flex justify-between text-muted-foreground",children:[e.jsx("span",{children:C("ecommerce.physical_products","Physical products")}),e.jsx("span",{children:h.formatPrice(qe,v)})]}):null,te.length>0?e.jsxs("div",{className:"flex justify-between text-muted-foreground",children:[e.jsx("span",{children:C("ecommerce.digital_products","Digital products")}),e.jsx("span",{children:h.formatPrice(Oe,v)})]}):null,w?e.jsxs("div",{className:"flex justify-between text-emerald-600",children:[e.jsxs("span",{children:[C("ecommerce.discount","Discount")," (",w.code,")"]}),e.jsxs("span",{children:["-",h.formatPrice(w.discountTotal,v)]})]}):null,(se.length>0||te.length>0)&&e.jsxs("div",{className:"flex justify-between font-bold text-lg pt-2 border-t mt-2",children:[e.jsx("span",{children:C("ecommerce.estimated_total","Estimated total")}),e.jsx("span",{className:"text-primary",children:h.formatPrice(Is,v)})]})]})]})]}),se.length>0?e.jsxs(os,{title:C("ecommerce.stripe_checkout_title","Stripe Checkout"),description:C("ecommerce.stripe_checkout_description","Pay for physical products in one Stripe checkout session."),badgeLabel:Ls,children:[e.jsxs("div",{className:"space-y-2 text-sm",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{children:C("ecommerce.physical_subtotal","Physical subtotal")}),e.jsx("span",{children:h.formatPrice(qe,v)})]}),Me>0?e.jsxs("div",{className:"flex justify-between text-emerald-600",children:[e.jsx("span",{children:C("ecommerce.discount","Discount")}),e.jsxs("span",{children:["-",h.formatPrice(Me,v)]})]}):null,e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{children:_("ecommerce.shipping")}),e.jsx("span",{children:we?h.formatPrice(we.amount,v):"-"})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{children:C("ecommerce.tax","Tax")}),e.jsx("span",{children:F?"...":P?.isPendingExternalCalculation?C("ecommerce.tax_calculated_on_stripe","Calculated on Stripe"):P?h.formatPrice(P.amount,v):"-"})]}),P&&P.lines.length>0?e.jsx("div",{className:"rounded-lg bg-muted/20 px-3 py-2 text-xs text-muted-foreground",children:P.lines.map(m=>e.jsxs("div",{className:"flex justify-between gap-3",children:[e.jsxs("span",{children:[m.name," (",m.rate.toFixed(4),"%)"]}),e.jsx("span",{children:h.formatPrice(m.amount,v)})]},m.id||`${m.name}-${m.rate}`))}):null,e.jsxs("div",{className:"flex justify-between font-semibold pt-2 border-t",children:[e.jsx("span",{children:C("ecommerce.total_on_stripe","Total on Stripe")}),e.jsx("span",{children:h.formatPrice(Ze,v)})]})]}),e.jsxs(H.Button,{className:"w-full",size:"lg",onClick:()=>ts("stripe",se,"stripe"),disabled:Fs,children:[r==="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"}),r==="stripe"?_("ecommerce.processing"):C("ecommerce.checkout_physical_products","Checkout Physical Products")]}),ze&&r===null?e.jsx("p",{className:"text-[11px] text-muted-foreground",children:ze}):null,c.stripe?e.jsx("div",{className:"rounded-lg border border-destructive/20 bg-destructive/10 px-3 py-2 text-xs text-destructive",children:c.stripe}):null,e.jsx("p",{className:"text-[11px] text-muted-foreground",children:P?.isPendingExternalCalculation?C("checkout_stripe_tax_finalized_notice","Tax will be finalized by Stripe Tax on the payment step."):C("ecommerce.shipping_taxes_collected_on_stripe","Shipping and taxes are only collected during the Stripe step for physical products.")})]}):null,te.length>0?e.jsxs(os,{title:C("ecommerce.freemius_checkout_title","Freemius Checkout"),description:C("ecommerce.freemius_checkout_description","Digital products use the Freemius checkout flow."),badgeLabel:Rs,children:[e.jsx("div",{className:"space-y-3",children:te.map(m=>{const E=me(m,{currencyCode:v,currencies:le}),z=ue(m),M=`freemius:${m.id}`,G=z?a[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:m.title}),m.billing_cycle?e.jsx("p",{className:"text-xs text-muted-foreground capitalize",children:qs(m.billing_cycle)}):null,z?e.jsxs("p",{className:"text-xs font-medium text-emerald-700",children:[z.label," - ",z.paymentRequirementLabel]}):null]}),e.jsx("span",{className:"font-medium",children:h.formatPrice(E.sale_price??E.price,v)})]}),z&&!m.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:C("ecommerce.freemius_trial_preference_title","How would you like to start your trial?")}),e.jsxs(Be.RadioGroup,{value:a[M]||"paid",onValueChange:B=>t(q=>({...q,[M]:B})),className:"gap-3",children:[e.jsxs("div",{className:"flex items-start space-x-3",children:[e.jsx(Be.RadioGroupItem,{value:"paid",id:`${M}-paid`,className:"mt-1"}),e.jsxs("div",{className:"grid gap-1.5",children:[e.jsx(T.Label,{htmlFor:`${M}-paid`,className:"font-medium leading-none cursor-pointer",children:C("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:C("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(Be.RadioGroupItem,{value:"free",id:`${M}-free`,className:"mt-1"}),e.jsx("div",{className:"grid gap-1.5",children:e.jsx(T.Label,{htmlFor:`${M}-free`,className:"font-medium leading-none cursor-pointer",children:C("ecommerce.freemius_trial_no_card","Start Free Trial (No card required)")})})]})]})]}),e.jsxs(H.Button,{className:"w-full h-auto min-h-[2.75rem] py-2",variant:te.length>1?"outline":"default",onClick:()=>ts("freemius",[{...m,...G?{trial_preference:G}:{}}],M),disabled:r!==null,children:[r===M?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:r===M?_("ecommerce.processing"):te.length>1?C("ecommerce.checkout_product","Checkout {title}",{title:m.title}):C("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:C("ecommerce.digital_subtotal","Digital subtotal")}),e.jsx("span",{children:h.formatPrice(Oe,v)})]}),De>0?e.jsxs("div",{className:"flex justify-between text-sm font-semibold text-emerald-600",children:[e.jsx("span",{children:C("ecommerce.discount","Discount")}),e.jsxs("span",{children:["-",h.formatPrice(De,v)]})]}):null,c.freemius?e.jsx("div",{className:"rounded-lg border border-destructive/20 bg-destructive/10 px-3 py-2 text-xs text-destructive",children:c.freemius}):null,e.jsx("p",{className:"text-[11px] text-muted-foreground",children:te.length>1?C("ecommerce.freemius_multi_checkout_notice","Freemius licenses are completed one at a time, so each digital product gets its own checkout action."):C("ecommerce.freemius_tax_notice","Taxes and compliance for digital products are handled inside the Freemius checkout.")})]}):null]})]})]})]})},st=()=>{const s=_e(r=>r.toggleCart),a=fs();return oe(r=>r.isOpen)!==void 0?e.jsxs(H.Button,{variant:"ghost",size:"icon",className:"relative",onClick:s,"aria-label":"Open cart",children:[e.jsx(S.ShoppingBag,{className:"h-5 w-5"}),a>0&&e.jsx(ie.Badge,{variant:"destructive",className:"absolute -right-1 -top-1 h-4 w-4 items-center justify-center p-0 text-[10px]",children:a})]}):e.jsx(H.Button,{variant:"ghost",size:"icon",className:"relative","aria-label":"Open cart",children:e.jsx(S.ShoppingBag,{className:"h-5 w-5"})})};function tt(){const{activeCurrencyCode:s,currencies:a,setActiveCurrencyCode:t}=ne();return a.length<=1?null:e.jsxs(ae.Select,{value:s,onValueChange:t,children:[e.jsx(ae.SelectTrigger,{className:"h-9 w-[88px] text-xs font-semibold",children:e.jsx(ae.SelectValue,{placeholder:s})}),e.jsx(ae.SelectContent,{children:a.map(r=>e.jsx(ae.SelectItem,{value:r.code,children:r.code},r.code))})]})}const $e=({product:s,className:a,quantity:t})=>{const r=oe(b=>b),{t:n}=h.useTranslations(),{activeCurrencyCode:c}=ne();if(!!s.has_variants&&!s.variant_id&&!l.isDigitalProduct(s))return e.jsx(H.Button,{asChild:!0,className:a,children:e.jsx(ge,{href:`/product/${s.slug}`,children:"Select Options"})});if(!r)return e.jsxs(H.Button,{disabled:!0,className:a,children:[e.jsx(S.ShoppingCart,{className:"mr-2 h-4 w-4"}),n("ecommerce.add_to_cart")]});const{addItem:p}=r,y=()=>{const b=l.getProductPaymentProvider(s)??"stripe",{success:f,error:x}=p({id:s.variant_id||s.id,product_id:s.id,title:s.title,price:s.price,prices:s.prices,sale_price:s.sale_price,sale_prices:s.sale_prices,is_taxable:s.is_taxable,image_url:s.image_url,slug:s.slug,sku:s.sku,stock:s.stock,language_id:s.language_id,translation_group_id:s.translation_group_id,product_type:s.product_type,payment_provider:s.payment_provider??b,provider:b,freemius_product_id:s.freemius_product_id,freemius_plan_id:s.freemius_plan_id,trial_period_days:s.trial_period_days??0,trial_requires_payment_method:s.trial_requires_payment_method??!1,has_variants:s.has_variants,variant_id:s.variant_id,variant_label:s.variant_label,selected_options:s.selected_options,currency_code:c,quantity:t});f?Ee.toast.success(n("ecommerce.added_to_cart_success",{item:s.title})):Ee.toast.error(x||n("ecommerce.added_to_cart_error"))};return e.jsxs(H.Button,{onClick:y,className:a,children:[e.jsx(S.ShoppingCart,{className:"mr-2 h-4 w-4"}),n("ecommerce.add_to_cart")]})},vs=({product:s,className:a})=>{const{activeCurrencyCode:t,currencies:r}=ne(),n=l.resolvePriceRangeForCurrency({entries:s.variants?.length?s.variants:s.product_variants?.length?s.product_variants:[],currencyCode:t,currencies:r}),c=!!(s.has_variants&&n),o=l.resolveEffectivePriceForCurrency({prices:s.prices,salePrices:s.sale_prices,fallbackPrice:s.price,fallbackSalePrice:s.sale_price,saleStartAt:s.sale_start_at,saleEndAt:s.sale_end_at,scheduledPrice:s.scheduled_price,scheduledPrices:s.scheduled_prices,scheduledPriceAt:s.scheduled_price_at,currencyCode:t,currencies:r}),p=c&&n?n.min===n.max?h.formatPrice(n.min,t):`${h.formatPrice(n.min,t)} - ${h.formatPrice(n.max,t)}`:h.formatPrice(o.sale_price??o.price,t),y=s.variants?.length?s.variants:s.product_variants?.length?s.product_variants:[],b=c?y.some(i=>l.resolveEffectivePriceForCurrency({prices:i.prices,salePrices:i.sale_prices,fallbackPrice:i.price,fallbackSalePrice:i.sale_price,saleStartAt:i.sale_start_at,saleEndAt:i.sale_end_at,scheduledPrice:i.scheduled_price,scheduledPrices:i.scheduled_prices,scheduledPriceAt:i.scheduled_price_at,currencyCode:t,currencies:r}).sale_price!=null):o.sale_price!=null,{t:f,lang:x}=h.useTranslations(),g=f("ecommerce.on_sale"),j=g==="ecommerce.on_sale"?"On Sale":g,d=ue(s),N=s.freemius_plans?.[0]?.freemius_pricing?.[0],I=r.find(i=>i.is_default)?.code||"USD",O=N?.override_monthly_price??N?.api_monthly_price,F=N?.override_annual_price??N?.api_annual_price,R=typeof O=="number"?l.resolvePriceForCurrency({prices:{[I]:h.majorUnitAmountToMinor(O,I)},currencyCode:t,currencies:r}):null,k=typeof F=="number"?l.resolvePriceForCurrency({prices:{[I]:h.majorUnitAmountToMinor(F,I)},currencyCode:t,currencies:r}):null;return e.jsxs("div",{className:h.cn("group relative flex flex-col overflow-hidden rounded-lg border bg-card text-card-foreground shadow-sm transition-all hover:shadow-md",a),children:[e.jsxs(ge,{href:`/product/${s.slug}`,className:"relative aspect-square overflow-hidden bg-muted",children:[b&&e.jsx("span",{className:"absolute left-3 top-3 z-10 rounded-full bg-destructive px-2.5 py-1 text-[10px] font-bold uppercase tracking-wider text-destructive-foreground shadow-sm",children:j}),s.image_url?e.jsx("img",{src:s.image_url,alt:s.title,className:"h-full w-full object-cover object-center transition-transform duration-300 group-hover:scale-105"}):e.jsx("div",{className:"flex h-full items-center justify-center text-muted-foreground",children:"No Image"})]}),e.jsxs("div",{className:"flex flex-1 flex-col p-4",children:[s.categories&&s.categories.length>0&&e.jsx("div",{className:"text-[10px] font-bold uppercase tracking-widest text-amber-600 dark:text-amber-400 mb-1",children:s.categories.map(i=>l.resolveTranslatedText(i.name,i.name_translations,x)).join(" • ")}),e.jsx(ge,{href:`/product/${s.slug}`,className:"mb-2",children:e.jsx("h3",{className:"line-clamp-1 text-lg font-medium text-foreground group-hover:underline",children:s.title})}),e.jsx("div",{className:"mb-4",children:s.product_type==="digital"&&(R||k)?e.jsxs("div",{className:"flex flex-wrap items-baseline gap-x-3 gap-y-1",children:[R&&e.jsxs("div",{className:"flex items-baseline gap-0.5",children:[e.jsx("span",{className:"text-xl font-bold text-primary",children:h.formatPrice(R.price,t)}),e.jsxs("span",{className:"text-xs font-medium text-muted-foreground lowercase",children:["/ ",f("ecommerce.month")]})]}),k&&e.jsxs("div",{className:"flex items-baseline gap-0.5",children:[e.jsx("span",{className:h.cn("font-bold text-primary",R?"text-lg":"text-xl"),children:h.formatPrice(k.price,t)}),e.jsxs("span",{className:"text-xs font-medium text-muted-foreground lowercase",children:["/ ",f("ecommerce.year")]})]})]}):e.jsxs("div",{className:"flex items-baseline gap-2",children:[e.jsx("span",{className:"text-xl font-bold text-primary",children:p}),!c&&o.sale_price&&e.jsx("span",{className:"text-sm text-muted-foreground line-through",children:h.formatPrice(o.price,t)})]})}),d&&e.jsxs("div",{className:"mb-4 rounded-md border border-emerald-200 bg-emerald-50 px-3 py-2 text-xs text-emerald-900",children:[e.jsx("div",{className:"font-semibold",children:d.label}),e.jsx("div",{className:"text-emerald-700",children:d.paymentRequirementLabel})]}),e.jsx("div",{className:"mt-auto",children:e.jsx($e,{product:{...s,price:s.price,prices:s.prices,sale_price:s.sale_price,sale_prices:s.sale_prices},className:"w-full"})})]})]})},rt=({products:s,columns:a=3,className:t})=>s.length?e.jsx("div",{className:h.cn("grid gap-6 sm:grid-cols-2",a===3&&"lg:grid-cols-3",a===4&&"lg:grid-cols-4",t),children:s.map(r=>e.jsx(vs,{product:r},r.id))}):e.jsx("div",{className:"py-12 text-center text-muted-foreground",children:"No products found."}),Ns=({images:s=[],className:a})=>{const[t,r]=u.useState(0);return u.useEffect(()=>{r(0)},[s]),s.length?e.jsxs("div",{className:h.cn("flex flex-col gap-4",a),children:[e.jsx("div",{className:"relative aspect-square w-full overflow-hidden rounded-lg border bg-white",children:e.jsx("img",{src:s[t].url,alt:s[t].alt,className:"h-full w-full object-cover object-center"})}),s.length>1&&e.jsx("div",{className:"flex gap-4 overflow-x-auto pb-2",children:s.map((n,c)=>e.jsx("button",{onClick:()=>r(c),className:h.cn("relative aspect-square w-20 flex-shrink-0 overflow-hidden rounded-md border",t===c?"ring-2 ring-primary":"ring-1 ring-transparent hover:ring-primary/50"),children:e.jsx("img",{src:n.url,alt:n.alt,className:"h-full w-full object-cover object-center"})},c))})]}):e.jsx("div",{className:h.cn("relative aspect-square w-full overflow-hidden rounded-lg bg-secondary",a),children:e.jsx("div",{className:"flex h-full items-center justify-center text-muted-foreground",children:"No Image"})})},at=({product:s,className:a,imagePosition:t="left"})=>{const{t:r}=h.useTranslations(),{activeCurrencyCode:n,currencies:c}=ne(),o=l.resolvePriceRangeForCurrency({entries:s.variants?.length?s.variants:s.product_variants?.length?s.product_variants:[],currencyCode:n,currencies:c}),p=!!(s.has_variants&&o),y=l.resolveEffectivePriceForCurrency({prices:s.prices,salePrices:s.sale_prices,fallbackPrice:s.price,fallbackSalePrice:s.sale_price,saleStartAt:s.sale_start_at,saleEndAt:s.sale_end_at,scheduledPrice:s.scheduled_price,scheduledPrices:s.scheduled_prices,scheduledPriceAt:s.scheduled_price_at,currencyCode:n,currencies:c}),b=p&&o?o.min===o.max?h.formatPrice(o.min,n):`${h.formatPrice(o.min,n)} - ${h.formatPrice(o.max,n)}`:h.formatPrice(y.sale_price??y.price,n),f=ue(s);return e.jsx("div",{className:h.cn("overflow-hidden rounded-xl border bg-card shadow-sm",a),children:e.jsxs("div",{className:h.cn("flex flex-col gap-8 md:flex-row",t==="right"&&"md:flex-row-reverse"),children:[e.jsx("div",{className:"relative aspect-square w-full md:w-1/2",children:s.image_url?e.jsx("img",{src:s.image_url,alt:s.title,className:"h-full w-full object-cover"}):e.jsx("div",{className:"flex h-full w-full items-center justify-center bg-secondary text-muted-foreground",children:r("ecommerce.no_image")})}),e.jsxs("div",{className:"flex flex-1 flex-col justify-center p-6 md:p-12",children:[e.jsx(ge,{href:`/product/${s.slug}`,children:e.jsx("h2",{className:"mb-4 text-3xl font-bold tracking-tight hover:underline md:text-4xl",children:s.title})}),e.jsxs("div",{className:"mb-6 flex items-baseline gap-3",children:[e.jsx("span",{className:"text-3xl font-bold text-primary",children:b}),!p&&y.sale_price&&e.jsx("span",{className:"text-lg text-muted-foreground line-through",children:h.formatPrice(y.price,n)})]}),f&&e.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:[e.jsx("span",{className:"font-semibold",children:f.label}),e.jsx("span",{className:"text-emerald-700",children:f.paymentRequirementLabel})]}),s.short_description&&e.jsx("p",{className:"mb-8 text-lg text-muted-foreground",children:s.short_description}),e.jsxs("div",{className:"flex flex-col gap-4 sm:flex-row",children:[e.jsx($e,{product:s,className:"h-12 w-full px-8 text-lg sm:w-auto"}),e.jsx(ge,{href:`/product/${s.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:r("ecommerce.view_details")})]})]})]})})};function ds(s,a,t){const r=s(a);return r===a?t:r}function nt(s){return s==="password"?S.KeyRound:S.Package2}function Cs({links:s,title:a,className:t}){const r=We.usePathname(),{t:n}=h.useTranslations();return s.length?e.jsxs("div",{className:h.cn("w-full space-y-3",t),children:[e.jsx("div",{className:"text-sm font-medium text-muted-foreground uppercase tracking-wider",children:a||ds(n,"account_navigation","Account")}),e.jsx("div",{className:"space-y-2",children:s.map(c=>{const o=nt(c.icon),p=r===c.href||r.startsWith(`${c.href}/`);return e.jsxs(ge,{href:c.href,className:h.cn("flex items-center gap-3 rounded-xl border px-3 py-2.5 text-sm font-medium transition-colors",p?"border-slate-900 bg-slate-900 text-white":"border-border bg-background hover:bg-muted/40"),children:[e.jsx(o,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{children:ds(n,c.labelKey,c.fallbackLabel)})]},c.href)})})]}):null}async function lt(s){const a=Ie.createClient(),{data:{user:t},error:r}=await a.auth.getUser();if(r||!t)throw new Error("Unauthorized");const n={full_name:s.full_name||null,avatar_url:s.avatar_url||null,website:s.website||null,github_username:s.github_username||null,phone:s.phone||null,updated_at:new Date().toISOString()},{error:c}=await a.from("profiles").update(n).eq("id",t.id);if(c)throw console.error("Error updating profile:",c),new Error("Failed to update profile");const o=l.normalizeCustomerAddress(s.billing_address),p=s.use_billing_for_shipping?o:l.normalizeCustomerAddress(s.shipping_address);return await l.upsertDefaultUserAddresses({userId:t.id,billingAddress:o,shippingAddress:p,client:a}),ns.revalidatePath("/profile"),ns.revalidatePath("/checkout"),{success:!0}}function Te(s){return{company_name:s?.company_name||"",recipient_name:s?.recipient_name||"",line1:s?.line1||"",line2:s?.line2||"",city:s?.city||"",state:s?.state||"",postal_code:s?.postal_code||"",country_code:l.normalizeCountryCode(s?.country_code)||"CA"}}function us({prefix:s,title:a,register:t}){const{t:r}=h.useTranslations(),n=r("company_name")==="company_name"?"Company name":r("company_name");return e.jsxs("div",{className:"space-y-4 rounded-xl border p-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:a}),e.jsx("p",{className:"text-sm text-muted-foreground",children:r("profile_address_defaults_help")})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(T.Label,{htmlFor:`${s}-company_name`,children:n}),e.jsx(U.Input,{id:`${s}-company_name`,...t(`${s}.company_name`)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T.Label,{htmlFor:`${s}-recipient_name`,children:r("full_name")}),e.jsx(U.Input,{id:`${s}-recipient_name`,...t(`${s}.recipient_name`)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T.Label,{htmlFor:`${s}-country_code`,children:r("country")}),e.jsx("select",{id:`${s}-country_code`,className:"flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm",...t(`${s}.country_code`),children:l.countries.map(c=>e.jsx("option",{value:c.code,children:c.name},c.code))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T.Label,{htmlFor:`${s}-line1`,children:r("address_line_1")}),e.jsx(U.Input,{id:`${s}-line1`,...t(`${s}.line1`)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T.Label,{htmlFor:`${s}-line2`,children:r("address_line_2")}),e.jsx(U.Input,{id:`${s}-line2`,...t(`${s}.line2`)})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(T.Label,{htmlFor:`${s}-city`,children:r("city")}),e.jsx(U.Input,{id:`${s}-city`,...t(`${s}.city`)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T.Label,{htmlFor:`${s}-state`,children:r("state_province")}),e.jsx(U.Input,{id:`${s}-state`,...t(`${s}.state`)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T.Label,{htmlFor:`${s}-postal_code`,children:r("postal_zip_code")}),e.jsx(U.Input,{id:`${s}-postal_code`,...t(`${s}.postal_code`)})]})]})]})}function ct({initialData:s,MediaPickerComponent:a,isAdmin:t,email:r,accountLinks:n,onAction:c,initialSuccessMessage:o}){const{t:p}=h.useTranslations(),[y,b]=u.useState(!1),[f,x]=u.useState(o?{type:"success",text:o}:null),[g,j]=u.useState(!1),[d,A]=u.useState(null),N=s?.use_billing_for_shipping??(!s?.shipping_address||l.addressesMatch(s?.billing_address,s?.shipping_address)),{register:I,handleSubmit:O,setValue:F,getValues:R,watch:k,reset:i}=Us.useForm({defaultValues:{full_name:s?.full_name||"",avatar_url:s?.avatar_url||"",website:s?.website||"",github_username:s?.github_username||"",phone:s?.phone||"",role:s?.role,use_billing_for_shipping:N,billing_address:Te(s?.billing_address),shipping_address:Te(s?.shipping_address)}});u.useEffect(()=>{s&&i({full_name:s.full_name||"",avatar_url:s.avatar_url||"",website:s.website||"",github_username:s.github_username||"",phone:s.phone||"",role:s.role,use_billing_for_shipping:s.use_billing_for_shipping??(!s.shipping_address||l.addressesMatch(s.billing_address,s.shipping_address)),billing_address:Te(s.billing_address),shipping_address:Te(s.shipping_address)})},[s,i]),u.useEffect(()=>{o&&x({type:"success",text:o})},[o]),u.useEffect(()=>{const w=ls.createClient();(async()=>{const{data:{user:V}}=await w.auth.getUser();if(!V)return;const K=V.identities?.find(Q=>Q.provider==="github");if(K){j(!0);const Q=K.identity_data?.email||(V.app_metadata.provider==="github"?V.email:null);if(A(Q),!R("website")){const J=K.identity_data?.custom_claims?.blog||K.identity_data?.blog||K.identity_data?.html_url;J&&F("website",J)}if(!R("avatar_url")){const J=K.identity_data?.avatar_url;J&&F("avatar_url",J)}const pe=K.identity_data?.user_name||K.identity_data?.preferred_username;pe&&F("github_username",pe)}!R("full_name")&&V.user_metadata?.full_name&&F("full_name",V.user_metadata.full_name)})()},[R,F]);const L=async()=>{const w=ls.createClient(),{error:Y}=await w.auth.linkIdentity({provider:"github"});Y&&(console.error("Error linking GitHub:",Y),x({type:"error",text:p("github_link_failed")||"Failed to link GitHub account"}))},D=w=>{const V=`${process.env.NEXT_PUBLIC_R2_BASE_URL||"https://assets.nextblock.com"}/${w.object_key}`;F("avatar_url",V)},P=async w=>{b(!0),x(null);const Y=l.normalizeCustomerAddress(w.billing_address)??l.emptyCustomerAddress(),V=w.use_billing_for_shipping?Y:l.normalizeCustomerAddress(w.shipping_address);try{const K={...w,billing_address:Y,shipping_address:V};if(c){const Q=await c(K);if(Q?.error)throw new Error(Q.error)}else await lt(K);x({type:"success",text:p("profile_updated_success")})}catch(K){if(K.message==="NEXT_REDIRECT"||K.message?.includes("NEXT_REDIRECT"))return;console.error(K),x({type:"error",text:K.message||p("profile_update_failed")})}finally{b(!1)}},W=k("use_billing_for_shipping");return e.jsxs("div",{className:"grid gap-6 md:grid-cols-12 max-w-5xl mx-auto",children:[e.jsxs($.Card,{className:"md:col-span-4 h-fit",children:[e.jsx($.CardHeader,{children:e.jsx($.CardTitle,{className:"text-xl",children:p("public_profile")})}),e.jsxs($.CardContent,{className:"flex flex-col items-center text-center space-y-4",children:[e.jsxs("div",{className:"relative group",children:[e.jsxs(Ue.Avatar,{className:"h-32 w-32 border-4 border-muted",children:[e.jsx(Ue.AvatarImage,{src:k("avatar_url")||void 0,className:"object-cover"}),e.jsx(Ue.AvatarFallback,{className:"text-4xl bg-secondary",children:k("full_name")?.charAt(0)?.toUpperCase()||e.jsx(S.User,{className:"h-12 w-12"})})]}),a&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity bg-black/40 rounded-full cursor-pointer",children:e.jsx(a,{triggerLabel:e.jsx(S.Upload,{className:"h-6 w-6 text-white"}),triggerVariant:"ghost",title:p("customer_profile"),onSelect:D,accept:w=>w.file_type.startsWith("image/"),hideTrigger:!1})})]}),!a&&e.jsxs("div",{className:"w-full",children:[e.jsx(T.Label,{htmlFor:"avatar_url",className:"sr-only",children:p("avatar_url")}),e.jsx(U.Input,{id:"avatar_url",...I("avatar_url"),placeholder:"https://...",className:"mt-2"})]}),e.jsxs("div",{className:"w-full space-y-1 text-left mt-4",children:[e.jsx("div",{className:"text-sm font-medium text-muted-foreground uppercase tracking-wider",children:p("identity")}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("span",{className:"font-semibold text-lg",children:k("full_name")||p("full_name")})}),g&&e.jsxs(ie.Badge,{variant:"secondary",className:"mt-2 w-fit gap-1",children:[e.jsx(S.Github,{className:"h-3 w-3"})," ",p("github_connected")||"GitHub Connected"]})]}),n?.length?e.jsx(Cs,{links:n,className:"mt-2 text-left"}):null]})]}),e.jsx($.Card,{className:"md:col-span-8",children:e.jsxs("form",{onSubmit:O(P),children:[e.jsx($.CardHeader,{children:e.jsx($.CardTitle,{children:p("details")})}),e.jsxs($.CardContent,{className:"space-y-6",children:[r&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs(T.Label,{htmlFor:"email",children:[p("email")||"Email"," (Read-only)"]}),e.jsx(U.Input,{id:"email",value:r,readOnly:!0,disabled:!0,className:"bg-muted/50"})]}),e.jsx("div",{className:"rounded-xl border bg-muted/20 p-4 text-sm text-muted-foreground",children:p("profile_basic_info_help")}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs(T.Label,{htmlFor:"full_name",className:"flex items-center gap-2",children:[e.jsx(S.User,{className:"h-4 w-4"})," ",p("full_name")]}),e.jsx(U.Input,{id:"full_name",...I("full_name")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(T.Label,{htmlFor:"phone",className:"flex items-center gap-2",children:[e.jsx(S.Phone,{className:"h-4 w-4"})," ",p("phone_number")]}),e.jsx(U.Input,{id:"phone",...I("phone")})]})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs(T.Label,{htmlFor:"website",className:"flex items-center gap-2",children:[e.jsx(S.Globe,{className:"h-4 w-4"})," ",p("website")]}),e.jsx(U.Input,{id:"website",...I("website"),placeholder:"https://example.com"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(T.Label,{htmlFor:"github_username",className:"flex items-center gap-2",children:[e.jsx(S.Github,{className:"h-4 w-4"})," ",p("github_username")]}),g?e.jsxs("div",{className:"space-y-2",children:[e.jsx(U.Input,{id:"github_username",...I("github_username"),disabled:!0,className:"bg-muted"}),d&&e.jsxs("p",{className:"text-xs text-muted-foreground flex items-center gap-1",children:[e.jsx(S.Mail,{className:"h-3 w-3"})," ",p("linked_to")||"Linked to"," ",d]})]}):e.jsxs(H.Button,{type:"button",variant:"outline",className:"w-full",onClick:L,children:[e.jsx(S.Github,{className:"mr-2 h-4 w-4"}),p("connect_github")]})]})]}),e.jsx(Qe.Separator,{className:"my-2"}),e.jsx(us,{prefix:"billing_address",title:p("billing_address"),register:I}),e.jsxs("div",{className:"flex items-center space-x-3 rounded-lg border p-4",children:[e.jsx(hs.Checkbox,{id:"use_billing_for_shipping",checked:!!W,onCheckedChange:w=>F("use_billing_for_shipping",!!w,{shouldDirty:!0})}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(T.Label,{htmlFor:"use_billing_for_shipping",className:"cursor-pointer",children:p("use_billing_for_shipping")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:p("profile_use_billing_for_shipping_help")})]})]}),!W&&e.jsx(us,{prefix:"shipping_address",title:p("shipping_address"),register:I}),f&&e.jsx("div",{className:`mt-4 rounded-xl border p-4 text-sm ${f.type==="success"?"border-emerald-200 bg-emerald-50 text-emerald-700":"border-red-200 bg-red-50 text-red-700"}`,children:f.text}),t&&e.jsxs("div",{className:"border-t pt-4 mt-4",children:[e.jsx("h3",{className:"text-sm font-medium mb-3",children:"Admin Settings"}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(T.Label,{htmlFor:"role",children:"Role"}),e.jsxs(ae.Select,{value:k("role")||"USER",onValueChange:w=>F("role",w),children:[e.jsx(ae.SelectTrigger,{children:e.jsx(ae.SelectValue,{placeholder:"Select role"})}),e.jsxs(ae.SelectContent,{children:[e.jsx(ae.SelectItem,{value:"USER",children:"User"}),e.jsx(ae.SelectItem,{value:"WRITER",children:"Writer"}),e.jsx(ae.SelectItem,{value:"ADMIN",children:"Admin"})]})]})]})]})]}),e.jsx($.CardFooter,{className:"flex justify-end",children:e.jsx(H.Button,{type:"submit",disabled:y,size:"lg",children:p(y?"saving":"save_changes")})})]})})]})}const ws=({product:s})=>{const a=oe(k=>k),{t}=h.useTranslations(),{activeCurrencyCode:r,currencies:n,defaultCurrency:c}=ne(),[o,p]=u.useState([]),[y,b]=u.useState(!0),[f,x]=u.useState("annual");if(u.useEffect(()=>{async function k(){try{if(!s.id)return;const i=await l.getPublicFreemiusPricing(s.id);p(i)}catch(i){console.error("Failed to load pricing:",i)}finally{b(!1)}}k()},[s.id]),!a)return e.jsx(cs.Skeleton,{className:"h-14 w-full"});const{addItem:g}=a,j=o[0],d=j?.pricing?.[0],A=()=>{let k=s.price,i=s.freemius_plan_id;d&&(f==="monthly"&&d.monthly_price!=null&&(k=h.majorUnitAmountToMinor(d.monthly_price,c.code)),f==="annual"&&d.annual_price!=null&&(k=h.majorUnitAmountToMinor(d.annual_price,c.code)),f==="lifetime"&&d.lifetime_price!=null&&(k=h.majorUnitAmountToMinor(d.lifetime_price,c.code)));const L=n.reduce((w,Y)=>(w[Y.code]=l.convertMinorUnitAmount({amount:k,fromCurrencyCode:c.code,toCurrencyCode:Y.code,currencies:n,applyRounding:!0}),w),{}),D=L[r]??k;j&&j.id&&(i=j.id);const{success:P,error:W}=g({id:s.id,product_id:s.id,title:s.title,price:D,prices:L,image_url:s.image_url,slug:s.slug,sku:s.sku,language_id:s.language_id,translation_group_id:s.translation_group_id,product_type:"digital",payment_provider:"freemius",provider:"freemius",billing_cycle:f,freemius_product_id:s.freemius_product_id,freemius_plan_id:i,trial_period_days:s.trial_period_days??0,trial_requires_payment_method:s.trial_requires_payment_method??!1,is_taxable:s.is_taxable,currency_code:r});P?Ee.toast.success(t("ecommerce.added_to_cart_success",{item:s.title})):Ee.toast.error(W||t("ecommerce.added_to_cart_error"))};if(y)return e.jsx(cs.Skeleton,{className:"h-32 w-full"});if(!j||!d)return e.jsx("div",{className:"p-4 border border-dashed rounded-lg text-center text-muted-foreground",children:t("ecommerce.pricing_unavailable")});const N=d.monthly_price!=null,I=d.annual_price!=null,O=d.lifetime_price!=null;f==="annual"&&!I&&(N?x("monthly"):O&&x("lifetime"));const F=ue(s);let R=s.price;return f==="monthly"&&d.monthly_price!=null&&(R=l.convertMinorUnitAmount({amount:h.majorUnitAmountToMinor(d.monthly_price,c.code),fromCurrencyCode:c.code,toCurrencyCode:r,currencies:n,applyRounding:!0})),f==="annual"&&d.annual_price!=null&&(R=l.convertMinorUnitAmount({amount:h.majorUnitAmountToMinor(d.annual_price,c.code),fromCurrencyCode:c.code,toCurrencyCode:r,currencies:n,applyRounding:!0})),f==="lifetime"&&d.lifetime_price!=null&&(R=l.convertMinorUnitAmount({amount:h.majorUnitAmountToMinor(d.lifetime_price,c.code),fromCurrencyCode:c.code,toCurrencyCode:r,currencies:n,applyRounding:!0})),e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"flex bg-secondary/35 p-1 rounded-lg w-full max-w-sm mx-auto shadow-inner",children:[N&&e.jsx("button",{onClick:()=>x("monthly"),className:`flex-1 py-1.5 text-xs font-semibold rounded-md transition-all ${f==="monthly"?"bg-background shadow-sm text-foreground":"text-muted-foreground hover:text-foreground"}`,children:t("ecommerce.monthly")}),I&&e.jsx("button",{onClick:()=>x("annual"),className:`flex-1 py-1.5 text-xs font-semibold rounded-md transition-all ${f==="annual"?"bg-background shadow-sm text-foreground":"text-muted-foreground hover:text-foreground"}`,children:t("ecommerce.annual")}),O&&e.jsx("button",{onClick:()=>x("lifetime"),className:`flex-1 py-1.5 text-xs font-semibold rounded-md transition-all ${f==="lifetime"?"bg-background shadow-sm text-foreground":"text-muted-foreground hover:text-foreground"}`,children:t("ecommerce.lifetime")})]}),e.jsxs("div",{className:"text-center",children:[e.jsx("span",{className:"text-3xl font-extrabold text-foreground",children:h.formatPrice(R,r)}),f!=="lifetime"&&e.jsxs("span",{className:"text-muted-foreground text-sm ml-1.5",children:["/ ",t(f==="annual"?"ecommerce.year":"ecommerce.month")]}),F&&e.jsxs("div",{className:"mt-1 text-xs font-medium text-emerald-600 dark:text-emerald-400",children:[F.label,e.jsx("span",{className:"mx-2 text-muted-foreground/50",children:"|"}),e.jsx("span",{className:"text-muted-foreground",children:F.paymentRequirementLabel})]})]}),e.jsxs(H.Button,{onClick:A,className:"w-full h-12 text-md font-bold shadow-md transition-all hover:shadow-lg active:scale-[0.98]",children:[e.jsx(S.ShoppingCart,{className:"mr-2 h-4 w-4"}),F?.label?`Start ${F.label}`:t("ecommerce.get_license")]})]})},it=(s,a)=>a.reduce((t,r)=>{switch(r.type){case"bold":return e.jsx("strong",{children:t});case"italic":return e.jsx("em",{children:t});case"underline":case"u":return e.jsx("u",{children:t});case"strike":return e.jsx("s",{children:t});case"code":return e.jsx("code",{className:"bg-muted px-1.5 py-0.5 rounded text-[0.875em] font-mono",children:t});case"link":{const n=r.attrs?.href||"#",c=r.attrs?.target||"_blank";return e.jsx("a",{href:n,target:c,rel:"noopener noreferrer",className:"underline text-primary hover:text-primary/80",children:t})}case"highlight":{const n=r.attrs?.color,c=n?{backgroundColor:n}:{};return e.jsx("mark",{style:c,className:n?void 0:"bg-yellow-200 dark:bg-yellow-800/50",children:t})}case"subscript":return e.jsx("sub",{children:t});case"superscript":return e.jsx("sup",{children:t});case"textStyle":{const n={};return r.attrs?.color&&(n.color=r.attrs.color),r.attrs?.fontSize&&(n.fontSize=r.attrs.fontSize),r.attrs?.fontFamily&&(n.fontFamily=r.attrs.fontFamily),Object.keys(n).length>0?e.jsx("span",{style:n,children:t}):e.jsx(e.Fragment,{children:t})}default:return t}},s),ot=["h1","h2","h3","h4","h5","h6"],dt=(s,a,t,r)=>{const n=Math.max(1,Math.min(6,s)),c=ot[n-1],o=r?.id;return u.createElement(c,{key:t,className:"font-bold my-4",id:o},a)},ms=s=>{const a={},t={},r=s?.colspan,n=s?.rowspan,c=s?.colwidth;return r&&r>1&&(a.colSpan=r),n&&n>1&&(a.rowSpan=n),c&&Array.isArray(c)&&c[0]&&(t.minWidth=c[0]),Object.keys(t).length>0&&(a.style=t),a},Ss=(s,a)=>{if(s.type==="text"){const r=s.text??"";return e.jsx(u.Fragment,{children:s.marks?.length?it(r,s.marks):r},a)}const t=s.content?.map((r,n)=>Ss(r,n))??null;switch(s.type){case"doc":return e.jsx("div",{children:t},a);case"paragraph":{if(!s.content?.length||s.content.every(o=>o.type==="text"&&(!o.text||!o.text.trim())))return null;const n=s.attrs?.textAlign,c=n?{textAlign:n}:{};return e.jsx("p",{className:"mb-4",style:Object.keys(c).length?c:void 0,children:t},a)}case"heading":return dt(s.attrs?.level||1,t,a,s.attrs??void 0);case"bulletList":return e.jsx("ul",{className:"list-disc pl-5 mb-4",children:t},a);case"orderedList":{const r=s.attrs?.start??1;return e.jsx("ol",{className:"list-decimal pl-5 mb-4",start:r!==1?r:void 0,children:t},a)}case"listItem":return e.jsx("li",{children:t},a);case"taskList":return e.jsx("ul",{className:"list-none pl-0 mb-4 space-y-1",children:t},a);case"taskItem":{const r=!!s.attrs?.checked;return e.jsxs("li",{className:"flex items-start gap-2",children:[e.jsx("input",{type:"checkbox",checked:r,readOnly:!0,className:"mt-1.5 rounded"}),e.jsx("div",{className:r?"line-through text-muted-foreground":"",children:t})]},a)}case"blockquote":return e.jsx("blockquote",{className:"border-l-4 border-border pl-4 italic my-4",children:t},a);case"codeBlock":{const r=s.attrs?.language;return e.jsx("pre",{className:"bg-muted rounded-lg p-4 mb-4 overflow-x-auto","data-language":r||void 0,children:e.jsx("code",{className:"text-sm font-mono",children:t})},a)}case"horizontalRule":return e.jsx("hr",{className:"my-6 border-border"},a);case"hardBreak":return e.jsx("br",{},a);case"image":{const r=s.attrs?.src,n=s.attrs?.alt||"",c=s.attrs?.title,o=s.attrs?.width,p=s.attrs?.height,y={};return o&&(y.width=typeof o=="number"?`${o}px`:o),p&&(y.height=typeof p=="number"?`${p}px`:p),e.jsx("img",{src:r,alt:n,title:c,style:Object.keys(y).length?y:void 0,className:"max-w-full h-auto rounded my-4"},a)}case"table":return e.jsx("div",{className:"overflow-x-auto my-4",children:e.jsx("table",{className:"w-full border-collapse border border-gray-300 dark:border-gray-700",style:{minWidth:500},children:e.jsx("tbody",{children:t})})},a);case"tableRow":return e.jsx("tr",{className:"border-b border-gray-300 dark:border-gray-700",children:t},a);case"tableHeader":return e.jsx("th",{...ms(s.attrs??void 0),className:"bg-gray-100 dark:bg-gray-800 font-bold p-3 text-left border border-gray-300 dark:border-gray-700",children:t},a);case"tableCell":return e.jsx("td",{...ms(s.attrs??void 0),className:"p-3 border border-gray-300 dark:border-gray-700",children:t},a);case"details":return e.jsx("details",{className:"my-4 border rounded-lg overflow-hidden",children:t},a);case"detailsSummary":return e.jsx("summary",{className:"cursor-pointer p-3 font-semibold bg-muted/30 hover:bg-muted/50",children:t},a);case"detailsContent":return e.jsx("div",{className:"p-3 border-t",children:t},a);case"youtube":{const r=s.attrs?.src,n=s.attrs?.width||640,c=s.attrs?.height||480;return e.jsx("div",{className:"relative my-4 overflow-hidden rounded-lg",style:{aspectRatio:`${n}/${c}`,maxWidth:n},children:e.jsx("iframe",{src:r,allow:"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture",allowFullScreen:!0,className:"absolute inset-0 w-full h-full"})},a)}case"iframe":{const r=s.attrs?.src;return e.jsx("div",{className:"my-4 overflow-hidden rounded-lg",style:{aspectRatio:"16/9"},children:e.jsx("iframe",{src:r,allowFullScreen:!0,className:"w-full h-full border-0"})},a)}case"mention":{const r=s.attrs?.label||s.attrs?.id||"";return e.jsxs("span",{className:"text-primary font-medium",children:["@",r]},a)}default:return e.jsx("div",{children:t},a)}},Ye=({content:s,className:a})=>{if(!s)return null;if(typeof s=="string"){if(s.trim().startsWith("{")||s.trim().startsWith("["))try{const r=JSON.parse(s);return e.jsx(Ye,{content:r,className:a})}catch{}return e.jsx("div",{className:a,dangerouslySetInnerHTML:{__html:s}})}const t=s;return!t.content||!Array.isArray(t.content)?null:e.jsx("div",{className:a,children:t.content.map((r,n)=>Ss(r,n))})},ks=u.createContext(void 0),ut=({product:s,children:a})=>e.jsx(ks.Provider,{value:{product:s},children:a}),Ps=()=>{const s=u.useContext(ks);if(!s)throw new Error("useProduct must be used within a ProductProvider. Ensure the component is wrapped in a ProductProvider.");return s.product};function Ge(s,a,t,r){const n={kind:"product-field",field:a,input:t,label:r},c=typeof window<"u"?window.location.origin:process.env.NEXT_PUBLIC_URL||process.env.TARGET_URL||(process.env.VERCEL_URL?`https://${process.env.VERCEL_URL}`:"")||"http://localhost:3000";let p=(typeof window<"u"?window.location.origin:process.env.NEXT_PUBLIC_URL||process.env.TARGET_URL||(process.env.VERCEL_URL?`https://${process.env.VERCEL_URL}`:"")||"http://localhost:3000").replace(/\/+$/,"");try{(p.startsWith("http://")||p.startsWith("https://"))&&(p=new URL(p).hostname)}catch{}const y=process.env.NEXTBLOCK_VERCEL_PROJECT_ID||process.env.VERCEL_PROJECT_ID,b=process.env.NEXTBLOCK_VERCEL_WORKSPACE_ID||process.env.VERCEL_ORG_ID,f={origin:p,editUrl:`${c}/cms/products/${s.id}/edit`,data:{parentType:"product",parentId:s.id,slug:s.slug,languageId:s.language_id,draftId:null,target:n}};return y&&(f.projectId=y),b&&(f.workspaceId=b),{"data-vercel-edit-info":JSON.stringify(f),"data-vercel-edit-target":JSON.stringify(n),"data-nextblock-visual-edit":`product:${a}`}}const mt=({visualEditingEnabled:s=!1,descriptionNode:a})=>{const t=Ps(),{t:r,lang:n}=h.useTranslations(),{activeCurrencyCode:c,currencies:o}=ne(),p=s?Ge(t,"title","plain-text","Product title"):void 0,y=s?Ge(t,"short_description","plain-text","Short description"):void 0,b=s?Ge(t,"description_json","tiptap","Product description"):void 0,f=(_,Z,v)=>{const le=r(_,v);return le===_?Z:le},x=t.images&&t.images.length>0?t.images:t.image_url?[{url:t.image_url,alt:t.title}]:[],g=t.custom_props?.provider==="freemius"||l.isDigitalProduct(t),j=ue(t),d=!g&&!!(t.has_variants&&t.attributes?.length&&t.variants?.length),A=t.attributes||[],N=t.variants||[],[I,O]=u.useState(()=>l.chooseInitialVariantSelections(A,N)),[F,R]=u.useState(1);u.useEffect(()=>{R(1)},[t.id]),u.useEffect(()=>{d&&O(l.chooseInitialVariantSelections(A,N))},[A,d,t.id,N]);const k=u.useMemo(()=>d?l.normalizeSelectionsToAvailableVariants(A,N,I):I,[A,d,I,N]);u.useEffect(()=>{JSON.stringify(k)!==JSON.stringify(I)&&O(k)},[k,I]);const i=u.useMemo(()=>d?l.findMatchingVariant(N,k):null,[d,k,N]),L=l.resolveEffectivePriceForCurrency({prices:t.prices,salePrices:t.sale_prices,fallbackPrice:t.price,fallbackSalePrice:t.sale_price,saleStartAt:t.sale_start_at,saleEndAt:t.sale_end_at,scheduledPrice:t.scheduled_price,scheduledPrices:t.scheduled_prices,scheduledPriceAt:t.scheduled_price_at,currencyCode:c,currencies:o}),D=d&&i?l.resolveEffectivePriceForCurrency({prices:i.prices,salePrices:i.sale_prices,fallbackPrice:i.price,fallbackSalePrice:i.sale_price,saleStartAt:i.sale_start_at,saleEndAt:i.sale_end_at,scheduledPrice:i.scheduled_price,scheduledPrices:i.scheduled_prices,scheduledPriceAt:i.scheduled_price_at,currencyCode:c,currencies:o}):null,P=D?.price??L.price,W=D?.sale_price??L.sale_price,w=d?i?.stock_quantity??0:t.stock??0,Y=u.useMemo(()=>{if(!i?.image_url)return x;const _={url:i.image_url,alt:`${t.title} ${i.label}`},Z=x.filter(v=>v.url!==i.image_url);return[_,...Z]},[x,t.title,i]),V=typeof W=="number"&&P>0?Math.round((P-W)/P*100):0,K=d&&i?{...t,sku:i.sku,price:i.price,prices:i.prices,sale_price:typeof i.sale_price=="number"?i.sale_price:null,sale_prices:i.sale_prices,image_url:i.image_url||t.image_url,stock:i.stock_quantity,variant_id:i.id,variant_label:i.label,selected_options:i.selected_options,currency_code:c}:{...t,currency_code:c},Q=(_,Z)=>{O(v=>l.normalizeSelectionsToAvailableVariants(A,N,{...v,[_]:Z}))},pe=f("ecommerce.in_stock",`${w} in stock`,{count:String(w)}),J=f("ecommerce.out_of_stock","Out of stock"),ve=f("ecommerce.select_options","Select Options"),he=f("ecommerce.variant_selection_required","Select one term from every dropdown to resolve a variation.");return e.jsxs("div",{className:"w-full animate-in fade-in slide-in-from-bottom-4 duration-700 ease-out",children:[e.jsx("div",{className:"container mx-auto px-4 md:px-6 py-12",children:e.jsxs("div",{className:"grid gap-12 lg:grid-cols-[2fr_3fr] items-start",children:[e.jsx("div",{className:"w-full max-w-2xl mx-auto lg:max-w-none",children:e.jsx(Ns,{images:Y,className:"w-full"})}),e.jsxs("div",{className:"flex flex-col gap-4 pb-2 max-w-xl mx-auto lg:mx-0 lg:max-w-none",children:[e.jsx("div",{className:"space-y-6",children:e.jsxs("div",{className:"space-y-4",children:[e.jsx("h1",{className:"text-3xl sm:text-4xl lg:text-5xl font-extrabold tracking-tight text-foreground leading-[1.1] lg:mt-0",...p,children:t.title}),t.categories&&t.categories.length>0&&e.jsx("div",{className:"flex flex-wrap items-center gap-1.5 text-xs font-bold uppercase tracking-widest text-amber-600 dark:text-amber-400",children:t.categories.map((_,Z)=>{const v=l.resolveTranslatedText(_.name,_.name_translations,n);return e.jsxs(u.Fragment,{children:[Z>0&&e.jsx("span",{className:"text-muted-foreground/30",children:"•"}),e.jsx("span",{children:v})]},_.id)})}),e.jsx("div",{className:"prose prose-neutral dark:prose-invert max-w-none text-muted-foreground leading-relaxed text-left",...y,children:t.short_description?e.jsx("div",{className:"text-lg mb-4 leading-relaxed",dangerouslySetInnerHTML:{__html:t.short_description}}):s?e.jsx("p",{className:"text-lg mb-4 italic text-muted-foreground",children:"Add a short product description."}):null}),e.jsxs("div",{className:"flex items-center gap-3",children:[typeof W=="number"&&e.jsx(ie.Badge,{variant:"destructive",className:"px-2.5 py-1 text-xs font-bold uppercase tracking-wide animate-pulse shadow-sm",children:r("ecommerce.sale_badge",{percent:String(V)})}),!g&&w>0&&w<10&&e.jsx(ie.Badge,{variant:"outline",className:"text-amber-600 border-amber-200 bg-amber-50",children:r("ecommerce.low_stock",{count:String(w)})}),j&&e.jsx(ie.Badge,{variant:"secondary",className:"border border-emerald-200 bg-emerald-50 text-emerald-800",children:j.label})]})]})}),e.jsxs("div",{className:"p-5 rounded-2xl bg-card/60 border border-border/80 shadow-md backdrop-blur-md space-y-4",children:[g?e.jsx(ws,{product:t}):e.jsxs("div",{className:"space-y-3.5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("span",{className:"text-[10px] font-bold text-muted-foreground uppercase tracking-widest",children:f("ecommerce.price","Price")}),e.jsxs("div",{className:"flex items-baseline gap-2.5",children:[e.jsx("span",{className:"text-3xl font-extrabold text-foreground",children:h.formatPrice(W??P,c)}),typeof W=="number"&&e.jsx("span",{className:"text-lg text-muted-foreground line-through decoration-destructive/20 decoration-1",children:h.formatPrice(P,c)})]})]}),!g&&(i||!d)&&e.jsxs("div",{className:"text-right space-y-1",children:[e.jsxs("span",{className:"text-[10px] font-bold text-muted-foreground uppercase tracking-widest block",children:[!d&&t.sku&&e.jsxs("span",{className:"mr-2 font-normal lowercase normal-case text-muted-foreground/70",children:["SKU: ",t.sku]}),f("ecommerce.status","Status")]}),e.jsx("div",{className:(w??0)>0?"text-emerald-600 dark:text-emerald-400 font-semibold text-sm":"text-destructive font-semibold text-sm",children:(w??0)>0?pe:J})]})]}),d&&e.jsx("div",{className:"space-y-3",children:e.jsx("div",{className:"grid gap-3 sm:grid-cols-2",children:A.map(_=>{const Z=l.getAvailableTermIdsForAttribute(N,_.id,k);return e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(T.Label,{htmlFor:`attribute-${_.id}`,className:"text-[11px] font-semibold text-muted-foreground uppercase tracking-wider",children:_.name}),i?.sku&&e.jsx("span",{className:"text-[10px] text-muted-foreground font-mono",children:i.sku})]}),e.jsx("select",{id:`attribute-${_.id}`,className:"flex h-9 w-full rounded-md border border-input bg-background px-3 py-1 text-sm focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring",value:k[_.id]||"",onChange:v=>Q(_.id,v.target.value),children:_.terms.map(v=>e.jsx("option",{value:v.id,disabled:!Z.has(v.id),children:v.value},v.id))})]},_.id)})})}),d&&!i&&e.jsx("p",{className:"text-xs text-muted-foreground italic pt-1",children:he}),e.jsxs("div",{className:"flex items-center gap-3 pt-1",children:[!g&&(w??0)>0&&e.jsxs("div",{className:"flex items-center border rounded-lg h-12 bg-background border-input select-none",children:[e.jsx("button",{type:"button",onClick:()=>R(_=>Math.max(1,_-1)),className:"px-3 h-full flex items-center justify-center text-muted-foreground hover:text-foreground active:scale-95 transition-all text-lg font-medium",disabled:F<=1,children:"-"}),e.jsx("span",{className:"w-8 text-center text-sm font-semibold",children:F}),e.jsx("button",{type:"button",onClick:()=>R(_=>w!==null&&_>=w?_:_+1),className:"px-3 h-full flex items-center justify-center text-muted-foreground hover:text-foreground active:scale-95 transition-all text-lg font-medium",disabled:w!==null&&F>=w,children:"+"})]}),d&&(!i||(w??0)<=0)?e.jsx(H.Button,{disabled:!0,className:"flex-1 h-12 text-md font-bold shadow-md",children:i?J:ve}):e.jsx($e,{product:K,quantity:F,className:"flex-1 h-12 text-md font-bold shadow-md transition-all hover:shadow-lg active:scale-[0.98]"})]})]}),e.jsx(Qe.Separator,{className:"opacity-60 my-0.5"}),e.jsxs("div",{className:"grid grid-cols-2 gap-4 text-center text-[11px] font-medium text-muted-foreground pt-1",children:[e.jsx("div",{className:"flex items-center justify-center gap-2",children:g?e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx(S.Download,{className:"h-3.5 w-3.5"}),r("ecommerce.instant_digital_delivery")]}):e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx(S.Package,{className:"h-3.5 w-3.5"}),r("ecommerce.free_shipping")]})}),e.jsx("div",{className:"flex items-center justify-center gap-2",children:e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx(S.ShieldCheck,{className:"h-3.5 w-3.5"}),r("ecommerce.secure_checkout")]})})]})]})]})]})}),e.jsx("div",{className:"min-w-0 w-full",...a?void 0:b,children:a||(t.description_json?e.jsx("div",{className:"container mx-auto px-4 md:px-6 pb-12 prose prose-neutral dark:prose-invert max-w-none leading-relaxed",children:e.jsx(Ye,{content:t.description_json})}):e.jsx("div",{className:"container mx-auto px-4 md:px-6 pb-12",children:e.jsx("p",{className:"italic text-sm text-muted-foreground",children:r("ecommerce.no_description")})}))})]})};exports.CURRENCY_ROUNDING_MODES=l.CURRENCY_ROUNDING_MODES;exports.DEFAULT_ENABLED_PAYMENT_PROVIDERS=l.DEFAULT_ENABLED_PAYMENT_PROVIDERS;exports.DEFAULT_INVOICE_SETTINGS=l.DEFAULT_INVOICE_SETTINGS;exports.INVOICE_SETTINGS_KEY=l.INVOICE_SETTINGS_KEY;exports.InvoiceDocument=l.InvoiceDocument;exports.InvoiceViewerShell=l.InvoiceViewerShell;exports.ProductCategorySelector=l.ProductCategorySelector;exports.ProductForm=l.ProductForm;exports.addressesMatch=l.addressesMatch;exports.aggregateOrderTaxLines=l.aggregateOrderTaxLines;exports.applyCurrencyRounding=l.applyCurrencyRounding;exports.buildCombinationKey=l.buildCombinationKey;exports.buildInvoiceDocumentLabels=l.buildInvoiceDocumentLabels;exports.buildOrderTaxDetailsFromCalculation=l.buildOrderTaxDetailsFromCalculation;exports.buildOrderTaxDetailsFromStripeSession=l.buildOrderTaxDetailsFromStripeSession;exports.buildVariantLabel=l.buildVariantLabel;exports.chooseInitialVariantSelections=l.chooseInitialVariantSelections;exports.convertMinorUnitAmount=l.convertMinorUnitAmount;exports.derivePaymentProviderFromProductType=l.derivePaymentProviderFromProductType;exports.describeCurrencyRoundingRule=l.describeCurrencyRoundingRule;exports.emptyCustomerAddress=l.emptyCustomerAddress;exports.emptyProviderDiscounts=l.emptyProviderDiscounts;exports.extractSelectedTermsByAttribute=l.extractSelectedTermsByAttribute;exports.findMatchingVariant=l.findMatchingVariant;exports.formatInvoiceCurrency=l.formatInvoiceCurrency;exports.formatInvoiceDate=l.formatInvoiceDate;exports.generateVariantDrafts=l.generateVariantDrafts;exports.getAvailableTermIdsForAttribute=l.getAvailableTermIdsForAttribute;exports.getCartLineCouponKey=l.getCartLineCouponKey;exports.getCurrencyLookup=l.getCurrencyLookup;exports.getDefaultCurrency=l.getDefaultCurrency;exports.getExchangeRateForCurrency=l.getExchangeRateForCurrency;exports.getInvoiceAddressLines=l.getInvoiceAddressLines;exports.getInvoiceLocale=l.getInvoiceLocale;exports.getOrderTaxRateJurisdiction=l.getOrderTaxRateJurisdiction;exports.getOrderTaxRateLabel=l.getOrderTaxRateLabel;exports.getOrderTaxRatePercentage=l.getOrderTaxRatePercentage;exports.getProductPaymentProvider=l.getProductPaymentProvider;exports.getVariantEffectivePriceRange=l.getVariantEffectivePriceRange;exports.inferCurrencyCodeFromLocale=l.inferCurrencyCodeFromLocale;exports.isCustomerAddressComplete=l.isCustomerAddressComplete;exports.isDigitalItem=l.isDigitalItem;exports.isDigitalProduct=l.isDigitalProduct;exports.isSaleWindowActive=l.isSaleWindowActive;exports.isScheduledPriceDue=l.isScheduledPriceDue;exports.localizeInvoicePresentationData=l.localizeInvoicePresentationData;exports.mapRawVariantRelations=l.mapRawVariantRelations;exports.normalizeCouponCode=l.normalizeCouponCode;exports.normalizeCurrencyRecord=l.normalizeCurrencyRecord;exports.normalizeCurrencyRoundingMode=l.normalizeCurrencyRoundingMode;exports.normalizeCustomerAddress=l.normalizeCustomerAddress;exports.normalizeEnabledPaymentProviders=l.normalizeEnabledPaymentProviders;exports.normalizeInvoiceSettings=l.normalizeInvoiceSettings;exports.normalizeOrderCustomerDetails=l.normalizeOrderCustomerDetails;exports.normalizeOrderTaxDetails=l.normalizeOrderTaxDetails;exports.normalizePriceMap=l.normalizePriceMap;exports.normalizeSalePriceMap=l.normalizeSalePriceMap;exports.normalizeSelectionsToAvailableVariants=l.normalizeSelectionsToAvailableVariants;exports.productSchema=l.productSchema;exports.resolveAttributeName=l.resolveAttributeName;exports.resolveEffectivePriceForCurrency=l.resolveEffectivePriceForCurrency;exports.resolvePriceForCurrency=l.resolvePriceForCurrency;exports.resolvePriceRangeForCurrency=l.resolvePriceRangeForCurrency;exports.resolveTermValue=l.resolveTermValue;exports.resolveTranslatedText=l.resolveTranslatedText;exports.serializeInvoiceSettings=l.serializeInvoiceSettings;exports.sortCurrencies=l.sortCurrencies;exports.translateOrFallback=l.translateOrFallback;exports.translateOrderStatus=l.translateOrderStatus;exports.AccountNavigationMenu=Cs;exports.AddToCartButton=$e;exports.Cart=Qs;exports.CartDrawer=Js;exports.CartIcon=st;exports.Checkout=et;exports.CouponForm=Re;exports.CurrencyProvider=Hs;exports.CurrencySwitcher=tt;exports.CustomerProfileForm=ct;exports.FeaturedProduct=at;exports.ProductCard=vs;exports.ProductDetailsLayout=mt;exports.ProductGallery=Ns;exports.ProductGrid=rt;exports.ProductProvider=ut;exports.SimpleTiptapRenderer=Ye;exports.SubscriptionSelector=ws;exports.getCartItemActivePrice=me;exports.getTrialCheckoutMode=_s;exports.getTrialLabel=ys;exports.getTrialPaymentRequirementLabel=bs;exports.getTrialPeriodDays=Fe;exports.getTrialSummary=ue;exports.useCart=oe;exports.useCartStore=_e;exports.useCartSubtotal=Xe;exports.useCartTotalItems=fs;exports.useCurrency=ne;exports.useCurrencyPreferenceStore=je;exports.useIsCartHydrated=Ks;exports.useProduct=Ps;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const C=require("./lib/components/CartDrawer.cjs.js"),P=require("./lib/components/Cart.cjs.js"),g=require("./lib/components/Checkout.cjs.js"),y=require("./lib/components/CartIcon.cjs.js"),v=require("./lib/components/CouponForm.cjs.js"),S=require("./lib/components/CurrencySwitcher.cjs.js"),T=require("./lib/components/AddToCartButton.cjs.js"),b=require("./lib/components/ProductCard.cjs.js"),p=require("./lib/components/ProductGrid.cjs.js"),I=require("./lib/components/ProductGallery.cjs.js"),D=require("./lib/components/FeaturedProduct.cjs.js"),_=require("./lib/components/CustomerProfileForm.cjs.js"),R=require("./lib/components/SubscriptionSelector.cjs.js"),A=require("./lib/components/InvoiceDocument.cjs.js"),q=require("./lib/components/InvoiceViewerShell.cjs.js"),F=require("./lib/components/AccountNavigationMenu.cjs.js"),E=require("./lib/components/SimpleTiptapRenderer.cjs.js"),L=require("./lib/pages/cms/products/components/ProductForm.cjs.js"),O=require("./lib/pages/cms/products/components/ProductCategorySelector.cjs.js"),u=require("./lib/cart-store.cjs.js"),s=require("./lib/coupons.cjs.js"),l=require("./lib/CurrencyProvider.cjs.js"),e=require("./lib/currency.cjs.js"),f=require("./lib/currency-store.cjs.js"),d=require("./lib/use-cart.cjs.js"),a=require("./lib/customer.cjs.js"),i=require("./lib/types.cjs.js"),n=require("./lib/trials.cjs.js"),t=require("./lib/order-tax-details.cjs.js"),o=require("./lib/invoice.cjs.js"),c=require("./lib/invoice-ui.cjs.js"),z=require("./lib/product-schema.cjs.js"),m=require("./lib/product-context.cjs.js"),V=require("./lib/components/ProductDetailsLayout.cjs.js"),r=require("./lib/variation-utils.cjs.js");exports.CartDrawer=C.CartDrawer;exports.Cart=P.Cart;exports.Checkout=g.Checkout;exports.CartIcon=y.CartIcon;exports.CouponForm=v.CouponForm;exports.CurrencySwitcher=S.CurrencySwitcher;exports.AddToCartButton=T.AddToCartButton;exports.ProductCard=b.ProductCard;exports.ProductGrid=p.ProductGrid;exports.ProductGallery=I.ProductGallery;exports.FeaturedProduct=D.FeaturedProduct;exports.CustomerProfileForm=_.CustomerProfileForm;exports.SubscriptionSelector=R.SubscriptionSelector;exports.InvoiceDocument=A.InvoiceDocument;exports.InvoiceViewerShell=q.InvoiceViewerShell;exports.AccountNavigationMenu=F.AccountNavigationMenu;exports.SimpleTiptapRenderer=E.SimpleTiptapRenderer;exports.ProductForm=L.ProductForm;exports.ProductCategorySelector=O.ProductCategorySelector;exports.getCartItemActivePrice=u.getCartItemActivePrice;exports.useCartStore=u.useCartStore;exports.useCartSubtotal=u.useCartSubtotal;exports.useCartTotalItems=u.useCartTotalItems;exports.emptyProviderDiscounts=s.emptyProviderDiscounts;exports.getCartLineCouponKey=s.getCartLineCouponKey;exports.normalizeCouponCode=s.normalizeCouponCode;exports.CurrencyProvider=l.CurrencyProvider;exports.useCurrency=l.useCurrency;exports.CURRENCY_ROUNDING_MODES=e.CURRENCY_ROUNDING_MODES;exports.applyCurrencyRounding=e.applyCurrencyRounding;exports.convertMinorUnitAmount=e.convertMinorUnitAmount;exports.describeCurrencyRoundingRule=e.describeCurrencyRoundingRule;exports.getCurrencyLookup=e.getCurrencyLookup;exports.getDefaultCurrency=e.getDefaultCurrency;exports.getExchangeRateForCurrency=e.getExchangeRateForCurrency;exports.inferCurrencyCodeFromLocale=e.inferCurrencyCodeFromLocale;exports.isSaleWindowActive=e.isSaleWindowActive;exports.isScheduledPriceDue=e.isScheduledPriceDue;exports.normalizeCurrencyRecord=e.normalizeCurrencyRecord;exports.normalizeCurrencyRoundingMode=e.normalizeCurrencyRoundingMode;exports.normalizePriceMap=e.normalizePriceMap;exports.normalizeSalePriceMap=e.normalizeSalePriceMap;exports.resolveEffectivePriceForCurrency=e.resolveEffectivePriceForCurrency;exports.resolvePriceForCurrency=e.resolvePriceForCurrency;exports.resolvePriceRangeForCurrency=e.resolvePriceRangeForCurrency;exports.sortCurrencies=e.sortCurrencies;exports.useCurrencyPreferenceStore=f.useCurrencyPreferenceStore;exports.useCart=d.useCart;exports.useIsCartHydrated=d.useIsCartHydrated;exports.addressesMatch=a.addressesMatch;exports.emptyCustomerAddress=a.emptyCustomerAddress;exports.isCustomerAddressComplete=a.isCustomerAddressComplete;exports.normalizeCustomerAddress=a.normalizeCustomerAddress;exports.normalizeOrderCustomerDetails=a.normalizeOrderCustomerDetails;exports.DEFAULT_ENABLED_PAYMENT_PROVIDERS=i.DEFAULT_ENABLED_PAYMENT_PROVIDERS;exports.derivePaymentProviderFromProductType=i.derivePaymentProviderFromProductType;exports.getProductPaymentProvider=i.getProductPaymentProvider;exports.isDigitalItem=i.isDigitalItem;exports.isDigitalProduct=i.isDigitalProduct;exports.normalizeEnabledPaymentProviders=i.normalizeEnabledPaymentProviders;exports.getTrialCheckoutMode=n.getTrialCheckoutMode;exports.getTrialLabel=n.getTrialLabel;exports.getTrialPaymentRequirementLabel=n.getTrialPaymentRequirementLabel;exports.getTrialPeriodDays=n.getTrialPeriodDays;exports.getTrialSummary=n.getTrialSummary;exports.aggregateOrderTaxLines=t.aggregateOrderTaxLines;exports.buildOrderTaxDetailsFromCalculation=t.buildOrderTaxDetailsFromCalculation;exports.buildOrderTaxDetailsFromStripeSession=t.buildOrderTaxDetailsFromStripeSession;exports.getOrderTaxRateJurisdiction=t.getOrderTaxRateJurisdiction;exports.getOrderTaxRateLabel=t.getOrderTaxRateLabel;exports.getOrderTaxRatePercentage=t.getOrderTaxRatePercentage;exports.normalizeOrderTaxDetails=t.normalizeOrderTaxDetails;exports.DEFAULT_INVOICE_SETTINGS=o.DEFAULT_INVOICE_SETTINGS;exports.INVOICE_SETTINGS_KEY=o.INVOICE_SETTINGS_KEY;exports.formatInvoiceCurrency=o.formatInvoiceCurrency;exports.formatInvoiceDate=o.formatInvoiceDate;exports.getInvoiceAddressLines=o.getInvoiceAddressLines;exports.normalizeInvoiceSettings=o.normalizeInvoiceSettings;exports.serializeInvoiceSettings=o.serializeInvoiceSettings;exports.buildInvoiceDocumentLabels=c.buildInvoiceDocumentLabels;exports.getInvoiceLocale=c.getInvoiceLocale;exports.localizeInvoicePresentationData=c.localizeInvoicePresentationData;exports.translateOrFallback=c.translateOrFallback;exports.translateOrderStatus=c.translateOrderStatus;exports.productSchema=z.productSchema;exports.ProductProvider=m.ProductProvider;exports.useProduct=m.useProduct;exports.ProductDetailsLayout=V.ProductDetailsLayout;exports.buildCombinationKey=r.buildCombinationKey;exports.buildVariantLabel=r.buildVariantLabel;exports.chooseInitialVariantSelections=r.chooseInitialVariantSelections;exports.extractSelectedTermsByAttribute=r.extractSelectedTermsByAttribute;exports.findMatchingVariant=r.findMatchingVariant;exports.generateVariantDrafts=r.generateVariantDrafts;exports.getAvailableTermIdsForAttribute=r.getAvailableTermIdsForAttribute;exports.getVariantEffectivePriceRange=r.getVariantEffectivePriceRange;exports.mapRawVariantRelations=r.mapRawVariantRelations;exports.normalizeSelectionsToAvailableVariants=r.normalizeSelectionsToAvailableVariants;exports.resolveAttributeName=r.resolveAttributeName;exports.resolveTermValue=r.resolveTermValue;exports.resolveTranslatedText=r.resolveTranslatedText;