@endora-commerce/mod-catalog 0.109.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 (519) 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 +13 -4
  6. package/dist/admin/components/PackagingUnitsEditor.d.ts.map +1 -1
  7. package/dist/admin/components/PackagingUnitsEditor.js +20 -85
  8. package/dist/admin/components/PackagingUnitsEditor.js.map +1 -1
  9. package/dist/admin/components/ProductAttachmentsSection.d.ts +1 -3
  10. package/dist/admin/components/ProductAttachmentsSection.d.ts.map +1 -1
  11. package/dist/admin/components/ProductAttachmentsSection.js +59 -98
  12. package/dist/admin/components/ProductAttachmentsSection.js.map +1 -1
  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 +2 -13
  22. package/dist/admin/components/ProductGallerySection.d.ts.map +1 -1
  23. package/dist/admin/components/ProductGallerySection.js +98 -354
  24. package/dist/admin/components/ProductGallerySection.js.map +1 -1
  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 -268
  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 +13 -1
  34. package/dist/admin/components/ProductScopeOverview.d.ts.map +1 -1
  35. package/dist/admin/components/ProductScopeOverview.js +51 -36
  36. package/dist/admin/components/ProductScopeOverview.js.map +1 -1
  37. package/dist/admin/components/ProductUrlRedirects.d.ts +15 -0
  38. package/dist/admin/components/ProductUrlRedirects.d.ts.map +1 -0
  39. package/dist/admin/components/ProductUrlRedirects.js +70 -0
  40. package/dist/admin/components/ProductUrlRedirects.js.map +1 -0
  41. package/dist/admin/components/editor/DetailsTab.d.ts +30 -0
  42. package/dist/admin/components/editor/DetailsTab.d.ts.map +1 -0
  43. package/dist/admin/components/editor/DetailsTab.js +59 -0
  44. package/dist/admin/components/editor/DetailsTab.js.map +1 -0
  45. package/dist/admin/components/editor/ImmediateBadge.d.ts +21 -0
  46. package/dist/admin/components/editor/ImmediateBadge.d.ts.map +1 -0
  47. package/dist/admin/components/editor/ImmediateBadge.js +21 -0
  48. package/dist/admin/components/editor/ImmediateBadge.js.map +1 -0
  49. package/dist/admin/components/editor/confirm-removal.d.ts +13 -0
  50. package/dist/admin/components/editor/confirm-removal.d.ts.map +1 -0
  51. package/dist/admin/components/editor/confirm-removal.js +33 -0
  52. package/dist/admin/components/editor/confirm-removal.js.map +1 -0
  53. package/dist/admin/components/editor/editor-context.d.ts +53 -0
  54. package/dist/admin/components/editor/editor-context.d.ts.map +1 -0
  55. package/dist/admin/components/editor/editor-context.js +88 -0
  56. package/dist/admin/components/editor/editor-context.js.map +1 -0
  57. package/dist/admin/components/editor/scoped-controls.d.ts +46 -0
  58. package/dist/admin/components/editor/scoped-controls.d.ts.map +1 -0
  59. package/dist/admin/components/editor/scoped-controls.js +64 -0
  60. package/dist/admin/components/editor/scoped-controls.js.map +1 -0
  61. package/dist/admin/index.d.ts +1 -1
  62. package/dist/admin/index.d.ts.map +1 -1
  63. package/dist/admin/index.js +11 -0
  64. package/dist/admin/index.js.map +1 -1
  65. package/dist/admin/lib/attribute-scope.d.ts +17 -14
  66. package/dist/admin/lib/attribute-scope.d.ts.map +1 -1
  67. package/dist/admin/lib/attribute-scope.js +12 -9
  68. package/dist/admin/lib/attribute-scope.js.map +1 -1
  69. package/dist/admin/lib/editor-scope.d.ts +35 -0
  70. package/dist/admin/lib/editor-scope.d.ts.map +1 -0
  71. package/dist/admin/lib/editor-scope.js +114 -0
  72. package/dist/admin/lib/editor-scope.js.map +1 -0
  73. package/dist/admin/lib/order-minimum-input.d.ts +13 -0
  74. package/dist/admin/lib/order-minimum-input.d.ts.map +1 -0
  75. package/dist/admin/lib/order-minimum-input.js +16 -0
  76. package/dist/admin/lib/order-minimum-input.js.map +1 -0
  77. package/dist/admin/lib/product-labels.d.ts +0 -2
  78. package/dist/admin/lib/product-labels.d.ts.map +1 -1
  79. package/dist/admin/lib/product-labels.js +1 -5
  80. package/dist/admin/lib/product-labels.js.map +1 -1
  81. package/dist/admin/lib/product-scopes-api.d.ts +5 -22
  82. package/dist/admin/lib/product-scopes-api.d.ts.map +1 -1
  83. package/dist/admin/lib/product-scopes-api.js +1 -45
  84. package/dist/admin/lib/product-scopes-api.js.map +1 -1
  85. package/dist/admin/lib/product-url-keys-api.d.ts +4 -27
  86. package/dist/admin/lib/product-url-keys-api.d.ts.map +1 -1
  87. package/dist/admin/lib/product-url-keys-api.js +0 -49
  88. package/dist/admin/lib/product-url-keys-api.js.map +1 -1
  89. package/dist/admin/lib/scope-overview.d.ts +13 -14
  90. package/dist/admin/lib/scope-overview.d.ts.map +1 -1
  91. package/dist/admin/lib/scope-overview.js +36 -31
  92. package/dist/admin/lib/scope-overview.js.map +1 -1
  93. package/dist/admin/lib/scoped-editor-store.d.ts +81 -0
  94. package/dist/admin/lib/scoped-editor-store.d.ts.map +1 -0
  95. package/dist/admin/lib/scoped-editor-store.js +198 -0
  96. package/dist/admin/lib/scoped-editor-store.js.map +1 -0
  97. package/dist/admin/lib/scoped-values-api.d.ts +14 -0
  98. package/dist/admin/lib/scoped-values-api.d.ts.map +1 -0
  99. package/dist/admin/lib/scoped-values-api.js +55 -0
  100. package/dist/admin/lib/scoped-values-api.js.map +1 -0
  101. package/dist/admin/pages/AttributesManager.d.ts.map +1 -1
  102. package/dist/admin/pages/AttributesManager.js +119 -38
  103. package/dist/admin/pages/AttributesManager.js.map +1 -1
  104. package/dist/admin/pages/ProductContentPage.d.ts +27 -0
  105. package/dist/admin/pages/ProductContentPage.d.ts.map +1 -0
  106. package/dist/admin/pages/ProductContentPage.js +161 -0
  107. package/dist/admin/pages/ProductContentPage.js.map +1 -0
  108. package/dist/admin/pages/ProductCreateForm.d.ts +3 -0
  109. package/dist/admin/pages/ProductCreateForm.d.ts.map +1 -0
  110. package/dist/admin/pages/ProductCreateForm.js +87 -0
  111. package/dist/admin/pages/ProductCreateForm.js.map +1 -0
  112. package/dist/admin/pages/ProductEditor.d.ts.map +1 -1
  113. package/dist/admin/pages/ProductEditor.js +840 -457
  114. package/dist/admin/pages/ProductEditor.js.map +1 -1
  115. package/dist/admin/pages/ProductsList.d.ts.map +1 -1
  116. package/dist/admin/pages/ProductsList.js +9 -19
  117. package/dist/admin/pages/ProductsList.js.map +1 -1
  118. package/dist/backend/admin-search-provider.d.ts +2 -1
  119. package/dist/backend/admin-search-provider.d.ts.map +1 -1
  120. package/dist/backend/admin-search-provider.js +1 -1
  121. package/dist/backend/admin-search-provider.js.map +1 -1
  122. package/dist/backend/commands/attribute-commands.d.ts +4 -3
  123. package/dist/backend/commands/attribute-commands.d.ts.map +1 -1
  124. package/dist/backend/commands/attribute-commands.js +82 -21
  125. package/dist/backend/commands/attribute-commands.js.map +1 -1
  126. package/dist/backend/commands/product-content-commands.d.ts +31 -0
  127. package/dist/backend/commands/product-content-commands.d.ts.map +1 -0
  128. package/dist/backend/commands/product-content-commands.js +70 -0
  129. package/dist/backend/commands/product-content-commands.js.map +1 -0
  130. package/dist/backend/commands/scoped-values.commands.d.ts +95 -0
  131. package/dist/backend/commands/scoped-values.commands.d.ts.map +1 -0
  132. package/dist/backend/commands/scoped-values.commands.js +235 -0
  133. package/dist/backend/commands/scoped-values.commands.js.map +1 -0
  134. package/dist/backend/demo/reset.d.ts.map +1 -1
  135. package/dist/backend/demo/reset.js +2 -1
  136. package/dist/backend/demo/reset.js.map +1 -1
  137. package/dist/backend/demo/rows.d.ts +18 -0
  138. package/dist/backend/demo/rows.d.ts.map +1 -1
  139. package/dist/backend/demo/rows.js +18 -0
  140. package/dist/backend/demo/rows.js.map +1 -1
  141. package/dist/backend/demo/seed.d.ts +2 -1
  142. package/dist/backend/demo/seed.d.ts.map +1 -1
  143. package/dist/backend/demo/seed.js +20 -6
  144. package/dist/backend/demo/seed.js.map +1 -1
  145. package/dist/backend/entities/gallery-item-scope-override.entity.d.ts +30 -0
  146. package/dist/backend/entities/gallery-item-scope-override.entity.d.ts.map +1 -0
  147. package/dist/backend/entities/gallery-item-scope-override.entity.js +80 -0
  148. package/dist/backend/entities/gallery-item-scope-override.entity.js.map +1 -0
  149. package/dist/backend/entities/gallery-item.entity.d.ts +7 -6
  150. package/dist/backend/entities/gallery-item.entity.d.ts.map +1 -1
  151. package/dist/backend/entities/gallery-item.entity.js +11 -6
  152. package/dist/backend/entities/gallery-item.entity.js.map +1 -1
  153. package/dist/backend/entities/gallery-role-scope-override.entity.d.ts +28 -0
  154. package/dist/backend/entities/gallery-role-scope-override.entity.d.ts.map +1 -0
  155. package/dist/backend/entities/gallery-role-scope-override.entity.js +75 -0
  156. package/dist/backend/entities/gallery-role-scope-override.entity.js.map +1 -0
  157. package/dist/backend/entities/product-attachment-scope-override.entity.d.ts +30 -0
  158. package/dist/backend/entities/product-attachment-scope-override.entity.d.ts.map +1 -0
  159. package/dist/backend/entities/product-attachment-scope-override.entity.js +80 -0
  160. package/dist/backend/entities/product-attachment-scope-override.entity.js.map +1 -0
  161. package/dist/backend/entities/product-attachment.entity.d.ts +4 -6
  162. package/dist/backend/entities/product-attachment.entity.d.ts.map +1 -1
  163. package/dist/backend/entities/product-attachment.entity.js +6 -12
  164. package/dist/backend/entities/product-attachment.entity.js.map +1 -1
  165. package/dist/backend/entities/product-attribute.entity.d.ts +5 -9
  166. package/dist/backend/entities/product-attribute.entity.d.ts.map +1 -1
  167. package/dist/backend/entities/product-attribute.entity.js +5 -13
  168. package/dist/backend/entities/product-attribute.entity.js.map +1 -1
  169. package/dist/backend/entities/product-channel-scope.entity.d.ts +7 -2
  170. package/dist/backend/entities/product-channel-scope.entity.d.ts.map +1 -1
  171. package/dist/backend/entities/product-channel-scope.entity.js +10 -1
  172. package/dist/backend/entities/product-channel-scope.entity.js.map +1 -1
  173. package/dist/backend/entities/product-content-value.entity.d.ts +39 -0
  174. package/dist/backend/entities/product-content-value.entity.d.ts.map +1 -0
  175. package/dist/backend/entities/product-content-value.entity.js +81 -0
  176. package/dist/backend/entities/product-content-value.entity.js.map +1 -0
  177. package/dist/backend/entities/product-packaging-unit-scope-override.entity.d.ts +30 -0
  178. package/dist/backend/entities/product-packaging-unit-scope-override.entity.d.ts.map +1 -0
  179. package/dist/backend/entities/product-packaging-unit-scope-override.entity.js +80 -0
  180. package/dist/backend/entities/product-packaging-unit-scope-override.entity.js.map +1 -0
  181. package/dist/backend/entities/product-packaging-unit.entity.d.ts +1 -7
  182. package/dist/backend/entities/product-packaging-unit.entity.d.ts.map +1 -1
  183. package/dist/backend/entities/product-packaging-unit.entity.js +0 -10
  184. package/dist/backend/entities/product-packaging-unit.entity.js.map +1 -1
  185. package/dist/backend/entities/product-url-key.entity.d.ts +14 -19
  186. package/dist/backend/entities/product-url-key.entity.d.ts.map +1 -1
  187. package/dist/backend/entities/product-url-key.entity.js +17 -22
  188. package/dist/backend/entities/product-url-key.entity.js.map +1 -1
  189. package/dist/backend/entities/product-url-redirect.entity.d.ts +8 -13
  190. package/dist/backend/entities/product-url-redirect.entity.d.ts.map +1 -1
  191. package/dist/backend/entities/product-url-redirect.entity.js +13 -14
  192. package/dist/backend/entities/product-url-redirect.entity.js.map +1 -1
  193. package/dist/backend/entities/product-variant.entity.d.ts +8 -1
  194. package/dist/backend/entities/product-variant.entity.d.ts.map +1 -1
  195. package/dist/backend/entities/product-variant.entity.js +13 -2
  196. package/dist/backend/entities/product-variant.entity.js.map +1 -1
  197. package/dist/backend/entities/product.entity.d.ts +31 -14
  198. package/dist/backend/entities/product.entity.d.ts.map +1 -1
  199. package/dist/backend/entities/product.entity.js +41 -34
  200. package/dist/backend/entities/product.entity.js.map +1 -1
  201. package/dist/backend/index.d.ts +8 -3
  202. package/dist/backend/index.d.ts.map +1 -1
  203. package/dist/backend/index.js +136 -49
  204. package/dist/backend/index.js.map +1 -1
  205. package/dist/backend/plugin.d.ts +36 -6
  206. package/dist/backend/plugin.d.ts.map +1 -1
  207. package/dist/backend/plugin.js +36 -13
  208. package/dist/backend/plugin.js.map +1 -1
  209. package/dist/backend/prompt-tools.d.ts +3 -2
  210. package/dist/backend/prompt-tools.d.ts.map +1 -1
  211. package/dist/backend/prompt-tools.js +18 -7
  212. package/dist/backend/prompt-tools.js.map +1 -1
  213. package/dist/backend/routes.admin.d.ts +15 -16
  214. package/dist/backend/routes.admin.d.ts.map +1 -1
  215. package/dist/backend/routes.admin.js +110 -99
  216. package/dist/backend/routes.admin.js.map +1 -1
  217. package/dist/backend/routes.api-key.d.ts.map +1 -1
  218. package/dist/backend/routes.api-key.js +4 -2
  219. package/dist/backend/routes.api-key.js.map +1 -1
  220. package/dist/backend/routes.public.d.ts +8 -1
  221. package/dist/backend/routes.public.d.ts.map +1 -1
  222. package/dist/backend/routes.public.js +60 -8
  223. package/dist/backend/routes.public.js.map +1 -1
  224. package/dist/backend/services/asset-references.d.ts +12 -1
  225. package/dist/backend/services/asset-references.d.ts.map +1 -1
  226. package/dist/backend/services/asset-references.js +42 -2
  227. package/dist/backend/services/asset-references.js.map +1 -1
  228. package/dist/backend/services/attachment-packaging-scopes.d.ts +38 -20
  229. package/dist/backend/services/attachment-packaging-scopes.d.ts.map +1 -1
  230. package/dist/backend/services/attachment-packaging-scopes.js +58 -75
  231. package/dist/backend/services/attachment-packaging-scopes.js.map +1 -1
  232. package/dist/backend/services/attachment.service.d.ts +4 -8
  233. package/dist/backend/services/attachment.service.d.ts.map +1 -1
  234. package/dist/backend/services/attachment.service.js +35 -49
  235. package/dist/backend/services/attachment.service.js.map +1 -1
  236. package/dist/backend/services/attribute-filter-match.d.ts +14 -0
  237. package/dist/backend/services/attribute-filter-match.d.ts.map +1 -0
  238. package/dist/backend/services/attribute-filter-match.js +19 -0
  239. package/dist/backend/services/attribute-filter-match.js.map +1 -0
  240. package/dist/backend/services/attribute-scope-preview.d.ts +17 -7
  241. package/dist/backend/services/attribute-scope-preview.d.ts.map +1 -1
  242. package/dist/backend/services/attribute-scope-preview.js +30 -20
  243. package/dist/backend/services/attribute-scope-preview.js.map +1 -1
  244. package/dist/backend/services/attribute-set.service.d.ts +10 -1
  245. package/dist/backend/services/attribute-set.service.d.ts.map +1 -1
  246. package/dist/backend/services/attribute-set.service.js +30 -4
  247. package/dist/backend/services/attribute-set.service.js.map +1 -1
  248. package/dist/backend/services/attribute-type-mapping.d.ts +2 -2
  249. package/dist/backend/services/attribute-type-mapping.d.ts.map +1 -1
  250. package/dist/backend/services/attribute-type-mapping.js +6 -0
  251. package/dist/backend/services/attribute-type-mapping.js.map +1 -1
  252. package/dist/backend/services/attribute-usage.d.ts +31 -0
  253. package/dist/backend/services/attribute-usage.d.ts.map +1 -0
  254. package/dist/backend/services/attribute-usage.js +29 -0
  255. package/dist/backend/services/attribute-usage.js.map +1 -0
  256. package/dist/backend/services/bulk-operation.service.d.ts.map +1 -1
  257. package/dist/backend/services/bulk-operation.service.js +12 -6
  258. package/dist/backend/services/bulk-operation.service.js.map +1 -1
  259. package/dist/backend/services/bundle.service.d.ts.map +1 -1
  260. package/dist/backend/services/bundle.service.js +19 -1
  261. package/dist/backend/services/bundle.service.js.map +1 -1
  262. package/dist/backend/services/catalog-admin-search.service.d.ts +3 -2
  263. package/dist/backend/services/catalog-admin-search.service.d.ts.map +1 -1
  264. package/dist/backend/services/catalog-admin-search.service.js +6 -6
  265. package/dist/backend/services/catalog-admin-search.service.js.map +1 -1
  266. package/dist/backend/services/catalog-admin.service.d.ts +63 -12
  267. package/dist/backend/services/catalog-admin.service.d.ts.map +1 -1
  268. package/dist/backend/services/catalog-admin.service.js +352 -189
  269. package/dist/backend/services/catalog-admin.service.js.map +1 -1
  270. package/dist/backend/services/catalog-attribute-read.service.d.ts +14 -0
  271. package/dist/backend/services/catalog-attribute-read.service.d.ts.map +1 -1
  272. package/dist/backend/services/catalog-attribute-read.service.js +7 -19
  273. package/dist/backend/services/catalog-attribute-read.service.js.map +1 -1
  274. package/dist/backend/services/catalog-bulk-import.service.d.ts +52 -5
  275. package/dist/backend/services/catalog-bulk-import.service.d.ts.map +1 -1
  276. package/dist/backend/services/catalog-bulk-import.service.js +190 -142
  277. package/dist/backend/services/catalog-bulk-import.service.js.map +1 -1
  278. package/dist/backend/services/catalog-bulk-update.service.d.ts +5 -3
  279. package/dist/backend/services/catalog-bulk-update.service.d.ts.map +1 -1
  280. package/dist/backend/services/catalog-bulk-update.service.js +21 -8
  281. package/dist/backend/services/catalog-bulk-update.service.js.map +1 -1
  282. package/dist/backend/services/catalog-product-read.service.d.ts +11 -1
  283. package/dist/backend/services/catalog-product-read.service.d.ts.map +1 -1
  284. package/dist/backend/services/catalog-product-read.service.js +37 -17
  285. package/dist/backend/services/catalog-product-read.service.js.map +1 -1
  286. package/dist/backend/services/catalog-query.service.d.ts +39 -8
  287. package/dist/backend/services/catalog-query.service.d.ts.map +1 -1
  288. package/dist/backend/services/catalog-query.service.js +154 -116
  289. package/dist/backend/services/catalog-query.service.js.map +1 -1
  290. package/dist/backend/services/catalog-quick-search.service.d.ts.map +1 -1
  291. package/dist/backend/services/catalog-quick-search.service.js +5 -5
  292. package/dist/backend/services/catalog-quick-search.service.js.map +1 -1
  293. package/dist/backend/services/catalog-write-ports.d.ts +14 -16
  294. package/dist/backend/services/catalog-write-ports.d.ts.map +1 -1
  295. package/dist/backend/services/catalog-write-ports.js +11 -70
  296. package/dist/backend/services/catalog-write-ports.js.map +1 -1
  297. package/dist/backend/services/category-admin.service.d.ts.map +1 -1
  298. package/dist/backend/services/category-admin.service.js +9 -1
  299. package/dist/backend/services/category-admin.service.js.map +1 -1
  300. package/dist/backend/services/content-attribute-rules.d.ts +49 -0
  301. package/dist/backend/services/content-attribute-rules.d.ts.map +1 -0
  302. package/dist/backend/services/content-attribute-rules.js +89 -0
  303. package/dist/backend/services/content-attribute-rules.js.map +1 -0
  304. package/dist/backend/services/effective-value.sql.d.ts +24 -38
  305. package/dist/backend/services/effective-value.sql.d.ts.map +1 -1
  306. package/dist/backend/services/effective-value.sql.js +37 -87
  307. package/dist/backend/services/effective-value.sql.js.map +1 -1
  308. package/dist/backend/services/gallery-scopes.d.ts +45 -22
  309. package/dist/backend/services/gallery-scopes.d.ts.map +1 -1
  310. package/dist/backend/services/gallery-scopes.js +116 -109
  311. package/dist/backend/services/gallery-scopes.js.map +1 -1
  312. package/dist/backend/services/gallery.service.d.ts +13 -27
  313. package/dist/backend/services/gallery.service.d.ts.map +1 -1
  314. package/dist/backend/services/gallery.service.js +75 -199
  315. package/dist/backend/services/gallery.service.js.map +1 -1
  316. package/dist/backend/services/grouped.service.d.ts.map +1 -1
  317. package/dist/backend/services/grouped.service.js +13 -1
  318. package/dist/backend/services/grouped.service.js.map +1 -1
  319. package/dist/backend/services/packaging-unit.service.d.ts.map +1 -1
  320. package/dist/backend/services/packaging-unit.service.js +7 -12
  321. package/dist/backend/services/packaging-unit.service.js.map +1 -1
  322. package/dist/backend/services/page-builder-content.d.ts +64 -0
  323. package/dist/backend/services/page-builder-content.d.ts.map +1 -0
  324. package/dist/backend/services/page-builder-content.js +113 -0
  325. package/dist/backend/services/page-builder-content.js.map +1 -0
  326. package/dist/backend/services/primary-asset-url.d.ts +6 -1
  327. package/dist/backend/services/primary-asset-url.d.ts.map +1 -1
  328. package/dist/backend/services/primary-asset-url.js +9 -4
  329. package/dist/backend/services/primary-asset-url.js.map +1 -1
  330. package/dist/backend/services/product-availability.service.d.ts +16 -3
  331. package/dist/backend/services/product-availability.service.d.ts.map +1 -1
  332. package/dist/backend/services/product-availability.service.js +58 -21
  333. package/dist/backend/services/product-availability.service.js.map +1 -1
  334. package/dist/backend/services/product-content.service.d.ts +62 -0
  335. package/dist/backend/services/product-content.service.d.ts.map +1 -0
  336. package/dist/backend/services/product-content.service.js +122 -0
  337. package/dist/backend/services/product-content.service.js.map +1 -0
  338. package/dist/backend/services/product-editor-preferences.service.d.ts +6 -0
  339. package/dist/backend/services/product-editor-preferences.service.d.ts.map +1 -1
  340. package/dist/backend/services/product-editor-preferences.service.js +12 -0
  341. package/dist/backend/services/product-editor-preferences.service.js.map +1 -1
  342. package/dist/backend/services/product-global-field-rules.d.ts +39 -0
  343. package/dist/backend/services/product-global-field-rules.d.ts.map +1 -0
  344. package/dist/backend/services/product-global-field-rules.js +84 -0
  345. package/dist/backend/services/product-global-field-rules.js.map +1 -0
  346. package/dist/backend/services/product-link.service.d.ts.map +1 -1
  347. package/dist/backend/services/product-link.service.js +14 -16
  348. package/dist/backend/services/product-link.service.js.map +1 -1
  349. package/dist/backend/services/product-list-view-service.d.ts.map +1 -1
  350. package/dist/backend/services/product-list-view-service.js +5 -8
  351. package/dist/backend/services/product-list-view-service.js.map +1 -1
  352. package/dist/backend/services/product-page-revalidation.d.ts +9 -0
  353. package/dist/backend/services/product-page-revalidation.d.ts.map +1 -1
  354. package/dist/backend/services/product-page-revalidation.js +19 -0
  355. package/dist/backend/services/product-page-revalidation.js.map +1 -1
  356. package/dist/backend/services/product-scopes.service.d.ts +15 -6
  357. package/dist/backend/services/product-scopes.service.d.ts.map +1 -1
  358. package/dist/backend/services/product-scopes.service.js +87 -33
  359. package/dist/backend/services/product-scopes.service.js.map +1 -1
  360. package/dist/backend/services/product-value-resolver.service.d.ts +2 -2
  361. package/dist/backend/services/product-value-resolver.service.d.ts.map +1 -1
  362. package/dist/backend/services/product-value-resolver.service.js +4 -7
  363. package/dist/backend/services/product-value-resolver.service.js.map +1 -1
  364. package/dist/backend/services/publication-window-sweep.d.ts +61 -7
  365. package/dist/backend/services/publication-window-sweep.d.ts.map +1 -1
  366. package/dist/backend/services/publication-window-sweep.js +106 -19
  367. package/dist/backend/services/publication-window-sweep.js.map +1 -1
  368. package/dist/backend/services/scheduled-work-probe.d.ts +34 -0
  369. package/dist/backend/services/scheduled-work-probe.d.ts.map +1 -0
  370. package/dist/backend/services/scheduled-work-probe.js +30 -0
  371. package/dist/backend/services/scheduled-work-probe.js.map +1 -0
  372. package/dist/backend/services/scope-completeness.d.ts +11 -11
  373. package/dist/backend/services/scope-completeness.d.ts.map +1 -1
  374. package/dist/backend/services/scope-completeness.js +26 -33
  375. package/dist/backend/services/scope-completeness.js.map +1 -1
  376. package/dist/backend/services/scope-overview.service.d.ts +24 -24
  377. package/dist/backend/services/scope-overview.service.d.ts.map +1 -1
  378. package/dist/backend/services/scope-overview.service.js +33 -76
  379. package/dist/backend/services/scope-overview.service.js.map +1 -1
  380. package/dist/backend/services/scoped-store-adapters.d.ts +58 -0
  381. package/dist/backend/services/scoped-store-adapters.d.ts.map +1 -0
  382. package/dist/backend/services/scoped-store-adapters.js +92 -0
  383. package/dist/backend/services/scoped-store-adapters.js.map +1 -0
  384. package/dist/backend/services/scoped-values-global-only.d.ts +36 -0
  385. package/dist/backend/services/scoped-values-global-only.d.ts.map +1 -0
  386. package/dist/backend/services/scoped-values-global-only.js +92 -0
  387. package/dist/backend/services/scoped-values-global-only.js.map +1 -0
  388. package/dist/backend/services/scoped-values-import.d.ts +86 -0
  389. package/dist/backend/services/scoped-values-import.d.ts.map +1 -0
  390. package/dist/backend/services/scoped-values-import.js +320 -0
  391. package/dist/backend/services/scoped-values-import.js.map +1 -0
  392. package/dist/backend/services/scoped-values-read.service.d.ts +56 -0
  393. package/dist/backend/services/scoped-values-read.service.d.ts.map +1 -0
  394. package/dist/backend/services/scoped-values-read.service.js +289 -0
  395. package/dist/backend/services/scoped-values-read.service.js.map +1 -0
  396. package/dist/backend/services/scoped-values-save.service.d.ts +79 -0
  397. package/dist/backend/services/scoped-values-save.service.d.ts.map +1 -0
  398. package/dist/backend/services/scoped-values-save.service.js +675 -0
  399. package/dist/backend/services/scoped-values-save.service.js.map +1 -0
  400. package/dist/backend/services/scoped-values-state.d.ts +94 -0
  401. package/dist/backend/services/scoped-values-state.d.ts.map +1 -0
  402. package/dist/backend/services/scoped-values-state.js +159 -0
  403. package/dist/backend/services/scoped-values-state.js.map +1 -0
  404. package/dist/backend/services/scoped-values.service.d.ts +36 -0
  405. package/dist/backend/services/scoped-values.service.d.ts.map +1 -0
  406. package/dist/backend/services/scoped-values.service.js +92 -0
  407. package/dist/backend/services/scoped-values.service.js.map +1 -0
  408. package/dist/backend/services/storefront-value-overrides.d.ts +7 -8
  409. package/dist/backend/services/storefront-value-overrides.d.ts.map +1 -1
  410. package/dist/backend/services/storefront-value-overrides.js +11 -14
  411. package/dist/backend/services/storefront-value-overrides.js.map +1 -1
  412. package/dist/backend/services/url-key-resolution.service.d.ts +12 -18
  413. package/dist/backend/services/url-key-resolution.service.d.ts.map +1 -1
  414. package/dist/backend/services/url-key-resolution.service.js +43 -43
  415. package/dist/backend/services/url-key-resolution.service.js.map +1 -1
  416. package/dist/backend/services/url-key.service.d.ts +87 -135
  417. package/dist/backend/services/url-key.service.d.ts.map +1 -1
  418. package/dist/backend/services/url-key.service.js +447 -619
  419. package/dist/backend/services/url-key.service.js.map +1 -1
  420. package/dist/manifest.d.ts +7 -1
  421. package/dist/manifest.d.ts.map +1 -1
  422. package/dist/manifest.js +34 -0
  423. package/dist/manifest.js.map +1 -1
  424. package/dist/migrations/20261030T113855_catalog_scope_model_texts.d.ts +36 -0
  425. package/dist/migrations/20261030T113855_catalog_scope_model_texts.d.ts.map +1 -0
  426. package/dist/migrations/20261030T113855_catalog_scope_model_texts.js +225 -0
  427. package/dist/migrations/20261030T113855_catalog_scope_model_texts.js.map +1 -0
  428. package/dist/migrations/20261030T113859_catalog_scope_model_order_rules.d.ts +18 -0
  429. package/dist/migrations/20261030T113859_catalog_scope_model_order_rules.d.ts.map +1 -0
  430. package/dist/migrations/20261030T113859_catalog_scope_model_order_rules.js +39 -0
  431. package/dist/migrations/20261030T113859_catalog_scope_model_order_rules.js.map +1 -0
  432. package/dist/migrations/20261030T113904_catalog_scope_model_url_keys.d.ts +6 -0
  433. package/dist/migrations/20261030T113904_catalog_scope_model_url_keys.d.ts.map +1 -0
  434. package/dist/migrations/20261030T113904_catalog_scope_model_url_keys.js +119 -0
  435. package/dist/migrations/20261030T113904_catalog_scope_model_url_keys.js.map +1 -0
  436. package/dist/migrations/20261030T113908_catalog_scope_model_media.d.ts +6 -0
  437. package/dist/migrations/20261030T113908_catalog_scope_model_media.d.ts.map +1 -0
  438. package/dist/migrations/20261030T113908_catalog_scope_model_media.js +185 -0
  439. package/dist/migrations/20261030T113908_catalog_scope_model_media.js.map +1 -0
  440. package/dist/migrations/20261104T121504_catalog_product_content_values.d.ts +36 -0
  441. package/dist/migrations/20261104T121504_catalog_product_content_values.d.ts.map +1 -0
  442. package/dist/migrations/20261104T121504_catalog_product_content_values.js +53 -0
  443. package/dist/migrations/20261104T121504_catalog_product_content_values.js.map +1 -0
  444. package/dist/migrations/20261107T093126_catalog_sku_unique_among_live.d.ts +33 -0
  445. package/dist/migrations/20261107T093126_catalog_sku_unique_among_live.d.ts.map +1 -0
  446. package/dist/migrations/20261107T093126_catalog_sku_unique_among_live.js +58 -0
  447. package/dist/migrations/20261107T093126_catalog_sku_unique_among_live.js.map +1 -0
  448. package/dist/migrations/20261107T120008_catalog_product_created_at_milliseconds.d.ts +36 -0
  449. package/dist/migrations/20261107T120008_catalog_product_created_at_milliseconds.d.ts.map +1 -0
  450. package/dist/migrations/20261107T120008_catalog_product_created_at_milliseconds.js +40 -0
  451. package/dist/migrations/20261107T120008_catalog_product_created_at_milliseconds.js.map +1 -0
  452. package/dist/migrations/index.d.ts +8 -1
  453. package/dist/migrations/index.d.ts.map +1 -1
  454. package/dist/migrations/index.js +15 -1
  455. package/dist/migrations/index.js.map +1 -1
  456. package/docs/catalog/attachments.md +53 -43
  457. package/docs/catalog/attribute-sets.md +2 -2
  458. package/docs/catalog/attributes.md +68 -8
  459. package/docs/catalog/category-content.md +3 -0
  460. package/docs/catalog/composite-products.md +2 -2
  461. package/docs/catalog/editing-a-product-at-a-scope.md +95 -0
  462. package/docs/catalog/gallery-and-labels.md +61 -60
  463. package/docs/catalog/packaging-units.md +43 -34
  464. package/docs/catalog/per-channel-per-language-overrides.md +83 -410
  465. package/docs/catalog/product-content.md +180 -0
  466. package/docs/catalog/product-links.md +2 -2
  467. package/docs/catalog/url-keys-and-redirects.md +79 -79
  468. package/docs/catalog.md +68 -14
  469. package/i18n/en.json +270 -270
  470. package/i18n/pl.json +272 -272
  471. package/package.json +11 -11
  472. package/dist/admin/components/AttachmentScopesDialog.d.ts +0 -22
  473. package/dist/admin/components/AttachmentScopesDialog.d.ts.map +0 -1
  474. package/dist/admin/components/AttachmentScopesDialog.js +0 -70
  475. package/dist/admin/components/AttachmentScopesDialog.js.map +0 -1
  476. package/dist/admin/components/ProductScopeControls.d.ts +0 -31
  477. package/dist/admin/components/ProductScopeControls.d.ts.map +0 -1
  478. package/dist/admin/components/ProductScopeControls.js +0 -243
  479. package/dist/admin/components/ProductScopeControls.js.map +0 -1
  480. package/dist/admin/components/ProductScopeEditor.d.ts +0 -88
  481. package/dist/admin/components/ProductScopeEditor.d.ts.map +0 -1
  482. package/dist/admin/components/ProductScopeEditor.js +0 -396
  483. package/dist/admin/components/ProductScopeEditor.js.map +0 -1
  484. package/dist/admin/components/ProductUrlKeysPanel.d.ts +0 -17
  485. package/dist/admin/components/ProductUrlKeysPanel.d.ts.map +0 -1
  486. package/dist/admin/components/ProductUrlKeysPanel.js +0 -215
  487. package/dist/admin/components/ProductUrlKeysPanel.js.map +0 -1
  488. package/dist/admin/components/ScopedDialogParts.d.ts +0 -23
  489. package/dist/admin/components/ScopedDialogParts.d.ts.map +0 -1
  490. package/dist/admin/components/ScopedDialogParts.js +0 -16
  491. package/dist/admin/components/ScopedDialogParts.js.map +0 -1
  492. package/dist/admin/lib/media-scopes.d.ts +0 -41
  493. package/dist/admin/lib/media-scopes.d.ts.map +0 -1
  494. package/dist/admin/lib/media-scopes.js +0 -66
  495. package/dist/admin/lib/media-scopes.js.map +0 -1
  496. package/dist/admin/lib/product-scope-drafts.d.ts +0 -77
  497. package/dist/admin/lib/product-scope-drafts.d.ts.map +0 -1
  498. package/dist/admin/lib/product-scope-drafts.js +0 -133
  499. package/dist/admin/lib/product-scope-drafts.js.map +0 -1
  500. package/dist/backend/entities/gallery-item-channel-hidden.entity.d.ts +0 -14
  501. package/dist/backend/entities/gallery-item-channel-hidden.entity.d.ts.map +0 -1
  502. package/dist/backend/entities/gallery-item-channel-hidden.entity.js +0 -42
  503. package/dist/backend/entities/gallery-item-channel-hidden.entity.js.map +0 -1
  504. package/dist/backend/entities/gallery-item-channel-label.entity.d.ts +0 -18
  505. package/dist/backend/entities/gallery-item-channel-label.entity.d.ts.map +0 -1
  506. package/dist/backend/entities/gallery-item-channel-label.entity.js +0 -49
  507. package/dist/backend/entities/gallery-item-channel-label.entity.js.map +0 -1
  508. package/dist/backend/entities/product-attachment-channel-hidden.entity.d.ts +0 -13
  509. package/dist/backend/entities/product-attachment-channel-hidden.entity.d.ts.map +0 -1
  510. package/dist/backend/entities/product-attachment-channel-hidden.entity.js +0 -41
  511. package/dist/backend/entities/product-attachment-channel-hidden.entity.js.map +0 -1
  512. package/dist/backend/services/product-overrides.service.d.ts +0 -84
  513. package/dist/backend/services/product-overrides.service.d.ts.map +0 -1
  514. package/dist/backend/services/product-overrides.service.js +0 -211
  515. package/dist/backend/services/product-overrides.service.js.map +0 -1
  516. package/dist/backend/services/product-scope-context.service.d.ts +0 -36
  517. package/dist/backend/services/product-scope-context.service.d.ts.map +0 -1
  518. package/dist/backend/services/product-scope-context.service.js +0 -107
  519. package/dist/backend/services/product-scope-context.service.js.map +0 -1
