@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,160 +1,157 @@
1
- 'use client';
2
- import { jsxs as a, jsx as r } from "react/jsx-runtime";
3
- import { useState as c, useEffect as P, useMemo as u } from "react";
4
- import { X as $, ChevronsUpDown as O, Search as Q, Loader2 as T, Check as q } from "lucide-react";
5
- import { cn as A } from "@nextblock-cms/utils";
6
- import { Badge as B, Popover as R, PopoverTrigger as z, Button as w, PopoverContent as D, Input as E, Checkbox as F } from "@nextblock-cms/ui";
7
- import { createCategoryAction as M } from "../server-actions.es.js";
8
- import { toast as h } from "sonner";
9
- function W({
10
- categories: m = [],
11
- selectedIds: o = [],
12
- onChange: d,
13
- placeholder: N = "Select categories..."
14
- }) {
15
- const [f, C] = c(!1), [l, p] = c(""), [n, g] = c(m), [x, b] = c(!1);
16
- P(() => {
17
- g(m);
18
- }, [m]);
19
- const y = u(() => n.filter((e) => o.includes(e.id)), [n, o]), v = u(() => {
20
- if (!l) return n;
21
- const e = l.toLowerCase();
22
- return n.filter(
23
- (t) => t.name.toLowerCase().includes(e) || t.slug.toLowerCase().includes(e)
24
- );
25
- }, [n, l]), s = l.trim(), k = u(() => {
26
- if (!s) return !1;
27
- const e = s.toLowerCase();
28
- return !n.some((t) => t.name.toLowerCase() === e);
29
- }, [n, s]), L = async () => {
30
- if (s) {
31
- b(!0);
32
- try {
33
- const e = await M({ name: s });
34
- if (e.success && e.category) {
35
- const t = {
36
- id: e.category.id,
37
- name: e.category.name,
38
- slug: e.category.slug
39
- };
40
- g((i) => [...i, t]), d([...o, t.id]), p(""), h.success(`Category "${t.name}" created successfully.`);
41
- } else
42
- h.error(e.error || "Failed to create category.");
43
- } catch (e) {
44
- h.error(e.message || "An error occurred while creating category.");
45
- } finally {
46
- b(!1);
47
- }
48
- }
49
- }, j = (e) => {
50
- const t = o.includes(e) ? o.filter((i) => i !== e) : [...o, e];
51
- d(t);
52
- }, S = (e, t) => {
53
- t.stopPropagation(), d(o.filter((i) => i !== e));
54
- };
55
- return /* @__PURE__ */ a("div", { className: "space-y-2", children: [
56
- /* @__PURE__ */ r("div", { className: "flex flex-wrap gap-1.5 min-h-[32px] p-1 border rounded-md bg-background focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2", children: y.length === 0 ? /* @__PURE__ */ r("span", { className: "text-xs text-muted-foreground self-center px-2 py-1 select-none", children: "No categories selected." }) : y.map((e) => /* @__PURE__ */ a(
57
- B,
58
- {
59
- variant: "secondary",
60
- className: "pl-2 pr-1.5 py-0.5 text-xs flex items-center gap-1 bg-amber-500/10 text-amber-800 dark:text-amber-300 border border-amber-500/20 rounded-full",
61
- children: [
62
- e.name,
63
- /* @__PURE__ */ r(
64
- "button",
65
- {
66
- type: "button",
67
- onClick: (t) => S(e.id, t),
68
- className: "rounded-full p-0.5 text-muted-foreground hover:bg-amber-500/20 hover:text-amber-950 dark:hover:text-amber-50 transition-colors cursor-pointer",
69
- "aria-label": `Remove ${e.name}`,
70
- children: /* @__PURE__ */ r($, { className: "h-3 w-3" })
71
- }
72
- )
73
- ]
74
- },
75
- e.id
76
- )) }),
77
- /* @__PURE__ */ a(R, { open: f, onOpenChange: C, children: [
78
- /* @__PURE__ */ r(z, { asChild: !0, children: /* @__PURE__ */ a(
79
- w,
80
- {
81
- variant: "outline",
82
- role: "combobox",
83
- "aria-expanded": f,
84
- className: "w-full justify-between h-8 text-xs font-normal",
85
- children: [
86
- /* @__PURE__ */ r("span", { className: "truncate", children: o.length > 0 ? `${o.length} categor${o.length === 1 ? "y" : "ies"} selected` : N }),
87
- /* @__PURE__ */ r(O, { className: "ml-2 h-4 w-4 shrink-0 opacity-50" })
88
- ]
89
- }
90
- ) }),
91
- /* @__PURE__ */ a(D, { className: "w-(--radix-popover-trigger-width) p-0", align: "start", children: [
92
- /* @__PURE__ */ a("div", { className: "flex items-center border-b px-3", children: [
93
- /* @__PURE__ */ r(Q, { className: "mr-2 h-4 w-4 shrink-0 opacity-50" }),
94
- /* @__PURE__ */ r(
95
- E,
96
- {
97
- className: "flex h-9 w-full rounded-md bg-transparent py-2 text-xs outline-none border-0 focus-visible:ring-0 focus-visible:ring-offset-0",
98
- placeholder: "Search categories...",
99
- value: l,
100
- onChange: (e) => p(e.target.value)
101
- }
102
- )
103
- ] }),
104
- k && /* @__PURE__ */ r("div", { className: "border-b border-border/50 p-1", children: /* @__PURE__ */ a(
105
- w,
106
- {
107
- type: "button",
108
- variant: "ghost",
109
- size: "sm",
110
- className: "w-full justify-start text-xs h-8 text-amber-600 dark:text-amber-400 hover:text-amber-700 hover:bg-amber-500/10 cursor-pointer",
111
- onClick: L,
112
- disabled: x,
113
- children: [
114
- x ? /* @__PURE__ */ r(T, { className: "mr-2 h-3 w-3 animate-spin" }) : /* @__PURE__ */ r("span", { className: "font-bold mr-1.5", children: "+" }),
115
- 'Create category "',
116
- s,
117
- '"'
118
- ]
119
- }
120
- ) }),
121
- /* @__PURE__ */ r("div", { className: "max-h-60 overflow-y-auto p-1", children: v.length === 0 ? /* @__PURE__ */ r("p", { className: "py-4 text-center text-xs text-muted-foreground", children: "No categories found." }) : /* @__PURE__ */ r("div", { className: "flex flex-col gap-0.5", children: v.map((e) => {
122
- const t = o.includes(e.id);
123
- return /* @__PURE__ */ a(
124
- "div",
125
- {
126
- onClick: () => j(e.id),
127
- className: A(
128
- "relative flex w-full cursor-pointer select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-xs outline-none hover:bg-accent hover:text-accent-foreground text-left transition-colors",
129
- t && "bg-accent/40 font-medium"
130
- ),
131
- children: [
132
- /* @__PURE__ */ r("span", { className: "absolute left-2 flex h-3.5 w-3.5 items-center justify-center pointer-events-none", children: /* @__PURE__ */ r(
133
- F,
134
- {
135
- checked: t,
136
- tabIndex: -1,
137
- "aria-label": `Toggle ${e.name}`,
138
- className: "h-3.5 w-3.5"
139
- }
140
- ) }),
141
- /* @__PURE__ */ a("span", { className: "flex flex-col", children: [
142
- /* @__PURE__ */ r("span", { children: e.name }),
143
- /* @__PURE__ */ a("span", { className: "font-mono text-[9px] text-muted-foreground leading-none", children: [
144
- "/",
145
- e.slug
146
- ] })
147
- ] }),
148
- t && /* @__PURE__ */ r("span", { className: "absolute right-2 flex h-3.5 w-3.5 items-center justify-center", children: /* @__PURE__ */ r(q, { className: "h-3.5 w-3.5 text-primary" }) })
149
- ]
150
- },
151
- e.id
152
- );
153
- }) }) })
154
- ] })
155
- ] })
156
- ] });
1
+ "use client";
2
+ import { createCategoryAction as e } from "../server-actions.es.js";
3
+ import { useEffect as t, useMemo as n, useState as r } from "react";
4
+ import { Check as i, ChevronsUpDown as a, Loader2 as o, Search as s, X as c } from "lucide-react";
5
+ import { cn as l } from "@nextblock-cms/utils";
6
+ import { jsx as u, jsxs as d } from "react/jsx-runtime";
7
+ import { toast as f } from "sonner";
8
+ import { Badge as p, Button as m, Checkbox as h, Input as g, Popover as _, PopoverContent as v, PopoverTrigger as y } from "@nextblock-cms/ui";
9
+ //#region libs/ecommerce/src/lib/pages/cms/products/components/ProductCategorySelector.tsx
10
+ function b({ categories: b = [], selectedIds: x = [], onChange: S, placeholder: C = "Select categories..." }) {
11
+ let [w, T] = r(!1), [E, D] = r(""), [O, k] = r(b), [A, j] = r(!1);
12
+ t(() => {
13
+ k(b);
14
+ }, [b]);
15
+ let M = n(() => O.filter((e) => x.includes(e.id)), [O, x]), N = n(() => {
16
+ if (!E) return O;
17
+ let e = E.toLowerCase();
18
+ return O.filter((t) => t.name.toLowerCase().includes(e) || t.slug.toLowerCase().includes(e));
19
+ }, [O, E]), P = E.trim(), F = n(() => {
20
+ if (!P) return !1;
21
+ let e = P.toLowerCase();
22
+ return !O.some((t) => t.name.toLowerCase() === e);
23
+ }, [O, P]), I = async () => {
24
+ if (P) {
25
+ j(!0);
26
+ try {
27
+ let t = await e({ name: P });
28
+ if (t.success && t.category) {
29
+ let e = {
30
+ id: t.category.id,
31
+ name: t.category.name,
32
+ slug: t.category.slug
33
+ };
34
+ k((t) => [...t, e]), S([...x, e.id]), D(""), f.success(`Category "${e.name}" created successfully.`);
35
+ } else f.error(t.error || "Failed to create category.");
36
+ } catch (e) {
37
+ f.error(e.message || "An error occurred while creating category.");
38
+ } finally {
39
+ j(!1);
40
+ }
41
+ }
42
+ }, L = (e) => {
43
+ S(x.includes(e) ? x.filter((t) => t !== e) : [...x, e]);
44
+ }, R = (e, t) => {
45
+ t.stopPropagation(), S(x.filter((t) => t !== e));
46
+ };
47
+ return /* @__PURE__ */ d("div", {
48
+ className: "space-y-2",
49
+ children: [/* @__PURE__ */ u("div", {
50
+ className: "flex flex-wrap gap-1.5 min-h-[32px] p-1 border rounded-md bg-background focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2",
51
+ children: M.length === 0 ? /* @__PURE__ */ u("span", {
52
+ className: "text-xs text-muted-foreground self-center px-2 py-1 select-none",
53
+ children: "No categories selected."
54
+ }) : M.map((e) => /* @__PURE__ */ d(p, {
55
+ variant: "secondary",
56
+ className: "pl-2 pr-1.5 py-0.5 text-xs flex items-center gap-1 bg-amber-500/10 text-amber-800 dark:text-amber-300 border border-amber-500/20 rounded-full",
57
+ children: [e.name, /* @__PURE__ */ u("button", {
58
+ type: "button",
59
+ onClick: (t) => R(e.id, t),
60
+ className: "rounded-full p-0.5 text-muted-foreground hover:bg-amber-500/20 hover:text-amber-950 dark:hover:text-amber-50 transition-colors cursor-pointer",
61
+ "aria-label": `Remove ${e.name}`,
62
+ children: /* @__PURE__ */ u(c, { className: "h-3 w-3" })
63
+ })]
64
+ }, e.id))
65
+ }), /* @__PURE__ */ d(_, {
66
+ open: w,
67
+ onOpenChange: T,
68
+ children: [/* @__PURE__ */ u(y, {
69
+ asChild: !0,
70
+ children: /* @__PURE__ */ d(m, {
71
+ variant: "outline",
72
+ role: "combobox",
73
+ "aria-expanded": w,
74
+ className: "w-full justify-between h-8 text-xs font-normal",
75
+ children: [/* @__PURE__ */ u("span", {
76
+ className: "truncate",
77
+ children: x.length > 0 ? `${x.length} categor${x.length === 1 ? "y" : "ies"} selected` : C
78
+ }), /* @__PURE__ */ u(a, { className: "ml-2 h-4 w-4 shrink-0 opacity-50" })]
79
+ })
80
+ }), /* @__PURE__ */ d(v, {
81
+ className: "w-(--radix-popover-trigger-width) p-0",
82
+ align: "start",
83
+ children: [
84
+ /* @__PURE__ */ d("div", {
85
+ className: "flex items-center border-b px-3",
86
+ children: [/* @__PURE__ */ u(s, { className: "mr-2 h-4 w-4 shrink-0 opacity-50" }), /* @__PURE__ */ u(g, {
87
+ className: "flex h-9 w-full rounded-md bg-transparent py-2 text-xs outline-none border-0 focus-visible:ring-0 focus-visible:ring-offset-0",
88
+ placeholder: "Search categories...",
89
+ value: E,
90
+ onChange: (e) => D(e.target.value)
91
+ })]
92
+ }),
93
+ F && /* @__PURE__ */ u("div", {
94
+ className: "border-b border-border/50 p-1",
95
+ children: /* @__PURE__ */ d(m, {
96
+ type: "button",
97
+ variant: "ghost",
98
+ size: "sm",
99
+ className: "w-full justify-start text-xs h-8 text-amber-600 dark:text-amber-400 hover:text-amber-700 hover:bg-amber-500/10 cursor-pointer",
100
+ onClick: I,
101
+ disabled: A,
102
+ children: [
103
+ A ? /* @__PURE__ */ u(o, { className: "mr-2 h-3 w-3 animate-spin" }) : /* @__PURE__ */ u("span", {
104
+ className: "font-bold mr-1.5",
105
+ children: "+"
106
+ }),
107
+ "Create category \"",
108
+ P,
109
+ "\""
110
+ ]
111
+ })
112
+ }),
113
+ /* @__PURE__ */ u("div", {
114
+ className: "max-h-60 overflow-y-auto p-1",
115
+ children: N.length === 0 ? /* @__PURE__ */ u("p", {
116
+ className: "py-4 text-center text-xs text-muted-foreground",
117
+ children: "No categories found."
118
+ }) : /* @__PURE__ */ u("div", {
119
+ className: "flex flex-col gap-0.5",
120
+ children: N.map((e) => {
121
+ let t = x.includes(e.id);
122
+ return /* @__PURE__ */ d("div", {
123
+ onClick: () => L(e.id),
124
+ className: l("relative flex w-full cursor-pointer select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-xs outline-none hover:bg-accent hover:text-accent-foreground text-left transition-colors", t && "bg-accent/40 font-medium"),
125
+ children: [
126
+ /* @__PURE__ */ u("span", {
127
+ className: "absolute left-2 flex h-3.5 w-3.5 items-center justify-center pointer-events-none",
128
+ children: /* @__PURE__ */ u(h, {
129
+ checked: t,
130
+ tabIndex: -1,
131
+ "aria-label": `Toggle ${e.name}`,
132
+ className: "h-3.5 w-3.5"
133
+ })
134
+ }),
135
+ /* @__PURE__ */ d("span", {
136
+ className: "flex flex-col",
137
+ children: [/* @__PURE__ */ u("span", { children: e.name }), /* @__PURE__ */ d("span", {
138
+ className: "font-mono text-[9px] text-muted-foreground leading-none",
139
+ children: ["/", e.slug]
140
+ })]
141
+ }),
142
+ t && /* @__PURE__ */ u("span", {
143
+ className: "absolute right-2 flex h-3.5 w-3.5 items-center justify-center",
144
+ children: /* @__PURE__ */ u(i, { className: "h-3.5 w-3.5 text-primary" })
145
+ })
146
+ ]
147
+ }, e.id);
148
+ })
149
+ })
150
+ })
151
+ ]
152
+ })]
153
+ })]
154
+ });
157
155
  }
158
- export {
159
- W as ProductCategorySelector
160
- };
156
+ //#endregion
157
+ export { b as ProductCategorySelector };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),o=require("react"),Ke=require("@hookform/resolvers/zod"),B=require("lucide-react"),a=require("@nextblock-cms/ui"),$e=require("../../../../product-schema.cjs.js"),He=require("react-hook-form"),Je=require("./ProductMediaManager.cjs.js"),Xe=require("./SyncFreemiusPricingButton.cjs.js"),Ye=require("./VariationsEditor.cjs.js"),Pe=require("./CurrencyPriceFields.cjs.js"),we=require("./SaleScheduleFields.cjs.js"),Qe=require("./ProductCategorySelector.cjs.js"),L=require("../product-price-sync.cjs.js"),We=require("../../../../types.cjs.js"),Ce=require("../../../../currency.cjs.js"),O=require("@nextblock-cms/utils");function z({title:s,description:r,action:y,children:m,hideHeader:P}){return e.jsxs("section",{className:"rounded-lg border bg-card p-3 shadow-sm space-y-3",children:[!P&&e.jsxs("div",{className:"flex items-start justify-between gap-4 flex-wrap border-b border-muted/50 pb-2 mb-1",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx("h2",{className:"text-sm font-bold tracking-tight",children:s}),r?e.jsx("p",{className:"text-[11px] text-muted-foreground leading-none",children:r}):null]}),y]}),e.jsx("div",{className:P?"":"pt-1",children:m})]})}function Ze(s,r,y){const m=r?Number.parseInt(r,10):void 0;return s?.language_id||(Number.isFinite(m)?m:void 0)||y.find(P=>P.is_default)?.id||y[0]?.id||1}function ke(s,r,y,m,P){const k=(m.find(b=>b.is_default)??m[0])?.code||"USD",I=s?.prices&&Object.keys(s.prices).length>0?s.prices:{[k]:typeof s?.price=="number"?s.price/100:0},T=s?.sale_prices&&Object.keys(s.sale_prices).length>0?s.sale_prices:typeof s?.sale_price=="number"?{[k]:s.sale_price/100}:{},A=s?.product_type||"",F=s?.payment_provider||(s?.product_type?We.derivePaymentProviderFromProductType(s.product_type):"stripe");return{...L.sanitizeProductFormValuesForStoreManagedCurrencies({product_type:A||"physical",payment_provider:F,title:s?.title||"",slug:s?.slug||"",sku:s?.sku||"",upc:s?.upc||"",is_taxable:s?.is_taxable??!0,price:typeof s?.price=="number"?s.price/100:0,prices:I,sale_price:typeof s?.sale_price=="number"?s.sale_price/100:null,sale_prices:T,stock:s?.stock||0,meta_title:s?.meta_title||"",meta_description:s?.meta_description||"",custom_canonical:s?.custom_canonical||"",short_description:s?.short_description||"",description_json:s?.description_json||{type:"doc",content:[{type:"paragraph"}]},freemius_product_id:s?.freemius_product_id||"",freemius_plan_id:s?.freemius_plan_id||"",trial_period_days:s?.trial_period_days??0,trial_requires_payment_method:s?.trial_requires_payment_method??!1,status:s?.status||"draft",language_id:Ze(s,r,y),translation_group_id:s?.translation_group_id||P||void 0,product_media:s?.product_media?.map(b=>({media_id:b.media_id}))||[],category_ids:s?.category_ids||[],variation_attributes:s?.variation_attributes||[],variants:s?.variants?.map(b=>({...b,prices:b.prices||{},sale_prices:b.sale_prices||{}}))||[]},m),product_type:A,payment_provider:F}}function Fe(s){return s?s.map(r=>({id:r.id||r.media_id,media_id:r.media_id,file_path:r.media?.file_path||r.media?.object_key||"",alt:r.media?.alt_text||"",sort_order:r.sort_order??0})).sort((r,y)=>r.sort_order-y.sort_order):[]}function Ge(s){return s.map(r=>({media_id:r.media_id}))}function De(s){return s.map(r=>({media_id:r.media_id,file_path:r.file_path,alt:r.alt}))}const es=s=>s.toString().toLowerCase().trim().replace(/\s+/g,"-").replace(/[^\w-]+/g,"").replace(/--+/g,"-").replace(/^-+/,"").replace(/-+$/,"");function ss({initialData:s,isEdit:r=!1,mediaPickerNode:y,availableLanguagesProp:m,globalAttributesProp:P,currenciesProp:K,translationGroupId:k,targetLanguageId:I,freemiusDashboardNode:T,enabledProviders:A,configStatus:F,createAction:$,updateAction:b,availableCategoriesProp:Me=[],hasOpenDraft:Ve=!1,onSeoChange:te}){const[R,H]=o.useState(!1),[J,X]=o.useState(()=>!!s?.variants?.length),u=o.useMemo(()=>K.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)),[K]),n=o.useMemo(()=>u.find(t=>t.is_default)??u[0],[u]),E=o.useMemo(()=>L.getStoreManagedPriceCurrencyCodes(u),[u]),re=He.useForm({resolver:Ke.zodResolver($e.productSchema),defaultValues:ke(s,I,m,u,k)}),{register:c,handleSubmit:Y,setValue:i,reset:ae,watch:l,setError:Q,formState:{errors:x,dirtyFields:ie}}=re,de=o.useRef(!0),W=o.useRef(null),[Ie,Z]=o.useState(!1),[oe,G]=o.useState(null),[ne,qe]=o.useState(null),M=l(),ce=re.formState.isDirty,le=M.title,ue=M.meta_title,pe=M.meta_description;o.useEffect(()=>{te?.({title:le,meta_title:ue,meta_description:pe})},[le,ue,pe,te]),o.useEffect(()=>{if(!r)return;if(de.current){de.current=!1,W.current=JSON.stringify(M);return}if(!ce)return;const t=JSON.stringify(M);if(t===W.current)return;const d=setTimeout(()=>{R||(W.current=t,Y(Se)())},400);return()=>clearTimeout(d)},[M,r,ce,R,Y]);const me=l("title"),q=l("product_type"),h=q==="digital"?"freemius":q==="physical"?"stripe":void 0,j=q==="physical",xe=q==="digital",he=h?A[h]:!1,fe=h?F[h].hasKeys:!1,Te=!!l("freemius_product_id"),ge=Number(l("trial_period_days")||0),_e=!!l("trial_requires_payment_method"),Ae=l("variants")||[],w=l("price"),V=l("sale_price"),v=l("prices")||{},C=l("sale_prices")||{},N=(Ae?.length||0)>0,Re=l("language_id"),Ee=m.find(t=>t.id===Re)?.code||m.find(t=>t.is_default)?.code||m[0]?.code,U=o.useMemo(()=>L.resolveEditorCurrencyPriceMaps({currencies:u,prices:v,salePrices:C,fallbackPrice:w,fallbackSalePrice:V}),[w,V,u,v,C]),Ue=o.useMemo(()=>s?.variants?.map(t=>({...t,prices:t.prices||{},sale_prices:t.sale_prices||{}})),[s?.variants]);o.useEffect(()=>{if(ie.title&&!r){const t=es(me);i("slug",t,{shouldValidate:!0})}},[me,ie.title,i,r]);const[D,ye]=o.useState(()=>Fe(s?.product_media)),[ee,be]=o.useState(new Set);o.useEffect(()=>{ae(ke(s,I,m,u,k)),ye(Fe(s?.product_media)),be(new Set),X(!!s?.variants?.length)},[m,u,s,ae,I,k]);const Be=t=>{const d=new Set(t.map(_=>_.id)),p=D.filter(_=>!d.has(_.id)),f=new Set(ee);p.forEach(_=>{_.media_id&&f.add(_.media_id)}),be(f),ye(t),i("product_media",Ge(t),{shouldDirty:!0}),i("explicitly_removed_media_ids",Array.from(f),{shouldDirty:!0})};o.useEffect(()=>{i("explicitly_removed_media_ids",Array.from(ee))},[ee,i]),o.useEffect(()=>{N&&X(!0)},[N]),o.useEffect(()=>{c("is_taxable"),c("price"),c("sale_price"),c("payment_provider"),c("trial_requires_payment_method")},[c]),o.useEffect(()=>{if(!xe){i("trial_period_days",0,{shouldDirty:!1,shouldValidate:!0}),i("trial_requires_payment_method",!1,{shouldDirty:!1,shouldValidate:!0});return}ge<=0&&i("trial_requires_payment_method",!1,{shouldDirty:!1,shouldValidate:!0})},[xe,i,ge]),o.useEffect(()=>{h&&i("payment_provider",h,{shouldDirty:!1,shouldValidate:!0})},[h,i]),o.useEffect(()=>{n&&v[n.code]===void 0&&i("prices",{...v,[n.code]:w||0},{shouldDirty:!1})},[w,n,v,i]);const je=o.useCallback((t,d)=>{const p={...v,[t]:d};i("prices",p,{shouldDirty:!0,shouldValidate:!0}),t===n?.code&&i("price",d,{shouldDirty:!0,shouldValidate:!0})},[n?.code,v,i]),ve=o.useCallback((t,d)=>{const p={...C,[t]:d};i("sale_prices",p,{shouldDirty:!0,shouldValidate:!0}),t===n?.code&&i("sale_price",d,{shouldDirty:!0,shouldValidate:!0})},[n?.code,C,i]),Ne=o.useCallback(()=>{if(!n)return;const t=new Set(E),d=v[n.code]??w??0,p=C[n.code]??V??null,f=u.reduce((S,g)=>{if(g.code!==n.code&&t.has(g.code))return S;const se=Ce.convertMinorUnitAmount({amount:O.majorUnitAmountToMinor(d,n.code),fromCurrencyCode:n.code,toCurrencyCode:g.code,currencies:u,applyRounding:!0});return S[g.code]=O.minorUnitAmountToMajor(se,g.code),S},{}),_=u.reduce((S,g)=>{if(g.code!==n.code&&t.has(g.code))return S;if(typeof p!="number")return(g.code===n.code||!t.has(g.code))&&(S[g.code]=null),S;const se=Ce.convertMinorUnitAmount({amount:O.majorUnitAmountToMinor(p,n.code),fromCurrencyCode:n.code,toCurrencyCode:g.code,currencies:u,applyRounding:!0});return S[g.code]=O.minorUnitAmountToMajor(se,g.code),S},{});i("prices",f,{shouldDirty:!0,shouldValidate:!0}),i("sale_prices",_,{shouldDirty:!0,shouldValidate:!0}),i("price",f[n.code]??d,{shouldDirty:!0,shouldValidate:!0}),i("sale_price",_[n.code]??null,{shouldDirty:!0,shouldValidate:!0})},[u,n,v,C,i,E,w,V]),Oe=o.useCallback(({variationAttributes:t,variants:d})=>{i("variation_attributes",t,{shouldDirty:!0}),i("variants",d,{shouldDirty:!0,shouldValidate:!0})},[i]),Se=async t=>{H(!0),Z(!0),G(null);try{if(!h){const _="Select whether this product is physical or digital before saving.";Q("product_type",{type:"manual",message:_}),r?G(_):alert(_),H(!1),Z(!1);return}const d=j?0:Math.max(0,Number(t.trial_period_days||0)),p={...t,product_type:t.product_type,payment_provider:h,freemius_product_id:j?"":t.freemius_product_id,freemius_plan_id:j?"":t.freemius_plan_id,trial_period_days:d,trial_requires_payment_method:!j&&d>0?t.trial_requires_payment_method:!1,upc:j?t.upc:null,is_taxable:j?t.is_taxable:!1,variation_attributes:j?t.variation_attributes:[],variants:j?t.variants:[]},f=L.sanitizeProductFormValuesForStoreManagedCurrencies(p,u);if(r&&b)await b(f),qe(new Date);else if($)await $(f);else throw new Error("Product form action is not configured.")}catch(d){if(console.error(d),d.message==="NEXT_REDIRECT")return;let p=d.message||"An error occurred while saving.";if(d.code==="23505"){const f=d.message?.toLowerCase()||"";f.includes("products_slug_key")||f.includes("slug")?(p="This slug is already in use. Please choose another one.",Q("slug",{type:"manual",message:p})):(f.includes("products_sku_key")||f.includes("sku"))&&(p="This SKU is already in use.",Q("sku",{type:"manual",message:p}))}r?G(p):alert(p)}finally{H(!1),Z(!1)}},ze=N?"bg-muted/60 text-muted-foreground opacity-70":"",Le=De(D);return e.jsxs("form",{onSubmit:Y(Se),className:"space-y-2.5 pb-4",children:[e.jsx("input",{type:"hidden",...c("translation_group_id")}),e.jsx("input",{type:"hidden",...c("payment_provider")}),e.jsxs("div",{className:"space-y-2.5 w-full",children:[e.jsxs("div",{className:"rounded-lg border bg-card p-2.5 px-4 shadow-sm flex items-center justify-between gap-3 flex-wrap",children:[e.jsxs("div",{className:"flex items-center gap-6",children:[e.jsxs("div",{className:"flex h-9 items-center gap-2",children:[e.jsx("span",{className:"text-sm font-bold whitespace-nowrap leading-none pt-0.5",children:"Product Type"}),x.product_type&&e.jsx(B.AlertCircle,{className:"h-4 w-4 text-destructive"})]}),e.jsx("div",{className:"flex h-9 items-center",children:e.jsxs(a.Select,{onValueChange:t=>i("product_type",t,{shouldDirty:!0,shouldValidate:!0}),value:q||void 0,children:[e.jsx(a.SelectTrigger,{className:"w-[160px] h-9 text-xs",children:e.jsx(a.SelectValue,{placeholder:"Select Type"})}),e.jsxs(a.SelectContent,{children:[e.jsx(a.SelectItem,{value:"physical",children:"Physical Product"}),e.jsx(a.SelectItem,{value:"digital",children:"Digital Product"})]})]})})]}),e.jsxs("div",{className:"flex items-center gap-6",children:[e.jsxs("div",{className:"flex h-9 items-center gap-3",children:[e.jsx("span",{className:"text-[11px] font-semibold text-muted-foreground uppercase tracking-wider leading-none",children:"Payment Provider"}),e.jsx(a.Badge,{variant:"outline",className:"text-xs py-1 font-bold bg-muted/30 leading-none",children:h?h==="stripe"?"Stripe":"Freemius":"—"})]}),h&&e.jsx("div",{className:"flex h-9 items-center gap-2",children:he&&fe?e.jsxs("span",{className:"flex items-center gap-1.5 text-emerald-600 text-[10px] font-bold bg-emerald-50 px-2 py-1 rounded-full border border-emerald-100 uppercase leading-none",children:[e.jsx(B.CheckCircle2,{className:"h-3 w-3"}),"Ready"]}):e.jsxs("span",{className:"flex items-center gap-1.5 text-amber-600 text-[10px] font-bold bg-amber-50 px-2 py-1 rounded-full border border-amber-100 uppercase leading-none",children:[e.jsx(B.AlertCircle,{className:"h-3 w-3"}),he?"Keys Missing":"Disabled"]})}),!fe&&h&&F[h].missing.length>0&&e.jsxs("a",{href:"/cms/payments",className:"hidden xl:flex h-9 items-center gap-1 text-[10px] text-muted-foreground bg-muted/50 px-2 py-1 rounded border border-dashed leading-none hover:text-foreground hover:border-solid",children:[e.jsx(B.Info,{className:"h-3 w-3"}),"Missing: ",F[h].missing.join(", ")," — set up payments"]})]})]}),e.jsxs(z,{title:"Product Information",hideHeader:!0,children:[r&&e.jsxs("div",{className:"flex items-center justify-between text-xs text-muted-foreground pb-2 border-b border-border/40 mb-2.5",children:[e.jsx("span",{className:"font-semibold text-[11px] uppercase tracking-wider text-muted-foreground/80",children:"Product Settings"}),e.jsx("div",{className:"flex items-center gap-1.5 min-h-[16px]",children:Ie?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"relative flex h-2 w-2",children:[e.jsx("span",{className:"animate-ping absolute inline-flex h-full w-full rounded-full bg-amber-400 opacity-75"}),e.jsx("span",{className:"relative inline-flex rounded-full h-2 w-2 bg-amber-500"})]}),e.jsx("span",{className:"text-amber-600 dark:text-amber-400 font-medium",children:"Autosaving settings..."})]}):oe?e.jsxs("span",{className:"text-red-500 font-medium",children:["Error saving settings: ",oe]}):ne?e.jsxs("span",{className:"text-emerald-600 dark:text-emerald-400 font-medium",children:["Settings autosaved at ",ne.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",second:"2-digit"})]}):e.jsx("span",{className:"text-muted-foreground/60",children:"Settings autosave in draft mode"})})]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-6 gap-2.5",children:[e.jsxs("div",{className:"col-span-2 space-y-1",children:[e.jsx(a.Label,{htmlFor:"title",className:"text-xs uppercase font-bold text-muted-foreground tracking-wider leading-none",children:"Title"}),e.jsx(a.Input,{id:"title",placeholder:"Product title",...c("title"),className:"h-8 text-sm"}),x.title&&e.jsx("p",{className:"text-destructive text-[11px] leading-none",children:x.title.message})]}),e.jsxs("div",{className:"col-span-2 space-y-1",children:[e.jsx(a.Label,{htmlFor:"slug",className:"text-xs uppercase font-bold text-muted-foreground tracking-wider leading-none",children:"Slug"}),e.jsx(a.Input,{id:"slug",placeholder:"product-slug",...c("slug"),className:"h-8 text-sm"}),x.slug&&e.jsx("p",{className:"text-destructive text-[11px] leading-none",children:x.slug.message})]}),e.jsxs("div",{className:"col-span-1 space-y-1",children:[e.jsx(a.Label,{htmlFor:"sku",className:"text-xs uppercase font-bold text-muted-foreground tracking-wider leading-none",children:"SKU"}),e.jsx(a.Input,{id:"sku",placeholder:"SKU",...c("sku"),className:"h-8 text-sm font-mono"}),x.sku&&e.jsx("p",{className:"text-destructive text-[11px] leading-none",children:x.sku.message})]}),e.jsxs("div",{className:"col-span-1 space-y-1",children:[e.jsx(a.Label,{htmlFor:"upc_ean",className:"text-xs uppercase font-bold text-muted-foreground tracking-wider leading-none",children:"UPC / EAN"}),e.jsx(a.Input,{id:"upc_ean",placeholder:"000000000",...c("upc"),className:"h-8 text-sm font-mono",readOnly:N})]})]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-12 gap-2.5 mt-2",children:[e.jsxs("div",{className:`${r?"lg:col-span-3":"lg:col-span-4"} col-span-2 space-y-1`,children:[e.jsx(a.Label,{htmlFor:"meta_title",className:"text-xs uppercase font-bold text-muted-foreground tracking-wider leading-none",children:"Meta Title"}),e.jsx(a.Input,{id:"meta_title",...c("meta_title"),placeholder:"SEO page title (50-60 chars)",className:"h-8 text-sm"})]}),e.jsxs("div",{className:"lg:col-span-4 col-span-2 space-y-1",children:[e.jsx(a.Label,{htmlFor:"meta_description",className:"text-xs uppercase font-bold text-muted-foreground tracking-wider leading-none",children:"Meta Description"}),e.jsx(a.Input,{id:"meta_description",...c("meta_description"),placeholder:"SEO description (150-160 chars)",className:"h-8 text-sm"})]}),e.jsxs("div",{className:`${r?"lg:col-span-3":"lg:col-span-4"} col-span-2 space-y-1`,children:[e.jsx(a.Label,{htmlFor:"custom_canonical",className:"text-xs uppercase font-bold text-muted-foreground tracking-wider leading-none",children:"Canonical URL (optional)"}),e.jsx(a.Input,{id:"custom_canonical",...c("custom_canonical"),placeholder:"Blank = self-referencing. Absolute https://… URL or /relative path to override.",className:"h-8 text-sm"})]})]})]}),e.jsx(z,{title:"Product Categories",description:"Assign this product to one or more categories.",children:e.jsx(Qe.ProductCategorySelector,{categories:Me,selectedIds:l("category_ids")||[],onChange:t=>i("category_ids",t,{shouldDirty:!0,shouldValidate:!0})})}),e.jsxs("section",{className:"rounded-lg border bg-card p-3 shadow-sm space-y-3",children:[j&&e.jsxs("div",{className:"flex items-center justify-between gap-4 flex-wrap border-b border-muted/50 pb-2",children:[e.jsx("div",{className:"flex items-center gap-4",children:e.jsxs("div",{className:"space-y-0.5",children:[e.jsx("h2",{className:"text-sm font-bold tracking-tight",children:"Pricing & Inventory"}),e.jsx("p",{className:"text-[11px] text-muted-foreground leading-none",children:"Manage simple or variant pricing."})]})}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2 bg-muted/40 rounded-md px-2.5 py-1.5",children:[e.jsx("span",{className:"text-xs uppercase font-bold text-muted-foreground tracking-wider leading-none",children:"Stock"}),e.jsx(a.Input,{id:"stock",type:"number",min:"0",...c("stock",{valueAsNumber:!0}),placeholder:"0",readOnly:N,className:`${ze} h-8 w-20 text-sm text-center font-mono bg-background`})]}),N?e.jsx(a.Badge,{variant:"secondary",className:"text-[11px] py-0 px-2 h-5",children:"Variant pricing"}):null]})]}),j?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"w-full",children:[e.jsx(Pe.CurrencyPriceFields,{idPrefix:"product",currencies:u,prices:U.prices,salePrices:U.salePrices,managedCurrencyCodes:E,onPriceChange:je,onSalePriceChange:ve,onAutoFill:Ne,readOnly:N,helperText:N?"Parent prices stay as a fallback, but active variants define the live shopper price.":void 0,trailing:e.jsx(we.SaleScheduleFields,{idPrefix:"product",startAt:l("sale_start_at"),endAt:l("sale_end_at"),onChange:(t,d)=>i(t,d,{shouldDirty:!0,shouldValidate:!0}),error:x.sale_end_at?.message,bare:!0})}),x.price&&e.jsx("p",{className:"text-destructive text-sm mt-1",children:x.price.message}),x.sale_price&&e.jsx("p",{className:"text-destructive text-sm mt-1",children:x.sale_price.message}),x.stock&&e.jsx("p",{className:"text-destructive text-[10px] font-medium leading-none mt-1",children:x.stock.message})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded border border-dashed p-2.5 bg-muted/5",children:[e.jsx("span",{className:"text-xs font-bold uppercase tracking-wider text-muted-foreground",children:N?"Variations Active":"Variations"}),e.jsx(a.Button,{type:"button",variant:J?"outline":"default",onClick:()=>X(t=>!t),size:"sm",className:"h-7 text-xs px-3",children:J?"Hide":"Manage"})]}),J&&e.jsx("div",{className:"border-t pt-3",children:e.jsx(Ye.VariationsEditor,{globalAttributes:P,currentLanguageCode:Ee,baseSku:l("sku")||"",basePrice:w||0,basePrices:v,baseSalePrice:typeof V=="number"?V:null,baseSalePrices:C,currencies:u,availableVariantImages:Le,initialVariationAttributes:s?.variation_attributes,initialVariants:Ue,onChange:Oe})})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-end gap-4 w-full",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx(a.Label,{htmlFor:"freemius_product_id",className:"text-[11px] uppercase tracking-wider text-muted-foreground font-bold mb-1.5 block",children:"Freemius Product ID"}),e.jsx(a.Input,{id:"freemius_product_id",...c("freemius_product_id"),className:"h-9"})]}),e.jsxs("div",{className:"flex-1",children:[e.jsx(a.Label,{htmlFor:"freemius_plan_id",className:"text-[11px] uppercase tracking-wider text-muted-foreground font-bold mb-1.5 block",children:"Freemius Plan ID"}),e.jsx(a.Input,{id:"freemius_plan_id",...c("freemius_plan_id"),className:"h-9"})]}),Te?e.jsx(Xe.SyncFreemiusPricingButton,{productId:l("freemius_product_id"),hasOpenDraft:Ve}):null]}),e.jsxs("div",{className:"bg-muted/10 border rounded-md overflow-hidden",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-6 bg-muted/20 border-b p-2.5 px-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[11px] font-bold uppercase tracking-wider text-muted-foreground",children:"Free Trial"}),e.jsxs(a.Badge,{variant:"outline",className:"font-mono text-xs shadow-sm bg-background",children:[String(l("trial_period_days")||0)," Days"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[11px] font-bold uppercase tracking-wider text-muted-foreground",children:"Card Required"}),e.jsx(a.Badge,{variant:_e?"default":"secondary",className:"text-xs shadow-sm",children:_e?"Yes":"No"})]}),e.jsx("span",{className:"text-[10px] text-muted-foreground ml-auto",children:"Managed in Freemius dashboard"}),e.jsx("input",{type:"hidden",...c("trial_period_days",{valueAsNumber:!0})})]}),e.jsxs("div",{className:"w-full p-4 pt-3 space-y-2",children:[e.jsx(Pe.CurrencyPriceFields,{idPrefix:"product",currencies:u,prices:U.prices,salePrices:U.salePrices,managedCurrencyCodes:E,onPriceChange:je,onSalePriceChange:ve,onAutoFill:Ne,readOnly:!0,trailing:e.jsx(we.SaleScheduleFields,{idPrefix:"product",startAt:l("sale_start_at"),endAt:l("sale_end_at"),onChange:(t,d)=>i(t,d,{shouldDirty:!0,shouldValidate:!0}),error:x.sale_end_at?.message,bare:!0})}),e.jsx("p",{className:"text-[10px] leading-snug text-muted-foreground",children:"Scheduling a sale on a Freemius product generates a time-bounded Freemius coupon so the discount is enforced at Freemius checkout."})]})]})]}),T&&e.jsx("div",{className:"pt-2 border-t",children:T})]})]}),e.jsx(z,{title:"Product Description",hideHeader:!0,children:e.jsx("div",{className:"space-y-2",children:e.jsxs("div",{className:"space-y-1",children:[e.jsx(a.Label,{htmlFor:"short_description",className:"text-xs uppercase font-bold text-muted-foreground tracking-wider leading-none",children:"Short Description"}),e.jsx(a.Input,{id:"short_description",...c("short_description"),placeholder:"Brief summary for product cards...",className:"h-8 text-sm"})]})})}),e.jsxs(z,{title:"Media Gallery",description:"Drag to reorder. First image is the hero.",children:[e.jsx(Je.ProductMediaManager,{initialMedia:D,onUpdate:Be,mediaPickerNode:y}),e.jsx("input",{type:"hidden",...c("product_media")})]}),!r&&e.jsxs("div",{className:"rounded-lg border bg-card p-3 px-4 shadow-sm flex items-center justify-between gap-3 flex-wrap",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"New products start as a draft. Publish it from the top bar once it's ready."}),e.jsx(a.Button,{disabled:R,type:"submit",size:"sm",className:"h-8 text-sm px-5",children:R?"Saving...":"Save Changes"})]})]})]})}exports.ProductForm=ss;
1
+ "use client";const e=require("../../../../../_virtual/_rolldown/runtime.cjs.js"),t=require("../../../../types.cjs.js"),n=require("../../../../currency.cjs.js"),r=require("../../../../product-schema.cjs.js"),i=require("./ProductMediaManager.cjs.js"),a=require("./SyncFreemiusPricingButton.cjs.js"),o=require("./CurrencyPriceFields.cjs.js"),s=require("./SaleScheduleFields.cjs.js"),c=require("../product-price-sync.cjs.js"),ee=require("./VariationsEditor.cjs.js"),l=require("./ProductCategorySelector.cjs.js");let u=require("react");u=e.__toESM(u,1);let d=require("lucide-react"),f=require("@nextblock-cms/utils"),p=require("react/jsx-runtime"),te=require("react-hook-form"),ne=require("@hookform/resolvers/zod"),m=require("@nextblock-cms/ui");function h({title:e,description:t,action:n,children:r,hideHeader:i}){return(0,p.jsxs)(`section`,{className:`rounded-lg border bg-card p-3 shadow-sm space-y-3`,children:[!i&&(0,p.jsxs)(`div`,{className:`flex items-start justify-between gap-4 flex-wrap border-b border-muted/50 pb-2 mb-1`,children:[(0,p.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,p.jsx)(`h2`,{className:`text-sm font-bold tracking-tight`,children:e}),t?(0,p.jsx)(`p`,{className:`text-[11px] text-muted-foreground leading-none`,children:t}):null]}),n]}),(0,p.jsx)(`div`,{className:i?``:`pt-1`,children:r})]})}function re(e,t,n){let r=t?Number.parseInt(t,10):void 0;return e?.language_id||(Number.isFinite(r)?r:void 0)||n.find(e=>e.is_default)?.id||n[0]?.id||1}function g(e,n,r,i,a){let o=(i.find(e=>e.is_default)??i[0])?.code||`USD`,s=e?.prices&&Object.keys(e.prices).length>0?e.prices:{[o]:typeof e?.price==`number`?e.price/100:0},ee=e?.sale_prices&&Object.keys(e.sale_prices).length>0?e.sale_prices:typeof e?.sale_price==`number`?{[o]:e.sale_price/100}:{},l=e?.product_type||``,u=e?.payment_provider||(e?.product_type?t.derivePaymentProviderFromProductType(e.product_type):`stripe`);return{...c.sanitizeProductFormValuesForStoreManagedCurrencies({product_type:l||`physical`,payment_provider:u,title:e?.title||``,slug:e?.slug||``,sku:e?.sku||``,upc:e?.upc||``,is_taxable:e?.is_taxable??!0,price:typeof e?.price==`number`?e.price/100:0,prices:s,sale_price:typeof e?.sale_price==`number`?e.sale_price/100:null,sale_prices:ee,stock:e?.stock||0,meta_title:e?.meta_title||``,meta_description:e?.meta_description||``,custom_canonical:e?.custom_canonical||``,short_description:e?.short_description||``,description_json:e?.description_json||{type:`doc`,content:[{type:`paragraph`}]},freemius_product_id:e?.freemius_product_id||``,freemius_plan_id:e?.freemius_plan_id||``,trial_period_days:e?.trial_period_days??0,trial_requires_payment_method:e?.trial_requires_payment_method??!1,status:e?.status||`draft`,language_id:re(e,n,r),translation_group_id:e?.translation_group_id||a||void 0,product_media:e?.product_media?.map(e=>({media_id:e.media_id}))||[],category_ids:e?.category_ids||[],variation_attributes:e?.variation_attributes||[],variants:e?.variants?.map(e=>({...e,prices:e.prices||{},sale_prices:e.sale_prices||{}}))||[]},i),product_type:l,payment_provider:u}}function ie(e){return e?e.map(e=>({id:e.id||e.media_id,media_id:e.media_id,file_path:e.media?.file_path||e.media?.object_key||``,alt:e.media?.alt_text||``,sort_order:e.sort_order??0})).sort((e,t)=>e.sort_order-t.sort_order):[]}function ae(e){return e.map(e=>({media_id:e.media_id}))}function oe(e){return e.map(e=>({media_id:e.media_id,file_path:e.file_path,alt:e.alt}))}var se=e=>e.toString().toLowerCase().trim().replace(/\s+/g,`-`).replace(/[^\w-]+/g,``).replace(/--+/g,`-`).replace(/^-+/,``).replace(/-+$/,``);function _({initialData:e,isEdit:t=!1,mediaPickerNode:re,availableLanguagesProp:_,globalAttributesProp:ce,currenciesProp:le,translationGroupId:v,targetLanguageId:y,freemiusDashboardNode:b,enabledProviders:ue,configStatus:x,createAction:S,updateAction:de,availableCategoriesProp:fe=[],hasOpenDraft:pe=!1,onSeoChange:me}){let[C,w]=(0,u.useState)(!1),[T,E]=(0,u.useState)(()=>!!e?.variants?.length),D=u.default.useMemo(()=>le.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),[le]),O=u.default.useMemo(()=>D.find(e=>e.is_default)??D[0],[D]),k=u.default.useMemo(()=>c.getStoreManagedPriceCurrencyCodes(D),[D]),he=(0,te.useForm)({resolver:(0,ne.zodResolver)(r.productSchema),defaultValues:g(e,y,_,D,v)}),{register:A,handleSubmit:j,setValue:M,reset:ge,watch:N,setError:P,formState:{errors:F,dirtyFields:I}}=he,L=(0,u.useRef)(!0),R=(0,u.useRef)(null),[_e,z]=(0,u.useState)(!1),[ve,B]=(0,u.useState)(null),[ye,be]=(0,u.useState)(null),V=N(),xe=he.formState.isDirty,Se=V.title,Ce=V.meta_title,we=V.meta_description;(0,u.useEffect)(()=>{me?.({title:Se,meta_title:Ce,meta_description:we})},[Se,Ce,we,me]),(0,u.useEffect)(()=>{if(!t)return;if(L.current){L.current=!1,R.current=JSON.stringify(V);return}if(!xe)return;let e=JSON.stringify(V);if(e===R.current)return;let n=setTimeout(()=>{C||(R.current=e,j(He)())},400);return()=>clearTimeout(n)},[V,t,xe,C,j]);let Te=N(`title`),H=N(`product_type`),U=H===`digital`?`freemius`:H===`physical`?`stripe`:void 0,W=H===`physical`,Ee=H===`digital`,De=U?ue[U]:!1,Oe=U?x[U].hasKeys:!1,ke=!!N(`freemius_product_id`),Ae=Number(N(`trial_period_days`)||0),je=!!N(`trial_requires_payment_method`),Me=N(`variants`)||[],G=N(`price`),K=N(`sale_price`),q=N(`prices`)||{},J=N(`sale_prices`)||{},Y=(Me?.length||0)>0,Ne=N(`language_id`),Pe=_.find(e=>e.id===Ne)?.code||_.find(e=>e.is_default)?.code||_[0]?.code,X=u.default.useMemo(()=>c.resolveEditorCurrencyPriceMaps({currencies:D,prices:q,salePrices:J,fallbackPrice:G,fallbackSalePrice:K}),[G,K,D,q,J]),Fe=u.default.useMemo(()=>e?.variants?.map(e=>({...e,prices:e.prices||{},sale_prices:e.sale_prices||{}})),[e?.variants]);(0,u.useEffect)(()=>{if(I.title&&!t){let e=se(Te);M(`slug`,e,{shouldValidate:!0})}},[Te,I.title,M,t]);let[Z,Ie]=(0,u.useState)(()=>ie(e?.product_media)),[Q,$]=(0,u.useState)(new Set);(0,u.useEffect)(()=>{ge(g(e,y,_,D,v)),Ie(ie(e?.product_media)),$(new Set),E(!!e?.variants?.length)},[_,D,e,ge,y,v]);let Le=e=>{let t=new Set(e.map(e=>e.id)),n=Z.filter(e=>!t.has(e.id)),r=new Set(Q);n.forEach(e=>{e.media_id&&r.add(e.media_id)}),$(r),Ie(e),M(`product_media`,ae(e),{shouldDirty:!0}),M(`explicitly_removed_media_ids`,Array.from(r),{shouldDirty:!0})};(0,u.useEffect)(()=>{M(`explicitly_removed_media_ids`,Array.from(Q))},[Q,M]),(0,u.useEffect)(()=>{Y&&E(!0)},[Y]),(0,u.useEffect)(()=>{A(`is_taxable`),A(`price`),A(`sale_price`),A(`payment_provider`),A(`trial_requires_payment_method`)},[A]),(0,u.useEffect)(()=>{if(!Ee){M(`trial_period_days`,0,{shouldDirty:!1,shouldValidate:!0}),M(`trial_requires_payment_method`,!1,{shouldDirty:!1,shouldValidate:!0});return}Ae<=0&&M(`trial_requires_payment_method`,!1,{shouldDirty:!1,shouldValidate:!0})},[Ee,M,Ae]),(0,u.useEffect)(()=>{U&&M(`payment_provider`,U,{shouldDirty:!1,shouldValidate:!0})},[U,M]),(0,u.useEffect)(()=>{O&&q[O.code]===void 0&&M(`prices`,{...q,[O.code]:G||0},{shouldDirty:!1})},[G,O,q,M]);let Re=(0,u.useCallback)((e,t)=>{let n={...q,[e]:t};M(`prices`,n,{shouldDirty:!0,shouldValidate:!0}),e===O?.code&&M(`price`,t,{shouldDirty:!0,shouldValidate:!0})},[O?.code,q,M]),ze=(0,u.useCallback)((e,t)=>{let n={...J,[e]:t};M(`sale_prices`,n,{shouldDirty:!0,shouldValidate:!0}),e===O?.code&&M(`sale_price`,t,{shouldDirty:!0,shouldValidate:!0})},[O?.code,J,M]),Be=(0,u.useCallback)(()=>{if(!O)return;let e=new Set(k),t=q[O.code]??G??0,r=J[O.code]??K??null,i=D.reduce((r,i)=>{if(i.code!==O.code&&e.has(i.code))return r;let a=n.convertMinorUnitAmount({amount:(0,f.majorUnitAmountToMinor)(t,O.code),fromCurrencyCode:O.code,toCurrencyCode:i.code,currencies:D,applyRounding:!0});return r[i.code]=(0,f.minorUnitAmountToMajor)(a,i.code),r},{}),a=D.reduce((t,i)=>{if(i.code!==O.code&&e.has(i.code))return t;if(typeof r!=`number`)return(i.code===O.code||!e.has(i.code))&&(t[i.code]=null),t;let a=n.convertMinorUnitAmount({amount:(0,f.majorUnitAmountToMinor)(r,O.code),fromCurrencyCode:O.code,toCurrencyCode:i.code,currencies:D,applyRounding:!0});return t[i.code]=(0,f.minorUnitAmountToMajor)(a,i.code),t},{});M(`prices`,i,{shouldDirty:!0,shouldValidate:!0}),M(`sale_prices`,a,{shouldDirty:!0,shouldValidate:!0}),M(`price`,i[O.code]??t,{shouldDirty:!0,shouldValidate:!0}),M(`sale_price`,a[O.code]??null,{shouldDirty:!0,shouldValidate:!0})},[D,O,q,J,M,k,G,K]),Ve=(0,u.useCallback)(({variationAttributes:e,variants:t})=>{M(`variation_attributes`,e,{shouldDirty:!0}),M(`variants`,t,{shouldDirty:!0,shouldValidate:!0})},[M]),He=async e=>{w(!0),z(!0),B(null);try{if(!U){let e=`Select whether this product is physical or digital before saving.`;P(`product_type`,{type:`manual`,message:e}),t?B(e):alert(e),w(!1),z(!1);return}let n=W?0:Math.max(0,Number(e.trial_period_days||0)),r={...e,product_type:e.product_type,payment_provider:U,freemius_product_id:W?``:e.freemius_product_id,freemius_plan_id:W?``:e.freemius_plan_id,trial_period_days:n,trial_requires_payment_method:!W&&n>0&&e.trial_requires_payment_method,upc:W?e.upc:null,is_taxable:W?e.is_taxable:!1,variation_attributes:W?e.variation_attributes:[],variants:W?e.variants:[]},i=c.sanitizeProductFormValuesForStoreManagedCurrencies(r,D);if(t&&de)await de(i),be(new Date);else if(S)await S(i);else throw Error(`Product form action is not configured.`)}catch(e){if(console.error(e),e.message===`NEXT_REDIRECT`)return;let n=e.message||`An error occurred while saving.`;if(e.code===`23505`){let t=e.message?.toLowerCase()||``;t.includes(`products_slug_key`)||t.includes(`slug`)?(n=`This slug is already in use. Please choose another one.`,P(`slug`,{type:`manual`,message:n})):(t.includes(`products_sku_key`)||t.includes(`sku`))&&(n=`This SKU is already in use.`,P(`sku`,{type:`manual`,message:n}))}t?B(n):alert(n)}finally{w(!1),z(!1)}},Ue=Y?`bg-muted/60 text-muted-foreground opacity-70`:``,We=oe(Z);return(0,p.jsxs)(`form`,{onSubmit:j(He),className:`space-y-2.5 pb-4`,children:[(0,p.jsx)(`input`,{type:`hidden`,...A(`translation_group_id`)}),(0,p.jsx)(`input`,{type:`hidden`,...A(`payment_provider`)}),(0,p.jsxs)(`div`,{className:`space-y-2.5 w-full`,children:[(0,p.jsxs)(`div`,{className:`rounded-lg border bg-card p-2.5 px-4 shadow-sm flex items-center justify-between gap-3 flex-wrap`,children:[(0,p.jsxs)(`div`,{className:`flex items-center gap-6`,children:[(0,p.jsxs)(`div`,{className:`flex h-9 items-center gap-2`,children:[(0,p.jsx)(`span`,{className:`text-sm font-bold whitespace-nowrap leading-none pt-0.5`,children:`Product Type`}),F.product_type&&(0,p.jsx)(d.AlertCircle,{className:`h-4 w-4 text-destructive`})]}),(0,p.jsx)(`div`,{className:`flex h-9 items-center`,children:(0,p.jsxs)(m.Select,{onValueChange:e=>M(`product_type`,e,{shouldDirty:!0,shouldValidate:!0}),value:H||void 0,children:[(0,p.jsx)(m.SelectTrigger,{className:`w-[160px] h-9 text-xs`,children:(0,p.jsx)(m.SelectValue,{placeholder:`Select Type`})}),(0,p.jsxs)(m.SelectContent,{children:[(0,p.jsx)(m.SelectItem,{value:`physical`,children:`Physical Product`}),(0,p.jsx)(m.SelectItem,{value:`digital`,children:`Digital Product`})]})]})})]}),(0,p.jsxs)(`div`,{className:`flex items-center gap-6`,children:[(0,p.jsxs)(`div`,{className:`flex h-9 items-center gap-3`,children:[(0,p.jsx)(`span`,{className:`text-[11px] font-semibold text-muted-foreground uppercase tracking-wider leading-none`,children:`Payment Provider`}),(0,p.jsx)(m.Badge,{variant:`outline`,className:`text-xs py-1 font-bold bg-muted/30 leading-none`,children:U?U===`stripe`?`Stripe`:`Freemius`:`—`})]}),U&&(0,p.jsx)(`div`,{className:`flex h-9 items-center gap-2`,children:De&&Oe?(0,p.jsxs)(`span`,{className:`flex items-center gap-1.5 text-emerald-600 text-[10px] font-bold bg-emerald-50 px-2 py-1 rounded-full border border-emerald-100 uppercase leading-none`,children:[(0,p.jsx)(d.CheckCircle2,{className:`h-3 w-3`}),`Ready`]}):(0,p.jsxs)(`span`,{className:`flex items-center gap-1.5 text-amber-600 text-[10px] font-bold bg-amber-50 px-2 py-1 rounded-full border border-amber-100 uppercase leading-none`,children:[(0,p.jsx)(d.AlertCircle,{className:`h-3 w-3`}),De?`Keys Missing`:`Disabled`]})}),!Oe&&U&&x[U].missing.length>0&&(0,p.jsxs)(`a`,{href:`/cms/payments`,className:`hidden xl:flex h-9 items-center gap-1 text-[10px] text-muted-foreground bg-muted/50 px-2 py-1 rounded border border-dashed leading-none hover:text-foreground hover:border-solid`,children:[(0,p.jsx)(d.Info,{className:`h-3 w-3`}),`Missing: `,x[U].missing.join(`, `),` — set up payments`]})]})]}),(0,p.jsxs)(h,{title:`Product Information`,hideHeader:!0,children:[t&&(0,p.jsxs)(`div`,{className:`flex items-center justify-between text-xs text-muted-foreground pb-2 border-b border-border/40 mb-2.5`,children:[(0,p.jsx)(`span`,{className:`font-semibold text-[11px] uppercase tracking-wider text-muted-foreground/80`,children:`Product Settings`}),(0,p.jsx)(`div`,{className:`flex items-center gap-1.5 min-h-[16px]`,children:_e?(0,p.jsxs)(p.Fragment,{children:[(0,p.jsxs)(`div`,{className:`relative flex h-2 w-2`,children:[(0,p.jsx)(`span`,{className:`animate-ping absolute inline-flex h-full w-full rounded-full bg-amber-400 opacity-75`}),(0,p.jsx)(`span`,{className:`relative inline-flex rounded-full h-2 w-2 bg-amber-500`})]}),(0,p.jsx)(`span`,{className:`text-amber-600 dark:text-amber-400 font-medium`,children:`Autosaving settings...`})]}):ve?(0,p.jsxs)(`span`,{className:`text-red-500 font-medium`,children:[`Error saving settings: `,ve]}):ye?(0,p.jsxs)(`span`,{className:`text-emerald-600 dark:text-emerald-400 font-medium`,children:[`Settings autosaved at `,ye.toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`,second:`2-digit`})]}):(0,p.jsx)(`span`,{className:`text-muted-foreground/60`,children:`Settings autosave in draft mode`})})]}),(0,p.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-3 lg:grid-cols-6 gap-2.5`,children:[(0,p.jsxs)(`div`,{className:`col-span-2 space-y-1`,children:[(0,p.jsx)(m.Label,{htmlFor:`title`,className:`text-xs uppercase font-bold text-muted-foreground tracking-wider leading-none`,children:`Title`}),(0,p.jsx)(m.Input,{id:`title`,placeholder:`Product title`,...A(`title`),className:`h-8 text-sm`}),F.title&&(0,p.jsx)(`p`,{className:`text-destructive text-[11px] leading-none`,children:F.title.message})]}),(0,p.jsxs)(`div`,{className:`col-span-2 space-y-1`,children:[(0,p.jsx)(m.Label,{htmlFor:`slug`,className:`text-xs uppercase font-bold text-muted-foreground tracking-wider leading-none`,children:`Slug`}),(0,p.jsx)(m.Input,{id:`slug`,placeholder:`product-slug`,...A(`slug`),className:`h-8 text-sm`}),F.slug&&(0,p.jsx)(`p`,{className:`text-destructive text-[11px] leading-none`,children:F.slug.message})]}),(0,p.jsxs)(`div`,{className:`col-span-1 space-y-1`,children:[(0,p.jsx)(m.Label,{htmlFor:`sku`,className:`text-xs uppercase font-bold text-muted-foreground tracking-wider leading-none`,children:`SKU`}),(0,p.jsx)(m.Input,{id:`sku`,placeholder:`SKU`,...A(`sku`),className:`h-8 text-sm font-mono`}),F.sku&&(0,p.jsx)(`p`,{className:`text-destructive text-[11px] leading-none`,children:F.sku.message})]}),(0,p.jsxs)(`div`,{className:`col-span-1 space-y-1`,children:[(0,p.jsx)(m.Label,{htmlFor:`upc_ean`,className:`text-xs uppercase font-bold text-muted-foreground tracking-wider leading-none`,children:`UPC / EAN`}),(0,p.jsx)(m.Input,{id:`upc_ean`,placeholder:`000000000`,...A(`upc`),className:`h-8 text-sm font-mono`,readOnly:Y})]})]}),(0,p.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-3 lg:grid-cols-12 gap-2.5 mt-2`,children:[(0,p.jsxs)(`div`,{className:`${t?`lg:col-span-3`:`lg:col-span-4`} col-span-2 space-y-1`,children:[(0,p.jsx)(m.Label,{htmlFor:`meta_title`,className:`text-xs uppercase font-bold text-muted-foreground tracking-wider leading-none`,children:`Meta Title`}),(0,p.jsx)(m.Input,{id:`meta_title`,...A(`meta_title`),placeholder:`SEO page title (50-60 chars)`,className:`h-8 text-sm`})]}),(0,p.jsxs)(`div`,{className:`lg:col-span-4 col-span-2 space-y-1`,children:[(0,p.jsx)(m.Label,{htmlFor:`meta_description`,className:`text-xs uppercase font-bold text-muted-foreground tracking-wider leading-none`,children:`Meta Description`}),(0,p.jsx)(m.Input,{id:`meta_description`,...A(`meta_description`),placeholder:`SEO description (150-160 chars)`,className:`h-8 text-sm`})]}),(0,p.jsxs)(`div`,{className:`${t?`lg:col-span-3`:`lg:col-span-4`} col-span-2 space-y-1`,children:[(0,p.jsx)(m.Label,{htmlFor:`custom_canonical`,className:`text-xs uppercase font-bold text-muted-foreground tracking-wider leading-none`,children:`Canonical URL (optional)`}),(0,p.jsx)(m.Input,{id:`custom_canonical`,...A(`custom_canonical`),placeholder:`Blank = self-referencing. Absolute https://… URL or /relative path to override.`,className:`h-8 text-sm`})]})]})]}),(0,p.jsx)(h,{title:`Product Categories`,description:`Assign this product to one or more categories.`,children:(0,p.jsx)(l.ProductCategorySelector,{categories:fe,selectedIds:N(`category_ids`)||[],onChange:e=>M(`category_ids`,e,{shouldDirty:!0,shouldValidate:!0})})}),(0,p.jsxs)(`section`,{className:`rounded-lg border bg-card p-3 shadow-sm space-y-3`,children:[W&&(0,p.jsxs)(`div`,{className:`flex items-center justify-between gap-4 flex-wrap border-b border-muted/50 pb-2`,children:[(0,p.jsx)(`div`,{className:`flex items-center gap-4`,children:(0,p.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,p.jsx)(`h2`,{className:`text-sm font-bold tracking-tight`,children:`Pricing & Inventory`}),(0,p.jsx)(`p`,{className:`text-[11px] text-muted-foreground leading-none`,children:`Manage simple or variant pricing.`})]})}),(0,p.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,p.jsxs)(`div`,{className:`flex items-center gap-2 bg-muted/40 rounded-md px-2.5 py-1.5`,children:[(0,p.jsx)(`span`,{className:`text-xs uppercase font-bold text-muted-foreground tracking-wider leading-none`,children:`Stock`}),(0,p.jsx)(m.Input,{id:`stock`,type:`number`,min:`0`,...A(`stock`,{valueAsNumber:!0}),placeholder:`0`,readOnly:Y,className:`${Ue} h-8 w-20 text-sm text-center font-mono bg-background`})]}),Y?(0,p.jsx)(m.Badge,{variant:`secondary`,className:`text-[11px] py-0 px-2 h-5`,children:`Variant pricing`}):null]})]}),W?(0,p.jsxs)(`div`,{className:`space-y-3`,children:[(0,p.jsxs)(`div`,{className:`w-full`,children:[(0,p.jsx)(o.CurrencyPriceFields,{idPrefix:`product`,currencies:D,prices:X.prices,salePrices:X.salePrices,managedCurrencyCodes:k,onPriceChange:Re,onSalePriceChange:ze,onAutoFill:Be,readOnly:Y,helperText:Y?`Parent prices stay as a fallback, but active variants define the live shopper price.`:void 0,trailing:(0,p.jsx)(s.SaleScheduleFields,{idPrefix:`product`,startAt:N(`sale_start_at`),endAt:N(`sale_end_at`),onChange:(e,t)=>M(e,t,{shouldDirty:!0,shouldValidate:!0}),error:F.sale_end_at?.message,bare:!0})}),F.price&&(0,p.jsx)(`p`,{className:`text-destructive text-sm mt-1`,children:F.price.message}),F.sale_price&&(0,p.jsx)(`p`,{className:`text-destructive text-sm mt-1`,children:F.sale_price.message}),F.stock&&(0,p.jsx)(`p`,{className:`text-destructive text-[10px] font-medium leading-none mt-1`,children:F.stock.message})]}),(0,p.jsxs)(`div`,{className:`flex items-center justify-between gap-3 rounded border border-dashed p-2.5 bg-muted/5`,children:[(0,p.jsx)(`span`,{className:`text-xs font-bold uppercase tracking-wider text-muted-foreground`,children:Y?`Variations Active`:`Variations`}),(0,p.jsx)(m.Button,{type:`button`,variant:T?`outline`:`default`,onClick:()=>E(e=>!e),size:`sm`,className:`h-7 text-xs px-3`,children:T?`Hide`:`Manage`})]}),T&&(0,p.jsx)(`div`,{className:`border-t pt-3`,children:(0,p.jsx)(ee.VariationsEditor,{globalAttributes:ce,currentLanguageCode:Pe,baseSku:N(`sku`)||``,basePrice:G||0,basePrices:q,baseSalePrice:typeof K==`number`?K:null,baseSalePrices:J,currencies:D,availableVariantImages:We,initialVariationAttributes:e?.variation_attributes,initialVariants:Fe,onChange:Ve})})]}):(0,p.jsxs)(p.Fragment,{children:[(0,p.jsxs)(`div`,{className:`space-y-4`,children:[(0,p.jsxs)(`div`,{className:`flex items-end gap-4 w-full`,children:[(0,p.jsxs)(`div`,{className:`flex-1`,children:[(0,p.jsx)(m.Label,{htmlFor:`freemius_product_id`,className:`text-[11px] uppercase tracking-wider text-muted-foreground font-bold mb-1.5 block`,children:`Freemius Product ID`}),(0,p.jsx)(m.Input,{id:`freemius_product_id`,...A(`freemius_product_id`),className:`h-9`})]}),(0,p.jsxs)(`div`,{className:`flex-1`,children:[(0,p.jsx)(m.Label,{htmlFor:`freemius_plan_id`,className:`text-[11px] uppercase tracking-wider text-muted-foreground font-bold mb-1.5 block`,children:`Freemius Plan ID`}),(0,p.jsx)(m.Input,{id:`freemius_plan_id`,...A(`freemius_plan_id`),className:`h-9`})]}),ke?(0,p.jsx)(a.SyncFreemiusPricingButton,{productId:N(`freemius_product_id`),hasOpenDraft:pe}):null]}),(0,p.jsxs)(`div`,{className:`bg-muted/10 border rounded-md overflow-hidden`,children:[(0,p.jsxs)(`div`,{className:`flex flex-wrap items-center gap-6 bg-muted/20 border-b p-2.5 px-4`,children:[(0,p.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,p.jsx)(`span`,{className:`text-[11px] font-bold uppercase tracking-wider text-muted-foreground`,children:`Free Trial`}),(0,p.jsxs)(m.Badge,{variant:`outline`,className:`font-mono text-xs shadow-sm bg-background`,children:[String(N(`trial_period_days`)||0),` Days`]})]}),(0,p.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,p.jsx)(`span`,{className:`text-[11px] font-bold uppercase tracking-wider text-muted-foreground`,children:`Card Required`}),(0,p.jsx)(m.Badge,{variant:je?`default`:`secondary`,className:`text-xs shadow-sm`,children:je?`Yes`:`No`})]}),(0,p.jsx)(`span`,{className:`text-[10px] text-muted-foreground ml-auto`,children:`Managed in Freemius dashboard`}),(0,p.jsx)(`input`,{type:`hidden`,...A(`trial_period_days`,{valueAsNumber:!0})})]}),(0,p.jsxs)(`div`,{className:`w-full p-4 pt-3 space-y-2`,children:[(0,p.jsx)(o.CurrencyPriceFields,{idPrefix:`product`,currencies:D,prices:X.prices,salePrices:X.salePrices,managedCurrencyCodes:k,onPriceChange:Re,onSalePriceChange:ze,onAutoFill:Be,readOnly:!0,trailing:(0,p.jsx)(s.SaleScheduleFields,{idPrefix:`product`,startAt:N(`sale_start_at`),endAt:N(`sale_end_at`),onChange:(e,t)=>M(e,t,{shouldDirty:!0,shouldValidate:!0}),error:F.sale_end_at?.message,bare:!0})}),(0,p.jsx)(`p`,{className:`text-[10px] leading-snug text-muted-foreground`,children:`Scheduling a sale on a Freemius product generates a time-bounded Freemius coupon so the discount is enforced at Freemius checkout.`})]})]})]}),b&&(0,p.jsx)(`div`,{className:`pt-2 border-t`,children:b})]})]}),(0,p.jsx)(h,{title:`Product Description`,hideHeader:!0,children:(0,p.jsx)(`div`,{className:`space-y-2`,children:(0,p.jsxs)(`div`,{className:`space-y-1`,children:[(0,p.jsx)(m.Label,{htmlFor:`short_description`,className:`text-xs uppercase font-bold text-muted-foreground tracking-wider leading-none`,children:`Short Description`}),(0,p.jsx)(m.Input,{id:`short_description`,...A(`short_description`),placeholder:`Brief summary for product cards...`,className:`h-8 text-sm`})]})})}),(0,p.jsxs)(h,{title:`Media Gallery`,description:`Drag to reorder. First image is the hero.`,children:[(0,p.jsx)(i.ProductMediaManager,{initialMedia:Z,onUpdate:Le,mediaPickerNode:re}),(0,p.jsx)(`input`,{type:`hidden`,...A(`product_media`)})]}),!t&&(0,p.jsxs)(`div`,{className:`rounded-lg border bg-card p-3 px-4 shadow-sm flex items-center justify-between gap-3 flex-wrap`,children:[(0,p.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`New products start as a draft. Publish it from the top bar once it's ready.`}),(0,p.jsx)(m.Button,{disabled:C,type:`submit`,size:`sm`,className:`h-8 text-sm px-5`,children:C?`Saving...`:`Save Changes`})]})]})]})}exports.ProductForm=_;