@endora-commerce/mod-catalog 0.109.0 → 0.111.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 (615) hide show
  1. package/dist/admin/components/CopyToChannelsDialog.d.ts +37 -0
  2. package/dist/admin/components/CopyToChannelsDialog.js +83 -0
  3. package/dist/admin/components/PackagingUnitsEditor.d.ts +13 -4
  4. package/dist/admin/components/PackagingUnitsEditor.js +21 -85
  5. package/dist/admin/components/ProductAttachmentsSection.d.ts +1 -3
  6. package/dist/admin/components/ProductAttachmentsSection.js +59 -98
  7. package/dist/admin/components/ProductAttributesTab.d.ts +1 -11
  8. package/dist/admin/components/ProductAttributesTab.js +128 -119
  9. package/dist/admin/components/ProductContentCard.d.ts +41 -0
  10. package/dist/admin/components/ProductContentCard.js +28 -0
  11. package/dist/admin/components/ProductEditorSaveAction.d.ts +22 -0
  12. package/dist/admin/components/ProductEditorSaveAction.js +23 -0
  13. package/dist/admin/components/ProductGallerySection.d.ts +2 -13
  14. package/dist/admin/components/ProductGallerySection.js +98 -354
  15. package/dist/admin/components/ProductInventoryTab.d.ts +12 -1
  16. package/dist/admin/components/ProductInventoryTab.js +52 -115
  17. package/dist/admin/components/ProductOrderRulesCard.d.ts +11 -15
  18. package/dist/admin/components/ProductOrderRulesCard.js +15 -268
  19. package/dist/admin/components/ProductScopeBar.d.ts +34 -0
  20. package/dist/admin/components/ProductScopeBar.js +70 -0
  21. package/dist/admin/components/ProductScopeOverview.d.ts +13 -1
  22. package/dist/admin/components/ProductScopeOverview.js +56 -37
  23. package/dist/admin/components/ProductUrlRedirects.d.ts +15 -0
  24. package/dist/admin/components/ProductUrlRedirects.js +70 -0
  25. package/dist/admin/components/ProductsBulkEditDialog.js +4 -3
  26. package/dist/admin/components/editor/DetailsTab.d.ts +30 -0
  27. package/dist/admin/components/editor/DetailsTab.js +60 -0
  28. package/dist/admin/components/editor/SectionHeading.d.ts +22 -0
  29. package/dist/admin/components/editor/SectionHeading.js +19 -0
  30. package/dist/admin/components/editor/confirm-removal.d.ts +13 -0
  31. package/dist/admin/components/editor/confirm-removal.js +33 -0
  32. package/dist/admin/components/editor/editor-context.d.ts +55 -0
  33. package/dist/admin/components/editor/editor-context.js +88 -0
  34. package/dist/admin/components/editor/scoped-controls.d.ts +46 -0
  35. package/dist/admin/components/editor/scoped-controls.js +64 -0
  36. package/dist/admin/index.d.ts +1 -1
  37. package/dist/admin/index.js +11 -0
  38. package/dist/admin/lib/attribute-scope.d.ts +17 -14
  39. package/dist/admin/lib/attribute-scope.js +12 -9
  40. package/dist/admin/lib/bulk-result-outcome.d.ts +14 -0
  41. package/dist/admin/lib/bulk-result-outcome.js +13 -0
  42. package/dist/admin/lib/editor-scope.d.ts +35 -0
  43. package/dist/admin/lib/editor-scope.js +114 -0
  44. package/dist/admin/lib/order-minimum-input.d.ts +13 -0
  45. package/dist/admin/lib/order-minimum-input.js +16 -0
  46. package/dist/admin/lib/product-labels.d.ts +0 -2
  47. package/dist/admin/lib/product-labels.js +1 -5
  48. package/dist/admin/lib/product-scopes-api.d.ts +5 -22
  49. package/dist/admin/lib/product-scopes-api.js +4 -48
  50. package/dist/admin/lib/product-url-keys-api.d.ts +4 -27
  51. package/dist/admin/lib/product-url-keys-api.js +1 -50
  52. package/dist/admin/lib/scope-overview.d.ts +13 -14
  53. package/dist/admin/lib/scope-overview.js +36 -31
  54. package/dist/admin/lib/scoped-editor-store.d.ts +81 -0
  55. package/dist/admin/lib/scoped-editor-store.js +198 -0
  56. package/dist/admin/lib/scoped-values-api.d.ts +14 -0
  57. package/dist/admin/lib/scoped-values-api.js +55 -0
  58. package/dist/admin/pages/AttachmentTypesPage.js +14 -4
  59. package/dist/admin/pages/AttributeSetsPage.js +11 -4
  60. package/dist/admin/pages/AttributesManager.js +130 -40
  61. package/dist/admin/pages/BulkOperationDetailPage.js +11 -4
  62. package/dist/admin/pages/CategoriesTree.d.ts +5 -0
  63. package/dist/admin/pages/CategoriesTree.js +226 -40
  64. package/dist/admin/pages/ProductContentPage.d.ts +27 -0
  65. package/dist/admin/pages/ProductContentPage.js +161 -0
  66. package/dist/admin/pages/ProductCreateForm.d.ts +3 -0
  67. package/dist/admin/pages/ProductCreateForm.js +87 -0
  68. package/dist/admin/pages/ProductEditor.js +938 -458
  69. package/dist/admin/pages/ProductsList.js +33 -38
  70. package/dist/backend/admin-search-provider.d.ts +2 -1
  71. package/dist/backend/admin-search-provider.js +1 -1
  72. package/dist/backend/commands/attribute-commands.d.ts +4 -3
  73. package/dist/backend/commands/attribute-commands.js +137 -30
  74. package/dist/backend/commands/product-content-commands.d.ts +31 -0
  75. package/dist/backend/commands/product-content-commands.js +70 -0
  76. package/dist/backend/commands/scoped-values.commands.d.ts +95 -0
  77. package/dist/backend/commands/scoped-values.commands.js +235 -0
  78. package/dist/backend/demo/reset.js +2 -1
  79. package/dist/backend/demo/rows.d.ts +18 -0
  80. package/dist/backend/demo/rows.js +18 -0
  81. package/dist/backend/demo/seed.d.ts +2 -1
  82. package/dist/backend/demo/seed.js +20 -6
  83. package/dist/backend/entities/gallery-item-scope-override.entity.d.ts +30 -0
  84. package/dist/backend/entities/gallery-item-scope-override.entity.js +80 -0
  85. package/dist/backend/entities/gallery-item.entity.d.ts +7 -6
  86. package/dist/backend/entities/gallery-item.entity.js +11 -6
  87. package/dist/backend/entities/gallery-role-scope-override.entity.d.ts +28 -0
  88. package/dist/backend/entities/gallery-role-scope-override.entity.js +75 -0
  89. package/dist/backend/entities/product-attachment-scope-override.entity.d.ts +30 -0
  90. package/dist/backend/entities/product-attachment-scope-override.entity.js +80 -0
  91. package/dist/backend/entities/product-attachment.entity.d.ts +4 -6
  92. package/dist/backend/entities/product-attachment.entity.js +6 -12
  93. package/dist/backend/entities/product-attribute.entity.d.ts +5 -9
  94. package/dist/backend/entities/product-attribute.entity.js +5 -13
  95. package/dist/backend/entities/product-channel-scope.entity.d.ts +7 -2
  96. package/dist/backend/entities/product-channel-scope.entity.js +10 -1
  97. package/dist/backend/entities/product-content-value.entity.d.ts +39 -0
  98. package/dist/backend/entities/product-content-value.entity.js +81 -0
  99. package/dist/backend/entities/product-packaging-unit-scope-override.entity.d.ts +30 -0
  100. package/dist/backend/entities/product-packaging-unit-scope-override.entity.js +80 -0
  101. package/dist/backend/entities/product-packaging-unit.entity.d.ts +1 -7
  102. package/dist/backend/entities/product-packaging-unit.entity.js +0 -10
  103. package/dist/backend/entities/product-url-key.entity.d.ts +14 -19
  104. package/dist/backend/entities/product-url-key.entity.js +17 -22
  105. package/dist/backend/entities/product-url-redirect.entity.d.ts +8 -13
  106. package/dist/backend/entities/product-url-redirect.entity.js +13 -14
  107. package/dist/backend/entities/product-variant.entity.d.ts +8 -1
  108. package/dist/backend/entities/product-variant.entity.js +13 -2
  109. package/dist/backend/entities/product.entity.d.ts +31 -14
  110. package/dist/backend/entities/product.entity.js +41 -34
  111. package/dist/backend/index.d.ts +11 -3
  112. package/dist/backend/index.js +155 -49
  113. package/dist/backend/plugin.d.ts +36 -6
  114. package/dist/backend/plugin.js +36 -13
  115. package/dist/backend/prompt-tools.d.ts +3 -2
  116. package/dist/backend/prompt-tools.js +18 -7
  117. package/dist/backend/routes.admin.d.ts +15 -16
  118. package/dist/backend/routes.admin.js +122 -103
  119. package/dist/backend/routes.api-key.js +4 -2
  120. package/dist/backend/routes.external.js +3 -2
  121. package/dist/backend/routes.public.d.ts +8 -1
  122. package/dist/backend/routes.public.js +68 -11
  123. package/dist/backend/services/asset-references.d.ts +12 -1
  124. package/dist/backend/services/asset-references.js +42 -2
  125. package/dist/backend/services/attachment-packaging-scopes.d.ts +38 -20
  126. package/dist/backend/services/attachment-packaging-scopes.js +58 -75
  127. package/dist/backend/services/attachment.service.d.ts +4 -8
  128. package/dist/backend/services/attachment.service.js +35 -49
  129. package/dist/backend/services/attribute-filter-match.d.ts +14 -0
  130. package/dist/backend/services/attribute-filter-match.js +19 -0
  131. package/dist/backend/services/attribute-scope-preview.d.ts +17 -7
  132. package/dist/backend/services/attribute-scope-preview.js +30 -20
  133. package/dist/backend/services/attribute-set.service.d.ts +10 -1
  134. package/dist/backend/services/attribute-set.service.js +30 -4
  135. package/dist/backend/services/attribute-type-mapping.d.ts +2 -2
  136. package/dist/backend/services/attribute-type-mapping.js +6 -0
  137. package/dist/backend/services/attribute-usage.d.ts +31 -0
  138. package/dist/backend/services/attribute-usage.js +29 -0
  139. package/dist/backend/services/bulk-operation.service.d.ts +1 -1
  140. package/dist/backend/services/bulk-operation.service.js +16 -6
  141. package/dist/backend/services/bundle.service.js +19 -1
  142. package/dist/backend/services/catalog-admin-search.service.d.ts +3 -2
  143. package/dist/backend/services/catalog-admin-search.service.js +6 -6
  144. package/dist/backend/services/catalog-admin.service.d.ts +63 -12
  145. package/dist/backend/services/catalog-admin.service.js +368 -195
  146. package/dist/backend/services/catalog-attribute-read.service.d.ts +14 -0
  147. package/dist/backend/services/catalog-attribute-read.service.js +9 -19
  148. package/dist/backend/services/catalog-bulk-import.service.d.ts +58 -5
  149. package/dist/backend/services/catalog-bulk-import.service.js +192 -142
  150. package/dist/backend/services/catalog-bulk-update.service.d.ts +5 -3
  151. package/dist/backend/services/catalog-bulk-update.service.js +21 -8
  152. package/dist/backend/services/catalog-product-read.service.d.ts +11 -1
  153. package/dist/backend/services/catalog-product-read.service.js +37 -17
  154. package/dist/backend/services/catalog-query.service.d.ts +48 -8
  155. package/dist/backend/services/catalog-query.service.js +180 -116
  156. package/dist/backend/services/catalog-quick-search.service.js +5 -5
  157. package/dist/backend/services/catalog-write-ports.d.ts +14 -16
  158. package/dist/backend/services/catalog-write-ports.js +11 -70
  159. package/dist/backend/services/category-admin.service.js +29 -5
  160. package/dist/backend/services/content-attribute-rules.d.ts +61 -0
  161. package/dist/backend/services/content-attribute-rules.js +102 -0
  162. package/dist/backend/services/effective-value.sql.d.ts +24 -38
  163. package/dist/backend/services/effective-value.sql.js +37 -87
  164. package/dist/backend/services/gallery-scopes.d.ts +45 -22
  165. package/dist/backend/services/gallery-scopes.js +116 -109
  166. package/dist/backend/services/gallery.service.d.ts +13 -27
  167. package/dist/backend/services/gallery.service.js +75 -199
  168. package/dist/backend/services/grouped.service.js +20 -3
  169. package/dist/backend/services/packaging-unit.service.js +7 -12
  170. package/dist/backend/services/page-builder-content.d.ts +64 -0
  171. package/dist/backend/services/page-builder-content.js +113 -0
  172. package/dist/backend/services/primary-asset-url.d.ts +6 -1
  173. package/dist/backend/services/primary-asset-url.js +9 -4
  174. package/dist/backend/services/product-availability.service.d.ts +16 -3
  175. package/dist/backend/services/product-availability.service.js +58 -21
  176. package/dist/backend/services/product-content.service.d.ts +62 -0
  177. package/dist/backend/services/product-content.service.js +122 -0
  178. package/dist/backend/services/product-editor-preferences.service.d.ts +6 -0
  179. package/dist/backend/services/product-editor-preferences.service.js +12 -0
  180. package/dist/backend/services/product-global-field-rules.d.ts +39 -0
  181. package/dist/backend/services/product-global-field-rules.js +84 -0
  182. package/dist/backend/services/product-link.service.js +14 -16
  183. package/dist/backend/services/product-list-view-service.js +5 -8
  184. package/dist/backend/services/product-page-revalidation.d.ts +9 -0
  185. package/dist/backend/services/product-page-revalidation.js +19 -0
  186. package/dist/backend/services/product-scopes.service.d.ts +18 -8
  187. package/dist/backend/services/product-scopes.service.js +91 -36
  188. package/dist/backend/services/product-value-resolver.service.d.ts +2 -2
  189. package/dist/backend/services/product-value-resolver.service.js +4 -7
  190. package/dist/backend/services/publication-window-sweep.d.ts +61 -7
  191. package/dist/backend/services/publication-window-sweep.js +106 -19
  192. package/dist/backend/services/scheduled-work-probe.d.ts +34 -0
  193. package/dist/backend/services/scheduled-work-probe.js +30 -0
  194. package/dist/backend/services/scope-completeness.d.ts +11 -11
  195. package/dist/backend/services/scope-completeness.js +26 -33
  196. package/dist/backend/services/scope-overview.service.d.ts +24 -24
  197. package/dist/backend/services/scope-overview.service.js +33 -76
  198. package/dist/backend/services/scoped-store-adapters.d.ts +58 -0
  199. package/dist/backend/services/scoped-store-adapters.js +92 -0
  200. package/dist/backend/services/scoped-values-global-only.d.ts +36 -0
  201. package/dist/backend/services/scoped-values-global-only.js +92 -0
  202. package/dist/backend/services/scoped-values-import.d.ts +86 -0
  203. package/dist/backend/services/scoped-values-import.js +320 -0
  204. package/dist/backend/services/scoped-values-read.service.d.ts +56 -0
  205. package/dist/backend/services/scoped-values-read.service.js +289 -0
  206. package/dist/backend/services/scoped-values-save.service.d.ts +79 -0
  207. package/dist/backend/services/scoped-values-save.service.js +675 -0
  208. package/dist/backend/services/scoped-values-state.d.ts +94 -0
  209. package/dist/backend/services/scoped-values-state.js +159 -0
  210. package/dist/backend/services/scoped-values.service.d.ts +36 -0
  211. package/dist/backend/services/scoped-values.service.js +92 -0
  212. package/dist/backend/services/storefront-value-overrides.d.ts +7 -8
  213. package/dist/backend/services/storefront-value-overrides.js +11 -14
  214. package/dist/backend/services/table-maintenance-queue.d.ts +78 -0
  215. package/dist/backend/services/table-maintenance-queue.js +97 -0
  216. package/dist/backend/services/url-key-resolution.service.d.ts +12 -18
  217. package/dist/backend/services/url-key-resolution.service.js +43 -43
  218. package/dist/backend/services/url-key.service.d.ts +87 -135
  219. package/dist/backend/services/url-key.service.js +447 -619
  220. package/dist/manifest.d.ts +51 -1
  221. package/dist/manifest.js +111 -7
  222. package/dist/migrations/20261030T113855_catalog_scope_model_texts.d.ts +36 -0
  223. package/dist/migrations/20261030T113855_catalog_scope_model_texts.js +225 -0
  224. package/dist/migrations/20261030T113859_catalog_scope_model_order_rules.d.ts +18 -0
  225. package/dist/migrations/20261030T113859_catalog_scope_model_order_rules.js +39 -0
  226. package/dist/migrations/20261030T113904_catalog_scope_model_url_keys.d.ts +6 -0
  227. package/dist/migrations/20261030T113904_catalog_scope_model_url_keys.js +119 -0
  228. package/dist/migrations/20261030T113908_catalog_scope_model_media.d.ts +6 -0
  229. package/dist/migrations/20261030T113908_catalog_scope_model_media.js +185 -0
  230. package/dist/migrations/20261104T121504_catalog_product_content_values.d.ts +36 -0
  231. package/dist/migrations/20261104T121504_catalog_product_content_values.js +53 -0
  232. package/dist/migrations/20261107T093126_catalog_sku_unique_among_live.d.ts +33 -0
  233. package/dist/migrations/20261107T093126_catalog_sku_unique_among_live.js +58 -0
  234. package/dist/migrations/20261107T120008_catalog_product_created_at_milliseconds.d.ts +36 -0
  235. package/dist/migrations/20261107T120008_catalog_product_created_at_milliseconds.js +40 -0
  236. package/dist/migrations/20261114T000706_catalog_category_main_image.d.ts +37 -0
  237. package/dist/migrations/20261114T000706_catalog_category_main_image.js +56 -0
  238. package/dist/migrations/index.d.ts +9 -1
  239. package/dist/migrations/index.js +17 -1
  240. package/docs/catalog/attachments.md +53 -43
  241. package/docs/catalog/attribute-sets.md +3 -2
  242. package/docs/catalog/attributes.md +99 -25
  243. package/docs/catalog/category-content.md +9 -3
  244. package/docs/catalog/composite-products.md +5 -3
  245. package/docs/catalog/editing-a-product-at-a-scope.md +151 -0
  246. package/docs/catalog/gallery-and-labels.md +61 -60
  247. package/docs/catalog/packaging-units.md +43 -34
  248. package/docs/catalog/per-channel-per-language-overrides.md +83 -410
  249. package/docs/catalog/product-content.md +184 -0
  250. package/docs/catalog/product-links.md +2 -2
  251. package/docs/catalog/url-keys-and-redirects.md +79 -79
  252. package/docs/catalog.md +113 -31
  253. package/i18n/en.json +317 -274
  254. package/i18n/pl.json +319 -276
  255. package/package.json +13 -12
  256. package/dist/admin/components/AttachmentScopesDialog.d.ts +0 -22
  257. package/dist/admin/components/AttachmentScopesDialog.d.ts.map +0 -1
  258. package/dist/admin/components/AttachmentScopesDialog.js +0 -70
  259. package/dist/admin/components/AttachmentScopesDialog.js.map +0 -1
  260. package/dist/admin/components/PackagingUnitsEditor.d.ts.map +0 -1
  261. package/dist/admin/components/PackagingUnitsEditor.js.map +0 -1
  262. package/dist/admin/components/ProductAttachmentsSection.d.ts.map +0 -1
  263. package/dist/admin/components/ProductAttachmentsSection.js.map +0 -1
  264. package/dist/admin/components/ProductAttributesTab.d.ts.map +0 -1
  265. package/dist/admin/components/ProductAttributesTab.js.map +0 -1
  266. package/dist/admin/components/ProductGallerySection.d.ts.map +0 -1
  267. package/dist/admin/components/ProductGallerySection.js.map +0 -1
  268. package/dist/admin/components/ProductInventoryTab.d.ts.map +0 -1
  269. package/dist/admin/components/ProductInventoryTab.js.map +0 -1
  270. package/dist/admin/components/ProductOrderRulesCard.d.ts.map +0 -1
  271. package/dist/admin/components/ProductOrderRulesCard.js.map +0 -1
  272. package/dist/admin/components/ProductScopeControls.d.ts +0 -31
  273. package/dist/admin/components/ProductScopeControls.d.ts.map +0 -1
  274. package/dist/admin/components/ProductScopeControls.js +0 -243
  275. package/dist/admin/components/ProductScopeControls.js.map +0 -1
  276. package/dist/admin/components/ProductScopeEditor.d.ts +0 -88
  277. package/dist/admin/components/ProductScopeEditor.d.ts.map +0 -1
  278. package/dist/admin/components/ProductScopeEditor.js +0 -396
  279. package/dist/admin/components/ProductScopeEditor.js.map +0 -1
  280. package/dist/admin/components/ProductScopeOverview.d.ts.map +0 -1
  281. package/dist/admin/components/ProductScopeOverview.js.map +0 -1
  282. package/dist/admin/components/ProductStatusPills.d.ts.map +0 -1
  283. package/dist/admin/components/ProductStatusPills.js.map +0 -1
  284. package/dist/admin/components/ProductUrlKeysPanel.d.ts +0 -17
  285. package/dist/admin/components/ProductUrlKeysPanel.d.ts.map +0 -1
  286. package/dist/admin/components/ProductUrlKeysPanel.js +0 -215
  287. package/dist/admin/components/ProductUrlKeysPanel.js.map +0 -1
  288. package/dist/admin/components/ProductsBulkEditDialog.d.ts.map +0 -1
  289. package/dist/admin/components/ProductsBulkEditDialog.js.map +0 -1
  290. package/dist/admin/components/ScopedDialogParts.d.ts +0 -23
  291. package/dist/admin/components/ScopedDialogParts.d.ts.map +0 -1
  292. package/dist/admin/components/ScopedDialogParts.js +0 -16
  293. package/dist/admin/components/ScopedDialogParts.js.map +0 -1
  294. package/dist/admin/index.d.ts.map +0 -1
  295. package/dist/admin/index.js.map +0 -1
  296. package/dist/admin/lib/attribute-scope.d.ts.map +0 -1
  297. package/dist/admin/lib/attribute-scope.js.map +0 -1
  298. package/dist/admin/lib/bulk-operation-log-text.d.ts.map +0 -1
  299. package/dist/admin/lib/bulk-operation-log-text.js.map +0 -1
  300. package/dist/admin/lib/media-scopes.d.ts +0 -41
  301. package/dist/admin/lib/media-scopes.d.ts.map +0 -1
  302. package/dist/admin/lib/media-scopes.js +0 -66
  303. package/dist/admin/lib/media-scopes.js.map +0 -1
  304. package/dist/admin/lib/product-labels.d.ts.map +0 -1
  305. package/dist/admin/lib/product-labels.js.map +0 -1
  306. package/dist/admin/lib/product-scope-drafts.d.ts +0 -77
  307. package/dist/admin/lib/product-scope-drafts.d.ts.map +0 -1
  308. package/dist/admin/lib/product-scope-drafts.js +0 -133
  309. package/dist/admin/lib/product-scope-drafts.js.map +0 -1
  310. package/dist/admin/lib/product-scopes-api.d.ts.map +0 -1
  311. package/dist/admin/lib/product-scopes-api.js.map +0 -1
  312. package/dist/admin/lib/product-url-keys-api.d.ts.map +0 -1
  313. package/dist/admin/lib/product-url-keys-api.js.map +0 -1
  314. package/dist/admin/lib/resolve-product-selection.d.ts.map +0 -1
  315. package/dist/admin/lib/resolve-product-selection.js.map +0 -1
  316. package/dist/admin/lib/scope-overview.d.ts.map +0 -1
  317. package/dist/admin/lib/scope-overview.js.map +0 -1
  318. package/dist/admin/pages/AttachmentTypesPage.d.ts.map +0 -1
  319. package/dist/admin/pages/AttachmentTypesPage.js.map +0 -1
  320. package/dist/admin/pages/AttributeSetsPage.d.ts.map +0 -1
  321. package/dist/admin/pages/AttributeSetsPage.js.map +0 -1
  322. package/dist/admin/pages/AttributesManager.d.ts.map +0 -1
  323. package/dist/admin/pages/AttributesManager.js.map +0 -1
  324. package/dist/admin/pages/BulkOperationDetailPage.d.ts.map +0 -1
  325. package/dist/admin/pages/BulkOperationDetailPage.js.map +0 -1
  326. package/dist/admin/pages/BulkOperationsPage.d.ts.map +0 -1
  327. package/dist/admin/pages/BulkOperationsPage.js.map +0 -1
  328. package/dist/admin/pages/CategoriesTree.d.ts.map +0 -1
  329. package/dist/admin/pages/CategoriesTree.js.map +0 -1
  330. package/dist/admin/pages/CategoryContentPage.d.ts.map +0 -1
  331. package/dist/admin/pages/CategoryContentPage.js.map +0 -1
  332. package/dist/admin/pages/ProductEditor.d.ts.map +0 -1
  333. package/dist/admin/pages/ProductEditor.js.map +0 -1
  334. package/dist/admin/pages/ProductsList.d.ts.map +0 -1
  335. package/dist/admin/pages/ProductsList.js.map +0 -1
  336. package/dist/backend/admin-search-provider.d.ts.map +0 -1
  337. package/dist/backend/admin-search-provider.js.map +0 -1
  338. package/dist/backend/commands/attribute-commands.d.ts.map +0 -1
  339. package/dist/backend/commands/attribute-commands.js.map +0 -1
  340. package/dist/backend/demo/reset.d.ts.map +0 -1
  341. package/dist/backend/demo/reset.js.map +0 -1
  342. package/dist/backend/demo/rows.d.ts.map +0 -1
  343. package/dist/backend/demo/rows.js.map +0 -1
  344. package/dist/backend/demo/seed.d.ts.map +0 -1
  345. package/dist/backend/demo/seed.js.map +0 -1
  346. package/dist/backend/entities/attachment-type.entity.d.ts.map +0 -1
  347. package/dist/backend/entities/attachment-type.entity.js.map +0 -1
  348. package/dist/backend/entities/attribute-set-attribute.entity.d.ts.map +0 -1
  349. package/dist/backend/entities/attribute-set-attribute.entity.js.map +0 -1
  350. package/dist/backend/entities/attribute-set.entity.d.ts.map +0 -1
  351. package/dist/backend/entities/attribute-set.entity.js.map +0 -1
  352. package/dist/backend/entities/bulk-operation.entity.d.ts.map +0 -1
  353. package/dist/backend/entities/bulk-operation.entity.js.map +0 -1
  354. package/dist/backend/entities/bundle-slot-option.entity.d.ts.map +0 -1
  355. package/dist/backend/entities/bundle-slot-option.entity.js.map +0 -1
  356. package/dist/backend/entities/bundle-slot.entity.d.ts.map +0 -1
  357. package/dist/backend/entities/bundle-slot.entity.js.map +0 -1
  358. package/dist/backend/entities/category.entity.d.ts.map +0 -1
  359. package/dist/backend/entities/category.entity.js.map +0 -1
  360. package/dist/backend/entities/gallery-item-channel-hidden.entity.d.ts +0 -14
  361. package/dist/backend/entities/gallery-item-channel-hidden.entity.d.ts.map +0 -1
  362. package/dist/backend/entities/gallery-item-channel-hidden.entity.js +0 -42
  363. package/dist/backend/entities/gallery-item-channel-hidden.entity.js.map +0 -1
  364. package/dist/backend/entities/gallery-item-channel-label.entity.d.ts +0 -18
  365. package/dist/backend/entities/gallery-item-channel-label.entity.d.ts.map +0 -1
  366. package/dist/backend/entities/gallery-item-channel-label.entity.js +0 -49
  367. package/dist/backend/entities/gallery-item-channel-label.entity.js.map +0 -1
  368. package/dist/backend/entities/gallery-item-label.entity.d.ts.map +0 -1
  369. package/dist/backend/entities/gallery-item-label.entity.js.map +0 -1
  370. package/dist/backend/entities/gallery-item.entity.d.ts.map +0 -1
  371. package/dist/backend/entities/gallery-item.entity.js.map +0 -1
  372. package/dist/backend/entities/grouped-item.entity.d.ts.map +0 -1
  373. package/dist/backend/entities/grouped-item.entity.js.map +0 -1
  374. package/dist/backend/entities/product-attachment-channel-hidden.entity.d.ts +0 -13
  375. package/dist/backend/entities/product-attachment-channel-hidden.entity.d.ts.map +0 -1
  376. package/dist/backend/entities/product-attachment-channel-hidden.entity.js +0 -41
  377. package/dist/backend/entities/product-attachment-channel-hidden.entity.js.map +0 -1
  378. package/dist/backend/entities/product-attachment.entity.d.ts.map +0 -1
  379. package/dist/backend/entities/product-attachment.entity.js.map +0 -1
  380. package/dist/backend/entities/product-attribute.entity.d.ts.map +0 -1
  381. package/dist/backend/entities/product-attribute.entity.js.map +0 -1
  382. package/dist/backend/entities/product-channel-language-scope.entity.d.ts.map +0 -1
  383. package/dist/backend/entities/product-channel-language-scope.entity.js.map +0 -1
  384. package/dist/backend/entities/product-channel-scope.entity.d.ts.map +0 -1
  385. package/dist/backend/entities/product-channel-scope.entity.js.map +0 -1
  386. package/dist/backend/entities/product-editor-preference.entity.d.ts.map +0 -1
  387. package/dist/backend/entities/product-editor-preference.entity.js.map +0 -1
  388. package/dist/backend/entities/product-link.entity.d.ts.map +0 -1
  389. package/dist/backend/entities/product-link.entity.js.map +0 -1
  390. package/dist/backend/entities/product-list-saved-view.entity.d.ts.map +0 -1
  391. package/dist/backend/entities/product-list-saved-view.entity.js.map +0 -1
  392. package/dist/backend/entities/product-packaging-unit.entity.d.ts.map +0 -1
  393. package/dist/backend/entities/product-packaging-unit.entity.js.map +0 -1
  394. package/dist/backend/entities/product-url-key.entity.d.ts.map +0 -1
  395. package/dist/backend/entities/product-url-key.entity.js.map +0 -1
  396. package/dist/backend/entities/product-url-redirect.entity.d.ts.map +0 -1
  397. package/dist/backend/entities/product-url-redirect.entity.js.map +0 -1
  398. package/dist/backend/entities/product-value-override.entity.d.ts.map +0 -1
  399. package/dist/backend/entities/product-value-override.entity.js.map +0 -1
  400. package/dist/backend/entities/product-variant.entity.d.ts.map +0 -1
  401. package/dist/backend/entities/product-variant.entity.js.map +0 -1
  402. package/dist/backend/entities/product.entity.d.ts.map +0 -1
  403. package/dist/backend/entities/product.entity.js.map +0 -1
  404. package/dist/backend/index.d.ts.map +0 -1
  405. package/dist/backend/index.js.map +0 -1
  406. package/dist/backend/plugin.d.ts.map +0 -1
  407. package/dist/backend/plugin.js.map +0 -1
  408. package/dist/backend/prompt-tools.d.ts.map +0 -1
  409. package/dist/backend/prompt-tools.js.map +0 -1
  410. package/dist/backend/routes.admin.d.ts.map +0 -1
  411. package/dist/backend/routes.admin.js.map +0 -1
  412. package/dist/backend/routes.admin.url-keys.d.ts.map +0 -1
  413. package/dist/backend/routes.admin.url-keys.js.map +0 -1
  414. package/dist/backend/routes.api-key.d.ts.map +0 -1
  415. package/dist/backend/routes.api-key.js.map +0 -1
  416. package/dist/backend/routes.external.d.ts.map +0 -1
  417. package/dist/backend/routes.external.js.map +0 -1
  418. package/dist/backend/routes.public.d.ts.map +0 -1
  419. package/dist/backend/routes.public.js.map +0 -1
  420. package/dist/backend/routes.public.url-keys.d.ts.map +0 -1
  421. package/dist/backend/routes.public.url-keys.js.map +0 -1
  422. package/dist/backend/saved-view-actor.d.ts.map +0 -1
  423. package/dist/backend/saved-view-actor.js.map +0 -1
  424. package/dist/backend/services/asset-references.d.ts.map +0 -1
  425. package/dist/backend/services/asset-references.js.map +0 -1
  426. package/dist/backend/services/attachment-packaging-scopes.d.ts.map +0 -1
  427. package/dist/backend/services/attachment-packaging-scopes.js.map +0 -1
  428. package/dist/backend/services/attachment.service.d.ts.map +0 -1
  429. package/dist/backend/services/attachment.service.js.map +0 -1
  430. package/dist/backend/services/attribute-option-validator.d.ts.map +0 -1
  431. package/dist/backend/services/attribute-option-validator.js.map +0 -1
  432. package/dist/backend/services/attribute-scope-preview.d.ts.map +0 -1
  433. package/dist/backend/services/attribute-scope-preview.js.map +0 -1
  434. package/dist/backend/services/attribute-set-validations.d.ts.map +0 -1
  435. package/dist/backend/services/attribute-set-validations.js.map +0 -1
  436. package/dist/backend/services/attribute-set.service.d.ts.map +0 -1
  437. package/dist/backend/services/attribute-set.service.js.map +0 -1
  438. package/dist/backend/services/attribute-type-mapping.d.ts.map +0 -1
  439. package/dist/backend/services/attribute-type-mapping.js.map +0 -1
  440. package/dist/backend/services/attribute-value-key.service.d.ts.map +0 -1
  441. package/dist/backend/services/attribute-value-key.service.js.map +0 -1
  442. package/dist/backend/services/audit-references.d.ts.map +0 -1
  443. package/dist/backend/services/audit-references.js.map +0 -1
  444. package/dist/backend/services/bulk-operation-queue.d.ts.map +0 -1
  445. package/dist/backend/services/bulk-operation-queue.js.map +0 -1
  446. package/dist/backend/services/bulk-operation.service.d.ts.map +0 -1
  447. package/dist/backend/services/bulk-operation.service.js.map +0 -1
  448. package/dist/backend/services/bundle.service.d.ts.map +0 -1
  449. package/dist/backend/services/bundle.service.js.map +0 -1
  450. package/dist/backend/services/catalog-admin-search.service.d.ts.map +0 -1
  451. package/dist/backend/services/catalog-admin-search.service.js.map +0 -1
  452. package/dist/backend/services/catalog-admin.service.d.ts.map +0 -1
  453. package/dist/backend/services/catalog-admin.service.js.map +0 -1
  454. package/dist/backend/services/catalog-attribute-read.service.d.ts.map +0 -1
  455. package/dist/backend/services/catalog-attribute-read.service.js.map +0 -1
  456. package/dist/backend/services/catalog-bulk-import.service.d.ts.map +0 -1
  457. package/dist/backend/services/catalog-bulk-import.service.js.map +0 -1
  458. package/dist/backend/services/catalog-bulk-update.service.d.ts.map +0 -1
  459. package/dist/backend/services/catalog-bulk-update.service.js.map +0 -1
  460. package/dist/backend/services/catalog-category-read.service.d.ts.map +0 -1
  461. package/dist/backend/services/catalog-category-read.service.js.map +0 -1
  462. package/dist/backend/services/catalog-org-price-decorator.d.ts.map +0 -1
  463. package/dist/backend/services/catalog-org-price-decorator.js.map +0 -1
  464. package/dist/backend/services/catalog-product-filter.service.d.ts.map +0 -1
  465. package/dist/backend/services/catalog-product-filter.service.js.map +0 -1
  466. package/dist/backend/services/catalog-product-read.service.d.ts.map +0 -1
  467. package/dist/backend/services/catalog-product-read.service.js.map +0 -1
  468. package/dist/backend/services/catalog-query.service.d.ts.map +0 -1
  469. package/dist/backend/services/catalog-query.service.js.map +0 -1
  470. package/dist/backend/services/catalog-quick-search.service.d.ts.map +0 -1
  471. package/dist/backend/services/catalog-quick-search.service.js.map +0 -1
  472. package/dist/backend/services/catalog-write-ports.d.ts.map +0 -1
  473. package/dist/backend/services/catalog-write-ports.js.map +0 -1
  474. package/dist/backend/services/category-admin.service.d.ts.map +0 -1
  475. package/dist/backend/services/category-admin.service.js.map +0 -1
  476. package/dist/backend/services/channel-url-facts.d.ts.map +0 -1
  477. package/dist/backend/services/channel-url-facts.js.map +0 -1
  478. package/dist/backend/services/effective-value.sql.d.ts.map +0 -1
  479. package/dist/backend/services/effective-value.sql.js.map +0 -1
  480. package/dist/backend/services/gallery-scopes.d.ts.map +0 -1
  481. package/dist/backend/services/gallery-scopes.js.map +0 -1
  482. package/dist/backend/services/gallery.service.d.ts.map +0 -1
  483. package/dist/backend/services/gallery.service.js.map +0 -1
  484. package/dist/backend/services/grouped.service.d.ts.map +0 -1
  485. package/dist/backend/services/grouped.service.js.map +0 -1
  486. package/dist/backend/services/label-resolver.d.ts.map +0 -1
  487. package/dist/backend/services/label-resolver.js.map +0 -1
  488. package/dist/backend/services/linkable-asset.d.ts.map +0 -1
  489. package/dist/backend/services/linkable-asset.js.map +0 -1
  490. package/dist/backend/services/packaging-unit.service.d.ts.map +0 -1
  491. package/dist/backend/services/packaging-unit.service.js.map +0 -1
  492. package/dist/backend/services/primary-asset-url.d.ts.map +0 -1
  493. package/dist/backend/services/primary-asset-url.js.map +0 -1
  494. package/dist/backend/services/product-availability.service.d.ts.map +0 -1
  495. package/dist/backend/services/product-availability.service.js.map +0 -1
  496. package/dist/backend/services/product-availability.sql.d.ts.map +0 -1
  497. package/dist/backend/services/product-availability.sql.js.map +0 -1
  498. package/dist/backend/services/product-editor-preferences.service.d.ts.map +0 -1
  499. package/dist/backend/services/product-editor-preferences.service.js.map +0 -1
  500. package/dist/backend/services/product-link.service.d.ts.map +0 -1
  501. package/dist/backend/services/product-link.service.js.map +0 -1
  502. package/dist/backend/services/product-list-view-service.d.ts.map +0 -1
  503. package/dist/backend/services/product-list-view-service.js.map +0 -1
  504. package/dist/backend/services/product-overrides.service.d.ts +0 -84
  505. package/dist/backend/services/product-overrides.service.d.ts.map +0 -1
  506. package/dist/backend/services/product-overrides.service.js +0 -211
  507. package/dist/backend/services/product-overrides.service.js.map +0 -1
  508. package/dist/backend/services/product-page-revalidation.d.ts.map +0 -1
  509. package/dist/backend/services/product-page-revalidation.js.map +0 -1
  510. package/dist/backend/services/product-scope-context.service.d.ts +0 -36
  511. package/dist/backend/services/product-scope-context.service.d.ts.map +0 -1
  512. package/dist/backend/services/product-scope-context.service.js +0 -107
  513. package/dist/backend/services/product-scope-context.service.js.map +0 -1
  514. package/dist/backend/services/product-scopes.service.d.ts.map +0 -1
  515. package/dist/backend/services/product-scopes.service.js.map +0 -1
  516. package/dist/backend/services/product-summary-text.d.ts.map +0 -1
  517. package/dist/backend/services/product-summary-text.js.map +0 -1
  518. package/dist/backend/services/product-type-validations.d.ts.map +0 -1
  519. package/dist/backend/services/product-type-validations.js.map +0 -1
  520. package/dist/backend/services/product-value-resolver.service.d.ts.map +0 -1
  521. package/dist/backend/services/product-value-resolver.service.js.map +0 -1
  522. package/dist/backend/services/publication-window-sweep.d.ts.map +0 -1
  523. package/dist/backend/services/publication-window-sweep.js.map +0 -1
  524. package/dist/backend/services/scope-completeness.d.ts.map +0 -1
  525. package/dist/backend/services/scope-completeness.js.map +0 -1
  526. package/dist/backend/services/scope-overview.service.d.ts.map +0 -1
  527. package/dist/backend/services/scope-overview.service.js.map +0 -1
  528. package/dist/backend/services/sql-id-arrays.d.ts.map +0 -1
  529. package/dist/backend/services/sql-id-arrays.js.map +0 -1
  530. package/dist/backend/services/storefront-value-overrides.d.ts.map +0 -1
  531. package/dist/backend/services/storefront-value-overrides.js.map +0 -1
  532. package/dist/backend/services/system-attribute-scopes.d.ts.map +0 -1
  533. package/dist/backend/services/system-attribute-scopes.js.map +0 -1
  534. package/dist/backend/services/url-key-resolution.service.d.ts.map +0 -1
  535. package/dist/backend/services/url-key-resolution.service.js.map +0 -1
  536. package/dist/backend/services/url-key.service.d.ts.map +0 -1
  537. package/dist/backend/services/url-key.service.js.map +0 -1
  538. package/dist/backend/services/viewer-organization.d.ts.map +0 -1
  539. package/dist/backend/services/viewer-organization.js.map +0 -1
  540. package/dist/manifest.d.ts.map +0 -1
  541. package/dist/manifest.js.map +0 -1
  542. package/dist/migrations/20260429T064146_catalog_attribute_sets_init.d.ts.map +0 -1
  543. package/dist/migrations/20260429T064146_catalog_attribute_sets_init.js.map +0 -1
  544. package/dist/migrations/20260429T070004_catalog_product_attribute_extensions.d.ts.map +0 -1
  545. package/dist/migrations/20260429T070004_catalog_product_attribute_extensions.js.map +0 -1
  546. package/dist/migrations/20260429T102322_catalog_product_type_and_virtual_fields.d.ts.map +0 -1
  547. package/dist/migrations/20260429T102322_catalog_product_type_and_virtual_fields.js.map +0 -1
  548. package/dist/migrations/20260429T111839_catalog_gallery_items_and_labels.d.ts.map +0 -1
  549. package/dist/migrations/20260429T111839_catalog_gallery_items_and_labels.js.map +0 -1
  550. package/dist/migrations/20260429T112543_catalog_product_attachments.d.ts.map +0 -1
  551. package/dist/migrations/20260429T112543_catalog_product_attachments.js.map +0 -1
  552. package/dist/migrations/20260429T123726_catalog_product_links.d.ts.map +0 -1
  553. package/dist/migrations/20260429T123726_catalog_product_links.js.map +0 -1
  554. package/dist/migrations/20260429T130803_catalog_grouped_and_bundle.d.ts.map +0 -1
  555. package/dist/migrations/20260429T130803_catalog_grouped_and_bundle.js.map +0 -1
  556. package/dist/migrations/20260501T185835_catalog_product_attribute_is_comparable.d.ts.map +0 -1
  557. package/dist/migrations/20260501T185835_catalog_product_attribute_is_comparable.js.map +0 -1
  558. package/dist/migrations/20260505T060113_catalog_attribute_options_and_flags.d.ts.map +0 -1
  559. package/dist/migrations/20260505T060113_catalog_attribute_options_and_flags.js.map +0 -1
  560. package/dist/migrations/20260515T082629_catalog_attribute_mass_editable.d.ts.map +0 -1
  561. package/dist/migrations/20260515T082629_catalog_attribute_mass_editable.js.map +0 -1
  562. package/dist/migrations/20260526T124736_catalog_product_status_inactive.d.ts.map +0 -1
  563. package/dist/migrations/20260526T124736_catalog_product_status_inactive.js.map +0 -1
  564. package/dist/migrations/20260611T140346_catalog_product_value_overrides_init.d.ts.map +0 -1
  565. package/dist/migrations/20260611T140346_catalog_product_value_overrides_init.js.map +0 -1
  566. package/dist/migrations/20260611T140400_catalog_attribute_quick_searchable.d.ts.map +0 -1
  567. package/dist/migrations/20260611T140400_catalog_attribute_quick_searchable.js.map +0 -1
  568. package/dist/migrations/20260611T140407_catalog_bulk_operations.d.ts.map +0 -1
  569. package/dist/migrations/20260611T140407_catalog_bulk_operations.js.map +0 -1
  570. package/dist/migrations/20260611T140408_catalog_bulk_operation_logs.d.ts.map +0 -1
  571. package/dist/migrations/20260611T140408_catalog_bulk_operation_logs.js.map +0 -1
  572. package/dist/migrations/20260611T140412_catalog_product_packaging_units.d.ts.map +0 -1
  573. package/dist/migrations/20260611T140412_catalog_product_packaging_units.js.map +0 -1
  574. package/dist/migrations/20260718T060659_catalog_bulk_operation_revert_state.d.ts.map +0 -1
  575. package/dist/migrations/20260718T060659_catalog_bulk_operation_revert_state.js.map +0 -1
  576. package/dist/migrations/20260718T200343_catalog_category_custom_field_values.d.ts.map +0 -1
  577. package/dist/migrations/20260718T200343_catalog_category_custom_field_values.js.map +0 -1
  578. package/dist/migrations/20260723T230401_catalog_attributes_on_custom_fields.d.ts.map +0 -1
  579. package/dist/migrations/20260723T230401_catalog_attributes_on_custom_fields.js.map +0 -1
  580. package/dist/migrations/20260804T152604_catalog_widen_product_sku.d.ts.map +0 -1
  581. package/dist/migrations/20260804T152604_catalog_widen_product_sku.js.map +0 -1
  582. package/dist/migrations/20260804T160244_catalog_category_activation.d.ts.map +0 -1
  583. package/dist/migrations/20260804T160244_catalog_category_activation.js.map +0 -1
  584. package/dist/migrations/20260912T094557_catalog_sales_channel_products.d.ts.map +0 -1
  585. package/dist/migrations/20260912T094557_catalog_sales_channel_products.js.map +0 -1
  586. package/dist/migrations/20260912T094623_catalog_sales_channel_categories.d.ts.map +0 -1
  587. package/dist/migrations/20260912T094623_catalog_sales_channel_categories.js.map +0 -1
  588. package/dist/migrations/20260925T125527_catalog_inventory_columns.d.ts.map +0 -1
  589. package/dist/migrations/20260925T125527_catalog_inventory_columns.js.map +0 -1
  590. package/dist/migrations/20261008T080839_catalog_product_attribute_is_price_rule.d.ts.map +0 -1
  591. package/dist/migrations/20261008T080839_catalog_product_attribute_is_price_rule.js.map +0 -1
  592. package/dist/migrations/20261008T092714_catalog_category_content.d.ts.map +0 -1
  593. package/dist/migrations/20261008T092714_catalog_category_content.js.map +0 -1
  594. package/dist/migrations/20261014T170531_catalog_product_list_saved_views.d.ts.map +0 -1
  595. package/dist/migrations/20261014T170531_catalog_product_list_saved_views.js.map +0 -1
  596. package/dist/migrations/20261016T082008_catalog_order_rules.d.ts.map +0 -1
  597. package/dist/migrations/20261016T082008_catalog_order_rules.js.map +0 -1
  598. package/dist/migrations/20261022T035133_catalog_product_scopes.d.ts.map +0 -1
  599. package/dist/migrations/20261022T035133_catalog_product_scopes.js.map +0 -1
  600. package/dist/migrations/20261022T054223_catalog_product_url_keys.d.ts.map +0 -1
  601. package/dist/migrations/20261022T054223_catalog_product_url_keys.js.map +0 -1
  602. package/dist/migrations/20261022T111811_catalog_price_fields_removed.d.ts.map +0 -1
  603. package/dist/migrations/20261022T111811_catalog_price_fields_removed.js.map +0 -1
  604. package/dist/migrations/20261022T182523_catalog_admin_name_keys.d.ts.map +0 -1
  605. package/dist/migrations/20261022T182523_catalog_admin_name_keys.js.map +0 -1
  606. package/dist/migrations/20261025T222634_catalog_product_status_drop_draft.d.ts.map +0 -1
  607. package/dist/migrations/20261025T222634_catalog_product_status_drop_draft.js.map +0 -1
  608. package/dist/migrations/20261026T033453_catalog_product_media_scopes.d.ts.map +0 -1
  609. package/dist/migrations/20261026T033453_catalog_product_media_scopes.js.map +0 -1
  610. package/dist/migrations/20261026T084533_catalog_attachment_packaging_translations.d.ts.map +0 -1
  611. package/dist/migrations/20261026T084533_catalog_attachment_packaging_translations.js.map +0 -1
  612. package/dist/migrations/index.d.ts.map +0 -1
  613. package/dist/migrations/index.js.map +0 -1
  614. package/dist/ports/index.d.ts.map +0 -1
  615. package/dist/ports/index.js.map +0 -1