@@ -1,515 +1,898 @@
1
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
- import { useCallback, useEffect, useMemo, useRef, useState, } from 'react';
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
3
  import { useNavigate, useParams, useSearchParams } from 'react-router-dom';
4
- import { Archive, ArchiveRestore, Trash2, ChevronLeft, Copy, Eye, FileText as FileTextIcon, Globe, Image as ImageIcon, CircleDollarSign, Layers, LayoutGrid, Link as LinkIcon, Paperclip, Save, SlidersHorizontal, Store as StoreIcon, Warehouse as WarehouseIcon, } from 'lucide-react';
4
+ import { Archive, ArchiveRestore, ChevronDown, ChevronLeft, Copy, Lock, RotateCw, Save, Trash2 } from 'lucide-react';
5
+ import { ERROR_CODES, } from '@endora-commerce/contracts';
5
6
  import { ApiError, apiClient, useAuth, useUnsavedChangesPrompt, 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 { ModalDialog, StickyFormActions, CategoryTreePicker, ProductPicker } from '@endora-commerce/admin-kit/components';
8
- import { useTranslation } from '@endora-commerce/admin-kit/i18n';
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
15
  import { ProductScopeOverview } from '../components/ProductScopeOverview.js';
15
- import { ProductUrlKeysPanel } from '../components/ProductUrlKeysPanel.js';
16
16
  import { GallerySection } from '../components/ProductGallerySection.js';
17
17
  import { AttachmentsSection } from '../components/ProductAttachmentsSection.js';
18
18
  import { ArchivedPill, ProductStatusPill } from '../components/ProductStatusPills.js';
19
- import { ProductScopeEditor, } from '../components/ProductScopeEditor.js';
20
- import { checkWindowInputs, isoToLocalInput } from '../lib/product-scope-drafts.js';
21
- import { describeIncompletePair, getProductScopes, isScopeIncomplete, loadChannelNamer, scopeSaveErrorMessage, } from '../lib/product-scopes-api.js';
22
- const LOCALES = ['en-US', 'pl-PL'];
23
- const PRODUCT_TYPES = [
24
- 'simple',
25
- 'configurable',
26
- 'grouped',
27
- 'bundle',
28
- 'virtual',
29
- ];
30
- const VISIBILITIES = ['public', 'logged_in_only', 'organization_restricted'];
31
- const STATUSES = ['active', 'inactive'];
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';
32
31
  /**
33
- * The tabs `?tab=` may open (review D3: the bulk scoped-status result links to
34
- * `?tab=scopes`) — those every saved product shows. A type-dependent or zone-counted
35
- * tab, or an unknown value, opens Details.
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.
36
44
  */
37
- const LINKABLE_TABS = new Set([
45
+ const TAB_IDS = [
38
46
  'details',
39
47
  'attributes',
40
48
  'pricing',
49
+ 'variants',
50
+ 'composite',
41
51
  'media',
42
52
  'inventory',
43
53
  'attachments',
44
54
  'links',
55
+ 'channels',
45
56
  'scopes',
46
57
  'seo',
47
- ]);
58
+ ];
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. */
48
95
  /**
49
- * Order-insensitive JSON snapshot of the editable form fields, used to detect
50
- * unsaved changes (object keys + array members are sorted so re-ordering alone
51
- * 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.
52
99
  */
53
- function stableSnapshot(values) {
54
- return JSON.stringify(values, (_key, value) => {
55
- if (Array.isArray(value))
56
- return [...value].sort();
57
- if (value && typeof value === 'object') {
58
- return Object.fromEntries(Object.entries(value).sort(([a], [b]) => a.localeCompare(b)));
59
- }
60
- return value;
61
- });
100
+ function withServerDetail(lead, err) {
101
+ const detail = errorOf(err)?.message;
102
+ return detail && detail !== lead ? `${lead} ${detail}` : lead;
62
103
  }
63
- 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 }) {
64
117
  const t = useTranslation('catalog');
65
- 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';
66
121
  const navigate = useNavigate();
67
- const isNew = params.id === 'new';
68
- const id = isNew ? null : params.id ?? null;
69
- // Feature 091 / P7a, Z15 — the Channels tab's button is a count of its own
70
- // body. Declared here rather than beside the tab table because the table is
71
- // built below an early return and a hook may not be.
72
- const channelContributions = useAdminZone('product.editor.channels', {
73
- productId: id ?? '',
74
- });
75
- // Archive / Restore write the catalogue (FR-019): an operator without
76
- // `catalog:write` is not offered either.
122
+ const [searchParams, setSearchParams] = useSearchParams();
77
123
  const { hasPermission } = useAuth();
78
124
  const canWrite = hasPermission('catalog:write');
79
- const [loading, setLoading] = useState(!isNew);
80
- const [error, setError] = useState(null);
81
- const [info, setInfo] = useState(null);
82
- // Feature 163 (US6, G-2) — what the completeness check reported on the last Save.
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,
138
+ });
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);
83
156
  const [gateWarning, setGateWarning] = useState(null);
