@endora-commerce/mod-catalog 0.108.0 → 0.110.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (571) hide show
  1. package/dist/admin/components/CopyToChannelsDialog.d.ts +37 -0
  2. package/dist/admin/components/CopyToChannelsDialog.d.ts.map +1 -0
  3. package/dist/admin/components/CopyToChannelsDialog.js +83 -0
  4. package/dist/admin/components/CopyToChannelsDialog.js.map +1 -0
  5. package/dist/admin/components/PackagingUnitsEditor.d.ts +16 -1
  6. package/dist/admin/components/PackagingUnitsEditor.d.ts.map +1 -1
  7. package/dist/admin/components/PackagingUnitsEditor.js +20 -14
  8. package/dist/admin/components/PackagingUnitsEditor.js.map +1 -1
  9. package/dist/admin/components/ProductAttachmentsSection.d.ts +3 -0
  10. package/dist/admin/components/ProductAttachmentsSection.d.ts.map +1 -0
  11. package/dist/admin/components/ProductAttachmentsSection.js +98 -0
  12. package/dist/admin/components/ProductAttachmentsSection.js.map +1 -0
  13. package/dist/admin/components/ProductAttributesTab.d.ts +1 -11
  14. package/dist/admin/components/ProductAttributesTab.d.ts.map +1 -1
  15. package/dist/admin/components/ProductAttributesTab.js +128 -119
  16. package/dist/admin/components/ProductAttributesTab.js.map +1 -1
  17. package/dist/admin/components/ProductContentCard.d.ts +41 -0
  18. package/dist/admin/components/ProductContentCard.d.ts.map +1 -0
  19. package/dist/admin/components/ProductContentCard.js +28 -0
  20. package/dist/admin/components/ProductContentCard.js.map +1 -0
  21. package/dist/admin/components/ProductGallerySection.d.ts +3 -0
  22. package/dist/admin/components/ProductGallerySection.d.ts.map +1 -0
  23. package/dist/admin/components/ProductGallerySection.js +129 -0
  24. package/dist/admin/components/ProductGallerySection.js.map +1 -0
  25. package/dist/admin/components/ProductOrderRulesCard.d.ts +11 -15
  26. package/dist/admin/components/ProductOrderRulesCard.d.ts.map +1 -1
  27. package/dist/admin/components/ProductOrderRulesCard.js +15 -140
  28. package/dist/admin/components/ProductOrderRulesCard.js.map +1 -1
  29. package/dist/admin/components/ProductScopeBar.d.ts +28 -0
  30. package/dist/admin/components/ProductScopeBar.d.ts.map +1 -0
  31. package/dist/admin/components/ProductScopeBar.js +70 -0
  32. package/dist/admin/components/ProductScopeBar.js.map +1 -0
  33. package/dist/admin/components/ProductScopeOverview.d.ts +38 -0
  34. package/dist/admin/components/ProductScopeOverview.d.ts.map +1 -0
  35. package/dist/admin/components/ProductScopeOverview.js +222 -0
  36. package/dist/admin/components/ProductScopeOverview.js.map +1 -0
  37. package/dist/admin/components/ProductStatusPills.d.ts +17 -0
  38. package/dist/admin/components/ProductStatusPills.d.ts.map +1 -0
  39. package/dist/admin/components/ProductStatusPills.js +23 -0
  40. package/dist/admin/components/ProductStatusPills.js.map +1 -0
  41. package/dist/admin/components/ProductUrlRedirects.d.ts +15 -0
  42. package/dist/admin/components/ProductUrlRedirects.d.ts.map +1 -0
  43. package/dist/admin/components/ProductUrlRedirects.js +70 -0
  44. package/dist/admin/components/ProductUrlRedirects.js.map +1 -0
  45. package/dist/admin/components/ProductsBulkEditDialog.d.ts +30 -0
  46. package/dist/admin/components/ProductsBulkEditDialog.d.ts.map +1 -1
  47. package/dist/admin/components/ProductsBulkEditDialog.js +288 -133
  48. package/dist/admin/components/ProductsBulkEditDialog.js.map +1 -1
  49. package/dist/admin/components/editor/DetailsTab.d.ts +30 -0
  50. package/dist/admin/components/editor/DetailsTab.d.ts.map +1 -0
  51. package/dist/admin/components/editor/DetailsTab.js +59 -0
  52. package/dist/admin/components/editor/DetailsTab.js.map +1 -0
  53. package/dist/admin/components/editor/ImmediateBadge.d.ts +21 -0
  54. package/dist/admin/components/editor/ImmediateBadge.d.ts.map +1 -0
  55. package/dist/admin/components/editor/ImmediateBadge.js +21 -0
  56. package/dist/admin/components/editor/ImmediateBadge.js.map +1 -0
  57. package/dist/admin/components/editor/confirm-removal.d.ts +13 -0
  58. package/dist/admin/components/editor/confirm-removal.d.ts.map +1 -0
  59. package/dist/admin/components/editor/confirm-removal.js +33 -0
  60. package/dist/admin/components/editor/confirm-removal.js.map +1 -0
  61. package/dist/admin/components/editor/editor-context.d.ts +53 -0
  62. package/dist/admin/components/editor/editor-context.d.ts.map +1 -0
  63. package/dist/admin/components/editor/editor-context.js +88 -0
  64. package/dist/admin/components/editor/editor-context.js.map +1 -0
  65. package/dist/admin/components/editor/scoped-controls.d.ts +46 -0
  66. package/dist/admin/components/editor/scoped-controls.d.ts.map +1 -0
  67. package/dist/admin/components/editor/scoped-controls.js +64 -0
  68. package/dist/admin/components/editor/scoped-controls.js.map +1 -0
  69. package/dist/admin/index.d.ts +2 -2
  70. package/dist/admin/index.d.ts.map +1 -1
  71. package/dist/admin/index.js +20 -0
  72. package/dist/admin/index.js.map +1 -1
  73. package/dist/admin/lib/attribute-scope.d.ts +23 -0
  74. package/dist/admin/lib/attribute-scope.d.ts.map +1 -0
  75. package/dist/admin/lib/attribute-scope.js +21 -0
  76. package/dist/admin/lib/attribute-scope.js.map +1 -0
  77. package/dist/admin/lib/bulk-operation-log-text.d.ts +9 -0
  78. package/dist/admin/lib/bulk-operation-log-text.d.ts.map +1 -0
  79. package/dist/admin/lib/bulk-operation-log-text.js +13 -0
  80. package/dist/admin/lib/bulk-operation-log-text.js.map +1 -0
  81. package/dist/admin/lib/editor-scope.d.ts +35 -0
  82. package/dist/admin/lib/editor-scope.d.ts.map +1 -0
  83. package/dist/admin/lib/editor-scope.js +114 -0
  84. package/dist/admin/lib/editor-scope.js.map +1 -0
  85. package/dist/admin/lib/order-minimum-input.d.ts +13 -0
  86. package/dist/admin/lib/order-minimum-input.d.ts.map +1 -0
  87. package/dist/admin/lib/order-minimum-input.js +16 -0
  88. package/dist/admin/lib/order-minimum-input.js.map +1 -0
  89. package/dist/admin/lib/product-labels.d.ts +12 -0
  90. package/dist/admin/lib/product-labels.d.ts.map +1 -0
  91. package/dist/admin/lib/product-labels.js +23 -0
  92. package/dist/admin/lib/product-labels.js.map +1 -0
  93. package/dist/admin/lib/product-scopes-api.d.ts +23 -0
  94. package/dist/admin/lib/product-scopes-api.d.ts.map +1 -0
  95. package/dist/admin/lib/product-scopes-api.js +57 -0
  96. package/dist/admin/lib/product-scopes-api.js.map +1 -0
  97. package/dist/admin/lib/product-url-keys-api.d.ts +23 -0
  98. package/dist/admin/lib/product-url-keys-api.d.ts.map +1 -0
  99. package/dist/admin/lib/product-url-keys-api.js +61 -0
  100. package/dist/admin/lib/product-url-keys-api.js.map +1 -0
  101. package/dist/admin/lib/resolve-product-selection.d.ts +29 -1
  102. package/dist/admin/lib/resolve-product-selection.d.ts.map +1 -1
  103. package/dist/admin/lib/resolve-product-selection.js +42 -6
  104. package/dist/admin/lib/resolve-product-selection.js.map +1 -1
  105. package/dist/admin/lib/scope-overview.d.ts +73 -0
  106. package/dist/admin/lib/scope-overview.d.ts.map +1 -0
  107. package/dist/admin/lib/scope-overview.js +178 -0
  108. package/dist/admin/lib/scope-overview.js.map +1 -0
  109. package/dist/admin/lib/scoped-editor-store.d.ts +81 -0
  110. package/dist/admin/lib/scoped-editor-store.d.ts.map +1 -0
  111. package/dist/admin/lib/scoped-editor-store.js +198 -0
  112. package/dist/admin/lib/scoped-editor-store.js.map +1 -0
  113. package/dist/admin/lib/scoped-values-api.d.ts +14 -0
  114. package/dist/admin/lib/scoped-values-api.d.ts.map +1 -0
  115. package/dist/admin/lib/scoped-values-api.js +55 -0
  116. package/dist/admin/lib/scoped-values-api.js.map +1 -0
  117. package/dist/admin/pages/AttributesManager.d.ts.map +1 -1
  118. package/dist/admin/pages/AttributesManager.js +186 -28
  119. package/dist/admin/pages/AttributesManager.js.map +1 -1
  120. package/dist/admin/pages/BulkOperationDetailPage.d.ts.map +1 -1
  121. package/dist/admin/pages/BulkOperationDetailPage.js +4 -19
  122. package/dist/admin/pages/BulkOperationDetailPage.js.map +1 -1
  123. package/dist/admin/pages/ProductContentPage.d.ts +27 -0
  124. package/dist/admin/pages/ProductContentPage.d.ts.map +1 -0
  125. package/dist/admin/pages/ProductContentPage.js +161 -0
  126. package/dist/admin/pages/ProductContentPage.js.map +1 -0
  127. package/dist/admin/pages/ProductCreateForm.d.ts +3 -0
  128. package/dist/admin/pages/ProductCreateForm.d.ts.map +1 -0
  129. package/dist/admin/pages/ProductCreateForm.js +87 -0
  130. package/dist/admin/pages/ProductCreateForm.js.map +1 -0
  131. package/dist/admin/pages/ProductEditor.d.ts +0 -4
  132. package/dist/admin/pages/ProductEditor.d.ts.map +1 -1
  133. package/dist/admin/pages/ProductEditor.js +878 -627
  134. package/dist/admin/pages/ProductEditor.js.map +1 -1
  135. package/dist/admin/pages/ProductsList.d.ts +12 -0
  136. package/dist/admin/pages/ProductsList.d.ts.map +1 -1
  137. package/dist/admin/pages/ProductsList.js +111 -54
  138. package/dist/admin/pages/ProductsList.js.map +1 -1
  139. package/dist/backend/admin-search-provider.d.ts +3 -2
  140. package/dist/backend/admin-search-provider.d.ts.map +1 -1
  141. package/dist/backend/admin-search-provider.js +2 -3
  142. package/dist/backend/admin-search-provider.js.map +1 -1
  143. package/dist/backend/commands/attribute-commands.d.ts +4 -3
  144. package/dist/backend/commands/attribute-commands.d.ts.map +1 -1
  145. package/dist/backend/commands/attribute-commands.js +82 -21
  146. package/dist/backend/commands/attribute-commands.js.map +1 -1
  147. package/dist/backend/commands/product-content-commands.d.ts +31 -0
  148. package/dist/backend/commands/product-content-commands.d.ts.map +1 -0
  149. package/dist/backend/commands/product-content-commands.js +70 -0
  150. package/dist/backend/commands/product-content-commands.js.map +1 -0
  151. package/dist/backend/commands/scoped-values.commands.d.ts +95 -0
  152. package/dist/backend/commands/scoped-values.commands.d.ts.map +1 -0
  153. package/dist/backend/commands/scoped-values.commands.js +235 -0
  154. package/dist/backend/commands/scoped-values.commands.js.map +1 -0
  155. package/dist/backend/demo/reset.d.ts.map +1 -1
  156. package/dist/backend/demo/reset.js +2 -1
  157. package/dist/backend/demo/reset.js.map +1 -1
  158. package/dist/backend/demo/rows.d.ts +25 -0
  159. package/dist/backend/demo/rows.d.ts.map +1 -1
  160. package/dist/backend/demo/rows.js +35 -12
  161. package/dist/backend/demo/rows.js.map +1 -1
  162. package/dist/backend/demo/seed.d.ts +2 -1
  163. package/dist/backend/demo/seed.d.ts.map +1 -1
  164. package/dist/backend/demo/seed.js +22 -8
  165. package/dist/backend/demo/seed.js.map +1 -1
  166. package/dist/backend/entities/bulk-operation.entity.d.ts +10 -0
  167. package/dist/backend/entities/bulk-operation.entity.d.ts.map +1 -1
  168. package/dist/backend/entities/bulk-operation.entity.js.map +1 -1
  169. package/dist/backend/entities/gallery-item-scope-override.entity.d.ts +30 -0
  170. package/dist/backend/entities/gallery-item-scope-override.entity.d.ts.map +1 -0
  171. package/dist/backend/entities/gallery-item-scope-override.entity.js +80 -0
  172. package/dist/backend/entities/gallery-item-scope-override.entity.js.map +1 -0
  173. package/dist/backend/entities/gallery-item.entity.d.ts +9 -1
  174. package/dist/backend/entities/gallery-item.entity.d.ts.map +1 -1
  175. package/dist/backend/entities/gallery-item.entity.js +16 -0
  176. package/dist/backend/entities/gallery-item.entity.js.map +1 -1
  177. package/dist/backend/entities/gallery-role-scope-override.entity.d.ts +28 -0
  178. package/dist/backend/entities/gallery-role-scope-override.entity.d.ts.map +1 -0
  179. package/dist/backend/entities/gallery-role-scope-override.entity.js +75 -0
  180. package/dist/backend/entities/gallery-role-scope-override.entity.js.map +1 -0
  181. package/dist/backend/entities/product-attachment-scope-override.entity.d.ts +30 -0
  182. package/dist/backend/entities/product-attachment-scope-override.entity.d.ts.map +1 -0
  183. package/dist/backend/entities/product-attachment-scope-override.entity.js +80 -0
  184. package/dist/backend/entities/product-attachment-scope-override.entity.js.map +1 -0
  185. package/dist/backend/entities/product-attachment.entity.d.ts +6 -1
  186. package/dist/backend/entities/product-attachment.entity.d.ts.map +1 -1
  187. package/dist/backend/entities/product-attachment.entity.js +9 -0
  188. package/dist/backend/entities/product-attachment.entity.js.map +1 -1
  189. package/dist/backend/entities/product-attribute.entity.d.ts +5 -9
  190. package/dist/backend/entities/product-attribute.entity.d.ts.map +1 -1
  191. package/dist/backend/entities/product-attribute.entity.js +5 -13
  192. package/dist/backend/entities/product-attribute.entity.js.map +1 -1
  193. package/dist/backend/entities/product-channel-language-scope.entity.d.ts +23 -0
  194. package/dist/backend/entities/product-channel-language-scope.entity.d.ts.map +1 -0
  195. package/dist/backend/entities/product-channel-language-scope.entity.js +61 -0
  196. package/dist/backend/entities/product-channel-language-scope.entity.js.map +1 -0
  197. package/dist/backend/entities/product-channel-scope.entity.d.ts +47 -0
  198. package/dist/backend/entities/product-channel-scope.entity.d.ts.map +1 -0
  199. package/dist/backend/entities/product-channel-scope.entity.js +113 -0
  200. package/dist/backend/entities/product-channel-scope.entity.js.map +1 -0
  201. package/dist/backend/entities/product-content-value.entity.d.ts +39 -0
  202. package/dist/backend/entities/product-content-value.entity.d.ts.map +1 -0
  203. package/dist/backend/entities/product-content-value.entity.js +81 -0
  204. package/dist/backend/entities/product-content-value.entity.js.map +1 -0
  205. package/dist/backend/entities/product-packaging-unit-scope-override.entity.d.ts +30 -0
  206. package/dist/backend/entities/product-packaging-unit-scope-override.entity.d.ts.map +1 -0
  207. package/dist/backend/entities/product-packaging-unit-scope-override.entity.js +80 -0
  208. package/dist/backend/entities/product-packaging-unit-scope-override.entity.js.map +1 -0
  209. package/dist/backend/entities/product-url-key.entity.d.ts +27 -0
  210. package/dist/backend/entities/product-url-key.entity.d.ts.map +1 -0
  211. package/dist/backend/entities/product-url-key.entity.js +70 -0
  212. package/dist/backend/entities/product-url-key.entity.js.map +1 -0
  213. package/dist/backend/entities/product-url-redirect.entity.d.ts +18 -0
  214. package/dist/backend/entities/product-url-redirect.entity.d.ts.map +1 -0
  215. package/dist/backend/entities/product-url-redirect.entity.js +57 -0
  216. package/dist/backend/entities/product-url-redirect.entity.js.map +1 -0
  217. package/dist/backend/entities/product-variant.entity.d.ts +8 -1
  218. package/dist/backend/entities/product-variant.entity.d.ts.map +1 -1
  219. package/dist/backend/entities/product-variant.entity.js +13 -2
  220. package/dist/backend/entities/product-variant.entity.js.map +1 -1
  221. package/dist/backend/entities/product.entity.d.ts +48 -16
  222. package/dist/backend/entities/product.entity.d.ts.map +1 -1
  223. package/dist/backend/entities/product.entity.js +65 -35
  224. package/dist/backend/entities/product.entity.js.map +1 -1
  225. package/dist/backend/index.d.ts +29 -2
  226. package/dist/backend/index.d.ts.map +1 -1
  227. package/dist/backend/index.js +311 -29
  228. package/dist/backend/index.js.map +1 -1
  229. package/dist/backend/plugin.d.ts +79 -8
  230. package/dist/backend/plugin.d.ts.map +1 -1
  231. package/dist/backend/plugin.js +98 -17
  232. package/dist/backend/plugin.js.map +1 -1
  233. package/dist/backend/prompt-tools.d.ts +11 -0
  234. package/dist/backend/prompt-tools.d.ts.map +1 -1
  235. package/dist/backend/prompt-tools.js +124 -9
  236. package/dist/backend/prompt-tools.js.map +1 -1
  237. package/dist/backend/routes.admin.d.ts +42 -14
  238. package/dist/backend/routes.admin.d.ts.map +1 -1
  239. package/dist/backend/routes.admin.js +214 -134
  240. package/dist/backend/routes.admin.js.map +1 -1
  241. package/dist/backend/routes.admin.url-keys.d.ts +23 -0
  242. package/dist/backend/routes.admin.url-keys.d.ts.map +1 -0
  243. package/dist/backend/routes.admin.url-keys.js +14 -0
  244. package/dist/backend/routes.admin.url-keys.js.map +1 -0
  245. package/dist/backend/routes.api-key.d.ts.map +1 -1
  246. package/dist/backend/routes.api-key.js +18 -3
  247. package/dist/backend/routes.api-key.js.map +1 -1
  248. package/dist/backend/routes.external.d.ts.map +1 -1
  249. package/dist/backend/routes.external.js +6 -1
  250. package/dist/backend/routes.external.js.map +1 -1
  251. package/dist/backend/routes.public.d.ts +31 -7
  252. package/dist/backend/routes.public.d.ts.map +1 -1
  253. package/dist/backend/routes.public.js +114 -33
  254. package/dist/backend/routes.public.js.map +1 -1
  255. package/dist/backend/routes.public.url-keys.d.ts +26 -0
  256. package/dist/backend/routes.public.url-keys.d.ts.map +1 -0
  257. package/dist/backend/routes.public.url-keys.js +17 -0
  258. package/dist/backend/routes.public.url-keys.js.map +1 -0
  259. package/dist/backend/services/asset-references.d.ts +12 -1
  260. package/dist/backend/services/asset-references.d.ts.map +1 -1
  261. package/dist/backend/services/asset-references.js +85 -32
  262. package/dist/backend/services/asset-references.js.map +1 -1
  263. package/dist/backend/services/attachment-packaging-scopes.d.ts +61 -0
  264. package/dist/backend/services/attachment-packaging-scopes.d.ts.map +1 -0
  265. package/dist/backend/services/attachment-packaging-scopes.js +98 -0
  266. package/dist/backend/services/attachment-packaging-scopes.js.map +1 -0
  267. package/dist/backend/services/attachment.service.d.ts +8 -1
  268. package/dist/backend/services/attachment.service.d.ts.map +1 -1
  269. package/dist/backend/services/attachment.service.js +105 -21
  270. package/dist/backend/services/attachment.service.js.map +1 -1
  271. package/dist/backend/services/attribute-filter-match.d.ts +14 -0
  272. package/dist/backend/services/attribute-filter-match.d.ts.map +1 -0
  273. package/dist/backend/services/attribute-filter-match.js +19 -0
  274. package/dist/backend/services/attribute-filter-match.js.map +1 -0
  275. package/dist/backend/services/attribute-scope-preview.d.ts +48 -0
  276. package/dist/backend/services/attribute-scope-preview.d.ts.map +1 -0
  277. package/dist/backend/services/attribute-scope-preview.js +76 -0
  278. package/dist/backend/services/attribute-scope-preview.js.map +1 -0
  279. package/dist/backend/services/attribute-set.service.d.ts +10 -1
  280. package/dist/backend/services/attribute-set.service.d.ts.map +1 -1
  281. package/dist/backend/services/attribute-set.service.js +30 -4
  282. package/dist/backend/services/attribute-set.service.js.map +1 -1
  283. package/dist/backend/services/attribute-type-mapping.d.ts +2 -2
  284. package/dist/backend/services/attribute-type-mapping.d.ts.map +1 -1
  285. package/dist/backend/services/attribute-type-mapping.js +6 -0
  286. package/dist/backend/services/attribute-type-mapping.js.map +1 -1
  287. package/dist/backend/services/attribute-usage.d.ts +31 -0
  288. package/dist/backend/services/attribute-usage.d.ts.map +1 -0
  289. package/dist/backend/services/attribute-usage.js +29 -0
  290. package/dist/backend/services/attribute-usage.js.map +1 -0
  291. package/dist/backend/services/bulk-operation.service.d.ts +36 -0
  292. package/dist/backend/services/bulk-operation.service.d.ts.map +1 -1
  293. package/dist/backend/services/bulk-operation.service.js +210 -37
  294. package/dist/backend/services/bulk-operation.service.js.map +1 -1
  295. package/dist/backend/services/bundle.service.d.ts +9 -1
  296. package/dist/backend/services/bundle.service.d.ts.map +1 -1
  297. package/dist/backend/services/bundle.service.js +31 -3
  298. package/dist/backend/services/bundle.service.js.map +1 -1
  299. package/dist/backend/services/catalog-admin-search.service.d.ts +4 -3
  300. package/dist/backend/services/catalog-admin-search.service.d.ts.map +1 -1
  301. package/dist/backend/services/catalog-admin-search.service.js +7 -7
  302. package/dist/backend/services/catalog-admin-search.service.js.map +1 -1
  303. package/dist/backend/services/catalog-admin.service.d.ts +171 -27
  304. package/dist/backend/services/catalog-admin.service.d.ts.map +1 -1
  305. package/dist/backend/services/catalog-admin.service.js +634 -315
  306. package/dist/backend/services/catalog-admin.service.js.map +1 -1
  307. package/dist/backend/services/catalog-attribute-read.service.d.ts +14 -0
  308. package/dist/backend/services/catalog-attribute-read.service.d.ts.map +1 -1
  309. package/dist/backend/services/catalog-attribute-read.service.js +7 -19
  310. package/dist/backend/services/catalog-attribute-read.service.js.map +1 -1
  311. package/dist/backend/services/catalog-bulk-import.service.d.ts +72 -3
  312. package/dist/backend/services/catalog-bulk-import.service.d.ts.map +1 -1
  313. package/dist/backend/services/catalog-bulk-import.service.js +212 -38
  314. package/dist/backend/services/catalog-bulk-import.service.js.map +1 -1
  315. package/dist/backend/services/catalog-bulk-update.service.d.ts +35 -5
  316. package/dist/backend/services/catalog-bulk-update.service.d.ts.map +1 -1
  317. package/dist/backend/services/catalog-bulk-update.service.js +123 -14
  318. package/dist/backend/services/catalog-bulk-update.service.js.map +1 -1
  319. package/dist/backend/services/catalog-org-price-decorator.d.ts +12 -25
  320. package/dist/backend/services/catalog-org-price-decorator.d.ts.map +1 -1
  321. package/dist/backend/services/catalog-org-price-decorator.js +48 -13
  322. package/dist/backend/services/catalog-org-price-decorator.js.map +1 -1
  323. package/dist/backend/services/catalog-product-filter.service.d.ts +16 -2
  324. package/dist/backend/services/catalog-product-filter.service.d.ts.map +1 -1
  325. package/dist/backend/services/catalog-product-filter.service.js +80 -3
  326. package/dist/backend/services/catalog-product-filter.service.js.map +1 -1
  327. package/dist/backend/services/catalog-product-read.service.d.ts +11 -1
  328. package/dist/backend/services/catalog-product-read.service.d.ts.map +1 -1
  329. package/dist/backend/services/catalog-product-read.service.js +40 -23
  330. package/dist/backend/services/catalog-product-read.service.js.map +1 -1
  331. package/dist/backend/services/catalog-query.service.d.ts +170 -42
  332. package/dist/backend/services/catalog-query.service.d.ts.map +1 -1
  333. package/dist/backend/services/catalog-query.service.js +797 -430
  334. package/dist/backend/services/catalog-query.service.js.map +1 -1
  335. package/dist/backend/services/catalog-quick-search.service.d.ts +18 -2
  336. package/dist/backend/services/catalog-quick-search.service.d.ts.map +1 -1
  337. package/dist/backend/services/catalog-quick-search.service.js +53 -21
  338. package/dist/backend/services/catalog-quick-search.service.js.map +1 -1
  339. package/dist/backend/services/catalog-write-ports.d.ts +16 -1
  340. package/dist/backend/services/catalog-write-ports.d.ts.map +1 -1
  341. package/dist/backend/services/catalog-write-ports.js +18 -0
  342. package/dist/backend/services/catalog-write-ports.js.map +1 -1
  343. package/dist/backend/services/category-admin.service.d.ts +12 -1
  344. package/dist/backend/services/category-admin.service.d.ts.map +1 -1
  345. package/dist/backend/services/category-admin.service.js +32 -3
  346. package/dist/backend/services/category-admin.service.js.map +1 -1
  347. package/dist/backend/services/channel-url-facts.d.ts +17 -0
  348. package/dist/backend/services/channel-url-facts.d.ts.map +1 -0
  349. package/dist/backend/services/channel-url-facts.js +20 -0
  350. package/dist/backend/services/channel-url-facts.js.map +1 -0
  351. package/dist/backend/services/content-attribute-rules.d.ts +49 -0
  352. package/dist/backend/services/content-attribute-rules.d.ts.map +1 -0
  353. package/dist/backend/services/content-attribute-rules.js +89 -0
  354. package/dist/backend/services/content-attribute-rules.js.map +1 -0
  355. package/dist/backend/services/effective-value.sql.d.ts +42 -0
  356. package/dist/backend/services/effective-value.sql.d.ts.map +1 -0
  357. package/dist/backend/services/effective-value.sql.js +61 -0
  358. package/dist/backend/services/effective-value.sql.js.map +1 -0
  359. package/dist/backend/services/gallery-scopes.d.ts +63 -0
  360. package/dist/backend/services/gallery-scopes.d.ts.map +1 -0
  361. package/dist/backend/services/gallery-scopes.js +158 -0
  362. package/dist/backend/services/gallery-scopes.js.map +1 -0
  363. package/dist/backend/services/gallery.service.d.ts +32 -4
  364. package/dist/backend/services/gallery.service.d.ts.map +1 -1
  365. package/dist/backend/services/gallery.service.js +182 -44
  366. package/dist/backend/services/gallery.service.js.map +1 -1
  367. package/dist/backend/services/grouped.service.d.ts.map +1 -1
  368. package/dist/backend/services/grouped.service.js +13 -1
  369. package/dist/backend/services/grouped.service.js.map +1 -1
  370. package/dist/backend/services/linkable-asset.d.ts +21 -0
  371. package/dist/backend/services/linkable-asset.d.ts.map +1 -0
  372. package/dist/backend/services/linkable-asset.js +31 -0
  373. package/dist/backend/services/linkable-asset.js.map +1 -0
  374. package/dist/backend/services/packaging-unit.service.d.ts.map +1 -1
  375. package/dist/backend/services/packaging-unit.service.js +73 -47
  376. package/dist/backend/services/packaging-unit.service.js.map +1 -1
  377. package/dist/backend/services/page-builder-content.d.ts +64 -0
  378. package/dist/backend/services/page-builder-content.d.ts.map +1 -0
  379. package/dist/backend/services/page-builder-content.js +113 -0
  380. package/dist/backend/services/page-builder-content.js.map +1 -0
  381. package/dist/backend/services/primary-asset-url.d.ts +12 -1
  382. package/dist/backend/services/primary-asset-url.d.ts.map +1 -1
  383. package/dist/backend/services/primary-asset-url.js +50 -14
  384. package/dist/backend/services/primary-asset-url.js.map +1 -1
  385. package/dist/backend/services/product-availability.service.d.ts +92 -0
  386. package/dist/backend/services/product-availability.service.d.ts.map +1 -0
  387. package/dist/backend/services/product-availability.service.js +260 -0
  388. package/dist/backend/services/product-availability.service.js.map +1 -0
  389. package/dist/backend/services/product-availability.sql.d.ts +71 -0
  390. package/dist/backend/services/product-availability.sql.d.ts.map +1 -0
  391. package/dist/backend/services/product-availability.sql.js +77 -0
  392. package/dist/backend/services/product-availability.sql.js.map +1 -0
  393. package/dist/backend/services/product-content.service.d.ts +62 -0
  394. package/dist/backend/services/product-content.service.d.ts.map +1 -0
  395. package/dist/backend/services/product-content.service.js +122 -0
  396. package/dist/backend/services/product-content.service.js.map +1 -0
  397. package/dist/backend/services/product-editor-preferences.service.d.ts +6 -0
  398. package/dist/backend/services/product-editor-preferences.service.d.ts.map +1 -1
  399. package/dist/backend/services/product-editor-preferences.service.js +12 -0
  400. package/dist/backend/services/product-editor-preferences.service.js.map +1 -1
  401. package/dist/backend/services/product-global-field-rules.d.ts +39 -0
  402. package/dist/backend/services/product-global-field-rules.d.ts.map +1 -0
  403. package/dist/backend/services/product-global-field-rules.js +84 -0
  404. package/dist/backend/services/product-global-field-rules.js.map +1 -0
  405. package/dist/backend/services/product-link.service.d.ts +10 -9
  406. package/dist/backend/services/product-link.service.d.ts.map +1 -1
  407. package/dist/backend/services/product-link.service.js +44 -36
  408. package/dist/backend/services/product-link.service.js.map +1 -1
  409. package/dist/backend/services/product-list-view-service.d.ts.map +1 -1
  410. package/dist/backend/services/product-list-view-service.js +5 -8
  411. package/dist/backend/services/product-list-view-service.js.map +1 -1
  412. package/dist/backend/services/product-page-revalidation.d.ts +60 -0
  413. package/dist/backend/services/product-page-revalidation.d.ts.map +1 -0
  414. package/dist/backend/services/product-page-revalidation.js +165 -0
  415. package/dist/backend/services/product-page-revalidation.js.map +1 -0
  416. package/dist/backend/services/product-scopes.service.d.ts +221 -0
  417. package/dist/backend/services/product-scopes.service.d.ts.map +1 -0
  418. package/dist/backend/services/product-scopes.service.js +692 -0
  419. package/dist/backend/services/product-scopes.service.js.map +1 -0
  420. package/dist/backend/services/product-summary-text.d.ts +8 -0
  421. package/dist/backend/services/product-summary-text.d.ts.map +1 -0
  422. package/dist/backend/services/product-summary-text.js +8 -0
  423. package/dist/backend/services/product-summary-text.js.map +1 -0
  424. package/dist/backend/services/product-value-resolver.service.d.ts +2 -2
  425. package/dist/backend/services/product-value-resolver.service.d.ts.map +1 -1
  426. package/dist/backend/services/product-value-resolver.service.js +4 -7
  427. package/dist/backend/services/product-value-resolver.service.js.map +1 -1
  428. package/dist/backend/services/publication-window-sweep.d.ts +131 -0
  429. package/dist/backend/services/publication-window-sweep.d.ts.map +1 -0
  430. package/dist/backend/services/publication-window-sweep.js +204 -0
  431. package/dist/backend/services/publication-window-sweep.js.map +1 -0
  432. package/dist/backend/services/scheduled-work-probe.d.ts +34 -0
  433. package/dist/backend/services/scheduled-work-probe.d.ts.map +1 -0
  434. package/dist/backend/services/scheduled-work-probe.js +30 -0
  435. package/dist/backend/services/scheduled-work-probe.js.map +1 -0
  436. package/dist/backend/services/scope-completeness.d.ts +107 -0
  437. package/dist/backend/services/scope-completeness.d.ts.map +1 -0
  438. package/dist/backend/services/scope-completeness.js +173 -0
  439. package/dist/backend/services/scope-completeness.js.map +1 -0
  440. package/dist/backend/services/scope-overview.service.d.ts +112 -0
  441. package/dist/backend/services/scope-overview.service.d.ts.map +1 -0
  442. package/dist/backend/services/scope-overview.service.js +329 -0
  443. package/dist/backend/services/scope-overview.service.js.map +1 -0
  444. package/dist/backend/services/scoped-store-adapters.d.ts +58 -0
  445. package/dist/backend/services/scoped-store-adapters.d.ts.map +1 -0
  446. package/dist/backend/services/scoped-store-adapters.js +92 -0
  447. package/dist/backend/services/scoped-store-adapters.js.map +1 -0
  448. package/dist/backend/services/scoped-values-global-only.d.ts +36 -0
  449. package/dist/backend/services/scoped-values-global-only.d.ts.map +1 -0
  450. package/dist/backend/services/scoped-values-global-only.js +92 -0
  451. package/dist/backend/services/scoped-values-global-only.js.map +1 -0
  452. package/dist/backend/services/scoped-values-import.d.ts +86 -0
  453. package/dist/backend/services/scoped-values-import.d.ts.map +1 -0
  454. package/dist/backend/services/scoped-values-import.js +320 -0
  455. package/dist/backend/services/scoped-values-import.js.map +1 -0
  456. package/dist/backend/services/scoped-values-read.service.d.ts +56 -0
  457. package/dist/backend/services/scoped-values-read.service.d.ts.map +1 -0
  458. package/dist/backend/services/scoped-values-read.service.js +289 -0
  459. package/dist/backend/services/scoped-values-read.service.js.map +1 -0
  460. package/dist/backend/services/scoped-values-save.service.d.ts +79 -0
  461. package/dist/backend/services/scoped-values-save.service.d.ts.map +1 -0
  462. package/dist/backend/services/scoped-values-save.service.js +675 -0
  463. package/dist/backend/services/scoped-values-save.service.js.map +1 -0
  464. package/dist/backend/services/scoped-values-state.d.ts +94 -0
  465. package/dist/backend/services/scoped-values-state.d.ts.map +1 -0
  466. package/dist/backend/services/scoped-values-state.js +159 -0
  467. package/dist/backend/services/scoped-values-state.js.map +1 -0
  468. package/dist/backend/services/scoped-values.service.d.ts +36 -0
  469. package/dist/backend/services/scoped-values.service.d.ts.map +1 -0
  470. package/dist/backend/services/scoped-values.service.js +92 -0
  471. package/dist/backend/services/scoped-values.service.js.map +1 -0
  472. package/dist/backend/services/sql-id-arrays.d.ts +16 -0
  473. package/dist/backend/services/sql-id-arrays.d.ts.map +1 -0
  474. package/dist/backend/services/sql-id-arrays.js +24 -0
  475. package/dist/backend/services/sql-id-arrays.js.map +1 -0
  476. package/dist/backend/services/storefront-value-overrides.d.ts +7 -8
  477. package/dist/backend/services/storefront-value-overrides.d.ts.map +1 -1
  478. package/dist/backend/services/storefront-value-overrides.js +11 -14
  479. package/dist/backend/services/storefront-value-overrides.js.map +1 -1
  480. package/dist/backend/services/url-key-resolution.service.d.ts +70 -0
  481. package/dist/backend/services/url-key-resolution.service.d.ts.map +1 -0
  482. package/dist/backend/services/url-key-resolution.service.js +179 -0
  483. package/dist/backend/services/url-key-resolution.service.js.map +1 -0
  484. package/dist/backend/services/url-key.service.d.ts +123 -0
  485. package/dist/backend/services/url-key.service.d.ts.map +1 -0
  486. package/dist/backend/services/url-key.service.js +566 -0
  487. package/dist/backend/services/url-key.service.js.map +1 -0
  488. package/dist/manifest.d.ts +9 -1
  489. package/dist/manifest.d.ts.map +1 -1
  490. package/dist/manifest.js +204 -10
  491. package/dist/manifest.js.map +1 -1
  492. package/dist/migrations/20261022T035133_catalog_product_scopes.d.ts +28 -0
  493. package/dist/migrations/20261022T035133_catalog_product_scopes.d.ts.map +1 -0
  494. package/dist/migrations/20261022T035133_catalog_product_scopes.js +92 -0
  495. package/dist/migrations/20261022T035133_catalog_product_scopes.js.map +1 -0
  496. package/dist/migrations/20261022T054223_catalog_product_url_keys.d.ts +32 -0
  497. package/dist/migrations/20261022T054223_catalog_product_url_keys.d.ts.map +1 -0
  498. package/dist/migrations/20261022T054223_catalog_product_url_keys.js +81 -0
  499. package/dist/migrations/20261022T054223_catalog_product_url_keys.js.map +1 -0
  500. package/dist/migrations/20261025T222634_catalog_product_status_drop_draft.d.ts +34 -0
  501. package/dist/migrations/20261025T222634_catalog_product_status_drop_draft.d.ts.map +1 -0
  502. package/dist/migrations/20261025T222634_catalog_product_status_drop_draft.js +57 -0
  503. package/dist/migrations/20261025T222634_catalog_product_status_drop_draft.js.map +1 -0
  504. package/dist/migrations/20261026T033453_catalog_product_media_scopes.d.ts +26 -0
  505. package/dist/migrations/20261026T033453_catalog_product_media_scopes.d.ts.map +1 -0
  506. package/dist/migrations/20261026T033453_catalog_product_media_scopes.js +54 -0
  507. package/dist/migrations/20261026T033453_catalog_product_media_scopes.js.map +1 -0
  508. package/dist/migrations/20261026T084533_catalog_attachment_packaging_translations.d.ts +27 -0
  509. package/dist/migrations/20261026T084533_catalog_attachment_packaging_translations.d.ts.map +1 -0
  510. package/dist/migrations/20261026T084533_catalog_attachment_packaging_translations.js +45 -0
  511. package/dist/migrations/20261026T084533_catalog_attachment_packaging_translations.js.map +1 -0
  512. package/dist/migrations/20261030T113855_catalog_scope_model_texts.d.ts +36 -0
  513. package/dist/migrations/20261030T113855_catalog_scope_model_texts.d.ts.map +1 -0
  514. package/dist/migrations/20261030T113855_catalog_scope_model_texts.js +225 -0
  515. package/dist/migrations/20261030T113855_catalog_scope_model_texts.js.map +1 -0
  516. package/dist/migrations/20261030T113859_catalog_scope_model_order_rules.d.ts +18 -0
  517. package/dist/migrations/20261030T113859_catalog_scope_model_order_rules.d.ts.map +1 -0
  518. package/dist/migrations/20261030T113859_catalog_scope_model_order_rules.js +39 -0
  519. package/dist/migrations/20261030T113859_catalog_scope_model_order_rules.js.map +1 -0
  520. package/dist/migrations/20261030T113904_catalog_scope_model_url_keys.d.ts +6 -0
  521. package/dist/migrations/20261030T113904_catalog_scope_model_url_keys.d.ts.map +1 -0
  522. package/dist/migrations/20261030T113904_catalog_scope_model_url_keys.js +119 -0
  523. package/dist/migrations/20261030T113904_catalog_scope_model_url_keys.js.map +1 -0
  524. package/dist/migrations/20261030T113908_catalog_scope_model_media.d.ts +6 -0
  525. package/dist/migrations/20261030T113908_catalog_scope_model_media.d.ts.map +1 -0
  526. package/dist/migrations/20261030T113908_catalog_scope_model_media.js +185 -0
  527. package/dist/migrations/20261030T113908_catalog_scope_model_media.js.map +1 -0
  528. package/dist/migrations/20261104T121504_catalog_product_content_values.d.ts +36 -0
  529. package/dist/migrations/20261104T121504_catalog_product_content_values.d.ts.map +1 -0
  530. package/dist/migrations/20261104T121504_catalog_product_content_values.js +53 -0
  531. package/dist/migrations/20261104T121504_catalog_product_content_values.js.map +1 -0
  532. package/dist/migrations/20261107T093126_catalog_sku_unique_among_live.d.ts +33 -0
  533. package/dist/migrations/20261107T093126_catalog_sku_unique_among_live.d.ts.map +1 -0
  534. package/dist/migrations/20261107T093126_catalog_sku_unique_among_live.js +58 -0
  535. package/dist/migrations/20261107T093126_catalog_sku_unique_among_live.js.map +1 -0
  536. package/dist/migrations/20261107T120008_catalog_product_created_at_milliseconds.d.ts +36 -0
  537. package/dist/migrations/20261107T120008_catalog_product_created_at_milliseconds.d.ts.map +1 -0
  538. package/dist/migrations/20261107T120008_catalog_product_created_at_milliseconds.js +40 -0
  539. package/dist/migrations/20261107T120008_catalog_product_created_at_milliseconds.js.map +1 -0
  540. package/dist/migrations/index.d.ts +13 -1
  541. package/dist/migrations/index.d.ts.map +1 -1
  542. package/dist/migrations/index.js +25 -1
  543. package/dist/migrations/index.js.map +1 -1
  544. package/docs/catalog/attachments.md +60 -8
  545. package/docs/catalog/attribute-sets.md +2 -2
  546. package/docs/catalog/attributes.md +68 -8
  547. package/docs/catalog/category-content.md +3 -0
  548. package/docs/catalog/composite-products.md +2 -2
  549. package/docs/catalog/editing-a-product-at-a-scope.md +95 -0
  550. package/docs/catalog/gallery-and-labels.md +68 -8
  551. package/docs/catalog/packaging-units.md +56 -10
  552. package/docs/catalog/per-channel-per-language-overrides.md +68 -237
  553. package/docs/catalog/product-content.md +180 -0
  554. package/docs/catalog/product-links.md +2 -2
  555. package/docs/catalog/url-keys-and-redirects.md +142 -0
  556. package/docs/catalog.md +241 -20
  557. package/i18n/en.json +977 -123
  558. package/i18n/pl.json +976 -122
  559. package/package.json +12 -12
  560. package/dist/admin/components/ProductScopeEditor.d.ts +0 -94
  561. package/dist/admin/components/ProductScopeEditor.d.ts.map +0 -1
  562. package/dist/admin/components/ProductScopeEditor.js +0 -395
  563. package/dist/admin/components/ProductScopeEditor.js.map +0 -1
  564. package/dist/backend/services/product-overrides.service.d.ts +0 -77
  565. package/dist/backend/services/product-overrides.service.d.ts.map +0 -1
  566. package/dist/backend/services/product-overrides.service.js +0 -204
  567. package/dist/backend/services/product-overrides.service.js.map +0 -1
  568. package/dist/backend/services/product-scope-context.service.d.ts +0 -36
  569. package/dist/backend/services/product-scope-context.service.d.ts.map +0 -1
  570. package/dist/backend/services/product-scope-context.service.js +0 -106
  571. package/dist/backend/services/product-scope-context.service.js.map +0 -1