@@ -1,515 +1,995 @@
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';
5
- 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';
4
+ import { Archive, ArchiveRestore, ChevronDown, ChevronLeft, Copy, Lock, RotateCw, Trash2 } from 'lucide-react';
5
+ import { ERROR_CODES, } from '@endora-commerce/contracts';
6
+ import { ApiError, apiClient, useAuth, useUnsavedChangesPrompt, cn, INERT_SAVE_SESSION, SaveSessionProvider, useSaveSession, } from '@endora-commerce/admin-kit/lib';
7
+ import { Alert, AlertDescription, Button, Card, CardContent, CardHeader, CardTitle, DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger, Input, Label, Select, Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from '@endora-commerce/admin-kit/ui';
8
+ import { ModalDialog, ProductPicker, SaveSessionSummary, ImmediateBadge } 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 { ProductEditorSaveAction } from '../components/ProductEditorSaveAction.js';
21
+ import { DetailsTab } from '../components/editor/DetailsTab.js';
22
+ import { EditorField, ProductEditorContextProvider, fieldDomId } from '../components/editor/editor-context.js';
23
+ import { SectionHeading } from '../components/editor/SectionHeading.js';
24
+ import { TextControl } from '../components/editor/scoped-controls.js';
25
+ import { useConfirmRemoval } from '../components/editor/confirm-removal.js';
26
+ import { ProductCreateForm } from './ProductCreateForm.js';
27
+ import { describeIncompletePair } from '../lib/product-scopes-api.js';
28
+ import { takeoverDetails, urlKeyErrorMessage, describeKeyInLanguage } from '../lib/product-url-keys-api.js';
29
+ import { initialEditorState, fieldViewAt, scopeToRequest, scopedEditorReducer, stagedToChanges, } from '../lib/scoped-editor-store.js';
30
+ import { getEditorPreference, getScopedValues, putEditorPreference, saveScopedValues } from '../lib/scoped-values-api.js';
31
+ import { channelName, languageName, parentScope, sameScope, scopeFromSearch, scopeInWords, scopeKey, scopeShortWords, searchWithScope, widerScope, } from '../lib/editor-scope.js';
32
32
  /**
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.
33
+ * The product editor (feature 174, US5–US7; `contracts/editor-ui.md`).
34
+ *
35
+ * One scope switcher sets the scope of the whole editor; the scope lives in the URL
36
+ * (`?scope=global|channel|cl&channel=…&language=…&tab=…&field=…`). The editor reads the scope in
37
+ * one request (`GET …/scoped-values`), stages every change of that scope in one store and writes
38
+ * them with one Save (`PUT …/scoped-values`) — the product row's global-only fields at Global
39
+ * included. Structural operations (variants, images, attachments, packaging units, links, prices,
40
+ * membership, stock) run at once as their own audited Commands, carry an "Applies immediately"
41
+ * badge, and neither stage nor clear the staged changes.
42
+ *
43
+ * Switching scope (the switcher, an "Edit at …" jump, browser Back) with staged changes asks
44
+ * Save / Discard / Stay first.
36
45
  */
37
- const LINKABLE_TABS = new Set([
46
+ const TAB_IDS = [
38
47
  'details',
39
48
  'attributes',
40
49
  'pricing',
50
+ 'variants',
51
+ 'composite',
41
52
  'media',
42
53
  'inventory',
43
54
  'attachments',
44
55
  'links',
56
+ 'channels',
45
57
  'scopes',
46
58
  'seo',
47
- ]);
59
+ ];
60
+ /** Tabs whose content is the same at every scope (§6): outside Global they show a notice. */
61
+ const GLOBAL_ONLY_TABS = new Set(['pricing', 'variants', 'composite', 'links', 'channels']);
62
+ const GLOBAL = { level: 'global' };
63
+ const PRODUCT_PATH = (id) => `/api/v1/admin/catalog/products/${encodeURIComponent(id)}`;
64
+ export function ProductEditor() {
65
+ const params = useParams();
66
+ if (params.id === 'new')
67
+ return _jsx(ProductCreateForm, {});
68
+ if (!params.id)
69
+ return null;
70
+ return _jsx(ProductEditorSession, { productId: params.id }, params.id);
71
+ }
48
72
  /**
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).
73
+ * Feature 180 (`specs/180-one-save-zone-editors/contracts/product-editor-save-ui.md` §1) — the
74
+ * editor's one Save covers its zone panels through a save session. The session belongs to the
75
+ * scope it was made at (OQ-4 = A): its key is the scope the editor last opened, so a scope switch
76
+ * — which the guard lets through only once every part is saved or discarded — starts an empty
77
+ * session.
52
78
  */
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
- });
79
+ function ProductEditorSession({ productId }) {
80
+ const [openedScope, setOpenedScope] = useState('');
81
+ return (_jsx(SaveSessionProvider, { resetKey: `${productId}|${openedScope}`, hostModule: "catalog", children: _jsx(ScopedProductEditor, { productId: productId, onScopeOpened: setOpenedScope }) }));
62
82
  }
