@nextblock-cms/ecom 0.8.6 → 0.8.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (277) hide show
  1. package/index.cjs.js +1 -1
  2. package/index.es.js +136 -533
  3. package/lib/CurrencyProvider.cjs.js +1 -0
  4. package/lib/CurrencyProvider.es.js +99 -0
  5. package/lib/cart-store.cjs.js +1 -0
  6. package/{cart-store.es.js → lib/cart-store.es.js} +13 -13
  7. package/lib/components/AccountNavigationMenu.cjs.js +1 -0
  8. package/lib/components/AccountNavigationMenu.es.js +44 -0
  9. package/lib/components/AddToCartButton.cjs.js +1 -0
  10. package/{AddToCartButton-ffE0DhHu.js → lib/components/AddToCartButton.es.js} +14 -13
  11. package/lib/components/Cart.cjs.js +1 -0
  12. package/lib/components/Cart.es.js +148 -0
  13. package/lib/components/CartDrawer.cjs.js +1 -0
  14. package/{components → lib/components}/CartDrawer.es.js +15 -14
  15. package/{components → lib/components}/CartIcon.cjs.js +1 -1
  16. package/{components → lib/components}/CartIcon.es.js +1 -0
  17. package/lib/components/Checkout.cjs.js +1 -0
  18. package/{components → lib/components}/Checkout.es.js +330 -363
  19. package/lib/components/CouponForm.cjs.js +1 -0
  20. package/lib/components/CouponForm.es.js +136 -0
  21. package/lib/components/CurrencySwitcher.cjs.js +1 -0
  22. package/{components → lib/components}/CurrencySwitcher.es.js +5 -4
  23. package/lib/components/CustomerProfileForm.cjs.js +1 -0
  24. package/lib/components/CustomerProfileForm.es.js +355 -0
  25. package/lib/components/FeaturedProduct.cjs.js +1 -0
  26. package/{components → lib/components}/FeaturedProduct.es.js +9 -8
  27. package/lib/components/InvoiceDocument.cjs.js +1 -0
  28. package/lib/components/InvoiceDocument.es.js +196 -0
  29. package/lib/components/InvoiceViewerShell.cjs.js +29 -0
  30. package/lib/components/InvoiceViewerShell.es.js +100 -0
  31. package/lib/components/ProductCard.cjs.js +1 -0
  32. package/lib/components/ProductCard.es.js +119 -0
  33. package/lib/components/ProductDetailsLayout.cjs.js +1 -0
  34. package/lib/components/ProductDetailsLayout.es.js +361 -0
  35. package/lib/components/ProductGallery.cjs.js +1 -0
  36. package/lib/components/ProductGallery.es.js +41 -0
  37. package/lib/components/ProductGrid.cjs.js +1 -0
  38. package/lib/components/ProductGrid.es.js +19 -0
  39. package/lib/components/ShippingEstimator.cjs.js +1 -0
  40. package/lib/components/ShippingEstimator.es.js +125 -0
  41. package/lib/components/SubscriptionSelector.cjs.js +1 -0
  42. package/lib/components/SubscriptionSelector.es.js +140 -0
  43. package/lib/countries.cjs.js +1 -0
  44. package/lib/countries.es.js +77 -0
  45. package/lib/coupon-server.cjs.js +1 -0
  46. package/{coupon-server-DUKVtyYs.js → lib/coupon-server.es.js} +68 -82
  47. package/lib/coupons.cjs.js +1 -0
  48. package/lib/coupons.es.js +17 -0
  49. package/lib/currency-store.cjs.js +1 -0
  50. package/lib/currency-store.es.js +27 -0
  51. package/lib/currency-sync.cjs.js +1 -0
  52. package/lib/currency-sync.es.js +180 -0
  53. package/lib/customer-addresses.cjs.js +1 -0
  54. package/lib/customer-addresses.es.js +116 -0
  55. package/lib/customer-orders.cjs.js +1 -0
  56. package/lib/customer-orders.es.js +45 -0
  57. package/lib/customer.cjs.js +1 -0
  58. package/{customer-C3xccjUg.js → lib/customer.es.js} +15 -14
  59. package/lib/export-helpers.cjs.js +1 -0
  60. package/lib/export-helpers.es.js +56 -0
  61. package/lib/factory.cjs.js +1 -0
  62. package/lib/factory.es.js +8 -0
  63. package/lib/freemius-coupons.cjs.js +1 -0
  64. package/lib/freemius-coupons.es.js +272 -0
  65. package/lib/freemius-order-sync.cjs.js +1 -0
  66. package/lib/freemius-order-sync.es.js +284 -0
  67. package/lib/inventory-settings.cjs.js +1 -0
  68. package/lib/inventory-settings.es.js +86 -0
  69. package/lib/invoice-server.cjs.js +33 -0
  70. package/lib/invoice-server.es.js +141 -0
  71. package/lib/invoice-ui.cjs.js +1 -0
  72. package/lib/invoice-ui.es.js +71 -0
  73. package/lib/invoice.cjs.js +1 -0
  74. package/lib/invoice.es.js +102 -0
  75. package/lib/order-inventory.cjs.js +61 -0
  76. package/lib/order-inventory.es.js +128 -0
  77. package/lib/order-tax-details.cjs.js +1 -0
  78. package/lib/order-tax-details.es.js +164 -0
  79. package/lib/pages/cms/coupons/CouponEditorForm.cjs.js +1 -0
  80. package/lib/pages/cms/coupons/CouponEditorForm.es.js +189 -0
  81. package/lib/pages/cms/coupons/CouponsPage.cjs.js +5 -0
  82. package/lib/pages/cms/coupons/CouponsPage.es.js +171 -0
  83. package/lib/pages/cms/coupons/CreateCouponDialog.cjs.js +1 -0
  84. package/lib/pages/cms/coupons/CreateCouponDialog.es.js +35 -0
  85. package/lib/pages/cms/coupons/EditCouponPage.cjs.js +1 -0
  86. package/lib/pages/cms/coupons/EditCouponPage.es.js +48 -0
  87. package/lib/pages/cms/coupons/ProductScopePicker.cjs.js +1 -0
  88. package/lib/pages/cms/coupons/ProductScopePicker.es.js +120 -0
  89. package/lib/pages/cms/coupons/actions.cjs.js +1 -0
  90. package/lib/pages/cms/coupons/actions.es.js +128 -0
  91. package/lib/pages/cms/coupons/product-options.cjs.js +1 -0
  92. package/lib/pages/cms/coupons/product-options.es.js +27 -0
  93. package/lib/pages/cms/orders/ExportReportsDialog.cjs.js +1 -0
  94. package/lib/pages/cms/orders/ExportReportsDialog.es.js +130 -0
  95. package/lib/pages/cms/orders/OrderDetailPage.cjs.js +1 -0
  96. package/lib/pages/cms/orders/OrderDetailPage.es.js +137 -0
  97. package/lib/pages/cms/orders/OrderPrintButton.cjs.js +1 -0
  98. package/lib/pages/cms/orders/OrderPrintButton.es.js +22 -0
  99. package/lib/pages/cms/orders/OrderStatusForm.cjs.js +1 -0
  100. package/lib/pages/cms/orders/OrderStatusForm.es.js +71 -0
  101. package/lib/pages/cms/orders/OrdersPage.cjs.js +1 -0
  102. package/lib/pages/cms/orders/OrdersPage.es.js +104 -0
  103. package/lib/pages/cms/orders/actions.cjs.js +7 -0
  104. package/lib/pages/cms/orders/actions.es.js +71 -0
  105. package/lib/pages/cms/orders/export-actions.cjs.js +1 -0
  106. package/lib/pages/cms/orders/export-actions.es.js +27 -0
  107. package/lib/pages/cms/orders/server-actions.cjs.js +1 -0
  108. package/lib/pages/cms/orders/server-actions.es.js +55 -0
  109. package/lib/pages/cms/payments/PaymentsClient.cjs.js +1 -0
  110. package/lib/pages/cms/payments/PaymentsClient.es.js +188 -0
  111. package/lib/pages/cms/payments/PaymentsPage.cjs.js +1 -0
  112. package/lib/pages/cms/payments/PaymentsPage.es.js +29 -0
  113. package/lib/pages/cms/payments/actions.cjs.js +1 -0
  114. package/lib/pages/cms/payments/actions.es.js +23 -0
  115. package/lib/pages/cms/payments/queries.cjs.js +1 -0
  116. package/lib/pages/cms/payments/queries.es.js +30 -0
  117. package/lib/pages/cms/products/ProductsPage.cjs.js +1 -0
  118. package/lib/pages/cms/products/ProductsPage.es.js +46 -0
  119. package/lib/pages/cms/products/_id_/edit/EditProductPage.cjs.js +1 -0
  120. package/lib/pages/cms/products/_id_/edit/EditProductPage.es.js +156 -0
  121. package/lib/pages/cms/products/actions.cjs.js +44 -0
  122. package/lib/pages/cms/products/actions.es.js +175 -0
  123. package/lib/pages/cms/products/attributes/AttributeManagementPage.cjs.js +1 -0
  124. package/lib/pages/cms/products/attributes/AttributeManagementPage.es.js +48 -0
  125. package/lib/pages/cms/products/attributes/components/AttributeManager.cjs.js +1 -0
  126. package/lib/pages/cms/products/attributes/components/AttributeManager.es.js +291 -0
  127. package/lib/pages/cms/products/categories/CategoryManagementPage.cjs.js +1 -0
  128. package/lib/pages/cms/products/categories/CategoryManagementPage.es.js +36 -0
  129. package/lib/pages/cms/products/categories/components/CategoryManager.cjs.js +1 -0
  130. package/lib/pages/cms/products/categories/components/CategoryManager.es.js +263 -0
  131. package/lib/pages/cms/products/components/CopyProductFromLanguage.cjs.js +1 -0
  132. package/lib/pages/cms/products/components/CopyProductFromLanguage.es.js +114 -0
  133. package/lib/pages/cms/products/components/CurrencyPriceFields.cjs.js +1 -0
  134. package/lib/pages/cms/products/components/CurrencyPriceFields.es.js +107 -0
  135. package/lib/pages/cms/products/components/DeleteProductButton.cjs.js +1 -0
  136. package/lib/pages/cms/products/components/DeleteProductButton.es.js +48 -0
  137. package/lib/pages/cms/products/components/FreemiusPricingDashboard.cjs.js +1 -0
  138. package/lib/pages/cms/products/components/FreemiusPricingDashboard.es.js +86 -0
  139. package/lib/pages/cms/products/components/ProductCategorySelector.cjs.js +1 -0
  140. package/lib/pages/cms/products/components/ProductCategorySelector.es.js +160 -0
  141. package/lib/pages/cms/products/components/ProductForm.cjs.js +1 -0
  142. package/lib/pages/cms/products/components/ProductForm.es.js +702 -0
  143. package/lib/pages/cms/products/components/ProductMediaManager.cjs.js +1 -0
  144. package/lib/pages/cms/products/components/ProductMediaManager.es.js +104 -0
  145. package/lib/pages/cms/products/components/ProductsBulkTable.cjs.js +1 -0
  146. package/lib/pages/cms/products/components/ProductsBulkTable.es.js +228 -0
  147. package/lib/pages/cms/products/components/SaleScheduleFields.cjs.js +1 -0
  148. package/lib/pages/cms/products/components/SaleScheduleFields.es.js +137 -0
  149. package/lib/pages/cms/products/components/SyncFreemiusButton.cjs.js +1 -0
  150. package/lib/pages/cms/products/components/SyncFreemiusButton.es.js +36 -0
  151. package/lib/pages/cms/products/components/SyncFreemiusPricingButton.cjs.js +1 -0
  152. package/lib/pages/cms/products/components/SyncFreemiusPricingButton.es.js +40 -0
  153. package/lib/pages/cms/products/components/VariationsEditor.cjs.js +1 -0
  154. package/lib/pages/cms/products/components/VariationsEditor.es.js +408 -0
  155. package/lib/pages/cms/products/inventory/InventoryPage.cjs.js +1 -0
  156. package/lib/pages/cms/products/inventory/InventoryPage.es.js +16 -0
  157. package/lib/pages/cms/products/inventory/InventoryTableClient.cjs.js +2 -0
  158. package/lib/pages/cms/products/inventory/InventoryTableClient.es.js +214 -0
  159. package/lib/pages/cms/products/inventory/actions.cjs.js +3 -0
  160. package/lib/pages/cms/products/inventory/actions.es.js +95 -0
  161. package/lib/pages/cms/products/new/NewProductPage.cjs.js +1 -0
  162. package/lib/pages/cms/products/new/NewProductPage.es.js +76 -0
  163. package/lib/pages/cms/products/product-price-sync.cjs.js +1 -0
  164. package/lib/pages/cms/products/product-price-sync.es.js +98 -0
  165. package/lib/pages/cms/products/server-actions.cjs.js +1 -0
  166. package/lib/pages/cms/products/server-actions.es.js +193 -0
  167. package/lib/pages/cms/shipping/ShippingPage.cjs.js +5 -0
  168. package/lib/pages/cms/shipping/ShippingPage.es.js +211 -0
  169. package/lib/pages/cms/shipping/components/RateForm.cjs.js +1 -0
  170. package/lib/pages/cms/shipping/components/RateForm.es.js +441 -0
  171. package/lib/pages/cms/shipping/components/ZoneForm.cjs.js +1 -0
  172. package/lib/pages/cms/shipping/components/ZoneForm.es.js +228 -0
  173. package/lib/pages/cms/shipping/server-actions.cjs.js +1 -0
  174. package/lib/pages/cms/shipping/server-actions.es.js +159 -0
  175. package/lib/pages/cms/taxes/TaxesPage.cjs.js +1 -0
  176. package/lib/pages/cms/taxes/TaxesPage.es.js +172 -0
  177. package/lib/pages/cms/taxes/actions.cjs.js +1 -0
  178. package/lib/pages/cms/taxes/actions.es.js +57 -0
  179. package/lib/pages/cms/taxes/components/TaxRateForm.cjs.js +1 -0
  180. package/lib/pages/cms/taxes/components/TaxRateForm.es.js +100 -0
  181. package/lib/product-actions.cjs.js +237 -0
  182. package/lib/product-actions.es.js +524 -0
  183. package/lib/product-context.cjs.js +1 -0
  184. package/lib/product-context.es.js +16 -0
  185. package/lib/product-schema.cjs.js +1 -0
  186. package/lib/product-schema.es.js +134 -0
  187. package/lib/providers/freemius.cjs.js +5 -0
  188. package/lib/providers/freemius.es.js +538 -0
  189. package/lib/providers/stripe.cjs.js +1 -0
  190. package/lib/providers/stripe.es.js +473 -0
  191. package/lib/server-actions/coupon-actions.cjs.js +1 -0
  192. package/lib/server-actions/coupon-actions.es.js +23 -0
  193. package/lib/server-actions/customer-actions.cjs.js +1 -0
  194. package/lib/server-actions/customer-actions.es.js +30 -0
  195. package/lib/server-actions/product-actions.cjs.js +1 -0
  196. package/{server-actions → lib/server-actions}/product-actions.es.js +5 -4
  197. package/lib/server-actions/shipping-actions.cjs.js +1 -0
  198. package/{shipping-actions-BnHjlo2q.js → lib/server-actions/shipping-actions.es.js} +9 -7
  199. package/lib/server-actions/tax-actions.cjs.js +1 -0
  200. package/lib/server-actions/tax-actions.es.js +40 -0
  201. package/lib/shared-inventory.cjs.js +15 -0
  202. package/lib/shared-inventory.es.js +171 -0
  203. package/lib/shipping/resolver.cjs.js +7 -0
  204. package/lib/shipping/resolver.es.js +62 -0
  205. package/lib/shipping-rate-currency.cjs.js +1 -0
  206. package/lib/shipping-rate-currency.es.js +72 -0
  207. package/lib/states.cjs.js +1 -0
  208. package/{states-DlHJezQ1.js → lib/states.es.js} +27 -100
  209. package/lib/stripe/checkout.cjs.js +1 -0
  210. package/lib/stripe/checkout.es.js +182 -0
  211. package/lib/stripe/client.cjs.js +1 -0
  212. package/lib/stripe/client.es.js +7 -0
  213. package/lib/stripe/order-sync.cjs.js +1 -0
  214. package/lib/stripe/order-sync.es.js +130 -0
  215. package/lib/stripe/webhooks.cjs.js +1 -0
  216. package/lib/stripe/webhooks.es.js +30 -0
  217. package/lib/tax-calculation.cjs.js +1 -0
  218. package/lib/tax-calculation.es.js +101 -0
  219. package/lib/trials.cjs.js +1 -0
  220. package/{trials-RDcRAZKx.js → lib/trials.es.js} +9 -9
  221. package/{use-cart.es.js → lib/use-cart.es.js} +1 -0
  222. package/lib/zod-config.cjs.js +1 -0
  223. package/lib/zod-config.es.js +6 -0
  224. package/package.json +4 -4
  225. package/server.cjs.js +1 -110
  226. package/server.es.js +178 -6052
  227. package/AddToCartButton-DsSEH9yp.cjs +0 -1
  228. package/CouponForm-BI_5SBHQ.js +0 -152
  229. package/CouponForm-D_uu2bLP.cjs +0 -1
  230. package/CurrencyProvider-Cg-Q6ucj.cjs +0 -1
  231. package/CurrencyProvider-OzlRN96V.js +0 -120
  232. package/CurrencyProvider.cjs.js +0 -1
  233. package/CurrencyProvider.es.js +0 -10
  234. package/ProductDetailsLayout-BxJH_BxR.cjs +0 -1
  235. package/ProductDetailsLayout-Dg8dRTYp.js +0 -530
  236. package/ProductGrid-BdL7iglO.cjs +0 -1
  237. package/ProductGrid-D3AWM8sr.js +0 -130
  238. package/actions-AHmBrS5e.cjs +0 -48
  239. package/actions-j5fuSZX-.js +0 -820
  240. package/cart-store.cjs.js +0 -1
  241. package/components/Cart.cjs.js +0 -1
  242. package/components/Cart.es.js +0 -259
  243. package/components/CartDrawer.cjs.js +0 -1
  244. package/components/Checkout.cjs.js +0 -1
  245. package/components/CurrencySwitcher.cjs.js +0 -1
  246. package/components/FeaturedProduct.cjs.js +0 -1
  247. package/components/ProductDetailsLayout.cjs.js +0 -1
  248. package/components/ProductDetailsLayout.es.js +0 -19
  249. package/components/ProductGrid.cjs.js +0 -1
  250. package/components/ProductGrid.es.js +0 -6
  251. package/coupon-server-C9ySm3I5.cjs +0 -1
  252. package/customer-C-UPvrYN.cjs +0 -1
  253. package/invoice-ui-CAnJPu6n.cjs +0 -29
  254. package/invoice-ui-DtpbTJE1.js +0 -2886
  255. package/product-actions-CONBF8i6.cjs +0 -251
  256. package/product-actions-DjlIWCMH.js +0 -691
  257. package/resolver-Fz_FKsfX.cjs +0 -7
  258. package/resolver-cfrCaHpE.js +0 -128
  259. package/server-actions/product-actions.cjs.js +0 -1
  260. package/shipping-actions-D6zt20gg.cjs +0 -1
  261. package/states-CWYRxV4B.cjs +0 -1
  262. package/tax-calculation-Dab89aHd.js +0 -181
  263. package/tax-calculation-MkDKOEkL.cjs +0 -1
  264. package/trials-DvZaOtNy.cjs +0 -1
  265. /package/{components → lib/components}/SimpleTiptapRenderer.cjs.js +0 -0
  266. /package/{components → lib/components}/SimpleTiptapRenderer.es.js +0 -0
  267. /package/{currency-constants.cjs.js → lib/currency-constants.cjs.js} +0 -0
  268. /package/{currency-constants.es.js → lib/currency-constants.es.js} +0 -0
  269. /package/{currency-rest-client-uolJxUkL.cjs → lib/currency-rest-client.cjs.js} +0 -0
  270. /package/{currency-rest-client-CwoqdgAP.js → lib/currency-rest-client.es.js} +0 -0
  271. /package/{currency.cjs.js → lib/currency.cjs.js} +0 -0
  272. /package/{currency.es.js → lib/currency.es.js} +0 -0
  273. /package/{types.cjs.js → lib/types.cjs.js} +0 -0
  274. /package/{types.es.js → lib/types.es.js} +0 -0
  275. /package/{use-cart.cjs.js → lib/use-cart.cjs.js} +0 -0
  276. /package/{variation-utils.cjs.js → lib/variation-utils.cjs.js} +0 -0
  277. /package/{variation-utils.es.js → lib/variation-utils.es.js} +0 -0