84
- // The product's archived state, read with the product and
85
- // moved only by the Archive / Restore actions below, never by Save.
86
- const [archivedAt, setArchivedAt] = useState(null);
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);
87
162
  const [archiveDialog, setArchiveDialog] = useState(null);
88
163
  const [archiving, setArchiving] = useState(false);
89
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);
90
169
  const [categories, setCategories] = useState([]);
91
- const [sku, setSku] = useState('');
92
- const [type, setType] = useState('simple');
93
- const [status, setStatus] = useState('inactive');
94
- const [visibility, setVisibility] = useState('public');
95
- const [name, setName] = useState({ 'en-US': '', 'pl-PL': '' });
96
- const [description, setDescription] = useState({
97
- 'en-US': '',
98
- 'pl-PL': '',
99
- });
100
- const [categoryIds, setCategoryIds] = useState([]);
101
- const [searchParams] = useSearchParams();
102
- const [activeTab, setActiveTab] = useState(() => {
103
- const linked = searchParams.get('tab');
104
- return !isNew && linked !== null && LINKABLE_TABS.has(linked) ? linked : 'details';
105
- });
106
- // Feature 002 (T034) — Attribute Set selector
170
+ const [categoriesLoading, setCategoriesLoading] = useState(true);
107
171
  const [attributeSets, setAttributeSets] = useState([]);