63
- export function ProductEditor() {
83
+ /** Zone → tab, for the summary's "Show" (`product-editor-save-ui.md` §2). */
84
+ function tabOfZone(zone) {
85
+ if (zone === 'product.editor.pricing.before' || zone === 'product.editor.pricing.after')
86
+ return 'pricing';
87
+ if (zone === 'product.editor.channels')
88
+ return 'channels';
89
+ return 'details';
90
+ }
91
+ /** A field whose `empty` the server refuses outside `view.required` (data-model §9, R21). */
92
+ function refusesEmpty(path, state) {
93
+ if (path.startsWith('product:'))
94
+ return true;
95
+ if (path === 'status' || path === 'returnable' || path === 'audience')
96
+ return true;
97
+ if (/^(gallery|attachment):[^:]+:hidden$/.test(path))
98
+ return true;
99
+ if (state.scope.level === 'global' && (/^attachment:[^:]+:name$/.test(path) || /^packagingUnit:[^:]+:name$/.test(path)))
100
+ return true;
101
+ if (path.startsWith('attribute:') && state.data) {
102
+ const attr = state.data.attributes.find((a) => `attribute:${a.key}` === path);
103
+ if (attr && ['enum', 'select', 'boolean'].includes(attr.valueType))
104
+ return true;
105
+ }
106
+ return false;
107
+ }
108
+ function errorOf(err) {
109
+ if (!(err instanceof ApiError))
110
+ return null;
111
+ const e = err.envelope.error;
112
+ return { status: err.status, code: e.code, message: e.message, ...(e.details ? { details: e.details } : {}) };
113
+ }
114
+ /** The tab a field lives on; a scope-map link without a field opens Details. */
115
+ /**
116
+ * A translated lead, then the server's sentence as detail (final design review): the envelope's
117
+ * message is in the request language only when the backend has that code's translation, so it is
118
+ * never the whole of what the operator reads.
119
+ */
120
+ function withServerDetail(lead, err) {
121
+ const detail = errorOf(err)?.message;
122
+ return detail && detail !== lead ? `${lead} ${detail}` : lead;
123
+ }
124
+ function tabOfField(field) {
125
+ return field?.startsWith('attribute:') ? 'attributes' : 'details';
126
+ }
127
+ function familyOfPath(path) {
128
+ if (path.startsWith('gallery'))
129
+ return 'gallery';
130
+ if (path.startsWith('attachment:'))
131
+ return 'attachments';
132
+ if (path.startsWith('packagingUnit:'))
133
+ return 'packagingUnits';
134
+ return null;
135
+ }
136
+ function ScopedProductEditor({ productId, onScopeOpened, }) {
64
137
  const t = useTranslation('catalog');
65
- const params = useParams();
138
+ // The admin's language names languages (`Intl.DisplayNames`); a screen mounted without the
139
+ // shell's provider (a test) falls back to English.
140
+ const adminLanguage = useContext(AppLanguageContext)?.language ?? 'en';
66
141
  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.
142
+ const [searchParams, setSearchParams] = useSearchParams();
77
143
  const { hasPermission } = useAuth();
78
144
  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.
145
+ const readOnly = !canWrite;
146
+ const session = useSaveSession();
147
+ const sessionRef = useRef(session);
148
+ sessionRef.current = session;
149
+ // The probe only counts contributions; it renders none, so it carries the inert handle.
150
+ const channelContributions = useAdminZone('product.editor.channels', { productId, saveSession: INERT_SAVE_SESSION });
151
+ const seoContributions = useAdminZone('product.editor.seo', {
152
+ productId,
153
+ scope: GLOBAL,
154
+ scopeLabel: '',
155
+ parentScopeLabel: null,
156
+ view: null,
157
+ staged: new Map(),
158
+ onStage: () => undefined,
159
+ readOnly: true,
160
+ errors: {},
161
+ version: null,
162
+ });
163
+ const urlScope = scopeFromSearch(searchParams);
164
+ const urlKey = urlScope ? scopeKey(urlScope) : '';
165
+ const [state, dispatch] = useReducer(scopedEditorReducer, urlScope ?? GLOBAL, initialEditorState);
166
+ const stateRef = useRef(state);
167
+ stateRef.current = state;
168
+ /** The scope the last load was started for; the URL effect compares against it. */
169
+ const loadedKeyRef = useRef(null);
170
+ const requestRef = useRef(0);
171
+ /** Set when the editor itself moves the URL after the guard has been passed. */
172
+ const skipGuardRef = useRef(false);
173
+ const pendingNoteRef = useRef(null);
174
+ const prefTimerRef = useRef(null);
175
+ /** The last valid-scope list, kept while a scope loads so the switcher stays usable. */
176
+ const validRef = useRef(null);
177
+ const [announcement, setAnnouncement] = useState('');
178
+ const [loadError, setLoadError] = useState(null);
179
+ const [formError, setFormError] = useState(null);
83
180
  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);
181
+ const [info, setInfo] = useState(null);
182
+ const [guard, setGuard] = useState(null);
183
+ const [saving, setSaving] = useState(false);
184
+ const [takeovers, setTakeovers] = useState(null);
185
+ const [archivedOverride, setArchivedOverride] = useState(undefined);
87
186
  const [archiveDialog, setArchiveDialog] = useState(null);
88
187
  const [archiving, setArchiving] = useState(false);
89
188
  const [archiveError, setArchiveError] = useState(null);
189
+ const [duplicating, setDuplicating] = useState(false);
190
+ const [wholeProductDialog, setWholeProductDialog] = useState(null);
191
+ const [wholeProductError, setWholeProductError] = useState(null);
192
+ const [deleting, setDeleting] = useState(false);
90
193
  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
194
+ const [categoriesLoading, setCategoriesLoading] = useState(true);
107
195
  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);