@@ -1,357 +1,898 @@
1
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
- import { forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState, } from 'react';
3
- import { useNavigate, useParams } from 'react-router-dom';
4
- import { Trash2, ChevronLeft, Copy, Eye, FileText as FileTextIcon, Globe, GripVertical, Image as ImageIcon, CircleDollarSign, Layers, Link as LinkIcon, Paperclip, Save, SlidersHorizontal, Store as StoreIcon, Warehouse as WarehouseIcon, } from 'lucide-react';
5
- import { ApiError, apiClient, useUnsavedChangesPrompt, toAbsoluteAssetUrl, cn } from '@endora-commerce/admin-kit/lib';
6
- import { Alert, AlertDescription, Button, Card, CardContent, CardHeader, CardTitle, Input, Label, Select, Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@endora-commerce/admin-kit/ui';
7
- import { AssetPicker, StickyFormActions, TouchReorderButtons, CategoryTreePicker, ProductPicker } from '@endora-commerce/admin-kit/components';
8
- import { useTranslation } from '@endora-commerce/admin-kit/i18n';
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useCallback, useContext, useEffect, useMemo, useReducer, useRef, useState, } from 'react';
3
+ import { useNavigate, useParams, useSearchParams } from 'react-router-dom';
4
+ import { Archive, ArchiveRestore, ChevronDown, ChevronLeft, Copy, Lock, RotateCw, Save, Trash2 } from 'lucide-react';
5
+ import { ERROR_CODES, } from '@endora-commerce/contracts';
6
+ import { ApiError, apiClient, useAuth, useUnsavedChangesPrompt, cn } from '@endora-commerce/admin-kit/lib';
7
+ import { Alert, AlertDescription, Button, Card, CardContent, CardHeader, CardTitle, DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger, Input, Label, Select, Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from '@endora-commerce/admin-kit/ui';
8
+ import { ModalDialog, ProductPicker, StickyFormActions } from '@endora-commerce/admin-kit/components';
9
+ import { AppLanguageContext, useTranslation } from '@endora-commerce/admin-kit/i18n';
9
10
  import { AdminZone, useAdminZone } from '@endora-commerce/admin-kit/zones';
10
11
  import { ProductInventoryTab } from '../components/ProductInventoryTab.js';
11
12
  import { PackagingUnitsEditor } from '../components/PackagingUnitsEditor.js';
12
13
  import { ProductOrderRulesCard } from '../components/ProductOrderRulesCard.js';
13
14
  import { ProductAttributesTab } from '../components/ProductAttributesTab.js';
14
- import { ProductScopeEditor, } from '../components/ProductScopeEditor.js';
15
- const LOCALES = ['en-US', 'pl-PL'];
16
- const PRODUCT_TYPES = [
17
- 'simple',
18
- 'configurable',
19
- 'grouped',
20
- 'bundle',
21
- 'virtual',
15
+ import { ProductScopeOverview } from '../components/ProductScopeOverview.js';
16
+ import { GallerySection } from '../components/ProductGallerySection.js';
17
+ import { AttachmentsSection } from '../components/ProductAttachmentsSection.js';
18
+ import { ArchivedPill, ProductStatusPill } from '../components/ProductStatusPills.js';
19
+ import { ProductScopeBar } from '../components/ProductScopeBar.js';
20
+ import { DetailsTab } from '../components/editor/DetailsTab.js';
21
+ import { EditorField, ProductEditorContextProvider, fieldDomId } from '../components/editor/editor-context.js';
22
+ import { ImmediateBadge, SectionHeading } from '../components/editor/ImmediateBadge.js';
23
+ import { TextControl } from '../components/editor/scoped-controls.js';
24
+ import { useConfirmRemoval } from '../components/editor/confirm-removal.js';
25
+ import { ProductCreateForm } from './ProductCreateForm.js';
26
+ import { describeIncompletePair } from '../lib/product-scopes-api.js';
27
+ import { takeoverDetails, urlKeyErrorMessage, describeKeyInLanguage } from '../lib/product-url-keys-api.js';
28
+ import { initialEditorState, fieldViewAt, scopeToRequest, scopedEditorReducer, stagedToChanges, } from '../lib/scoped-editor-store.js';
29
+ import { getEditorPreference, getScopedValues, putEditorPreference, saveScopedValues } from '../lib/scoped-values-api.js';
30
+ import { channelName, languageName, parentScope, sameScope, scopeFromSearch, scopeInWords, scopeKey, scopeShortWords, searchWithScope, widerScope, } from '../lib/editor-scope.js';
31
+ /**
32
+ * The product editor (feature 174, US5–US7; `contracts/editor-ui.md`).
33
+ *
34
+ * One scope switcher sets the scope of the whole editor; the scope lives in the URL
35
+ * (`?scope=global|channel|cl&channel=…&language=…&tab=…&field=…`). The editor reads the scope in
36
+ * one request (`GET …/scoped-values`), stages every change of that scope in one store and writes
37
+ * them with one Save (`PUT …/scoped-values`) — the product row's global-only fields at Global
38
+ * included. Structural operations (variants, images, attachments, packaging units, links, prices,
39
+ * membership, stock) run at once as their own audited Commands, carry an "Applies immediately"
40
+ * badge, and neither stage nor clear the staged changes.
41
+ *
42
+ * Switching scope (the switcher, an "Edit at …" jump, browser Back) with staged changes asks
43
+ * Save / Discard / Stay first.
44
+ */
45
+ const TAB_IDS = [
46
+ 'details',
47
+ 'attributes',
48
+ 'pricing',
49
+ 'variants',
50
+ 'composite',
51
+ 'media',
52
+ 'inventory',
53
+ 'attachments',
54
+ 'links',
55
+ 'channels',
56
+ 'scopes',
57
+ 'seo',
22
58
  ];
23
- const VISIBILITIES = ['public', 'logged_in_only', 'organization_restricted'];
24
- const STATUSES = ['draft', 'active', 'inactive'];
59
+ /** Tabs whose content is the same at every scope (§6): outside Global they show a notice. */
60
+ const GLOBAL_ONLY_TABS = new Set(['pricing', 'variants', 'composite', 'links', 'channels']);
61
+ const GLOBAL = { level: 'global' };
62
+ const PRODUCT_PATH = (id) => `/api/v1/admin/catalog/products/${encodeURIComponent(id)}`;
63
+ export function ProductEditor() {
64
+ const params = useParams();
65
+ if (params.id === 'new')
66
+ return _jsx(ProductCreateForm, {});
67
+ if (!params.id)
68
+ return null;
69
+ return _jsx(ScopedProductEditor, { productId: params.id }, params.id);
70
+ }
71
+ /** A field whose `empty` the server refuses outside `view.required` (data-model §9, R21). */
72
+ function refusesEmpty(path, state) {
73
+ if (path.startsWith('product:'))
74
+ return true;
75
+ if (path === 'status' || path === 'returnable' || path === 'audience')
76
+ return true;
77
+ if (/^(gallery|attachment):[^:]+:hidden$/.test(path))
78
+ return true;
79
+ if (state.scope.level === 'global' && (/^attachment:[^:]+:name$/.test(path) || /^packagingUnit:[^:]+:name$/.test(path)))
80
+ return true;
81
+ if (path.startsWith('attribute:') && state.data) {
82
+ const attr = state.data.attributes.find((a) => `attribute:${a.key}` === path);
83
+ if (attr && ['enum', 'select', 'boolean'].includes(attr.valueType))
84
+ return true;
85
+ }
86
+ return false;
87
+ }
88
+ function errorOf(err) {
89
+ if (!(err instanceof ApiError))
90
+ return null;
91
+ const e = err.envelope.error;
92
+ return { status: err.status, code: e.code, message: e.message, ...(e.details ? { details: e.details } : {}) };
93
+ }
94
+ /** The tab a field lives on; a scope-map link without a field opens Details. */
25
95
  /**
26
- * Order-insensitive JSON snapshot of the editable form fields, used to detect
27
- * unsaved changes (object keys + array members are sorted so re-ordering alone
28
- * never reads as a change).
96
+ * A translated lead, then the server's sentence as detail (final design review): the envelope's
97
+ * message is in the request language only when the backend has that code's translation, so it is
98
+ * never the whole of what the operator reads.
29
99
  */
30
- function stableSnapshot(values) {
31
- return JSON.stringify(values, (_key, value) => {
32
- if (Array.isArray(value))
33
- return [...value].sort();
34
- if (value && typeof value === 'object') {
35
- return Object.fromEntries(Object.entries(value).sort(([a], [b]) => a.localeCompare(b)));
36
- }
37
- return value;
38
- });
100
+ function withServerDetail(lead, err) {
101
+ const detail = errorOf(err)?.message;
102
+ return detail && detail !== lead ? `${lead} ${detail}` : lead;
39
103
  }
40
- export function ProductEditor() {
104
+ function tabOfField(field) {
105
+ return field?.startsWith('attribute:') ? 'attributes' : 'details';
106
+ }
107
+ function familyOfPath(path) {
108
+ if (path.startsWith('gallery'))
109
+ return 'gallery';
110
+ if (path.startsWith('attachment:'))
111
+ return 'attachments';
112
+ if (path.startsWith('packagingUnit:'))
113
+ return 'packagingUnits';
114
+ return null;
115
+ }
116
+ function ScopedProductEditor({ productId }) {
41
117
  const t = useTranslation('catalog');
42
- const params = useParams();
118
+ // The admin's language names languages (`Intl.DisplayNames`); a screen mounted without the
119
+ // shell's provider (a test) falls back to English.
120
+ const adminLanguage = useContext(AppLanguageContext)?.language ?? 'en';
43
121
  const navigate = useNavigate();
44
- const isNew = params.id === 'new';
45
- const id = isNew ? null : params.id ?? null;
46
- // Feature 091 / P7a, Z15 — the Channels tab's button is a count of its own
47
- // body. Declared here rather than beside the tab table because the table is
48
- // built below an early return and a hook may not be.
49
- const channelContributions = useAdminZone('product.editor.channels', {
50
- productId: id ?? '',
122
+ const [searchParams, setSearchParams] = useSearchParams();
123
+ const { hasPermission } = useAuth();
124
+ const canWrite = hasPermission('catalog:write');
125
+ const readOnly = !canWrite;
126
+ const channelContributions = useAdminZone('product.editor.channels', { productId });
127
+ const seoContributions = useAdminZone('product.editor.seo', {
128
+ productId,
129
+ scope: GLOBAL,
130
+ scopeLabel: '',
131
+ parentScopeLabel: null,
132
+ view: null,
133
+ staged: new Map(),
134
+ onStage: () => undefined,
135
+ readOnly: true,
136
+ errors: {},
137
+ version: null,
51
138
  });
52
- const [loading, setLoading] = useState(!isNew);
53
- const [error, setError] = useState(null);
139
+ const urlScope = scopeFromSearch(searchParams);
140
+ const urlKey = urlScope ? scopeKey(urlScope) : '';
141
+ const [state, dispatch] = useReducer(scopedEditorReducer, urlScope ?? GLOBAL, initialEditorState);
142
+ const stateRef = useRef(state);
143
+ stateRef.current = state;
144
+ /** The scope the last load was started for; the URL effect compares against it. */
145
+ const loadedKeyRef = useRef(null);
146
+ const requestRef = useRef(0);
147
+ /** Set when the editor itself moves the URL after the guard has been passed. */
148
+ const skipGuardRef = useRef(false);
149
+ const pendingNoteRef = useRef(null);
150
+ const prefTimerRef = useRef(null);
151
+ /** The last valid-scope list, kept while a scope loads so the switcher stays usable. */
152
+ const validRef = useRef(null);
153
+ const [announcement, setAnnouncement] = useState('');
154
+ const [loadError, setLoadError] = useState(null);
155
+ const [formError, setFormError] = useState(null);
156
+ const [gateWarning, setGateWarning] = useState(null);
54
157
  const [info, setInfo] = useState(null);
158
+ const [guard, setGuard] = useState(null);
159
+ const [saving, setSaving] = useState(false);
160
+ const [takeovers, setTakeovers] = useState(null);
161
+ const [archivedOverride, setArchivedOverride] = useState(undefined);
162
+ const [archiveDialog, setArchiveDialog] = useState(null);
163
+ const [archiving, setArchiving] = useState(false);
164
+ const [archiveError, setArchiveError] = useState(null);
165
+ const [duplicating, setDuplicating] = useState(false);
166
+ const [wholeProductDialog, setWholeProductDialog] = useState(null);
167
+ const [wholeProductError, setWholeProductError] = useState(null);
168
+ const [deleting, setDeleting] = useState(false);
55
169
  const [categories, setCategories] = useState([]);
56
- const [sku, setSku] = useState('');
57
- const [type, setType] = useState('simple');
58
- const [status, setStatus] = useState('draft');
59
- const [visibility, setVisibility] = useState('public');
60
- const [name, setName] = useState({ 'en-US': '', 'pl-PL': '' });
61
- const [description, setDescription] = useState({
62
- 'en-US': '',
63
- 'pl-PL': '',
64
- });
65
- const [categoryIds, setCategoryIds] = useState([]);
66
- const [activeTab, setActiveTab] = useState('details');
67
- // Feature 002 (T034) — Attribute Set selector
170
+ const [categoriesLoading, setCategoriesLoading] = useState(true);
68
171
  const [attributeSets, setAttributeSets] = useState([]);
69
- const [attributeSetId, setAttributeSetId] = useState('');
70
- // Editable attribute values keyed by attribute `key` (Attributes tab).
71
- const [attrValues, setAttrValues] = useState({});
72
- // Feature 023 — imperative handle on the scope-editor so the page Save
73
- // can flush every pending channel-scoped override in a single PATCH.
74
- const scopeEditorRef = useRef(null);
75
- // Media tab — page-Save flushes staged gallery label/order edits via this
76
- // imperative handle (mirrors the scope-editor pattern above).
77
- const galleryRef = useRef(null);
78
- // Unsaved-changes guard — a stable snapshot of the editable fields is taken
79
- // on load (and re-taken after each save via refresh()); the form is "dirty"
80
- // whenever the live values diverge from it.
81
- const initialSnapshotRef = useRef('');
82
- const currentSnapshot = stableSnapshot({
83
- sku,
84
- type,
85
- status,
86
- visibility,
87
- name,
88
- description,
89
- categoryIds,
90
- attributeSetId,
91
- attrValues,
92
- });
93
- const dirty = !loading &&
94
- initialSnapshotRef.current !== '' &&
95
- currentSnapshot !== initialSnapshotRef.current;
96
- useUnsavedChangesPrompt(dirty);
97
- const refresh = useCallback(async () => {
98
- setLoading(true);
99
- setError(null);
100
- try {
101
- const [cats, sets] = await Promise.all([
102
- apiClient.get('/api/v1/admin/catalog/categories'),
103
- apiClient.get('/api/v1/admin/catalog/attribute-sets'),
104
- ]);
105
- setCategories(cats.data);
106
- setAttributeSets(sets.data);
107
- // Pick the system Default as the initial selection for new Products.
108
- const defaultSet = sets.data.find((s) => s.code === 'default');
109
- if (isNew && defaultSet)
110
- setAttributeSetId(defaultSet.id);
111
- if (isNew) {
112
- // Baseline for a brand-new product matches the useState defaults.
113
- initialSnapshotRef.current = stableSnapshot({
114
- sku: '',
115
- type: 'simple',
116
- status: 'draft',
117
- visibility: 'public',
118
- name: { 'en-US': '', 'pl-PL': '' },
119
- description: { 'en-US': '', 'pl-PL': '' },
120
- categoryIds: [],
121
- attributeSetId: defaultSet?.id ?? '',
122
- attrValues: {},
123
- });
172
+ if (state.data)
173
+ validRef.current = state.data.validScopes;
174
+ const valid = state.data?.validScopes ?? validRef.current ?? { channels: [] };
175
+ const words = (scope, v = valid) => scopeInWords(scope, v, t, adminLanguage);
176
+ const scopeLabel = scopeShortWords(state.scope, valid, t, adminLanguage);
177
+ const parentLabel = scopeShortWords(parentScope(state.scope), valid, t, adminLanguage);
178
+ /** `key.one|few|many|other` by the admin language's plural rules (PL needs few / many). */
179
+ const plural = (key, count, params = {}) => t(`${key}.${new Intl.PluralRules(adminLanguage).select(count)}`, { count: String(count), ...params });
180
+ // The live region is cleared first, so the same sentence twice is announced twice (WCAG 4.1.3).
181
+ const announceTimerRef = useRef(null);
182
+ const announce = useCallback((text) => {
183
+ setAnnouncement('');
184
+ if (announceTimerRef.current)
185
+ clearTimeout(announceTimerRef.current);
186
+ announceTimerRef.current = setTimeout(() => setAnnouncement(text), 50);
187
+ }, []);
188
+ useEffect(() => () => {
189
+ if (announceTimerRef.current)
190
+ clearTimeout(announceTimerRef.current);
191
+ }, []);
192
+ /** The scope the last successful read opened; a different one is announced once its data is in. */
193
+ const announcedScopeRef = useRef(null);
194
+ // The reference lists the Details tab picks from (global, read once). A failed read is an
195
+ // error with a retry, never an empty list (final design review): "No categories" would be a lie.
196
+ const [referenceError, setReferenceError] = useState(false);
197
+ const referenceRequest = useRef(0);
198
+ const loadReference = useCallback(() => {
199
+ const request = ++referenceRequest.current;
200
+ setCategoriesLoading(true);
201
+ setReferenceError(false);
202
+ void Promise.allSettled([
203
+ apiClient.get('/api/v1/admin/catalog/categories'),
204
+ apiClient.get('/api/v1/admin/catalog/attribute-sets'),
205
+ ]).then(([cats, sets]) => {
206
+ if (request !== referenceRequest.current)
207
+ return;
208
+ if (cats.status === 'fulfilled')
209
+ setCategories(cats.value.data ?? []);
210
+ if (sets.status === 'fulfilled')
211
+ setAttributeSets(sets.value.data ?? []);
212
+ setReferenceError(cats.status === 'rejected' || sets.status === 'rejected');
213
+ setCategoriesLoading(false);
214
+ });
215
+ }, []);
216
+ useEffect(() => {
217
+ loadReference();
218
+ return () => {
219
+ referenceRequest.current += 1;
220
+ };
221
+ }, [loadReference]);
222
+ // --- Loading a scope --------------------------------------------------------------------
223
+ const load = useCallback(async (requested, options = {}) => {
224
+ const request = ++requestRef.current;
225
+ loadedKeyRef.current = scopeKey(requested);
226
+ dispatch({ type: 'switching', scope: requested });
227
+ setLoadError(null);
228
+ setFormError(null);
229
+ setGateWarning(null);
230
+ let target = requested;
231
+ let reason = null;
232
+ for (;;) {
233
+ try {
234
+ const res = await getScopedValues(productId, target);
235
+ if (request !== requestRef.current)
236
+ return;
237
+ dispatch({ type: 'loaded', data: res.data });
238
+ const opened = res.data.scope;
239
+ if (!sameScope(opened, requested)) {
240
+ loadedKeyRef.current = scopeKey(opened);
241
+ setSearchParams((prev) => searchWithScope(prev, opened), { replace: true });
242
+ }
243
+ const openedWords = scopeInWords(opened, res.data.validScopes, t, adminLanguage);
244
+ const note = reason ? t('productEditor.scope.openedAt', { scope: openedWords, reason }) : (options.note ?? null);
245
+ // After the data is in (not when the switch starts): the scope, Global included.
246
+ const previous = announcedScopeRef.current;
247
+ announcedScopeRef.current = scopeKey(opened);
248
+ const switched = previous !== null && previous !== scopeKey(opened);
249
+ const where = switched
250
+ ? opened.level === 'global'
251
+ ? t('productEditor.scope.loadedAt', { scope: openedWords })
252
+ : t('productEditor.scope.banner', { scope: openedWords })
253
+ : null;
254
+ const spoken = [note, where].filter(Boolean).join(' ');
255
+ if (spoken)
256
+ announce(spoken);
257
+ if (prefTimerRef.current)
258
+ clearTimeout(prefTimerRef.current);
259
+ prefTimerRef.current = setTimeout(() => void putEditorPreference(productId, opened), 500);
260
+ if (options.field) {
261
+ const field = options.field;
262
+ setTimeout(() => document.getElementById(fieldDomId(field))?.focus(), 0);
263
+ }
264
+ return;
124
265
  }
125
- if (id) {
126
- const res = await apiClient.get(`/api/v1/admin/catalog/products/${id}`);
127
- const p = res.data;
128
- setSku(p.sku);
129
- setType(p.type);
130
- setStatus(p.status);
131
- setVisibility(p.visibility);
132
- const loadedName = {
133
- 'en-US': p.name['en-US'] ?? '',
134
- 'pl-PL': p.name['pl-PL'] ?? '',
135
- };
136
- setName(loadedName);
137
- const loadedDescription = {
138
- 'en-US': p.description['en-US'] ?? '',
139
- 'pl-PL': p.description['pl-PL'] ?? '',
140
- };
141
- setDescription(loadedDescription);
142
- setAttrValues(p.attributeValues ?? {});
143
- setAttributeSetId(p.attributeSetId);
144
- setCategoryIds(p.categoryIds ?? []);
145
- // Capture the loaded state as the clean baseline for dirty-tracking.
146
- initialSnapshotRef.current = stableSnapshot({
147
- sku: p.sku,
148
- type: p.type,
149
- status: p.status,
150
- visibility: p.visibility,
151
- name: loadedName,
152
- description: loadedDescription,
153
- categoryIds: p.categoryIds ?? [],
154
- attributeSetId: p.attributeSetId,
155
- attrValues: p.attributeValues ?? {},
156
- });
266
+ catch (err) {
267
+ if (request !== requestRef.current)
268
+ return;
269
+ const e = errorOf(err);
270
+ const wider = widerScope(target);
271
+ if (e?.code === ERROR_CODES.SCOPE_INVALID && wider) {
272
+ reason ??=
273
+ e.details?.['reason'] === 'language_not_offered'
274
+ ? t('productEditor.scope.reason.languageNotOffered')
275
+ : t('productEditor.scope.reason.notMember');
276
+ target = wider;
277
+ continue;
278
+ }
279
+ setLoadError(e?.message ?? t('productEditor.error.load'));
280
+ return;
157
281
  }
158
282
  }
159
- catch (err) {
160
- setError(err instanceof ApiError ? err.envelope.error.message : 'Failed to load.');
161
- }
162
- finally {
163
- setLoading(false);
283
+ }, [productId, setSearchParams, t, adminLanguage, announce]);
284
+ // No scope in the URL: the preference seeds it (Global when there is none), replacing the entry.
285
+ useEffect(() => {
286
+ if (urlScope)
287
+ return undefined;
288
+ let cancelled = false;
289
+ void getEditorPreference(productId)
290
+ .catch(() => null)
291
+ .then((pref) => {
292
+ if (!cancelled)
293
+ setSearchParams((prev) => searchWithScope(prev, pref ?? GLOBAL), { replace: true });
294
+ });
295
+ return () => {
296
+ cancelled = true;
297
+ };
298
+ // eslint-disable-next-line react-hooks/exhaustive-deps
299
+ }, [urlKey, productId]);
300
+ // The URL is the truth: a scope it names that is not the loaded one is loaded — through the
301
+ // switch guard when there are staged changes (browser Back / Forward).
302
+ useEffect(() => {
303
+ if (!urlScope)
304
+ return;
305
+ if (scopeKey(urlScope) === loadedKeyRef.current)
306
+ return;
307
+ if (!skipGuardRef.current && loadedKeyRef.current !== null && stateRef.current.staged.size > 0) {
308
+ setGuard({ kind: 'url', target: urlScope });
309
+ return;
164
310
  }
165
- }, [id, isNew]);
311
+ skipGuardRef.current = false;
312
+ const note = pendingNoteRef.current;
313
+ pendingNoteRef.current = null;
314
+ void load(urlScope, { note, field: searchParams.get('field') });
315
+ // eslint-disable-next-line react-hooks/exhaustive-deps
316
+ }, [urlKey]);
317
+ useEffect(() => () => {
318
+ if (prefTimerRef.current)
319
+ clearTimeout(prefTimerRef.current);
320
+ }, []);
321
+ // A staged change of a subject an immediate action removed is dropped and said (§3).
166
322
  useEffect(() => {
167
- void refresh();
168
- }, [refresh]);
169
- const handleSave = useCallback(async (e) => {
170
- e.preventDefault();
171
- setError(null);
172
- setInfo(null);
173
- const trimmedName = {};
174
- const trimmedDescription = {};
175
- for (const l of LOCALES) {
176
- if (name[l])
177
- trimmedName[l] = name[l];
178
- if (description[l])
179
- trimmedDescription[l] = description[l];
180
- }
181
- if (Object.keys(trimmedName).length === 0) {
182
- setError('At least one locale name is required.');
323
+ if (state.dropped.length === 0)
324
+ return;
325
+ const family = familyOfPath(state.dropped[0]);
326
+ announce(t(family === 'attachments'
327
+ ? 'productEditor.immediate.droppedAttachment'
328
+ : family === 'packagingUnits'
329
+ ? 'productEditor.immediate.droppedPackagingUnit'
330
+ : 'productEditor.immediate.droppedImage'));
331
+ }, [state.dropped, t, announce]);
332
+ useUnsavedChangesPrompt(state.staged.size > 0);
333
+ // "Saved N changes" belongs to the last save: a new staged edit clears it.
334
+ useEffect(() => {
335
+ if (state.staged.size > 0)
336
+ setInfo(null);
337
+ }, [state.staged.size]);
338
+ const go = useCallback((next, note, field, tab) => {
339
+ pendingNoteRef.current = note ?? null;
340
+ skipGuardRef.current = true;
341
+ setSearchParams((prev) => {
342
+ const sp = searchWithScope(prev, next);
343
+ sp.delete('field');
344
+ if (field)
345
+ sp.set('field', field);
346
+ if (tab)
347
+ sp.set('tab', tab);
348
+ return sp;
349
+ });
350
+ }, [setSearchParams]);
351
+ const requestScope = useCallback((next, note, field, tab) => {
352
+ if (sameScope(next, stateRef.current.scope)) {
353
+ if (tab) {
354
+ setSearchParams((prev) => {
355
+ const sp = new URLSearchParams(prev);
356
+ sp.set('tab', tab);
357
+ sp.delete('field');
358
+ return sp;
359
+ });
360
+ }
361
+ if (field)
362
+ setTimeout(() => document.getElementById(fieldDomId(field))?.focus(), 0);
183
363
  return;
184
364
  }
185
- // The Attributes-tab edits. A product has no price of its own: prices
186
- // are set in price books (feature 160), so nothing else is added here.
187
- const attributeValues = { ...attrValues };
365
+ if (stateRef.current.staged.size > 0) {
366
+ setGuard({ kind: 'switch', target: next, ...(note ? { note } : {}), ...(field ? { field } : {}), ...(tab ? { tab } : {}) });
367
+ return;
368
+ }
369
+ go(next, note, field, tab);
370
+ }, [go, setSearchParams]);
371
+ const refreshFamily = useCallback(async (family) => {
372
+ const scope = stateRef.current.scope;
188
373
  try {
189
- if (isNew) {
190
- const res = await apiClient.post('/api/v1/admin/catalog/products', {
191
- sku,
192
- type,
193
- name: trimmedName,
194
- description: trimmedDescription,
195
- categoryIds,
196
- attributeValues,
197
- visibility,
198
- ...(attributeSetId ? { attributeSetId } : {}),
199
- });
200
- navigate(`/catalog/products/${res.data.id}`);
374
+ const res = await getScopedValues(productId, scope);
375
+ if (sameScope(stateRef.current.scope, scope))
376
+ dispatch({ type: 'refreshFamily', family, data: res.data });
377
+ }
378
+ catch {
379
+ // The structural change is done; the list refreshes on the next read.
380
+ }
381
+ }, [productId]);
382
+ // The copy (§8) bumped the version: the next Save sends it; staged cells stay (R7).
383
+ const afterCopy = useCallback((version, fieldLabel, count) => {
384
+ dispatch({ type: 'version', version });
385
+ announce(plural('productEditor.copy.done', count, { field: fieldLabel }));
386
+ },
387
+ // `plural` reads `t` and the admin language only.
388
+ // eslint-disable-next-line react-hooks/exhaustive-deps
389
+ [announce, t, adminLanguage]);
390
+ // --- Save --------------------------------------------------------------------------------
391
+ const save = useCallback(async (confirmTakeover) => {
392
+ const s = stateRef.current;
393
+ if (!s.data || s.version === null || s.staged.size === 0 || readOnly)
394
+ return false;
395
+ const parent = scopeShortWords(parentScope(s.scope), s.data.validScopes, t, adminLanguage);
396
+ const errors = {};
397
+ for (const [path, op] of s.staged) {
398
+ if (op.op !== 'empty')
399
+ continue;
400
+ if (fieldViewAt(s.data, path)?.required || refusesEmpty(path, s)) {
401
+ errors[path] =
402
+ s.scope.level === 'global'
403
+ ? t('productEditor.save.error.requiredEmpty')
404
+ : t('productEditor.save.error.requiredEmptyScoped', { scope: parent });
405
+ }
406
+ }
407
+ if (Object.keys(errors).length > 0) {
408
+ dispatch({ type: 'errors', errors });
409
+ setFormError({ kind: 'validation', count: Object.keys(errors).length });
410
+ const first = Object.keys(errors)[0];
411
+ setTimeout(() => document.getElementById(fieldDomId(first))?.focus(), 0);
412
+ return false;
413
+ }
414
+ setSaving(true);
415
+ setFormError(null);
416
+ setGateWarning(null);
417
+ setInfo(null);
418
+ try {
419
+ const changes = stagedToChanges(s.staged);
420
+ const res = await saveScopedValues(productId, {
421
+ scope: scopeToRequest(s.scope),
422
+ version: s.version,
423
+ changes: confirmTakeover ? { ...changes, confirmTakeover } : changes,
424
+ });
425
+ const count = s.staged.size;
426
+ dispatch({ type: 'loaded', data: res.data });
427
+ setTakeovers(null);
428
+ const completeness = (res.warnings ?? []).filter((w) => w.kind === 'completeness');
429
+ if (completeness.length > 0) {
430
+ const name = (id) => channelName(res.data.validScopes, id);
431
+ setGateWarning(t('productEditor.scopeControls.warning.incomplete', {
432
+ details: completeness.map((w) => describeIncompletePair(w, name, t)).join('; '),
433
+ }));
201
434
  }
202
- else if (id) {
203
- // Feature 023 — page-Save commits both the per-language baseline
204
- // (carried by `trimmedName` / `trimmedDescription` via the existing
205
- // PATCH) AND any pending channel-scoped override drafts held in
206
- // the ProductScopeEditor panel. Run them in parallel; if the
207
- // override flush rejects, the page PATCH still committed.
208
- await Promise.all([
209
- apiClient.patch(`/api/v1/admin/catalog/products/${id}`, {
210
- sku: sku.trim(),
211
- status,
212
- name: trimmedName,
213
- description: trimmedDescription,
214
- categoryIds,
215
- attributeValues,
216
- visibility,
217
- ...(attributeSetId ? { attributeSetId } : {}),
218
- }),
219
- scopeEditorRef.current?.flushOverrides() ?? Promise.resolve(),
220
- galleryRef.current?.flushGallery() ?? Promise.resolve(),
221
- ]);
222
- setInfo('Saved.');
223
- await refresh();
435
+ else {
436
+ setInfo(plural('productEditor.save.saved', count, { scope: scopeInWords(s.scope, s.data.validScopes, t, adminLanguage) }));
224
437
  }
438
+ return true;
225
439
  }
226
440
  catch (err) {
227
- setError(err instanceof ApiError ? err.envelope.error.message : 'Save failed.');
441
+ handleSaveError(err, s);
442
+ return false;
228
443
  }
229
- }, [isNew, id, sku, status, type, name, description, categoryIds, attrValues, attributeSetId, visibility, navigate, refresh]);
230
- const handleAttrChange = useCallback((key, value) => {
231
- setAttrValues((prev) => ({ ...prev, [key]: value }));
232
- }, []);
233
- // Swapping the Attribute Set drops the values whose keys are not in the
234
- // newly-selected set, so the save payload doesn't carry orphan keys left
235
- // over from the previous set.
236
- const handleAttributeSetChange = useCallback(async (newSetId) => {
237
- setAttributeSetId(newSetId);
238
- if (!newSetId)
444
+ finally {
445
+ setSaving(false);
446
+ }
447
+ },
448
+ // eslint-disable-next-line react-hooks/exhaustive-deps
449
+ [productId, readOnly, t, adminLanguage]);
450
+ function handleSaveError(err, s) {
451
+ const e = errorOf(err);
452
+ if (!e) {
453
+ setFormError({ kind: 'message', text: t('productEditor.error.save') });
239
454
  return;
240
- try {
241
- const res = await apiClient.get(`/api/v1/admin/catalog/attribute-sets/${newSetId}`);
242
- const allowed = new Set(res.data.attributes.map((a) => a.key));
243
- setAttrValues((prev) => {
244
- const next = {};
245
- for (const [k, v] of Object.entries(prev)) {
246
- if (allowed.has(k)) {
247
- next[k] = v;
248
- }
249
- }
250
- return next;
455
+ }
456
+ const takeover = takeoverDetails(err);
457
+ if (takeover) {
458
+ setTakeovers(takeover.takeovers);
459
+ return;
460
+ }
461
+ if (e.code === ERROR_CODES.VERSION_CONFLICT) {
462
+ setFormError({ kind: 'conflict' });
463
+ return;
464
+ }
465
+ if (e.code === 'MODULE_DISABLED') {
466
+ setFormError({ kind: 'seo' });
467
+ return;
468
+ }
469
+ if (e.code === ERROR_CODES.SKU_ALREADY_EXISTS) {
470
+ dispatch({ type: 'errors', errors: { 'product:sku': t('errors.SKU_ALREADY_EXISTS') } });
471
+ setFormError({ kind: 'validation', count: 1 });
472
+ setTimeout(() => document.getElementById(fieldDomId('product:sku'))?.focus(), 0);
473
+ return;
474
+ }
475
+ if (e.code === ERROR_CODES.URL_KEY_TAKEN) {
476
+ dispatch({ type: 'errors', errors: { urlKey: urlKeyErrorMessage(err, t) ?? t('errors.URL_KEY_TAKEN') } });
477
+ setFormError({ kind: 'validation', count: 1 });
478
+ setTimeout(() => document.getElementById(fieldDomId('urlKey'))?.focus(), 0);
479
+ return;
480
+ }
481
+ if (e.code === ERROR_CODES.SCOPE_INCOMPLETE && Array.isArray(e.details?.['pairs'])) {
482
+ const pairs = e.details['pairs'];
483
+ const name = (id) => channelName(s.data?.validScopes ?? { channels: [] }, id);
484
+ setFormError({
485
+ kind: 'message',
486
+ text: t('productEditor.statusGate.refused', { details: pairs.map((p) => describeIncompletePair(p, name, t)).join('; ') }),
251
487
  });
488
+ return;
252
489
  }
253
- catch {
254
- // Non-fatal — the backend tolerates round-tripped keys, so leaving
255
- // the values untouched on a fetch failure still saves correctly.
490
+ const fields = e.details?.['fields'];
491
+ if (Array.isArray(fields) && fields.length > 0) {
492
+ const errors = {};
493
+ const gone = [];
494
+ let download = false;
495
+ for (const entry of fields) {
496
+ // The Global-only family answers `product.<key>`; the editor's path is `product:<key>`.
497
+ const raw = typeof entry === 'string' ? `product:${entry}` : entry.field;
498
+ const field = raw.startsWith('product.') ? `product:${raw.slice('product.'.length)}` : raw;
499
+ const reason = typeof entry === 'string'
500
+ ? 'global_only'
501
+ : (entry.reason ?? (e.code === ERROR_CODES.FIELD_NOT_AT_SCOPE ? 'not_at_scope' : 'invalid'));
502
+ if (field === 'product:downloadAssetId' || field === 'product:downloadUrl')
503
+ download = true;
504
+ else if (field === 'product:attributeSetId' || field === 'product:categoryIds') {
505
+ // A Global-only reference that names nothing: the field's own words, the change kept.
506
+ errors[field] = reason === 'subject_not_found' ? t(`productEditor.save.reason.${field.replace(':', '.')}`) : t(`productEditor.save.reason.${reason}`);
507
+ }
508
+ else if (reason === 'subject_not_found')
509
+ gone.push(field);
510
+ else
511
+ errors[field] = t(`productEditor.save.reason.${reason}`);
512
+ }
513
+ if (gone.length > 0)
514
+ dispatch({ type: 'dropPaths', paths: gone });
515
+ if (download && Object.keys(errors).length === 0) {
516
+ // The download rules have no field in the editor (virtual products, feature 002).
517
+ setFormError({ kind: 'message', text: t('productEditor.save.error.download') });
518
+ return;
519
+ }
520
+ if (Object.keys(errors).length > 0) {
521
+ dispatch({ type: 'errors', errors });
522
+ setFormError({ kind: 'validation', count: Object.keys(errors).length });
523
+ const first = Object.keys(errors)[0];
524
+ setTimeout(() => document.getElementById(fieldDomId(first))?.focus(), 0);
525
+ }
526
+ else {
527
+ setFormError({ kind: 'message', text: t('productEditor.save.error.subjectGone') });
528
+ }
529
+ return;
256
530
  }
257
- }, []);
258
- const handleDeleteProduct = useCallback(async () => {
259
- if (!id)
531
+ setFormError({ kind: 'message', text: e.message });
532
+ }
533
+ const reloadDiscarding = () => {
534
+ dispatch({ type: 'discard' });
535
+ setFormError(null);
536
+ // The Reload button goes with the alert: focus the panel the fresh values are in.
537
+ void load(stateRef.current.scope, { note: t('productEditor.save.reloaded') }).then(() => document.getElementById('product-tabpanel')?.focus());
538
+ };
539
+ // The copy dialog's conflict reloads through the same path as Save's (a stable handle for the context).
540
+ const reloadDiscardingRef = useRef(reloadDiscarding);
541
+ reloadDiscardingRef.current = reloadDiscarding;
542
+ const dropSeoChanges = () => {
543
+ dispatch({ type: 'dropPaths', paths: [...stateRef.current.staged.keys()].filter((p) => p.startsWith('seo:')) });
544
+ setFormError(null);
545
+ announce(t('productEditor.save.seoDropped'));
546
+ };
547
+ // --- Guard -------------------------------------------------------------------------------
548
+ const proceed = (g) => {
549
+ setGuard(null);
550
+ if (g.kind === 'leave') {
551
+ navigate('/catalog/products');
552
+ return;
553
+ }
554
+ if (g.kind === 'url') {
555
+ skipGuardRef.current = false;
556
+ void load(g.target, { field: searchParams.get('field') });
260
557
  return;
261
- if (!confirm(t('productEditor.deleteConfirm')))
558
+ }
559
+ go(g.target, g.note, g.field, g.tab);
560
+ };
561
+ const stay = (g) => {
562
+ setGuard(null);
563
+ // Back / Forward moved the URL: put the current scope back (§11, Stay re-pushes the URL).
564
+ if (g.kind === 'url')
565
+ setSearchParams((prev) => searchWithScope(prev, stateRef.current.scope));
566
+ };
567
+ // --- Whole-product actions (each applies at once, at every scope) -------------------------
568
+ const handleDelete = async () => {
569
+ if (deleting)
262
570
  return;
571
+ setDeleting(true);
572
+ setWholeProductError(null);
263
573
  try {
264
- await apiClient.delete(`/api/v1/admin/catalog/products/${id}`);
574
+ await apiClient.delete(PRODUCT_PATH(productId));
265
575
  navigate('/catalog/products');
266
576
  }
267
577
  catch (err) {
268
- setError(err instanceof ApiError ? err.envelope.error.message : 'Delete failed.');
578
+ setWholeProductError(withServerDetail(t('productEditor.error.delete'), err));
269
579
  }
270
- }, [id, navigate, t]);
271
- const [duplicating, setDuplicating] = useState(false);
272
- const handleDuplicate = useCallback(async () => {
273
- if (!id || duplicating)
274
- return;
275
- if (!confirm('Duplicate this product? A draft copy will be created.'))
580
+ finally {
581
+ setDeleting(false);
582
+ }
583
+ };
584
+ /** FR-119: the copy takes every scope except status and URL keys; the dialog says so. */
585
+ const handleDuplicate = async () => {
586
+ if (duplicating)
276
587
  return;
277
588
  setDuplicating(true);
278
- setError(null);
589
+ setWholeProductError(null);
279
590
  try {
280
- const res = await apiClient.post(`/api/v1/admin/catalog/products/${id}/duplicate`, {});
591
+ const res = await apiClient.post(`${PRODUCT_PATH(productId)}/duplicate`, {});
281
592
  navigate(`/catalog/products/${res.data.id}`);
282
593
  }
283
594
  catch (err) {
284
- setError(err instanceof ApiError ? err.envelope.error.message : 'Duplicate failed.');
595
+ setWholeProductError(withServerDetail(t('productEditor.error.duplicate'), err));
285
596
  }
286
597
  finally {
287
598
  setDuplicating(false);
288
599
  }
289
- }, [id, duplicating, navigate]);
290
- if (loading)
291
- return (_jsx("div", { className: "b2b-page b2b-page--wide", children: _jsx("div", { style: { padding: 32, color: 'var(--fg-muted)', fontSize: 13 }, children: t('productEditor.loading') }) }));
292
- const tabs = [
293
- { id: 'details', label: 'Details', icon: _jsx(FileTextIcon, { size: 14 }), show: true },
294
- { id: 'attributes', label: 'Attributes', icon: _jsx(SlidersHorizontal, { size: 14 }), show: !isNew },
295
- { id: 'pricing', label: t('productEditor.tab.pricing'), icon: _jsx(CircleDollarSign, { size: 14 }), show: !isNew },
296
- {
297
- id: 'variants',
298
- label: 'Variants',
299
- icon: _jsx(Layers, { size: 14 }),
300
- show: !isNew && type === 'configurable',
301
- },
302
- {
303
- id: 'composite',
304
- label: type === 'grouped' ? 'Grouped items' : 'Bundle slots',
305
- icon: _jsx(Layers, { size: 14 }),
306
- show: !isNew && (type === 'grouped' || type === 'bundle'),
307
- },
308
- { id: 'media', label: 'Media', icon: _jsx(ImageIcon, { size: 14 }), show: !isNew },
309
- { id: 'inventory', label: 'Inventory', icon: _jsx(WarehouseIcon, { size: 14 }), show: !isNew },
310
- { id: 'attachments', label: 'Attachments', icon: _jsx(Paperclip, { size: 14 }), show: !isNew },
311
- { id: 'links', label: 'Related', icon: _jsx(LinkIcon, { size: 14 }), show: !isNew },
312
- // Feature 091 / P7a, Z15 — the tab body is a zone, so the button is shown
313
- // by counting it. `useAdminZone` has already applied both presence axes and
314
- // each contributor's permission, so its length is the honest answer to "is
315
- // there anything behind this tab" — and a tab that opens on an empty panel
316
- // is worse than no tab. The label stays this screen's own word for the
317
- // place (Z14); what it stops knowing is which module fills it.
318
- {
319
- id: 'channels',
320
- label: 'Channels',
321
- icon: _jsx(StoreIcon, { size: 14 }),
322
- show: !isNew && channelContributions.length > 0,
323
- },
324
- { id: 'seo', label: 'SEO', icon: _jsx(Globe, { size: 14 }), show: !isNew },
325
- ];
326
- const visibleTabs = tabs.filter((t) => t.show);
327
- return (_jsxs("div", { className: "b2b-page b2b-page--wide", children: [_jsxs("div", { className: "b2b-page-head", children: [_jsxs("div", { className: "b2b-grow", children: [_jsxs("button", { type: "button", className: "b2b-page-head__back", onClick: () => { navigate('/catalog/products'); }, children: [_jsx(ChevronLeft, { size: 14 }), " Products"] }), _jsxs("div", { className: "b2b-page-head__title", children: [_jsx("span", { children: isNew ? 'New product' : pickName(name) || sku }), !isNew ? _jsx(StatusPill, { status: status }) : null] }), !isNew ? (_jsxs("div", { className: "b2b-page-head__sub", children: [_jsx("span", { className: "b2b-mono", children: sku }), " \u00B7 ", _jsx("span", { style: { textTransform: 'capitalize' }, children: type })] })) : null] }), _jsxs(StickyFormActions, { className: "b2b-page-head__actions", children: [!isNew ? (_jsxs(_Fragment, { children: [_jsxs("button", { type: "button", className: "b2b-btn b2b-btn--default b2b-btn--sm", children: [_jsx(Eye, { size: 13 }), " Preview"] }), _jsxs("button", { type: "button", className: "b2b-btn b2b-btn--default b2b-btn--sm", onClick: () => void handleDuplicate(), disabled: duplicating, children: [_jsx(Copy, { size: 13 }), " ", duplicating ? 'Duplicating…' : 'Duplicate'] }), _jsxs("button", { type: "button", className: "b2b-btn b2b-btn--danger b2b-btn--sm", onClick: () => void handleDeleteProduct(), children: [_jsx(Trash2, { size: 13 }), " ", t('productEditor.action.delete')] })] })) : null, _jsxs("button", { type: "button", className: "b2b-btn b2b-btn--primary", onClick: (e) => {
328
- void handleSave(e);
329
- }, children: [_jsx(Save, { size: 14 }), " Save"] })] })] }), error ? (_jsx(Alert, { variant: "destructive", className: "mb-4", children: _jsx(AlertDescription, { children: error }) })) : null, info ? (_jsx(Alert, { variant: "success", className: "mb-4", children: _jsx(AlertDescription, { children: info }) })) : null, _jsxs("div", { className: "b2b-card", children: [_jsx("div", { style: { padding: '4px 4px 0', overflow: 'hidden' }, children: _jsx("div", { className: "b2b-tabs-scroll", children: _jsx("div", { className: "b2b-tabs", role: "tablist", children: visibleTabs.map((t) => (_jsxs("button", { type: "button", role: "tab", "aria-selected": activeTab === t.id, className: cn('b2b-tab', activeTab === t.id && 'is-active'), onClick: () => setActiveTab(t.id), children: [t.icon, t.label] }, t.id))) }) }) }), _jsxs("div", { className: "b2b-card__body", children: [activeTab === 'details' ? (_jsx("form", { id: "product-details-form", onSubmit: handleSave, children: _jsxs("div", { className: "b2b-col", style: { gap: 18 }, children: [id ? (_jsx(AdminZone, { name: "product.editor.details.before", props: { productId: id } })) : null, id ? (_jsxs("div", { className: "flex flex-wrap gap-x-4 gap-y-1", children: [_jsx(AdminZone, { name: "product.editor.field.after", props: { productId: id, fieldPath: 'name', languageCodes: LOCALES } }), _jsx(AdminZone, { name: "product.editor.field.after", props: { productId: id, fieldPath: 'description', languageCodes: LOCALES } })] })) : null, id ? (_jsx(ProductScopeEditor, { ref: scopeEditorRef, productId: id, baselineName: name, baselineDescription: description, onBaselineNameChange: (next) => setName({
330
- 'en-US': next['en-US'] ?? '',
331
- 'pl-PL': next['pl-PL'] ?? '',
332
- }), onBaselineDescriptionChange: (next) => setDescription({
333
- 'en-US': next['en-US'] ?? '',
334
- 'pl-PL': next['pl-PL'] ?? '',
335
- }) })) : null, _jsxs("div", { children: [_jsx("div", { className: "b2b-label", children: t('productEditor.section.identity') }), _jsxs("div", { style: { display: 'grid', gridTemplateColumns: '1fr 1fr 1fr', gap: 12 }, children: [_jsxs("div", { children: [_jsx(Label, { htmlFor: "sku", children: t('productEditor.field.sku') }), _jsx(Input, { id: "sku", value: sku, onChange: (e) => setSku(e.target.value), required: true })] }), _jsxs("div", { children: [_jsx(Label, { htmlFor: "ptype", children: t('productEditor.field.type') }), _jsx(Select, { id: "ptype", value: type, onChange: (e) => setType(e.target.value), disabled: !isNew, children: PRODUCT_TYPES.map((pt) => (_jsx("option", { value: pt, children: pt }, pt))) })] }), _jsxs("div", { children: [_jsx(Label, { htmlFor: "pvis", children: t('productEditor.field.visibility') }), _jsx(Select, { id: "pvis", value: visibility, onChange: (e) => setVisibility(e.target.value), children: VISIBILITIES.map((v) => (_jsx("option", { value: v, children: v }, v))) })] }), _jsxs("div", { children: [_jsx(Label, { htmlFor: "pattrset", children: t('productEditor.field.attributeSet') }), _jsx(Select, { id: "pattrset", value: attributeSetId, onChange: (e) => void handleAttributeSetChange(e.target.value), children: attributeSets.length === 0 ? (_jsx("option", { value: "", children: t('productEditor.attributeSet.loading') })) : (attributeSets.map((s) => (_jsxs("option", { value: s.id, children: [s.code, s.isSystem ? t('productEditor.attributeSet.systemSuffix') : ''] }, s.id)))) })] }), _jsxs("div", { children: [_jsx(Label, { htmlFor: "pstatus", children: t('productEditor.field.status') }), _jsx(Select, { id: "pstatus", value: status, onChange: (e) => setStatus(e.target.value), children: STATUSES.map((s) => (_jsx("option", { value: s, children: s }, s))) }), _jsx("p", { className: "b2b-help", children: t('productEditor.field.status.help') })] })] })] }), isNew ? (_jsxs(_Fragment, { children: [_jsx("hr", { className: "b2b-hr" }), _jsxs("div", { children: [_jsx("div", { className: "b2b-label", children: t('productEditor.section.localizedContent') }), _jsx("p", { className: "b2b-help", style: { marginTop: 0, marginBottom: 12 }, children: t('productEditor.section.localizedContent.help') }), _jsx("div", { className: "b2b-col", style: { gap: 18 }, children: LOCALES.map((l) => (_jsxs("div", { className: "b2b-col", style: { gap: 8 }, children: [_jsxs("div", { children: [_jsx(Label, { htmlFor: `name-${l}`, children: t('productEditor.field.localizedName', { locale: l }) }), _jsx(Input, { id: `name-${l}`, value: name[l], onChange: (e) => setName((prev) => ({ ...prev, [l]: e.target.value })) })] }), _jsxs("div", { children: [_jsx(Label, { htmlFor: `desc-${l}`, children: t('productEditor.field.localizedDescription', { locale: l }) }), _jsx("textarea", { id: `desc-${l}`, rows: 3, className: "b2b-field", value: description[l], onChange: (e) => setDescription((prev) => ({ ...prev, [l]: e.target.value })) })] })] }, l))) })] })] })) : null, _jsx("hr", { className: "b2b-hr" }), _jsxs("div", { children: [_jsxs("div", { className: "b2b-label", children: [t('productEditor.section.categories'), id ? (_jsx(AdminZone, { name: "product.editor.field.after", props: { productId: id, fieldPath: 'categories', languageCodes: null } })) : null] }), _jsx(CategoryTreePicker, { categories: categories, selectedIds: categoryIds, onChange: setCategoryIds, loading: loading }), _jsx("p", { className: "b2b-help", children: t('productEditor.section.categories.help') })] })] }) })) : null, activeTab === 'attributes' && id ? (_jsx(ProductAttributesTab, { productId: id, attributeSetId: attributeSetId, values: attrValues, onChange: handleAttrChange })) : null, activeTab === 'pricing' && id ? (_jsxs("div", { className: "b2b-col", style: { gap: 16 }, children: [_jsx(AdminZone, { name: "product.editor.pricing.before", props: { productId: id } }), _jsx(AdminZone, { name: "product.editor.pricing.after", props: { productId: id } })] })) : null, activeTab === 'variants' && id ? _jsx(VariantsSection, { productId: id }) : null, activeTab === 'composite' && id ? (type === 'grouped' ? (_jsx(GroupedItemsSection, { productId: id })) : (_jsx(BundleSlotsSection, { productId: id }))) : null, activeTab === 'media' && id ? (_jsxs(_Fragment, { children: [_jsx(AdminZone, { name: "product.editor.field.after", props: { productId: id, fieldPath: 'gallery', languageCodes: null } }), _jsx(GallerySection, { ref: galleryRef, productId: id })] })) : null, activeTab === 'inventory' && id ? (_jsxs("div", { className: "b2b-col", style: { gap: 16 }, children: [_jsx(ProductInventoryTab, { productId: id }), _jsx(ProductOrderRulesCard, { productId: id, productType: type }), type === 'simple' || type === 'configurable' ? (_jsx(PackagingUnitsEditor, { productId: id })) : null] })) : null, activeTab === 'attachments' && id ? (_jsxs(_Fragment, { children: [_jsx(AdminZone, { name: "product.editor.field.after", props: { productId: id, fieldPath: 'attachments', languageCodes: null } }), _jsx(AttachmentsSection, { productId: id })] })) : null, activeTab === 'links' && id ? _jsx(ProductLinksSection, { productId: id }) : null, activeTab === 'channels' && id ? (_jsx(AdminZone, { name: "product.editor.channels", props: { productId: id } })) : null, activeTab === 'seo' ? _jsx(SeoStub, { name: name }) : null] })] })] }));
336
- }
337
- function StatusPill({ status }) {
338
- const map = {
339
- active: { cls: 'b2b-badge--success', label: 'Active' },
340
- draft: { cls: 'b2b-badge--warn', label: 'Draft' },
341
- inactive: { cls: '', label: 'Inactive' },
342
600
  };
343
- const v = map[status];
344
- return _jsx("span", { className: cn('b2b-badge', 'b2b-badge--dot', v.cls), children: v.label });
345
- }
346
- function pickName(name) {
347
- return name['en-US'] ?? Object.values(name)[0] ?? '';
348
- }
349
- function SeoStub({ name }) {
350
- const t = useTranslation('catalog');
351
- return (_jsxs("div", { className: "b2b-col", style: { gap: 12 }, children: [_jsx("div", { className: "b2b-label", children: t('productEditor.seo.title') }), _jsx("div", { className: "b2b-help", style: { marginTop: 0 }, children: t('productEditor.seo.description') }), _jsxs("div", { children: [_jsx(Label, { htmlFor: "seo-title", children: t('productEditor.seo.pageTitlePreview') }), _jsx(Input, { id: "seo-title", defaultValue: pickName(name) })] })] }));
601
+ // The dialog a Product menu item asked for, opened once the menu has handed focus back to its
602
+ // trigger (`onCloseAutoFocus`), so the dialog's focus trap starts from the trigger and returns
603
+ // there. A bare `setTimeout` raced the menu's own focus return on a slow machine.
604
+ const pendingWholeProductDialog = useRef(null);
605
+ const openWholeProductDialog = (kind) => {
606
+ setWholeProductError(null);
607
+ setArchiveError(null);
608
+ pendingWholeProductDialog.current = kind;
609
+ };
610
+ const afterProductMenuClosed = () => {
611
+ const kind = pendingWholeProductDialog.current;
612
+ pendingWholeProductDialog.current = null;
613
+ if (kind === null)
614
+ return;
615
+ // The menu focuses its trigger right after this handler returns.
616
+ setTimeout(() => {
617
+ if (kind === 'archive')
618
+ setArchiveDialog('archive');
619
+ else
620
+ setWholeProductDialog(kind);
621
+ }, 0);
622
+ };
623
+ const handleArchiveAction = async () => {
624
+ if (archiveDialog === null || archiving)
625
+ return;
626
+ setArchiving(true);
627
+ setArchiveError(null);
628
+ try {
629
+ const res = await apiClient.post(`${PRODUCT_PATH(productId)}/${archiveDialog}`, {});
630
+ setArchivedOverride(res.data.archivedAt ?? null);
631
+ setInfo(t(archiveDialog === 'archive' ? 'productEditor.archive.done' : 'productEditor.restore.done'));
632
+ setArchiveDialog(null);
633
+ }
634
+ catch (err) {
635
+ setArchiveError(withServerDetail(t(archiveDialog === 'archive' ? 'productEditor.archive.failed' : 'productEditor.restore.failed'), err));
636
+ }
637
+ finally {
638
+ setArchiving(false);
639
+ }
640
+ };
641
+ // --- Tabs ------------------------------------------------------------------------------------
642
+ const data = state.data;
643
+ const type = data?.product.type ?? null;
644
+ const tabLabel = (id) => id === 'composite' ? t(type === 'grouped' ? 'productEditor.tab.grouped' : 'productEditor.tab.bundle') : t(`productEditor.tab.${id}`);
645
+ const visibleTabs = TAB_IDS.filter((id) => {
646
+ if (id === 'variants')
647
+ return type === 'configurable';
648
+ if (id === 'composite')
649
+ return type === 'grouped' || type === 'bundle';
650
+ if (id === 'channels')
651
+ return channelContributions.length > 0;
652
+ if (id === 'seo')
653
+ return seoContributions.length > 0;
654
+ return true;
655
+ });
656
+ const requestedTab = searchParams.get('tab');
657
+ const activeTab = requestedTab && TAB_IDS.includes(requestedTab) && (visibleTabs.includes(requestedTab) || type === null)
658
+ ? requestedTab
659
+ : 'details';
660
+ const selectTab = (id, focus = false) => {
661
+ setSearchParams((prev) => {
662
+ const sp = new URLSearchParams(prev);
663
+ sp.set('tab', id);
664
+ sp.delete('field');
665
+ return sp;
666
+ }, { replace: true });
667
+ if (focus)
668
+ setTimeout(() => document.getElementById(`product-tab-${id}`)?.focus(), 0);
669
+ };
670
+ const onTabKey = (event) => {
671
+ const index = visibleTabs.indexOf(activeTab);
672
+ let next = index;
673
+ if (event.key === 'ArrowRight')
674
+ next = (index + 1) % visibleTabs.length;
675
+ else if (event.key === 'ArrowLeft')
676
+ next = (index - 1 + visibleTabs.length) % visibleTabs.length;
677
+ else if (event.key === 'Home')
678
+ next = 0;
679
+ else if (event.key === 'End')
680
+ next = visibleTabs.length - 1;
681
+ else
682
+ return;
683
+ event.preventDefault();
684
+ selectTab(visibleTabs[next], true);
685
+ };
686
+ const missingText = useCallback((fieldPath) => {
687
+ const c = state.data?.completeness;
688
+ if (!c || c.level !== 'channel_language')
689
+ return undefined;
690
+ return c.missing.includes(fieldPath)
691
+ ? t('productEditor.completeness.missingHere', { scope: scopeInWords(state.scope, state.data.validScopes, t, adminLanguage) })
692
+ : undefined;
693
+ }, [state.data, state.scope, t, adminLanguage]);
694
+ // --- Completeness summary (§9, FR-097), from saved values -------------------------------
695
+ const fieldLabel = (path) => {
696
+ if (path === 'name')
697
+ return t('productEditor.field.name');
698
+ if (path === 'urlKey')
699
+ return t('productEditor.field.urlKey');
700
+ const key = path.replace(/^attribute:/, '');
701
+ const attr = state.data?.attributes.find((a) => a.key === key);
702
+ const label = attr ? (Object.entries(attr.label).find(([code]) => code.split('-')[0] === adminLanguage)?.[1] ?? Object.values(attr.label)[0]) : undefined;
703
+ return label ?? key;
704
+ };
705
+ const fieldHref = (path) => {
706
+ const sp = new URLSearchParams(searchParams);
707
+ sp.set('tab', path.startsWith('attribute:') ? 'attributes' : 'details');
708
+ sp.set('field', path);
709
+ return `?${sp.toString()}`;
710
+ };
711
+ const openField = (path) => {
712
+ const tab = path.startsWith('attribute:') ? 'attributes' : 'details';
713
+ selectTab(tab);
714
+ setTimeout(() => document.getElementById(fieldDomId(path))?.focus(), 0);
715
+ };
716
+ const completenessNode = (() => {
717
+ const c = state.data?.completeness;
718
+ if (!c || !state.data)
719
+ return null;
720
+ const linkClass = 'text-primary underline underline-offset-2 max-lg:inline-flex max-lg:min-h-11 max-lg:items-center';
721
+ const fieldLink = (path, text) => (_jsx("a", { href: fieldHref(path), "data-own-unsaved-guard": "", className: linkClass, onClick: (e) => {
722
+ e.preventDefault();
723
+ openField(path);
724
+ }, children: text }, path));
725
+ const joined = (items) => items.flatMap((item, i) => (i === 0 ? [item] : [', ', item]));
726
+ let body = null;
727
+ if (c.level === 'channel_language' && c.missing.length > 0) {
728
+ body = (_jsxs(_Fragment, { children: [t('productEditor.completeness.here'), " ", joined(c.missing.map((m) => fieldLink(m, fieldLabel(m))))] }));
729
+ }
730
+ else if (c.level === 'channel' && c.missing.length > 0) {
731
+ const channelId = state.scope.level === 'global' ? null : state.scope.channelId;
732
+ body = (_jsxs(_Fragment, { children: [t('productEditor.completeness.channel'), ' ', joined(c.missing.map((m) => fieldLink(m.field, t('productEditor.completeness.fieldLanguages', {
733
+ field: fieldLabel(m.field),
734
+ languages: m.languages.map((code) => languageName(state.data.validScopes, channelId, code, adminLanguage)).join(', '),
735
+ }))))] }));
736
+ }
737
+ else if (c.level === 'global' && c.incompleteScopes > 0) {
738
+ body = (_jsxs(_Fragment, { children: [plural('productEditor.completeness.global', c.incompleteScopes), " \u2014", ' ', _jsx("a", { href: `?${(() => {
739
+ const sp = new URLSearchParams(searchParams);
740
+ sp.set('tab', 'scopes');
741
+ return sp.toString();
742
+ })()}`, className: linkClass, "data-own-unsaved-guard": "", onClick: (e) => {
743
+ e.preventDefault();
744
+ selectTab('scopes');
745
+ }, children: t('productEditor.scope.scopeMap') })] }));
746
+ }
747
+ if (!body)
748
+ return null;
749
+ return (_jsxs("p", { className: "m-0 inline-flex flex-wrap items-center gap-x-1 text-destructive", "data-testid": "completeness-summary", children: [_jsxs("span", { className: "sr-only", children: [t('productEditor.completeness.region'), ": "] }), body] }));
750
+ })();
751
+ const contextValue = useMemo(() => ({
752
+ productId,
753
+ state,
754
+ dispatch,
755
+ readOnly,
756
+ scopeLabel,
757
+ parentScopeLabel: parentLabel,
758
+ jumpTo: (scope, field) => requestScope(scope, undefined, field),
759
+ refreshFamily,
760
+ missingText,
761
+ afterCopy,
762
+ reloadDiscarding: () => reloadDiscardingRef.current(),
763
+ }), [productId, state, readOnly, scopeLabel, parentLabel, requestScope, refreshFamily, missingText, afterCopy]);
764
+ const archivedAt = archivedOverride !== undefined ? archivedOverride : (data?.product.archivedAt ?? null);
765
+ const status = data?.fields.status;
766
+ const statusValue = (status?.value ?? 'inactive');
767
+ const statusSource = !status || state.scope.level === 'global' || status.source === 'set' || status.source === 'set_empty'
768
+ ? null
769
+ : status.source === 'inherited_channel'
770
+ ? t('productEditor.statusSource.from', { scope: parentLabel })
771
+ : t('productEditor.statusSource.from', { scope: t('productEditor.scope.global') });
772
+ const title = data?.fields.name.value || data?.product.sku || '';
773
+ const stagedCount = state.staged.size;
774
+ const atGlobal = state.scope.level === 'global';
775
+ const globalOnlyNotice = (_jsxs(Alert, { className: "mb-4", "data-testid": "global-only-tab-notice", children: [_jsx(Lock, { className: "size-4", "aria-hidden": "true" }), _jsx(AlertDescription, { children: _jsxs("div", { className: "flex flex-wrap items-center gap-3", children: [_jsx("span", { className: "flex-1", children: t('productEditor.globalOnlyTab.body', { scope: words(state.scope) }) }), !readOnly ? (_jsx(Button, { type: "button", variant: "outline", size: "sm", className: "max-lg:min-h-11", onClick: () => requestScope(GLOBAL), children: t('productEditor.globalOnlyTab.editAtGlobal') })) : null] }) })] }));
776
+ const seoStaged = new Map();
777
+ for (const [path, op] of state.staged)
778
+ if (path.startsWith('seo:'))
779
+ seoStaged.set(path.slice(4), op);
780
+ const seoErrors = {};
781
+ for (const [path, message] of Object.entries(state.errors))
782
+ if (path.startsWith('seo:'))
783
+ seoErrors[path.slice(4)] = message;
784
+ const panel = () => {
785
+ if (!data && loadError) {
786
+ return (_jsxs("div", { className: "flex flex-col items-start gap-3 py-6", "data-testid": "editor-load-error", children: [_jsx("p", { role: "alert", className: "m-0 text-sm text-destructive", children: loadError }), _jsxs(Button, { type: "button", variant: "outline", size: "sm", className: "max-lg:min-h-11", onClick: () => void load(state.scope), children: [_jsx(RotateCw, { size: 14, "aria-hidden": "true" }), " ", t('productEditor.error.retry')] })] }));
787
+ }
788
+ if (!data) {
789
+ return (_jsx("div", { className: "space-y-3", "data-testid": "editor-skeleton", children: [0, 1, 2, 3].map((i) => (_jsx("div", { className: "h-16 animate-pulse rounded-md bg-muted motion-reduce:animate-none" }, i))) }));
790
+ }
791
+ // Global-only tabs outside Global: the notice, then the content read-only (FR-081). The
792
+ // zone-backed tabs (Pricing, Channels) belong to their contributors, which take no read-only
793
+ // flag, so they show the notice alone.
794
+ const structuralReadOnly = readOnly || !atGlobal;
795
+ if (GLOBAL_ONLY_TABS.has(activeTab) && !atGlobal && (activeTab === 'pricing' || activeTab === 'channels'))
796
+ return globalOnlyNotice;
797
+ const notice = GLOBAL_ONLY_TABS.has(activeTab) && !atGlobal ? globalOnlyNotice : null;
798
+ switch (activeTab) {
799
+ case 'details':
800
+ return (_jsx(DetailsTab, { attributeSets: attributeSets, categories: categories, categoriesLoading: categoriesLoading, referenceError: referenceError, onRetryReference: loadReference }));
801
+ case 'attributes':
802
+ return _jsx(ProductAttributesTab, {});
803
+ case 'pricing':
804
+ return (_jsxs("div", { className: "b2b-col", style: { gap: 16 }, children: [_jsx(SectionHeading, { title: t('productEditor.tab.pricing'), immediate: !readOnly }), _jsx(AdminZone, { name: "product.editor.pricing.before", props: { productId } }), _jsx(AdminZone, { name: "product.editor.pricing.after", props: { productId } })] }));
805
+ case 'variants':
806
+ return (_jsxs(_Fragment, { children: [notice, _jsx(VariantsSection, { productId: productId, readOnly: structuralReadOnly })] }));
807
+ case 'composite':
808
+ return (_jsxs(_Fragment, { children: [notice, type === 'grouped' ? (_jsx(GroupedItemsSection, { productId: productId, readOnly: structuralReadOnly })) : (_jsx(BundleSlotsSection, { productId: productId, readOnly: structuralReadOnly }))] }));
809
+ case 'media':
810
+ return (_jsxs(_Fragment, { children: [_jsx(AdminZone, { name: "product.editor.field.after", props: { productId, fieldPath: 'gallery', scope: state.scope, languageCodes: null } }), _jsx(GallerySection, {})] }));
811
+ case 'inventory':
812
+ return (_jsxs("div", { className: "b2b-col", style: { gap: 16 }, children: [atGlobal ? null : globalOnlyNotice, _jsxs("section", { "aria-labelledby": "product-stock-heading", className: "space-y-2", children: [_jsx(SectionHeading, { id: "product-stock-heading", title: t('productEditor.stock.title'), immediate: !structuralReadOnly }), structuralReadOnly ? (
813
+ // Stock outside Global (or without catalog:write) is shown, not edited: the panel
814
+ // has no read-only mode of its own, so its controls are disabled as a group.
815
+ _jsx("fieldset", { disabled: true, className: "m-0 min-w-0 border-0 p-0", "data-testid": "stock-read-only", children: _jsx(ProductInventoryTab, { productId: productId }) })) : (_jsx(ProductInventoryTab, { productId: productId }))] }), _jsx(ProductOrderRulesCard, { productType: type ?? 'simple' }), type === 'simple' || type === 'configurable' ? (_jsx(PackagingUnitsEditor, { productId: productId, canWrite: canWrite, atGlobal: atGlobal, onChanged: () => refreshFamily('packagingUnits'), renderName: (unit) => (_jsx(EditorField, { fieldPath: `packagingUnit:${unit.id}:name`, label: t('packagingUnits.nameFor', { quantity: String(unit.baseQuantity) }), textField: true, render: (p) => _jsx(TextControl, { ...p, maxLength: 160 }) })) })) : null] }));
816
+ case 'attachments':
817
+ return (_jsxs(_Fragment, { children: [_jsx(AdminZone, { name: "product.editor.field.after", props: { productId, fieldPath: 'attachments', scope: state.scope, languageCodes: null } }), _jsx(AttachmentsSection, {})] }));
818
+ case 'links':
819
+ return (_jsxs(_Fragment, { children: [notice, _jsx(ProductLinksSection, { productId: productId, readOnly: structuralReadOnly })] }));
820
+ case 'channels':
821
+ return (_jsxs("div", { className: "space-y-2", children: [_jsx(SectionHeading, { title: t('productEditor.tab.channels'), immediate: !readOnly }), _jsx(AdminZone, { name: "product.editor.channels", props: { productId } })] }));
822
+ case 'scopes':
823
+ return (_jsx(ProductScopeOverview, { productId: productId, links: {
824
+ href: (scope, field) => {
825
+ const sp = searchWithScope(searchParams, scope);
826
+ sp.set('tab', tabOfField(field));
827
+ sp.delete('field');
828
+ if (field)
829
+ sp.set('field', field);
830
+ return `?${sp.toString()}`;
831
+ },
832
+ open: (scope, field) => requestScope(scope, undefined, field, tabOfField(field)),
833
+ words: (scope) => scopeShortWords(scope, valid, t, adminLanguage),
834
+ } }));
835
+ case 'seo':
836
+ return (_jsx(AdminZone, { name: "product.editor.seo", props: {
837
+ productId,
838
+ scope: state.scope,
839
+ scopeLabel,
840
+ parentScopeLabel: atGlobal ? null : parentLabel,
841
+ view: data.seo,
842
+ staged: seoStaged,
843
+ onStage: (field, op) => dispatch({ type: 'stage', path: `seo:${field}`, op }),
844
+ readOnly,
845
+ errors: seoErrors,
846
+ version: state.version,
847
+ } }));
848
+ }
849
+ };
850
+ const guardOpen = guard !== null;
851
+ return (_jsx(ProductEditorContextProvider, { value: contextValue, children: _jsxs("div", { className: "b2b-page b2b-page--wide", children: [_jsxs("div", { className: "b2b-page-head", children: [_jsxs("div", { className: "b2b-grow", children: [_jsxs("button", { type: "button", className: "b2b-page-head__back", onClick: () => {
852
+ if (stateRef.current.staged.size > 0)
853
+ setGuard({ kind: 'leave' });
854
+ else
855
+ navigate('/catalog/products');
856
+ }, children: [_jsx(ChevronLeft, { size: 14 }), " ", t('productEditor.back')] }), _jsxs("div", { className: "b2b-page-head__title", children: [_jsx("span", { children: title }), data ? _jsx(ProductStatusPill, { status: statusValue, archived: Boolean(archivedAt) }) : null, statusSource ? _jsx("span", { className: "text-xs text-muted-foreground", children: statusSource }) : null, archivedAt ? _jsx(ArchivedPill, {}) : null] }), data ? (_jsxs("div", { className: "b2b-page-head__sub", children: [_jsx("span", { className: "b2b-mono", children: data.product.sku }), " \u00B7 ", _jsx("span", { children: t(`productEditor.type.${data.product.type}`) })] })) : null] }), canWrite ? (_jsxs("div", { className: "flex items-start gap-2", children: [_jsxs(DropdownMenu, { children: [_jsx(DropdownMenuTrigger, { asChild: true, children: _jsxs("button", { type: "button", className: "b2b-btn b2b-btn--default max-lg:min-h-11", "aria-describedby": "product-whole-caption", disabled: !data, children: [t('productEditor.wholeProduct.menu'), " ", _jsx(ChevronDown, { size: 14, "aria-hidden": "true" })] }) }), _jsxs(DropdownMenuContent, { align: "end", "aria-labelledby": "product-whole-caption", onCloseAutoFocus: afterProductMenuClosed, children: [_jsx("p", { "aria-hidden": "true", className: "m-0 px-2 py-1.5 text-xs text-muted-foreground", children: t('productEditor.wholeProduct.caption') }), _jsxs(DropdownMenuItem, { className: "max-lg:min-h-11", onSelect: () => openWholeProductDialog('duplicate'), children: [_jsx(Copy, { size: 14, "aria-hidden": "true" }), " ", t('productEditor.action.duplicate')] }), !archivedAt ? (_jsxs(DropdownMenuItem, { className: "max-lg:min-h-11", onSelect: () => openWholeProductDialog('archive'), children: [_jsx(Archive, { size: 14, "aria-hidden": "true" }), " ", t('productEditor.action.archive')] })) : null, _jsx(DropdownMenuSeparator, {}), _jsxs(DropdownMenuItem, { className: "max-lg:min-h-11", destructive: true, onSelect: () => openWholeProductDialog('delete'), children: [_jsx(Trash2, { size: 14, "aria-hidden": "true" }), " ", t('productEditor.action.delete')] })] })] }), _jsx("span", { id: "product-whole-caption", className: "sr-only", children: t('productEditor.wholeProduct.caption') }), _jsxs(StickyFormActions, { className: "b2b-page-head__actions", children: [_jsxs("button", { type: "button", className: "b2b-btn b2b-btn--primary max-lg:min-h-11 aria-disabled:cursor-not-allowed aria-disabled:opacity-50", "aria-disabled": stagedCount === 0 || saving || !data, "aria-describedby": "product-save-note", onClick: () => {
857
+ if (stagedCount === 0 || saving || !data)
858
+ return;
859
+ void save();
860
+ }, children: [_jsx(Save, { size: 14, "aria-hidden": "true" }), saving
861
+ ? t('productEditor.save.saving')
862
+ : stagedCount > 0
863
+ ? plural('productEditor.save.actionCount', stagedCount)
864
+ : t('productEditor.save.action'), ' ', _jsx("span", { className: "sr-only", children: t('productEditor.save.atScope', { scope: words(state.scope) }) })] }), _jsx("span", { id: "product-save-note", className: "text-xs text-muted-foreground", children: stagedCount === 0 ? t('productEditor.save.noChanges') : '' })] })] })) : null] }), _jsx(ProductScopeBar, { scope: state.scope, validScopes: state.data?.validScopes ?? validRef.current, scopeWords: words(state.scope), readOnly: readOnly, adminLanguage: adminLanguage, onRequestScope: (next, note) => requestScope(next, note), onOpenScopeMap: () => selectTab('scopes'), completeness: completenessNode }), _jsx("p", { role: "status", className: "sr-only", "data-testid": "editor-announcer", children: announcement }), formError ? (_jsx(Alert, { variant: "destructive", className: "mb-4", "data-testid": "product-save-error", id: "product-save-error", tabIndex: -1, children: _jsx(AlertDescription, { children: formError.kind === 'validation' ? (plural('productEditor.save.error.fields', formError.count)) : formError.kind === 'conflict' ? (_jsxs("div", { className: "flex flex-wrap items-center gap-3", children: [_jsx("span", { className: "flex-1", children: t('productEditor.save.error.conflict') }), _jsx(Button, { type: "button", variant: "outline", size: "sm", className: "max-lg:min-h-11", onClick: reloadDiscarding, children: t('productEditor.save.reloadDiscarding') })] })) : formError.kind === 'seo' ? (_jsxs("div", { className: "flex flex-wrap items-center gap-3", children: [_jsx("span", { className: "flex-1", children: t('productEditor.save.error.seoOff') }), _jsx(Button, { type: "button", variant: "outline", size: "sm", className: "max-lg:min-h-11", onClick: dropSeoChanges, children: t('productEditor.save.removeSeoChanges') })] })) : (formError.text) }) })) : null, _jsx("div", { role: "status", children: info ? (_jsx(Alert, { variant: "success", role: "none", className: "mb-4", "data-testid": "product-save-info", children: _jsx(AlertDescription, { children: info }) })) : null }), _jsx("div", { role: "status", children: gateWarning ? (_jsx(Alert, { variant: "warning", role: "none", className: "mb-4", "data-testid": "product-gate-warning", children: _jsx(AlertDescription, { children: gateWarning }) })) : null }), archivedAt ? (_jsx(Alert, { variant: "warning", role: "status", className: "mb-4", "data-testid": "product-archived-notice", children: _jsx(AlertDescription, { children: _jsxs("div", { className: "flex flex-wrap items-center gap-3", children: [_jsxs("span", { className: "flex-1", children: [_jsx("strong", { children: t('productEditor.archived.title') }), " ", t('productEditor.archived.body')] }), canWrite ? (_jsxs(Button, { type: "button", variant: "outline", size: "sm", className: "max-lg:min-h-11", onClick: () => {
865
+ setArchiveError(null);
866
+ setArchiveDialog('restore');
867
+ }, children: [_jsx(ArchiveRestore, { size: 13, "aria-hidden": "true" }), " ", t('productEditor.action.restore')] })) : null] }) }) })) : null, _jsxs("div", { className: "b2b-card", children: [_jsx("div", { style: { padding: '4px 4px 0', overflow: 'hidden' }, children: _jsx("div", { className: "b2b-tabs-scroll", children: _jsx("div", { className: "b2b-tabs", role: "tablist", "aria-label": t('productEditor.tabs.label'), children: visibleTabs.map((id) => {
868
+ const selected = activeTab === id;
869
+ return (_jsx("button", { id: `product-tab-${id}`, type: "button", role: "tab", "aria-selected": selected, "aria-controls": "product-tabpanel", tabIndex: selected ? 0 : -1, className: cn('b2b-tab', selected && 'is-active'), onClick: () => selectTab(id), onKeyDown: onTabKey, children: tabLabel(id) }, id));
870
+ }) }) }) }), _jsx("div", { className: "b2b-card__body", role: "tabpanel", id: "product-tabpanel", "aria-labelledby": `product-tab-${activeTab}`, "aria-busy": state.busy && !loadError, tabIndex: -1, children: panel() })] }), guardOpen && guard ? (_jsx(ModalDialog, { title: t('productEditor.guard.title', { scope: words(state.scope) }), onClose: () => stay(guard), busy: saving, dismissOnScrim: false, "aria-describedby": "product-guard-body", footer: _jsxs(_Fragment, { children: [_jsx(Button, { type: "button", variant: "outline", disabled: saving, onClick: () => stay(guard), children: t('productEditor.guard.stay') }), _jsx(Button, { type: "button", variant: "outline", disabled: saving, onClick: () => {
871
+ dispatch({ type: 'discard' });
872
+ proceed(guard);
873
+ }, children: t('productEditor.guard.discard') }), _jsx(Button, { type: "button", disabled: saving, "aria-busy": saving || undefined, onClick: () => {
874
+ void save().then((ok) => {
875
+ if (ok) {
876
+ proceed(guard);
877
+ return;
878
+ }
879
+ setGuard(null);
880
+ setTimeout(() => document.getElementById('product-save-error')?.focus(), 0);
881
+ });
882
+ }, children: t('productEditor.guard.save') })] }), children: _jsx("p", { id: "product-guard-body", className: "text-sm", children: plural(guard.kind === 'leave' ? 'productEditor.guard.bodyLeave' : 'productEditor.guard.body', stagedCount) }) })) : null, takeovers ? (_jsxs(ModalDialog, { title: t('productEditor.urlKeys.takeover.title'), busy: saving, onClose: () => setTakeovers(null), footer: _jsxs(_Fragment, { children: [_jsx(Button, { type: "button", variant: "outline", disabled: saving, onClick: () => setTakeovers(null), children: t('productEditor.urlKeys.cancel') }), _jsx(Button, { type: "button", disabled: saving, onClick: () => void save(takeovers.map((k) => k.key)), children: t('productEditor.urlKeys.takeover.confirm') })] }), children: [_jsx("p", { className: "text-sm", children: t('productEditor.urlKeys.takeover.body') }), _jsx("ul", { className: "mt-2 list-disc space-y-1 pl-5 text-sm", children: takeovers.map((k) => (_jsx("li", { children: t('productEditor.urlKeys.takeover.item', {
883
+ product: k.losingProductName,
884
+ key: describeKeyInLanguage(k.key, k.languageCode, t),
885
+ }) }, `${k.languageCode ?? ''}|${k.key}`))) })] })) : null, wholeProductDialog !== null ? (_jsxs(ModalDialog, { title: t(wholeProductDialog === 'duplicate' ? 'productEditor.duplicateTitle' : 'productEditor.deleteTitle', { product: title }), onClose: () => setWholeProductDialog(null), busy: duplicating || deleting, "aria-describedby": "product-whole-confirm-body", footer: _jsxs(_Fragment, { children: [_jsx(Button, { type: "button", variant: "outline", disabled: duplicating || deleting, onClick: () => setWholeProductDialog(null), children: t('productEditor.archive.cancel') }), _jsx(Button, { type: "button", variant: wholeProductDialog === 'delete' ? 'destructive' : 'default', disabled: duplicating || deleting, "aria-busy": duplicating || deleting || undefined, onClick: () => void (wholeProductDialog === 'duplicate' ? handleDuplicate() : handleDelete()), children: wholeProductDialog === 'duplicate'
886
+ ? duplicating
887
+ ? t('productEditor.action.duplicating')
888
+ : t('productEditor.duplicateAction')
889
+ : t('productEditor.deleteAction') })] }), children: [_jsxs("p", { id: "product-whole-confirm-body", className: "text-sm", children: [t(wholeProductDialog === 'duplicate' ? 'productEditor.duplicateConfirm' : 'productEditor.deleteConfirm'), stagedCount > 0
890
+ ? ` ${t(wholeProductDialog === 'duplicate' ? 'productEditor.duplicateUnsaved' : 'productEditor.deleteUnsaved')}`
891
+ : null] }), wholeProductError ? (_jsx("p", { role: "alert", className: "mt-3 text-sm text-destructive", children: wholeProductError })) : null] })) : null, archiveDialog !== null ? (_jsxs(ModalDialog, { title: t(archiveDialog === 'archive' ? 'productEditor.archive.confirmTitle' : 'productEditor.restore.confirmTitle'), onClose: () => setArchiveDialog(null), busy: archiving, "aria-describedby": "product-archive-confirm-body", footer: _jsxs(_Fragment, { children: [_jsx(Button, { type: "button", variant: "outline", disabled: archiving, onClick: () => setArchiveDialog(null), children: t('productEditor.archive.cancel') }), _jsx(Button, { type: "button", disabled: archiving, "aria-busy": archiving || undefined, onClick: () => void handleArchiveAction(), children: t(archiveDialog === 'archive' ? 'productEditor.archive.confirm' : 'productEditor.restore.confirm') })] }), children: [_jsx("p", { id: "product-archive-confirm-body", className: "text-sm", children: t(archiveDialog === 'archive' ? 'productEditor.archive.confirmBody' : 'productEditor.restore.confirmBody') }), archiveError ? (_jsx("p", { role: "alert", className: "mt-3 text-sm text-destructive", children: archiveError })) : null] })) : null] }) }));
352
892
  }
353
- function VariantsSection({ productId }) {
893
+ function VariantsSection({ productId, readOnly = false }) {
354
894
  const t = useTranslation('catalog');
895
+ const { ask, dialog: removalDialog } = useConfirmRemoval();
355
896
  const [variants, setVariants] = useState([]);
356
897
  const [loading, setLoading] = useState(true);
357
898
  const [error, setError] = useState(null);
@@ -360,12 +901,11 @@ function VariantsSection({ productId }) {
360
901
  setLoading(true);
361
902
  setError(null);
362
903
  try {
363
- // The PDP returns variants nested in productDetail; admin needs a
364
- // standalone read to keep the forms quick. Foundation didn't ship
365
- // a GET /admin/.../variants, but the public productDetail under
366
- // /api/v1/catalog/products/<idOrSlug> includes them — use that.
367
- const res = await apiClient.get(`/api/v1/catalog/products/${productId}`);
368
- setVariants(res.data.variants ?? []);
904
+ // Issue #410 — the admin read answers every variant whatever the
905
+ // product's status or channels; the storefront's product read answers
906
+ // an inactive product 410 and an out-of-channel one 404.
907
+ const res = await apiClient.get(`/api/v1/admin/catalog/products/${productId}/variants`);
908
+ setVariants(res.data);
369
909
  }
370
910
  catch (err) {
371
911
  setError(err instanceof ApiError ? err.envelope.error.message : t('productEditor.variants.error.load'));
@@ -405,7 +945,7 @@ function VariantsSection({ productId }) {
405
945
  }
406
946
  }, [productId, refresh, t]);
407
947
  const handleDelete = useCallback(async (variantId, sku) => {
408
- if (!confirm(t('productEditor.variants.deleteConfirm', { sku })))
948
+ if (!(await ask(t('productEditor.variants.deleteConfirm', { sku }))))
409
949
  return;
410
950
  try {
411
951
  await apiClient.delete(`/api/v1/admin/catalog/products/${productId}/variants/${variantId}`);
@@ -415,10 +955,10 @@ function VariantsSection({ productId }) {
415
955
  catch (err) {
416
956
  setError(err instanceof ApiError ? err.envelope.error.message : t('productEditor.variants.error.delete'));
417
957
  }
418
- }, [productId, refresh, t]);
419
- return (_jsxs(Card, { className: "mt-4", children: [_jsx(CardHeader, { children: _jsx(CardTitle, { children: t('productEditor.variants.title') }) }), _jsxs(CardContent, { className: "space-y-4", children: [error ? (_jsx(Alert, { variant: "destructive", children: _jsx(AlertDescription, { children: error }) })) : null, info ? (_jsx(Alert, { children: _jsx(AlertDescription, { children: info }) })) : null, loading ? (_jsx("p", { className: "text-sm text-muted-foreground", children: t('productEditor.loading') })) : variants.length === 0 ? (_jsx("p", { className: "text-sm text-muted-foreground", children: t('productEditor.variants.empty') })) : (_jsxs(Table, { children: [_jsx(TableHeader, { children: _jsxs(TableRow, { children: [_jsx(TableHead, { children: t('productEditor.variants.column.sku') }), _jsx(TableHead, { children: t('productEditor.variants.column.attributes') }), _jsx(TableHead, { children: t('productEditor.variants.column.stock') }), _jsx(TableHead, { className: "w-[1%] whitespace-nowrap", children: t('productEditor.variants.column.actions') })] }) }), _jsx(TableBody, { children: variants.map((v) => (_jsxs(TableRow, { children: [_jsx(TableCell, { className: "font-mono", children: v.sku }), _jsx(TableCell, { children: Object.entries(v.variantAttributeValues)
958
+ }, [productId, refresh, ask, t]);
959
+ return (_jsxs(Card, { className: "mt-4", children: [_jsx(CardHeader, { children: _jsxs(CardTitle, { children: [t('productEditor.variants.title'), readOnly ? null : _jsx(ImmediateBadge, {})] }) }), _jsxs(CardContent, { className: "space-y-4", children: [error ? (_jsx(Alert, { variant: "destructive", children: _jsx(AlertDescription, { children: error }) })) : null, info ? (_jsx(Alert, { children: _jsx(AlertDescription, { children: info }) })) : null, loading ? (_jsx("p", { className: "text-sm text-muted-foreground", children: t('productEditor.loading') })) : variants.length === 0 ? (_jsx("p", { className: "text-sm text-muted-foreground", children: t('productEditor.variants.empty') })) : (_jsxs(Table, { children: [_jsx(TableHeader, { children: _jsxs(TableRow, { children: [_jsx(TableHead, { children: t('productEditor.variants.column.sku') }), _jsx(TableHead, { children: t('productEditor.variants.column.attributes') }), _jsx(TableHead, { children: t('productEditor.variants.column.stock') }), readOnly ? null : _jsx(TableHead, { className: "w-[1%] whitespace-nowrap", children: t('productEditor.variants.column.actions') })] }) }), _jsx(TableBody, { children: variants.map((v) => (_jsxs(TableRow, { children: [_jsx(TableCell, { className: "font-mono", children: v.sku }), _jsx(TableCell, { children: Object.entries(v.variantAttributeValues)
420
960
  .map(([k, val]) => `${k}=${String(val)}`)
421
- .join(', ') || '—' }), _jsx(TableCell, { children: v.stockLevel ?? '—' }), _jsx(TableCell, { children: _jsx(Button, { type: "button", variant: "destructive", size: "sm", onClick: () => void handleDelete(v.id, v.sku), children: t('productEditor.variants.action.delete') }) })] }, v.id))) })] })), _jsx(CreateVariantInline, { onCreate: handleCreate })] })] }));
961
+ .join(', ') || '—' }), _jsx(TableCell, { children: v.stockLevel ?? '—' }), readOnly ? null : (_jsx(TableCell, { children: _jsx(Button, { type: "button", variant: "destructive", size: "sm", className: "max-lg:min-h-11", onClick: () => void handleDelete(v.id, v.sku), children: t('productEditor.variants.action.delete') }) }))] }, v.id))) })] })), readOnly ? null : _jsx(CreateVariantInline, { onCreate: handleCreate })] }), removalDialog] }));
422
962
  }
423
963
  function CreateVariantInline({ onCreate, }) {
424
964
  const t = useTranslation('catalog');
@@ -434,298 +974,6 @@ function CreateVariantInline({ onCreate, }) {
434
974
  }, children: t('productEditor.variants.action.add') }) })] }));
435
975
  }
436
976
  // ---------------------------------------------------------------------------
437
- // Gallery section (T085) — admin CRUD for the Product's gallery items.
438
- // Foundation lacks an admin Asset upload endpoint, so for now the form
439
- // accepts an existing assetId; future work adds drag-and-drop on top of
440
- // an Assets module admin upload route.
441
- // ---------------------------------------------------------------------------
442
- const GALLERY_LABELS = ['base_image', 'small_image', 'thumbnail'];
443
- /** Immutable array move used by drag-and-drop / arrow reordering. */
444
- function moveGalleryItem(items, from, to) {
445
- if (to < 0 || to >= items.length || from === to)
446
- return items;
447
- const next = items.slice();
448
- const [moved] = next.splice(from, 1);
449
- if (moved === undefined)
450
- return items;
451
- next.splice(to, 0, moved);
452
- return next;
453
- }
454
- const GallerySection = forwardRef(function GallerySection({ productId }, ref) {
455
- const t = useTranslation('catalog');
456
- const [items, setItems] = useState([]);
457
- const [images, setImages] = useState([]);
458
- const [loading, setLoading] = useState(true);
459
- const [busy, setBusy] = useState(false);
460
- const [error, setError] = useState(null);
461
- const [info, setInfo] = useState(null);
462
- const [previewUrl, setPreviewUrl] = useState(null);
463
- const dragIdRef = useRef(null);
464
- // Server-truth snapshot (id order + labels) used to diff the staged edits
465
- // that the page-Save button flushes.
466
- const baselineRef = useRef('');
467
- const snapshot = (list) => JSON.stringify(list.map((g) => ({ id: g.id, labels: [...g.labels].sort() })));
468
- const refresh = useCallback(async () => {
469
- setLoading(true);
470
- setError(null);
471
- try {
472
- // Public PDP carries the resolved gallery (with asset urls) so
473
- // admins see the same shape customers do; the admin GET returns
474
- // bare ids without urls. The PDP also carries the product's flat
475
- // `assets` (legacy product_assets) — the storefront renders those
476
- // when the label-aware gallery is empty, so we surface them here
477
- // too, otherwise a product whose images live on product_assets
478
- // looks empty in the admin while showing fine on the storefront.
479
- const res = await apiClient.get(`/api/v1/catalog/products/${productId}`);
480
- const gallery = res.data.gallery ?? [];
481
- const mapped = gallery
482
- .slice()
483
- .sort((a, b) => a.position - b.position)
484
- .map((g) => ({
485
- id: g.id,
486
- productId,
487
- assetId: g.asset.id,
488
- position: g.position,
489
- labels: g.labels,
490
- asset: { url: g.asset.url, kind: g.asset.kind },
491
- }));
492
- setItems(mapped);
493
- baselineRef.current = snapshot(mapped);
494
- const assets = res.data.assets ?? [];
495
- setImages(assets
496
- .filter((a) => a.kind === 'image' || a.kind === 'video')
497
- .map((a) => ({
498
- id: a.id,
499
- kind: a.kind,
500
- url: a.url,
501
- altText: a.altText ?? null,
502
- })));
503
- }
504
- catch (err) {
505
- setError(err instanceof ApiError ? err.envelope.error.message : t('productEditor.gallery.error.load'));
506
- }
507
- finally {
508
- setLoading(false);
509
- }
510
- }, [productId, t]);
511
- useEffect(() => {
512
- void refresh();
513
- }, [refresh]);
514
- // --- Staged label edits: each label lives on at most one item; assigning it
515
- // to one item strips it from every other (radio semantics). Persisted on
516
- // page Save, so no per-row Save button and no "already taken" error. ---
517
- const assignLabel = useCallback((label, itemId) => {
518
- setInfo(null);
519
- setItems((prev) => prev.map((it) => {
520
- const without = it.labels.filter((l) => l !== label);
521
- return { ...it, labels: it.id === itemId ? [...without, label] : without };
522
- }));
523
- }, []);
524
- const clearLabel = useCallback((label) => {
525
- setInfo(null);
526
- setItems((prev) => prev.map((it) => ({ ...it, labels: it.labels.filter((l) => l !== label) })));
527
- }, []);
528
- // --- Staged reorder (array order === display order). ---
529
- const moveItem = useCallback((from, to) => {
530
- setInfo(null);
531
- setItems((prev) => moveGalleryItem(prev, from, to));
532
- }, []);
533
- const handleDrop = useCallback((index) => {
534
- const draggedId = dragIdRef.current;
535
- if (!draggedId)
536
- return;
537
- setItems((prev) => {
538
- const from = prev.findIndex((it) => it.id === draggedId);
539
- return from < 0 || from === index ? prev : moveGalleryItem(prev, from, index);
540
- });
541
- }, []);
542
- // --- Immediate CRUD (add / remove) — these hit the server directly and
543
- // re-load, which also resets the staged baseline. ---
544
- const handleCreate = useCallback(async (assetId) => {
545
- setBusy(true);
546
- try {
547
- await apiClient.post(`/api/v1/admin/catalog/products/${productId}/gallery`, {
548
- assetId,
549
- labels: [],
550
- });
551
- setInfo(t('productEditor.gallery.success.add'));
552
- await refresh();
553
- }
554
- catch (err) {
555
- setError(err instanceof ApiError ? err.envelope.error.message : t('productEditor.gallery.error.add'));
556
- }
557
- finally {
558
- setBusy(false);
559
- }
560
- }, [productId, refresh, t]);
561
- const handleDelete = useCallback(async (itemId) => {
562
- if (!confirm(t('productEditor.gallery.removeConfirm')))
563
- return;
564
- setBusy(true);
565
- try {
566
- await apiClient.delete(`/api/v1/admin/catalog/products/${productId}/gallery/${itemId}`);
567
- setInfo(t('productEditor.gallery.success.remove'));
568
- await refresh();
569
- }
570
- catch (err) {
571
- setError(err instanceof ApiError ? err.envelope.error.message : t('productEditor.gallery.error.delete'));
572
- }
573
- finally {
574
- setBusy(false);
575
- }
576
- }, [productId, refresh, t]);
577
- // --- Page-Save hook: flush staged label + order edits. Labels are patched
578
- // with `replace=true` so reassigning a label moves it atomically. ---
579
- const flushGallery = useCallback(async () => {
580
- const baseline = JSON.parse(baselineRef.current || '[]');
581
- const baseLabels = new Map(baseline.map((b) => [b.id, [...b.labels].sort().join(',')]));
582
- const changed = items.filter((it) => baseLabels.get(it.id) !== [...it.labels].sort().join(','));
583
- for (const it of changed) {
584
- await apiClient.patch(`/api/v1/admin/catalog/products/${productId}/gallery/${it.id}?replace=true`, { labels: it.labels });
585
- }
586
- const baseOrder = baseline.map((b) => b.id).join(',');
587
- const curOrder = items.map((it) => it.id).join(',');
588
- if (items.length > 0 && curOrder !== baseOrder) {
589
- await apiClient.put(`/api/v1/admin/catalog/products/${productId}/gallery/order`, {
590
- orderedGalleryItemIds: items.map((it) => it.id),
591
- });
592
- }
593
- if (changed.length > 0 || curOrder !== baseOrder) {
594
- await refresh();
595
- }
596
- }, [items, productId, refresh]);
597
- useImperativeHandle(ref, () => ({ flushGallery }), [flushGallery]);
598
- const disabled = busy || loading;
599
- return (_jsxs(Card, { className: "mt-4", children: [_jsx(CardHeader, { children: _jsx(CardTitle, { children: t('productEditor.gallery.title') }) }), _jsxs(CardContent, { className: "space-y-4", children: [error ? (_jsx(Alert, { variant: "destructive", children: _jsx(AlertDescription, { children: error }) })) : null, info ? (_jsx(Alert, { children: _jsx(AlertDescription, { children: info }) })) : null, !loading && images.length > 0 ? (_jsxs("div", { className: "space-y-2", children: [_jsx("p", { className: "text-sm font-medium", children: t('productEditor.gallery.productImages.title') }), _jsx("p", { className: "text-xs text-muted-foreground", children: t('productEditor.gallery.productImages.hint') }), _jsx("div", { className: "flex flex-wrap gap-2", children: images.map((img) => img.kind === 'video' ? (_jsx("video", { src: toAbsoluteAssetUrl(img.url), className: "h-20 w-20 rounded border object-cover", muted: true }, img.id)) : (_jsx("img", { src: toAbsoluteAssetUrl(img.url), alt: img.altText ?? '', className: "h-20 w-20 rounded border object-cover" }, img.id))) })] })) : null, loading ? (_jsx("p", { className: "text-sm text-muted-foreground", children: t('productEditor.loading') })) : items.length === 0 ? (_jsx("p", { className: "text-sm text-muted-foreground", children: t('productEditor.gallery.empty') })) : (_jsxs(_Fragment, { children: [_jsx("p", { className: "text-xs text-muted-foreground", children: t('productEditor.gallery.dragHint') }), _jsxs(Table, { children: [_jsx(TableHeader, { children: _jsxs(TableRow, { children: [_jsx(TableHead, { className: "w-8" }), _jsx(TableHead, { children: t('productEditor.gallery.column.preview') }), GALLERY_LABELS.map((label) => (_jsx(TableHead, { className: "text-center", children: t(`productEditor.gallery.label.${label}`) }, label))), _jsx(TableHead, { children: t('productEditor.gallery.column.assetId') }), _jsx(TableHead, { className: "w-[1%] whitespace-nowrap text-right", children: t('productEditor.gallery.column.actions') })] }) }), _jsx(TableBody, { children: items.map((item, index) => (_jsx(GalleryRow, { item: item, index: index, total: items.length, disabled: disabled, onAssignLabel: assignLabel, onClearLabel: clearLabel, onMove: moveItem, onDragStart: (id) => {
600
- dragIdRef.current = id;
601
- }, onDragOver: (e) => e.preventDefault(), onDrop: handleDrop, onDragEnd: () => {
602
- dragIdRef.current = null;
603
- }, onPreview: setPreviewUrl, onDelete: handleDelete }, item.id))) })] })] })), _jsx(CreateGalleryItemInline, { disabled: disabled, onCreate: handleCreate })] }), previewUrl ? (_jsxs("div", { className: "fixed inset-0 z-50 flex items-center justify-center bg-black/70 p-6", role: "dialog", "aria-modal": "true", "aria-label": t('productEditor.gallery.preview.title'), onClick: () => setPreviewUrl(null), children: [_jsx("img", { src: previewUrl, alt: t('productEditor.gallery.preview.title'), className: "max-h-full max-w-full rounded shadow-lg", onClick: (e) => e.stopPropagation() }), _jsx("button", { type: "button", className: "b2b-btn b2b-btn--sm", style: { position: 'fixed', top: 16, right: 16 }, onClick: () => setPreviewUrl(null), children: t('productEditor.gallery.preview.close') })] })) : null] }));
604
- });
605
- function GalleryRow({ item, index, total, disabled, onAssignLabel, onClearLabel, onMove, onDragStart, onDragOver, onDrop, onDragEnd, onPreview, onDelete, }) {
606
- const t = useTranslation('catalog');
607
- const url = item.asset?.url ? toAbsoluteAssetUrl(item.asset.url) : null;
608
- return (_jsxs(TableRow, { draggable: !disabled, onDragStart: () => onDragStart(item.id), onDragOver: onDragOver, onDrop: () => onDrop(index), onDragEnd: onDragEnd, children: [_jsx(TableCell, { className: "w-8", children: _jsx("span", { className: "inline-flex cursor-grab items-center text-muted-foreground", title: t('productEditor.gallery.dragHint'), "aria-hidden": true, children: _jsx(GripVertical, { className: "h-4 w-4" }) }) }), _jsx(TableCell, { children: url ? (item.asset?.kind === 'video' ? (_jsx("video", { src: url, className: "h-12 w-12 rounded border object-cover", muted: true })) : (_jsx("button", { type: "button", className: "block rounded border p-0", title: t('productEditor.gallery.preview.open'), onClick: () => onPreview(url), children: _jsx("img", { src: url, alt: "", className: "h-12 w-12 rounded object-cover" }) }))) : (_jsx("span", { className: "text-muted-foreground text-xs", children: "\u2014" })) }), GALLERY_LABELS.map((label) => {
609
- const checked = item.labels.includes(label);
610
- return (_jsx(TableCell, { className: "text-center", children: _jsx("input", { type: "radio", name: `gallery-label-${label}`, checked: checked, disabled: disabled, "aria-label": t(`productEditor.gallery.label.${label}`), onChange: () => { }, onClick: () => checked ? onClearLabel(label) : onAssignLabel(label, item.id) }) }, label));
611
- }), _jsxs(TableCell, { className: "font-mono text-xs", children: [item.assetId.slice(0, 8), "\u2026"] }), _jsxs(TableCell, { className: "space-x-2 whitespace-nowrap text-right", children: [_jsx(TouchReorderButtons, { disabled: disabled, onMoveUp: () => onMove(index, index - 1), onMoveDown: () => onMove(index, index + 1), disableUp: index === 0, disableDown: index === total - 1 }), _jsx(Button, { type: "button", size: "sm", variant: "destructive", disabled: disabled, onClick: () => void onDelete(item.id), children: t('productEditor.gallery.action.remove') })] })] }));
612
- }
613
- function CreateGalleryItemInline({ disabled, onCreate, }) {
614
- const t = useTranslation('catalog');
615
- const [assetId, setAssetId] = useState('');
616
- const [pickerOpen, setPickerOpen] = useState(false);
617
- const [pickedFilename, setPickedFilename] = useState(null);
618
- const onPick = (a) => {
619
- setAssetId(a.id);
620
- setPickedFilename(a.filename);
621
- setPickerOpen(false);
622
- };
623
- return (_jsxs("div", { className: "space-y-3 border-t pt-4", role: "group", "aria-label": t('productEditor.gallery.addTitle'), children: [pickerOpen ? (_jsx(AssetPicker, { acceptMimePrefix: "image/", allowUpload: true, onSelect: onPick, onClose: () => setPickerOpen(false) })) : null, _jsxs("div", { className: "grid gap-3 md:grid-cols-4", children: [_jsxs("div", { className: "space-y-1 md:col-span-3", children: [_jsx(Label, { htmlFor: "gasset", children: t('productEditor.gallery.field.asset') }), _jsxs("div", { className: "flex items-center gap-2", children: [_jsx(Input, { id: "gasset", value: pickedFilename ?? assetId, readOnly: true, placeholder: t('productEditor.gallery.field.noAsset') }), _jsx(Button, { type: "button", variant: "outline", size: "sm", onClick: () => setPickerOpen(true), children: t('productEditor.gallery.action.pickOrUpload') })] })] }), _jsx("div", { className: "flex items-end", children: _jsx(Button, { type: "button", disabled: disabled || !assetId, onClick: () => {
624
- if (!assetId)
625
- return;
626
- void onCreate(assetId).then(() => {
627
- setAssetId('');
628
- setPickedFilename(null);
629
- });
630
- }, children: t('productEditor.gallery.action.add') }) })] })] }));
631
- }
632
- function AttachmentsSection({ productId }) {
633
- const t = useTranslation('catalog');
634
- const [attachments, setAttachments] = useState([]);
635
- const [types, setTypes] = useState([]);
636
- const [loading, setLoading] = useState(true);
637
- const [error, setError] = useState(null);
638
- const [info, setInfo] = useState(null);
639
- const refresh = useCallback(async () => {
640
- setLoading(true);
641
- setError(null);
642
- try {
643
- const [detail, typesRes] = await Promise.all([
644
- apiClient.get(`/api/v1/catalog/products/${productId}`),
645
- apiClient.get('/api/v1/admin/catalog/attachment-types'),
646
- ]);
647
- const detailAttachments = detail.data.attachments ?? [];
648
- setAttachments(detailAttachments.map((a) => ({
649
- id: a.id,
650
- productId,
651
- assetId: a.asset.id,
652
- attachmentTypeId: a.type.id,
653
- name: a.name,
654
- description: a.description,
655
- position: a.position,
656
- asset: {
657
- url: a.asset.url,
658
- filename: a.asset.filename,
659
- mimeType: a.asset.mimeType,
660
- },
661
- type: { code: a.type.code, name: a.type.name },
662
- })));
663
- setTypes(typesRes.data);
664
- }
665
- catch (err) {
666
- setError(err instanceof ApiError ? err.envelope.error.message : t('productEditor.attachments.error.load'));
667
- }
668
- finally {
669
- setLoading(false);
670
- }
671
- }, [productId, t]);
672
- useEffect(() => {
673
- void refresh();
674
- }, [refresh]);
675
- const handleCreate = useCallback(async (input) => {
676
- try {
677
- await apiClient.post(`/api/v1/admin/catalog/products/${productId}/attachments`, {
678
- assetId: input.assetId,
679
- attachmentTypeId: input.attachmentTypeId,
680
- name: input.name,
681
- ...(input.description ? { description: input.description } : {}),
682
- });
683
- setInfo(t('productEditor.attachments.success.add'));
684
- await refresh();
685
- }
686
- catch (err) {
687
- setError(err instanceof ApiError ? err.envelope.error.message : t('productEditor.attachments.error.add'));
688
- }
689
- }, [productId, refresh, t]);
690
- const handleDelete = useCallback(async (attachmentId, name) => {
691
- if (!confirm(t('productEditor.attachments.deleteConfirm', { name })))
692
- return;
693
- try {
694
- await apiClient.delete(`/api/v1/admin/catalog/products/${productId}/attachments/${attachmentId}`);
695
- setInfo(t('productEditor.attachments.success.delete', { name }));
696
- await refresh();
697
- }
698
- catch (err) {
699
- setError(err instanceof ApiError ? err.envelope.error.message : t('productEditor.attachments.error.delete'));
700
- }
701
- }, [productId, refresh, t]);
702
- return (_jsxs(Card, { className: "mt-4", children: [_jsx(CardHeader, { children: _jsx(CardTitle, { children: t('productEditor.attachments.title') }) }), _jsxs(CardContent, { className: "space-y-4", children: [error ? (_jsx(Alert, { variant: "destructive", children: _jsx(AlertDescription, { children: error }) })) : null, info ? (_jsx(Alert, { children: _jsx(AlertDescription, { children: info }) })) : null, loading ? (_jsx("p", { className: "text-sm text-muted-foreground", children: t('productEditor.loading') })) : attachments.length === 0 ? (_jsx("p", { className: "text-sm text-muted-foreground", children: t('productEditor.attachments.empty') })) : (_jsxs(Table, { children: [_jsx(TableHeader, { children: _jsxs(TableRow, { children: [_jsx(TableHead, { children: t('productEditor.attachments.column.type') }), _jsx(TableHead, { children: t('productEditor.attachments.column.name') }), _jsx(TableHead, { children: t('productEditor.attachments.column.description') }), _jsx(TableHead, { children: t('productEditor.attachments.column.file') }), _jsx(TableHead, { className: "w-[1%] whitespace-nowrap", children: t('productEditor.attachments.column.actions') })] }) }), _jsx(TableBody, { children: attachments.map((att) => (_jsxs(TableRow, { children: [_jsx(TableCell, { children: att.type?.name['en-US'] ?? att.type?.code ?? '—' }), _jsx(TableCell, { className: "font-medium", children: att.name }), _jsx(TableCell, { className: "text-muted-foreground", children: att.description ?? '—' }), _jsx(TableCell, { children: att.asset?.url ? (_jsx("a", { href: att.asset.url, target: "_blank", rel: "noopener", className: "text-xs underline", children: att.asset.filename })) : ('—') }), _jsx(TableCell, { children: _jsx(Button, { type: "button", size: "sm", variant: "destructive", onClick: () => void handleDelete(att.id, att.name), children: t('productEditor.attachments.action.delete') }) })] }, att.id))) })] })), _jsx(CreateAttachmentInline, { types: types, onCreate: handleCreate })] })] }));
703
- }
704
- function CreateAttachmentInline({ types, onCreate, }) {
705
- const [assetId, setAssetId] = useState('');
706
- const [attachmentTypeId, setAttachmentTypeId] = useState('');
707
- const [name, setName] = useState('');
708
- const [description, setDescription] = useState('');
709
- const [pickerOpen, setPickerOpen] = useState(false);
710
- const [pickedFilename, setPickedFilename] = useState(null);
711
- const t = useTranslation('catalog');
712
- return (_jsxs("div", { className: "space-y-3 border-t pt-4", role: "group", "aria-label": t('productEditor.attachments.addTitle'), children: [pickerOpen ? (_jsx(AssetPicker, { allowUpload: true, onSelect: (a) => {
713
- setAssetId(a.id);
714
- setPickedFilename(a.filename);
715
- setPickerOpen(false);
716
- }, onClose: () => setPickerOpen(false) })) : null, _jsxs("div", { className: "grid gap-3 md:grid-cols-4", children: [_jsxs("div", { className: "space-y-1", children: [_jsx(Label, { htmlFor: "aasset", children: t('productEditor.attachments.field.asset') }), _jsxs("div", { className: "flex items-center gap-2", children: [_jsx(Input, { id: "aasset", value: pickedFilename ?? assetId, readOnly: true, placeholder: t('productEditor.attachments.field.noAsset') }), _jsx(Button, { type: "button", variant: "outline", size: "sm", onClick: () => setPickerOpen(true), children: t('productEditor.attachments.action.pickOrUpload') })] })] }), _jsxs("div", { className: "space-y-1", children: [_jsx(Label, { htmlFor: "atype", children: t('productEditor.attachments.field.type') }), _jsxs(Select, { id: "atype", value: attachmentTypeId, onChange: (e) => setAttachmentTypeId(e.target.value), children: [_jsx("option", { value: "", children: "\u2014" }), types.map((typ) => (_jsx("option", { value: typ.id, children: typ.name['en-US'] ?? typ.code }, typ.id)))] })] }), _jsxs("div", { className: "space-y-1", children: [_jsx(Label, { htmlFor: "aname", children: t('productEditor.attachments.field.name') }), _jsx(Input, { id: "aname", value: name, onChange: (e) => setName(e.target.value), placeholder: t('productEditor.attachments.field.namePlaceholder') })] }), _jsxs("div", { className: "space-y-1", children: [_jsx(Label, { htmlFor: "adesc", children: t('productEditor.attachments.field.description') }), _jsx(Input, { id: "adesc", value: description, onChange: (e) => setDescription(e.target.value), placeholder: t('productEditor.attachments.field.descriptionPlaceholder') })] }), _jsx("div", { className: "md:col-span-4", children: _jsx(Button, { type: "button", onClick: () => {
717
- if (!assetId || !attachmentTypeId || !name)
718
- return;
719
- void onCreate({ assetId, attachmentTypeId, name, description }).then(() => {
720
- setAssetId('');
721
- setPickedFilename(null);
722
- setAttachmentTypeId('');
723
- setName('');
724
- setDescription('');
725
- });
726
- }, children: t('productEditor.attachments.action.add') }) })] })] }));
727
- }
728
- // ---------------------------------------------------------------------------
729
977
  // Product Links section (T109, US4) — Related / Up-sell / Cross-sell.
730
978
  // Three sub-lists, one product picker (paste id) + kind selector +
731
979
  // "Add" button per kind. Backend bulkCreate is all-or-nothing and
@@ -733,13 +981,12 @@ function CreateAttachmentInline({ types, onCreate, }) {
733
981
  // ---------------------------------------------------------------------------
734
982
  const LINK_KINDS = ['related', 'up_sell', 'cross_sell'];
735
983
  function pickProductName(name, fallback) {
736
- if (!name)
737
- return fallback;
738
- return name['en-US'] ?? Object.values(name)[0] ?? fallback;
984
+ return typeof name === 'string' && name !== '' ? name : fallback;
739
985
  }
740
986
  const TARGETS_BATCH_PAGE_SIZE = 200;
741
- function ProductLinksSection({ productId }) {
987
+ function ProductLinksSection({ productId, readOnly = false }) {
742
988
  const t = useTranslation('catalog');
989
+ const { ask, dialog: removalDialog } = useConfirmRemoval();
743
990
  const [links, setLinks] = useState([]);
744
991
  const [targetsById, setTargetsById] = useState(() => new Map());
745
992
  const [loading, setLoading] = useState(true);
@@ -801,7 +1048,7 @@ function ProductLinksSection({ productId }) {
801
1048
  }
802
1049
  }, [productId, refresh, t]);
803
1050
  const handleDelete = useCallback(async (linkId) => {
804
- if (!confirm(t('productEditor.links.removeConfirm')))
1051
+ if (!(await ask(t('productEditor.links.removeConfirm'))))
805
1052
  return;
806
1053
  try {
807
1054
  await apiClient.delete(`/api/v1/admin/catalog/products/${productId}/links/${linkId}`);
@@ -811,7 +1058,7 @@ function ProductLinksSection({ productId }) {
811
1058
  catch (err) {
812
1059
  setError(err instanceof ApiError ? err.envelope.error.message : t('productEditor.links.error.delete'));
813
1060
  }
814
- }, [productId, refresh, t]);
1061
+ }, [productId, refresh, ask, t]);
815
1062
  const byKind = useMemo(() => {
816
1063
  const result = {
817
1064
  related: [],
@@ -825,14 +1072,16 @@ function ProductLinksSection({ productId }) {
825
1072
  }
826
1073
  return result;
827
1074
  }, [links]);
828
- return (_jsxs(Card, { className: "mt-4", children: [_jsx(CardHeader, { children: _jsx(CardTitle, { children: t('productEditor.links.title') }) }), _jsxs(CardContent, { className: "space-y-4", children: [error ? (_jsx(Alert, { variant: "destructive", children: _jsx(AlertDescription, { children: error }) })) : null, info ? (_jsx(Alert, { children: _jsx(AlertDescription, { children: info }) })) : null, loading ? (_jsx("p", { className: "text-sm text-muted-foreground", children: t('productEditor.loading') })) : (_jsx("div", { className: "space-y-6", children: LINK_KINDS.map((kind) => (_jsxs("div", { className: "space-y-2", children: [_jsxs("h3", { className: "text-sm font-medium uppercase tracking-wide", children: [t(`productEditor.links.kind.${kind}`), " (", byKind[kind].length, ")"] }), byKind[kind].length === 0 ? (_jsx("p", { className: "text-xs text-muted-foreground", children: t('productEditor.links.empty') })) : (_jsxs(Table, { children: [_jsx(TableHeader, { children: _jsxs(TableRow, { children: [_jsx(TableHead, { children: t('productEditor.links.column.target') }), _jsx(TableHead, { children: t('productEditor.links.column.sku') }), _jsx(TableHead, { children: t('productEditor.links.column.position') }), _jsx(TableHead, { className: "w-[1%] whitespace-nowrap", children: t('productEditor.links.column.actions') })] }) }), _jsx(TableBody, { children: byKind[kind].map((link) => {
1075
+ return (_jsxs(Card, { className: "mt-4", children: [_jsx(CardHeader, { children: _jsxs(CardTitle, { children: [t('productEditor.links.title'), readOnly ? null : _jsx(ImmediateBadge, {})] }) }), _jsxs(CardContent, { className: "space-y-4", children: [error ? (_jsx(Alert, { variant: "destructive", children: _jsx(AlertDescription, { children: error }) })) : null, info ? (_jsx(Alert, { children: _jsx(AlertDescription, { children: info }) })) : null, loading ? (_jsx("p", { className: "text-sm text-muted-foreground", children: t('productEditor.loading') })) : (_jsx("div", { className: "space-y-6", children: LINK_KINDS.map((kind) => (_jsxs("div", { className: "space-y-2", children: [_jsxs("h3", { className: "text-sm font-medium uppercase tracking-wide", children: [t(`productEditor.links.kind.${kind}`), " (", byKind[kind].length, ")"] }), byKind[kind].length === 0 ? (_jsx("p", { className: "text-xs text-muted-foreground", children: t('productEditor.links.empty') })) : (_jsxs(Table, { children: [_jsx(TableHeader, { children: _jsxs(TableRow, { children: [_jsx(TableHead, { children: t('productEditor.links.column.target') }), _jsx(TableHead, { children: t('productEditor.links.column.sku') }), _jsx(TableHead, { children: t('productEditor.links.column.position') }), readOnly ? null : _jsx(TableHead, { className: "w-[1%] whitespace-nowrap", children: t('productEditor.links.column.actions') })] }) }), _jsx(TableBody, { children: byKind[kind].map((link) => {
829
1076
  const target = targetsById.get(link.targetProductId);
830
1077
  const isMissing = !target;
1078
+ // `inactive` is plain off; archived is its own fact.
831
1079
  const isInactive = target?.status === 'inactive';
832
- return (_jsxs(TableRow, { children: [_jsx(TableCell, { children: _jsxs("div", { className: "flex items-center gap-2", children: [_jsx("span", { className: isMissing || isInactive ? 'text-muted-foreground' : '', children: target
1080
+ const isArchived = target?.archivedAt != null;
1081
+ return (_jsxs(TableRow, { children: [_jsx(TableCell, { children: _jsxs("div", { className: "flex items-center gap-2", children: [_jsx("span", { className: isMissing || isInactive || isArchived ? 'text-muted-foreground' : '', children: target
833
1082
  ? pickProductName(target.name, target.slug)
834
- : `${link.targetProductId.slice(0, 8)}…` }), isMissing ? (_jsx("span", { className: "rounded border px-1.5 py-0.5 text-[10px] uppercase text-muted-foreground", children: t('productEditor.links.badge.missing') })) : null, isInactive ? (_jsx("span", { className: "rounded border px-1.5 py-0.5 text-[10px] uppercase text-muted-foreground", children: t('productEditor.links.badge.inactive') })) : null] }) }), _jsx(TableCell, { className: "font-mono text-xs", children: target?.sku ?? '—' }), _jsx(TableCell, { children: link.position }), _jsx(TableCell, { children: _jsx(Button, { type: "button", size: "sm", variant: "destructive", onClick: () => void handleDelete(link.id), children: t('productEditor.links.action.remove') }) })] }, link.id));
835
- }) })] }))] }, kind))) })), _jsx(CreateProductLinkInline, { onCreate: handleCreate, sourceProductId: productId })] })] }));
1083
+ : `${link.targetProductId.slice(0, 8)}…` }), isMissing ? (_jsx("span", { className: "rounded border px-1.5 py-0.5 text-[10px] uppercase text-muted-foreground", children: t('productEditor.links.badge.missing') })) : null, isInactive ? (_jsx("span", { className: "rounded border px-1.5 py-0.5 text-[10px] uppercase text-muted-foreground", children: t('productEditor.links.badge.inactive') })) : null, isArchived ? (_jsx("span", { className: "rounded border px-1.5 py-0.5 text-[10px] uppercase text-muted-foreground", children: t('productEditor.links.badge.archived') })) : null] }) }), _jsx(TableCell, { className: "font-mono text-xs", children: target?.sku ?? '—' }), _jsx(TableCell, { children: link.position }), readOnly ? null : (_jsx(TableCell, { children: _jsx(Button, { type: "button", size: "sm", className: "max-lg:min-h-11", variant: "destructive", onClick: () => void handleDelete(link.id), children: t('productEditor.links.action.remove') }) }))] }, link.id));
1084
+ }) })] }))] }, kind))) })), readOnly ? null : _jsx(CreateProductLinkInline, { onCreate: handleCreate, sourceProductId: productId })] }), removalDialog] }));
836
1085
  }
837
1086
  function CreateProductLinkInline({ onCreate, sourceProductId, }) {
838
1087
  const t = useTranslation('catalog');
@@ -846,8 +1095,9 @@ function CreateProductLinkInline({ onCreate, sourceProductId, }) {
846
1095
  });
847
1096
  }, children: t('productEditor.links.action.add') }) })] }));
848
1097
  }
