@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,441 +1,444 @@
1
- 'use client';
2
- import { jsxs as n, jsx as r } from "react/jsx-runtime";
3
- import { useState as h, useMemo as C, useEffect as Y } from "react";
4
- import { Dialog as he, DialogTrigger as pe, Button as z, DialogContent as fe, DialogHeader as ge, DialogTitle as be, DialogDescription as ve, Label as N, Input as O, Select as ee, SelectTrigger as te, SelectValue as re, SelectContent as ne, SelectItem as V, Badge as q, DialogFooter as xe } from "@nextblock-cms/ui";
5
- import { Edit2 as ye, Plus as Ce, Languages as Ne, DollarSign as B, Gift as _e } from "lucide-react";
6
- import { updateShippingRate as Ae, createShippingRate as Se } from "../server-actions.es.js";
7
- import { normalizeCurrencyCode as G, getCurrencyMinorUnitFactor as E, majorUnitAmountToMinor as we, minorUnitAmountToMajor as Me } from "@nextblock-cms/utils";
8
- import { normalizeCurrencyRecord as oe, convertMinorUnitAmount as ae } from "../../../../currency.es.js";
9
- import { normalizeShippingRateCurrencyMode as se, sanitizeShippingRateAmountMaps as ke } from "../../../../shipping-rate-currency.es.js";
10
- function w(u, m) {
11
- if (typeof u != "number")
12
- return "";
13
- const c = Me(u, m);
14
- return E(m) === 1 ? c.toFixed(0) : c.toFixed(2);
1
+ "use client";
2
+ import { convertMinorUnitAmount as e, normalizeCurrencyRecord as t } from "../../../../currency.es.js";
3
+ import { normalizeShippingRateCurrencyMode as n, sanitizeShippingRateAmountMaps as r } from "../../../../shipping-rate-currency.es.js";
4
+ import { createShippingRate as ee, updateShippingRate as te } from "../server-actions.es.js";
5
+ import { useEffect as i, useMemo as a, useState as o } from "react";
6
+ import { DollarSign as s, Edit2 as ne, Gift as re, Languages as ie, Plus as ae } from "lucide-react";
7
+ import { getCurrencyMinorUnitFactor as c, majorUnitAmountToMinor as l, minorUnitAmountToMajor as u, normalizeCurrencyCode as d } from "@nextblock-cms/utils";
8
+ import { jsx as f, jsxs as p } from "react/jsx-runtime";
9
+ import { Badge as m, Button as h, Dialog as oe, DialogContent as se, DialogDescription as ce, DialogFooter as le, DialogHeader as ue, DialogTitle as de, DialogTrigger as fe, Input as g, Label as _, Select as pe, SelectContent as v, SelectItem as y, SelectTrigger as b, SelectValue as x } from "@nextblock-cms/ui";
10
+ //#region libs/ecommerce/src/lib/pages/cms/shipping/components/RateForm.tsx
11
+ function S(e, t) {
12
+ if (typeof e != "number") return "";
13
+ let n = u(e, t);
14
+ return c(t) === 1 ? n.toFixed(0) : n.toFixed(2);
15
15
  }
16
- function Fe(u) {
17
- return u.reduce((m, c) => (m[c.code] = E(c.code) === 1 ? "0" : "0.00", m), {});
16
+ function me(e) {
17
+ return e.reduce((e, t) => (e[t.code] = c(t.code) === 1 ? "0" : "0.00", e), {});
18
18
  }
19
- function _(u, m) {
20
- const c = String(u || "").trim();
21
- if (!c)
22
- return null;
23
- const f = Number(c);
24
- return !Number.isFinite(f) || f < 0 ? null : we(f, m);
19
+ function C(e, t) {
20
+ let n = String(e || "").trim();
21
+ if (!n) return null;
22
+ let r = Number(n);
23
+ return !Number.isFinite(r) || r < 0 ? null : l(r, t);
25
24
  }
26
- function de(u) {
27
- return u.currencies.reduce((m, c) => (m[c.code] = w(
28
- u.amounts[c.code],
29
- c.code
30
- ), m), {});
25
+ function w(e) {
26
+ return e.currencies.reduce((t, n) => (t[n.code] = S(e.amounts[n.code], n.code), t), {});
31
27
  }
32
- function Pe({
33
- zoneId: u,
34
- zoneName: m,
35
- languages: c,
36
- currencies: f = [],
37
- defaultCurrencyCode: ce = "USD",
38
- mode: le = "create",
39
- initialData: l
40
- }) {
41
- const [$, I] = h(!1), A = le === "edit", H = C(
42
- () => c.find((e) => e.is_default) || c[0] || null,
43
- [c]
44
- ), X = C(
45
- () => c.filter((e) => !e.is_default),
46
- [c]
47
- ), M = G(ce), s = C(() => {
48
- const e = oe({
49
- code: M,
50
- symbol: M,
51
- exchange_rate: 1,
52
- is_default: !0,
53
- is_active: !0
54
- }), o = (f.length > 0 ? f : [e]).map((t) => oe(t)).filter((t) => t.is_active !== !1).sort((t, d) => t.is_default !== d.is_default ? t.is_default ? -1 : 1 : t.code.localeCompare(d.code));
55
- return o.length > 0 ? o : [e];
56
- }, [f, M]), g = C(
57
- () => s.find((e) => e.is_default) || s[0],
58
- [s]
59
- ), [k, Z] = h(l?.name || ""), [D, J] = h(
60
- l?.name_translations || {}
61
- ), [b, K] = h(
62
- l?.method_type || "flat_rate"
63
- ), [i, Q] = h(
64
- se(l?.currency_pricing_mode)
65
- ), [a, j] = h(
66
- G(l?.cost_currency || g?.code || M)
67
- ), [v, S] = h({}), [x, F] = h({}), [L, T] = h(!1), P = C(() => {
68
- if (i === "manual")
69
- return s.reduce((t, d) => (t[d.code] = v[d.code] ?? "", t), {});
70
- const e = s.reduce(
71
- (t, d) => (t[d.code] = v[d.code] ?? (d.code === a, ""), t),
72
- {}
73
- ), o = _(
74
- v[a],
75
- a
76
- );
77
- if (o === null)
78
- return e;
79
- for (const t of s) {
80
- if (t.code === a) {
81
- e[t.code] = v[t.code] ?? w(o, t.code);
82
- continue;
83
- }
84
- e[t.code] = w(
85
- ae({
86
- amount: o,
87
- fromCurrencyCode: a,
88
- toCurrencyCode: t.code,
89
- currencies: s
90
- }),
91
- t.code
92
- );
93
- }
94
- return e;
95
- }, [s, v, i, a]), U = C(() => {
96
- if (i === "manual")
97
- return s.reduce((t, d) => (t[d.code] = x[d.code] ?? "", t), {});
98
- const e = s.reduce(
99
- (t, d) => (t[d.code] = x[d.code] ?? "", t),
100
- {}
101
- ), o = _(
102
- x[a],
103
- a
104
- );
105
- if (o === null)
106
- return e;
107
- for (const t of s) {
108
- if (t.code === a) {
109
- e[t.code] = x[t.code] ?? w(o, t.code);
110
- continue;
111
- }
112
- e[t.code] = w(
113
- ae({
114
- amount: o,
115
- fromCurrencyCode: a,
116
- toCurrencyCode: t.code,
117
- currencies: s
118
- }),
119
- t.code
120
- );
121
- }
122
- return e;
123
- }, [s, x, i, a]);
124
- Y(() => {
125
- g && (s.some((e) => e.code === a) || j(g.code));
126
- }, [s, g, a]), Y(() => {
127
- if (!$ || !g)
128
- return;
129
- const e = se(
130
- l?.currency_pricing_mode
131
- ), o = ke({
132
- currencies: s,
133
- mode: e,
134
- sourceCurrencyCode: l?.cost_currency || g.code,
135
- costAmounts: l?.cost_amounts || void 0,
136
- minOrderAmounts: l?.min_order_amounts || void 0,
137
- fallbackCostAmount: l?.cost_amount,
138
- fallbackMinOrderAmount: l?.min_order_amount
139
- });
140
- Z(l?.name || ""), J(l?.name_translations || {}), K(l?.method_type || "flat_rate"), Q(e), j(o.sourceCurrencyCode), S(
141
- de({
142
- amounts: o.costAmounts,
143
- currencies: s
144
- })
145
- ), F(
146
- de({
147
- amounts: o.minOrderAmounts,
148
- currencies: s
149
- })
150
- );
151
- }, [s, g, l, $]);
152
- const ie = (e) => {
153
- e !== i && (e === "manual" && (S(P), F(U)), Q(e));
154
- }, me = (e) => {
155
- const o = G(e);
156
- S((t) => ({
157
- ...t,
158
- [o]: P[o] ?? t[o] ?? ""
159
- })), F((t) => ({
160
- ...t,
161
- [o]: U[o] ?? t[o] ?? ""
162
- })), j(o);
163
- }, ue = (e) => {
164
- K(e), e === "free_shipping" && S(Fe(s));
165
- };
166
- return /* @__PURE__ */ n(he, { open: $, onOpenChange: I, children: [
167
- /* @__PURE__ */ r(pe, { asChild: !0, children: A ? /* @__PURE__ */ r(z, { variant: "ghost", size: "icon", className: "h-7 w-7 text-slate-400 hover:text-primary", children: /* @__PURE__ */ r(ye, { className: "h-3 w-3" }) }) : /* @__PURE__ */ n(z, { variant: "outline", size: "sm", className: "h-8 gap-1.5 border-dashed hover:border-solid shadow-sm", children: [
168
- /* @__PURE__ */ r(Ce, { className: "h-3.5 w-3.5" }),
169
- "Add Rate"
170
- ] }) }),
171
- /* @__PURE__ */ r(fe, { className: "max-h-[85vh] max-w-4xl overflow-y-auto", children: /* @__PURE__ */ n("form", { onSubmit: async (e) => {
172
- e.preventDefault(), T(!0);
173
- const o = {}, t = {};
174
- if (i === "manual")
175
- for (const R of s) {
176
- const p = R.code;
177
- if (b === "free_shipping")
178
- o[p] = 0;
179
- else {
180
- const W = _(
181
- v[p],
182
- p
183
- );
184
- if (W === null) {
185
- T(!1), alert(`Enter a valid shipping cost for ${p}.`);
186
- return;
187
- }
188
- o[p] = W;
189
- }
190
- t[p] = _(x[p], p) ?? 0;
191
- }
192
- else {
193
- const R = b === "free_shipping" ? 0 : _(
194
- v[a],
195
- a
196
- );
197
- if (R === null) {
198
- T(!1), alert(`Enter a valid shipping cost for ${a}.`);
199
- return;
200
- }
201
- o[a] = R, t[a] = _(
202
- x[a],
203
- a
204
- ) ?? 0;
205
- }
206
- const d = {
207
- name: k,
208
- nameTranslations: D,
209
- type: b,
210
- currencyPricingMode: i,
211
- sourceCurrencyCode: a,
212
- costAmounts: o,
213
- minOrderAmounts: t
214
- }, y = A && l?.id ? await Ae(l.id, d) : await Se(u, d);
215
- T(!1), y.success ? I(!1) : y.error && alert(y.error);
216
- }, children: [
217
- /* @__PURE__ */ n(ge, { children: [
218
- /* @__PURE__ */ r(be, { children: A ? "Edit Shipping Rate" : "Add Shipping Rate" }),
219
- /* @__PURE__ */ n(ve, { children: [
220
- "Configure shipping costs and localized labels for matching orders in ",
221
- /* @__PURE__ */ r("strong", { children: m }),
222
- "."
223
- ] })
224
- ] }),
225
- /* @__PURE__ */ n("div", { className: "grid gap-5 py-6", children: [
226
- /* @__PURE__ */ n("div", { className: "space-y-2", children: [
227
- /* @__PURE__ */ n(N, { htmlFor: "rate-name", children: [
228
- "Rate Name",
229
- H ? ` (${H.name})` : ""
230
- ] }),
231
- /* @__PURE__ */ r(
232
- O,
233
- {
234
- id: "rate-name",
235
- value: k,
236
- onChange: (e) => Z(e.target.value),
237
- placeholder: "e.g. Standard, Express, Free Shipping",
238
- required: !0
239
- }
240
- )
241
- ] }),
242
- X.length > 0 && /* @__PURE__ */ n("div", { className: "space-y-4 rounded-xl border bg-slate-50/70 p-4 dark:bg-slate-900/40", children: [
243
- /* @__PURE__ */ n("div", { className: "flex items-center gap-2", children: [
244
- /* @__PURE__ */ r(Ne, { className: "h-4 w-4 text-slate-500" }),
245
- /* @__PURE__ */ n("div", { children: [
246
- /* @__PURE__ */ r("p", { className: "text-sm font-medium", children: "Translations" }),
247
- /* @__PURE__ */ r("p", { className: "text-xs text-muted-foreground", children: "Add translated shipping rate labels for the active storefront languages." })
248
- ] })
249
- ] }),
250
- /* @__PURE__ */ r("div", { className: "grid gap-4 md:grid-cols-2", children: X.map((e) => /* @__PURE__ */ n("div", { className: "space-y-2", children: [
251
- /* @__PURE__ */ r(N, { htmlFor: `rate-name-${e.code}`, children: e.name }),
252
- /* @__PURE__ */ r(
253
- O,
254
- {
255
- id: `rate-name-${e.code}`,
256
- value: D[e.code] || "",
257
- onChange: (o) => J((t) => ({
258
- ...t,
259
- [e.code]: o.target.value
260
- })),
261
- placeholder: k || "Translated label"
262
- }
263
- )
264
- ] }, e.code)) })
265
- ] }),
266
- /* @__PURE__ */ n("div", { className: "space-y-2", children: [
267
- /* @__PURE__ */ r(N, { htmlFor: "type", children: "Method Type" }),
268
- /* @__PURE__ */ n(
269
- ee,
270
- {
271
- value: b,
272
- onValueChange: ue,
273
- children: [
274
- /* @__PURE__ */ r(
275
- te,
276
- {
277
- id: "type",
278
- className: "bg-slate-50/50 dark:bg-slate-900/50",
279
- children: /* @__PURE__ */ r(re, { placeholder: "Select type" })
280
- }
281
- ),
282
- /* @__PURE__ */ n(ne, { children: [
283
- /* @__PURE__ */ r(V, { value: "flat_rate", children: /* @__PURE__ */ n("div", { className: "flex items-center gap-2", children: [
284
- /* @__PURE__ */ r("div", { className: "p-1 min-w-5 h-5 rounded bg-emerald-100 dark:bg-emerald-900/30 text-emerald-600", children: /* @__PURE__ */ r(B, { className: "h-3 w-3" }) }),
285
- /* @__PURE__ */ r("span", { children: "Flat Rate" })
286
- ] }) }),
287
- /* @__PURE__ */ r(V, { value: "free_shipping", children: /* @__PURE__ */ n("div", { className: "flex items-center gap-2", children: [
288
- /* @__PURE__ */ r("div", { className: "p-1 min-w-5 h-5 rounded bg-amber-100 dark:bg-amber-900/30 text-amber-600", children: /* @__PURE__ */ r(_e, { className: "h-3 w-3" }) }),
289
- /* @__PURE__ */ r("span", { children: "Free Shipping" })
290
- ] }) })
291
- ] })
292
- ]
293
- }
294
- )
295
- ] }),
296
- /* @__PURE__ */ n("div", { className: "space-y-3 rounded-xl border bg-slate-50/70 p-4 dark:bg-slate-900/40", children: [
297
- /* @__PURE__ */ n("label", { className: "flex items-start gap-3", children: [
298
- /* @__PURE__ */ r(
299
- "input",
300
- {
301
- type: "checkbox",
302
- checked: i === "auto",
303
- onChange: (e) => ie(
304
- e.target.checked ? "auto" : "manual"
305
- ),
306
- className: "mt-1 h-4 w-4 rounded border-slate-300 text-primary focus:ring-primary"
307
- }
308
- ),
309
- /* @__PURE__ */ n("span", { className: "space-y-1", children: [
310
- /* @__PURE__ */ r("span", { className: "block text-sm font-medium text-slate-900 dark:text-slate-100", children: "Auto-sync all currency rates from one source amount" }),
311
- /* @__PURE__ */ r("span", { className: "block text-xs text-muted-foreground", children: "Turn this off to set exact shipping costs and free-shipping thresholds for every active currency manually." })
312
- ] })
313
- ] }),
314
- i === "auto" ? /* @__PURE__ */ n("div", { className: "space-y-2", children: [
315
- /* @__PURE__ */ r(N, { htmlFor: "rate-currency", children: "Sync From Currency" }),
316
- /* @__PURE__ */ n(
317
- ee,
318
- {
319
- value: a,
320
- onValueChange: me,
321
- children: [
322
- /* @__PURE__ */ r(
323
- te,
324
- {
325
- id: "rate-currency",
326
- className: "bg-background",
327
- children: /* @__PURE__ */ r(re, { placeholder: "Select currency" })
328
- }
329
- ),
330
- /* @__PURE__ */ r(ne, { children: s.map((e) => /* @__PURE__ */ n(V, { value: e.code, children: [
331
- e.code,
332
- e.is_default ? " (Default)" : ""
333
- ] }, e.code)) })
334
- ]
335
- }
336
- ),
337
- /* @__PURE__ */ r("p", { className: "text-[10px] text-slate-500", children: "Enter the source amount once and the other currencies will be derived automatically using the current FX rates." })
338
- ] }) : /* @__PURE__ */ r("p", { className: "text-[10px] text-slate-500", children: "Manual mode stores exact values per currency. This is the best choice when shipping should not follow exchange-rate math directly." })
339
- ] }),
340
- /* @__PURE__ */ n("div", { className: "space-y-3", children: [
341
- /* @__PURE__ */ n("div", { children: [
342
- /* @__PURE__ */ r("p", { className: "text-sm font-medium", children: "Currency Rates" }),
343
- /* @__PURE__ */ r("p", { className: "text-xs text-muted-foreground", children: b === "free_shipping" ? "Free-shipping methods keep cost at zero, but you can still control the threshold per currency." : i === "auto" ? `Only ${a} is editable. The rest are derived automatically.` : "Set the exact shopper-facing shipping price for each active currency." })
344
- ] }),
345
- /* @__PURE__ */ r("div", { className: "grid gap-4 md:grid-cols-2 xl:grid-cols-3", children: s.map((e) => {
346
- const o = i === "auto" && e.code !== a, t = E(e.code) === 1 ? "1" : "0.01";
347
- return /* @__PURE__ */ n(
348
- "div",
349
- {
350
- className: "space-y-4 rounded-xl border bg-card/70 p-4 shadow-sm",
351
- children: [
352
- /* @__PURE__ */ n("div", { className: "flex items-center justify-between gap-2", children: [
353
- /* @__PURE__ */ n("div", { children: [
354
- /* @__PURE__ */ r("p", { className: "font-medium", children: e.code }),
355
- /* @__PURE__ */ n("p", { className: "text-xs text-muted-foreground", children: [
356
- "Rate ",
357
- e.exchange_rate
358
- ] })
359
- ] }),
360
- /* @__PURE__ */ n("div", { className: "flex flex-wrap items-center gap-2", children: [
361
- e.is_default ? /* @__PURE__ */ r(q, { variant: "outline", children: "Default" }) : null,
362
- i === "auto" && e.code === a ? /* @__PURE__ */ r(q, { children: "Source" }) : null,
363
- o ? /* @__PURE__ */ r(q, { variant: "outline", children: "Derived" }) : null
364
- ] })
365
- ] }),
366
- /* @__PURE__ */ n("div", { className: "space-y-2", children: [
367
- /* @__PURE__ */ n(N, { htmlFor: `rate-cost-${e.code}`, children: [
368
- "Cost (",
369
- e.code,
370
- ")"
371
- ] }),
372
- /* @__PURE__ */ n("div", { className: "relative", children: [
373
- /* @__PURE__ */ r(B, { className: "absolute left-2.5 top-2.5 h-4 w-4 text-slate-400" }),
374
- /* @__PURE__ */ r(
375
- O,
376
- {
377
- id: `rate-cost-${e.code}`,
378
- type: "number",
379
- step: t,
380
- min: "0",
381
- value: P[e.code] ?? "",
382
- onChange: (d) => S((y) => ({
383
- ...y,
384
- [e.code]: d.target.value
385
- })),
386
- className: "pl-9 bg-slate-50/50 dark:bg-slate-900/50 disabled:opacity-70",
387
- disabled: b === "free_shipping" || o,
388
- required: b !== "free_shipping" && i === "manual"
389
- }
390
- )
391
- ] })
392
- ] }),
393
- /* @__PURE__ */ n("div", { className: "space-y-2", children: [
394
- /* @__PURE__ */ n(N, { htmlFor: `rate-threshold-${e.code}`, children: [
395
- "Free-Shipping Threshold (",
396
- e.code,
397
- ")"
398
- ] }),
399
- /* @__PURE__ */ n("div", { className: "relative", children: [
400
- /* @__PURE__ */ r(B, { className: "absolute left-2.5 top-2.5 h-4 w-4 text-slate-400" }),
401
- /* @__PURE__ */ r(
402
- O,
403
- {
404
- id: `rate-threshold-${e.code}`,
405
- type: "number",
406
- step: t,
407
- min: "0",
408
- value: U[e.code] ?? "",
409
- onChange: (d) => F((y) => ({
410
- ...y,
411
- [e.code]: d.target.value
412
- })),
413
- className: "pl-9 bg-slate-50/50 dark:bg-slate-900/50 disabled:opacity-70",
414
- disabled: o,
415
- placeholder: E(e.code) === 1 ? "0" : "0.00"
416
- }
417
- )
418
- ] })
419
- ] }),
420
- o ? /* @__PURE__ */ n("p", { className: "text-[10px] text-muted-foreground", children: [
421
- "This currency is synced automatically from ",
422
- a,
423
- "."
424
- ] }) : i === "manual" ? /* @__PURE__ */ r("p", { className: "text-[10px] text-muted-foreground", children: "Enter the exact amount shoppers should see in this currency." }) : null
425
- ]
426
- },
427
- e.code
428
- );
429
- }) })
430
- ] })
431
- ] }),
432
- /* @__PURE__ */ n(xe, { className: "bg-slate-50 dark:bg-slate-900/50 -mx-6 -mb-6 p-4 border-t dark:border-slate-800", children: [
433
- /* @__PURE__ */ r(z, { type: "button", variant: "ghost", onClick: () => I(!1), disabled: L, children: "Cancel" }),
434
- /* @__PURE__ */ r(z, { type: "submit", disabled: L || !k.trim(), children: L ? A ? "Saving..." : "Adding..." : A ? "Save Changes" : "Add Rate" })
435
- ] })
436
- ] }) })
437
- ] });
28
+ function T({ zoneId: l, zoneName: u, languages: T, currencies: E = [], defaultCurrencyCode: he = "USD", mode: ge = "create", initialData: D }) {
29
+ let [O, k] = o(!1), A = ge === "edit", j = a(() => T.find((e) => e.is_default) || T[0] || null, [T]), M = a(() => T.filter((e) => !e.is_default), [T]), N = d(he), P = a(() => {
30
+ let e = t({
31
+ code: N,
32
+ symbol: N,
33
+ exchange_rate: 1,
34
+ is_default: !0,
35
+ is_active: !0
36
+ }), n = (E.length > 0 ? E : [e]).map((e) => t(e)).filter((e) => e.is_active !== !1).sort((e, t) => e.is_default === t.is_default ? e.code.localeCompare(t.code) : e.is_default ? -1 : 1);
37
+ return n.length > 0 ? n : [e];
38
+ }, [E, N]), F = a(() => P.find((e) => e.is_default) || P[0], [P]), [I, L] = o(D?.name || ""), [R, z] = o(D?.name_translations || {}), [B, V] = o(D?.method_type || "flat_rate"), [H, U] = o(n(D?.currency_pricing_mode)), [W, G] = o(d(D?.cost_currency || F?.code || N)), [K, q] = o({}), [J, Y] = o({}), [X, Z] = o(!1), Q = a(() => {
39
+ if (H === "manual") return P.reduce((e, t) => (e[t.code] = K[t.code] ?? "", e), {});
40
+ let t = P.reduce((e, t) => (e[t.code] = K[t.code] ?? (t.code, ""), e), {}), n = C(K[W], W);
41
+ if (n === null) return t;
42
+ for (let r of P) {
43
+ if (r.code === W) {
44
+ t[r.code] = K[r.code] ?? S(n, r.code);
45
+ continue;
46
+ }
47
+ t[r.code] = S(e({
48
+ amount: n,
49
+ fromCurrencyCode: W,
50
+ toCurrencyCode: r.code,
51
+ currencies: P
52
+ }), r.code);
53
+ }
54
+ return t;
55
+ }, [
56
+ P,
57
+ K,
58
+ H,
59
+ W
60
+ ]), $ = a(() => {
61
+ if (H === "manual") return P.reduce((e, t) => (e[t.code] = J[t.code] ?? "", e), {});
62
+ let t = P.reduce((e, t) => (e[t.code] = J[t.code] ?? "", e), {}), n = C(J[W], W);
63
+ if (n === null) return t;
64
+ for (let r of P) {
65
+ if (r.code === W) {
66
+ t[r.code] = J[r.code] ?? S(n, r.code);
67
+ continue;
68
+ }
69
+ t[r.code] = S(e({
70
+ amount: n,
71
+ fromCurrencyCode: W,
72
+ toCurrencyCode: r.code,
73
+ currencies: P
74
+ }), r.code);
75
+ }
76
+ return t;
77
+ }, [
78
+ P,
79
+ J,
80
+ H,
81
+ W
82
+ ]);
83
+ i(() => {
84
+ F && (P.some((e) => e.code === W) || G(F.code));
85
+ }, [
86
+ P,
87
+ F,
88
+ W
89
+ ]), i(() => {
90
+ if (!O || !F) return;
91
+ let e = n(D?.currency_pricing_mode), t = r({
92
+ currencies: P,
93
+ mode: e,
94
+ sourceCurrencyCode: D?.cost_currency || F.code,
95
+ costAmounts: D?.cost_amounts || void 0,
96
+ minOrderAmounts: D?.min_order_amounts || void 0,
97
+ fallbackCostAmount: D?.cost_amount,
98
+ fallbackMinOrderAmount: D?.min_order_amount
99
+ });
100
+ L(D?.name || ""), z(D?.name_translations || {}), V(D?.method_type || "flat_rate"), U(e), G(t.sourceCurrencyCode), q(w({
101
+ amounts: t.costAmounts,
102
+ currencies: P
103
+ })), Y(w({
104
+ amounts: t.minOrderAmounts,
105
+ currencies: P
106
+ }));
107
+ }, [
108
+ P,
109
+ F,
110
+ D,
111
+ O
112
+ ]);
113
+ let _e = (e) => {
114
+ e !== H && (e === "manual" && (q(Q), Y($)), U(e));
115
+ };
116
+ return /* @__PURE__ */ p(oe, {
117
+ open: O,
118
+ onOpenChange: k,
119
+ children: [/* @__PURE__ */ f(fe, {
120
+ asChild: !0,
121
+ children: A ? /* @__PURE__ */ f(h, {
122
+ variant: "ghost",
123
+ size: "icon",
124
+ className: "h-7 w-7 text-slate-400 hover:text-primary",
125
+ children: /* @__PURE__ */ f(ne, { className: "h-3 w-3" })
126
+ }) : /* @__PURE__ */ p(h, {
127
+ variant: "outline",
128
+ size: "sm",
129
+ className: "h-8 gap-1.5 border-dashed hover:border-solid shadow-sm",
130
+ children: [/* @__PURE__ */ f(ae, { className: "h-3.5 w-3.5" }), "Add Rate"]
131
+ })
132
+ }), /* @__PURE__ */ f(se, {
133
+ className: "max-h-[85vh] max-w-4xl overflow-y-auto",
134
+ children: /* @__PURE__ */ p("form", {
135
+ onSubmit: async (e) => {
136
+ e.preventDefault(), Z(!0);
137
+ let t = {}, n = {};
138
+ if (H === "manual") for (let e of P) {
139
+ let r = e.code;
140
+ if (B === "free_shipping") t[r] = 0;
141
+ else {
142
+ let e = C(K[r], r);
143
+ if (e === null) {
144
+ Z(!1), alert(`Enter a valid shipping cost for ${r}.`);
145
+ return;
146
+ }
147
+ t[r] = e;
148
+ }
149
+ n[r] = C(J[r], r) ?? 0;
150
+ }
151
+ else {
152
+ let e = B === "free_shipping" ? 0 : C(K[W], W);
153
+ if (e === null) {
154
+ Z(!1), alert(`Enter a valid shipping cost for ${W}.`);
155
+ return;
156
+ }
157
+ t[W] = e, n[W] = C(J[W], W) ?? 0;
158
+ }
159
+ let r = {
160
+ name: I,
161
+ nameTranslations: R,
162
+ type: B,
163
+ currencyPricingMode: H,
164
+ sourceCurrencyCode: W,
165
+ costAmounts: t,
166
+ minOrderAmounts: n
167
+ }, i = A && D?.id ? await te(D.id, r) : await ee(l, r);
168
+ Z(!1), i.success ? k(!1) : i.error && alert(i.error);
169
+ },
170
+ children: [
171
+ /* @__PURE__ */ p(ue, { children: [/* @__PURE__ */ f(de, { children: A ? "Edit Shipping Rate" : "Add Shipping Rate" }), /* @__PURE__ */ p(ce, { children: [
172
+ "Configure shipping costs and localized labels for matching orders in ",
173
+ /* @__PURE__ */ f("strong", { children: u }),
174
+ "."
175
+ ] })] }),
176
+ /* @__PURE__ */ p("div", {
177
+ className: "grid gap-5 py-6",
178
+ children: [
179
+ /* @__PURE__ */ p("div", {
180
+ className: "space-y-2",
181
+ children: [/* @__PURE__ */ p(_, {
182
+ htmlFor: "rate-name",
183
+ children: ["Rate Name", j ? ` (${j.name})` : ""]
184
+ }), /* @__PURE__ */ f(g, {
185
+ id: "rate-name",
186
+ value: I,
187
+ onChange: (e) => L(e.target.value),
188
+ placeholder: "e.g. Standard, Express, Free Shipping",
189
+ required: !0
190
+ })]
191
+ }),
192
+ M.length > 0 && /* @__PURE__ */ p("div", {
193
+ className: "space-y-4 rounded-xl border bg-slate-50/70 p-4 dark:bg-slate-900/40",
194
+ children: [/* @__PURE__ */ p("div", {
195
+ className: "flex items-center gap-2",
196
+ children: [/* @__PURE__ */ f(ie, { className: "h-4 w-4 text-slate-500" }), /* @__PURE__ */ p("div", { children: [/* @__PURE__ */ f("p", {
197
+ className: "text-sm font-medium",
198
+ children: "Translations"
199
+ }), /* @__PURE__ */ f("p", {
200
+ className: "text-xs text-muted-foreground",
201
+ children: "Add translated shipping rate labels for the active storefront languages."
202
+ })] })]
203
+ }), /* @__PURE__ */ f("div", {
204
+ className: "grid gap-4 md:grid-cols-2",
205
+ children: M.map((e) => /* @__PURE__ */ p("div", {
206
+ className: "space-y-2",
207
+ children: [/* @__PURE__ */ f(_, {
208
+ htmlFor: `rate-name-${e.code}`,
209
+ children: e.name
210
+ }), /* @__PURE__ */ f(g, {
211
+ id: `rate-name-${e.code}`,
212
+ value: R[e.code] || "",
213
+ onChange: (t) => z((n) => ({
214
+ ...n,
215
+ [e.code]: t.target.value
216
+ })),
217
+ placeholder: I || "Translated label"
218
+ })]
219
+ }, e.code))
220
+ })]
221
+ }),
222
+ /* @__PURE__ */ p("div", {
223
+ className: "space-y-2",
224
+ children: [/* @__PURE__ */ f(_, {
225
+ htmlFor: "type",
226
+ children: "Method Type"
227
+ }), /* @__PURE__ */ p(pe, {
228
+ value: B,
229
+ onValueChange: (e) => {
230
+ V(e), e === "free_shipping" && q(me(P));
231
+ },
232
+ children: [/* @__PURE__ */ f(b, {
233
+ id: "type",
234
+ className: "bg-slate-50/50 dark:bg-slate-900/50",
235
+ children: /* @__PURE__ */ f(x, { placeholder: "Select type" })
236
+ }), /* @__PURE__ */ p(v, { children: [/* @__PURE__ */ f(y, {
237
+ value: "flat_rate",
238
+ children: /* @__PURE__ */ p("div", {
239
+ className: "flex items-center gap-2",
240
+ children: [/* @__PURE__ */ f("div", {
241
+ className: "p-1 min-w-5 h-5 rounded bg-emerald-100 dark:bg-emerald-900/30 text-emerald-600",
242
+ children: /* @__PURE__ */ f(s, { className: "h-3 w-3" })
243
+ }), /* @__PURE__ */ f("span", { children: "Flat Rate" })]
244
+ })
245
+ }), /* @__PURE__ */ f(y, {
246
+ value: "free_shipping",
247
+ children: /* @__PURE__ */ p("div", {
248
+ className: "flex items-center gap-2",
249
+ children: [/* @__PURE__ */ f("div", {
250
+ className: "p-1 min-w-5 h-5 rounded bg-amber-100 dark:bg-amber-900/30 text-amber-600",
251
+ children: /* @__PURE__ */ f(re, { className: "h-3 w-3" })
252
+ }), /* @__PURE__ */ f("span", { children: "Free Shipping" })]
253
+ })
254
+ })] })]
255
+ })]
256
+ }),
257
+ /* @__PURE__ */ p("div", {
258
+ className: "space-y-3 rounded-xl border bg-slate-50/70 p-4 dark:bg-slate-900/40",
259
+ children: [/* @__PURE__ */ p("label", {
260
+ className: "flex items-start gap-3",
261
+ children: [/* @__PURE__ */ f("input", {
262
+ type: "checkbox",
263
+ checked: H === "auto",
264
+ onChange: (e) => _e(e.target.checked ? "auto" : "manual"),
265
+ className: "mt-1 h-4 w-4 rounded border-slate-300 text-primary focus:ring-primary"
266
+ }), /* @__PURE__ */ p("span", {
267
+ className: "space-y-1",
268
+ children: [/* @__PURE__ */ f("span", {
269
+ className: "block text-sm font-medium text-slate-900 dark:text-slate-100",
270
+ children: "Auto-sync all currency rates from one source amount"
271
+ }), /* @__PURE__ */ f("span", {
272
+ className: "block text-xs text-muted-foreground",
273
+ children: "Turn this off to set exact shipping costs and free-shipping thresholds for every active currency manually."
274
+ })]
275
+ })]
276
+ }), H === "auto" ? /* @__PURE__ */ p("div", {
277
+ className: "space-y-2",
278
+ children: [
279
+ /* @__PURE__ */ f(_, {
280
+ htmlFor: "rate-currency",
281
+ children: "Sync From Currency"
282
+ }),
283
+ /* @__PURE__ */ p(pe, {
284
+ value: W,
285
+ onValueChange: (e) => {
286
+ let t = d(e);
287
+ q((e) => ({
288
+ ...e,
289
+ [t]: Q[t] ?? e[t] ?? ""
290
+ })), Y((e) => ({
291
+ ...e,
292
+ [t]: $[t] ?? e[t] ?? ""
293
+ })), G(t);
294
+ },
295
+ children: [/* @__PURE__ */ f(b, {
296
+ id: "rate-currency",
297
+ className: "bg-background",
298
+ children: /* @__PURE__ */ f(x, { placeholder: "Select currency" })
299
+ }), /* @__PURE__ */ f(v, { children: P.map((e) => /* @__PURE__ */ p(y, {
300
+ value: e.code,
301
+ children: [e.code, e.is_default ? " (Default)" : ""]
302
+ }, e.code)) })]
303
+ }),
304
+ /* @__PURE__ */ f("p", {
305
+ className: "text-[10px] text-slate-500",
306
+ children: "Enter the source amount once and the other currencies will be derived automatically using the current FX rates."
307
+ })
308
+ ]
309
+ }) : /* @__PURE__ */ f("p", {
310
+ className: "text-[10px] text-slate-500",
311
+ children: "Manual mode stores exact values per currency. This is the best choice when shipping should not follow exchange-rate math directly."
312
+ })]
313
+ }),
314
+ /* @__PURE__ */ p("div", {
315
+ className: "space-y-3",
316
+ children: [/* @__PURE__ */ p("div", { children: [/* @__PURE__ */ f("p", {
317
+ className: "text-sm font-medium",
318
+ children: "Currency Rates"
319
+ }), /* @__PURE__ */ f("p", {
320
+ className: "text-xs text-muted-foreground",
321
+ children: B === "free_shipping" ? "Free-shipping methods keep cost at zero, but you can still control the threshold per currency." : H === "auto" ? `Only ${W} is editable. The rest are derived automatically.` : "Set the exact shopper-facing shipping price for each active currency."
322
+ })] }), /* @__PURE__ */ f("div", {
323
+ className: "grid gap-4 md:grid-cols-2 xl:grid-cols-3",
324
+ children: P.map((e) => {
325
+ let t = H === "auto" && e.code !== W, n = c(e.code) === 1 ? "1" : "0.01";
326
+ return /* @__PURE__ */ p("div", {
327
+ className: "space-y-4 rounded-xl border bg-card/70 p-4 shadow-sm",
328
+ children: [
329
+ /* @__PURE__ */ p("div", {
330
+ className: "flex items-center justify-between gap-2",
331
+ children: [/* @__PURE__ */ p("div", { children: [/* @__PURE__ */ f("p", {
332
+ className: "font-medium",
333
+ children: e.code
334
+ }), /* @__PURE__ */ p("p", {
335
+ className: "text-xs text-muted-foreground",
336
+ children: ["Rate ", e.exchange_rate]
337
+ })] }), /* @__PURE__ */ p("div", {
338
+ className: "flex flex-wrap items-center gap-2",
339
+ children: [
340
+ e.is_default ? /* @__PURE__ */ f(m, {
341
+ variant: "outline",
342
+ children: "Default"
343
+ }) : null,
344
+ H === "auto" && e.code === W ? /* @__PURE__ */ f(m, { children: "Source" }) : null,
345
+ t ? /* @__PURE__ */ f(m, {
346
+ variant: "outline",
347
+ children: "Derived"
348
+ }) : null
349
+ ]
350
+ })]
351
+ }),
352
+ /* @__PURE__ */ p("div", {
353
+ className: "space-y-2",
354
+ children: [/* @__PURE__ */ p(_, {
355
+ htmlFor: `rate-cost-${e.code}`,
356
+ children: [
357
+ "Cost (",
358
+ e.code,
359
+ ")"
360
+ ]
361
+ }), /* @__PURE__ */ p("div", {
362
+ className: "relative",
363
+ children: [/* @__PURE__ */ f(s, { className: "absolute left-2.5 top-2.5 h-4 w-4 text-slate-400" }), /* @__PURE__ */ f(g, {
364
+ id: `rate-cost-${e.code}`,
365
+ type: "number",
366
+ step: n,
367
+ min: "0",
368
+ value: Q[e.code] ?? "",
369
+ onChange: (t) => q((n) => ({
370
+ ...n,
371
+ [e.code]: t.target.value
372
+ })),
373
+ className: "pl-9 bg-slate-50/50 dark:bg-slate-900/50 disabled:opacity-70",
374
+ disabled: B === "free_shipping" || t,
375
+ required: B !== "free_shipping" && H === "manual"
376
+ })]
377
+ })]
378
+ }),
379
+ /* @__PURE__ */ p("div", {
380
+ className: "space-y-2",
381
+ children: [/* @__PURE__ */ p(_, {
382
+ htmlFor: `rate-threshold-${e.code}`,
383
+ children: [
384
+ "Free-Shipping Threshold (",
385
+ e.code,
386
+ ")"
387
+ ]
388
+ }), /* @__PURE__ */ p("div", {
389
+ className: "relative",
390
+ children: [/* @__PURE__ */ f(s, { className: "absolute left-2.5 top-2.5 h-4 w-4 text-slate-400" }), /* @__PURE__ */ f(g, {
391
+ id: `rate-threshold-${e.code}`,
392
+ type: "number",
393
+ step: n,
394
+ min: "0",
395
+ value: $[e.code] ?? "",
396
+ onChange: (t) => Y((n) => ({
397
+ ...n,
398
+ [e.code]: t.target.value
399
+ })),
400
+ className: "pl-9 bg-slate-50/50 dark:bg-slate-900/50 disabled:opacity-70",
401
+ disabled: t,
402
+ placeholder: c(e.code) === 1 ? "0" : "0.00"
403
+ })]
404
+ })]
405
+ }),
406
+ t ? /* @__PURE__ */ p("p", {
407
+ className: "text-[10px] text-muted-foreground",
408
+ children: [
409
+ "This currency is synced automatically from ",
410
+ W,
411
+ "."
412
+ ]
413
+ }) : H === "manual" ? /* @__PURE__ */ f("p", {
414
+ className: "text-[10px] text-muted-foreground",
415
+ children: "Enter the exact amount shoppers should see in this currency."
416
+ }) : null
417
+ ]
418
+ }, e.code);
419
+ })
420
+ })]
421
+ })
422
+ ]
423
+ }),
424
+ /* @__PURE__ */ p(le, {
425
+ className: "bg-slate-50 dark:bg-slate-900/50 -mx-6 -mb-6 p-4 border-t dark:border-slate-800",
426
+ children: [/* @__PURE__ */ f(h, {
427
+ type: "button",
428
+ variant: "ghost",
429
+ onClick: () => k(!1),
430
+ disabled: X,
431
+ children: "Cancel"
432
+ }), /* @__PURE__ */ f(h, {
433
+ type: "submit",
434
+ disabled: X || !I.trim(),
435
+ children: X ? A ? "Saving..." : "Adding..." : A ? "Save Changes" : "Add Rate"
436
+ })]
437
+ })
438
+ ]
439
+ })
440
+ })]
441
+ });
438
442
  }
439
- export {
440
- Pe as RateForm
441
- };
443
+ //#endregion
444
+ export { T as RateForm };