196
+ if (state.data)
197
+ validRef.current = state.data.validScopes;
198
+ const valid = state.data?.validScopes ?? validRef.current ?? { channels: [] };
199
+ const words = (scope, v = valid) => scopeInWords(scope, v, t, adminLanguage);
200
+ const scopeLabel = scopeShortWords(state.scope, valid, t, adminLanguage);
201
+ const parentLabel = scopeShortWords(parentScope(state.scope), valid, t, adminLanguage);
202
+ /** `key.one|few|many|other` by the admin language's plural rules (PL needs few / many). */
203
+ const plural = (key, count, params = {}) => t(`${key}.${new Intl.PluralRules(adminLanguage).select(count)}`, { count: String(count), ...params });
204
+ // The live region is cleared first, so the same sentence twice is announced twice (WCAG 4.1.3).
205
+ const announceTimerRef = useRef(null);
206
+ const announce = useCallback((text) => {
207
+ setAnnouncement('');
208
+ if (announceTimerRef.current)
209
+ clearTimeout(announceTimerRef.current);
210
+ announceTimerRef.current = setTimeout(() => setAnnouncement(text), 50);
211
+ }, []);
212
+ useEffect(() => () => {
213
+ if (announceTimerRef.current)
214
+ clearTimeout(announceTimerRef.current);
215
+ }, []);
216
+ /** The scope the last successful read opened; a different one is announced once its data is in. */
217
+ const announcedScopeRef = useRef(null);
218
+ // The reference lists the Details tab picks from (global, read once). A failed read is an
219
+ // error with a retry, never an empty list (final design review): "No categories" would be a lie.
220
+ const [referenceError, setReferenceError] = useState(false);
221
+ const referenceRequest = useRef(0);
222
+ const loadReference = useCallback(() => {
223
+ const request = ++referenceRequest.current;
224
+ setCategoriesLoading(true);
225
+ setReferenceError(false);
226
+ void Promise.allSettled([
227
+ apiClient.get('/api/v1/admin/catalog/categories'),
228
+ apiClient.get('/api/v1/admin/catalog/attribute-sets'),
229
+ ]).then(([cats, sets]) => {
230
+ if (request !== referenceRequest.current)
231
+ return;
232
+ if (cats.status === 'fulfilled')
233
+ setCategories(cats.value.data ?? []);
234
+ if (sets.status === 'fulfilled')
235
+ setAttributeSets(sets.value.data ?? []);
236
+ setReferenceError(cats.status === 'rejected' || sets.status === 'rejected');
237
+ setCategoriesLoading(false);
238
+ });
239
+ }, []);
146
240
  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);
