@nextblock-cms/ecom 0.20.1 → 0.21.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 (317) hide show
  1. package/_virtual/_rolldown/runtime.cjs.js +1 -0
  2. package/index.cjs.js +1 -1
  3. package/index.es.js +38 -146
  4. package/lib/CurrencyProvider.cjs.js +1 -1
  5. package/lib/CurrencyProvider.d.ts +1 -1
  6. package/lib/CurrencyProvider.es.js +85 -95
  7. package/lib/PaymentReadinessProvider.cjs.js +1 -1
  8. package/lib/PaymentReadinessProvider.d.ts +1 -1
  9. package/lib/PaymentReadinessProvider.es.js +24 -27
  10. package/lib/cart-store.cjs.js +1 -1
  11. package/lib/cart-store.es.js +109 -121
  12. package/lib/components/AccountNavigationMenu.cjs.js +1 -1
  13. package/lib/components/AccountNavigationMenu.d.ts +1 -1
  14. package/lib/components/AccountNavigationMenu.es.js +36 -50
  15. package/lib/components/AddToCartButton.cjs.js +1 -1
  16. package/lib/components/AddToCartButton.d.ts +1 -1
  17. package/lib/components/AddToCartButton.es.js +94 -89
  18. package/lib/components/Cart.cjs.js +1 -1
  19. package/lib/components/Cart.d.ts +1 -1
  20. package/lib/components/Cart.es.js +261 -180
  21. package/lib/components/CartDrawer.cjs.js +1 -1
  22. package/lib/components/CartDrawer.d.ts +1 -1
  23. package/lib/components/CartDrawer.es.js +218 -148
  24. package/lib/components/CartIcon.cjs.js +1 -1
  25. package/lib/components/CartIcon.d.ts +1 -1
  26. package/lib/components/CartIcon.es.js +33 -35
  27. package/lib/components/Checkout.cjs.js +1 -1
  28. package/lib/components/Checkout.d.ts +1 -1
  29. package/lib/components/Checkout.es.js +1092 -1108
  30. package/lib/components/CouponForm.cjs.js +1 -1
  31. package/lib/components/CouponForm.d.ts +1 -1
  32. package/lib/components/CouponForm.es.js +136 -148
  33. package/lib/components/CurrencySwitcher.cjs.js +1 -1
  34. package/lib/components/CurrencySwitcher.d.ts +1 -1
  35. package/lib/components/CurrencySwitcher.es.js +22 -18
  36. package/lib/components/CustomerProfileForm.cjs.js +1 -1
  37. package/lib/components/CustomerProfileForm.es.js +454 -313
  38. package/lib/components/FeaturedProduct.cjs.js +1 -1
  39. package/lib/components/FeaturedProduct.d.ts +1 -1
  40. package/lib/components/FeaturedProduct.es.js +98 -83
  41. package/lib/components/FreemiusLicensePanel.cjs.js +1 -1
  42. package/lib/components/FreemiusLicensePanel.d.ts +1 -1
  43. package/lib/components/FreemiusLicensePanel.es.js +70 -65
  44. package/lib/components/InvoiceDocument.cjs.js +1 -1
  45. package/lib/components/InvoiceDocument.es.js +256 -192
  46. package/lib/components/InvoiceViewerShell.cjs.js +2 -2
  47. package/lib/components/InvoiceViewerShell.d.ts +1 -1
  48. package/lib/components/InvoiceViewerShell.es.js +75 -106
  49. package/lib/components/ProductCard.cjs.js +1 -1
  50. package/lib/components/ProductCard.d.ts +1 -1
  51. package/lib/components/ProductCard.es.js +186 -171
  52. package/lib/components/ProductDetailsLayout.cjs.js +1 -1
  53. package/lib/components/ProductDetailsLayout.es.js +405 -404
  54. package/lib/components/ProductGallery.cjs.js +1 -1
  55. package/lib/components/ProductGallery.d.ts +1 -1
  56. package/lib/components/ProductGallery.es.js +51 -54
  57. package/lib/components/ProductGrid.cjs.js +1 -1
  58. package/lib/components/ProductGrid.d.ts +1 -1
  59. package/lib/components/ProductGrid.es.js +23 -25
  60. package/lib/components/ShippingEstimator.cjs.js +1 -1
  61. package/lib/components/ShippingEstimator.d.ts +1 -1
  62. package/lib/components/ShippingEstimator.es.js +158 -153
  63. package/lib/components/ShortDescription.cjs.js +1 -1
  64. package/lib/components/ShortDescription.es.js +17 -17
  65. package/lib/components/SimpleTiptapRenderer.cjs.js +1 -1
  66. package/lib/components/SimpleTiptapRenderer.es.js +238 -211
  67. package/lib/components/SubscriptionSelector.cjs.js +1 -1
  68. package/lib/components/SubscriptionSelector.es.js +159 -154
  69. package/lib/countries.cjs.js +1 -1
  70. package/lib/countries.es.js +232 -75
  71. package/lib/coupon-server.cjs.js +1 -1
  72. package/lib/coupon-server.es.js +180 -224
  73. package/lib/coupons.cjs.js +1 -1
  74. package/lib/coupons.es.js +12 -14
  75. package/lib/currency-constants.cjs.js +1 -1
  76. package/lib/currency-constants.es.js +4 -4
  77. package/lib/currency-rest-client.cjs.js +1 -1
  78. package/lib/currency-rest-client.es.js +15 -22
  79. package/lib/currency-store.cjs.js +1 -1
  80. package/lib/currency-store.es.js +20 -27
  81. package/lib/currency-sync.cjs.js +1 -1
  82. package/lib/currency-sync.es.js +124 -170
  83. package/lib/currency.cjs.js +1 -1
  84. package/lib/currency.es.js +242 -310
  85. package/lib/customer-addresses.cjs.js +1 -1
  86. package/lib/customer-addresses.es.js +80 -109
  87. package/lib/customer-orders.cjs.js +1 -1
  88. package/lib/customer-orders.es.js +31 -43
  89. package/lib/customer.cjs.js +1 -1
  90. package/lib/customer.es.js +43 -52
  91. package/lib/export-helpers.cjs.js +1 -1
  92. package/lib/export-helpers.es.js +53 -52
  93. package/lib/factory.cjs.js +1 -1
  94. package/lib/factory.es.js +10 -7
  95. package/lib/freemius-coupons.cjs.js +1 -1
  96. package/lib/freemius-coupons.es.js +245 -262
  97. package/lib/freemius-license-claim.cjs.js +1 -1
  98. package/lib/freemius-license-claim.es.js +87 -71
  99. package/lib/freemius-license.cjs.js +1 -1
  100. package/lib/freemius-license.es.js +32 -39
  101. package/lib/freemius-order-sync.cjs.js +1 -1
  102. package/lib/freemius-order-sync.es.js +226 -290
  103. package/lib/freemius-trial-provision.cjs.js +1 -1
  104. package/lib/freemius-trial-provision.es.js +136 -130
  105. package/lib/inventory-settings.cjs.js +1 -1
  106. package/lib/inventory-settings.es.js +69 -77
  107. package/lib/invoice-server.cjs.js +3 -3
  108. package/lib/invoice-server.es.js +94 -141
  109. package/lib/invoice-ui.cjs.js +1 -1
  110. package/lib/invoice-ui.es.js +50 -66
  111. package/lib/invoice.cjs.js +1 -1
  112. package/lib/invoice.es.js +85 -94
  113. package/lib/order-inventory.cjs.js +25 -25
  114. package/lib/order-inventory.es.js +67 -79
  115. package/lib/order-tax-details.cjs.js +1 -1
  116. package/lib/order-tax-details.es.js +142 -153
  117. package/lib/pages/cms/coupons/CouponEditorForm.cjs.js +1 -1
  118. package/lib/pages/cms/coupons/CouponEditorForm.d.ts +1 -1
  119. package/lib/pages/cms/coupons/CouponEditorForm.es.js +227 -185
  120. package/lib/pages/cms/coupons/CouponsPage.cjs.js +2 -2
  121. package/lib/pages/cms/coupons/CouponsPage.d.ts +1 -1
  122. package/lib/pages/cms/coupons/CouponsPage.es.js +235 -166
  123. package/lib/pages/cms/coupons/CreateCouponDialog.cjs.js +1 -1
  124. package/lib/pages/cms/coupons/CreateCouponDialog.d.ts +1 -1
  125. package/lib/pages/cms/coupons/CreateCouponDialog.es.js +35 -34
  126. package/lib/pages/cms/coupons/EditCouponPage.cjs.js +1 -1
  127. package/lib/pages/cms/coupons/EditCouponPage.d.ts +1 -1
  128. package/lib/pages/cms/coupons/EditCouponPage.es.js +47 -47
  129. package/lib/pages/cms/coupons/ProductScopePicker.cjs.js +1 -1
  130. package/lib/pages/cms/coupons/ProductScopePicker.d.ts +1 -1
  131. package/lib/pages/cms/coupons/ProductScopePicker.es.js +128 -117
  132. package/lib/pages/cms/coupons/actions.cjs.js +1 -1
  133. package/lib/pages/cms/coupons/actions.es.js +112 -115
  134. package/lib/pages/cms/coupons/index.cjs.js +1 -0
  135. package/lib/pages/cms/coupons/index.es.js +3 -0
  136. package/lib/pages/cms/coupons/product-options.cjs.js +1 -1
  137. package/lib/pages/cms/coupons/product-options.es.js +21 -23
  138. package/lib/pages/cms/orders/ExportReportsDialog.cjs.js +1 -1
  139. package/lib/pages/cms/orders/ExportReportsDialog.es.js +135 -129
  140. package/lib/pages/cms/orders/MarkPaidButton.d.ts +1 -1
  141. package/lib/pages/cms/orders/OrderDetailPage.cjs.js +1 -1
  142. package/lib/pages/cms/orders/OrderDetailPage.d.ts +1 -1
  143. package/lib/pages/cms/orders/OrderDetailPage.es.js +186 -134
  144. package/lib/pages/cms/orders/OrderPrintButton.cjs.js +1 -1
  145. package/lib/pages/cms/orders/OrderPrintButton.d.ts +1 -1
  146. package/lib/pages/cms/orders/OrderPrintButton.es.js +15 -21
  147. package/lib/pages/cms/orders/OrderStatusForm.cjs.js +1 -1
  148. package/lib/pages/cms/orders/OrderStatusForm.d.ts +1 -1
  149. package/lib/pages/cms/orders/OrderStatusForm.es.js +85 -69
  150. package/lib/pages/cms/orders/OrdersPage.cjs.js +1 -1
  151. package/lib/pages/cms/orders/OrdersPage.d.ts +1 -1
  152. package/lib/pages/cms/orders/OrdersPage.es.js +170 -102
  153. package/lib/pages/cms/orders/actions.cjs.js +3 -3
  154. package/lib/pages/cms/orders/actions.es.js +53 -69
  155. package/lib/pages/cms/orders/export-actions.cjs.js +1 -1
  156. package/lib/pages/cms/orders/export-actions.es.js +23 -26
  157. package/lib/pages/cms/orders/index.cjs.js +1 -0
  158. package/lib/pages/cms/orders/index.es.js +6 -0
  159. package/lib/pages/cms/orders/server-actions.cjs.js +1 -1
  160. package/lib/pages/cms/orders/server-actions.es.js +60 -51
  161. package/lib/pages/cms/payments/PaymentsClient.cjs.js +1 -1
  162. package/lib/pages/cms/payments/PaymentsClient.d.ts +1 -1
  163. package/lib/pages/cms/payments/PaymentsClient.es.js +316 -346
  164. package/lib/pages/cms/payments/PaymentsPage.cjs.js +1 -1
  165. package/lib/pages/cms/payments/PaymentsPage.d.ts +1 -1
  166. package/lib/pages/cms/payments/PaymentsPage.es.js +29 -32
  167. package/lib/pages/cms/payments/actions.cjs.js +1 -1
  168. package/lib/pages/cms/payments/actions.es.js +38 -48
  169. package/lib/pages/cms/payments/index.cjs.js +1 -0
  170. package/lib/pages/cms/payments/index.es.js +3 -0
  171. package/lib/pages/cms/payments/queries.cjs.js +1 -1
  172. package/lib/pages/cms/payments/queries.es.js +38 -48
  173. package/lib/pages/cms/products/ProductsPage.cjs.js +1 -1
  174. package/lib/pages/cms/products/ProductsPage.d.ts +1 -1
  175. package/lib/pages/cms/products/ProductsPage.es.js +63 -66
  176. package/lib/pages/cms/products/[id]/edit/EditProductPage.d.ts +1 -1
  177. package/lib/pages/cms/products/_id_/edit/EditProductPage.cjs.js +1 -1
  178. package/lib/pages/cms/products/_id_/edit/EditProductPage.es.js +138 -155
  179. package/lib/pages/cms/products/actions.cjs.js +4 -4
  180. package/lib/pages/cms/products/actions.es.js +121 -162
  181. package/lib/pages/cms/products/attributes/AttributeManagementPage.cjs.js +1 -1
  182. package/lib/pages/cms/products/attributes/AttributeManagementPage.d.ts +1 -1
  183. package/lib/pages/cms/products/attributes/AttributeManagementPage.es.js +55 -47
  184. package/lib/pages/cms/products/attributes/components/AttributeManager.cjs.js +1 -1
  185. package/lib/pages/cms/products/attributes/components/AttributeManager.d.ts +1 -1
  186. package/lib/pages/cms/products/attributes/components/AttributeManager.es.js +285 -290
  187. package/lib/pages/cms/products/categories/CategoryManagementPage.cjs.js +1 -1
  188. package/lib/pages/cms/products/categories/CategoryManagementPage.d.ts +1 -1
  189. package/lib/pages/cms/products/categories/CategoryManagementPage.es.js +43 -35
  190. package/lib/pages/cms/products/categories/components/CategoryManager.cjs.js +1 -1
  191. package/lib/pages/cms/products/categories/components/CategoryManager.es.js +315 -262
  192. package/lib/pages/cms/products/components/CopyProductFromLanguage.cjs.js +1 -1
  193. package/lib/pages/cms/products/components/CopyProductFromLanguage.es.js +115 -113
  194. package/lib/pages/cms/products/components/CurrencyPriceFields.cjs.js +1 -1
  195. package/lib/pages/cms/products/components/CurrencyPriceFields.d.ts +1 -1
  196. package/lib/pages/cms/products/components/CurrencyPriceFields.es.js +136 -145
  197. package/lib/pages/cms/products/components/DeleteProductButton.cjs.js +1 -1
  198. package/lib/pages/cms/products/components/DeleteProductButton.d.ts +1 -1
  199. package/lib/pages/cms/products/components/DeleteProductButton.es.js +35 -47
  200. package/lib/pages/cms/products/components/FreemiusPricingDashboard.cjs.js +1 -1
  201. package/lib/pages/cms/products/components/FreemiusPricingDashboard.d.ts +1 -1
  202. package/lib/pages/cms/products/components/FreemiusPricingDashboard.es.js +106 -84
  203. package/lib/pages/cms/products/components/ProductCategorySelector.cjs.js +1 -1
  204. package/lib/pages/cms/products/components/ProductCategorySelector.es.js +156 -159
  205. package/lib/pages/cms/products/components/ProductForm.cjs.js +1 -1
  206. package/lib/pages/cms/products/components/ProductForm.es.js +872 -693
  207. package/lib/pages/cms/products/components/ProductMediaManager.cjs.js +1 -1
  208. package/lib/pages/cms/products/components/ProductMediaManager.es.js +106 -103
  209. package/lib/pages/cms/products/components/ProductsBulkTable.cjs.js +1 -1
  210. package/lib/pages/cms/products/components/ProductsBulkTable.d.ts +1 -1
  211. package/lib/pages/cms/products/components/ProductsBulkTable.es.js +303 -294
  212. package/lib/pages/cms/products/components/SaleScheduleFields.cjs.js +1 -1
  213. package/lib/pages/cms/products/components/SaleScheduleFields.d.ts +1 -1
  214. package/lib/pages/cms/products/components/SaleScheduleFields.es.js +111 -134
  215. package/lib/pages/cms/products/components/SyncFreemiusButton.cjs.js +1 -1
  216. package/lib/pages/cms/products/components/SyncFreemiusButton.d.ts +1 -1
  217. package/lib/pages/cms/products/components/SyncFreemiusButton.es.js +29 -35
  218. package/lib/pages/cms/products/components/SyncFreemiusPricingButton.cjs.js +2 -2
  219. package/lib/pages/cms/products/components/SyncFreemiusPricingButton.d.ts +1 -1
  220. package/lib/pages/cms/products/components/SyncFreemiusPricingButton.es.js +36 -48
  221. package/lib/pages/cms/products/components/SyncProductForm.d.ts +1 -1
  222. package/lib/pages/cms/products/components/VariationsEditor.cjs.js +1 -1
  223. package/lib/pages/cms/products/components/VariationsEditor.d.ts +1 -1
  224. package/lib/pages/cms/products/components/VariationsEditor.es.js +396 -405
  225. package/lib/pages/cms/products/index.cjs.js +1 -0
  226. package/lib/pages/cms/products/index.es.js +8 -0
  227. package/lib/pages/cms/products/inventory/InventoryPage.cjs.js +1 -1
  228. package/lib/pages/cms/products/inventory/InventoryPage.d.ts +1 -1
  229. package/lib/pages/cms/products/inventory/InventoryPage.es.js +21 -15
  230. package/lib/pages/cms/products/inventory/InventoryTableClient.cjs.js +2 -2
  231. package/lib/pages/cms/products/inventory/InventoryTableClient.d.ts +1 -1
  232. package/lib/pages/cms/products/inventory/InventoryTableClient.es.js +230 -209
  233. package/lib/pages/cms/products/inventory/actions.cjs.js +3 -3
  234. package/lib/pages/cms/products/inventory/actions.es.js +83 -91
  235. package/lib/pages/cms/products/new/NewProductPage.cjs.js +1 -1
  236. package/lib/pages/cms/products/new/NewProductPage.d.ts +1 -1
  237. package/lib/pages/cms/products/new/NewProductPage.es.js +58 -74
  238. package/lib/pages/cms/products/product-price-sync.cjs.js +1 -1
  239. package/lib/pages/cms/products/product-price-sync.es.js +74 -89
  240. package/lib/pages/cms/products/server-actions.cjs.js +1 -1
  241. package/lib/pages/cms/products/server-actions.es.js +250 -233
  242. package/lib/pages/cms/shipping/ShippingPage.cjs.js +2 -2
  243. package/lib/pages/cms/shipping/ShippingPage.es.js +287 -209
  244. package/lib/pages/cms/shipping/components/RateForm.cjs.js +1 -1
  245. package/lib/pages/cms/shipping/components/RateForm.d.ts +1 -1
  246. package/lib/pages/cms/shipping/components/RateForm.es.js +439 -436
  247. package/lib/pages/cms/shipping/components/ZoneForm.cjs.js +1 -1
  248. package/lib/pages/cms/shipping/components/ZoneForm.es.js +245 -224
  249. package/lib/pages/cms/shipping/index.cjs.js +1 -0
  250. package/lib/pages/cms/shipping/index.es.js +3 -0
  251. package/lib/pages/cms/shipping/server-actions.cjs.js +1 -1
  252. package/lib/pages/cms/shipping/server-actions.es.js +131 -149
  253. package/lib/pages/cms/taxes/TaxesPage.cjs.js +1 -1
  254. package/lib/pages/cms/taxes/TaxesPage.d.ts +1 -1
  255. package/lib/pages/cms/taxes/TaxesPage.es.js +211 -169
  256. package/lib/pages/cms/taxes/actions.cjs.js +1 -1
  257. package/lib/pages/cms/taxes/actions.es.js +41 -53
  258. package/lib/pages/cms/taxes/components/TaxRateForm.cjs.js +1 -1
  259. package/lib/pages/cms/taxes/components/TaxRateForm.d.ts +1 -1
  260. package/lib/pages/cms/taxes/components/TaxRateForm.es.js +112 -99
  261. package/lib/pages/cms/taxes/index.cjs.js +1 -0
  262. package/lib/pages/cms/taxes/index.es.js +3 -0
  263. package/lib/payment-config.cjs.js +1 -1
  264. package/lib/payment-config.es.js +110 -126
  265. package/lib/product-actions.cjs.js +4 -4
  266. package/lib/product-actions.es.js +289 -544
  267. package/lib/product-context.cjs.js +1 -1
  268. package/lib/product-context.es.js +13 -15
  269. package/lib/product-schema.cjs.js +1 -1
  270. package/lib/product-schema.es.js +99 -134
  271. package/lib/providers/freemius.cjs.js +1 -5
  272. package/lib/providers/freemius.es.js +446 -530
  273. package/lib/providers/stripe.cjs.js +1 -1
  274. package/lib/providers/stripe.es.js +417 -477
  275. package/lib/server-actions/coupon-actions.cjs.js +1 -1
  276. package/lib/server-actions/coupon-actions.es.js +22 -22
  277. package/lib/server-actions/customer-actions.cjs.js +1 -1
  278. package/lib/server-actions/customer-actions.es.js +26 -28
  279. package/lib/server-actions/product-actions.cjs.js +1 -1
  280. package/lib/server-actions/product-actions.es.js +9 -15
  281. package/lib/server-actions/shipping-actions.cjs.js +1 -1
  282. package/lib/server-actions/shipping-actions.es.js +27 -24
  283. package/lib/server-actions/tax-actions.cjs.js +1 -1
  284. package/lib/server-actions/tax-actions.es.js +33 -39
  285. package/lib/shared-inventory.cjs.js +2 -2
  286. package/lib/shared-inventory.es.js +111 -160
  287. package/lib/shipping/resolver.cjs.js +2 -2
  288. package/lib/shipping/resolver.es.js +44 -61
  289. package/lib/shipping-rate-currency.cjs.js +1 -1
  290. package/lib/shipping-rate-currency.es.js +52 -67
  291. package/lib/states.cjs.js +1 -1
  292. package/lib/states.es.js +333 -154
  293. package/lib/stripe/checkout.cjs.js +1 -1
  294. package/lib/stripe/checkout.es.js +125 -181
  295. package/lib/stripe/client.cjs.js +1 -1
  296. package/lib/stripe/client.es.js +14 -19
  297. package/lib/stripe/order-sync.cjs.js +1 -1
  298. package/lib/stripe/order-sync.es.js +106 -126
  299. package/lib/stripe/webhooks.cjs.js +1 -1
  300. package/lib/stripe/webhooks.es.js +37 -31
  301. package/lib/tax-calculation.cjs.js +1 -1
  302. package/lib/tax-calculation.es.js +84 -98
  303. package/lib/trials.cjs.js +1 -1
  304. package/lib/trials.es.js +24 -30
  305. package/lib/types.cjs.js +1 -1
  306. package/lib/types.es.js +21 -27
  307. package/lib/use-cart.cjs.js +1 -1
  308. package/lib/use-cart.es.js +38 -40
  309. package/lib/use-price-formatter.cjs.js +1 -1
  310. package/lib/use-price-formatter.es.js +10 -11
  311. package/lib/variation-utils.cjs.js +1 -1
  312. package/lib/variation-utils.es.js +199 -261
  313. package/lib/zod-config.cjs.js +1 -1
  314. package/lib/zod-config.es.js +5 -6
  315. package/package.json +16 -16
  316. package/server.cjs.js +1 -1
  317. package/server.es.js +56 -211
