@nextblock-cms/ecom 0.0.10 → 0.8.0

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 (147) hide show
  1. package/actions.d.ts +2 -0
  2. package/currency-rest-client-CwoqdgAP.js +23 -0
  3. package/currency-rest-client-uolJxUkL.cjs +1 -0
  4. package/index.cjs.js +1 -0
  5. package/index.d.ts +35 -0
  6. package/index.es.js +3226 -0
  7. package/invoice-ui-BJZfedDd.cjs +332 -0
  8. package/invoice-ui-GJ1ADAjn.js +5759 -0
  9. package/lib/CurrencyProvider.d.ts +18 -0
  10. package/lib/cart-store.d.ts +47 -0
  11. package/lib/components/AccountNavigationMenu.d.ts +14 -0
  12. package/lib/components/AddToCartButton.d.ts +8 -0
  13. package/lib/components/Cart.d.ts +1 -0
  14. package/lib/components/CartDrawer.d.ts +1 -0
  15. package/lib/components/CartIcon.d.ts +1 -0
  16. package/lib/components/Checkout.d.ts +6 -0
  17. package/lib/components/CouponForm.d.ts +8 -0
  18. package/lib/components/CurrencySwitcher.d.ts +1 -0
  19. package/lib/components/CustomerProfileForm.d.ts +21 -0
  20. package/lib/components/FeaturedProduct.d.ts +8 -0
  21. package/lib/components/InvoiceDocument.d.ts +32 -0
  22. package/lib/components/InvoiceViewerShell.d.ts +26 -0
  23. package/lib/components/ProductCard.d.ts +7 -0
  24. package/lib/components/ProductDetailsLayout.d.ts +7 -0
  25. package/lib/components/ProductGallery.d.ts +9 -0
  26. package/lib/components/ProductGrid.d.ts +8 -0
  27. package/lib/components/ShippingEstimator.d.ts +5 -0
  28. package/lib/components/SimpleTiptapRenderer.d.ts +7 -0
  29. package/lib/components/SubscriptionSelector.d.ts +7 -0
  30. package/lib/components/media/MediaImage.d.ts +12 -0
  31. package/lib/components/media/MediaPickerDialog.d.ts +16 -0
  32. package/lib/components/media/MediaUploadForm.d.ts +10 -0
  33. package/lib/components/media/UploadFolderContext.d.ts +10 -0
  34. package/lib/countries.d.ts +5 -0
  35. package/lib/coupon-server.d.ts +22 -0
  36. package/lib/coupon-server.test.d.ts +1 -0
  37. package/lib/coupons.d.ts +41 -0
  38. package/lib/currency-constants.d.ts +1 -0
  39. package/lib/currency-rest-client.d.ts +1 -0
  40. package/lib/currency-sale-schedule.test.d.ts +1 -0
  41. package/lib/currency-store.d.ts +20 -0
  42. package/lib/currency-sync.d.ts +19 -0
  43. package/lib/currency.d.ts +116 -0
  44. package/lib/customer-addresses.d.ts +19 -0
  45. package/lib/customer-orders.d.ts +23 -0
  46. package/lib/customer.d.ts +51 -0
  47. package/lib/export-helpers.d.ts +48 -0
  48. package/lib/factory.d.ts +2 -0
  49. package/lib/freemius-coupons.d.ts +58 -0
  50. package/lib/freemius-order-sync.d.ts +133 -0
  51. package/lib/freemius-order-sync.test.d.ts +1 -0
  52. package/lib/inventory-settings.d.ts +16 -0
  53. package/lib/invoice-server.d.ts +18 -0
  54. package/lib/invoice-ui.d.ts +29 -0
  55. package/lib/invoice.d.ts +75 -0
  56. package/lib/order-inventory.d.ts +7 -0
  57. package/lib/order-tax-details.d.ts +57 -0
  58. package/lib/pages/cms/coupons/CouponEditorForm.d.ts +23 -0
  59. package/lib/pages/cms/coupons/CouponsPage.d.ts +8 -0
  60. package/lib/pages/cms/coupons/CreateCouponDialog.d.ts +6 -0
  61. package/lib/pages/cms/coupons/EditCouponPage.d.ts +5 -0
  62. package/lib/pages/cms/coupons/ProductScopePicker.d.ts +16 -0
  63. package/lib/pages/cms/coupons/actions.d.ts +5 -0
  64. package/lib/pages/cms/coupons/index.d.ts +2 -0
  65. package/lib/pages/cms/coupons/product-options.d.ts +2 -0
  66. package/lib/pages/cms/orders/ExportReportsDialog.d.ts +2 -0
  67. package/lib/pages/cms/orders/MarkPaidButton.d.ts +3 -0
  68. package/lib/pages/cms/orders/OrderDetailPage.d.ts +5 -0
  69. package/lib/pages/cms/orders/OrderPrintButton.d.ts +3 -0
  70. package/lib/pages/cms/orders/OrderStatusForm.d.ts +4 -0
  71. package/lib/pages/cms/orders/OrdersPage.d.ts +6 -0
  72. package/lib/pages/cms/orders/actions.d.ts +7 -0
  73. package/lib/pages/cms/orders/export-actions.d.ts +2 -0
  74. package/lib/pages/cms/orders/index.d.ts +6 -0
  75. package/lib/pages/cms/orders/server-actions.d.ts +11 -0
  76. package/lib/pages/cms/orders/types.d.ts +60 -0
  77. package/lib/pages/cms/payments/PaymentsClient.d.ts +19 -0
  78. package/lib/pages/cms/payments/PaymentsPage.d.ts +1 -0
  79. package/lib/pages/cms/payments/actions.d.ts +4 -0
  80. package/lib/pages/cms/payments/index.d.ts +2 -0
  81. package/lib/pages/cms/payments/queries.d.ts +12 -0
  82. package/lib/pages/cms/products/ProductsPage.d.ts +7 -0
  83. package/lib/pages/cms/products/[id]/edit/EditProductPage.d.ts +12 -0
  84. package/lib/pages/cms/products/actions.d.ts +18201 -0
  85. package/lib/pages/cms/products/attributes/AttributeManagementPage.d.ts +1 -0
  86. package/lib/pages/cms/products/attributes/components/AttributeManager.d.ts +50 -0
  87. package/lib/pages/cms/products/categories/CategoryManagementPage.d.ts +1 -0
  88. package/lib/pages/cms/products/categories/components/CategoryManager.d.ts +47 -0
  89. package/lib/pages/cms/products/components/CopyProductFromLanguage.d.ts +9 -0
  90. package/lib/pages/cms/products/components/CurrencyPriceFields.d.ts +18 -0
  91. package/lib/pages/cms/products/components/DeleteProductButton.d.ts +9 -0
  92. package/lib/pages/cms/products/components/FreemiusPricingDashboard.d.ts +24 -0
  93. package/lib/pages/cms/products/components/ProductCategorySelector.d.ts +14 -0
  94. package/lib/pages/cms/products/components/ProductForm.d.ts +62 -0
  95. package/lib/pages/cms/products/components/ProductMediaManager.d.ts +17 -0
  96. package/lib/pages/cms/products/components/ProductsBulkTable.d.ts +32 -0
  97. package/lib/pages/cms/products/components/SaleScheduleFields.d.ts +16 -0
  98. package/lib/pages/cms/products/components/SyncFreemiusButton.d.ts +3 -0
  99. package/lib/pages/cms/products/components/SyncFreemiusPricingButton.d.ts +5 -0
  100. package/lib/pages/cms/products/components/SyncProductForm.d.ts +1 -0
  101. package/lib/pages/cms/products/components/VariationsEditor.d.ts +26 -0
  102. package/lib/pages/cms/products/index.d.ts +7 -0
  103. package/lib/pages/cms/products/inventory/InventoryPage.d.ts +1 -0
  104. package/lib/pages/cms/products/inventory/InventoryTableClient.d.ts +6 -0
  105. package/lib/pages/cms/products/inventory/actions.d.ts +38 -0
  106. package/lib/pages/cms/products/new/NewProductPage.d.ts +9 -0
  107. package/lib/pages/cms/products/product-price-sync.d.ts +43 -0
  108. package/lib/pages/cms/products/server-actions.d.ts +125 -0
  109. package/lib/pages/cms/shipping/ShippingPage.d.ts +6 -0
  110. package/lib/pages/cms/shipping/components/RateForm.d.ts +26 -0
  111. package/lib/pages/cms/shipping/components/ZoneForm.d.ts +13 -0
  112. package/lib/pages/cms/shipping/index.d.ts +2 -0
  113. package/lib/pages/cms/shipping/server-actions.d.ts +80 -0
  114. package/lib/pages/cms/taxes/TaxesPage.d.ts +5 -0
  115. package/lib/pages/cms/taxes/actions.d.ts +3 -0
  116. package/lib/pages/cms/taxes/components/TaxRateForm.d.ts +8 -0
  117. package/lib/pages/cms/taxes/index.d.ts +2 -0
  118. package/lib/product-actions.d.ts +18457 -0
  119. package/lib/product-context.d.ts +7 -0
  120. package/lib/product-schema.d.ts +73 -0
  121. package/lib/providers/freemius.d.ts +49 -0
  122. package/lib/providers/stripe.d.ts +13 -0
  123. package/lib/server-actions/coupon-actions.d.ts +17 -0
  124. package/lib/server-actions/customer-actions.d.ts +18 -0
  125. package/lib/server-actions/product-actions.d.ts +69 -0
  126. package/lib/server-actions/shipping-actions.d.ts +10 -0
  127. package/lib/server-actions/tax-actions.d.ts +7 -0
  128. package/lib/shared-inventory.d.ts +38 -0
  129. package/lib/shipping/resolver.d.ts +16 -0
  130. package/lib/shipping-rate-currency.d.ts +39 -0
  131. package/lib/states.d.ts +9 -0
  132. package/lib/stripe/checkout.d.ts +6 -0
  133. package/lib/stripe/client.d.ts +2 -0
  134. package/lib/stripe/order-sync.d.ts +18 -0
  135. package/lib/stripe/webhooks.d.ts +4 -0
  136. package/lib/tax-calculation.d.ts +23 -0
  137. package/lib/trials.d.ts +15 -0
  138. package/lib/types.d.ts +245 -0
  139. package/lib/use-cart.d.ts +11 -0
  140. package/lib/variation-utils.d.ts +72 -0
  141. package/lib/zod-config.d.ts +2 -0
  142. package/package.json +47 -2
  143. package/server.cjs.js +110 -0
  144. package/server.d.ts +31 -0
  145. package/server.es.js +6039 -0
  146. package/index.ts +0 -12
  147. package/tsconfig.lib.json +0 -10