241
+ loadReference();
242
+ return () => {
243
+ referenceRequest.current += 1;
244
+ };
245
+ }, [loadReference]);
246
+ // --- Loading a scope --------------------------------------------------------------------
247
+ const load = useCallback(async (requested, options = {}) => {
248
+ const request = ++requestRef.current;
249
+ loadedKeyRef.current = scopeKey(requested);
250
+ dispatch({ type: 'switching', scope: requested });
251
+ setLoadError(null);
252
+ setFormError(null);
253
+ setGateWarning(null);
254
+ let target = requested;
255
+ let reason = null;
256
+ for (;;) {
257
+ try {
258
+ const res = await getScopedValues(productId, target);
259
+ if (request !== requestRef.current)
260
+ return;
261
+ dispatch({ type: 'loaded', data: res.data });
262
+ const opened = res.data.scope;
263
+ onScopeOpened(scopeKey(opened));
264
+ if (!sameScope(opened, requested)) {
265
+ loadedKeyRef.current = scopeKey(opened);
266
+ setSearchParams((prev) => searchWithScope(prev, opened), { replace: true });
216
267
  }
217
- catch {
218
- // Best effort — the rest of the editor stays usable.
268
+ const openedWords = scopeInWords(opened, res.data.validScopes, t, adminLanguage);
269
+ const note = reason ? t('productEditor.scope.openedAt', { scope: openedWords, reason }) : (options.note ?? null);
270
+ // After the data is in (not when the switch starts): the scope, Global included.
271
+ const previous = announcedScopeRef.current;
272
+ announcedScopeRef.current = scopeKey(opened);
273
+ const switched = previous !== null && previous !== scopeKey(opened);
274
+ const where = switched
275
+ ? opened.level === 'global'
276
+ ? t('productEditor.scope.loadedAt', { scope: openedWords })
277
+ : t('productEditor.scope.banner', { scope: openedWords })
278
+ : null;
279
+ const spoken = [note, where].filter(Boolean).join(' ');
280
+ if (spoken)
281
+ announce(spoken);
282
+ if (prefTimerRef.current)
283
+ clearTimeout(prefTimerRef.current);
284
+ prefTimerRef.current = setTimeout(() => void putEditorPreference(productId, opened), 500);
285
+ if (options.field) {
286
+ const field = options.field;
287
+ setTimeout(() => document.getElementById(fieldDomId(field))?.focus(), 0);
219
288
  }
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
- });
289
+ return;
290
+ }
291
+ catch (err) {
292
+ if (request !== requestRef.current)
293
+ return;
294
+ const e = errorOf(err);
295
+ const wider = widerScope(target);
296
+ if (e?.code === ERROR_CODES.SCOPE_INVALID && wider) {
297
+ reason ??=
298
+ e.details?.['reason'] === 'language_not_offered'
299
+ ? t('productEditor.scope.reason.languageNotOffered')
300
+ : t('productEditor.scope.reason.notMember');
301
+ target = wider;
302
+ continue;
303
+ }
304
+ setLoadError(e?.message ?? t('productEditor.error.load'));
305
+ return;
238
306
  }
239
307
  }
240
- catch (err) {
241
- setError(err instanceof ApiError ? err.envelope.error.message : tRef.current('productEditor.error.load'));
242
- }
243
- finally {
244
- setLoading(false);
308
+ }, [productId, setSearchParams, t, adminLanguage, announce, onScopeOpened]);
309
+ /** The host's staged cells plus every participant's changes (FR-010, FR-030). */
310
+ const hasUnsaved = useCallback(() => stateRef.current.staged.size + sessionRef.current.dirtyCount > 0, []);
311
+ // No scope in the URL: the preference seeds it (Global when there is none), replacing the entry.
312
+ useEffect(() => {
313
+ if (urlScope)
314
+ return undefined;
315
+ let cancelled = false;
316
+ void getEditorPreference(productId)
317
+ .catch(() => null)
318
+ .then((pref) => {
319
+ if (!cancelled)
320
+ setSearchParams((prev) => searchWithScope(prev, pref ?? GLOBAL), { replace: true });
321
+ });
322
+ return () => {
323
+ cancelled = true;
324
+ };
325
+ // eslint-disable-next-line react-hooks/exhaustive-deps
326
+ }, [urlKey, productId]);
327
+ // The URL is the truth: a scope it names that is not the loaded one is loaded — through the
328
+ // switch guard when there are staged changes (browser Back / Forward).
329
+ useEffect(() => {
330
+ if (!urlScope)
331
+ return;
332
+ if (scopeKey(urlScope) === loadedKeyRef.current)
333
+ return;
334
+ if (!skipGuardRef.current && loadedKeyRef.current !== null && hasUnsaved()) {
335
+ setGuard({ kind: 'url', target: urlScope });
336
+ return;
245
337
  }
246
- }, [id, isNew]);
338
+ skipGuardRef.current = false;
339
+ const note = pendingNoteRef.current;
340
+ pendingNoteRef.current = null;
341
+ void load(urlScope, { note, field: searchParams.get('field') });
342
+ // eslint-disable-next-line react-hooks/exhaustive-deps
343
+ }, [urlKey]);
344
+ useEffect(() => () => {
345
+ if (prefTimerRef.current)
346
+ clearTimeout(prefTimerRef.current);
347
+ }, []);
348
+ // A staged change of a subject an immediate action removed is dropped and said (§3).
247
349
  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'));
350
+ if (state.dropped.length === 0)
265
351
  return;