@@ -1,408 +1,399 @@
1
- 'use client';
2
- import { jsxs as i, jsx as o } from "react/jsx-runtime";
3
- import F from "next/link";
4
- import { useState as R, useMemo as E, useEffect as v } from "react";
5
- import { Badge as D, Button as z, Label as P, Input as U } from "@nextblock-cms/ui";
6
- import { extractSelectedTermsByAttribute as re, resolveTermValue as L, resolveAttributeName as q, generateVariantDrafts as ne } from "../../../../variation-utils.es.js";
7
- import { CurrencyPriceFields as oe } from "./CurrencyPriceFields.es.js";
8
- import { SaleScheduleFields as se } from "./SaleScheduleFields.es.js";
9
- import { normalizeSalePriceMap as ie, normalizePriceMap as de, convertMinorUnitAmount as I } from "../../../../currency.es.js";
10
- import { sanitizeVariantDraftsForStoreManagedCurrencies as K, getStoreManagedPriceCurrencyCodes as ce, resolveEditorCurrencyPriceMaps as le } from "../product-price-sync.es.js";
11
- import { majorUnitAmountToMinor as X, minorUnitAmountToMajor as G } from "@nextblock-cms/utils";
12
- const O = process.env.NEXT_PUBLIC_R2_BASE_URL || "", Q = process.env.NEXT_PUBLIC_SUPABASE_URL || "", ae = (c) => c.startsWith("http") ? c : O ? `${O.replace(/\/+$/, "")}/${c.replace(/^\/+/, "")}` : Q ? `${Q.replace(/\/+$/, "")}/storage/v1/object/public/media/${c.replace(/^\/+/, "")}` : c;
13
- function W(c, m = "USD") {
14
- return new Intl.NumberFormat("en-US", {
15
- style: "currency",
16
- currency: m
17
- }).format(c);
1
+ "use client";
2
+ import { convertMinorUnitAmount as e, normalizePriceMap as t, normalizeSalePriceMap as n } from "../../../../currency.es.js";
3
+ import { extractSelectedTermsByAttribute as r, generateVariantDrafts as i, resolveAttributeName as a, resolveTermValue as o } from "../../../../variation-utils.es.js";
4
+ import { CurrencyPriceFields as s } from "./CurrencyPriceFields.es.js";
5
+ import { SaleScheduleFields as c } from "./SaleScheduleFields.es.js";
6
+ import { getStoreManagedPriceCurrencyCodes as l, resolveEditorCurrencyPriceMaps as u, sanitizeVariantDraftsForStoreManagedCurrencies as d } from "../product-price-sync.es.js";
7
+ import f from "next/link";
8
+ import { useEffect as p, useMemo as m, useState as h } from "react";
9
+ import { majorUnitAmountToMinor as g, minorUnitAmountToMajor as _ } from "@nextblock-cms/utils";
10
+ import { jsx as v, jsxs as y } from "react/jsx-runtime";
11
+ import { Badge as b, Button as x, Input as S, Label as C } from "@nextblock-cms/ui";
12
+ //#region libs/ecommerce/src/lib/pages/cms/products/components/VariationsEditor.tsx
13
+ var w = process.env.NEXT_PUBLIC_R2_BASE_URL || "", T = process.env.NEXT_PUBLIC_SUPABASE_URL || "", E = (e) => e.startsWith("http") ? e : w ? `${w.replace(/\/+$/, "")}/${e.replace(/^\/+/, "")}` : T ? `${T.replace(/\/+$/, "")}/storage/v1/object/public/media/${e.replace(/^\/+/, "")}` : e;
14
+ function D(e, t = "USD") {
15
+ return new Intl.NumberFormat("en-US", {
16
+ style: "currency",
17
+ currency: t
18
+ }).format(e);
18
19
  }
19
- function me(c) {
20
- return Object.entries(c).filter(([, m]) => m.length > 0).map(([m, _]) => ({ attribute_id: m, term_ids: _ }));
20
+ function O(e) {
21
+ return Object.entries(e).filter(([, e]) => e.length > 0).map(([e, t]) => ({
22
+ attribute_id: e,
23
+ term_ids: t
24
+ }));
21
25
  }
22
- function Ne({
23
- globalAttributes: c,
24
- currentLanguageCode: m,
25
- baseSku: _,
26
- basePrice: $,
27
- basePrices: M,
28
- baseSalePrice: w,
29
- baseSalePrices: A,
30
- currencies: d,
31
- availableVariantImages: x = [],
32
- initialVariationAttributes: b,
33
- initialVariants: T,
34
- onChange: B
35
- }) {
36
- const [g, H] = R(() => b && b.length > 0 ? b.reduce((e, r) => (e[r.attribute_id] = r.term_ids, e), {}) : re(T || [])), [h, f] = R(
37
- K(
38
- T || [],
39
- d
40
- )
41
- ), y = E(
42
- () => c.map((e) => ({
43
- attribute_id: e.id,
44
- attribute_name: q(e, m),
45
- terms: e.terms.filter((r) => (g[e.id] || []).includes(r.id)).map((r) => ({
46
- ...r,
47
- value: L(r, m)
48
- }))
49
- })).filter((e) => e.terms.length > 0),
50
- [m, c, g]
51
- );
52
- v(() => {
53
- if (y.length === 0) {
54
- f([]);
55
- return;
56
- }
57
- f(
58
- (e) => K(
59
- ne({
60
- baseSku: _,
61
- basePrice: $,
62
- basePrices: de(M),
63
- baseSalePrice: w,
64
- baseSalePrices: ie(A),
65
- selectedAttributes: y,
66
- previousVariants: e
67
- }),
68
- d
69
- )
70
- );
71
- }, [$, M, w, A, _, d, y]), v(() => {
72
- B({
73
- variationAttributes: me(g),
74
- variants: h
75
- });
76
- }, [B, g, h]);
77
- const J = h.reduce(
78
- (e, r) => e + (r.stock_quantity || 0),
79
- 0
80
- ), k = d.find((e) => e.is_default) ?? d[0], N = E(
81
- () => ce(d),
82
- [d]
83
- ), Y = (e, r) => {
84
- H((t) => {
85
- const n = new Set(t[e] || []);
86
- return n.has(r) ? n.delete(r) : n.add(r), {
87
- ...t,
88
- [e]: [...n]
89
- };
90
- });
91
- }, C = (e, r, t) => {
92
- f(
93
- (n) => n.map((s) => {
94
- if (s.combination_key !== e)
95
- return s;
96
- if (r === "sku")
97
- return {
98
- ...s,
99
- sku: t
100
- };
101
- if (r === "upc")
102
- return {
103
- ...s,
104
- upc: t
105
- };
106
- if (r === "sale_price" && t === "")
107
- return {
108
- ...s,
109
- sale_price: null
110
- };
111
- if (r === "prices" || r === "sale_prices")
112
- return s;
113
- const l = t === "" ? 0 : Number(t);
114
- return {
115
- ...s,
116
- [r]: Number.isFinite(l) ? l : 0
117
- };
118
- })
119
- );
120
- }, Z = (e, r, t) => {
121
- f(
122
- (n) => n.map(
123
- (s) => s.combination_key === e ? { ...s, [r]: t } : s
124
- )
125
- );
126
- }, V = (e, r, t, n) => {
127
- const s = d.find((l) => l.is_default) ?? d[0];
128
- f(
129
- (l) => l.map((p) => {
130
- if (p.combination_key !== e)
131
- return p;
132
- const u = {
133
- ...t === "prices" ? p.prices : p.sale_prices,
134
- [r]: n
135
- };
136
- return {
137
- ...p,
138
- [t]: u,
139
- ...r === s?.code ? t === "prices" ? { price: n ?? 0 } : { sale_price: n } : {}
140
- };
141
- })
142
- );
143
- }, ee = (e) => {
144
- const r = d.find((n) => n.is_default) ?? d[0], t = new Set(N);
145
- r && f(
146
- (n) => n.map((s) => {
147
- if (s.combination_key !== e)
148
- return s;
149
- const l = d.reduce((u, a) => {
150
- if (a.code !== r.code && t.has(a.code))
151
- return u;
152
- const S = I({
153
- amount: X(s.price, r.code),
154
- fromCurrencyCode: r.code,
155
- toCurrencyCode: a.code,
156
- currencies: d,
157
- applyRounding: !0
158
- });
159
- return u[a.code] = G(S, a.code), u;
160
- }, {}), p = d.reduce(
161
- (u, a) => {
162
- if (a.code !== r.code && t.has(a.code))
163
- return u;
164
- if (typeof s.sale_price != "number")
165
- return u[a.code] = null, u;
166
- const S = I({
167
- amount: X(s.sale_price, r.code),
168
- fromCurrencyCode: r.code,
169
- toCurrencyCode: a.code,
170
- currencies: d,
171
- applyRounding: !0
172
- });
173
- return u[a.code] = G(S, a.code), u;
174
- },
175
- {}
176
- );
177
- return {
178
- ...s,
179
- prices: l,
180
- sale_prices: p
181
- };
182
- })
183
- );
184
- }, te = (e, r) => {
185
- const t = x.find((l) => l.media_id === r);
186
- if (!t)
187
- return;
188
- const n = t.file_path, s = ae(n);
189
- f(
190
- (l) => l.map(
191
- (p) => p.combination_key === e ? {
192
- ...p,
193
- main_media_id: t.media_id,
194
- main_image_url: s
195
- } : p
196
- )
197
- );
198
- }, j = (e) => {
199
- f(
200
- (r) => r.map(
201
- (t) => t.combination_key === e ? {
202
- ...t,
203
- main_media_id: null,
204
- main_image_url: null
205
- } : t
206
- )
207
- );
208
- };
209
- return c.length === 0 ? /* @__PURE__ */ i("div", { className: "rounded-lg border border-dashed p-6 text-sm text-muted-foreground", children: [
210
- "No global attributes have been created yet. Create them first in",
211
- " ",
212
- /* @__PURE__ */ o(F, { href: "/cms/products/attributes", className: "font-medium text-primary underline-offset-4 hover:underline", children: "Attribute Management" }),
213
- "."
214
- ] }) : /* @__PURE__ */ i("div", { className: "space-y-3", children: [
215
- /* @__PURE__ */ i("div", { className: "space-y-2", children: [
216
- /* @__PURE__ */ i("div", { className: "flex items-center justify-between gap-3", children: [
217
- /* @__PURE__ */ i("div", { className: "flex items-center gap-3", children: [
218
- /* @__PURE__ */ o("span", { className: "text-xs uppercase font-bold text-muted-foreground tracking-wider leading-none", children: "Attributes" }),
219
- /* @__PURE__ */ i(D, { variant: "outline", className: "text-[10px] px-1.5 h-4", children: [
220
- h.length,
221
- " variants"
222
- ] }),
223
- /* @__PURE__ */ i(D, { variant: "secondary", className: "text-[10px] px-1.5 h-4", children: [
224
- "Stock: ",
225
- J
226
- ] })
227
- ] }),
228
- /* @__PURE__ */ o(z, { asChild: !0, variant: "outline", size: "sm", className: "h-7 text-xs px-3", children: /* @__PURE__ */ o(F, { href: "/cms/products/attributes", children: "Manage" }) })
229
- ] }),
230
- /* @__PURE__ */ o("div", { className: "grid gap-2 lg:grid-cols-2", children: c.map((e) => {
231
- const r = g[e.id] || [];
232
- return /* @__PURE__ */ i("div", { className: "flex items-center gap-3 rounded border p-2.5", children: [
233
- /* @__PURE__ */ i("div", { className: "shrink-0 w-[100px]", children: [
234
- /* @__PURE__ */ o("span", { className: "text-sm font-bold block leading-tight", children: q(e, m) }),
235
- /* @__PURE__ */ i("span", { className: "text-[10px] text-muted-foreground leading-none", children: [
236
- r.length,
237
- " selected"
238
- ] })
239
- ] }),
240
- /* @__PURE__ */ o("div", { className: "flex flex-wrap gap-1.5 flex-1", children: e.terms.map((t) => {
241
- const n = r.includes(t.id);
242
- return /* @__PURE__ */ o(
243
- "button",
244
- {
245
- type: "button",
246
- onClick: () => Y(e.id, t.id),
247
- className: `rounded-full border px-2.5 py-0.5 text-[11px] font-medium transition-colors ${n ? "border-primary bg-primary/10 text-primary" : "border-border bg-background text-foreground hover:border-primary/40"}`,
248
- children: L(t, m)
249
- },
250
- t.id
251
- );
252
- }) })
253
- ] }, e.id);
254
- }) })
255
- ] }),
256
- h.length === 0 ? /* @__PURE__ */ o("div", { className: "rounded border border-dashed p-3 text-xs text-muted-foreground text-center", children: "Select terms above to generate variations." }) : /* @__PURE__ */ o("div", { className: "space-y-2", children: h.map((e) => {
257
- const r = le({
258
- currencies: d,
259
- prices: e.prices || {},
260
- salePrices: e.sale_prices || {},
261
- fallbackPrice: e.price,
262
- fallbackSalePrice: e.sale_price
263
- });
264
- return /* @__PURE__ */ i("div", { className: "rounded border p-3 space-y-2", children: [
265
- /* @__PURE__ */ i("div", { className: "flex items-center justify-between gap-3", children: [
266
- /* @__PURE__ */ i("div", { className: "flex items-center gap-2", children: [
267
- /* @__PURE__ */ o("span", { className: "text-sm font-bold", children: e.label }),
268
- /* @__PURE__ */ o("span", { className: "text-xs text-muted-foreground", children: e.selected_options.map((t) => `${t.attribute_name}: ${t.term_value}`).join(" · ") })
269
- ] }),
270
- /* @__PURE__ */ i("div", { className: "flex items-center gap-3 text-xs text-muted-foreground", children: [
271
- /* @__PURE__ */ i("span", { children: [
272
- "Reg: ",
273
- W(e.price, k?.code || "USD")
274
- ] }),
275
- /* @__PURE__ */ i("span", { children: [
276
- "Sale:",
277
- " ",
278
- e.sale_price !== null && e.sale_price !== void 0 ? W(e.sale_price, k?.code || "USD") : "—"
279
- ] })
280
- ] })
281
- ] }),
282
- /* @__PURE__ */ i("div", { className: "grid grid-cols-3 gap-2.5", children: [
283
- /* @__PURE__ */ i("div", { className: "flex items-center gap-2", children: [
284
- /* @__PURE__ */ o(P, { htmlFor: `variant-sku-${e.combination_key}`, className: "text-xs uppercase font-bold text-muted-foreground tracking-wider shrink-0", children: "SKU" }),
285
- /* @__PURE__ */ o(
286
- U,
287
- {
288
- id: `variant-sku-${e.combination_key}`,
289
- value: e.sku,
290
- onChange: (t) => C(e.combination_key, "sku", t.target.value),
291
- placeholder: "SKU",
292
- className: "h-8 text-sm font-mono"
293
- }
294
- )
295
- ] }),
296
- /* @__PURE__ */ i("div", { className: "flex items-center gap-2", children: [
297
- /* @__PURE__ */ o(P, { htmlFor: `variant-upc-${e.combination_key}`, className: "text-xs uppercase font-bold text-muted-foreground tracking-wider shrink-0", children: "UPC" }),
298
- /* @__PURE__ */ o(
299
- U,
300
- {
301
- id: `variant-upc-${e.combination_key}`,
302
- value: e.upc ?? "",
303
- onChange: (t) => C(e.combination_key, "upc", t.target.value),
304
- placeholder: "—",
305
- className: "h-8 text-sm font-mono"
306
- }
307
- )
308
- ] }),
309
- /* @__PURE__ */ i("div", { className: "flex items-center gap-2", children: [
310
- /* @__PURE__ */ o(P, { htmlFor: `variant-stock-${e.combination_key}`, className: "text-xs uppercase font-bold text-muted-foreground tracking-wider shrink-0", children: "Qty" }),
311
- /* @__PURE__ */ o(
312
- U,
313
- {
314
- id: `variant-stock-${e.combination_key}`,
315
- type: "number",
316
- min: "0",
317
- value: e.stock_quantity,
318
- onChange: (t) => C(
319
- e.combination_key,
320
- "stock_quantity",
321
- t.target.value
322
- ),
323
- className: "h-8 text-sm font-mono w-20"
324
- }
325
- )
326
- ] })
327
- ] }),
328
- /* @__PURE__ */ o(
329
- oe,
330
- {
331
- idPrefix: `variant-${e.combination_key}`,
332
- currencies: d,
333
- prices: r.prices,
334
- salePrices: r.salePrices,
335
- managedCurrencyCodes: N,
336
- onPriceChange: (t, n) => V(
337
- e.combination_key,
338
- t,
339
- "prices",
340
- n
341
- ),
342
- onSalePriceChange: (t, n) => V(
343
- e.combination_key,
344
- t,
345
- "sale_prices",
346
- n
347
- ),
348
- onAutoFill: () => ee(e.combination_key),
349
- helperText: N.length > 0 ? `Store-managed currencies derive from ${k?.code || "the base currency"}.` : void 0,
350
- trailing: /* @__PURE__ */ o(
351
- se,
352
- {
353
- idPrefix: `variant-${e.combination_key}`,
354
- startAt: e.sale_start_at,
355
- endAt: e.sale_end_at,
356
- onChange: (t, n) => Z(e.combination_key, t, n),
357
- bare: !0
358
- }
359
- )
360
- }
361
- ),
362
- /* @__PURE__ */ i("div", { className: "flex items-center gap-3 pt-1.5 border-t border-muted/30", children: [
363
- e.main_image_url && /* @__PURE__ */ o("div", { className: "h-9 w-9 overflow-hidden rounded border bg-background shrink-0", children: /* @__PURE__ */ o(
364
- "img",
365
- {
366
- src: e.main_image_url,
367
- alt: `${e.label} image`,
368
- className: "h-full w-full object-cover"
369
- }
370
- ) }),
371
- /* @__PURE__ */ o("span", { className: "text-xs uppercase font-bold text-muted-foreground tracking-wider shrink-0", children: "Image" }),
372
- x.length > 0 ? /* @__PURE__ */ i(
373
- "select",
374
- {
375
- className: "flex h-8 rounded-md border border-input bg-background px-2 py-1 text-sm min-w-[180px]",
376
- value: e.main_media_id ?? "",
377
- onChange: (t) => {
378
- if (!t.target.value) {
379
- j(e.combination_key);
380
- return;
381
- }
382
- te(e.combination_key, t.target.value);
383
- },
384
- children: [
385
- /* @__PURE__ */ o("option", { value: "", children: "Use parent image" }),
386
- x.map((t, n) => /* @__PURE__ */ o("option", { value: t.media_id, children: t.alt?.trim() || `Gallery image ${n + 1}` }, t.media_id))
387
- ]
388
- }
389
- ) : /* @__PURE__ */ o("span", { className: "text-xs text-muted-foreground", children: "Add gallery images first." }),
390
- e.main_media_id && /* @__PURE__ */ o(
391
- z,
392
- {
393
- type: "button",
394
- variant: "ghost",
395
- size: "sm",
396
- className: "h-7 text-xs px-2 text-muted-foreground hover:text-destructive",
397
- onClick: () => j(e.combination_key),
398
- children: "Remove"
399
- }
400
- )
401
- ] })
402
- ] }, e.combination_key);
403
- }) })
404
- ] });
26
+ function k({ globalAttributes: w, currentLanguageCode: T, baseSku: k, basePrice: A, basePrices: j, baseSalePrice: M, baseSalePrices: N, currencies: P, availableVariantImages: F = [], initialVariationAttributes: I, initialVariants: L, onChange: R }) {
27
+ let [z, B] = h(() => I && I.length > 0 ? I.reduce((e, t) => (e[t.attribute_id] = t.term_ids, e), {}) : r(L || [])), [V, H] = h(d(L || [], P)), U = m(() => w.map((e) => ({
28
+ attribute_id: e.id,
29
+ attribute_name: a(e, T),
30
+ terms: e.terms.filter((t) => (z[e.id] || []).includes(t.id)).map((e) => ({
31
+ ...e,
32
+ value: o(e, T)
33
+ }))
34
+ })).filter((e) => e.terms.length > 0), [
35
+ T,
36
+ w,
37
+ z
38
+ ]);
39
+ p(() => {
40
+ if (U.length === 0) {
41
+ H([]);
42
+ return;
43
+ }
44
+ H((e) => d(i({
45
+ baseSku: k,
46
+ basePrice: A,
47
+ basePrices: t(j),
48
+ baseSalePrice: M,
49
+ baseSalePrices: n(N),
50
+ selectedAttributes: U,
51
+ previousVariants: e
52
+ }), P));
53
+ }, [
54
+ A,
55
+ j,
56
+ M,
57
+ N,
58
+ k,
59
+ P,
60
+ U
61
+ ]), p(() => {
62
+ R({
63
+ variationAttributes: O(z),
64
+ variants: V
65
+ });
66
+ }, [
67
+ R,
68
+ z,
69
+ V
70
+ ]);
71
+ let W = V.reduce((e, t) => e + (t.stock_quantity || 0), 0), G = P.find((e) => e.is_default) ?? P[0], K = m(() => l(P), [P]), q = (e, t) => {
72
+ B((n) => {
73
+ let r = new Set(n[e] || []);
74
+ return r.has(t) ? r.delete(t) : r.add(t), {
75
+ ...n,
76
+ [e]: [...r]
77
+ };
78
+ });
79
+ }, J = (e, t, n) => {
80
+ H((r) => r.map((r) => {
81
+ if (r.combination_key !== e) return r;
82
+ if (t === "sku") return {
83
+ ...r,
84
+ sku: n
85
+ };
86
+ if (t === "upc") return {
87
+ ...r,
88
+ upc: n
89
+ };
90
+ if (t === "sale_price" && n === "") return {
91
+ ...r,
92
+ sale_price: null
93
+ };
94
+ if (t === "prices" || t === "sale_prices") return r;
95
+ let i = n === "" ? 0 : Number(n);
96
+ return {
97
+ ...r,
98
+ [t]: Number.isFinite(i) ? i : 0
99
+ };
100
+ }));
101
+ }, Y = (e, t, n) => {
102
+ H((r) => r.map((r) => r.combination_key === e ? {
103
+ ...r,
104
+ [t]: n
105
+ } : r));
106
+ }, X = (e, t, n, r) => {
107
+ let i = P.find((e) => e.is_default) ?? P[0];
108
+ H((a) => a.map((a) => {
109
+ if (a.combination_key !== e) return a;
110
+ let o = {
111
+ ...n === "prices" ? a.prices : a.sale_prices,
112
+ [t]: r
113
+ };
114
+ return {
115
+ ...a,
116
+ [n]: o,
117
+ ...t === i?.code ? n === "prices" ? { price: r ?? 0 } : { sale_price: r } : {}
118
+ };
119
+ }));
120
+ }, Z = (t) => {
121
+ let n = P.find((e) => e.is_default) ?? P[0], r = new Set(K);
122
+ n && H((i) => i.map((i) => {
123
+ if (i.combination_key !== t) return i;
124
+ let a = P.reduce((t, a) => {
125
+ if (a.code !== n.code && r.has(a.code)) return t;
126
+ let o = e({
127
+ amount: g(i.price, n.code),
128
+ fromCurrencyCode: n.code,
129
+ toCurrencyCode: a.code,
130
+ currencies: P,
131
+ applyRounding: !0
132
+ });
133
+ return t[a.code] = _(o, a.code), t;
134
+ }, {}), o = P.reduce((t, a) => {
135
+ if (a.code !== n.code && r.has(a.code)) return t;
136
+ if (typeof i.sale_price != "number") return t[a.code] = null, t;
137
+ let o = e({
138
+ amount: g(i.sale_price, n.code),
139
+ fromCurrencyCode: n.code,
140
+ toCurrencyCode: a.code,
141
+ currencies: P,
142
+ applyRounding: !0
143
+ });
144
+ return t[a.code] = _(o, a.code), t;
145
+ }, {});
146
+ return {
147
+ ...i,
148
+ prices: a,
149
+ sale_prices: o
150
+ };
151
+ }));
152
+ }, Q = (e, t) => {
153
+ let n = F.find((e) => e.media_id === t);
154
+ if (!n) return;
155
+ let r = n.file_path, i = E(r);
156
+ H((t) => t.map((t) => t.combination_key === e ? {
157
+ ...t,
158
+ main_media_id: n.media_id,
159
+ main_image_url: i
160
+ } : t));
161
+ }, $ = (e) => {
162
+ H((t) => t.map((t) => t.combination_key === e ? {
163
+ ...t,
164
+ main_media_id: null,
165
+ main_image_url: null
166
+ } : t));
167
+ };
168
+ return w.length === 0 ? /* @__PURE__ */ y("div", {
169
+ className: "rounded-lg border border-dashed p-6 text-sm text-muted-foreground",
170
+ children: [
171
+ "No global attributes have been created yet. Create them first in",
172
+ " ",
173
+ /* @__PURE__ */ v(f, {
174
+ href: "/cms/products/attributes",
175
+ className: "font-medium text-primary underline-offset-4 hover:underline",
176
+ children: "Attribute Management"
177
+ }),
178
+ "."
179
+ ]
180
+ }) : /* @__PURE__ */ y("div", {
181
+ className: "space-y-3",
182
+ children: [/* @__PURE__ */ y("div", {
183
+ className: "space-y-2",
184
+ children: [/* @__PURE__ */ y("div", {
185
+ className: "flex items-center justify-between gap-3",
186
+ children: [/* @__PURE__ */ y("div", {
187
+ className: "flex items-center gap-3",
188
+ children: [
189
+ /* @__PURE__ */ v("span", {
190
+ className: "text-xs uppercase font-bold text-muted-foreground tracking-wider leading-none",
191
+ children: "Attributes"
192
+ }),
193
+ /* @__PURE__ */ y(b, {
194
+ variant: "outline",
195
+ className: "text-[10px] px-1.5 h-4",
196
+ children: [V.length, " variants"]
197
+ }),
198
+ /* @__PURE__ */ y(b, {
199
+ variant: "secondary",
200
+ className: "text-[10px] px-1.5 h-4",
201
+ children: ["Stock: ", W]
202
+ })
203
+ ]
204
+ }), /* @__PURE__ */ v(x, {
205
+ asChild: !0,
206
+ variant: "outline",
207
+ size: "sm",
208
+ className: "h-7 text-xs px-3",
209
+ children: /* @__PURE__ */ v(f, {
210
+ href: "/cms/products/attributes",
211
+ children: "Manage"
212
+ })
213
+ })]
214
+ }), /* @__PURE__ */ v("div", {
215
+ className: "grid gap-2 lg:grid-cols-2",
216
+ children: w.map((e) => {
217
+ let t = z[e.id] || [];
218
+ return /* @__PURE__ */ y("div", {
219
+ className: "flex items-center gap-3 rounded border p-2.5",
220
+ children: [/* @__PURE__ */ y("div", {
221
+ className: "shrink-0 w-[100px]",
222
+ children: [/* @__PURE__ */ v("span", {
223
+ className: "text-sm font-bold block leading-tight",
224
+ children: a(e, T)
225
+ }), /* @__PURE__ */ y("span", {
226
+ className: "text-[10px] text-muted-foreground leading-none",
227
+ children: [t.length, " selected"]
228
+ })]
229
+ }), /* @__PURE__ */ v("div", {
230
+ className: "flex flex-wrap gap-1.5 flex-1",
231
+ children: e.terms.map((n) => {
232
+ let r = t.includes(n.id);
233
+ return /* @__PURE__ */ v("button", {
234
+ type: "button",
235
+ onClick: () => q(e.id, n.id),
236
+ className: `rounded-full border px-2.5 py-0.5 text-[11px] font-medium transition-colors ${r ? "border-primary bg-primary/10 text-primary" : "border-border bg-background text-foreground hover:border-primary/40"}`,
237
+ children: o(n, T)
238
+ }, n.id);
239
+ })
240
+ })]
241
+ }, e.id);
242
+ })
243
+ })]
244
+ }), V.length === 0 ? /* @__PURE__ */ v("div", {
245
+ className: "rounded border border-dashed p-3 text-xs text-muted-foreground text-center",
246
+ children: "Select terms above to generate variations."
247
+ }) : /* @__PURE__ */ v("div", {
248
+ className: "space-y-2",
249
+ children: V.map((e) => {
250
+ let t = u({
251
+ currencies: P,
252
+ prices: e.prices || {},
253
+ salePrices: e.sale_prices || {},
254
+ fallbackPrice: e.price,
255
+ fallbackSalePrice: e.sale_price
256
+ });
257
+ return /* @__PURE__ */ y("div", {
258
+ className: "rounded border p-3 space-y-2",
259
+ children: [
260
+ /* @__PURE__ */ y("div", {
261
+ className: "flex items-center justify-between gap-3",
262
+ children: [/* @__PURE__ */ y("div", {
263
+ className: "flex items-center gap-2",
264
+ children: [/* @__PURE__ */ v("span", {
265
+ className: "text-sm font-bold",
266
+ children: e.label
267
+ }), /* @__PURE__ */ v("span", {
268
+ className: "text-xs text-muted-foreground",
269
+ children: e.selected_options.map((e) => `${e.attribute_name}: ${e.term_value}`).join(" · ")
270
+ })]
271
+ }), /* @__PURE__ */ y("div", {
272
+ className: "flex items-center gap-3 text-xs text-muted-foreground",
273
+ children: [/* @__PURE__ */ y("span", { children: ["Reg: ", D(e.price, G?.code || "USD")] }), /* @__PURE__ */ y("span", { children: [
274
+ "Sale:",
275
+ " ",
276
+ e.sale_price !== null && e.sale_price !== void 0 ? D(e.sale_price, G?.code || "USD") : "—"
277
+ ] })]
278
+ })]
279
+ }),
280
+ /* @__PURE__ */ y("div", {
281
+ className: "grid grid-cols-3 gap-2.5",
282
+ children: [
283
+ /* @__PURE__ */ y("div", {
284
+ className: "flex items-center gap-2",
285
+ children: [/* @__PURE__ */ v(C, {
286
+ htmlFor: `variant-sku-${e.combination_key}`,
287
+ className: "text-xs uppercase font-bold text-muted-foreground tracking-wider shrink-0",
288
+ children: "SKU"
289
+ }), /* @__PURE__ */ v(S, {
290
+ id: `variant-sku-${e.combination_key}`,
291
+ value: e.sku,
292
+ onChange: (t) => J(e.combination_key, "sku", t.target.value),
293
+ placeholder: "SKU",
294
+ className: "h-8 text-sm font-mono"
295
+ })]
296
+ }),
297
+ /* @__PURE__ */ y("div", {
298
+ className: "flex items-center gap-2",
299
+ children: [/* @__PURE__ */ v(C, {
300
+ htmlFor: `variant-upc-${e.combination_key}`,
301
+ className: "text-xs uppercase font-bold text-muted-foreground tracking-wider shrink-0",
302
+ children: "UPC"
303
+ }), /* @__PURE__ */ v(S, {
304
+ id: `variant-upc-${e.combination_key}`,
305
+ value: e.upc ?? "",
306
+ onChange: (t) => J(e.combination_key, "upc", t.target.value),
307
+ placeholder: "—",
308
+ className: "h-8 text-sm font-mono"
309
+ })]
310
+ }),
311
+ /* @__PURE__ */ y("div", {
312
+ className: "flex items-center gap-2",
313
+ children: [/* @__PURE__ */ v(C, {
314
+ htmlFor: `variant-stock-${e.combination_key}`,
315
+ className: "text-xs uppercase font-bold text-muted-foreground tracking-wider shrink-0",
316
+ children: "Qty"
317
+ }), /* @__PURE__ */ v(S, {
318
+ id: `variant-stock-${e.combination_key}`,
319
+ type: "number",
320
+ min: "0",
321
+ value: e.stock_quantity,
322
+ onChange: (t) => J(e.combination_key, "stock_quantity", t.target.value),
323
+ className: "h-8 text-sm font-mono w-20"
324
+ })]
325
+ })
326
+ ]
327
+ }),
328
+ /* @__PURE__ */ v(s, {
329
+ idPrefix: `variant-${e.combination_key}`,
330
+ currencies: P,
331
+ prices: t.prices,
332
+ salePrices: t.salePrices,
333
+ managedCurrencyCodes: K,
334
+ onPriceChange: (t, n) => X(e.combination_key, t, "prices", n),
335
+ onSalePriceChange: (t, n) => X(e.combination_key, t, "sale_prices", n),
336
+ onAutoFill: () => Z(e.combination_key),
337
+ helperText: K.length > 0 ? `Store-managed currencies derive from ${G?.code || "the base currency"}.` : void 0,
338
+ trailing: /* @__PURE__ */ v(c, {
339
+ idPrefix: `variant-${e.combination_key}`,
340
+ startAt: e.sale_start_at,
341
+ endAt: e.sale_end_at,
342
+ onChange: (t, n) => Y(e.combination_key, t, n),
343
+ bare: !0
344
+ })
345
+ }),
346
+ /* @__PURE__ */ y("div", {
347
+ className: "flex items-center gap-3 pt-1.5 border-t border-muted/30",
348
+ children: [
349
+ e.main_image_url && /* @__PURE__ */ v("div", {
350
+ className: "h-9 w-9 overflow-hidden rounded border bg-background shrink-0",
351
+ children: /* @__PURE__ */ v("img", {
352
+ src: e.main_image_url,
353
+ alt: `${e.label} image`,
354
+ className: "h-full w-full object-cover"
355
+ })
356
+ }),
357
+ /* @__PURE__ */ v("span", {
358
+ className: "text-xs uppercase font-bold text-muted-foreground tracking-wider shrink-0",
359
+ children: "Image"
360
+ }),
361
+ F.length > 0 ? /* @__PURE__ */ y("select", {
362
+ className: "flex h-8 rounded-md border border-input bg-background px-2 py-1 text-sm min-w-[180px]",
363
+ value: e.main_media_id ?? "",
364
+ onChange: (t) => {
365
+ if (!t.target.value) {
366
+ $(e.combination_key);
367
+ return;
368
+ }
369
+ Q(e.combination_key, t.target.value);
370
+ },
371
+ children: [/* @__PURE__ */ v("option", {
372
+ value: "",
373
+ children: "Use parent image"
374
+ }), F.map((e, t) => /* @__PURE__ */ v("option", {
375
+ value: e.media_id,
376
+ children: e.alt?.trim() || `Gallery image ${t + 1}`
377
+ }, e.media_id))]
378
+ }) : /* @__PURE__ */ v("span", {
379
+ className: "text-xs text-muted-foreground",
380
+ children: "Add gallery images first."
381
+ }),
382
+ e.main_media_id && /* @__PURE__ */ v(x, {
383
+ type: "button",
384
+ variant: "ghost",
385
+ size: "sm",
386
+ className: "h-7 text-xs px-2 text-muted-foreground hover:text-destructive",
387
+ onClick: () => $(e.combination_key),
388
+ children: "Remove"
389
+ })
390
+ ]
391
+ })
392
+ ]
393
+ }, e.combination_key);
394
+ })
395
+ })]
396
+ });
405
397
  }
406
- export {
407
- Ne as VariationsEditor
408
- };
398
+ //#endregion
399
+ export { k as VariationsEditor };