108
- const [attributeSetId, setAttributeSetId] = useState('');
109
- // Editable attribute values keyed by attribute `key` (Attributes tab).
110
- const [attrValues, setAttrValues] = useState({});
111
- // Feature 163 (FR-023) — the global publication window, as `datetime-local`
112
- // values in the operator's zone. `loadedWindow` is what the server holds, so
113
- // the page PATCH carries the window only when it changed.
114
- const [publishFrom, setPublishFrom] = useState('');
115
- const [publishUntil, setPublishUntil] = useState('');
116
- const [loadedWindow, setLoadedWindow] = useState({ from: '', until: '' });
117
- const [windowError, setWindowError] = useState(null);
118
- // Feature 023 — imperative handle on the scope-editor so the page Save
119
- // can flush every pending channel-scoped override in a single PATCH.
120
- const scopeEditorRef = useRef(null);
121
- // Media tab — page-Save flushes staged gallery label/order edits via this
122
- // imperative handle (mirrors the scope-editor pattern above).
123
- const galleryRef = useRef(null);
124
- // Unsaved-changes guard — a stable snapshot of the editable fields is taken
125
- // on load (and re-taken after each save via refresh()); the form is "dirty"
126
- // whenever the live values diverge from it.
127
- const initialSnapshotRef = useRef('');
128
- const currentSnapshot = stableSnapshot({
129
- sku,
130
- type,
131
- status,
132
- visibility,
133
- name,
134
- description,
135
- categoryIds,
136
- attributeSetId,
137
- attrValues,
138
- publishFrom,
139
- publishUntil,
140
- });
141
- // Review D4 — the gallery's staged edits are unsaved changes too. The gallery stays
142
- // mounted once its tab is opened (hidden on the other tabs), so its staging survives a
143
- // tab switch and the page Save still writes it.
144
- const [galleryDirty, setGalleryDirty] = useState(false);
145
- const [galleryOpened, setGalleryOpened] = useState(false);
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
+ }, []);
146
216
  useEffect(() => {
147
- if (activeTab === 'media')
148
- setGalleryOpened(true);
149
- }, [activeTab]);
150
- const dirty = !loading &&
151
- ((initialSnapshotRef.current !== '' && currentSnapshot !== initialSnapshotRef.current) || galleryDirty);
152
- useUnsavedChangesPrompt(dirty);
153
- // Read through a ref so a language switch does not re-load the product (and drop edits).
154
- const tRef = useRef(t);
155
- tRef.current = t;
156
- const refresh = useCallback(async () => {
157
- setLoading(true);
158
- setError(null);
159
- try {
160
- const [cats, sets] = await Promise.all([
161
- apiClient.get('/api/v1/admin/catalog/categories'),
162
- apiClient.get('/api/v1/admin/catalog/attribute-sets'),
163
- ]);
164
- setCategories(cats.data);
165
- setAttributeSets(sets.data);
166
- // Pick the system Default as the initial selection for new Products.
167
- const defaultSet = sets.data.find((s) => s.code === 'default');
168
- if (isNew && defaultSet)
169
- setAttributeSetId(defaultSet.id);
170
- if (isNew) {
171
- // Baseline for a brand-new product matches the useState defaults.
172
- initialSnapshotRef.current = stableSnapshot({
173
- sku: '',
174
- type: 'simple',
175
- status: 'inactive',
176
- visibility: 'public',
177
- name: { 'en-US': '', 'pl-PL': '' },
178
- description: { 'en-US': '', 'pl-PL': '' },
179
- categoryIds: [],
180
- attributeSetId: defaultSet?.id ?? '',
181
- attrValues: {},
182
- publishFrom: '',
183
- publishUntil: '',
184
- });
185
- }
186
- if (id) {
187
- const res = await apiClient.get(`/api/v1/admin/catalog/products/${id}`);
188
- const p = res.data;
189
- setSku(p.sku);
190
- setType(p.type);
191
- setStatus(p.status);
192
- setArchivedAt(p.archivedAt ?? null);
193
- setVisibility(p.visibility);
194
- const loadedName = {
195
- 'en-US': p.name['en-US'] ?? '',
196
- 'pl-PL': p.name['pl-PL'] ?? '',
197
- };
198
- setName(loadedName);
199
- const loadedDescription = {
200
- 'en-US': p.description['en-US'] ?? '',
201
- 'pl-PL': p.description['pl-PL'] ?? '',
202
- };
203
- setDescription(loadedDescription);
204
- setAttrValues(p.attributeValues ?? {});
205
- setAttributeSetId(p.attributeSetId);
206
- setCategoryIds(p.categoryIds ?? []);
207
- // Feature 163 — the global window is read from the scopes answer (the
208
- // product answer does not carry it). A failed read leaves the fields
209
- // empty and unchanged, so nothing is sent for them on save.
210
- let loadedFrom = '';
211
- let loadedUntil = '';
212
- try {
213
- const scopes = await getProductScopes(id);
214
- loadedFrom = isoToLocalInput(scopes?.global?.publishFrom ?? null);
215
- loadedUntil = isoToLocalInput(scopes?.global?.publishUntil ?? null);
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 });
216
242
  }
217
- catch {
218
- // Best effort — the rest of the editor stays usable.
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);
219
263
  }
220
- setPublishFrom(loadedFrom);
221
- setPublishUntil(loadedUntil);
222
- setLoadedWindow({ from: loadedFrom, until: loadedUntil });
223
- setWindowError(null);
224
- // Capture the loaded state as the clean baseline for dirty-tracking.
225
- initialSnapshotRef.current = stableSnapshot({
226
- sku: p.sku,
227
- type: p.type,
228
- status: p.status,
229
- visibility: p.visibility,
230
- name: loadedName,
231
- description: loadedDescription,
232
- categoryIds: p.categoryIds ?? [],
233
- attributeSetId: p.attributeSetId,
234
- attrValues: p.attributeValues ?? {},
235
- publishFrom: loadedFrom,
236
- publishUntil: loadedUntil,
237
- });
264
+ return;
265
+ }
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;
238
281
  }