@@ -1,29 +0,0 @@
1
- "use strict";const t=require("react/jsx-runtime"),Fe=require("next/link"),V=require("lucide-react"),st=require("@nextblock-cms/ui/button"),gt=require("next/image"),y=require("react"),Vt=require("@hookform/resolvers/zod"),d=require("@nextblock-cms/ui"),u=require("zod"),Lt=require("react-hook-form"),ae=require("sonner"),Me=require("./actions-AHmBrS5e.cjs"),de=require("./variation-utils.cjs.js"),Y=require("./currency.cjs.js"),R=require("@nextblock-cms/utils"),L=require("@nextblock-cms/db/server"),$e=require("./product-actions-CONBF8i6.cjs"),w=require("next/cache"),Bt=require("next/navigation"),Kt=require("./types.cjs.js"),Jt="invoice_settings",Ue={businessName:"",email:"",phone:"",address:{line1:"",line2:"",city:"",state:"",postal_code:"",country_code:"CA"},taxRegistrations:[]};function X(e){return typeof e!="string"?"":e.trim()}function _t(e){if(!e||typeof e!="object"||Array.isArray(e))return{...Ue.address};const r=e;return{line1:X(r.line1),line2:X(r.line2),city:X(r.city),state:X(r.state),postal_code:X(r.postal_code),country_code:X(r.country_code).toUpperCase()||"CA"}}function ht(e){return Array.isArray(e)?e.map(r=>{if(!r||typeof r!="object"||Array.isArray(r))return null;const n=r,s=X(n.label),a=X(n.value);return!s&&!a?null:{label:s,value:a}}).filter(r=>!!r):[]}function Gt(e){if(!e||typeof e!="object"||Array.isArray(e))return{...Ue};const r=e;return{businessName:X(r.business_name??r.businessName),email:X(r.email),phone:X(r.phone),address:_t(r.address),taxRegistrations:ht(r.tax_registrations??r.taxRegistrations)}}function Xt(e){return{business_name:X(e.businessName),email:X(e.email),phone:X(e.phone),address:_t(e.address),tax_registrations:ht(e.taxRegistrations)}}function re(e,r="usd",n="en-US"){return new Intl.NumberFormat(n,{style:"currency",currency:r.toUpperCase()}).format(e/100)}function bt(e,r="en-US"){if(!e)return"";const n=new Date(e);return Number.isNaN(n.getTime())?"":new Intl.DateTimeFormat(r,{year:"numeric",month:"short",day:"numeric"}).format(n)}function je(e){if(!e)return[];const r=[e.city,e.state,e.postal_code].filter(Boolean).join(", ").replace(", ,",",").trim();return["company_name"in e&&e.company_name||"","recipient_name"in e&&e.recipient_name||"",e.line1||"",e.line2||"",r,e.country_code||""].filter(Boolean)}const nt={gst:"GST",qst:"QST",hst:"HST",pst:"PST",vat:"VAT",sales_tax:"Sales Tax",amusement_tax:"Amusement Tax",retail_delivery_fee:"Retail Delivery Fee"};function Ve(){return new Date().toISOString()}function me(e){const r=e.tax_type?.trim().toLowerCase();return r&&nt[r]?nt[r]:e.display_name||"Tax"}function pe(e){return typeof e.effective_percentage=="number"?e.effective_percentage:typeof e.percentage=="number"?e.percentage:null}function ve(e){return e.jurisdiction?e.jurisdiction:[e.state,e.country].filter(Boolean).join(", ")||null}function Yt(e){return JSON.stringify({source:e.source,rate_id:e.rate.id??null,display_name:me(e.rate),percentage:pe(e.rate),jurisdiction:ve(e.rate),jurisdiction_level:e.rate.jurisdiction_level??null,country:e.rate.country??null,state:e.rate.state??null,tax_type:e.rate.tax_type??null,inclusive:e.rate.inclusive??null})}function Le(e){const r=new Map;for(const n of e){const s=Yt(n),a=r.get(s);if(!a){r.set(s,{...n,scope:"aggregate",line_item_id:null});continue}a.amount+=n.amount,typeof a.taxable_amount=="number"||typeof n.taxable_amount=="number"?a.taxable_amount=(typeof a.taxable_amount=="number"?a.taxable_amount:0)+(typeof n.taxable_amount=="number"?n.taxable_amount:0):a.taxable_amount=null,a.description!==n.description&&(a.description=null),a.taxability_reason!==n.taxability_reason&&(a.taxability_reason=null)}return[...r.values()].sort((n,s)=>{const a=me(n.rate).localeCompare(me(s.rate));return a!==0?a:(pe(n.rate)??0)-(pe(s.rate)??0)})}function Ht(e){if(!e||typeof e!="object"||Array.isArray(e))return null;const r=e;return typeof r.currency!="string"?null:{source:r.source==="manual"||r.source==="stripe_checkout"||r.source==="none"?r.source:"none",mode:r.mode==="automatic"?"automatic":"manual",currency:r.currency,subtotal:typeof r.subtotal=="number"?r.subtotal:0,shipping_total:typeof r.shipping_total=="number"?r.shipping_total:0,tax_total:typeof r.tax_total=="number"?r.tax_total:0,total:typeof r.total=="number"?r.total:0,is_finalized:!!r.is_finalized,lines:Array.isArray(r.lines)?Le(r.lines):[],updated_at:typeof r.updated_at=="string"?r.updated_at:Ve()}}function Qt(e){const r=e.currency||"usd",n=e.calculation.mode==="manual"&&!e.calculation.isPendingExternalCalculation;return{source:e.calculation.enabled&&e.calculation.mode==="manual"?"manual":e.calculation.mode==="automatic"?"stripe_checkout":"none",mode:e.calculation.mode,currency:r,subtotal:e.subtotal,shipping_total:e.shippingTotal,tax_total:e.calculation.amount,total:e.total,is_finalized:n,lines:e.calculation.enabled&&e.calculation.mode==="manual"?e.calculation.lines.map(s=>({scope:"aggregate",source:"manual",amount:s.amount,taxable_amount:e.calculation.taxableSubtotal,description:s.name,rate:{id:s.id??null,display_name:s.name,percentage:s.rate,country:s.country_code,state:s.state_code??null}})):[],updated_at:Ve()}}function at(e){return{id:e.id,display_name:e.display_name,percentage:e.percentage,effective_percentage:e.effective_percentage,jurisdiction:e.jurisdiction,jurisdiction_level:e.jurisdiction_level,country:e.country,state:e.state,tax_type:e.tax_type,inclusive:e.inclusive,description:e.description}}function Zt(e){const r=e.currency||e.session.currency||"usd",n=typeof e.session.amount_total=="number"?e.session.amount_total:0,s=e.session.total_details?.amount_tax??0,a=[];for(const l of e.lineItems)for(const i of l.taxes||[])a.push({scope:"line_item",source:"stripe_checkout",amount:i.amount,taxable_amount:i.taxable_amount,description:l.description||void 0,line_item_id:l.id,taxability_reason:i.taxability_reason,rate:at(i.rate)});if(a.length===0)for(const l of e.session.total_details?.breakdown?.taxes||[])a.push({scope:"aggregate",source:"stripe_checkout",amount:l.amount,taxable_amount:l.taxable_amount,description:l.rate.display_name,taxability_reason:l.taxability_reason,rate:at(l.rate)});const o=Le(a);return{source:s>0||o.length>0?"stripe_checkout":"none",mode:e.fallbackMode==="manual"?"manual":"automatic",currency:r,subtotal:e.subtotal,shipping_total:e.shippingTotal,tax_total:s,total:n,is_finalized:!0,lines:o,updated_at:Ve()}}function yt({data:e,labels:r,locale:n="en-US",className:s=""}){const a=je(e.settings.address),o=je(e.order.customer_details?.billing),l=je(e.order.customer_details?.shipping);return t.jsxs("section",{className:`rounded-2xl border bg-white text-slate-900 shadow-sm print:rounded-none print:border-0 print:text-[10px] print:shadow-none ${s}`,children:[t.jsx("div",{className:"border-b px-6 py-6 print:px-0",children:t.jsxs("div",{className:"grid gap-6 md:grid-cols-[minmax(0,1fr)_auto_minmax(0,1fr)] md:items-start print:grid-cols-[minmax(0,1fr)_72px_280px] print:items-start print:gap-4",children:[t.jsxs("div",{className:"order-2 max-w-md space-y-4 print:order-none print:max-w-none print:space-y-2 md:order-none",children:[t.jsxs("div",{className:"space-y-1 text-sm print:text-[10px]",children:[t.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.2em] text-slate-500",children:r.from}),e.settings.businessName?t.jsx("p",{className:"text-base font-semibold",children:e.settings.businessName}):null,a.map((i,h)=>t.jsx("p",{children:i},`seller-${h}-${i}`)),e.settings.email?t.jsx("p",{children:e.settings.email}):null,e.settings.phone?t.jsx("p",{children:e.settings.phone}):null]}),e.settings.taxRegistrations.length>0?t.jsxs("div",{className:"rounded-xl border bg-slate-50 px-4 py-3 text-sm print:px-3 print:py-2 print:text-[10px]",children:[t.jsx("p",{className:"mb-2 font-semibold",children:r.taxRegistrations}),t.jsx("div",{className:"space-y-1",children:e.settings.taxRegistrations.map((i,h)=>t.jsxs("p",{children:[t.jsx("span",{className:"font-medium",children:i.label}),i.label&&i.value?": ":"",i.value]},`${i.label}-${i.value}-${h}`))})]}):null]}),t.jsx("div",{className:"order-1 flex justify-center md:order-none md:pt-2 print:order-none print:pt-1",children:e.logo?.url?t.jsx(gt,{src:e.logo.url,alt:e.logo.name||e.settings.businessName||"Logo",className:"mx-auto h-24 w-auto object-contain print:h-14",width:e.logo.width||320,height:e.logo.height||120}):null}),t.jsx("div",{className:"order-3 flex justify-start md:order-none md:justify-end print:order-none",children:t.jsxs("div",{className:"w-full max-w-[380px] rounded-2xl bg-slate-950 px-5 py-5 text-white print:max-w-none print:border print:border-slate-300 print:bg-white print:px-3 print:py-3 print:text-[10px] print:text-slate-950",children:[t.jsx("p",{className:"text-xs uppercase tracking-[0.2em] text-white/70 print:text-slate-500",children:r.invoice}),t.jsxs("div",{className:"mt-4 space-y-3 text-sm print:mt-3 print:space-y-2 print:text-[10px]",children:[t.jsx(ge,{label:r.invoiceNumber,value:e.order.invoice_number||"--"}),t.jsx(ge,{label:r.orderNumber,value:e.order.id}),t.jsx(ge,{label:r.paidOn,value:bt(e.order.paid_at||e.order.created_at,n)||"--"}),t.jsx(ge,{label:r.status,value:e.order.status})]})]})})]})}),t.jsxs("div",{className:"grid gap-4 border-b px-6 py-6 md:grid-cols-2 print:grid-cols-2 print:gap-3 print:px-0 print:py-3",children:[t.jsx(it,{title:r.billTo,lines:o}),t.jsx(it,{title:r.shipTo,lines:l})]}),t.jsxs("div",{className:"px-6 py-6 print:px-0 print:py-3",children:[t.jsx("div",{className:"overflow-hidden rounded-2xl border",children:t.jsxs("table",{className:"w-full border-collapse text-sm print:table-fixed print:text-[9px]",children:[t.jsx("thead",{className:"bg-slate-50",children:t.jsxs("tr",{children:[t.jsx("th",{className:"px-4 py-3 text-left font-semibold print:w-[22%] print:px-2 print:py-1.5",children:r.item}),t.jsx("th",{className:"px-4 py-3 text-left font-semibold print:w-[38%] print:px-2 print:py-1.5",children:r.details}),t.jsx("th",{className:"px-4 py-3 text-right font-semibold print:w-[10%] print:px-2 print:py-1.5",children:r.quantity}),t.jsx("th",{className:"px-4 py-3 text-right font-semibold print:w-[15%] print:px-2 print:py-1.5",children:r.price}),t.jsx("th",{className:"px-4 py-3 text-right font-semibold print:w-[15%] print:px-2 print:py-1.5",children:r.amount})]})}),t.jsx("tbody",{children:e.order.items.map(i=>t.jsxs("tr",{className:"border-t",children:[t.jsx("td",{className:"px-4 py-4 font-medium print:px-2 print:py-1.5",children:i.title}),t.jsx("td",{className:"px-4 py-4 text-slate-600 print:px-2 print:py-1.5",children:i.description||"--"}),t.jsx("td",{className:"px-4 py-4 text-right print:px-2 print:py-1.5",children:i.quantity}),t.jsx("td",{className:"px-4 py-4 text-right print:px-2 print:py-1.5",children:re(i.unit_amount,e.order.currency,n)}),t.jsx("td",{className:"px-4 py-4 text-right font-medium print:px-2 print:py-1.5",children:re(i.total_amount,e.order.currency,n)})]},i.id))})]})}),t.jsxs("div",{className:"mt-6 grid gap-6 md:grid-cols-[minmax(0,1fr)_320px] print:mt-4 print:grid-cols-[minmax(0,1fr)_220px] print:items-start print:gap-4",children:[t.jsx("div",{children:e.order.tax_details?.lines?.length?t.jsxs("div",{className:"rounded-xl border bg-slate-50 px-5 py-4 print:break-inside-avoid print:px-3 print:py-2.5 print:text-[10px]",children:[t.jsx("p",{className:"mb-3 font-semibold",children:r.taxBreakdown}),t.jsx("div",{className:"space-y-3 text-sm print:space-y-2 print:text-[10px]",children:e.order.tax_details.lines.map((i,h)=>{const j=pe(i.rate);return t.jsxs("div",{className:"flex items-start justify-between gap-4",children:[t.jsxs("div",{children:[t.jsxs("p",{className:"font-medium",children:[me(i.rate),typeof j=="number"?` - ${j.toFixed(4)}%`:""]}),ve(i.rate)?t.jsx("p",{className:"text-xs text-slate-500 print:text-[9px]",children:ve(i.rate)}):null]}),t.jsx("span",{children:re(i.amount,e.order.currency,n)})]},`${i.rate.display_name}-${i.description||"tax"}-${h}`)})})]}):null}),t.jsxs("div",{className:"rounded-xl border bg-slate-950 px-5 py-5 text-sm text-white print:break-inside-avoid print:border-slate-300 print:bg-white print:px-3 print:py-3 print:text-[10px] print:text-slate-950",children:[t.jsxs("div",{className:"space-y-3 print:space-y-2",children:[t.jsx(ue,{label:r.subtotal,value:re(e.order.subtotal,e.order.currency,n)}),e.order.discount_total>0?t.jsx(ue,{label:e.order.coupon_code?`${r.discount} (${e.order.coupon_code})`:r.discount,value:`-${re(e.order.discount_total,e.order.currency,n)}`}):null,t.jsx(ue,{label:r.shipping,value:re(e.order.shipping_total,e.order.currency,n)}),t.jsx(ue,{label:r.tax,value:re(e.order.tax_total,e.order.currency,n)})]}),t.jsx("div",{className:"mt-4 border-t border-white/15 pt-4 print:mt-3 print:border-slate-300 print:pt-3",children:t.jsx(ue,{label:r.total,value:re(e.order.total,e.order.currency,n),strong:!0})})]})]})]})]})}function it({title:e,lines:r}){return t.jsxs("div",{className:"rounded-xl border bg-slate-50 px-5 py-4 print:break-inside-avoid print:px-3 print:py-2.5 print:text-[10px]",children:[t.jsx("p",{className:"mb-3 text-xs font-semibold uppercase tracking-[0.2em] text-slate-500",children:e}),r.length?t.jsx("div",{className:"space-y-1 text-sm print:text-[10px]",children:r.map((n,s)=>t.jsx("p",{children:n},`${e}-${s}-${n}`))}):t.jsx("p",{className:"text-sm text-slate-500",children:"--"})]})}function ge({label:e,value:r}){return t.jsxs("div",{className:"flex items-center justify-between gap-4",children:[t.jsx("span",{className:"text-white/70 print:text-[9px] print:text-slate-500",children:e}),t.jsx("span",{className:"text-right font-medium",children:r})]})}function ue({label:e,value:r,strong:n=!1}){return t.jsxs("div",{className:"flex items-center justify-between gap-4",children:[t.jsx("span",{className:n?"text-base font-semibold print:text-sm":"text-white/75 print:text-[9px] print:text-slate-500",children:e}),t.jsx("span",{className:n?"text-lg font-semibold print:text-base":"font-medium",children:r})]})}function Wt({invoice:e,labels:r,locale:n,title:s,description:a,printLabel:o,headerVisual:l,action:i,loading:h=!1,loadingMessage:j,error:S,emptyMessage:F,className:b="",showHeader:g=!0}){return t.jsxs(t.Fragment,{children:[t.jsx("style",{children:`
2
- @media print {
3
- @page {
4
- size: portrait;
5
- margin: 12mm;
6
- }
7
-
8
- body {
9
- background: white !important;
10
- }
11
-
12
- body * {
13
- visibility: hidden;
14
- }
15
-
16
- [data-print-invoice-root],
17
- [data-print-invoice-root] * {
18
- visibility: visible;
19
- }
20
-
21
- [data-print-invoice-root] {
22
- position: absolute;
23
- inset: 0;
24
- width: 100%;
25
- margin: 0;
26
- padding: 0;
27
- }
28
- }
29
- `}),t.jsxs("div",{className:`mx-auto max-w-6xl px-4 py-10 md:px-6 print:max-w-none print:px-0 print:py-0 ${b}`,children:[g?t.jsxs("div",{className:"mb-6 flex flex-col gap-4 md:flex-row md:items-center md:justify-between print:hidden",children:[t.jsxs("div",{className:"flex items-center gap-4",children:[l?t.jsx("div",{className:"shrink-0",children:l}):null,t.jsxs("div",{children:[t.jsx("h1",{className:"text-3xl font-bold",children:s}),a?t.jsx("p",{className:"text-sm text-muted-foreground",children:a}):null]})]}),t.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[t.jsxs(st.Button,{type:"button",variant:"outline",onClick:()=>window.print(),disabled:!e,children:[t.jsx(V.Printer,{className:"mr-2 h-4 w-4"}),o]}),i?t.jsx(st.Button,{asChild:!0,variant:i.variant||"default",children:t.jsx(Fe,{href:i.href,children:i.label})}):null]})]}):null,h?t.jsx("div",{className:"mb-6 flex items-center justify-center gap-3 rounded-2xl border bg-background px-5 py-4 text-sm text-muted-foreground print:hidden",children:j}):null,S?t.jsx("div",{className:"mb-6 rounded-2xl border border-amber-200 bg-amber-50 px-5 py-4 text-sm text-amber-700 print:hidden",children:S}):null,e?t.jsx("div",{"data-print-invoice-root":!0,children:t.jsx(yt,{data:e,labels:r,locale:n})}):!h&&!S?t.jsx("div",{className:"rounded-2xl border bg-background px-6 py-12 text-center text-muted-foreground print:hidden",children:F}):null]})]})}u.z.config({jitless:!0});const er=u.z.enum(["physical","digital"]).or(u.z.literal("")).refine(e=>e!=="",{message:"Product type is required"}).transform(e=>e),jt=u.z.record(u.z.string().regex(/^[A-Z]{3}$/,"Currency code must be ISO 4217"),u.z.coerce.number().min(0,"Prices must be non-negative")),vt=u.z.record(u.z.string().regex(/^[A-Z]{3}$/,"Currency code must be ISO 4217"),u.z.coerce.number().min(0,"Sale prices must be non-negative").nullable()),Ne=u.z.string().trim().refine(e=>e===""||!Number.isNaN(Date.parse(e)),{message:"Must be a valid date and time"}).transform(e=>e===""?null:e).nullable().optional();function Nt(e,r){if(!e||!r)return!0;const n=Date.parse(e),s=Date.parse(r);return Number.isNaN(n)||Number.isNaN(s)?!0:n<s}const tr=u.z.object({attribute_id:u.z.string().uuid(),attribute_name:u.z.string(),term_id:u.z.string().uuid(),term_value:u.z.string(),term_slug:u.z.string().optional()}),rr=u.z.object({id:u.z.string().uuid().optional(),combination_key:u.z.string().min(1),sku:u.z.string().min(1,"Variant SKU is required"),upc:u.z.string().optional().nullable(),price:u.z.coerce.number().min(0,"Variant price must be non-negative"),prices:jt.default({}),sale_price:u.z.coerce.number().min(0,"Variant sale price must be non-negative").optional().nullable(),sale_prices:vt.default({}),sale_start_at:Ne,sale_end_at:Ne,stock_quantity:u.z.coerce.number().int().min(0,"Variant stock must be a non-negative integer"),main_media_id:u.z.string().uuid().optional().nullable(),main_image_url:u.z.string().optional().nullable(),attribute_term_ids:u.z.array(u.z.string().uuid()).min(1),selected_options:u.z.array(tr).min(1),label:u.z.string().min(1)}).refine(e=>e.sale_price===null||e.sale_price===void 0||e.sale_price<=e.price,{message:"Variant sale price cannot exceed the regular price",path:["sale_price"]}).refine(e=>Object.entries(e.sale_prices||{}).every(([r,n])=>{if(n==null)return!0;const s=e.prices?.[r];return typeof s=="number"?n<=s:!0}),{message:"Variant sale prices cannot exceed regular prices",path:["sale_prices"]}).refine(e=>Nt(e.sale_start_at,e.sale_end_at),{message:"Sale end must be after the sale start",path:["sale_end_at"]}),sr=u.z.object({attribute_id:u.z.string().uuid(),term_ids:u.z.array(u.z.string().uuid())}),wt=u.z.object({product_type:er,payment_provider:u.z.enum(["stripe","freemius"]),title:u.z.string().min(1,"Title is required"),slug:u.z.string().min(1,"Slug is required").regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/,"Slug must be lowercase alphanumeric with hyphens"),sku:u.z.string().min(1,"SKU is required"),upc:u.z.string().optional().nullable(),price:u.z.coerce.number().min(0,"Price must be non-negative"),prices:jt.default({}),sale_price:u.z.coerce.number().min(0,"Sale price must be non-negative").optional().nullable(),sale_prices:vt.default({}),sale_start_at:Ne,sale_end_at:Ne,stock:u.z.coerce.number().int().min(0,"Stock must be a non-negative integer"),meta_title:u.z.string().optional().nullable(),meta_description:u.z.string().optional().nullable(),short_description:u.z.string().optional(),description_json:u.z.any().optional(),freemius_plan_id:u.z.string().optional(),freemius_product_id:u.z.string().optional(),trial_period_days:u.z.coerce.number().int().min(0,"Trial period must be zero or greater").default(0),trial_requires_payment_method:u.z.boolean().default(!1),media_id:u.z.string().optional(),product_media:u.z.array(u.z.object({media_id:u.z.string()})).optional(),category_ids:u.z.array(u.z.string().uuid()).optional(),is_taxable:u.z.boolean(),status:u.z.enum(["draft","active","archived"]),language_id:u.z.coerce.number().int().min(1,"Language is required"),translation_group_id:u.z.string().uuid().optional().or(u.z.literal("")).transform(e=>e===""?void 0:e),explicitly_removed_media_ids:u.z.array(u.z.string()).optional(),variation_attributes:u.z.array(sr).optional(),variants:u.z.array(rr).optional()}).refine(e=>e.sale_price===null||e.sale_price===void 0||e.sale_price<=e.price,{message:"Sale price cannot exceed the regular price",path:["sale_price"]}).refine(e=>Object.entries(e.sale_prices||{}).every(([r,n])=>{if(n==null)return!0;const s=e.prices?.[r];return typeof s=="number"?n<=s:!0}),{message:"Sale prices cannot exceed regular prices",path:["sale_prices"]}).refine(e=>Nt(e.sale_start_at,e.sale_end_at),{message:"Sale end must be after the sale start",path:["sale_end_at"]}),ot=process.env.NEXT_PUBLIC_R2_BASE_URL||"",ct=e=>e?e.startsWith("http")||!ot?e:`${ot.replace(/\/+$/,"")}/${e.replace(/^\/+/,"")}`:"",nr=({initialMedia:e,onUpdate:r,mediaPickerNode:n})=>{const[s,a]=y.useState(e),o=y.useRef(null),l=y.useRef(null);y.useEffect(()=>{a(e)},[e]);const i=(g,x)=>{o.current=x,g.dataTransfer.effectAllowed="move"},h=(g,x)=>{l.current=x,g.preventDefault()},j=g=>{g.preventDefault()},S=g=>{if(g.preventDefault(),o.current===null||l.current===null)return;const x=[...s],N=x[o.current];x.splice(o.current,1),x.splice(l.current,0,N),o.current=null,l.current=null;const M=x.map((H,k)=>({...H,sort_order:k}));a(M),r(M)},F=g=>{if(!g||s.some(M=>M.media_id===g.id))return;const x={id:`temp-${Date.now()}`,media_id:g.id,file_path:g.file_path||g.object_key,alt:g.description||g.file_name||"",sort_order:s.length,isNew:!0},N=[...s,x];a(N),r(N)},b=g=>{const N=s.filter((M,H)=>H!==g).map((M,H)=>({...M,sort_order:H}));a(N),r(N)};return t.jsxs("div",{className:"space-y-4",children:[t.jsxs("div",{className:"grid grid-cols-3 sm:grid-cols-4 md:grid-cols-5 lg:grid-cols-6 gap-4",children:[s.map((g,x)=>t.jsxs("div",{className:"group relative aspect-square bg-muted/40 rounded-lg border overflow-hidden cursor-move transition-all hover:shadow-md",draggable:!0,onDragStart:N=>i(N,x),onDragEnter:N=>h(N,x),onDragOver:j,onDrop:S,children:[x===0&&t.jsx("div",{className:"absolute top-2 left-2 z-10 bg-primary text-primary-foreground text-[10px] font-bold px-2 py-0.5 rounded shadow-sm",children:"MAIN"}),t.jsx("button",{type:"button",onClick:()=>b(x),className:"absolute top-1 right-1 z-20 p-1 bg-destructive/90 text-destructive-foreground rounded-full opacity-0 group-hover:opacity-100 transition-opacity",children:t.jsx(V.X,{className:"w-3 h-3"})}),t.jsx("div",{className:"absolute inset-0 bg-black/0 group-hover:bg-black/5 transition-colors pointer-events-none"}),t.jsx("div",{className:"absolute bottom-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity",children:t.jsx(V.GripVertical,{className:"w-4 h-4 text-white drop-shadow-md"})}),ct(g.file_path)?t.jsx(gt,{src:ct(g.file_path),alt:g.alt,fill:!0,className:"object-cover",sizes:"(max-width: 768px) 50vw, 33vw"}):t.jsx("div",{className:"flex h-full w-full items-center justify-center text-muted-foreground",children:t.jsx(V.Image,{className:"w-8 h-8 opacity-30"})})]},g.id)),n?y.cloneElement(n,{onSelect:F,children:t.jsxs("button",{type:"button",className:"group relative aspect-square flex flex-col items-center justify-center border-2 border-dashed rounded-lg bg-muted/10 text-muted-foreground hover:bg-muted/20 hover:border-muted-foreground/50 transition-all focus:outline-none focus:ring-2 focus:ring-primary",children:[t.jsx(V.Image,{className:"w-8 h-8 mb-2 opacity-50 group-hover:opacity-75 transition-opacity"}),t.jsx("span",{className:"text-sm font-medium",children:"Add Image"})]})}):t.jsxs("div",{className:"relative aspect-square flex flex-col items-center justify-center border-2 border-dashed rounded-lg bg-muted/10 text-muted-foreground",children:[t.jsx(V.Image,{className:"w-8 h-8 mb-2 opacity-30"}),t.jsx("span",{className:"text-xs text-center px-2",children:"Media Picker not injected"})]})]}),t.jsx("p",{className:"text-xs text-muted-foreground",children:"Drag and drop images to reorder. The first image will be used as the main product image."})]})};function ar({productId:e}){const[r,n]=y.useState(!1),s=async()=>{if(!e){ae.toast.error("Product ID is missing");return}n(!0);try{const a=await Me.triggerSingleProductSync(e);a.error?ae.toast.error(a.error):ae.toast.success("Pricing sync complete!")}catch(a){ae.toast.error(a.message||"An unexpected error occurred during sync")}finally{n(!1)}};return t.jsxs(d.Button,{variant:"outline",onClick:s,disabled:r,className:"gap-2",children:[t.jsx(V.RefreshCw,{className:`w-4 h-4 ${r?"animate-spin":""}`}),r?"Syncing...":"Sync Prices from Freemius"]})}function qe({idPrefix:e="currency",currencies:r,prices:n,salePrices:s,managedCurrencyCodes:a=[],onPriceChange:o,onSalePriceChange:l,readOnly:i=!1,helperText:h,trailing:j}){const S=r.find(b=>b.is_default)??r[0],F=new Set(a);return S?t.jsxs("div",{className:"flex flex-col gap-2",children:[h&&t.jsx("p",{className:"text-xs text-muted-foreground bg-muted/20 p-2 rounded-md border",children:h}),t.jsx("div",{className:"divide-y divide-muted/50",children:r.map(b=>{const g=Y.normalizeCurrencyRecord(b),x=g.is_default!==!0&&F.has(g.code),N=i||x;return t.jsxs("div",{className:"flex flex-wrap items-stretch gap-4 py-3 first:pt-0 last:pb-0",children:[t.jsxs("div",{className:"flex items-center gap-2 w-[160px] shrink-0 self-stretch border-r border-border/50 pr-4",children:[t.jsx("span",{className:"text-sm font-black tracking-tighter text-foreground",children:g.code}),t.jsx("span",{className:"text-[11px] text-muted-foreground font-medium",children:g.symbol}),g.is_default?t.jsx("span",{className:"text-[9px] uppercase font-bold bg-primary/10 text-primary px-1.5 py-0.5 rounded tracking-widest leading-none",children:"Default"}):x?t.jsx("span",{className:"text-[9px] uppercase font-bold bg-muted text-muted-foreground px-1.5 py-0.5 rounded tracking-widest leading-none",children:"Auto"}):null,!g.is_default&&t.jsxs("span",{className:"text-[9px] text-muted-foreground/80 font-medium tracking-wide leading-none ml-auto",children:["x",g.exchange_rate]})]}),t.jsxs("div",{className:"grid flex-1 grid-cols-2 items-end gap-3 sm:grid-cols-4",children:[t.jsxs("div",{className:"min-w-0 space-y-1",children:[t.jsx(d.Label,{htmlFor:`${e}-price-${g.code}`,className:"block text-[10px] uppercase font-bold text-muted-foreground tracking-widest",children:"Price"}),t.jsxs("div",{className:"relative",children:[t.jsx("span",{className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-xs text-muted-foreground font-bold pointer-events-none",children:g.symbol}),t.jsx(d.Input,{id:`${e}-price-${g.code}`,type:"number",step:"0.01",min:"0",value:n[g.code]??"",disabled:N,className:"h-8 w-full text-sm pl-6",onChange:M=>o(g.code,Number(M.target.value||0))})]})]}),t.jsxs("div",{className:"min-w-0 space-y-1",children:[t.jsx(d.Label,{htmlFor:`${e}-sale-price-${g.code}`,className:"block text-[10px] uppercase font-bold text-muted-foreground tracking-widest",children:"Sale"}),t.jsxs("div",{className:"relative",children:[t.jsx("span",{className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-xs text-muted-foreground font-bold pointer-events-none",children:g.symbol}),t.jsx(d.Input,{id:`${e}-sale-price-${g.code}`,type:"number",step:"0.01",min:"0",value:s[g.code]??"",disabled:N,placeholder:x?"Auto":"—",className:"h-8 w-full text-sm pl-6",onChange:M=>l(g.code,M.target.value===""?null:Number(M.target.value))})]})]}),j&&g.is_default?j:null]})]},g.code)})})]}):null}const _e=e=>String(e).padStart(2,"0");function he(e){if(!e)return"";const r=new Date(e);return Number.isNaN(r.getTime())?"":`${r.getFullYear()}-${_e(r.getMonth()+1)}-${_e(r.getDate())}T${_e(r.getHours())}:${_e(r.getMinutes())}`}function be(e){if(!e)return null;const r=new Date(e);return Number.isNaN(r.getTime())?null:r.toISOString()}function Re({idPrefix:e="product",startAt:r,endAt:n,onChange:s,error:a,disabled:o,description:l,dense:i,bare:h}){const j=Intl.DateTimeFormat().resolvedOptions().timeZone,S=R.cn("h-7 text-xs",i||h?"w-[150px]":"w-[160px] sm:w-[180px]"),F=t.jsxs(t.Fragment,{children:[t.jsx(d.Label,{htmlFor:`${e}-sale-start-at`,className:"text-[10px] uppercase tracking-wider text-muted-foreground",children:"Starts"}),t.jsx(d.Input,{id:`${e}-sale-start-at`,type:"datetime-local",value:he(r),disabled:o,onChange:b=>s("sale_start_at",be(b.target.value)),className:S}),t.jsx("span",{className:"text-xs text-muted-foreground",children:"→"}),t.jsx(d.Label,{htmlFor:`${e}-sale-end-at`,className:"text-[10px] uppercase tracking-wider text-muted-foreground",children:"Ends"}),t.jsx(d.Input,{id:`${e}-sale-end-at`,type:"datetime-local",value:he(n),disabled:o,onChange:b=>s("sale_end_at",be(b.target.value)),className:S})]});return h?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"min-w-0 space-y-1",children:[t.jsx(d.Label,{htmlFor:`${e}-sale-start-at`,className:"block text-[10px] uppercase font-bold tracking-widest text-muted-foreground",children:"Starts"}),t.jsx(d.Input,{id:`${e}-sale-start-at`,type:"datetime-local",value:he(r),disabled:o,onChange:b=>s("sale_start_at",be(b.target.value)),className:"h-8 w-full text-xs"})]}),t.jsxs("div",{className:"min-w-0 space-y-1",children:[t.jsx(d.Label,{htmlFor:`${e}-sale-end-at`,className:"block text-[10px] uppercase font-bold tracking-widest text-muted-foreground",children:"Ends"}),t.jsx(d.Input,{id:`${e}-sale-end-at`,type:"datetime-local",value:he(n),disabled:o,onChange:b=>s("sale_end_at",be(b.target.value)),className:"h-8 w-full text-xs"}),a?t.jsx("p",{className:"mt-0.5 text-[10px] text-destructive",children:a}):null]})]}):t.jsxs("div",{className:R.cn("rounded border border-dashed bg-muted/5 space-y-1",i?"p-1.5":"p-2"),children:[t.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1.5",children:[t.jsx("span",{className:"shrink-0 text-[11px] font-bold uppercase tracking-wider text-muted-foreground",children:"Sale window"}),F,t.jsxs("span",{className:"ml-auto text-[10px] text-muted-foreground",children:[j||"local time"," · empty = always on"]})]}),l&&!i?t.jsx("p",{className:"text-[10px] leading-snug text-muted-foreground",children:l}):null,a?t.jsx("p",{className:"text-[11px] text-destructive",children:a}):null]})}function De(e){return Object.entries(e||{}).reduce((r,[n,s])=>(typeof s=="number"&&Number.isFinite(s)&&s>=0?r[R.normalizeCurrencyCode(n)]=s:s===null&&(r[R.normalizeCurrencyCode(n)]=null),r),{})}function Ee(e){const r=Y.normalizeCurrencyRecord(e);return r.is_default!==!0&&r.auto_sync_product_prices===!0}function Be(e){return e.map(r=>Y.normalizeCurrencyRecord(r)).filter(r=>Ee(r)).map(r=>r.code)}function we(e,r){const n=new Set(Be(r)),s=De(e);return Object.entries(s).reduce((a,[o,l])=>(n.has(o)||(a[o]=l),a),{})}function dt(e){const{baseAmount:r,defaultCurrencyCode:n,targetCurrencyCode:s,currencies:a}=e;if(typeof r!="number"||!Number.isFinite(r)||r<0)return null;const o=Y.convertMinorUnitAmount({amount:R.majorUnitAmountToMinor(r,n),fromCurrencyCode:n,toCurrencyCode:s,currencies:a,applyRounding:!0});return R.minorUnitAmountToMajor(o,s)}function St(e){const{currencies:r,fallbackPrice:n,fallbackSalePrice:s}=e,a=De(e.prices),o=De(e.salePrices),l=r.find(b=>b.is_default)??r[0];if(!l)return{prices:a,salePrices:o};const i=R.normalizeCurrencyCode(l.code),h=a[i]??(typeof n=="number"?n:null),j=o[i]??(typeof s=="number"?s:null),S=r.reduce((b,g)=>{const x=Y.normalizeCurrencyRecord(g);return Ee(x)?(b[x.code]=dt({baseAmount:h,defaultCurrencyCode:i,targetCurrencyCode:x.code,currencies:r}),b):(b[x.code]=a[x.code]??(x.code===i?h:void 0),b)},{}),F=r.reduce((b,g)=>{const x=Y.normalizeCurrencyRecord(g);return Ee(x)?(b[x.code]=dt({baseAmount:j,defaultCurrencyCode:i,targetCurrencyCode:x.code,currencies:r}),b):(b[x.code]=o[x.code]??(x.code===i?j:void 0),b)},{});return{prices:S,salePrices:F}}function ir(e,r){const n=r.find(l=>l.is_default)??r[0],s=n?R.normalizeCurrencyCode(n.code):"USD",a=we(e.prices,r),o=we(e.sale_prices,r);return{...e,price:typeof a[s]=="number"?a[s]:e.price,prices:a,sale_price:typeof o[s]=="number"?o[s]:e.sale_price??null,sale_prices:o}}function Oe(e,r){return e?.map(n=>ir(n,r))||[]}function Se(e,r){const n=r.find(l=>l.is_default)??r[0],s=n?R.normalizeCurrencyCode(n.code):"USD",a=we(e.prices,r),o=we(e.sale_prices,r);return{...e,price:typeof a[s]=="number"?a[s]:e.price,prices:a,sale_price:typeof o[s]=="number"?o[s]:e.sale_price??null,sale_prices:o,variants:Oe(e.variants,r)}}const lt=process.env.NEXT_PUBLIC_R2_BASE_URL||"",ut=process.env.NEXT_PUBLIC_SUPABASE_URL||"",or=e=>e.startsWith("http")?e:lt?`${lt.replace(/\/+$/,"")}/${e.replace(/^\/+/,"")}`:ut?`${ut.replace(/\/+$/,"")}/storage/v1/object/public/media/${e.replace(/^\/+/,"")}`:e;function mt(e,r="USD"){return new Intl.NumberFormat("en-US",{style:"currency",currency:r}).format(e)}function cr(e){return Object.entries(e).filter(([,r])=>r.length>0).map(([r,n])=>({attribute_id:r,term_ids:n}))}function dr({globalAttributes:e,currentLanguageCode:r,baseSku:n,basePrice:s,basePrices:a,baseSalePrice:o,baseSalePrices:l,currencies:i,availableVariantImages:h=[],initialVariationAttributes:j,initialVariants:S,onChange:F}){const[b,g]=y.useState(()=>j&&j.length>0?j.reduce((c,f)=>(c[f.attribute_id]=f.term_ids,c),{}):de.extractSelectedTermsByAttribute(S||[])),[x,N]=y.useState(Oe(S||[],i)),M=y.useMemo(()=>e.map(c=>({attribute_id:c.id,attribute_name:de.resolveAttributeName(c,r),terms:c.terms.filter(f=>(b[c.id]||[]).includes(f.id)).map(f=>({...f,value:de.resolveTermValue(f,r)}))})).filter(c=>c.terms.length>0),[r,e,b]);y.useEffect(()=>{if(M.length===0){N([]);return}N(c=>Oe(de.generateVariantDrafts({baseSku:n,basePrice:s,basePrices:Y.normalizePriceMap(a),baseSalePrice:o,baseSalePrices:Y.normalizeSalePriceMap(l),selectedAttributes:M,previousVariants:c}),i))},[s,a,o,l,n,i,M]),y.useEffect(()=>{F({variationAttributes:cr(b),variants:x})},[F,b,x]);const H=x.reduce((c,f)=>c+(f.stock_quantity||0),0),k=i.find(c=>c.is_default)??i[0],p=y.useMemo(()=>Be(i),[i]),T=(c,f)=>{g(_=>{const C=new Set(_[c]||[]);return C.has(f)?C.delete(f):C.add(f),{..._,[c]:[...C]}})},Q=(c,f,_)=>{N(C=>C.map(A=>{if(A.combination_key!==c)return A;if(f==="sku")return{...A,sku:_};if(f==="upc")return{...A,upc:_};if(f==="sale_price"&&_==="")return{...A,sale_price:null};if(f==="prices"||f==="sale_prices")return A;const B=_===""?0:Number(_);return{...A,[f]:Number.isFinite(B)?B:0}}))},q=(c,f,_)=>{N(C=>C.map(A=>A.combination_key===c?{...A,[f]:_}:A))},ie=(c,f,_,C)=>{const A=i.find(B=>B.is_default)??i[0];N(B=>B.map($=>{if($.combination_key!==c)return $;const K={..._==="prices"?$.prices:$.sale_prices,[f]:C};return{...$,[_]:K,...f===A?.code?_==="prices"?{price:C??0}:{sale_price:C}:{}}}))},v=c=>{const f=i.find(C=>C.is_default)??i[0],_=new Set(p);f&&N(C=>C.map(A=>{if(A.combination_key!==c)return A;const B=i.reduce((K,D)=>{if(D.code!==f.code&&_.has(D.code))return K;const oe=Y.convertMinorUnitAmount({amount:R.majorUnitAmountToMinor(A.price,f.code),fromCurrencyCode:f.code,toCurrencyCode:D.code,currencies:i,applyRounding:!0});return K[D.code]=R.minorUnitAmountToMajor(oe,D.code),K},{}),$=i.reduce((K,D)=>{if(D.code!==f.code&&_.has(D.code))return K;if(typeof A.sale_price!="number")return K[D.code]=null,K;const oe=Y.convertMinorUnitAmount({amount:R.majorUnitAmountToMinor(A.sale_price,f.code),fromCurrencyCode:f.code,toCurrencyCode:D.code,currencies:i,applyRounding:!0});return K[D.code]=R.minorUnitAmountToMajor(oe,D.code),K},{});return{...A,prices:B,sale_prices:$}}))},xe=(c,f)=>{const _=h.find(B=>B.media_id===f);if(!_)return;const C=_.file_path,A=or(C);N(B=>B.map($=>$.combination_key===c?{...$,main_media_id:_.media_id,main_image_url:A}:$))},z=c=>{N(f=>f.map(_=>_.combination_key===c?{..._,main_media_id:null,main_image_url:null}:_))};return e.length===0?t.jsxs("div",{className:"rounded-lg border border-dashed p-6 text-sm text-muted-foreground",children:["No global attributes have been created yet. Create them first in"," ",t.jsx(Fe,{href:"/cms/products/attributes",className:"font-medium text-primary underline-offset-4 hover:underline",children:"Attribute Management"}),"."]}):t.jsxs("div",{className:"space-y-3",children:[t.jsxs("div",{className:"space-y-2",children:[t.jsxs("div",{className:"flex items-center justify-between gap-3",children:[t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("span",{className:"text-xs uppercase font-bold text-muted-foreground tracking-wider leading-none",children:"Attributes"}),t.jsxs(d.Badge,{variant:"outline",className:"text-[10px] px-1.5 h-4",children:[x.length," variants"]}),t.jsxs(d.Badge,{variant:"secondary",className:"text-[10px] px-1.5 h-4",children:["Stock: ",H]})]}),t.jsx(d.Button,{asChild:!0,variant:"outline",size:"sm",className:"h-7 text-xs px-3",children:t.jsx(Fe,{href:"/cms/products/attributes",children:"Manage"})})]}),t.jsx("div",{className:"grid gap-2 lg:grid-cols-2",children:e.map(c=>{const f=b[c.id]||[];return t.jsxs("div",{className:"flex items-center gap-3 rounded border p-2.5",children:[t.jsxs("div",{className:"shrink-0 w-[100px]",children:[t.jsx("span",{className:"text-sm font-bold block leading-tight",children:de.resolveAttributeName(c,r)}),t.jsxs("span",{className:"text-[10px] text-muted-foreground leading-none",children:[f.length," selected"]})]}),t.jsx("div",{className:"flex flex-wrap gap-1.5 flex-1",children:c.terms.map(_=>{const C=f.includes(_.id);return t.jsx("button",{type:"button",onClick:()=>T(c.id,_.id),className:`rounded-full border px-2.5 py-0.5 text-[11px] font-medium transition-colors ${C?"border-primary bg-primary/10 text-primary":"border-border bg-background text-foreground hover:border-primary/40"}`,children:de.resolveTermValue(_,r)},_.id)})})]},c.id)})})]}),x.length===0?t.jsx("div",{className:"rounded border border-dashed p-3 text-xs text-muted-foreground text-center",children:"Select terms above to generate variations."}):t.jsx("div",{className:"space-y-2",children:x.map(c=>{const f=St({currencies:i,prices:c.prices||{},salePrices:c.sale_prices||{},fallbackPrice:c.price,fallbackSalePrice:c.sale_price});return t.jsxs("div",{className:"rounded border p-3 space-y-2",children:[t.jsxs("div",{className:"flex items-center justify-between gap-3",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-sm font-bold",children:c.label}),t.jsx("span",{className:"text-xs text-muted-foreground",children:c.selected_options.map(_=>`${_.attribute_name}: ${_.term_value}`).join(" · ")})]}),t.jsxs("div",{className:"flex items-center gap-3 text-xs text-muted-foreground",children:[t.jsxs("span",{children:["Reg: ",mt(c.price,k?.code||"USD")]}),t.jsxs("span",{children:["Sale:"," ",c.sale_price!==null&&c.sale_price!==void 0?mt(c.sale_price,k?.code||"USD"):"—"]})]})]}),t.jsxs("div",{className:"grid grid-cols-3 gap-2.5",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(d.Label,{htmlFor:`variant-sku-${c.combination_key}`,className:"text-xs uppercase font-bold text-muted-foreground tracking-wider shrink-0",children:"SKU"}),t.jsx(d.Input,{id:`variant-sku-${c.combination_key}`,value:c.sku,onChange:_=>Q(c.combination_key,"sku",_.target.value),placeholder:"SKU",className:"h-8 text-sm font-mono"})]}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(d.Label,{htmlFor:`variant-upc-${c.combination_key}`,className:"text-xs uppercase font-bold text-muted-foreground tracking-wider shrink-0",children:"UPC"}),t.jsx(d.Input,{id:`variant-upc-${c.combination_key}`,value:c.upc??"",onChange:_=>Q(c.combination_key,"upc",_.target.value),placeholder:"—",className:"h-8 text-sm font-mono"})]}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(d.Label,{htmlFor:`variant-stock-${c.combination_key}`,className:"text-xs uppercase font-bold text-muted-foreground tracking-wider shrink-0",children:"Qty"}),t.jsx(d.Input,{id:`variant-stock-${c.combination_key}`,type:"number",min:"0",value:c.stock_quantity,onChange:_=>Q(c.combination_key,"stock_quantity",_.target.value),className:"h-8 text-sm font-mono w-20"})]})]}),t.jsx(qe,{idPrefix:`variant-${c.combination_key}`,currencies:i,prices:f.prices,salePrices:f.salePrices,managedCurrencyCodes:p,onPriceChange:(_,C)=>ie(c.combination_key,_,"prices",C),onSalePriceChange:(_,C)=>ie(c.combination_key,_,"sale_prices",C),onAutoFill:()=>v(c.combination_key),helperText:p.length>0?`Store-managed currencies derive from ${k?.code||"the base currency"}.`:void 0,trailing:t.jsx(Re,{idPrefix:`variant-${c.combination_key}`,startAt:c.sale_start_at,endAt:c.sale_end_at,onChange:(_,C)=>q(c.combination_key,_,C),bare:!0})}),t.jsxs("div",{className:"flex items-center gap-3 pt-1.5 border-t border-muted/30",children:[c.main_image_url&&t.jsx("div",{className:"h-9 w-9 overflow-hidden rounded border bg-background shrink-0",children:t.jsx("img",{src:c.main_image_url,alt:`${c.label} image`,className:"h-full w-full object-cover"})}),t.jsx("span",{className:"text-xs uppercase font-bold text-muted-foreground tracking-wider shrink-0",children:"Image"}),h.length>0?t.jsxs("select",{className:"flex h-8 rounded-md border border-input bg-background px-2 py-1 text-sm min-w-[180px]",value:c.main_media_id??"",onChange:_=>{if(!_.target.value){z(c.combination_key);return}xe(c.combination_key,_.target.value)},children:[t.jsx("option",{value:"",children:"Use parent image"}),h.map((_,C)=>t.jsx("option",{value:_.media_id,children:_.alt?.trim()||`Gallery image ${C+1}`},_.media_id))]}):t.jsx("span",{className:"text-xs text-muted-foreground",children:"Add gallery images first."}),c.main_media_id&&t.jsx(d.Button,{type:"button",variant:"ghost",size:"sm",className:"h-7 text-xs px-2 text-muted-foreground hover:text-destructive",onClick:()=>z(c.combination_key),children:"Remove"})]})]},c.combination_key)})})]})}function pt(e){if(!e)return null;const r=new Date(e);return Number.isNaN(r.getTime())?e:r.toISOString().replace("T"," ").replace(/\.\d{3}Z$/,"")}function lr(e){return e==="percent"?"percentage":"dollar"}function ur(e){return Me.resolveFreemiusCheckoutCredentials(e).apiKey||Me.readFreemiusEnvValue("FREEMIUS_API_KEY")}async function Ke(e){const r=ur(e.productId);if(!r)throw new Error(`Missing Freemius API bearer token for product ${e.productId}. Set FREEMIUS_API_KEY or FREEMIUS_CHECKOUT_PRODUCTS_JSON[${e.productId}].apiKey.`);const n=e.couponId?`/${e.couponId}`:"",s=await fetch(`https://api.freemius.com/v1/products/${e.productId}/coupons${n}.json`,{method:e.method,headers:{Authorization:`Bearer ${r}`,"Content-Type":"application/json",Accept:"application/json"},body:e.method==="DELETE"?void 0:JSON.stringify(e.body||{})}),a=await s.text(),o=a?JSON.parse(a):null;if(!s.ok)throw new Error(o?.message||o?.error?.message||`Freemius coupon request failed with ${s.status}`);return o}function Ct(e,r){return{code:e.code,discount:e.discount_type==="fixed"?R.minorUnitAmountToMajor(e.discount_amount,"USD"):e.discount_amount,discount_type:lr(e.discount_type),plans:r.planIds.length>0?r.planIds.join(","):null,licenses:null,billing_cycles:null,start_date:pt(e.starts_at),end_date:pt(e.ends_at),redemptions_limit:e.redemption_limit??null,has_renewals_discount:!1,has_addons_discount:!1,is_one_per_user:!1,is_active:e.is_active,user_type:"all"}}async function mr(e,r){if(r.provider_scope==="stripe")return[];const{data:n,error:s}=await e.from("coupon_products").select("product_id").eq("coupon_id",r.id);if(s)throw new Error(s.message);const a=(n||[]).map(j=>j.product_id);let o=e.from("products").select("id, freemius_product_id, freemius_plan_id").eq("payment_provider","freemius").not("freemius_product_id","is",null);a.length>0&&(o=o.in("id",a));const{data:l,error:i}=await o;if(i)throw new Error(i.message);const h=new Map;for(const j of l||[]){const S=String(j.freemius_product_id||"").trim();if(!S)continue;const F=h.get(S)??{freemiusProductId:S,productId:j.id,planIds:[]};a.length>0&&j.freemius_plan_id&&F.planIds.push(String(j.freemius_plan_id)),h.set(S,F)}return[...h.values()].map(j=>({...j,planIds:[...new Set(j.planIds)]}))}async function pr(e,r){const{data:n}=await e.from("coupon_freemius_mappings").select("sync_status, sync_error").eq("coupon_id",r),s=n||[];if(s.length===0){await e.from("coupons").update({freemius_sync_status:"not_required",freemius_sync_error:null}).eq("id",r);return}const a=s.find(o=>o.sync_status==="failed");await e.from("coupons").update({freemius_sync_status:a?"failed":"synced",freemius_sync_error:a?.sync_error??null}).eq("id",r)}async function xr(e){const{data:r,error:n}=await e.client.from("coupons").select("id, code, name, internal_note, provider_scope, discount_type, discount_amount, is_active, starts_at, ends_at, redemption_limit").eq("id",e.couponId).single();if(n||!r)return{success:!1,error:n?.message||"Coupon not found"};const s=r,a=await mr(e.client,s);await e.client.from("coupons").update({freemius_sync_status:a.length>0?"pending":"not_required",freemius_sync_error:null}).eq("id",s.id);for(const o of a){const{data:l}=await e.client.from("coupon_freemius_mappings").select("id, freemius_coupon_id").eq("coupon_id",s.id).eq("freemius_product_id",o.freemiusProductId).maybeSingle(),i=Ct(s,o);try{const h=await Ke({productId:o.freemiusProductId,method:l?.freemius_coupon_id?"PUT":"POST",couponId:l?.freemius_coupon_id??null,body:i}),j=h?.coupon??h;await e.client.from("coupon_freemius_mappings").upsert({id:l?.id,coupon_id:s.id,product_id:o.productId,freemius_product_id:o.freemiusProductId,freemius_coupon_id:j?.id?String(j.id):l?.freemius_coupon_id??null,freemius_coupon_code:s.code,sync_status:"synced",sync_error:null,remote_payload:h,last_synced_at:new Date().toISOString()},{onConflict:"coupon_id,freemius_product_id"})}catch(h){await e.client.from("coupon_freemius_mappings").upsert({id:l?.id,coupon_id:s.id,product_id:o.productId,freemius_product_id:o.freemiusProductId,freemius_coupon_id:l?.freemius_coupon_id??null,freemius_coupon_code:s.code,sync_status:"failed",sync_error:h.message||"Freemius sync failed",last_synced_at:new Date().toISOString()},{onConflict:"coupon_id,freemius_product_id"})}}return await pr(e.client,s.id),{success:!0,targetCount:a.length}}function fr(e){const r=(e.sku||"").toUpperCase().replace(/[^A-Z0-9]/g,"");return r?`SALE${r}`.slice(0,32):`SALE${e.productId.replace(/[^A-Za-z0-9]/g,"").toUpperCase()}`.slice(0,32)}function gr(e,r){if(typeof e!="number"||e<=0||typeof r!="number"||r<0||r>=e)return null;const n=Math.round((1-r/e)*100);return n<=0||n>100?null:n}async function Pt(e){const{data:r,error:n}=await e.client.from("products").select("id, sku, price, sale_price, sale_start_at, sale_end_at, payment_provider, freemius_product_id, freemius_plan_id").eq("id",e.productId).maybeSingle();if(n||!r)return{success:!1,error:n?.message||"Product not found"};const s=r,a=String(s.freemius_product_id||"").trim();if(s.payment_provider!=="freemius"||!a)return{success:!0,skipped:!0,reason:"not_a_freemius_product"};const o=gr(s.price,s.sale_price),l=o!==null,{data:i}=await e.client.from("product_freemius_sale_coupons").select("id, freemius_coupon_id, freemius_coupon_code, discount_percent, is_active").eq("product_id",s.id).maybeSingle();if(!l&&!i?.freemius_coupon_id)return i?.id&&await e.client.from("product_freemius_sale_coupons").update({is_active:!1,updated_at:new Date().toISOString()}).eq("id",i.id),{success:!0,active:!1};const h=i?.freemius_coupon_code||fr({sku:s.sku,productId:s.id}),j=s.freemius_plan_id?[String(s.freemius_plan_id)]:[],S=o??i?.discount_percent??1,F={id:s.id,code:h,name:`Scheduled sale ${s.sku||s.id}`,discount_type:"percent",discount_amount:S,is_active:l,starts_at:s.sale_start_at,ends_at:s.sale_end_at,redemption_limit:null},b={productId:s.id,planIds:j},g=Ct(F,b);try{const x=await Ke({productId:a,method:i?.freemius_coupon_id?"PUT":"POST",couponId:i?.freemius_coupon_id??null,body:g}),N=x?.coupon??x;return await e.client.from("product_freemius_sale_coupons").upsert({id:i?.id,product_id:s.id,freemius_product_id:a,freemius_plan_id:s.freemius_plan_id?String(s.freemius_plan_id):null,freemius_coupon_id:N?.id?String(N.id):i?.freemius_coupon_id??null,freemius_coupon_code:h,discount_percent:o,starts_at:s.sale_start_at,ends_at:s.sale_end_at,is_active:l,sync_status:"synced",sync_error:null,remote_payload:x,last_synced_at:new Date().toISOString()},{onConflict:"product_id"}),{success:!0,active:l,code:h}}catch(x){return await e.client.from("product_freemius_sale_coupons").upsert({id:i?.id,product_id:s.id,freemius_product_id:a,freemius_plan_id:s.freemius_plan_id?String(s.freemius_plan_id):null,freemius_coupon_id:i?.freemius_coupon_id??null,freemius_coupon_code:h,discount_percent:o,starts_at:s.sale_start_at,ends_at:s.sale_end_at,is_active:l,sync_status:"failed",sync_error:x.message||"Freemius sale coupon sync failed",last_synced_at:new Date().toISOString()},{onConflict:"product_id"}),{success:!1,error:x.message||"Freemius sale coupon sync failed"}}}async function _r(e){const{data:r}=await e.client.from("coupon_freemius_mappings").select("id, freemius_product_id, freemius_coupon_id").eq("coupon_id",e.couponId).not("freemius_coupon_id","is",null);for(const n of r||[])try{await Ke({productId:n.freemius_product_id,couponId:n.freemius_coupon_id,method:"DELETE"}),await e.client.from("coupon_freemius_mappings").update({sync_status:"deleted",sync_error:null,updated_at:new Date().toISOString()}).eq("id",n.id)}catch(s){await e.client.from("coupon_freemius_mappings").update({sync_status:"failed",sync_error:s.message||"Freemius delete failed",updated_at:new Date().toISOString()}).eq("id",n.id)}}function Ce(e){return e.toLowerCase().trim().replace(/\s+/g,"-").replace(/[^a-z0-9-]/g,"").replace(/-+/g,"-").replace(/^-|-$/g,"")}async function hr(e){const r=L.createClient(),{data:n}=await r.from("currencies").select("code, symbol, exchange_rate, is_default, is_active, auto_sync_product_prices, auto_update_exchange_rate, exchange_rate_source, exchange_rate_updated_at, rounding_mode, rounding_increment, rounding_charm_amount").eq("is_active",!0).order("code",{ascending:!0}),s=Se(e,(n||[]).map(o=>Y.normalizeCurrencyRecord(o))),a=await $e.createProduct(r,s);if(s.payment_provider==="freemius"&&a?.id)try{await Pt({productId:a.id,client:L.getServiceRoleSupabaseClient()})}catch(o){console.error("Failed to sync Freemius sale coupon on create:",o)}w.revalidatePath("/cms/products"),Bt.redirect("/cms/products")}async function br(e,r){const n=L.createClient(),{data:{user:s}}=await n.auth.getUser();if(!s)throw new Error("User not authenticated.");const{data:a}=await n.from("currencies").select("code, symbol, exchange_rate, is_default, is_active, auto_sync_product_prices, auto_update_exchange_rate, exchange_rate_source, exchange_rate_updated_at, rounding_mode, rounding_increment, rounding_charm_amount").eq("is_active",!0).order("code",{ascending:!0}),o=Se(r,(a||[]).map(i=>Y.normalizeCurrencyRecord(i))),{error:l}=await n.from("product_drafts").upsert({product_id:e,author_id:s.id,meta:o,updated_at:new Date().toISOString()},{onConflict:"product_id"});if(l)throw new Error(`Failed to save product draft: ${l.message}`);return{success:!0}}async function yr(e){const r=L.createClient();await $e.deleteProduct(r,e),w.revalidatePath("/cms/products")}function kt(e){return Array.from(new Set(e.map(r=>r.trim()).filter(Boolean)))}async function jr(e){const r=kt(e);if(r.length===0)return{success:!1,error:"Select at least one product."};const n=L.createClient(),{error:s}=await n.from("products").delete().in("id",r);return s?{success:!1,error:s.message}:(w.revalidatePath("/cms/products"),{success:!0,count:r.length})}async function vr(e){const r=kt(e);if(r.length===0)return{success:!1,error:"Select at least one product."};const n=L.createClient(),{error:s}=await n.from("products").update({status:"draft",updated_at:new Date().toISOString()}).in("id",r);return s?{success:!1,error:s.message}:(w.revalidatePath("/cms/products"),{success:!0,count:r.length})}async function Nr(e){const r=L.getServiceRoleSupabaseClient(),n=e.name.trim(),s=Ce(e.slug?.trim()||e.name);if(!n||!s)return{success:!1,error:"Attribute name is required."};const{error:a}=await r.from("product_attributes").insert({name:n,slug:s});return a?{success:!1,error:a.message}:(w.revalidatePath("/cms/products/attributes"),w.revalidatePath("/cms/products/new"),w.revalidatePath("/cms/products"),{success:!0})}async function wr(e){const r=L.getServiceRoleSupabaseClient(),{error:n}=await r.from("product_attributes").delete().eq("id",e);return n?{success:!1,error:n.message}:(w.revalidatePath("/cms/products/attributes"),w.revalidatePath("/cms/products/new"),w.revalidatePath("/cms/products"),{success:!0})}async function Sr(e){const r=L.getServiceRoleSupabaseClient(),n=e.value.trim(),s=Ce(e.slug?.trim()||e.value);if(!n||!s)return{success:!1,error:"Term value is required."};const{data:a}=await r.from("product_attribute_terms").select("sort_order").eq("attribute_id",e.attributeId).order("sort_order",{ascending:!1}).limit(1),o=typeof a?.[0]?.sort_order=="number"?a[0].sort_order+1:0,{error:l}=await r.from("product_attribute_terms").insert({attribute_id:e.attributeId,value:n,slug:s,sort_order:o});return l?{success:!1,error:l.message}:(w.revalidatePath("/cms/products/attributes"),w.revalidatePath("/cms/products/new"),w.revalidatePath("/cms/products"),{success:!0})}async function Cr(e){const r=L.getServiceRoleSupabaseClient();for(const[n,s]of e.orderedTermIds.entries()){const{error:a}=await r.from("product_attribute_terms").update({sort_order:n,updated_at:new Date().toISOString()}).eq("id",s).eq("attribute_id",e.attributeId);if(a)return{success:!1,error:a.message}}return w.revalidatePath("/cms/products/attributes"),w.revalidatePath("/cms/products/new"),w.revalidatePath("/cms/products"),{success:!0}}async function Pr(e){const r=L.getServiceRoleSupabaseClient(),{error:n}=await r.from("product_attributes").update({name_translations:e.nameTranslations,updated_at:new Date().toISOString()}).eq("id",e.attributeId);if(n)return{success:!1,error:n.message};for(const s of e.termTranslations){const{error:a}=await r.from("product_attribute_terms").update({value_translations:s.valueTranslations,updated_at:new Date().toISOString()}).eq("id",s.termId).eq("attribute_id",e.attributeId);if(a)return{success:!1,error:a.message}}return w.revalidatePath("/cms/products/attributes"),w.revalidatePath("/cms/products/new"),w.revalidatePath("/cms/products"),{success:!0}}async function kr(e){const r=L.getServiceRoleSupabaseClient(),{error:n}=await r.from("product_attribute_terms").delete().eq("id",e);return n?{success:!1,error:n.message}:(w.revalidatePath("/cms/products/attributes"),w.revalidatePath("/cms/products/new"),w.revalidatePath("/cms/products"),{success:!0})}async function It(e){const r=L.getServiceRoleSupabaseClient(),n=e.name.trim(),s=Ce(e.slug?.trim()||e.name);if(!n||!s)return{success:!1,error:"Category name is required."};const{data:a,error:o}=await r.from("categories").insert({name:n,slug:s,description:e.description?.trim()||null,name_translations:e.nameTranslations||{},description_translations:e.descriptionTranslations||{}}).select().single();return o?{success:!1,error:o.message}:(w.revalidatePath("/cms/products/categories"),w.revalidatePath("/cms/products/new"),w.revalidatePath("/cms/products"),{success:!0,category:a})}async function Ir(e,r){const n=L.getServiceRoleSupabaseClient(),s=r.name.trim(),a=Ce(r.slug?.trim()||r.name);if(!s||!a)return{success:!1,error:"Category name is required."};const{error:o}=await n.from("categories").update({name:s,slug:a,description:r.description?.trim()||null,name_translations:r.nameTranslations||{},description_translations:r.descriptionTranslations||{}}).eq("id",e);return o?{success:!1,error:o.message}:(w.revalidatePath("/cms/products/categories"),w.revalidatePath("/cms/products/new"),w.revalidatePath("/cms/products"),{success:!0})}async function Ar(e){const r=L.getServiceRoleSupabaseClient(),{error:n}=await r.from("categories").delete().eq("id",e);return n?{success:!1,error:n.message}:(w.revalidatePath("/cms/products/categories"),w.revalidatePath("/cms/products/new"),w.revalidatePath("/cms/products"),{success:!0})}async function Tr(e,r){const n=L.getServiceRoleSupabaseClient();try{return await $e.syncCategoriesForTranslationGroup(n,e,r),w.revalidatePath("/cms/products"),w.revalidatePath(`/cms/products/${e}/edit`),{success:!0}}catch(s){return{success:!1,error:s.message}}}function At({categories:e=[],selectedIds:r=[],onChange:n,placeholder:s="Select categories..."}){const[a,o]=y.useState(!1),[l,i]=y.useState(""),[h,j]=y.useState(e),[S,F]=y.useState(!1);y.useEffect(()=>{j(e)},[e]);const b=y.useMemo(()=>h.filter(p=>r.includes(p.id)),[h,r]),g=y.useMemo(()=>{if(!l)return h;const p=l.toLowerCase();return h.filter(T=>T.name.toLowerCase().includes(p)||T.slug.toLowerCase().includes(p))},[h,l]),x=l.trim(),N=y.useMemo(()=>{if(!x)return!1;const p=x.toLowerCase();return!h.some(T=>T.name.toLowerCase()===p)},[h,x]),M=async()=>{if(x){F(!0);try{const p=await It({name:x});if(p.success&&p.category){const T={id:p.category.id,name:p.category.name,slug:p.category.slug};j(Q=>[...Q,T]),n([...r,T.id]),i(""),ae.toast.success(`Category "${T.name}" created successfully.`)}else ae.toast.error(p.error||"Failed to create category.")}catch(p){ae.toast.error(p.message||"An error occurred while creating category.")}finally{F(!1)}}},H=p=>{const T=r.includes(p)?r.filter(Q=>Q!==p):[...r,p];n(T)},k=(p,T)=>{T.stopPropagation(),n(r.filter(Q=>Q!==p))};return t.jsxs("div",{className:"space-y-2",children:[t.jsx("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:b.length===0?t.jsx("span",{className:"text-xs text-muted-foreground self-center px-2 py-1 select-none",children:"No categories selected."}):b.map(p=>t.jsxs(d.Badge,{variant:"secondary",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",children:[p.name,t.jsx("button",{type:"button",onClick:T=>k(p.id,T),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","aria-label":`Remove ${p.name}`,children:t.jsx(V.X,{className:"h-3 w-3"})})]},p.id))}),t.jsxs(d.Popover,{open:a,onOpenChange:o,children:[t.jsx(d.PopoverTrigger,{asChild:!0,children:t.jsxs(d.Button,{variant:"outline",role:"combobox","aria-expanded":a,className:"w-full justify-between h-8 text-xs font-normal",children:[t.jsx("span",{className:"truncate",children:r.length>0?`${r.length} categor${r.length===1?"y":"ies"} selected`:s}),t.jsx(V.ChevronsUpDown,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),t.jsxs(d.PopoverContent,{className:"w-[--radix-popover-trigger-width] p-0",align:"start",children:[t.jsxs("div",{className:"flex items-center border-b px-3",children:[t.jsx(V.Search,{className:"mr-2 h-4 w-4 shrink-0 opacity-50"}),t.jsx(d.Input,{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",placeholder:"Search categories...",value:l,onChange:p=>i(p.target.value)})]}),N&&t.jsx("div",{className:"border-b border-border/50 p-1",children:t.jsxs(d.Button,{type:"button",variant:"ghost",size:"sm",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",onClick:M,disabled:S,children:[S?t.jsx(V.Loader2,{className:"mr-2 h-3 w-3 animate-spin"}):t.jsx("span",{className:"font-bold mr-1.5",children:"+"}),'Create category "',x,'"']})}),t.jsx("div",{className:"max-h-60 overflow-y-auto p-1",children:g.length===0?t.jsx("p",{className:"py-4 text-center text-xs text-muted-foreground",children:"No categories found."}):t.jsx("div",{className:"flex flex-col gap-0.5",children:g.map(p=>{const T=r.includes(p.id);return t.jsxs("div",{onClick:()=>H(p.id),className:R.cn("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"),children:[t.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center pointer-events-none",children:t.jsx(d.Checkbox,{checked:T,tabIndex:-1,"aria-label":`Toggle ${p.name}`,className:"h-3.5 w-3.5"})}),t.jsxs("span",{className:"flex flex-col",children:[t.jsx("span",{children:p.name}),t.jsxs("span",{className:"font-mono text-[9px] text-muted-foreground leading-none",children:["/",p.slug]})]}),T&&t.jsx("span",{className:"absolute right-2 flex h-3.5 w-3.5 items-center justify-center",children:t.jsx(V.Check,{className:"h-3.5 w-3.5 text-primary"})})]},p.id)})})})]})]})]})}function ye({title:e,description:r,action:n,children:s,hideHeader:a}){return t.jsxs("section",{className:"rounded-lg border bg-card p-3 shadow-sm space-y-3",children:[!a&&t.jsxs("div",{className:"flex items-start justify-between gap-4 flex-wrap border-b border-muted/50 pb-2 mb-1",children:[t.jsxs("div",{className:"space-y-0.5",children:[t.jsx("h2",{className:"text-sm font-bold tracking-tight",children:e}),r?t.jsx("p",{className:"text-[11px] text-muted-foreground leading-none",children:r}):null]}),n]}),t.jsx("div",{className:a?"":"pt-1",children:s})]})}function zr(e,r,n){const s=r?Number.parseInt(r,10):void 0;return e?.language_id||(Number.isFinite(s)?s:void 0)||n.find(a=>a.is_default)?.id||n[0]?.id||1}function xt(e,r,n,s,a){const l=(s.find(b=>b.is_default)??s[0])?.code||"USD",i=e?.prices&&Object.keys(e.prices).length>0?e.prices:{[l]:typeof e?.price=="number"?e.price/100:0},h=e?.sale_prices&&Object.keys(e.sale_prices).length>0?e.sale_prices:typeof e?.sale_price=="number"?{[l]:e.sale_price/100}:{},j=e?.product_type||"",S=e?.payment_provider||(e?.product_type?Kt.derivePaymentProviderFromProductType(e.product_type):"stripe");return{...Se({product_type:j||"physical",payment_provider:S,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:i,sale_price:typeof e?.sale_price=="number"?e.sale_price/100:null,sale_prices:h,stock:e?.stock||0,meta_title:e?.meta_title||"",meta_description:e?.meta_description||"",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:zr(e,r,n),translation_group_id:e?.translation_group_id||a||void 0,product_media:e?.product_media?.map(b=>({media_id:b.media_id}))||[],category_ids:e?.category_ids||[],variation_attributes:e?.variation_attributes||[],variants:e?.variants?.map(b=>({...b,prices:b.prices||{},sale_prices:b.sale_prices||{}}))||[]},s),product_type:j,payment_provider:S}}function ft(e){return e?e.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,n)=>r.sort_order-n.sort_order):[]}function Fr(e){return e.map(r=>({media_id:r.media_id}))}function Mr(e){return e.map(r=>({media_id:r.media_id,file_path:r.file_path,alt:r.alt}))}const qr=e=>e.toString().toLowerCase().trim().replace(/\s+/g,"-").replace(/[^\w-]+/g,"").replace(/--+/g,"-").replace(/^-+/,"").replace(/-+$/,"");function Rr({initialData:e,isEdit:r=!1,mediaPickerNode:n,availableLanguagesProp:s,globalAttributesProp:a,currenciesProp:o,translationGroupId:l,targetLanguageId:i,freemiusDashboardNode:h,enabledProviders:j,configStatus:S,createAction:F,updateAction:b,availableCategoriesProp:g=[]}){const[x,N]=y.useState(!1),[M,H]=y.useState(()=>!!e?.variants?.length),k=y.useMemo(()=>o.filter(m=>m.is_active!==!1).sort((m,P)=>m.is_default!==P.is_default?m.is_default?-1:1:m.code.localeCompare(P.code)),[o]),p=y.useMemo(()=>k.find(m=>m.is_default)??k[0],[k]),T=y.useMemo(()=>Be(k),[k]),Q=Lt.useForm({resolver:Vt.zodResolver(wt),defaultValues:xt(e,i,s,k,l)}),{register:q,handleSubmit:ie,setValue:v,reset:xe,watch:z,setError:c,formState:{errors:f,dirtyFields:_}}=Q,C=y.useRef(!0),A=y.useRef(null),[B,$]=y.useState(!1),[K,D]=y.useState(null),[oe,zt]=y.useState(null),Pe=z(),Je=Q.formState.isDirty;y.useEffect(()=>{if(!r)return;if(C.current){C.current=!1,A.current=JSON.stringify(Pe);return}if(!Je)return;const m=JSON.stringify(Pe);if(m===A.current)return;const P=setTimeout(()=>{x||(A.current=m,ie(rt)())},1e3);return()=>clearTimeout(P)},[Pe,r,Je,x,ie]);const Ge=z("title"),le=z("product_type"),U=le==="digital"?"freemius":le==="physical"?"stripe":void 0,Z=le==="physical",Xe=le==="digital",ke=U?j[U]:!1,Ie=U?S[U].hasKeys:!1,Ft=!!z("freemius_product_id"),Ye=Number(z("trial_period_days")||0),He=!!z("trial_requires_payment_method"),Mt=z("variants")||[],se=z("price"),ce=z("sale_price"),W=z("prices")||{},ne=z("sale_prices")||{},ee=(Mt?.length||0)>0,qt=z("language_id"),Rt=s.find(m=>m.id===qt)?.code||s.find(m=>m.is_default)?.code||s[0]?.code,fe=y.useMemo(()=>St({currencies:k,prices:W,salePrices:ne,fallbackPrice:se,fallbackSalePrice:ce}),[se,ce,k,W,ne]),Dt=y.useMemo(()=>e?.variants?.map(m=>({...m,prices:m.prices||{},sale_prices:m.sale_prices||{}})),[e?.variants]);y.useEffect(()=>{if(_.title&&!r){const m=qr(Ge);v("slug",m,{shouldValidate:!0})}},[Ge,_.title,v,r]);const[Ae,Qe]=y.useState(()=>ft(e?.product_media)),[Te,Ze]=y.useState(new Set);y.useEffect(()=>{xe(xt(e,i,s,k,l)),Qe(ft(e?.product_media)),Ze(new Set),H(!!e?.variants?.length)},[s,k,e,xe,i,l]);const Et=m=>{const P=new Set(m.map(O=>O.id)),E=Ae.filter(O=>!P.has(O.id)),J=new Set(Te);E.forEach(O=>{O.media_id&&J.add(O.media_id)}),Ze(J),Qe(m),v("product_media",Fr(m),{shouldDirty:!0}),v("explicitly_removed_media_ids",Array.from(J),{shouldDirty:!0})};y.useEffect(()=>{v("explicitly_removed_media_ids",Array.from(Te))},[Te,v]),y.useEffect(()=>{ee&&H(!0)},[ee]),y.useEffect(()=>{q("is_taxable"),q("price"),q("sale_price"),q("payment_provider"),q("trial_requires_payment_method")},[q]),y.useEffect(()=>{if(!Xe){v("trial_period_days",0,{shouldDirty:!1,shouldValidate:!0}),v("trial_requires_payment_method",!1,{shouldDirty:!1,shouldValidate:!0});return}Ye<=0&&v("trial_requires_payment_method",!1,{shouldDirty:!1,shouldValidate:!0})},[Xe,v,Ye]),y.useEffect(()=>{U&&v("payment_provider",U,{shouldDirty:!1,shouldValidate:!0})},[U,v]),y.useEffect(()=>{p&&W[p.code]===void 0&&v("prices",{...W,[p.code]:se||0},{shouldDirty:!1})},[se,p,W,v]);const We=y.useCallback((m,P)=>{const E={...W,[m]:P};v("prices",E,{shouldDirty:!0,shouldValidate:!0}),m===p?.code&&v("price",P,{shouldDirty:!0,shouldValidate:!0})},[p?.code,W,v]),et=y.useCallback((m,P)=>{const E={...ne,[m]:P};v("sale_prices",E,{shouldDirty:!0,shouldValidate:!0}),m===p?.code&&v("sale_price",P,{shouldDirty:!0,shouldValidate:!0})},[p?.code,ne,v]),tt=y.useCallback(()=>{if(!p)return;const m=new Set(T),P=W[p.code]??se??0,E=ne[p.code]??ce??null,J=k.reduce((te,G)=>{if(G.code!==p.code&&m.has(G.code))return te;const ze=Y.convertMinorUnitAmount({amount:R.majorUnitAmountToMinor(P,p.code),fromCurrencyCode:p.code,toCurrencyCode:G.code,currencies:k,applyRounding:!0});return te[G.code]=R.minorUnitAmountToMajor(ze,G.code),te},{}),O=k.reduce((te,G)=>{if(G.code!==p.code&&m.has(G.code))return te;if(typeof E!="number")return(G.code===p.code||!m.has(G.code))&&(te[G.code]=null),te;const ze=Y.convertMinorUnitAmount({amount:R.majorUnitAmountToMinor(E,p.code),fromCurrencyCode:p.code,toCurrencyCode:G.code,currencies:k,applyRounding:!0});return te[G.code]=R.minorUnitAmountToMajor(ze,G.code),te},{});v("prices",J,{shouldDirty:!0,shouldValidate:!0}),v("sale_prices",O,{shouldDirty:!0,shouldValidate:!0}),v("price",J[p.code]??P,{shouldDirty:!0,shouldValidate:!0}),v("sale_price",O[p.code]??null,{shouldDirty:!0,shouldValidate:!0})},[k,p,W,ne,v,T,se,ce]),Ot=y.useCallback(({variationAttributes:m,variants:P})=>{v("variation_attributes",m,{shouldDirty:!0}),v("variants",P,{shouldDirty:!0,shouldValidate:!0})},[v]),rt=async m=>{N(!0),$(!0),D(null);try{if(!U){const O="Select whether this product is physical or digital before saving.";c("product_type",{type:"manual",message:O}),r?D(O):alert(O),N(!1),$(!1);return}if(m.status==="active"&&(!ke||!Ie)){const O=`${U==="stripe"?"Stripe":"Freemius"} must be enabled and fully configured before this product can be published.`;c("product_type",{type:"manual",message:O}),r?D(O):alert(O),N(!1),$(!1);return}const P=Z?0:Math.max(0,Number(m.trial_period_days||0)),E={...m,product_type:m.product_type,payment_provider:U,freemius_product_id:Z?"":m.freemius_product_id,freemius_plan_id:Z?"":m.freemius_plan_id,trial_period_days:P,trial_requires_payment_method:!Z&&P>0?m.trial_requires_payment_method:!1,upc:Z?m.upc:null,is_taxable:Z?m.is_taxable:!1,variation_attributes:Z?m.variation_attributes:[],variants:Z?m.variants:[]},J=Se(E,k);if(r&&b)await b(J),zt(new Date);else if(F)await F(J);else throw new Error("Product form action is not configured.")}catch(P){if(console.error(P),P.message==="NEXT_REDIRECT")return;let E=P.message||"An error occurred while saving.";if(P.code==="23505"){const J=P.message?.toLowerCase()||"";J.includes("products_slug_key")||J.includes("slug")?(E="This slug is already in use. Please choose another one.",c("slug",{type:"manual",message:E})):(J.includes("products_sku_key")||J.includes("sku"))&&(E="This SKU is already in use.",c("sku",{type:"manual",message:E}))}r?D(E):alert(E)}finally{N(!1),$(!1)}},$t=ee?"bg-muted/60 text-muted-foreground opacity-70":"",Ut=Mr(Ae);return t.jsxs("form",{onSubmit:ie(rt),className:"space-y-2.5 pb-4",children:[t.jsx("input",{type:"hidden",...q("translation_group_id")}),t.jsx("input",{type:"hidden",...q("payment_provider")}),t.jsxs("div",{className:"space-y-2.5 w-full",children:[t.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:[t.jsxs("div",{className:"flex items-center gap-6",children:[t.jsxs("div",{className:"flex h-9 items-center gap-2",children:[t.jsx("span",{className:"text-sm font-bold whitespace-nowrap leading-none pt-0.5",children:"Product Type"}),f.product_type&&t.jsx(V.AlertCircle,{className:"h-4 w-4 text-destructive"})]}),t.jsx("div",{className:"flex h-9 items-center",children:t.jsxs(d.Select,{onValueChange:m=>v("product_type",m,{shouldDirty:!0,shouldValidate:!0}),value:le||void 0,children:[t.jsx(d.SelectTrigger,{className:"w-[160px] h-9 text-xs",children:t.jsx(d.SelectValue,{placeholder:"Select Type"})}),t.jsxs(d.SelectContent,{children:[t.jsx(d.SelectItem,{value:"physical",children:"Physical Product"}),t.jsx(d.SelectItem,{value:"digital",children:"Digital Product"})]})]})})]}),t.jsxs("div",{className:"flex items-center gap-6",children:[t.jsxs("div",{className:"flex h-9 items-center gap-3",children:[t.jsx("span",{className:"text-[11px] font-semibold text-muted-foreground uppercase tracking-wider leading-none",children:"Payment Provider"}),t.jsx(d.Badge,{variant:"outline",className:"text-xs py-1 font-bold bg-muted/30 leading-none",children:U?U==="stripe"?"Stripe":"Freemius":"—"})]}),U&&t.jsx("div",{className:"flex h-9 items-center gap-2",children:ke&&Ie?t.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:[t.jsx(V.CheckCircle2,{className:"h-3 w-3"}),"Ready"]}):t.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:[t.jsx(V.AlertCircle,{className:"h-3 w-3"}),ke?"Keys Missing":"Disabled"]})}),!Ie&&U&&S[U].missing.length>0&&t.jsxs("div",{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",children:[t.jsx(V.Info,{className:"h-3 w-3"}),"Missing: ",S[U].missing.join(", ")]})]})]}),t.jsxs(ye,{title:"Product Information",hideHeader:!0,children:[r&&t.jsxs("div",{className:"flex items-center justify-between text-xs text-muted-foreground pb-2 border-b border-border/40 mb-2.5",children:[t.jsx("span",{className:"font-semibold text-[11px] uppercase tracking-wider text-muted-foreground/80",children:"Product Settings"}),t.jsx("div",{className:"flex items-center gap-1.5 min-h-[16px]",children:B?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"relative flex h-2 w-2",children:[t.jsx("span",{className:"animate-ping absolute inline-flex h-full w-full rounded-full bg-amber-400 opacity-75"}),t.jsx("span",{className:"relative inline-flex rounded-full h-2 w-2 bg-amber-500"})]}),t.jsx("span",{className:"text-amber-600 dark:text-amber-400 font-medium",children:"Autosaving settings..."})]}):K?t.jsxs("span",{className:"text-red-500 font-medium",children:["Error saving settings: ",K]}):oe?t.jsxs("span",{className:"text-emerald-600 dark:text-emerald-400 font-medium",children:["Settings autosaved at ",oe.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",second:"2-digit"})]}):t.jsx("span",{className:"text-muted-foreground/60",children:"Settings autosave in draft mode"})})]}),t.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-6 gap-2.5",children:[t.jsxs("div",{className:"col-span-2 space-y-1",children:[t.jsx(d.Label,{htmlFor:"title",className:"text-xs uppercase font-bold text-muted-foreground tracking-wider leading-none",children:"Title"}),t.jsx(d.Input,{id:"title",placeholder:"Product title",...q("title"),className:"h-8 text-sm"}),f.title&&t.jsx("p",{className:"text-destructive text-[11px] leading-none",children:f.title.message})]}),t.jsxs("div",{className:"col-span-2 space-y-1",children:[t.jsx(d.Label,{htmlFor:"slug",className:"text-xs uppercase font-bold text-muted-foreground tracking-wider leading-none",children:"Slug"}),t.jsx(d.Input,{id:"slug",placeholder:"product-slug",...q("slug"),className:"h-8 text-sm"}),f.slug&&t.jsx("p",{className:"text-destructive text-[11px] leading-none",children:f.slug.message})]}),t.jsxs("div",{className:"col-span-1 space-y-1",children:[t.jsx(d.Label,{htmlFor:"sku",className:"text-xs uppercase font-bold text-muted-foreground tracking-wider leading-none",children:"SKU"}),t.jsx(d.Input,{id:"sku",placeholder:"SKU",...q("sku"),className:"h-8 text-sm font-mono"}),f.sku&&t.jsx("p",{className:"text-destructive text-[11px] leading-none",children:f.sku.message})]}),t.jsxs("div",{className:"col-span-1 space-y-1",children:[t.jsx(d.Label,{htmlFor:"upc_ean",className:"text-xs uppercase font-bold text-muted-foreground tracking-wider leading-none",children:"UPC / EAN"}),t.jsx(d.Input,{id:"upc_ean",placeholder:"000000000",...q("upc"),className:"h-8 text-sm font-mono",readOnly:ee})]})]}),t.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-6 gap-2.5 mt-2",children:[t.jsxs("div",{className:"lg:col-span-2 col-span-2 space-y-1",children:[t.jsx(d.Label,{htmlFor:"meta_title",className:"text-xs uppercase font-bold text-muted-foreground tracking-wider leading-none",children:"Meta Title"}),t.jsx(d.Input,{id:"meta_title",...q("meta_title"),placeholder:"SEO page title (50-60 chars)",className:"h-8 text-sm"})]}),t.jsxs("div",{className:`lg:col-span-${r?"3":"4"} col-span-2 space-y-1`,children:[t.jsx(d.Label,{htmlFor:"meta_description",className:"text-xs uppercase font-bold text-muted-foreground tracking-wider leading-none",children:"Meta Description"}),t.jsx(d.Input,{id:"meta_description",...q("meta_description"),placeholder:"SEO description (150-160 chars)",className:"h-8 text-sm"})]}),r&&t.jsxs("div",{className:"lg:col-span-1 col-span-2 space-y-1",children:[t.jsx(d.Label,{htmlFor:"status",className:"text-xs uppercase font-bold text-muted-foreground tracking-wider leading-none",children:"Status"}),t.jsxs(d.Select,{onValueChange:m=>v("status",m,{shouldDirty:!0}),value:z("status"),children:[t.jsx(d.SelectTrigger,{className:"h-8 text-xs",children:t.jsx(d.SelectValue,{placeholder:"Status"})}),t.jsxs(d.SelectContent,{children:[t.jsx(d.SelectItem,{value:"draft",children:"Draft"}),t.jsx(d.SelectItem,{value:"active",children:"Active"}),t.jsx(d.SelectItem,{value:"archived",children:"Archived"})]})]})]})]})]}),t.jsx(ye,{title:"Product Categories",description:"Assign this product to one or more categories.",children:t.jsx(At,{categories:g,selectedIds:z("category_ids")||[],onChange:m=>v("category_ids",m,{shouldDirty:!0,shouldValidate:!0})})}),t.jsxs("section",{className:"rounded-lg border bg-card p-3 shadow-sm space-y-3",children:[Z&&t.jsxs("div",{className:"flex items-center justify-between gap-4 flex-wrap border-b border-muted/50 pb-2",children:[t.jsx("div",{className:"flex items-center gap-4",children:t.jsxs("div",{className:"space-y-0.5",children:[t.jsx("h2",{className:"text-sm font-bold tracking-tight",children:"Pricing & Inventory"}),t.jsx("p",{className:"text-[11px] text-muted-foreground leading-none",children:"Manage simple or variant pricing."})]})}),t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsxs("div",{className:"flex items-center gap-2 bg-muted/40 rounded-md px-2.5 py-1.5",children:[t.jsx("span",{className:"text-xs uppercase font-bold text-muted-foreground tracking-wider leading-none",children:"Stock"}),t.jsx(d.Input,{id:"stock",type:"number",min:"0",...q("stock",{valueAsNumber:!0}),placeholder:"0",readOnly:ee,className:`${$t} h-8 w-20 text-sm text-center font-mono bg-background`})]}),ee?t.jsx(d.Badge,{variant:"secondary",className:"text-[11px] py-0 px-2 h-5",children:"Variant pricing"}):null]})]}),Z?t.jsxs("div",{className:"space-y-3",children:[t.jsxs("div",{className:"w-full",children:[t.jsx(qe,{idPrefix:"product",currencies:k,prices:fe.prices,salePrices:fe.salePrices,managedCurrencyCodes:T,onPriceChange:We,onSalePriceChange:et,onAutoFill:tt,readOnly:ee,helperText:ee?"Parent prices stay as a fallback, but active variants define the live shopper price.":void 0,trailing:t.jsx(Re,{idPrefix:"product",startAt:z("sale_start_at"),endAt:z("sale_end_at"),onChange:(m,P)=>v(m,P,{shouldDirty:!0,shouldValidate:!0}),error:f.sale_end_at?.message,bare:!0})}),f.price&&t.jsx("p",{className:"text-destructive text-sm mt-1",children:f.price.message}),f.sale_price&&t.jsx("p",{className:"text-destructive text-sm mt-1",children:f.sale_price.message}),f.stock&&t.jsx("p",{className:"text-destructive text-[10px] font-medium leading-none mt-1",children:f.stock.message})]}),t.jsxs("div",{className:"flex items-center justify-between gap-3 rounded border border-dashed p-2.5 bg-muted/5",children:[t.jsx("span",{className:"text-xs font-bold uppercase tracking-wider text-muted-foreground",children:ee?"Variations Active":"Variations"}),t.jsx(d.Button,{type:"button",variant:M?"outline":"default",onClick:()=>H(m=>!m),size:"sm",className:"h-7 text-xs px-3",children:M?"Hide":"Manage"})]}),M&&t.jsx("div",{className:"border-t pt-3",children:t.jsx(dr,{globalAttributes:a,currentLanguageCode:Rt,baseSku:z("sku")||"",basePrice:se||0,basePrices:W,baseSalePrice:typeof ce=="number"?ce:null,baseSalePrices:ne,currencies:k,availableVariantImages:Ut,initialVariationAttributes:e?.variation_attributes,initialVariants:Dt,onChange:Ot})})]}):t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"space-y-4",children:[t.jsxs("div",{className:"flex items-end gap-4 w-full",children:[t.jsxs("div",{className:"flex-1",children:[t.jsx(d.Label,{htmlFor:"freemius_product_id",className:"text-[11px] uppercase tracking-wider text-muted-foreground font-bold mb-1.5 block",children:"Freemius Product ID"}),t.jsx(d.Input,{id:"freemius_product_id",...q("freemius_product_id"),className:"h-9"})]}),t.jsxs("div",{className:"flex-1",children:[t.jsx(d.Label,{htmlFor:"freemius_plan_id",className:"text-[11px] uppercase tracking-wider text-muted-foreground font-bold mb-1.5 block",children:"Freemius Plan ID"}),t.jsx(d.Input,{id:"freemius_plan_id",...q("freemius_plan_id"),className:"h-9"})]}),Ft?t.jsx(ar,{productId:z("freemius_product_id")}):null]}),t.jsxs("div",{className:"bg-muted/10 border rounded-md overflow-hidden",children:[t.jsxs("div",{className:"flex flex-wrap items-center gap-6 bg-muted/20 border-b p-2.5 px-4",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-[11px] font-bold uppercase tracking-wider text-muted-foreground",children:"Free Trial"}),t.jsxs(d.Badge,{variant:"outline",className:"font-mono text-xs shadow-sm bg-background",children:[String(z("trial_period_days")||0)," Days"]})]}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-[11px] font-bold uppercase tracking-wider text-muted-foreground",children:"Card Required"}),t.jsx(d.Badge,{variant:He?"default":"secondary",className:"text-xs shadow-sm",children:He?"Yes":"No"})]}),t.jsx("span",{className:"text-[10px] text-muted-foreground ml-auto",children:"Managed in Freemius dashboard"}),t.jsx("input",{type:"hidden",...q("trial_period_days",{valueAsNumber:!0})})]}),t.jsxs("div",{className:"w-full p-4 pt-3 space-y-2",children:[t.jsx(qe,{idPrefix:"product",currencies:k,prices:fe.prices,salePrices:fe.salePrices,managedCurrencyCodes:T,onPriceChange:We,onSalePriceChange:et,onAutoFill:tt,readOnly:!0,trailing:t.jsx(Re,{idPrefix:"product",startAt:z("sale_start_at"),endAt:z("sale_end_at"),onChange:(m,P)=>v(m,P,{shouldDirty:!0,shouldValidate:!0}),error:f.sale_end_at?.message,bare:!0})}),t.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."})]})]})]}),h&&t.jsx("div",{className:"pt-2 border-t",children:h})]})]}),t.jsx(ye,{title:"Product Description",hideHeader:!0,children:t.jsx("div",{className:"space-y-2",children:t.jsxs("div",{className:"space-y-1",children:[t.jsx(d.Label,{htmlFor:"short_description",className:"text-xs uppercase font-bold text-muted-foreground tracking-wider leading-none",children:"Short Description"}),t.jsx(d.Input,{id:"short_description",...q("short_description"),placeholder:"Brief summary for product cards...",className:"h-8 text-sm"})]})})}),t.jsxs(ye,{title:"Media Gallery",description:"Drag to reorder. First image is the hero.",children:[t.jsx(nr,{initialMedia:Ae,onUpdate:Et,mediaPickerNode:n}),t.jsx("input",{type:"hidden",...q("product_media")})]}),!r&&t.jsxs("div",{className:"rounded-lg border bg-card p-3 px-4 shadow-sm flex items-center justify-between gap-3 flex-wrap",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-xs uppercase font-bold text-muted-foreground tracking-wider leading-none",children:"Status"}),t.jsxs(d.Select,{onValueChange:m=>v("status",m),value:z("status"),children:[t.jsx(d.SelectTrigger,{className:"h-8 w-[110px] text-sm",children:t.jsx(d.SelectValue,{placeholder:"Status"})}),t.jsxs(d.SelectContent,{children:[t.jsx(d.SelectItem,{value:"draft",children:"Draft"}),t.jsx(d.SelectItem,{value:"active",children:"Active"}),t.jsx(d.SelectItem,{value:"archived",children:"Archived"})]})]})]}),t.jsx(d.Button,{disabled:x,type:"submit",size:"sm",className:"h-8 text-sm px-5",children:x?"Saving...":"Save Changes"})]})]})]})}function I(e,r,n){const s=e(r);return s===r?n:s}function Dr(e){return{invoice:I(e,"invoice","Invoice"),invoiceNumber:I(e,"invoice_number","Invoice #"),orderNumber:I(e,"order_number","Order #"),paidOn:I(e,"paid_on","Paid on"),status:I(e,"status","Status"),from:I(e,"from","From"),billTo:I(e,"bill_to","Bill to"),shipTo:I(e,"ship_to","Ship to"),item:I(e,"product","Item"),details:I(e,"details","Details"),quantity:I(e,"ecommerce.qty","Qty"),price:I(e,"price","Price"),amount:I(e,"amount","Amount"),subtotal:I(e,"ecommerce.subtotal","Subtotal"),discount:I(e,"ecommerce.discount","Discount"),shipping:I(e,"ecommerce.shipping","Shipping"),tax:I(e,"ecommerce.tax","Tax"),total:I(e,"ecommerce.total","Total"),taxBreakdown:I(e,"tax_breakdown","Tax breakdown"),taxRegistrations:I(e,"tax_registrations","Tax registrations")}}function Er(e){return e==="fr"?"fr-CA":"en-US"}function Tt(e,r){if(!e)return"";switch(e.toLowerCase()){case"paid":return I(r,"order_status_paid","Paid");case"pending":return I(r,"order_status_pending","Pending");case"trial":return I(r,"order_status_trial","Trial");case"shipped":return I(r,"order_status_shipped","Shipped");case"cancelled":return I(r,"order_status_cancelled","Cancelled");case"refunded":return I(r,"order_status_refunded","Refunded");default:return e}}function Or(e,r){return e?{...e,order:{...e.order,status:Tt(e.order.status,r)}}:null}exports.DEFAULT_INVOICE_SETTINGS=Ue;exports.INVOICE_SETTINGS_KEY=Jt;exports.InvoiceDocument=yt;exports.InvoiceViewerShell=Wt;exports.ProductCategorySelector=At;exports.ProductForm=Rr;exports.aggregateOrderTaxLines=Le;exports.buildInvoiceDocumentLabels=Dr;exports.buildOrderTaxDetailsFromCalculation=Qt;exports.buildOrderTaxDetailsFromStripeSession=Zt;exports.bulkDeleteProductsAction=jr;exports.bulkDraftProductsAction=vr;exports.createCategoryAction=It;exports.createProductAction=hr;exports.createProductAttributeAction=Nr;exports.createProductAttributeTermAction=Sr;exports.deleteCategoryAction=Ar;exports.deleteCouponFromFreemius=_r;exports.deleteProductAction=yr;exports.deleteProductAttributeAction=wr;exports.deleteProductAttributeTermAction=kr;exports.formatInvoiceCurrency=re;exports.formatInvoiceDate=bt;exports.getInvoiceAddressLines=je;exports.getInvoiceLocale=Er;exports.getOrderTaxRateJurisdiction=ve;exports.getOrderTaxRateLabel=me;exports.getOrderTaxRatePercentage=pe;exports.localizeInvoicePresentationData=Or;exports.normalizeInvoiceSettings=Gt;exports.normalizeOrderTaxDetails=Ht;exports.productSchema=wt;exports.reorderProductAttributeTermsAction=Cr;exports.serializeInvoiceSettings=Xt;exports.syncCouponToFreemius=xr;exports.syncProductCategoriesAction=Tr;exports.syncProductSaleCouponToFreemius=Pt;exports.translateOrFallback=I;exports.translateOrderStatus=Tt;exports.updateCategoryAction=Ir;exports.updateProductAction=br;exports.updateProductAttributeTranslationsAction=Pr;