package/actions.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './lib/server-actions/product-actions';
2
+ export * from './lib/server-actions/customer-actions';
@@ -0,0 +1,23 @@
1
+ async function n() {
2
+ const a = process.env.NEXT_PUBLIC_SUPABASE_URL, r = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY;
3
+ if (!a || !r)
4
+ return [];
5
+ const e = new URL("/rest/v1/currencies", a);
6
+ e.searchParams.set(
7
+ "select",
8
+ "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"
9
+ ), e.searchParams.set("is_active", "eq.true"), e.searchParams.set("order", "code.asc");
10
+ const t = await fetch(e.toString(), {
11
+ headers: {
12
+ apikey: r,
13
+ Authorization: `Bearer ${r}`
14
+ }
15
+ });
16
+ if (!t.ok)
17
+ return [];
18
+ const s = await t.json();
19
+ return Array.isArray(s) ? s : [];
20
+ }
21
+ export {
22
+ n as fetchActiveCurrenciesFromRest
23
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});async function c(){const t=process.env.NEXT_PUBLIC_SUPABASE_URL,r=process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY;if(!t||!r)return[];const e=new URL("/rest/v1/currencies",t);e.searchParams.set("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"),e.searchParams.set("is_active","eq.true"),e.searchParams.set("order","code.asc");const a=await fetch(e.toString(),{headers:{apikey:r,Authorization:`Bearer ${r}`}});if(!a.ok)return[];const s=await a.json();return Array.isArray(s)?s:[]}exports.fetchActiveCurrenciesFromRest=c;
package/index.cjs.js ADDED
@@ -0,0 +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;
package/index.d.ts ADDED
@@ -0,0 +1,35 @@
1
+ export * from './lib/components/CartDrawer';
2
+ export * from './lib/components/Cart';
3
+ export * from './lib/components/Checkout';
4
+ export * from './lib/components/CartIcon';
5
+ export * from './lib/components/CouponForm';
6
+ export * from './lib/components/CurrencySwitcher';
7
+ export * from './lib/components/AddToCartButton';
8
+ export * from './lib/components/ProductCard';
9
+ export * from './lib/components/ProductGrid';
10
+ export * from './lib/components/ProductGallery';
11
+ export * from './lib/components/FeaturedProduct';
12
+ export * from './lib/components/CustomerProfileForm';
13
+ export * from './lib/components/SubscriptionSelector';
14
+ export * from './lib/components/InvoiceDocument';
15
+ export * from './lib/components/InvoiceViewerShell';
16
+ export * from './lib/components/AccountNavigationMenu';
17
+ export * from './lib/components/SimpleTiptapRenderer';
18
+ export { ProductForm } from './lib/pages/cms/products/components/ProductForm';
19
+ export { ProductCategorySelector } from './lib/pages/cms/products/components/ProductCategorySelector';
20
+ export * from './lib/cart-store';
21
+ export * from './lib/coupons';
22
+ export * from './lib/CurrencyProvider';
23
+ export * from './lib/currency';
24
+ export * from './lib/currency-store';
25
+ export * from './lib/use-cart';
26
+ export * from './lib/customer';
27
+ export * from './lib/types';
28
+ export * from './lib/trials';
29
+ export * from './lib/order-tax-details';
30
+ export * from './lib/invoice';
31
+ export * from './lib/invoice-ui';
32
+ export * from './lib/product-schema';
33
+ export * from './lib/product-context';
34
+ export * from './lib/components/ProductDetailsLayout';
35
+ export * from './lib/variation-utils';