239
282
  }
240
- catch (err) {
241
- setError(err instanceof ApiError ? err.envelope.error.message : tRef.current('productEditor.error.load'));
242
- }
243
- finally {
244
- 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;
245
310
  }
246
- }, [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).
247
322
  useEffect(() => {
248
- void refresh();
249
- }, [refresh]);
250
- const handleSave = useCallback(async (e) => {
251
- e.preventDefault();
252
- setError(null);
253
- setInfo(null);
254
- setGateWarning(null);
255
- const trimmedName = {};
256
- const trimmedDescription = {};
257
- for (const l of LOCALES) {
258
- if (name[l])
259
- trimmedName[l] = name[l];
260
- if (description[l])
261
- trimmedDescription[l] = description[l];
262
- }
263
- if (Object.keys(trimmedName).length === 0) {
264
- setError(t('productEditor.error.nameRequired'));
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);
265
363
  return;
266
364
  }
267
- // The Attributes-tab edits. A product has no price of its own: prices
268
- // are set in price books (feature 160), so nothing else is added here.
269
- const attributeValues = { ...attrValues };
270
- // Feature 163 (FR-023) — the window travels only when it changed, and
271
- // a window that does not start before it ends is refused here, beside
272
- // its fields, without a request.
273
- let windowPatch = null;
274
- if (publishFrom !== loadedWindow.from || publishUntil !== loadedWindow.until) {
275
- const check = checkWindowInputs(publishFrom, publishUntil);
276
- if (!check.ok) {
277
- setWindowError(check.reason);
278
- return;
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;
373
+ try {
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 });
279
405
  }
280
- windowPatch = { publishFrom: check.from, publishUntil: check.until };
281
406
  }