352
+ const family = familyOfPath(state.dropped[0]);
353
+ announce(t(family === 'attachments'
354
+ ? 'productEditor.immediate.droppedAttachment'
355
+ : family === 'packagingUnits'
356
+ ? 'productEditor.immediate.droppedPackagingUnit'
357
+ : 'productEditor.immediate.droppedImage'));
358
+ }, [state.dropped, t, announce]);
359
+ const totalUnsaved = state.staged.size + session.dirtyCount;
360
+ useUnsavedChangesPrompt(totalUnsaved > 0);
361
+ // "Saved N changes" belongs to the last save: a new staged edit clears it, and the summary of
362
+ // the last save with it (FR-016; a participant's edit clears the summary itself).
363
+ useEffect(() => {
364
+ if (state.staged.size > 0) {
365
+ setInfo(null);
366
+ sessionRef.current.clearOutcome();
266
367
  }
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;
368
+ }, [state.staged]);
369
+ useEffect(() => {
370
+ if (session.dirtyCount > 0)
371
+ setInfo(null);
372
+ }, [session.dirtyCount]);
373
+ const go = useCallback((next, note, field, tab) => {
374
+ pendingNoteRef.current = note ?? null;
375
+ skipGuardRef.current = true;
376
+ setSearchParams((prev) => {
377
+ const sp = searchWithScope(prev, next);
378
+ sp.delete('field');
379
+ if (field)
380
+ sp.set('field', field);
381
+ if (tab)
382
+ sp.set('tab', tab);
383
+ return sp;
384
+ });
385
+ }, [setSearchParams]);
386
+ const requestScope = useCallback((next, note, field, tab) => {
387
+ if (sameScope(next, stateRef.current.scope)) {
388
+ if (tab) {
389
+ setSearchParams((prev) => {
390
+ const sp = new URLSearchParams(prev);
391
+ sp.set('tab', tab);
392
+ sp.delete('field');
393
+ return sp;
394
+ });
279
395
  }
280
- windowPatch = { publishFrom: check.from, publishUntil: check.until };
396
+ if (field)
397
+ setTimeout(() => document.getElementById(fieldDomId(field))?.focus(), 0);
398
+ return;
399
+ }
400
+ if (hasUnsaved()) {
401
+ setGuard({ kind: 'switch', target: next, ...(note ? { note } : {}), ...(field ? { field } : {}), ...(tab ? { tab } : {}) });
402
+ return;
281
403
  }
282
- setWindowError(null);
404
+ go(next, note, field, tab);
405
+ }, [go, setSearchParams, hasUnsaved]);
406
+ const refreshFamily = useCallback(async (family) => {
407
+ const scope = stateRef.current.scope;
283
408
  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}`);
299
- }
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
- }));
409
+ const res = await getScopedValues(productId, scope);
410
+ if (sameScope(stateRef.current.scope, scope))
411
+ dispatch({ type: 'refreshFamily', family, data: res.data });
412
+ }
413
+ catch {
414
+ // The structural change is done; the list refreshes on the next read.
415
+ }
416
+ }, [productId]);
417
+ // The copy (§8) bumped the version: the next Save sends it; staged cells stay (R7).
418
+ const afterCopy = useCallback((version, fieldLabel, count) => {
419
+ dispatch({ type: 'version', version });
420
+ announce(plural('productEditor.copy.done', count, { field: fieldLabel }));
421
+ },
422
+ // `plural` reads `t` and the admin language only.
423
+ // eslint-disable-next-line react-hooks/exhaustive-deps
424
+ [announce, t, adminLanguage]);
425
+ // --- Save --------------------------------------------------------------------------------
426
+ /**
427
+ * Feature 180 — the editor's own write, as the first and blocking part of the one Save
428
+ * (`product-editor-save-ui.md` §1, OQ-2 = A): the required-empty checks are its `validate`, the
429
+ * `PUT …/scoped-values` its `save`, and the error handling is 174's, unchanged. `null` when no
430
+ * scoped change is staged or the operator may not write the product (OQ-6 = A).
431
+ */
432
+ const hostPart = (s, confirmTakeover) => {
433
+ if (!s.data || s.version === null || s.staged.size === 0 || readOnly)
434
+ return null;
435
+ const data = s.data;
436
+ const version = s.version;
437
+ return {
438
+ id: 'host',
439
+ label: t('productEditor.save.hostPartLabel'),
440
+ blocking: true,
441
+ count: s.staged.size,
442
+ validate: async () => {
443
+ const parent = scopeShortWords(parentScope(s.scope), data.validScopes, t, adminLanguage);
444
+ const errors = {};
445
+ for (const [path, op] of s.staged) {
446
+ if (op.op !== 'empty')
447
+ continue;
448
+ if (fieldViewAt(data, path)?.required || refusesEmpty(path, s)) {
449
+ errors[path] =
450
+ s.scope.level === 'global'
451
+ ? t('productEditor.save.error.requiredEmpty')
452
+ : t('productEditor.save.error.requiredEmptyScoped', { scope: parent });
453
+ }
330
454
  }
331
- else {
332
- setInfo(t('productEditor.saved'));
455
+ if (Object.keys(errors).length > 0) {
456
+ dispatch({ type: 'errors', errors });
457
+ setFormError({ kind: 'validation', count: Object.keys(errors).length });
458
+ const first = Object.keys(errors)[0];
459
+ setTimeout(() => document.getElementById(fieldDomId(first))?.focus(), 0);
333
460
  }
334
- await refresh();
461
+ return { fields: errors };
462
+ },
463
+ save: async () => {
464
+ try {
465
+ const changes = stagedToChanges(s.staged);
466
+ const res = await saveScopedValues(productId, {
467
+ scope: scopeToRequest(s.scope),
468
+ version,
469
+ changes: confirmTakeover ? { ...changes, confirmTakeover } : changes,
470
+ });
471
+ dispatch({ type: 'loaded', data: res.data });
472
+ setTakeovers(null);
473
+ const completeness = (res.warnings ?? []).filter((w) => w.kind === 'completeness');
474
+ if (completeness.length > 0) {
475
+ gateWarnedRef.current = true;
476
+ const name = (id) => channelName(res.data.validScopes, id);
477
+ setGateWarning(t('productEditor.scopeControls.warning.incomplete', {
478
+ details: completeness.map((w) => describeIncompletePair(w, name, t)).join('; '),
479
+ }));
480
+ }
481
+ }
482
+ catch (err) {
483
+ handleSaveError(err, s);
484
+ throw err;
485
+ }
486
+ },
487
+ };
488
+ };
489
+ /** Set by the host part when the write answered a completeness warning (no success sentence then). */
490
+ const gateWarnedRef = useRef(false);
491
+ /**
492
+ * The one Save (FR-010…FR-016): the host part first, then every participant in zone order,
493
+ * through the session. True when every part was saved.
494
+ */
495
+ const save = useCallback(async (confirmTakeover) => {
496
+ const s = stateRef.current;
497
+ const current = sessionRef.current;
498
+ if (!s.data)
499
+ return false;
500
+ const host = hostPart(s, confirmTakeover);
501
+ if (host === null && current.dirtyCount === 0)
502
+ return false;
503
+ const total = (host?.count ?? 0) + current.dirtyCount;
504
+ gateWarnedRef.current = false;
505
+ setSaving(true);
506
+ setFormError(null);
507
+ setGateWarning(null);
508
+ setInfo(null);
509
+ try {
510
+ const outcome = await current.run(host);
511
+ if (outcome.result === 'saved') {
512
+ if (!gateWarnedRef.current)
513
+ setInfo(plural('productEditor.save.saved', total, { scope: scopeInWords(s.scope, s.data.validScopes, t, adminLanguage) }));
514
+ return true;
335
515
  }
516
+ return false;
336
517
  }
337
- 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'));
518
+ finally {
519
+ setSaving(false);
520
+ }
521
+ },
522
+ // `hostPart` and `plural` read `t`, the admin language, `productId` and `readOnly` only.
523
+ // eslint-disable-next-line react-hooks/exhaustive-deps
524
+ [productId, readOnly, t, adminLanguage]);
525
+ function handleSaveError(err, s) {
526
+ const e = errorOf(err);
527
+ if (!e) {
528
+ setFormError({ kind: 'message', text: t('productEditor.error.save') });
529
+ return;
530
+ }
531
+ const takeover = takeoverDetails(err);
532
+ if (takeover) {
533
+ setTakeovers(takeover.takeovers);
534
+ return;
535
+ }
536
+ if (e.code === ERROR_CODES.VERSION_CONFLICT) {
537
+ setFormError({ kind: 'conflict' });
538
+ return;
539
+ }
540
+ if (e.code === 'MODULE_DISABLED') {
541
+ setFormError({ kind: 'seo' });
542
+ return;
543
+ }
544
+ if (e.code === ERROR_CODES.SKU_ALREADY_EXISTS) {
545
+ dispatch({ type: 'errors', errors: { 'product:sku': t('errors.SKU_ALREADY_EXISTS') } });
546
+ setFormError({ kind: 'validation', count: 1 });
547
+ setTimeout(() => document.getElementById(fieldDomId('product:sku'))?.focus(), 0);
548
+ return;
549
+ }
550
+ if (e.code === ERROR_CODES.URL_KEY_TAKEN) {
551
+ dispatch({ type: 'errors', errors: { urlKey: urlKeyErrorMessage(err, t) ?? t('errors.URL_KEY_TAKEN') } });
552
+ setFormError({ kind: 'validation', count: 1 });
553
+ setTimeout(() => document.getElementById(fieldDomId('urlKey'))?.focus(), 0);
554
+ return;
555
+ }
556
+ if (e.code === ERROR_CODES.SCOPE_INCOMPLETE && Array.isArray(e.details?.['pairs'])) {
557
+ const pairs = e.details['pairs'];
558
+ const name = (id) => channelName(s.data?.validScopes ?? { channels: [] }, id);
559
+ setFormError({
560
+ kind: 'message',
561
+ text: t('productEditor.statusGate.refused', { details: pairs.map((p) => describeIncompletePair(p, name, t)).join('; ') }),
562
+ });
563
+ return;
564
+ }
565
+ const fields = e.details?.['fields'];
566
+ if (Array.isArray(fields) && fields.length > 0) {
567
+ const errors = {};
568
+ const gone = [];
569
+ let download = false;
570
+ for (const entry of fields) {
571
+ // The Global-only family answers `product.<key>`; the editor's path is `product:<key>`.
572
+ const raw = typeof entry === 'string' ? `product:${entry}` : entry.field;
573
+ const field = raw.startsWith('product.') ? `product:${raw.slice('product.'.length)}` : raw;
574
+ const reason = typeof entry === 'string'
575
+ ? 'global_only'
576
+ : (entry.reason ?? (e.code === ERROR_CODES.FIELD_NOT_AT_SCOPE ? 'not_at_scope' : 'invalid'));
577
+ if (field === 'product:downloadAssetId' || field === 'product:downloadUrl')
578
+ download = true;
579
+ else if (field === 'product:attributeSetId' || field === 'product:categoryIds') {
580
+ // A Global-only reference that names nothing: the field's own words, the change kept.
581
+ errors[field] = reason === 'subject_not_found' ? t(`productEditor.save.reason.${field.replace(':', '.')}`) : t(`productEditor.save.reason.${reason}`);
582
+ }
583
+ else if (reason === 'subject_not_found')
584
+ gone.push(field);
585
+ else
586
+ errors[field] = t(`productEditor.save.reason.${reason}`);
587
+ }
588
+ if (gone.length > 0)
589
+ dispatch({ type: 'dropPaths', paths: gone });
590
+ if (download && Object.keys(errors).length === 0) {
591
+ // The download rules have no field in the editor (virtual products, feature 002).
592
+ setFormError({ kind: 'message', text: t('productEditor.save.error.download') });
342
593
  return;
343
594
  }
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)
595
+ if (Object.keys(errors).length > 0) {
596
+ dispatch({ type: 'errors', errors });
597
+ setFormError({ kind: 'validation', count: Object.keys(errors).length });
598
+ const first = Object.keys(errors)[0];
599
+ setTimeout(() => document.getElementById(fieldDomId(first))?.focus(), 0);
600
+ }
601
+ else {
602
+ setFormError({ kind: 'message', text: t('productEditor.save.error.subjectGone') });
603
+ }
362
604
  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
605
  }
376
- catch {
377
- // Non-fatal — the backend tolerates round-tripped keys, so leaving
378
- // the values untouched on a fetch failure still saves correctly.
606
+ setFormError({ kind: 'message', text: e.message });
607
+ }
608
+ const reloadDiscarding = () => {
609
+ dispatch({ type: 'discard' });
610
+ // The reload discards every change on the page, the panels' too (spec § Edge cases).
611
+ sessionRef.current.discardAll();
612
+ setFormError(null);
613
+ // The Reload button goes with the alert: focus the panel the fresh values are in.
614
+ void load(stateRef.current.scope, { note: t('productEditor.save.reloaded') }).then(() => document.getElementById('product-tabpanel')?.focus());
615
+ };
616
+ // The copy dialog's conflict reloads through the same path as Save's (a stable handle for the context).
617
+ const reloadDiscardingRef = useRef(reloadDiscarding);
618
+ reloadDiscardingRef.current = reloadDiscarding;
619
+ const dropSeoChanges = () => {
620
+ dispatch({ type: 'dropPaths', paths: [...stateRef.current.staged.keys()].filter((p) => p.startsWith('seo:')) });
621
+ setFormError(null);
622
+ announce(t('productEditor.save.seoDropped'));
623
+ };
624
+ // --- Guard -------------------------------------------------------------------------------
625
+ const proceed = (g) => {
626
+ setGuard(null);
627
+ if (g.kind === 'leave') {
628
+ navigate('/catalog/products');
629
+ return;
379
630
  }
380
- }, []);
381
- const handleDeleteProduct = useCallback(async () => {
382
- if (!id)
631
+ if (g.kind === 'url') {
632
+ skipGuardRef.current = false;
633
+ void load(g.target, { field: searchParams.get('field') });
383
634
  return;
384
- if (!confirm(t('productEditor.deleteConfirm')))
635
+ }
636
+ go(g.target, g.note, g.field, g.tab);
637
+ };
638
+ const stay = (g) => {
639
+ setGuard(null);
640
+ // Back / Forward moved the URL: put the current scope back (§11, Stay re-pushes the URL).
641
+ if (g.kind === 'url')
642
+ setSearchParams((prev) => searchWithScope(prev, stateRef.current.scope));
643
+ };
644
+ // --- Whole-product actions (each applies at once, at every scope) -------------------------
645
+ const handleDelete = async () => {
646
+ if (deleting)
385
647
  return;
648
+ setDeleting(true);
649
+ setWholeProductError(null);
386
650
  try {
387
- await apiClient.delete(`/api/v1/admin/catalog/products/${id}`);
651
+ await apiClient.delete(PRODUCT_PATH(productId));
388
652
  navigate('/catalog/products');
389
653
  }
390
654
  catch (err) {
391
- setError(err instanceof ApiError ? err.envelope.error.message : t('productEditor.error.delete'));
655
+ setWholeProductError(withServerDetail(t('productEditor.error.delete'), err));
392
656
  }
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')))
657
+ finally {
658
+ setDeleting(false);
659
+ }
660
+ };
661
+ /** FR-119: the copy takes every scope except status and URL keys; the dialog says so. */
662
+ const handleDuplicate = async () => {
663
+ if (duplicating)
399
664
  return;
400
665
  setDuplicating(true);
401
- setError(null);
666
+ setWholeProductError(null);
402
667
  try {
403
- const res = await apiClient.post(`/api/v1/admin/catalog/products/${id}/duplicate`, {});
668
+ const res = await apiClient.post(`${PRODUCT_PATH(productId)}/duplicate`, {});
404
669
  navigate(`/catalog/products/${res.data.id}`);
405
670
  }
406
671
  catch (err) {
407
- setError(err instanceof ApiError ? err.envelope.error.message : t('productEditor.error.duplicate'));
672
+ setWholeProductError(withServerDetail(t('productEditor.error.duplicate'), err));
408
673
  }
409
674
  finally {
410
675
  setDuplicating(false);
411
676
  }
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)
677
+ };
678
+ // The dialog a Product menu item asked for, opened once the menu has handed focus back to its
679
+ // trigger (`onCloseAutoFocus`), so the dialog's focus trap starts from the trigger and returns
680
+ // there. A bare `setTimeout` raced the menu's own focus return on a slow machine.
681
+ const pendingWholeProductDialog = useRef(null);
682
+ const openWholeProductDialog = (kind) => {
683
+ setWholeProductError(null);
684
+ setArchiveError(null);
685
+ pendingWholeProductDialog.current = kind;
686
+ };
687
+ const afterProductMenuClosed = () => {
688
+ const kind = pendingWholeProductDialog.current;
689
+ pendingWholeProductDialog.current = null;
690
+ if (kind === null)
691
+ return;
692
+ // The menu focuses its trigger right after this handler returns.
693
+ setTimeout(() => {
694
+ if (kind === 'archive')
695
+ setArchiveDialog('archive');
696
+ else
697
+ setWholeProductDialog(kind);
698
+ }, 0);
699
+ };
700
+ const handleArchiveAction = async () => {
701
+ if (archiveDialog === null || archiving)
418
702
  return;
419
703
  setArchiving(true);
420
704
  setArchiveError(null);
421
705
  try {
422
- const res = await apiClient.post(`/api/v1/admin/catalog/products/${id}/${archiveDialog}`, {});
423
- setArchivedAt(res.data.archivedAt ?? null);
706
+ const res = await apiClient.post(`${PRODUCT_PATH(productId)}/${archiveDialog}`, {});
707
+ setArchivedOverride(res.data.archivedAt ?? null);
424
708
  setInfo(t(archiveDialog === 'archive' ? 'productEditor.archive.done' : 'productEditor.restore.done'));
425
- setError(null);
426
709
  setArchiveDialog(null);
427
710
  }
428
711
  catch (err) {
429
- setArchiveError(err instanceof ApiError
430
- ? err.envelope.error.message
431
- : t(archiveDialog === 'archive' ? 'productEditor.archive.failed' : 'productEditor.restore.failed'));
712
+ setArchiveError(withServerDetail(t(archiveDialog === 'archive' ? 'productEditor.archive.failed' : 'productEditor.restore.failed'), err));
432
713
  }
433
714
  finally {
434
715
  setArchiving(false);
435
716
  }
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] ?? '';
717
+ };
718
+ // --- Tabs ------------------------------------------------------------------------------------
719
+ const data = state.data;
720
+ const type = data?.product.type ?? null;
721
+ const tabLabel = (id) => id === 'composite' ? t(type === 'grouped' ? 'productEditor.tab.grouped' : 'productEditor.tab.bundle') : t(`productEditor.tab.${id}`);
722
+ const visibleTabs = TAB_IDS.filter((id) => {
723
+ if (id === 'variants')
724
+ return type === 'configurable';
725
+ if (id === 'composite')
726
+ return type === 'grouped' || type === 'bundle';
727
+ if (id === 'channels')
728
+ return channelContributions.length > 0;
729
+ if (id === 'seo')
730
+ return seoContributions.length > 0;
731
+ return true;
732
+ });
733
+ const requestedTab = searchParams.get('tab');
734
+ const activeTab = requestedTab && TAB_IDS.includes(requestedTab) && (visibleTabs.includes(requestedTab) || type === null)
735
+ ? requestedTab
736
+ : 'details';
737
+ const selectTab = (id, focus = false) => {
738
+ setSearchParams((prev) => {
739
+ const sp = new URLSearchParams(prev);
740
+ sp.set('tab', id);
741
+ sp.delete('field');
742
+ return sp;
743
+ }, { replace: true });
744
+ if (focus)
745
+ setTimeout(() => document.getElementById(`product-tab-${id}`)?.focus(), 0);
746
+ };
747
+ const onTabKey = (event) => {
748
+ const index = visibleTabs.indexOf(activeTab);
749
+ let next = index;
750
+ if (event.key === 'ArrowRight')
751
+ next = (index + 1) % visibleTabs.length;
752
+ else if (event.key === 'ArrowLeft')
753
+ next = (index - 1 + visibleTabs.length) % visibleTabs.length;
754
+ else if (event.key === 'Home')
755
+ next = 0;
756
+ else if (event.key === 'End')
757
+ next = visibleTabs.length - 1;
758
+ else
759
+ return;
760
+ event.preventDefault();
761
+ selectTab(visibleTabs[next], true);
762
+ };
763
+ const missingText = useCallback((fieldPath) => {
764
+ const c = state.data?.completeness;
765
+ if (!c || c.level !== 'channel_language')
766
+ return undefined;
767
+ return c.missing.includes(fieldPath)
768
+ ? t('productEditor.completeness.missingHere', { scope: scopeInWords(state.scope, state.data.validScopes, t, adminLanguage) })
769
+ : undefined;
770
+ }, [state.data, state.scope, t, adminLanguage]);
771
+ // --- Completeness summary (§9, FR-097), from saved values -------------------------------
772
+ const fieldLabel = (path) => {
773
+ if (path === 'name')
774
+ return t('productEditor.field.name');
775
+ if (path === 'urlKey')
776
+ return t('productEditor.field.urlKey');
777
+ const key = path.replace(/^attribute:/, '');
778
+ const attr = state.data?.attributes.find((a) => a.key === key);
779
+ const label = attr ? (Object.entries(attr.label).find(([code]) => code.split('-')[0] === adminLanguage)?.[1] ?? Object.values(attr.label)[0]) : undefined;
780
+ return label ?? key;
781
+ };
782
+ const fieldHref = (path) => {
783
+ const sp = new URLSearchParams(searchParams);
784
+ sp.set('tab', path.startsWith('attribute:') ? 'attributes' : 'details');
785
+ sp.set('field', path);
786
+ return `?${sp.toString()}`;
787
+ };
788
+ const openField = (path) => {
789
+ const tab = path.startsWith('attribute:') ? 'attributes' : 'details';
790
+ selectTab(tab);
791
+ setTimeout(() => document.getElementById(fieldDomId(path))?.focus(), 0);
792
+ };
793
+ const completenessNode = (() => {
794
+ const c = state.data?.completeness;
795
+ if (!c || !state.data)
796
+ return null;
797
+ const linkClass = 'text-primary underline underline-offset-2 max-lg:inline-flex max-lg:min-h-11 max-lg:items-center';
798
+ const fieldLink = (path, text) => (_jsx("a", { href: fieldHref(path), "data-own-unsaved-guard": "", className: linkClass, onClick: (e) => {
799
+ e.preventDefault();
800
+ openField(path);
801
+ }, children: text }, path));
802
+ const joined = (items) => items.flatMap((item, i) => (i === 0 ? [item] : [', ', item]));
803
+ let body = null;
804
+ if (c.level === 'channel_language' && c.missing.length > 0) {
805
+ body = (_jsxs(_Fragment, { children: [t('productEditor.completeness.here'), " ", joined(c.missing.map((m) => fieldLink(m, fieldLabel(m))))] }));
806
+ }
807
+ else if (c.level === 'channel' && c.missing.length > 0) {
808
+ const channelId = state.scope.level === 'global' ? null : state.scope.channelId;
809
+ body = (_jsxs(_Fragment, { children: [t('productEditor.completeness.channel'), ' ', joined(c.missing.map((m) => fieldLink(m.field, t('productEditor.completeness.fieldLanguages', {
810
+ field: fieldLabel(m.field),
811
+ languages: m.languages.map((code) => languageName(state.data.validScopes, channelId, code, adminLanguage)).join(', '),
812
+ }))))] }));
813
+ }
814
+ else if (c.level === 'global' && c.incompleteScopes > 0) {
815
+ body = (_jsxs(_Fragment, { children: [plural('productEditor.completeness.global', c.incompleteScopes), " \u2014", ' ', _jsx("a", { href: `?${(() => {
816
+ const sp = new URLSearchParams(searchParams);
817
+ sp.set('tab', 'scopes');
818
+ return sp.toString();
819
+ })()}`, className: linkClass, "data-own-unsaved-guard": "", onClick: (e) => {
820
+ e.preventDefault();
821
+ selectTab('scopes');
822
+ }, children: t('productEditor.scope.scopeMap') })] }));
823
+ }
824
+ if (!body)
825
+ return null;
826
+ 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] }));
827
+ })();
828
+ const contextValue = useMemo(() => ({
829
+ productId,
830
+ state,
831
+ dispatch,
832
+ readOnly,
833
+ scopeLabel,
834
+ parentScopeLabel: parentLabel,
835
+ jumpTo: (scope, field) => requestScope(scope, undefined, field),
836
+ refreshFamily,
837
+ missingText,
838
+ afterCopy,
839
+ reloadDiscarding: () => reloadDiscardingRef.current(),
840
+ saveSession: session.handle,
841
+ }), [productId, state, readOnly, scopeLabel, parentLabel, requestScope, refreshFamily, missingText, afterCopy, session.handle]);
842
+ const archivedAt = archivedOverride !== undefined ? archivedOverride : (data?.product.archivedAt ?? null);
843
+ const status = data?.fields.status;
844
+ const statusValue = (status?.value ?? 'inactive');
845
+ const statusSource = !status || state.scope.level === 'global' || status.source === 'set' || status.source === 'set_empty'
846
+ ? null
847
+ : status.source === 'inherited_channel'
848
+ ? t('productEditor.statusSource.from', { scope: parentLabel })
849
+ : t('productEditor.statusSource.from', { scope: t('productEditor.scope.global') });
850
+ const title = data?.fields.name.value || data?.product.sku || '';
851
+ const stagedCount = totalUnsaved;
852
+ const atGlobal = state.scope.level === 'global';
853
+ 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] }) })] }));
854
+ const seoStaged = new Map();
855
+ for (const [path, op] of state.staged)
856
+ if (path.startsWith('seo:'))
857
+ seoStaged.set(path.slice(4), op);
858
+ const seoErrors = {};
859
+ for (const [path, message] of Object.entries(state.errors))
860
+ if (path.startsWith('seo:'))
861
+ seoErrors[path.slice(4)] = message;
862
+ const panel = () => {
863
+ if (!data && loadError) {
864
+ 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')] })] }));
865
+ }
866
+ if (!data) {
867
+ 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))) }));
868
+ }
869
+ // Global-only tabs outside Global: the notice, then the content read-only (FR-081). The
870
+ // zone-backed tabs (Pricing, Channels) belong to their contributors, which take no read-only
871
+ // flag, so they show the notice alone.
872
+ const structuralReadOnly = readOnly || !atGlobal;
873
+ if (GLOBAL_ONLY_TABS.has(activeTab) && !atGlobal && (activeTab === 'pricing' || activeTab === 'channels'))
874
+ return globalOnlyNotice;
875
+ const notice = GLOBAL_ONLY_TABS.has(activeTab) && !atGlobal ? globalOnlyNotice : null;
876
+ switch (activeTab) {
877
+ case 'details':
878
+ return (_jsx(DetailsTab, { attributeSets: attributeSets, categories: categories, categoriesLoading: categoriesLoading, referenceError: referenceError, onRetryReference: loadReference }));
879
+ case 'attributes':
880
+ return _jsx(ProductAttributesTab, {});
881
+ case 'pricing':
882
+ return (_jsxs("div", { className: "b2b-col", style: { gap: 16 }, children: [_jsx(SectionHeading, { title: t('productEditor.tab.pricing'), immediate: false }), _jsx(AdminZone, { name: "product.editor.pricing.before", props: { productId, saveSession: session.handle } }), _jsx(AdminZone, { name: "product.editor.pricing.after", props: { productId, saveSession: session.handle } })] }));
883
+ case 'variants':
884
+ return (_jsxs(_Fragment, { children: [notice, _jsx(VariantsSection, { productId: productId, readOnly: structuralReadOnly })] }));
885
+ case 'composite':
886
+ return (_jsxs(_Fragment, { children: [notice, type === 'grouped' ? (_jsx(GroupedItemsSection, { productId: productId, readOnly: structuralReadOnly })) : (_jsx(BundleSlotsSection, { productId: productId, readOnly: structuralReadOnly }))] }));
887
+ case 'media':
888
+ return (_jsxs(_Fragment, { children: [_jsx(AdminZone, { name: "product.editor.field.after", props: { productId, fieldPath: 'gallery', scope: state.scope, languageCodes: null, saveSession: session.handle } }), _jsx(GallerySection, {})] }));
889
+ case 'inventory':
890
+ 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: false }), structuralReadOnly ? (
891
+ // Stock outside Global (or without catalog:write) is shown, not edited: the panel
892
+ // has no read-only mode of its own, so its controls are disabled as a group.
893
+ _jsx("fieldset", { disabled: true, className: "m-0 min-w-0 border-0 p-0", "data-testid": "stock-read-only", children: _jsx(ProductInventoryTab, { productId: productId, editable: false }) })) : (_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] }));
894
+ case 'attachments':
895
+ return (_jsxs(_Fragment, { children: [_jsx(AdminZone, { name: "product.editor.field.after", props: { productId, fieldPath: 'attachments', scope: state.scope, languageCodes: null, saveSession: session.handle } }), _jsx(AttachmentsSection, {})] }));
896
+ case 'links':
897
+ return (_jsxs(_Fragment, { children: [notice, _jsx(ProductLinksSection, { productId: productId, readOnly: structuralReadOnly })] }));
898
+ case 'channels':
899
+ 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, saveSession: session.handle } })] }));
900
+ case 'scopes':
901
+ return (_jsx(ProductScopeOverview, { productId: productId, links: {
902
+ href: (scope, field) => {
903
+ const sp = searchWithScope(searchParams, scope);
904
+ sp.set('tab', tabOfField(field));
905
+ sp.delete('field');
906
+ if (field)
907
+ sp.set('field', field);
908
+ return `?${sp.toString()}`;
909
+ },
910
+ open: (scope, field) => requestScope(scope, undefined, field, tabOfField(field)),
911
+ words: (scope) => scopeShortWords(scope, valid, t, adminLanguage),
912
+ } }));
913
+ case 'seo':
914
+ return (_jsx(AdminZone, { name: "product.editor.seo", props: {
915
+ productId,
916
+ scope: state.scope,
917
+ scopeLabel,
918
+ parentScopeLabel: atGlobal ? null : parentLabel,
919
+ view: data.seo,
920
+ staged: seoStaged,
921
+ onStage: (field, op) => dispatch({ type: 'stage', path: `seo:${field}`, op }),
922
+ readOnly,
923
+ errors: seoErrors,
924
+ version: state.version,
925
+ } }));
926
+ }
927
+ };
928
+ /**
929
+ * The summary speaks for the parts the editor's own alert does not (`product-editor-save-ui.md`
930
+ * §2): a refusal or failure of the host part alone keeps 174's messages; a part of a panel, or a
931
+ * partial save, is listed part by part.
932
+ */
933
+ function showSummary(outcome) {
934
+ if (outcome === null || outcome.result === 'saved')
935
+ return false;
936
+ return outcome.result === 'partial' || outcome.parts.some((part) => part.id !== 'host' && part.result !== 'saved' && part.result !== 'not-attempted');
937
+ }
938
+ /** "Show": the part's tab, then its first marked field. */
939
+ const showPart = (partId) => {
940
+ const tab = partId === 'host' ? activeTab : tabOfZone(session.zoneOf(partId));
941
+ selectTab(tab);
942
+ setTimeout(() => {
943
+ const panel = document.getElementById('product-tabpanel');
944
+ const first = panel?.querySelector('[aria-invalid="true"]');
945
+ (first ?? panel)?.focus();
946
+ }, 0);
947
+ };
948
+ const guardOpen = guard !== null;
949
+ 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: () => {
950
+ if (hasUnsaved())
951
+ setGuard({ kind: 'leave' });
952
+ else
953
+ navigate('/catalog/products');
954
+ }, 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') })] })) : 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, action:
955
+ // OQ-6 = A (FR-035): shown when the operator may write the product or any panel.
956
+ canWrite || session.hasWritableParticipant ? (_jsx(ProductEditorSaveAction, { stagedCount: stagedCount, saving: saving || session.saving, ready: Boolean(data), scopeWords: words(state.scope), onSave: () => void save() })) : null }), _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, showSummary(session.lastOutcome) || session.notices.length > 0 ? (_jsx("div", { className: "mb-4", "data-testid": "product-save-summary", children: _jsx(SaveSessionSummary, { outcome: showSummary(session.lastOutcome) ? session.lastOutcome : null, notices: session.notices, onShow: showPart }) })) : 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: () => {
957
+ setArchiveError(null);
958
+ setArchiveDialog('restore');
959
+ }, 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) => {
960
+ const selected = activeTab === id;
961
+ 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));
962
+ }) }) }) }), _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: () => {
963
+ dispatch({ type: 'discard' });
964
+ session.discardAll();
965
+ proceed(guard);
966
+ }, children: t('productEditor.guard.discard') }), _jsx(Button, { type: "button", disabled: saving, "aria-busy": saving || undefined, onClick: () => {
967
+ void save().then((ok) => {
968
+ if (ok) {
969
+ proceed(guard);
970
+ return;
971
+ }
972
+ setGuard(null);
973
+ // The summary focuses itself when it has something to say; else the form error.
974
+ setTimeout(() => {
975
+ if (!document.querySelector('[data-testid="product-save-summary"]'))
976
+ document.getElementById('product-save-error')?.focus();
977
+ }, 0);
978
+ });
979
+ }, 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', {
980
+ product: k.losingProductName,
981
+ key: describeKeyInLanguage(k.key, k.languageCode, t),
982
+ }) }, `${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'
983
+ ? duplicating
984
+ ? t('productEditor.action.duplicating')
985
+ : t('productEditor.duplicateAction')
986
+ : t('productEditor.deleteAction') })] }), children: [_jsxs("p", { id: "product-whole-confirm-body", className: "text-sm", children: [t(wholeProductDialog === 'duplicate' ? 'productEditor.duplicateConfirm' : 'productEditor.deleteConfirm'), stagedCount > 0
987
+ ? ` ${t(wholeProductDialog === 'duplicate' ? 'productEditor.duplicateUnsaved' : 'productEditor.deleteUnsaved')}`
988
+ : 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
989
  }
511
- function VariantsSection({ productId }) {
990
+ function VariantsSection({ productId, readOnly = false }) {
512
991
  const t = useTranslation('catalog');
992
+ const { ask, dialog: removalDialog } = useConfirmRemoval();
513
993
  const [variants, setVariants] = useState([]);
514
994
  const [loading, setLoading] = useState(true);
515
995
  const [error, setError] = useState(null);
@@ -518,12 +998,11 @@ function VariantsSection({ productId }) {
518
998
  setLoading(true);
519
999
  setError(null);
520
1000
  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 ?? []);
1001
+ // Issue #410 — the admin read answers every variant whatever the
1002
+ // product's status or channels; the storefront's product read answers
1003
+ // an inactive product 410 and an out-of-channel one 404.
1004
+ const res = await apiClient.get(`/api/v1/admin/catalog/products/${productId}/variants`);
1005
+ setVariants(res.data);
527
1006
  }
528
1007
  catch (err) {
529
1008
  setError(err instanceof ApiError ? err.envelope.error.message : t('productEditor.variants.error.load'));
@@ -563,7 +1042,7 @@ function VariantsSection({ productId }) {
563
1042
  }
564
1043
  }, [productId, refresh, t]);
565
1044
  const handleDelete = useCallback(async (variantId, sku) => {
566
- if (!confirm(t('productEditor.variants.deleteConfirm', { sku })))
1045
+ if (!(await ask(t('productEditor.variants.deleteConfirm', { sku }))))
567
1046
  return;
568
1047
  try {
569
1048
  await apiClient.delete(`/api/v1/admin/catalog/products/${productId}/variants/${variantId}`);
@@ -573,10 +1052,10 @@ function VariantsSection({ productId }) {
573
1052
  catch (err) {
574
1053
  setError(err instanceof ApiError ? err.envelope.error.message : t('productEditor.variants.error.delete'));
575
1054
  }
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)
1055
+ }, [productId, refresh, ask, t]);
1056
+ 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
1057
  .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 })] })] }));