849
- function GroupedItemsSection({ productId }) {
1098
+ function GroupedItemsSection({ productId, readOnly = false }) {
850
1099
  const t = useTranslation('catalog');
1100
+ const { ask, dialog: removalDialog } = useConfirmRemoval();
851
1101
  const [items, setItems] = useState([]);
852
1102
  const [loading, setLoading] = useState(true);
853
1103
  const [error, setError] = useState(null);
@@ -885,7 +1135,7 @@ function GroupedItemsSection({ productId }) {
885
1135
  }
886
1136
  }, [productId, refresh, t]);
887
1137
  const handleDelete = useCallback(async (itemId) => {
888
- if (!confirm(t('productEditor.grouped.removeConfirm')))
1138
+ if (!(await ask(t('productEditor.grouped.removeConfirm'))))
889
1139
  return;
890
1140
  try {
891
1141
  await apiClient.delete(`/api/v1/admin/catalog/products/${productId}/grouped-items/${itemId}`);
@@ -895,8 +1145,8 @@ function GroupedItemsSection({ productId }) {
895
1145
  catch (err) {
896
1146
  setError(err instanceof ApiError ? err.envelope.error.message : t('productEditor.grouped.error.delete'));
897
1147
  }
898
- }, [productId, refresh, t]);
899
- return (_jsxs(Card, { className: "mt-4", children: [_jsx(CardHeader, { children: _jsx(CardTitle, { children: t('productEditor.grouped.title') }) }), _jsxs(CardContent, { className: "space-y-4", children: [error ? (_jsx(Alert, { variant: "destructive", children: _jsx(AlertDescription, { children: error }) })) : null, info ? (_jsx(Alert, { children: _jsx(AlertDescription, { children: info }) })) : null, loading ? (_jsx("p", { className: "text-sm text-muted-foreground", children: t('productEditor.loading') })) : items.length === 0 ? (_jsx("p", { className: "text-sm text-muted-foreground", children: t('productEditor.grouped.empty') })) : (_jsxs(Table, { children: [_jsx(TableHeader, { children: _jsxs(TableRow, { children: [_jsx(TableHead, { children: t('productEditor.grouped.column.child') }), _jsx(TableHead, { children: t('productEditor.grouped.column.quantity') }), _jsx(TableHead, { children: t('productEditor.grouped.column.position') }), _jsx(TableHead, { className: "w-[1%] whitespace-nowrap", children: t('productEditor.grouped.column.actions') })] }) }), _jsx(TableBody, { children: items.map((item) => (_jsxs(TableRow, { children: [_jsx(TableCell, { className: "font-mono text-xs", children: item.childProductId }), _jsx(TableCell, { children: item.quantity }), _jsx(TableCell, { children: item.position }), _jsx(TableCell, { children: _jsx(Button, { type: "button", size: "sm", variant: "destructive", onClick: () => void handleDelete(item.id), children: t('productEditor.grouped.action.remove') }) })] }, item.id))) })] })), _jsx(CreateGroupedItemInline, { onCreate: handleCreate })] })] }));
1148
+ }, [productId, refresh, ask, t]);
1149
+ return (_jsxs(Card, { className: "mt-4", children: [_jsx(CardHeader, { children: _jsxs(CardTitle, { children: [t('productEditor.grouped.title'), readOnly ? null : _jsx(ImmediateBadge, {})] }) }), _jsxs(CardContent, { className: "space-y-4", children: [error ? (_jsx(Alert, { variant: "destructive", children: _jsx(AlertDescription, { children: error }) })) : null, info ? (_jsx(Alert, { children: _jsx(AlertDescription, { children: info }) })) : null, loading ? (_jsx("p", { className: "text-sm text-muted-foreground", children: t('productEditor.loading') })) : items.length === 0 ? (_jsx("p", { className: "text-sm text-muted-foreground", children: t('productEditor.grouped.empty') })) : (_jsxs(Table, { children: [_jsx(TableHeader, { children: _jsxs(TableRow, { children: [_jsx(TableHead, { children: t('productEditor.grouped.column.child') }), _jsx(TableHead, { children: t('productEditor.grouped.column.quantity') }), _jsx(TableHead, { children: t('productEditor.grouped.column.position') }), readOnly ? null : _jsx(TableHead, { className: "w-[1%] whitespace-nowrap", children: t('productEditor.grouped.column.actions') })] }) }), _jsx(TableBody, { children: items.map((item) => (_jsxs(TableRow, { children: [_jsx(TableCell, { className: "font-mono text-xs", children: item.childProductId }), _jsx(TableCell, { children: item.quantity }), _jsx(TableCell, { children: item.position }), readOnly ? null : (_jsx(TableCell, { children: _jsx(Button, { type: "button", size: "sm", className: "max-lg:min-h-11", variant: "destructive", onClick: () => void handleDelete(item.id), children: t('productEditor.grouped.action.remove') }) }))] }, item.id))) })] })), readOnly ? null : _jsx(CreateGroupedItemInline, { onCreate: handleCreate })] }), removalDialog] }));
900
1150
  }