282
- setWindowError(null);
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);
283
418
  try {
284
- if (isNew) {
285
- const res = await apiClient.post('/api/v1/admin/catalog/products', {
286
- sku,
287
- type,
288
- // A new product is `inactive` unless the operator chose otherwise
289
- // (FR-010, Q1-d); the selector's value is sent, not assumed.
290
- status,
291
- name: trimmedName,
292
- description: trimmedDescription,
293
- categoryIds,
294
- attributeValues,
295
- visibility,
296
- ...(attributeSetId ? { attributeSetId } : {}),
297
- });
298
- navigate(`/catalog/products/${res.data.id}`);
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
+ }));
299
434
  }
300
- else if (id) {
301
- // Feature 023 — page-Save commits the per-language baseline (the product
302
- // PATCH) and the drafts staged in the ProductScopeEditor panel and the
303
- // gallery. Feature 163 (US6 #3): the PATCH goes first and alone — when the
304
- // completeness gate refuses it (`422 SCOPE_INCOMPLETE`) nothing else is
305
- // written, so "not saved, still in the form" is true of the whole change.
306
- const saved = await apiClient.patch(`/api/v1/admin/catalog/products/${id}`, {
307
- sku: sku.trim(),
308
- status,
309
- name: trimmedName,
310
- description: trimmedDescription,
311
- categoryIds,
312
- attributeValues,
313
- visibility,
314
- ...(attributeSetId ? { attributeSetId } : {}),
315
- ...(windowPatch ?? {}),
316
- });
317
- await Promise.all([
318
- scopeEditorRef.current?.flushOverrides() ?? Promise.resolve(),
319
- galleryRef.current?.flushGallery() ?? Promise.resolve(),
320
- ]);
321
- // The status change was saved; where it switched the product on with values
322
- // missing (`warn` mode) the page says what, by channel and language — instead
323
- // of "Saved.", which would read as "nothing left to do".
324
- const completeness = (saved.warnings ?? []).filter((w) => w.kind === 'completeness');
325
- if (completeness.length > 0) {
326
- const channelName = await loadChannelNamer(id);
327
- setGateWarning(t('productEditor.scopeControls.warning.incomplete', {
328
- details: completeness.map((w) => describeIncompletePair(w, channelName, t)).join('; '),
329
- }));
330
- }
331
- else {
332
- setInfo(t('productEditor.saved'));
333
- }
334
- await refresh();
435
+ else {
436
+ setInfo(plural('productEditor.save.saved', count, { scope: scopeInWords(s.scope, s.data.validScopes, t, adminLanguage) }));
335
437
  }
438
+ return true;
336
439
  }
337
440
  catch (err) {
338
- if (id && isScopeIncomplete(err)) {
339
- // `refuse` mode: nothing in this request was saved; the edits stay in the form.
340
- const channelName = await loadChannelNamer(id);
341
- setError(scopeSaveErrorMessage(err, channelName, t, 'productEditor.scopeControls.error.generic', 'productEditor.statusGate.refused'));
441
+ handleSaveError(err, s);
442
+ return false;
443
+ }
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') });
454
+ return;
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('; ') }),
487
+ });
488
+ return;
489
+ }
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') });
342
518
  return;
343
519
  }
344
- const windowRefused = err instanceof ApiError &&
345
- err.envelope.error.details?.field === 'window';
346
- setError(windowRefused
347
- ? t('productEditor.error.publishWindow')
348
- : err instanceof ApiError
349
- ? err.envelope.error.message
350
- : t('productEditor.error.save'));
351
- }
352
- }, [isNew, id, sku, status, type, name, description, categoryIds, attrValues, attributeSetId, visibility, navigate, refresh, publishFrom, publishUntil, loadedWindow, t]);
353
- const handleAttrChange = useCallback((key, value) => {
354
- setAttrValues((prev) => ({ ...prev, [key]: value }));
355
- }, []);
356
- // Swapping the Attribute Set drops the values whose keys are not in the
357
- // newly-selected set, so the save payload doesn't carry orphan keys left
358
- // over from the previous set.
359
- const handleAttributeSetChange = useCallback(async (newSetId) => {
360
- setAttributeSetId(newSetId);
361
- if (!newSetId)
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
+ }
362
529
  return;
363
- try {
364
- const res = await apiClient.get(`/api/v1/admin/catalog/attribute-sets/${newSetId}`);
365
- const allowed = new Set(res.data.attributes.map((a) => a.key));
366
- setAttrValues((prev) => {
367
- const next = {};
368
- for (const [k, v] of Object.entries(prev)) {
369
- if (allowed.has(k)) {
370
- next[k] = v;
371
- }
372
- }
373
- return next;
374
- });
375
530
  }
376
- catch {
377
- // Non-fatal — the backend tolerates round-tripped keys, so leaving
378
- // the values untouched on a fetch failure still saves correctly.
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;
379
553
  }
380
- }, []);
381
- const handleDeleteProduct = useCallback(async () => {
382
- if (!id)
554
+ if (g.kind === 'url') {
555
+ skipGuardRef.current = false;
556
+ void load(g.target, { field: searchParams.get('field') });
383
557
  return;
384
- 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)
385
570
  return;
571
+ setDeleting(true);
572
+ setWholeProductError(null);
386
573
  try {
387
- await apiClient.delete(`/api/v1/admin/catalog/products/${id}`);
574
+ await apiClient.delete(PRODUCT_PATH(productId));
388
575
  navigate('/catalog/products');
389
576
  }
390
577
  catch (err) {
391
- setError(err instanceof ApiError ? err.envelope.error.message : t('productEditor.error.delete'));
578
+ setWholeProductError(withServerDetail(t('productEditor.error.delete'), err));
392
579
  }
393
- }, [id, navigate, t]);
394
- const [duplicating, setDuplicating] = useState(false);
395
- const handleDuplicate = useCallback(async () => {
396
- if (!id || duplicating)
397
- return;
398
- if (!confirm(t('productEditor.duplicateConfirm')))
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)
399
587
  return;
400
588
  setDuplicating(true);
401
- setError(null);
589
+ setWholeProductError(null);
402
590
  try {
403
- const res = await apiClient.post(`/api/v1/admin/catalog/products/${id}/duplicate`, {});
591
+ const res = await apiClient.post(`${PRODUCT_PATH(productId)}/duplicate`, {});
404
592
  navigate(`/catalog/products/${res.data.id}`);
405
593
  }
406
594
  catch (err) {
407
- setError(err instanceof ApiError ? err.envelope.error.message : t('productEditor.error.duplicate'));
595
+ setWholeProductError(withServerDetail(t('productEditor.error.duplicate'), err));
408
596
  }
409
597
  finally {
410
598
  setDuplicating(false);
411
599
  }
412
- }, [id, duplicating, navigate, t]);
413
- // Archive / Restore take effect at once, through their own
414
- // routes; they touch `archivedAt` only, so the form's unsaved edits (status
415
- // included) are neither sent nor lost.
416
- const handleArchiveAction = useCallback(async () => {
417
- if (!id || archiveDialog === null || archiving)
600
+ };
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)
418
625
  return;