1058
+ .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
1059
  }
581
1060
  function CreateVariantInline({ onCreate, }) {
582
1061
  const t = useTranslation('catalog');
@@ -599,13 +1078,12 @@ function CreateVariantInline({ onCreate, }) {
599
1078
  // ---------------------------------------------------------------------------
600
1079
  const LINK_KINDS = ['related', 'up_sell', 'cross_sell'];
601
1080
  function pickProductName(name, fallback) {
602
- if (!name)
603
- return fallback;
604
- return name['en-US'] ?? Object.values(name)[0] ?? fallback;
1081
+ return typeof name === 'string' && name !== '' ? name : fallback;
605
1082
  }
606
1083
  const TARGETS_BATCH_PAGE_SIZE = 200;
607
- function ProductLinksSection({ productId }) {
1084
+ function ProductLinksSection({ productId, readOnly = false }) {
608
1085
  const t = useTranslation('catalog');
1086
+ const { ask, dialog: removalDialog } = useConfirmRemoval();
609
1087
  const [links, setLinks] = useState([]);
610
1088
  const [targetsById, setTargetsById] = useState(() => new Map());
611
1089
  const [loading, setLoading] = useState(true);
@@ -667,7 +1145,7 @@ function ProductLinksSection({ productId }) {
667
1145
  }
668
1146
  }, [productId, refresh, t]);
669
1147
  const handleDelete = useCallback(async (linkId) => {
670
- if (!confirm(t('productEditor.links.removeConfirm')))
1148
+ if (!(await ask(t('productEditor.links.removeConfirm'))))
671
1149
  return;
672
1150
  try {
673
1151
  await apiClient.delete(`/api/v1/admin/catalog/products/${productId}/links/${linkId}`);
@@ -677,7 +1155,7 @@ function ProductLinksSection({ productId }) {
677
1155
  catch (err) {
678
1156
  setError(err instanceof ApiError ? err.envelope.error.message : t('productEditor.links.error.delete'));
679
1157
  }
680
- }, [productId, refresh, t]);
1158
+ }, [productId, refresh, ask, t]);
681
1159
  const byKind = useMemo(() => {
682
1160
  const result = {
683
1161
  related: [],
@@ -691,7 +1169,7 @@ function ProductLinksSection({ productId }) {
691
1169
  }
692
1170
  return result;
693
1171
  }, [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) => {
1172
+ 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
1173
  const target = targetsById.get(link.targetProductId);
696
1174
  const isMissing = !target;
697
1175
  // `inactive` is plain off; archived is its own fact.
@@ -699,8 +1177,8 @@ function ProductLinksSection({ productId }) {
699
1177
  const isArchived = target?.archivedAt != null;
700
1178
  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
1179
  ? 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 })] })] }));