901
1151
  function CreateGroupedItemInline({ onCreate, }) {
902
1152
  const t = useTranslation('catalog');
@@ -911,8 +1161,9 @@ function CreateGroupedItemInline({ onCreate, }) {
911
1161
  });
912
1162
  }, children: t('productEditor.grouped.action.add') }) })] }));
913
1163
  }
914
- function BundleSlotsSection({ productId }) {
1164
+ function BundleSlotsSection({ productId, readOnly = false }) {
915
1165
  const t = useTranslation('catalog');
1166
+ const { ask, dialog: removalDialog } = useConfirmRemoval();
916
1167
  const [slots, setSlots] = useState([]);
917
1168
  const [loading, setLoading] = useState(true);
918
1169
  const [error, setError] = useState(null);
@@ -955,7 +1206,7 @@ function BundleSlotsSection({ productId }) {
955
1206
  }
956
1207
  }, [productId, refresh, t]);
957
1208
  const handleDeleteSlot = useCallback(async (slotId) => {
958
- if (!confirm(t('productEditor.bundle.removeSlotConfirm')))
1209
+ if (!(await ask(t('productEditor.bundle.removeSlotConfirm'))))
959
1210
  return;
960
1211
  try {
961
1212
  await apiClient.delete(`/api/v1/admin/catalog/products/${productId}/bundle-slots/${slotId}`);
@@ -965,7 +1216,7 @@ function BundleSlotsSection({ productId }) {
965
1216
  catch (err) {
966
1217
  setError(err instanceof ApiError ? err.envelope.error.message : t('productEditor.bundle.error.deleteSlot'));
967
1218
  }
968
- }, [productId, refresh, t]);
1219
+ }, [productId, refresh, ask, t]);
969
1220
  const handleAddOption = useCallback(async (slotId, optionProductId) => {
970
1221
  if (!optionProductId)
971
1222
  return;
@@ -979,7 +1230,7 @@ function BundleSlotsSection({ productId }) {
979
1230
  }
980
1231
  }, [productId, refresh, t]);