419
626
  setArchiving(true);
420
627
  setArchiveError(null);
421
628
  try {
422
- const res = await apiClient.post(`/api/v1/admin/catalog/products/${id}/${archiveDialog}`, {});
423
- setArchivedAt(res.data.archivedAt ?? null);
629
+ const res = await apiClient.post(`${PRODUCT_PATH(productId)}/${archiveDialog}`, {});
630
+ setArchivedOverride(res.data.archivedAt ?? null);
424
631
  setInfo(t(archiveDialog === 'archive' ? 'productEditor.archive.done' : 'productEditor.restore.done'));
425
- setError(null);
426
632
  setArchiveDialog(null);
427
633
  }
428
634
  catch (err) {
429
- setArchiveError(err instanceof ApiError
430
- ? err.envelope.error.message
431
- : t(archiveDialog === 'archive' ? 'productEditor.archive.failed' : 'productEditor.restore.failed'));
635
+ setArchiveError(withServerDetail(t(archiveDialog === 'archive' ? 'productEditor.archive.failed' : 'productEditor.restore.failed'), err));
432
636
  }
433
637
  finally {
434
638
  setArchiving(false);
435
639
  }
436
- }, [id, archiveDialog, archiving, t]);
437
- if (loading)
438
- 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') }) }));
439
- const tabs = [
440
- { id: 'details', label: 'Details', icon: _jsx(FileTextIcon, { size: 14 }), show: true },
441
- { id: 'attributes', label: 'Attributes', icon: _jsx(SlidersHorizontal, { size: 14 }), show: !isNew },
442
- { id: 'pricing', label: t('productEditor.tab.pricing'), icon: _jsx(CircleDollarSign, { size: 14 }), show: !isNew },
443
- {
444
- id: 'variants',
445
- label: 'Variants',
446
- icon: _jsx(Layers, { size: 14 }),
447
- show: !isNew && type === 'configurable',
448
- },
449
- {
450
- id: 'composite',
451
- label: type === 'grouped' ? 'Grouped items' : 'Bundle slots',
452
- icon: _jsx(Layers, { size: 14 }),
453
- show: !isNew && (type === 'grouped' || type === 'bundle'),
454
- },
455
- { id: 'media', label: 'Media', icon: _jsx(ImageIcon, { size: 14 }), show: !isNew },
456
- { id: 'inventory', label: 'Inventory', icon: _jsx(WarehouseIcon, { size: 14 }), show: !isNew },
457
- { id: 'attachments', label: 'Attachments', icon: _jsx(Paperclip, { size: 14 }), show: !isNew },
458
- { id: 'links', label: 'Related', icon: _jsx(LinkIcon, { size: 14 }), show: !isNew },
459
- // Feature 091 / P7a, Z15 — the tab body is a zone, so the button is shown
460
- // by counting it. `useAdminZone` has already applied both presence axes and
461
- // each contributor's permission, so its length is the honest answer to "is
462
- // there anything behind this tab" — and a tab that opens on an empty panel
463
- // is worse than no tab. The label stays this screen's own word for the
464
- // place (Z14); what it stops knowing is which module fills it.
465
- {
466
- id: 'channels',
467
- label: 'Channels',
468
- icon: _jsx(StoreIcon, { size: 14 }),
469
- show: !isNew && channelContributions.length > 0,
470
- },
471
- // Feature 163 (US4) — channels × languages for this product, beside the channels it is in.
472
- { id: 'scopes', label: t('productEditor.tab.scopes'), icon: _jsx(LayoutGrid, { size: 14 }), show: !isNew },
473
- { id: 'seo', label: 'SEO', icon: _jsx(Globe, { size: 14 }), show: !isNew },
474
- ];
475
- const visibleTabs = tabs.filter((t) => t.show);
476
- 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(ProductStatusPill, { status: status, archived: Boolean(archivedAt) }) : null, !isNew && archivedAt ? _jsx(ArchivedPill, {}) : 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'] }), canWrite && !archivedAt ? (_jsxs("button", { type: "button", className: "b2b-btn b2b-btn--default b2b-btn--sm", onClick: () => {
477
- setArchiveError(null);
478
- setArchiveDialog('archive');
479
- }, children: [_jsx(Archive, { size: 13, "aria-hidden": "true" }), " ", t('productEditor.action.archive')] })) : null, _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) => {
480
- void handleSave(e);
481
- }, 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, _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 }), !isNew && 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", onClick: () => {
482
- setArchiveError(null);
483
- setArchiveDialog('restore');
484
- }, children: [_jsx(ArchiveRestore, { size: 13, "aria-hidden": "true" }), " ", t('productEditor.action.restore')] })) : 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: () => {
485
- void handleArchiveAction();
486
- }, 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, _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, globalStatus: status, onBaselineNameChange: (next) => setName({
487
- 'en-US': next['en-US'] ?? '',
488
- 'pl-PL': next['pl-PL'] ?? '',
489
- }), onBaselineDescriptionChange: (next) => setDescription({
490
- 'en-US': next['en-US'] ?? '',
491
- 'pl-PL': next['pl-PL'] ?? '',
492
- }) })) : 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, "aria-describedby": !isNew && archivedAt ? 'pstatus-help pstatus-archived' : 'pstatus-help', onChange: (e) => setStatus(e.target.value), children: STATUSES.map((s) => (_jsx("option", { value: s, children: t(`productEditor.statusValue.${s}`) }, s))) }), _jsx("p", { id: "pstatus-help", className: "b2b-help", children: t('productEditor.field.status.help') }), !isNew && archivedAt ? (_jsx("p", { id: "pstatus-archived", className: "b2b-help", children: t('productEditor.field.status.archivedNote') })) : null] })] })] }), id ? (_jsxs("div", { children: [_jsx("div", { className: "b2b-label", children: t('productEditor.field.publishWindow') }), _jsxs("div", { className: "b2b-row", style: { gap: 12, flexWrap: 'wrap' }, children: [_jsxs("div", { children: [_jsx(Label, { htmlFor: "ppublish-from", children: t('productEditor.field.publishFrom') }), _jsx(Input, { id: "ppublish-from", type: "datetime-local", value: publishFrom, "aria-describedby": windowError ? 'ppublish-help ppublish-error' : 'ppublish-help', "aria-invalid": windowError === 'invalidDate' ? true : undefined, onKeyDown: (e) => {
493
- if (e.key === 'Enter')
494
- e.preventDefault();
495
- }, onChange: (e) => {
496
- setPublishFrom(e.target.value);
497
- setWindowError(null);
498
- } })] }), _jsxs("div", { children: [_jsx(Label, { htmlFor: "ppublish-until", children: t('productEditor.field.publishUntil') }), _jsx(Input, { id: "ppublish-until", type: "datetime-local", value: publishUntil, "aria-describedby": windowError ? 'ppublish-help ppublish-error' : 'ppublish-help', "aria-invalid": windowError ? true : undefined, onKeyDown: (e) => {
499
- if (e.key === 'Enter')
500
- e.preventDefault();
501
- }, onChange: (e) => {
502
- setPublishUntil(e.target.value);
503
- setWindowError(null);
504
- } })] })] }), _jsx("p", { id: "ppublish-help", className: "b2b-help", children: t('productEditor.field.publishWindow.help') }), windowError ? (_jsx("p", { id: "ppublish-error", role: "alert", className: "text-sm text-destructive", style: { margin: 0 }, children: windowError === 'order'
505
- ? t('productEditor.scopeControls.window.invalidOrder')
506
- : t('productEditor.scopeControls.window.invalidDate') })) : null] })) : null, 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 ? (_jsx(AdminZone, { name: "product.editor.field.after", props: { productId: id, fieldPath: 'gallery', languageCodes: null } })) : null, (activeTab === 'media' || galleryOpened) && id ? (_jsx("div", { hidden: activeTab !== 'media', children: _jsx(GallerySection, { ref: galleryRef, productId: id, onDirtyChange: setGalleryDirty }) })) : 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, canWrite: canWrite })) : 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 === 'scopes' && id ? _jsx(ProductScopeOverview, { productId: id }) : null, activeTab === 'seo' && id ? _jsx(ProductUrlKeysPanel, { productId: id }) : null, activeTab === 'seo' && id ? (_jsx(AdminZone, { name: "product.editor.seo.after", props: { productId: id } })) : null] })] })] }));
507
- }
508
- function pickName(name) {
509
- return name['en-US'] ?? Object.values(name)[0] ?? '';
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] }) }));
510
892
  }