1180
+ : `${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));
1181
+ }) })] }))] }, kind))) })), readOnly ? null : _jsx(CreateProductLinkInline, { onCreate: handleCreate, sourceProductId: productId })] }), removalDialog] }));
704
1182
  }
705
1183
  function CreateProductLinkInline({ onCreate, sourceProductId, }) {
706
1184
  const t = useTranslation('catalog');
@@ -714,8 +1192,9 @@ function CreateProductLinkInline({ onCreate, sourceProductId, }) {
714
1192
  });
715
1193
  }, children: t('productEditor.links.action.add') }) })] }));
716
1194
  }
717
- function GroupedItemsSection({ productId }) {
1195
+ function GroupedItemsSection({ productId, readOnly = false }) {
718
1196
  const t = useTranslation('catalog');
1197
+ const { ask, dialog: removalDialog } = useConfirmRemoval();
719
1198
  const [items, setItems] = useState([]);
720
1199
  const [loading, setLoading] = useState(true);
721
1200
  const [error, setError] = useState(null);
@@ -753,7 +1232,7 @@ function GroupedItemsSection({ productId }) {
753
1232
  }
754
1233
  }, [productId, refresh, t]);
755
1234
  const handleDelete = useCallback(async (itemId) => {
756
- if (!confirm(t('productEditor.grouped.removeConfirm')))
1235
+ if (!(await ask(t('productEditor.grouped.removeConfirm'))))
757
1236
  return;
758
1237
  try {
759
1238
  await apiClient.delete(`/api/v1/admin/catalog/products/${productId}/grouped-items/${itemId}`);
@@ -763,8 +1242,8 @@ function GroupedItemsSection({ productId }) {
763
1242
  catch (err) {
764
1243
  setError(err instanceof ApiError ? err.envelope.error.message : t('productEditor.grouped.error.delete'));
765
1244
  }
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 })] })] }));
1245
+ }, [productId, refresh, ask, t]);
1246
+ 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
1247
  }
769
1248
  function CreateGroupedItemInline({ onCreate, }) {
770
1249
  const t = useTranslation('catalog');
@@ -779,8 +1258,9 @@ function CreateGroupedItemInline({ onCreate, }) {
779
1258
  });
780
1259
  }, children: t('productEditor.grouped.action.add') }) })] }));
781
1260
  }
782
- function BundleSlotsSection({ productId }) {
1261
+ function BundleSlotsSection({ productId, readOnly = false }) {
783
1262
  const t = useTranslation('catalog');
1263
+ const { ask, dialog: removalDialog } = useConfirmRemoval();
784
1264
  const [slots, setSlots] = useState([]);
785
1265
  const [loading, setLoading] = useState(true);
786
1266
  const [error, setError] = useState(null);
@@ -823,7 +1303,7 @@ function BundleSlotsSection({ productId }) {
823
1303
  }
824
1304
  }, [productId, refresh, t]);
825
1305
  const handleDeleteSlot = useCallback(async (slotId) => {
826
- if (!confirm(t('productEditor.bundle.removeSlotConfirm')))
1306
+ if (!(await ask(t('productEditor.bundle.removeSlotConfirm'))))
827
1307
  return;
828
1308
  try {
829
1309
  await apiClient.delete(`/api/v1/admin/catalog/products/${productId}/bundle-slots/${slotId}`);
@@ -833,7 +1313,7 @@ function BundleSlotsSection({ productId }) {
833
1313
  catch (err) {
834
1314
  setError(err instanceof ApiError ? err.envelope.error.message : t('productEditor.bundle.error.deleteSlot'));
835
1315
  }
836
- }, [productId, refresh, t]);
1316
+ }, [productId, refresh, ask, t]);
837
1317
  const handleAddOption = useCallback(async (slotId, optionProductId) => {
838
1318
  if (!optionProductId)
839
1319
  return;
@@ -847,7 +1327,7 @@ function BundleSlotsSection({ productId }) {
847
1327
  }
848
1328
  }, [productId, refresh, t]);
849
1329
  const handleRemoveOption = useCallback(async (slotId, optionId) => {
850
- if (!confirm(t('productEditor.bundle.removeOptionConfirm')))
1330
+ if (!(await ask(t('productEditor.bundle.removeOptionConfirm'))))
851
1331
  return;
852
1332
  try {
853
1333
  await apiClient.delete(`/api/v1/admin/catalog/products/${productId}/bundle-slots/${slotId}/options/${optionId}`);
@@ -857,21 +1337,21 @@ function BundleSlotsSection({ productId }) {
857
1337
  catch (err) {
858
1338
  setError(err instanceof ApiError ? err.envelope.error.message : t('productEditor.bundle.error.deleteOption'));
859
1339
  }
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 })] })] }));
1340
+ }, [productId, refresh, ask, t]);
1341
+ 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
1342
  }
863
- function BundleSlotCard({ slot, onAddOption, onRemoveOption, onDeleteSlot, }) {
1343
+ function BundleSlotCard({ slot, onAddOption, onRemoveOption, onDeleteSlot, readOnly = false, }) {
864
1344
  const t = useTranslation('catalog');
865
1345
  const [optionId, setOptionId] = useState('');
866
1346
  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
1347
  min: slot.minQuantity,
868
1348
  max: slot.maxQuantity,
869
1349
  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: () => {
1350
+ }) })] }), 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
1351
  void onAddOption(slot.id, optionId).then(() => {
872
1352
  setOptionId('');
873
1353
  });
874
- }, children: t('productEditor.bundle.action.addOption') })] })] }));
1354
+ }, children: t('productEditor.bundle.action.addOption') })] }))] }));
875
1355
  }
876
1356
  function CreateBundleSlotInline({ onCreate, }) {
877
1357
  const t = useTranslation('catalog');