981
1232
  const handleRemoveOption = useCallback(async (slotId, optionId) => {
982
- if (!confirm(t('productEditor.bundle.removeOptionConfirm')))
1233
+ if (!(await ask(t('productEditor.bundle.removeOptionConfirm'))))
983
1234
  return;
984
1235
  try {
985
1236
  await apiClient.delete(`/api/v1/admin/catalog/products/${productId}/bundle-slots/${slotId}/options/${optionId}`);
@@ -989,21 +1240,21 @@ function BundleSlotsSection({ productId }) {
989
1240
  catch (err) {
990
1241
  setError(err instanceof ApiError ? err.envelope.error.message : t('productEditor.bundle.error.deleteOption'));
991
1242
  }
992
- }, [productId, refresh, t]);
993
- return (_jsxs(Card, { className: "mt-4", children: [_jsx(CardHeader, { children: _jsx(CardTitle, { children: t('productEditor.bundle.title') }) }), _jsxs(CardContent, { className: "space-y-4", children: [error ? (_jsx(Alert, { variant: "destructive", children: _jsx(AlertDescription, { children: error }) })) : null, info ? (_jsx(Alert, { children: _jsx(AlertDescription, { children: info }) })) : null, loading ? (_jsx("p", { className: "text-sm text-muted-foreground", children: t('productEditor.loading') })) : slots.length === 0 ? (_jsx("p", { className: "text-sm text-muted-foreground", children: t('productEditor.bundle.empty') })) : (_jsx("div", { className: "space-y-4", children: slots.map((slot) => (_jsx(BundleSlotCard, { slot: slot, onAddOption: handleAddOption, onRemoveOption: handleRemoveOption, onDeleteSlot: handleDeleteSlot }, slot.id))) })), _jsx(CreateBundleSlotInline, { onCreate: handleCreateSlot })] })] }));
1243
+ }, [productId, refresh, ask, t]);
1244
+ return (_jsxs(Card, { className: "mt-4", children: [_jsx(CardHeader, { children: _jsxs(CardTitle, { children: [t('productEditor.bundle.title'), readOnly ? null : _jsx(ImmediateBadge, {})] }) }), _jsxs(CardContent, { className: "space-y-4", children: [error ? (_jsx(Alert, { variant: "destructive", children: _jsx(AlertDescription, { children: error }) })) : null, info ? (_jsx(Alert, { children: _jsx(AlertDescription, { children: info }) })) : null, loading ? (_jsx("p", { className: "text-sm text-muted-foreground", children: t('productEditor.loading') })) : slots.length === 0 ? (_jsx("p", { className: "text-sm text-muted-foreground", children: t('productEditor.bundle.empty') })) : (_jsx("div", { className: "space-y-4", children: slots.map((slot) => (_jsx(BundleSlotCard, { slot: slot, onAddOption: handleAddOption, onRemoveOption: handleRemoveOption, onDeleteSlot: handleDeleteSlot, readOnly: readOnly }, slot.id))) })), readOnly ? null : _jsx(CreateBundleSlotInline, { onCreate: handleCreateSlot })] }), removalDialog] }));
994
1245
  }