511
- function VariantsSection({ productId }) {
893
+ function VariantsSection({ productId, readOnly = false }) {
512
894
  const t = useTranslation('catalog');
895
+ const { ask, dialog: removalDialog } = useConfirmRemoval();
513
896
  const [variants, setVariants] = useState([]);
514
897
  const [loading, setLoading] = useState(true);
515
898
  const [error, setError] = useState(null);
@@ -518,12 +901,11 @@ function VariantsSection({ productId }) {
518
901
  setLoading(true);
519
902
  setError(null);
520
903
  try {
521
- // The PDP returns variants nested in productDetail; admin needs a
522
- // standalone read to keep the forms quick. Foundation didn't ship
523
- // a GET /admin/.../variants, but the public productDetail under
524
- // /api/v1/catalog/products/<idOrSlug> includes them — use that.
525
- const res = await apiClient.get(`/api/v1/catalog/products/${productId}`);
526
- 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);
527
909
  }
528
910
  catch (err) {
529
911
  setError(err instanceof ApiError ? err.envelope.error.message : t('productEditor.variants.error.load'));
@@ -563,7 +945,7 @@ function VariantsSection({ productId }) {
563
945
  }
564
946
  }, [productId, refresh, t]);
565
947
  const handleDelete = useCallback(async (variantId, sku) => {
566
- if (!confirm(t('productEditor.variants.deleteConfirm', { sku })))
948
+ if (!(await ask(t('productEditor.variants.deleteConfirm', { sku }))))
567
949
  return;
568
950
  try {
569
951
  await apiClient.delete(`/api/v1/admin/catalog/products/${productId}/variants/${variantId}`);
@@ -573,10 +955,10 @@ function VariantsSection({ productId }) {
573
955
  catch (err) {
574
956
  setError(err instanceof ApiError ? err.envelope.error.message : t('productEditor.variants.error.delete'));
575
957
  }
576
- }, [productId, refresh, t]);
577
- 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)
578
960
  .map(([k, val]) => `${k}=${String(val)}`)
579
- .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] }));
580
962
  }
581
963
  function CreateVariantInline({ onCreate, }) {
582
964
  const t = useTranslation('catalog');
@@ -599,13 +981,12 @@ function CreateVariantInline({ onCreate, }) {
599
981
  // ---------------------------------------------------------------------------
600
982
  const LINK_KINDS = ['related', 'up_sell', 'cross_sell'];
601
983
  function pickProductName(name, fallback) {
602
- if (!name)
603
- return fallback;
604
- return name['en-US'] ?? Object.values(name)[0] ?? fallback;
984
+ return typeof name === 'string' && name !== '' ? name : fallback;
605
985
  }
606
986
  const TARGETS_BATCH_PAGE_SIZE = 200;
607
- function ProductLinksSection({ productId }) {
987
+ function ProductLinksSection({ productId, readOnly = false }) {
608
988
  const t = useTranslation('catalog');
989
+ const { ask, dialog: removalDialog } = useConfirmRemoval();
609
990
  const [links, setLinks] = useState([]);
610
991
  const [targetsById, setTargetsById] = useState(() => new Map());
611
992
  const [loading, setLoading] = useState(true);
@@ -667,7 +1048,7 @@ function ProductLinksSection({ productId }) {
667
1048
  }
668
1049
  }, [productId, refresh, t]);
669
1050
  const handleDelete = useCallback(async (linkId) => {
670
- if (!confirm(t('productEditor.links.removeConfirm')))
1051
+ if (!(await ask(t('productEditor.links.removeConfirm'))))
671
1052
  return;
672
1053
  try {
673
1054
  await apiClient.delete(`/api/v1/admin/catalog/products/${productId}/links/${linkId}`);
@@ -677,7 +1058,7 @@ function ProductLinksSection({ productId }) {
677
1058
  catch (err) {
678
1059
  setError(err instanceof ApiError ? err.envelope.error.message : t('productEditor.links.error.delete'));
679
1060
  }
680
- }, [productId, refresh, t]);
1061
+ }, [productId, refresh, ask, t]);
681
1062
  const byKind = useMemo(() => {
682
1063
  const result = {
683
1064
  related: [],
@@ -691,7 +1072,7 @@ function ProductLinksSection({ productId }) {
691
1072
  }
692
1073
  return result;
693
1074
  }, [links]);
694
- 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) => {
695
1076
  const target = targetsById.get(link.targetProductId);
696
1077
  const isMissing = !target;
697
1078
  // `inactive` is plain off; archived is its own fact.
@@ -699,8 +1080,8 @@ function ProductLinksSection({ productId }) {
699
1080
  const isArchived = target?.archivedAt != null;
700
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
701
1082
  ? pickProductName(target.name, target.slug)
702
- : `${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 }), _jsx(TableCell, { children: _jsx(Button, { type: "button", size: "sm", variant: "destructive", onClick: () => void handleDelete(link.id), children: t('productEditor.links.action.remove') }) })] }, link.id));
703
- }) })] }))] }, 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] }));
704
1085
  }
705
1086
  function CreateProductLinkInline({ onCreate, sourceProductId, }) {
706
1087
  const t = useTranslation('catalog');
@@ -714,8 +1095,9 @@ function CreateProductLinkInline({ onCreate, sourceProductId, }) {
714
1095
  });
715
1096
  }, children: t('productEditor.links.action.add') }) })] }));
716
1097
  }
717
- function GroupedItemsSection({ productId }) {
1098
+ function GroupedItemsSection({ productId, readOnly = false }) {
718
1099
  const t = useTranslation('catalog');
1100
+ const { ask, dialog: removalDialog } = useConfirmRemoval();
719
1101
  const [items, setItems] = useState([]);
720
1102
  const [loading, setLoading] = useState(true);
721
1103
  const [error, setError] = useState(null);
@@ -753,7 +1135,7 @@ function GroupedItemsSection({ productId }) {
753
1135
  }
754
1136
  }, [productId, refresh, t]);
755
1137
  const handleDelete = useCallback(async (itemId) => {
756
- if (!confirm(t('productEditor.grouped.removeConfirm')))
1138
+ if (!(await ask(t('productEditor.grouped.removeConfirm'))))
757
1139
  return;
758
1140
  try {
759
1141
  await apiClient.delete(`/api/v1/admin/catalog/products/${productId}/grouped-items/${itemId}`);
@@ -763,8 +1145,8 @@ function GroupedItemsSection({ productId }) {
763
1145
  catch (err) {
764
1146
  setError(err instanceof ApiError ? err.envelope.error.message : t('productEditor.grouped.error.delete'));
765
1147
  }
766
- }, [productId, refresh, t]);
767
- 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] }));
768
1150
  }
769
1151
  function CreateGroupedItemInline({ onCreate, }) {
770
1152
  const t = useTranslation('catalog');
@@ -779,8 +1161,9 @@ function CreateGroupedItemInline({ onCreate, }) {
779
1161
  });
780
1162
  }, children: t('productEditor.grouped.action.add') }) })] }));
781
1163
  }
782
- function BundleSlotsSection({ productId }) {
1164
+ function BundleSlotsSection({ productId, readOnly = false }) {
783
1165
  const t = useTranslation('catalog');
1166
+ const { ask, dialog: removalDialog } = useConfirmRemoval();
784
1167
  const [slots, setSlots] = useState([]);
785
1168
  const [loading, setLoading] = useState(true);
786
1169
  const [error, setError] = useState(null);
@@ -823,7 +1206,7 @@ function BundleSlotsSection({ productId }) {
823
1206
  }
824
1207
  }, [productId, refresh, t]);
825
1208
  const handleDeleteSlot = useCallback(async (slotId) => {
826
- if (!confirm(t('productEditor.bundle.removeSlotConfirm')))
1209
+ if (!(await ask(t('productEditor.bundle.removeSlotConfirm'))))
827
1210
  return;
828
1211
  try {
829
1212
  await apiClient.delete(`/api/v1/admin/catalog/products/${productId}/bundle-slots/${slotId}`);
@@ -833,7 +1216,7 @@ function BundleSlotsSection({ productId }) {
833
1216
  catch (err) {
834
1217
  setError(err instanceof ApiError ? err.envelope.error.message : t('productEditor.bundle.error.deleteSlot'));
835
1218
  }
836
- }, [productId, refresh, t]);
1219
+ }, [productId, refresh, ask, t]);
837
1220
  const handleAddOption = useCallback(async (slotId, optionProductId) => {
838
1221
  if (!optionProductId)
839
1222
  return;
@@ -847,7 +1230,7 @@ function BundleSlotsSection({ productId }) {
847
1230
  }
848
1231
  }, [productId, refresh, t]);
849
1232
  const handleRemoveOption = useCallback(async (slotId, optionId) => {
850
- if (!confirm(t('productEditor.bundle.removeOptionConfirm')))
1233
+ if (!(await ask(t('productEditor.bundle.removeOptionConfirm'))))
851
1234
  return;
852
1235
  try {
853
1236
  await apiClient.delete(`/api/v1/admin/catalog/products/${productId}/bundle-slots/${slotId}/options/${optionId}`);
@@ -857,21 +1240,21 @@ function BundleSlotsSection({ productId }) {
857
1240
  catch (err) {
858
1241
  setError(err instanceof ApiError ? err.envelope.error.message : t('productEditor.bundle.error.deleteOption'));
859
1242
  }
860
- }, [productId, refresh, t]);
861
- 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] }));
862
1245
  }
863
- function BundleSlotCard({ slot, onAddOption, onRemoveOption, onDeleteSlot, }) {
1246
+ function BundleSlotCard({ slot, onAddOption, onRemoveOption, onDeleteSlot, readOnly = false, }) {
864
1247
  const t = useTranslation('catalog');
865
1248
  const [optionId, setOptionId] = useState('');
866
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', {
867
1250
  min: slot.minQuantity,
868
1251
  max: slot.maxQuantity,
869
1252
  position: slot.position,
870
- }) })] }), _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: () => {
871
1254
  void onAddOption(slot.id, optionId).then(() => {
872
1255
  setOptionId('');
873
1256
  });
874
- }, children: t('productEditor.bundle.action.addOption') })] })] }));
1257
+ }, children: t('productEditor.bundle.action.addOption') })] }))] }));
875
1258
  }
876
1259
  function CreateBundleSlotInline({ onCreate, }) {
877
1260
  const t = useTranslation('catalog');