995
- function BundleSlotCard({ slot, onAddOption, onRemoveOption, onDeleteSlot, }) {
1246
+ function BundleSlotCard({ slot, onAddOption, onRemoveOption, onDeleteSlot, readOnly = false, }) {
996
1247
  const t = useTranslation('catalog');
997
1248
  const [optionId, setOptionId] = useState('');
998
1249
  return (_jsxs("div", { className: "rounded border p-3", children: [_jsxs("div", { className: "flex items-center justify-between", children: [_jsxs("h3", { className: "font-medium", children: [slot.name['en-US'] ?? Object.values(slot.name)[0] ?? '—', ' ', _jsx("span", { className: "text-xs text-muted-foreground", children: t('productEditor.bundle.slotMeta', {
999
1250
  min: slot.minQuantity,
1000
1251
  max: slot.maxQuantity,
1001
1252
  position: slot.position,
1002
- }) })] }), _jsx(Button, { type: "button", size: "sm", variant: "destructive", onClick: () => void onDeleteSlot(slot.id), children: t('productEditor.bundle.action.deleteSlot') })] }), _jsx("div", { className: "mt-2", children: slot.options.length === 0 ? (_jsx("p", { className: "text-xs text-muted-foreground", children: t('productEditor.bundle.optionsEmpty') })) : (_jsxs(Table, { children: [_jsx(TableHeader, { children: _jsxs(TableRow, { children: [_jsx(TableHead, { children: t('productEditor.bundle.column.optionProductId') }), _jsx(TableHead, { children: t('productEditor.bundle.column.defaultQuantity') }), _jsx(TableHead, { children: t('productEditor.bundle.column.position') }), _jsx(TableHead, { className: "w-[1%] whitespace-nowrap", children: t('productEditor.bundle.column.actions') })] }) }), _jsx(TableBody, { children: slot.options.map((opt) => (_jsxs(TableRow, { children: [_jsx(TableCell, { className: "font-mono text-xs", children: opt.optionProductId }), _jsx(TableCell, { children: opt.defaultQuantity }), _jsx(TableCell, { children: opt.position }), _jsx(TableCell, { children: _jsx(Button, { type: "button", size: "sm", variant: "destructive", onClick: () => void onRemoveOption(slot.id, opt.id), children: t('productEditor.bundle.action.removeOption') }) })] }, opt.id))) })] })) }), _jsxs("div", { className: "mt-3 flex items-end gap-2", children: [_jsxs("div", { className: "flex-1 space-y-1", children: [_jsx(Label, { htmlFor: `opt-${slot.id}`, children: t('productEditor.bundle.column.optionProductId') }), _jsx(ProductPicker, { id: `opt-${slot.id}`, mode: "select", value: optionId || null, onChange: (v) => setOptionId(v ?? '') })] }), _jsx(Button, { type: "button", onClick: () => {
1253
+ }) })] }), readOnly ? null : (_jsx(Button, { type: "button", size: "sm", className: "max-lg:min-h-11", variant: "destructive", onClick: () => void onDeleteSlot(slot.id), children: t('productEditor.bundle.action.deleteSlot') }))] }), _jsx("div", { className: "mt-2", children: slot.options.length === 0 ? (_jsx("p", { className: "text-xs text-muted-foreground", children: t('productEditor.bundle.optionsEmpty') })) : (_jsxs(Table, { children: [_jsx(TableHeader, { children: _jsxs(TableRow, { children: [_jsx(TableHead, { children: t('productEditor.bundle.column.optionProductId') }), _jsx(TableHead, { children: t('productEditor.bundle.column.defaultQuantity') }), _jsx(TableHead, { children: t('productEditor.bundle.column.position') }), readOnly ? null : _jsx(TableHead, { className: "w-[1%] whitespace-nowrap", children: t('productEditor.bundle.column.actions') })] }) }), _jsx(TableBody, { children: slot.options.map((opt) => (_jsxs(TableRow, { children: [_jsx(TableCell, { className: "font-mono text-xs", children: opt.optionProductId }), _jsx(TableCell, { children: opt.defaultQuantity }), _jsx(TableCell, { children: opt.position }), readOnly ? null : (_jsx(TableCell, { children: _jsx(Button, { type: "button", size: "sm", className: "max-lg:min-h-11", variant: "destructive", onClick: () => void onRemoveOption(slot.id, opt.id), children: t('productEditor.bundle.action.removeOption') }) }))] }, opt.id))) })] })) }), readOnly ? null : (_jsxs("div", { className: "mt-3 flex items-end gap-2", children: [_jsxs("div", { className: "flex-1 space-y-1", children: [_jsx(Label, { htmlFor: `opt-${slot.id}`, children: t('productEditor.bundle.column.optionProductId') }), _jsx(ProductPicker, { id: `opt-${slot.id}`, mode: "select", value: optionId || null, onChange: (v) => setOptionId(v ?? '') })] }), _jsx(Button, { type: "button", onClick: () => {
1003
1254
  void onAddOption(slot.id, optionId).then(() => {
1004
1255
  setOptionId('');
1005
1256
  });
1006
- }, children: t('productEditor.bundle.action.addOption') })] })] }));
1257
+ }, children: t('productEditor.bundle.action.addOption') })] }))] }));
1007
1258
  }
1008
1259
  function CreateBundleSlotInline({ onCreate, }) {
1009
1260
  const t = useTranslation('catalog');