@mercurjs/vendor 2.2.0-canary.2 → 2.2.0-canary.21

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 (266) hide show
  1. package/dist/{[id]-KRLGIVLR.js → [id]-3JICOSAI.js} +133 -41
  2. package/dist/[id]-CR76L5TG.js +3102 -0
  3. package/dist/{[id]-7BAKUHUO.js → [id]-DDGHFRSB.js} +5 -5
  4. package/dist/{[id]-KVWYLDN3.js → [id]-E7DYRMMO.js} +162 -71
  5. package/dist/{[id]-4OBGG7OH.js → [id]-FIP4UMQ4.js} +197 -105
  6. package/dist/{[id]-3EC6HYXL.js → [id]-FZRXOJWL.js} +22 -21
  7. package/dist/{[id]-ZWWMJAKI.js → [id]-PD3ISUL5.js} +7 -7
  8. package/dist/{[id]-UUUQK22M.js → [id]-Q5AXQ5XO.js} +460 -581
  9. package/dist/{[id]-KJIQTFGE.js → [id]-VSNA6SV5.js} +15 -15
  10. package/dist/{[id]-Y2ISCLUD.js → [id]-XUKQKCDN.js} +3 -3
  11. package/dist/{[id]-K2CT7BXQ.js → [id]-YPCO3DJV.js} +1 -1
  12. package/dist/{[id]-LUFRJLAU.js → [id]-ZEFQ7FQQ.js} +36 -33
  13. package/dist/{[id]-COLO4TQJ.js → [id]-ZW7TBWDU.js} +24 -23
  14. package/dist/{[province_id]-H2QAPKVH.js → [province_id]-CHOO7ERP.js} +14 -14
  15. package/dist/{add-FIWTANZX.js → add-GYXNRUAE.js} +40 -37
  16. package/dist/{add-PBZQCIZQ.js → add-IC5R27X3.js} +95 -32
  17. package/dist/{add-customer-groups-RAHCP67U.js → add-customer-groups-KIGBZT5G.js} +20 -23
  18. package/dist/{add-products-N3V2MVLD.js → add-products-ALJVIFXU.js} +23 -22
  19. package/dist/{add-promotions-CSCAJZHV.js → add-promotions-EQ5MMQKG.js} +8 -8
  20. package/dist/{add-to-campaign-DLP7PSQB.js → add-to-campaign-C6JDNB6F.js} +4 -4
  21. package/dist/{address-7F5SN7PV.js → address-UKLDTSTP.js} +13 -13
  22. package/dist/{adjust-inventory-SZF4W7LR.js → adjust-inventory-5XPGE44Y.js} +2 -2
  23. package/dist/allocate-items-URVRAFPS.js +685 -0
  24. package/dist/{areas-7Y6BVS5A.js → areas-64VXOFYS.js} +6 -6
  25. package/dist/{attributes-MBZ76HVZ.js → attributes-YQNW5JBY.js} +2 -2
  26. package/dist/{breadcrumb-HND5FFWC.js → breadcrumb-26G7BS3Q.js} +3 -3
  27. package/dist/{breadcrumb-7PURSRTT.js → breadcrumb-2AYN2SV7.js} +12 -12
  28. package/dist/{breadcrumb-ZCG2RHIU.js → breadcrumb-4KKLMVC3.js} +12 -12
  29. package/dist/{breadcrumb-WRG4SITG.js → breadcrumb-4XSHX5RV.js} +13 -13
  30. package/dist/{breadcrumb-QV2IAX7N.js → breadcrumb-E5OF4L2J.js} +2 -2
  31. package/dist/breadcrumb-JC5FUQYF.js +28 -0
  32. package/dist/{breadcrumb-YBBYFQYG.js → breadcrumb-LBO2I4OJ.js} +1 -1
  33. package/dist/breadcrumb-PIDJ23EZ.js +13 -0
  34. package/dist/{breadcrumb-65SAGUUL.js → breadcrumb-RWYEU5JK.js} +3 -3
  35. package/dist/{breadcrumb-VWELWDB2.js → breadcrumb-VXKAO6GP.js} +1 -1
  36. package/dist/{breadcrumb-FLDHJRVY.js → breadcrumb-WMNG4P6C.js} +9 -8
  37. package/dist/{breadcrumb-EDPMEN2P.js → breadcrumb-XPQETVMM.js} +2 -2
  38. package/dist/{campaigns-L6ULR6KR.js → campaigns-4I2T6EDZ.js} +5 -5
  39. package/dist/{categories-FUZQKBXV.js → categories-3P2DRH5V.js} +10 -8
  40. package/dist/{chunk-EZ3JOAUS.js → chunk-22CIYLKO.js} +1 -1
  41. package/dist/{chunk-RZLN2Q6G.js → chunk-247L47JD.js} +1 -1
  42. package/dist/{chunk-SFQKKIHA.js → chunk-27WLUOI2.js} +1 -1
  43. package/dist/{chunk-M7KSRYRI.js → chunk-2ECD67FO.js} +2 -2
  44. package/dist/{chunk-36L54SQQ.js → chunk-2H4FGZ4U.js} +1 -1
  45. package/dist/{chunk-X2FVFUET.js → chunk-2NUZTTBU.js} +27 -8
  46. package/dist/chunk-2OY4NW7L.js +185 -0
  47. package/dist/{chunk-K4X324QP.js → chunk-36WXPGD2.js} +6 -5
  48. package/dist/{chunk-PXYDR7WQ.js → chunk-3BXCPHN6.js} +3 -2
  49. package/dist/chunk-3EDZQSKG.js +33 -0
  50. package/dist/{chunk-2DXNJURE.js → chunk-3L2DVCOC.js} +1 -1
  51. package/dist/chunk-42R54Z2X.js +8 -0
  52. package/dist/{chunk-CNMY5HVP.js → chunk-4EQIJMQT.js} +3 -3
  53. package/dist/{chunk-UAF2S447.js → chunk-4OIOYUQE.js} +3 -3
  54. package/dist/{chunk-UORPTGV2.js → chunk-4R5GESED.js} +10 -14
  55. package/dist/{chunk-WUPJADSO.js → chunk-4RFPRO2W.js} +2 -2
  56. package/dist/chunk-4YWKKCTT.js +32 -0
  57. package/dist/{chunk-XFQJU6FA.js → chunk-5QG6P6EU.js} +1 -1
  58. package/dist/{chunk-N4MVIBFM.js → chunk-5Y6RDTW2.js} +3 -3
  59. package/dist/{chunk-DZIXC7OE.js → chunk-6FLSBL4Q.js} +30 -85
  60. package/dist/{chunk-DVEKYLPV.js → chunk-6QS6IZC6.js} +1 -1
  61. package/dist/chunk-6ZGQ3SOR.js +127 -0
  62. package/dist/{chunk-NXNJQZCP.js → chunk-7FIPNQM2.js} +1 -1
  63. package/dist/{chunk-NSZQERLE.js → chunk-7GGWRJJF.js} +2 -2
  64. package/dist/{chunk-QS6RWIBL.js → chunk-7RGUD6PI.js} +34 -20
  65. package/dist/{chunk-5L2DCA4W.js → chunk-7ZPJGL4C.js} +57 -6
  66. package/dist/{chunk-KD7RYE6R.js → chunk-AG6KIAUD.js} +2 -2
  67. package/dist/{chunk-UCQKXXLD.js → chunk-AKKIZD2P.js} +32 -34
  68. package/dist/chunk-CHBURL76.js +438 -0
  69. package/dist/{chunk-PBD36EZJ.js → chunk-CI4YXVQF.js} +2 -2
  70. package/dist/{chunk-7LBY5JLV.js → chunk-DAV7WS53.js} +1 -1
  71. package/dist/{chunk-6BS2AVGJ.js → chunk-DNXMONCL.js} +6 -6
  72. package/dist/{chunk-TNVYTMBL.js → chunk-E4O5PARZ.js} +4 -4
  73. package/dist/{chunk-L7QKFC5N.js → chunk-E6W57UP3.js} +32 -122
  74. package/dist/chunk-EEBJYXWA.js +15 -0
  75. package/dist/chunk-FP6U6BPH.js +61 -0
  76. package/dist/{chunk-SGR4DMCW.js → chunk-FRYZRBLA.js} +1 -1
  77. package/dist/chunk-FWPGOIFA.js +22 -0
  78. package/dist/chunk-GL7F6NDU.js +30 -0
  79. package/dist/chunk-H7BVANDX.js +407 -0
  80. package/dist/{chunk-FDR22JMM.js → chunk-HFRHHT36.js} +8 -63
  81. package/dist/{chunk-FJUUGFXL.js → chunk-HOUDNM5M.js} +1 -1
  82. package/dist/{chunk-6Y53VZ3C.js → chunk-HZCSJLGH.js} +11 -11
  83. package/dist/chunk-I75SROQZ.js +315 -0
  84. package/dist/{chunk-JQV7CXEC.js → chunk-II3ACSV2.js} +17 -2
  85. package/dist/{chunk-DARJTN4I.js → chunk-IMJ62GAP.js} +10 -5
  86. package/dist/{chunk-PPLC4IKI.js → chunk-IV57G2CB.js} +14 -1
  87. package/dist/{chunk-7SLWXX6L.js → chunk-J434WDD3.js} +5 -6
  88. package/dist/chunk-J6XCRFBW.js +30 -0
  89. package/dist/{chunk-KAZ5BYTQ.js → chunk-KCHYLLVG.js} +6 -4
  90. package/dist/{chunk-YGRTRAWX.js → chunk-KDE4HKH2.js} +1 -0
  91. package/dist/{chunk-GXIAIITP.js → chunk-KZYRC3WR.js} +36 -39
  92. package/dist/chunk-L57USMYC.js +39 -0
  93. package/dist/chunk-LFX6WU4A.js +36 -0
  94. package/dist/{chunk-EROX26D4.js → chunk-LRMWYKSF.js} +1 -1
  95. package/dist/{chunk-LWJF63JW.js → chunk-LTQQRVZG.js} +89 -14
  96. package/dist/chunk-LYYM7H7H.js +59 -0
  97. package/dist/{chunk-NHFEY3EI.js → chunk-M3YUT5AY.js} +2 -2
  98. package/dist/{chunk-H6LZ77GX.js → chunk-MJCL3WID.js} +1 -1
  99. package/dist/{chunk-X4INVIWL.js → chunk-MZRZVLWD.js} +3 -3
  100. package/dist/{chunk-DDH7ULIQ.js → chunk-N6MGVXXQ.js} +1 -1
  101. package/dist/{chunk-QXLRABYH.js → chunk-O7VOGTLX.js} +1 -1
  102. package/dist/{chunk-35G3SZRN.js → chunk-P3SOE76R.js} +1 -1
  103. package/dist/{chunk-PZ44R4AS.js → chunk-P7Q5ZSZD.js} +1 -1
  104. package/dist/{chunk-5ATEALH7.js → chunk-PFJFS3F4.js} +1 -5
  105. package/dist/chunk-POOTMH3K.js +62 -0
  106. package/dist/{chunk-GGWUWT55.js → chunk-QJI4OET7.js} +23 -36
  107. package/dist/{chunk-NJMNYS7G.js → chunk-QS35HWC5.js} +1 -1
  108. package/dist/{chunk-RTBNJQOV.js → chunk-R4JLYNUA.js} +419 -538
  109. package/dist/{chunk-DIW4GRTI.js → chunk-RT3G3GEK.js} +47 -31
  110. package/dist/{chunk-QT7YFHCA.js → chunk-S23FD6FA.js} +12 -0
  111. package/dist/{chunk-U2ZFCAPX.js → chunk-SITRHMZZ.js} +11 -8
  112. package/dist/chunk-SPFLYPY6.js +6 -0
  113. package/dist/{chunk-EIUYXS7E.js → chunk-SZBERGA4.js} +1 -1
  114. package/dist/chunk-T6DSYOY5.js +173 -0
  115. package/dist/{chunk-4LVP635F.js → chunk-TKSKCYM3.js} +128 -126
  116. package/dist/{chunk-QNNJN4H6.js → chunk-TSTUAL6N.js} +59 -0
  117. package/dist/{chunk-LNM2D2I4.js → chunk-TZMNEN7A.js} +7 -6
  118. package/dist/chunk-UM7ZR3VU.js +14 -0
  119. package/dist/{chunk-X22KTLZ7.js → chunk-UO6IX5Y7.js} +1 -1
  120. package/dist/chunk-VCUUITW6.js +35 -0
  121. package/dist/{chunk-LQD232FW.js → chunk-WJ5EU3KW.js} +1 -1
  122. package/dist/{chunk-AIF2KTEE.js → chunk-WKRW5OPL.js} +12 -2
  123. package/dist/{chunk-6YA3C4NB.js → chunk-XBKWFLJG.js} +4 -13
  124. package/dist/{chunk-WBHFU3MG.js → chunk-XJYQ4SW5.js} +2 -2
  125. package/dist/chunk-XQUF3WIS.js +159 -0
  126. package/dist/chunk-YBF45CX5.js +23 -0
  127. package/dist/{chunk-AVOIZO63.js → chunk-YQZBAP3S.js} +4 -2
  128. package/dist/chunk-ZHFFTT3I.js +17 -0
  129. package/dist/{chunk-TODJFRLH.js → chunk-ZHR77OQI.js} +2 -2
  130. package/dist/chunk-ZUHIKMQL.js +353 -0
  131. package/dist/{chunk-44RQ5PTN.js → chunk-ZZIJSTXN.js} +225 -90
  132. package/dist/{collections-YCAAFGSW.js → collections-7M7O23NO.js} +28 -26
  133. package/dist/{configuration-UOSNP45I.js → configuration-5IDQRYJQ.js} +4 -4
  134. package/dist/{configuration-C4IGBNXH.js → configuration-TXRAYMI4.js} +1 -1
  135. package/dist/{create-BJ4OO6LS.js → create-2N73Y6FO.js} +14 -14
  136. package/dist/{create-R7K3ECN6.js → create-3MUVY3UY.js} +1 -1
  137. package/dist/{create-SFU3W3ZH.js → create-6DRXGPYA.js} +1 -1
  138. package/dist/{create-XAD5NMSJ.js → create-6KM5AZCG.js} +20 -20
  139. package/dist/{create-YDDBH4VQ.js → create-A6CPQMMH.js} +27 -26
  140. package/dist/create-B4EWCX7X.js +1798 -0
  141. package/dist/{create-YBF4YGWG.js → create-BHSMHOFN.js} +1 -1
  142. package/dist/{create-XVHOCZHJ.js → create-BVUZWMET.js} +1 -1
  143. package/dist/create-CJEZCYN6.js +1179 -0
  144. package/dist/create-DAVMJNC2.js +1931 -0
  145. package/dist/{create-35MYQPVM.js → create-E4HTVPP7.js} +17 -17
  146. package/dist/{create-JDGM5KXE.js → create-G4TF2M7G.js} +88 -42
  147. package/dist/{create-UQNYMVBM.js → create-LOP7AF5N.js} +6 -6
  148. package/dist/{create-UPYB65PD.js → create-MKFDE32U.js} +1 -1
  149. package/dist/{create-B5ZXTK3K.js → create-NR7ULWQS.js} +37 -34
  150. package/dist/{create-HI5UI2EZ.js → create-SJSLOXOW.js} +31 -26
  151. package/dist/{create-GB3ZA4LH.js → create-SYI6DVKM.js} +4 -4
  152. package/dist/{create-ORXYT74H.js → create-ZAGMLDR4.js} +13 -13
  153. package/dist/create-ZP4LSJYQ.js +216 -0
  154. package/dist/customer-group-add-customers-GTM556QA.js +251 -0
  155. package/dist/customer-group-create-OYHAXX2T.js +140 -0
  156. package/dist/customer-group-detail-KW62TLWA.js +58 -0
  157. package/dist/customer-group-edit-WH7O4N4L.js +137 -0
  158. package/dist/customer-groups-UJFZBZ2B.js +276 -0
  159. package/dist/{customers-ETXVNM3G.js → customers-4WKIFPUU.js} +7 -7
  160. package/dist/{edit-UGEC27HP.js → edit-3EN2H52W.js} +39 -36
  161. package/dist/{edit-ZMERG3L7.js → edit-3VNT35DW.js} +1 -1
  162. package/dist/{edit-ORXS3A2Y.js → edit-6DUTTLEV.js} +1 -1
  163. package/dist/edit-6K3NSVI7.js +103 -0
  164. package/dist/{edit-REDDBLTA.js → edit-6Z6RIJRZ.js} +4 -4
  165. package/dist/{edit-2Q7TRUTL.js → edit-CVSO5CX7.js} +14 -14
  166. package/dist/{edit-ZAHCMF5U.js → edit-FQDSESVI.js} +1 -1
  167. package/dist/edit-GZXLWSTL.js +176 -0
  168. package/dist/edit-LLNKSZR4.js +871 -0
  169. package/dist/{edit-O4JLGKQR.js → edit-MKVDAUA5.js} +1 -1
  170. package/dist/{edit-ZCXUG42Q.js → edit-NDUSRTWY.js} +13 -13
  171. package/dist/{edit-522DG3BY.js → edit-RBREBAQQ.js} +1 -1
  172. package/dist/{edit-Q3UQIOLS.js → edit-RQHOHZR6.js} +1 -1
  173. package/dist/{edit-VKT62KHG.js → edit-SAB6F3ZG.js} +36 -15
  174. package/dist/{edit-C4OCKQVU.js → edit-SM2GHVKW.js} +1 -1
  175. package/dist/{edit-KAKVPHZZ.js → edit-UVY3TEHD.js} +1 -1
  176. package/dist/{edit-SGUY2CCK.js → edit-V7WLYLOQ.js} +16 -16
  177. package/dist/{edit-FKXIQ6ZI.js → edit-XMZSLH4O.js} +16 -16
  178. package/dist/{edit-L5ZZLMAY.js → edit-YTS77SJS.js} +43 -32
  179. package/dist/{edit-budget-L3CCEWNF.js → edit-budget-4JMGEPNF.js} +1 -1
  180. package/dist/{edit-inventory-item-6B7ITDGD.js → edit-inventory-item-G22KFCYY.js} +2 -2
  181. package/dist/{edit-inventory-item-attributes-Y7MQZLXI.js → edit-inventory-item-attributes-RJSM4MEI.js} +2 -2
  182. package/dist/edit-price-K6K2FTMF.js +196 -0
  183. package/dist/edit-stock-6TUSJD5R.js +229 -0
  184. package/dist/fulfillment-VEF6HG6D.js +641 -0
  185. package/dist/{fulfillment-providers-DQAU43JZ.js → fulfillment-providers-VKBWFH45.js} +24 -24
  186. package/dist/index.css +107 -10
  187. package/dist/index.js +302 -183
  188. package/dist/{inventory-KAUVPMPZ.js → inventory-OCIGVZ4V.js} +6 -6
  189. package/dist/{offer-inventory-batch-page-WKCWNDNK.js → inventory-T7BRSFKY.js} +16 -16
  190. package/dist/{invite-CI2P4GF6.js → invite-J6L3Q7MQ.js} +12 -12
  191. package/dist/{invite-Q6EYDZVQ.js → invite-VWNUFOFI.js} +21 -21
  192. package/dist/loader-2EQ4ROTD.js +34 -0
  193. package/dist/loader-HYUC2XZX.js +33 -0
  194. package/dist/{login-KY342RMK.js → login-WOZMCEFY.js} +12 -12
  195. package/dist/{manage-locations-WNHEBS3A.js → manage-locations-R3ASMF5B.js} +1 -1
  196. package/dist/{media-B6ME2WXY.js → media-KIIJ6WSZ.js} +18 -17
  197. package/dist/media-RJHUSBXL.js +315 -0
  198. package/dist/{metadata-WR4RFXO5.js → metadata-45S6CFKY.js} +14 -14
  199. package/dist/{metadata-2CMH4I6U.js → metadata-FCATUWIZ.js} +14 -14
  200. package/dist/{metadata-GWI6R4ES.js → metadata-L5GBBXC4.js} +14 -14
  201. package/dist/{metadata-TLDUF5KV.js → metadata-R4ZRMAO6.js} +14 -14
  202. package/dist/{metadata-NUXUC2JA.js → metadata-RM5VVAOS.js} +14 -14
  203. package/dist/{offer-create-page-4Z6L63BU.js → offer-create-page-DV4JCIL2.js} +190 -195
  204. package/dist/offer-detail-page-TIBYGQBS.js +590 -0
  205. package/dist/offer-variant-detail-page-ORH56HZI.js +421 -0
  206. package/dist/offers-VA63KV3C.js +54 -0
  207. package/dist/{onboarding-43LQQQGQ.js → onboarding-L5RRKT65.js} +12 -12
  208. package/dist/{orders-ZV4D6L2V.js → orders-KKJD6EWZ.js} +27 -27
  209. package/dist/{organization-ZTQGRJWS.js → organization-6YPU2RQP.js} +53 -89
  210. package/dist/{organize-K6QMAMEN.js → organize-LR7FWK2J.js} +3 -3
  211. package/dist/{organize-HNJUHEEG.js → organize-SUG4SGVR.js} +3 -3
  212. package/dist/pages/index.d.ts +40 -16
  213. package/dist/pages/index.js +73 -73
  214. package/dist/{payment-details-64US5XWD.js → payment-details-UVEIHQA5.js} +13 -13
  215. package/dist/{payouts-UXJDTXDL.js → payouts-D4A4CILI.js} +8 -8
  216. package/dist/{price-lists-KBPUVSZI.js → price-lists-WJFXFGEV.js} +10 -10
  217. package/dist/{pricing-DF6C5XK4.js → pricing-QEVR2Z4K.js} +19 -19
  218. package/dist/{offer-pricing-edit-page-4TYGGSOE.js → pricing-XJUUCYL5.js} +24 -18
  219. package/dist/{product-tags-6MZB4W5R.js → product-tags-MW2JMRFY.js} +36 -33
  220. package/dist/{product-types-UUHBV4IZ.js → product-types-XXU7X42K.js} +6 -6
  221. package/dist/product-variant-detail-XZWTSH3H.js +369 -0
  222. package/dist/{product-variant-edit-YYNPHE4L.js → product-variant-edit-A2KO3E7B.js} +41 -44
  223. package/dist/{products-MZBU5MEV.js → products-TZS2OPK3.js} +37 -37
  224. package/dist/{products-IWKTGZS6.js → products-XSXEUKIB.js} +23 -22
  225. package/dist/{professional-details-5T2VS6MM.js → professional-details-ELUEJPOH.js} +13 -13
  226. package/dist/{profile-6XGHAT7H.js → profile-EDVGIBW6.js} +16 -16
  227. package/dist/{promotions-O7U4BTK6.js → promotions-JYO23G6N.js} +8 -8
  228. package/dist/receive-47SMYKIJ.js +578 -0
  229. package/dist/refund-IU7B77FV.js +268 -0
  230. package/dist/{register-N6WOSMLA.js → register-SR2SYX4Q.js} +14 -14
  231. package/dist/{reset-password-EICPAY2N.js → reset-password-N22YRMR3.js} +1 -1
  232. package/dist/{return-reasons-IX3LIOCU.js → return-reasons-POR5YPTF.js} +18 -15
  233. package/dist/{sales-channels-JW3QUYR7.js → sales-channels-ETB6QRRY.js} +8 -8
  234. package/dist/{sales-channels-B6FULRWI.js → sales-channels-YXRRARDL.js} +7 -7
  235. package/dist/{settings-MV53ZZ53.js → settings-MHBYIZ2I.js} +38 -35
  236. package/dist/shipment-ZX6PQ32L.js +241 -0
  237. package/dist/shipping-W4SPR3JO.js +122 -0
  238. package/dist/{shipping-profile-Y4SNEPZX.js → shipping-profile-L5CFXVEE.js} +4 -8
  239. package/dist/{shipping-profiles-2NWKCEJK.js → shipping-profiles-QBJUWXVQ.js} +17 -17
  240. package/dist/{stock-7CSVEJJU.js → stock-FW4DOVFV.js} +14 -14
  241. package/dist/{store-X23G3JCJ.js → store-NWWBV2UO.js} +75 -144
  242. package/dist/{store-closure-P5PD2RSV.js → store-closure-O3CBSOJD.js} +19 -14
  243. package/dist/{store-select-TREPDS3G.js → store-select-C7GI5MKK.js} +13 -13
  244. package/dist/{tax-regions-YXZW7UVX.js → tax-regions-2JCIB4T7.js} +2 -2
  245. package/dist/{team-SPP5OY5W.js → team-MY24J5WO.js} +20 -20
  246. package/package.json +2 -2
  247. package/dist/[id]-LTNOHLGE.js +0 -1219
  248. package/dist/allocate-items-SDFS5GYN.js +0 -533
  249. package/dist/chunk-432S4FGR.js +0 -0
  250. package/dist/chunk-AIZM66CG.js +0 -66
  251. package/dist/chunk-BDZOSMAX.js +0 -23
  252. package/dist/chunk-CFRWIQIZ.js +0 -43
  253. package/dist/chunk-GKZHBXZK.js +0 -426
  254. package/dist/chunk-RXZFEFNV.js +0 -73
  255. package/dist/chunk-T6LHVNWO.js +0 -27
  256. package/dist/chunk-WLT7K7K7.js +0 -63
  257. package/dist/create-FCKGCZSM.js +0 -210
  258. package/dist/edit-GQNIINRR.js +0 -192
  259. package/dist/fulfillment-75Z4H23W.js +0 -559
  260. package/dist/loader-FBB5OQRT.js +0 -31
  261. package/dist/metadata-5BPOBBU2.js +0 -45
  262. package/dist/offer-detail-page-6MAHNNIO.js +0 -488
  263. package/dist/offer-edit-page-DYQFU6JU.js +0 -151
  264. package/dist/offers-ZG6OTDZ2.js +0 -32
  265. package/dist/product-variant-detail-RVWEYVPC.js +0 -220
  266. package/dist/shipment-Q33QBMXX.js +0 -176
@@ -0,0 +1,1931 @@
1
+ import {
2
+ getOfferRestockPreview
3
+ } from "./chunk-J6XCRFBW.js";
4
+ import {
5
+ ItemPlaceholder
6
+ } from "./chunk-ZHFFTT3I.js";
7
+ import {
8
+ useReturnReasons
9
+ } from "./chunk-LHKHQAAY.js";
10
+ import {
11
+ useAddExchangeInboundItems,
12
+ useAddExchangeInboundShipping,
13
+ useAddExchangeOutboundItems,
14
+ useAddExchangeOutboundShipping,
15
+ useCancelExchangeBegin,
16
+ useCreateExchange,
17
+ useRemoveExchangeInboundItem,
18
+ useRemoveExchangeOutboundItem,
19
+ useRequestExchange,
20
+ useUpdateExchangeInboundItem,
21
+ useUpdateExchangeOutboundItem
22
+ } from "./chunk-2OY4NW7L.js";
23
+ import {
24
+ EXCHANGE_POLICY_DAYS
25
+ } from "./chunk-VCUUITW6.js";
26
+ import {
27
+ getReturnableQuantity
28
+ } from "./chunk-UM7ZR3VU.js";
29
+ import {
30
+ MoneyAmountCell
31
+ } from "./chunk-L57USMYC.js";
32
+ import {
33
+ getStylizedAmount
34
+ } from "./chunk-3BXCPHN6.js";
35
+ import {
36
+ ProductCell,
37
+ ProductHeader
38
+ } from "./chunk-FWPGOIFA.js";
39
+ import "./chunk-FQERBIVS.js";
40
+ import {
41
+ PlaceholderCell
42
+ } from "./chunk-PHOCVOZ5.js";
43
+ import {
44
+ _DataTable,
45
+ useDataTable
46
+ } from "./chunk-WKRW5OPL.js";
47
+ import "./chunk-YN3FGNJM.js";
48
+ import "./chunk-KCHYLLVG.js";
49
+ import "./chunk-3EF54XFY.js";
50
+ import "./chunk-IQPN4PZJ.js";
51
+ import {
52
+ Combobox
53
+ } from "./chunk-VBRTC2VU.js";
54
+ import "./chunk-TKGWSUEI.js";
55
+ import {
56
+ KeyboundForm
57
+ } from "./chunk-SITRHMZZ.js";
58
+ import {
59
+ RouteFocusModal,
60
+ StackedFocusModal,
61
+ useRouteModal,
62
+ useStackedModal
63
+ } from "./chunk-GDWBOQI5.js";
64
+ import {
65
+ Form
66
+ } from "./chunk-3QSRE5LS.js";
67
+ import {
68
+ useQueryParams
69
+ } from "./chunk-THHRRYRS.js";
70
+ import "./chunk-LRD242C7.js";
71
+ import {
72
+ Thumbnail
73
+ } from "./chunk-WIYFXWRI.js";
74
+ import "./chunk-INNFZYX2.js";
75
+ import {
76
+ useShippingOptions
77
+ } from "./chunk-VXMOPVRH.js";
78
+ import {
79
+ useStockLocations
80
+ } from "./chunk-NBPMNUKZ.js";
81
+ import {
82
+ useOffers
83
+ } from "./chunk-4R5GESED.js";
84
+ import {
85
+ useOrder,
86
+ useOrderPreview
87
+ } from "./chunk-7RGUD6PI.js";
88
+ import {
89
+ ActionMenu
90
+ } from "./chunk-BDGZ4EQO.js";
91
+ import "./chunk-LAVHRER2.js";
92
+ import "./chunk-QHQWEERJ.js";
93
+ import "./chunk-Y7QKP6QU.js";
94
+ import "./chunk-TSTUAL6N.js";
95
+ import "./chunk-A5DJIOHN.js";
96
+ import "./chunk-RHKRREUU.js";
97
+ import "./chunk-ZA2KFUFR.js";
98
+ import "./chunk-RIN4CBRB.js";
99
+ import "./chunk-NBMM2TZK.js";
100
+
101
+ // src/pages/orders/[id]/exchanges/create/index.tsx
102
+ import { useTranslation as useTranslation12 } from "react-i18next";
103
+
104
+ // src/pages/orders/[id]/exchanges/create/_components/exchange-create-form/exchange-create-form.tsx
105
+ import { zodResolver } from "@hookform/resolvers/zod";
106
+ import { Button as Button3, Heading as Heading3, Switch, Text as Text5, toast as toast3, usePrompt } from "@medusajs/ui";
107
+ import { useEffect as useEffect3, useMemo as useMemo7, useState as useState3 } from "react";
108
+ import { useForm } from "react-hook-form";
109
+ import { useNavigate, useParams } from "react-router-dom";
110
+ import { useTranslation as useTranslation11 } from "react-i18next";
111
+
112
+ // src/pages/orders/[id]/exchanges/create/_components/exchange-create-form/exchange-inbound-section.tsx
113
+ import { Button, Heading, Text as Text2, toast } from "@medusajs/ui";
114
+ import { useEffect, useMemo as useMemo3 } from "react";
115
+ import { useFieldArray } from "react-hook-form";
116
+ import { useTranslation as useTranslation5 } from "react-i18next";
117
+
118
+ // src/pages/orders/[id]/exchanges/create/_components/add-exchange-inbound-items-table/add-exchange-inbound-items-table.tsx
119
+ import { useMemo as useMemo2, useState } from "react";
120
+ import { useTranslation as useTranslation3 } from "react-i18next";
121
+
122
+ // src/pages/orders/[id]/exchanges/create/_components/add-exchange-inbound-items-table/use-exchange-item-table-columns.tsx
123
+ import { Checkbox } from "@medusajs/ui";
124
+ import { createColumnHelper } from "@tanstack/react-table";
125
+ import { useMemo } from "react";
126
+ import { useTranslation } from "react-i18next";
127
+ import { jsx } from "react/jsx-runtime";
128
+ var columnHelper = createColumnHelper();
129
+ var useExchangeItemTableColumns = (currencyCode) => {
130
+ const { t } = useTranslation();
131
+ return useMemo(
132
+ () => [
133
+ columnHelper.display({
134
+ id: "select",
135
+ header: ({ table }) => {
136
+ return /* @__PURE__ */ jsx(
137
+ Checkbox,
138
+ {
139
+ checked: table.getIsSomePageRowsSelected() ? "indeterminate" : table.getIsAllPageRowsSelected(),
140
+ onCheckedChange: (value) => table.toggleAllPageRowsSelected(!!value)
141
+ }
142
+ );
143
+ },
144
+ cell: ({ row }) => {
145
+ const isSelectable = row.getCanSelect();
146
+ return /* @__PURE__ */ jsx(
147
+ Checkbox,
148
+ {
149
+ disabled: !isSelectable,
150
+ checked: row.getIsSelected(),
151
+ onCheckedChange: (value) => row.toggleSelected(!!value),
152
+ onClick: (e) => {
153
+ e.stopPropagation();
154
+ }
155
+ }
156
+ );
157
+ }
158
+ }),
159
+ columnHelper.display({
160
+ id: "product",
161
+ header: () => /* @__PURE__ */ jsx(ProductHeader, {}),
162
+ cell: ({ row }) => /* @__PURE__ */ jsx(
163
+ ProductCell,
164
+ {
165
+ product: {
166
+ thumbnail: row.original.thumbnail,
167
+ title: row.original.product_title
168
+ }
169
+ }
170
+ )
171
+ }),
172
+ columnHelper.accessor("variant.sku", {
173
+ header: t("fields.sku"),
174
+ cell: ({ getValue }) => {
175
+ return getValue() || "-";
176
+ }
177
+ }),
178
+ columnHelper.accessor("variant.title", {
179
+ header: t("fields.variant")
180
+ }),
181
+ columnHelper.accessor("quantity", {
182
+ header: () => /* @__PURE__ */ jsx("div", { className: "flex size-full items-center overflow-hidden text-right", children: /* @__PURE__ */ jsx("span", { className: "truncate", children: t("fields.quantity") }) }),
183
+ cell: ({ row }) => {
184
+ return getReturnableQuantity(row.original);
185
+ }
186
+ }),
187
+ columnHelper.accessor("refundable_total", {
188
+ header: () => /* @__PURE__ */ jsx("div", { className: "flex size-full items-center justify-end overflow-hidden text-right", children: /* @__PURE__ */ jsx("span", { className: "truncate", children: t("fields.price") }) }),
189
+ cell: ({ getValue }) => {
190
+ const amount = getValue() || 0;
191
+ const stylized = getStylizedAmount(amount, currencyCode);
192
+ return /* @__PURE__ */ jsx("div", { className: "flex size-full items-center justify-end overflow-hidden text-right", children: /* @__PURE__ */ jsx("span", { className: "truncate", children: stylized }) });
193
+ }
194
+ })
195
+ ],
196
+ [t, currencyCode]
197
+ );
198
+ };
199
+
200
+ // src/pages/orders/[id]/exchanges/create/_components/add-exchange-inbound-items-table/use-exchange-item-table-filters.tsx
201
+ import { useTranslation as useTranslation2 } from "react-i18next";
202
+ var useExchangeItemTableFilters = () => {
203
+ const { t } = useTranslation2();
204
+ const filters = [
205
+ {
206
+ key: "created_at",
207
+ label: t("fields.createdAt"),
208
+ type: "date"
209
+ },
210
+ {
211
+ key: "updated_at",
212
+ label: t("fields.updatedAt"),
213
+ type: "date"
214
+ }
215
+ ];
216
+ return filters;
217
+ };
218
+
219
+ // src/pages/orders/[id]/exchanges/create/_components/add-exchange-inbound-items-table/use-exchange-item-table-query.tsx
220
+ var useExchangeItemTableQuery = ({
221
+ pageSize = 50,
222
+ prefix
223
+ }) => {
224
+ const raw = useQueryParams(
225
+ ["q", "offset", "order", "created_at", "updated_at"],
226
+ prefix
227
+ );
228
+ const { offset, created_at, updated_at, ...rest } = raw;
229
+ const searchParams = {
230
+ ...rest,
231
+ limit: pageSize,
232
+ offset: offset ? Number(offset) : 0,
233
+ created_at: created_at ? JSON.parse(created_at) : void 0,
234
+ updated_at: updated_at ? JSON.parse(updated_at) : void 0
235
+ };
236
+ return { searchParams, raw };
237
+ };
238
+
239
+ // src/pages/orders/[id]/exchanges/create/_components/add-exchange-inbound-items-table/add-exchange-inbound-items-table.tsx
240
+ import { jsx as jsx2 } from "react/jsx-runtime";
241
+ var PAGE_SIZE = 50;
242
+ var PREFIX = "rit";
243
+ var AddExchangeInboundItemsTable = ({
244
+ onSelectionChange,
245
+ selectedItems,
246
+ items,
247
+ currencyCode
248
+ }) => {
249
+ const { t } = useTranslation3();
250
+ const [rowSelection, setRowSelection] = useState(
251
+ selectedItems.reduce((acc, id) => {
252
+ acc[id] = true;
253
+ return acc;
254
+ }, {})
255
+ );
256
+ const updater = (fn) => {
257
+ const newState = typeof fn === "function" ? fn(rowSelection) : fn;
258
+ setRowSelection(newState);
259
+ onSelectionChange(Object.keys(newState));
260
+ };
261
+ const { searchParams, raw } = useExchangeItemTableQuery({
262
+ pageSize: PAGE_SIZE,
263
+ prefix: PREFIX
264
+ });
265
+ const queriedItems = useMemo2(() => {
266
+ const { order, offset, limit, q, created_at, updated_at } = searchParams;
267
+ let results = items;
268
+ if (q) {
269
+ const needle = q.toLowerCase();
270
+ results = results.filter((i) => {
271
+ return i.product_title?.toLowerCase().includes(needle) || i.variant_title?.toLowerCase().includes(needle) || i.variant_sku?.toLowerCase().includes(needle);
272
+ });
273
+ }
274
+ if (order) {
275
+ const direction = order[0] === "-" ? "desc" : "asc";
276
+ const field = order.replace("-", "");
277
+ results = sortItems(results, field, direction);
278
+ }
279
+ if (created_at) {
280
+ results = filterByDate(
281
+ results,
282
+ created_at,
283
+ "created_at"
284
+ );
285
+ }
286
+ if (updated_at) {
287
+ results = filterByDate(
288
+ results,
289
+ updated_at,
290
+ "updated_at"
291
+ );
292
+ }
293
+ return results.slice(offset, offset + limit);
294
+ }, [items, searchParams]);
295
+ const columns = useExchangeItemTableColumns(currencyCode);
296
+ const filters = useExchangeItemTableFilters();
297
+ const { table } = useDataTable({
298
+ data: queriedItems,
299
+ columns,
300
+ count: queriedItems.length,
301
+ enablePagination: true,
302
+ getRowId: (row) => row.id,
303
+ pageSize: PAGE_SIZE,
304
+ enableRowSelection: (row) => {
305
+ return getReturnableQuantity(row.original) > 0;
306
+ },
307
+ rowSelection: {
308
+ state: rowSelection,
309
+ updater
310
+ }
311
+ });
312
+ return /* @__PURE__ */ jsx2("div", { className: "flex size-full flex-col overflow-hidden", children: /* @__PURE__ */ jsx2(
313
+ _DataTable,
314
+ {
315
+ table,
316
+ columns,
317
+ pageSize: PAGE_SIZE,
318
+ count: queriedItems.length,
319
+ filters,
320
+ pagination: true,
321
+ layout: "fill",
322
+ search: true,
323
+ orderBy: [
324
+ { key: "product_title", label: t("fields.product") },
325
+ { key: "variant_title", label: t("fields.variant") },
326
+ { key: "sku", label: t("fields.sku") }
327
+ ],
328
+ prefix: PREFIX,
329
+ queryObject: raw
330
+ }
331
+ ) });
332
+ };
333
+ var sortItems = (items, field, direction) => {
334
+ return items.sort((a, b) => {
335
+ let aValue;
336
+ let bValue;
337
+ if (field === "product_title") {
338
+ aValue = a.product_title;
339
+ bValue = b.product_title;
340
+ } else if (field === "variant_title") {
341
+ aValue = a.variant_title;
342
+ bValue = b.variant_title;
343
+ } else if (field === "sku") {
344
+ aValue = a.variant_sku;
345
+ bValue = b.variant_sku;
346
+ }
347
+ const aSafe = aValue ?? "";
348
+ const bSafe = bValue ?? "";
349
+ if (aSafe < bSafe) {
350
+ return direction === "asc" ? -1 : 1;
351
+ }
352
+ if (aSafe > bSafe) {
353
+ return direction === "asc" ? 1 : -1;
354
+ }
355
+ return 0;
356
+ });
357
+ };
358
+ var filterByDate = (items, date, field) => {
359
+ const { gt, gte, lt, lte } = date;
360
+ return items.filter((i) => {
361
+ const itemDate = new Date(i[field]);
362
+ let isValid = true;
363
+ if (gt) {
364
+ isValid = isValid && itemDate > new Date(gt);
365
+ }
366
+ if (gte) {
367
+ isValid = isValid && itemDate >= new Date(gte);
368
+ }
369
+ if (lt) {
370
+ isValid = isValid && itemDate < new Date(lt);
371
+ }
372
+ if (lte) {
373
+ isValid = isValid && itemDate <= new Date(lte);
374
+ }
375
+ return isValid;
376
+ });
377
+ };
378
+
379
+ // src/pages/orders/[id]/exchanges/create/_components/exchange-create-form/exchange-inbound-item.tsx
380
+ import { ChatBubble, DocumentText, XCircle, XMark } from "@medusajs/icons";
381
+ import { IconButton, Input, Text } from "@medusajs/ui";
382
+ import { useTranslation as useTranslation4 } from "react-i18next";
383
+ import { jsx as jsx3, jsxs } from "react/jsx-runtime";
384
+ function ExchangeInboundItem({
385
+ item,
386
+ previewItem,
387
+ currencyCode,
388
+ form,
389
+ onRemove,
390
+ onUpdate,
391
+ index,
392
+ locationName
393
+ }) {
394
+ const { t } = useTranslation4();
395
+ const { return_reasons = [] } = useReturnReasons({ fields: "+label" });
396
+ const returnReasons = return_reasons;
397
+ const formItem = form.watch(`inbound_items.${index}`);
398
+ const showReturnReason = typeof formItem?.reason_id === "string";
399
+ const showNote = typeof formItem?.note === "string";
400
+ const quantity = formItem?.quantity ?? 0;
401
+ const appliedPromoCodes = (previewItem?.adjustments ?? []).map((adjustment) => adjustment.code).filter((code) => Boolean(code));
402
+ return /* @__PURE__ */ jsxs(
403
+ "div",
404
+ {
405
+ className: "bg-ui-bg-subtle shadow-elevation-card-rest my-2 rounded-xl",
406
+ "data-testid": `exchange-inbound-item-${item.id}`,
407
+ children: [
408
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col items-center gap-x-3 gap-y-2 p-3 text-sm md:flex-row", children: [
409
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-1 items-center gap-x-3", children: [
410
+ /* @__PURE__ */ jsx3(Thumbnail, { src: item.thumbnail }),
411
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-grow flex-col", children: [
412
+ /* @__PURE__ */ jsxs("div", { children: [
413
+ /* @__PURE__ */ jsxs(Text, { className: "txt-small", as: "span", weight: "plus", children: [
414
+ item.title,
415
+ " "
416
+ ] }),
417
+ item.variant_sku && /* @__PURE__ */ jsxs("span", { children: [
418
+ "(",
419
+ item.variant_sku,
420
+ ")"
421
+ ] })
422
+ ] }),
423
+ /* @__PURE__ */ jsx3(Text, { as: "div", className: "text-ui-fg-subtle txt-small", children: item.product_title })
424
+ ] }),
425
+ appliedPromoCodes.length > 0 && /* @__PURE__ */ jsx3(
426
+ "div",
427
+ {
428
+ className: "flex flex-shrink",
429
+ title: appliedPromoCodes.join(", ")
430
+ }
431
+ )
432
+ ] }),
433
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-1 justify-between", children: [
434
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-grow items-center gap-2", children: [
435
+ /* @__PURE__ */ jsx3(
436
+ Form.Field,
437
+ {
438
+ control: form.control,
439
+ name: `inbound_items.${index}.quantity`,
440
+ render: ({ field }) => {
441
+ return /* @__PURE__ */ jsxs(Form.Item, { children: [
442
+ /* @__PURE__ */ jsx3(Form.Control, { children: /* @__PURE__ */ jsx3(
443
+ Input,
444
+ {
445
+ ...field,
446
+ className: "bg-ui-bg-base txt-small w-[67px] rounded-lg",
447
+ min: 1,
448
+ max: item.quantity,
449
+ type: "number",
450
+ "data-testid": `exchange-inbound-item-${item.id}-qty`,
451
+ onBlur: (e) => {
452
+ const val = e.target.value;
453
+ const payload = val === "" ? null : Number(val);
454
+ field.onChange(payload);
455
+ if (payload) {
456
+ onUpdate({ quantity: payload });
457
+ }
458
+ }
459
+ }
460
+ ) }),
461
+ /* @__PURE__ */ jsx3(Form.ErrorMessage, {})
462
+ ] });
463
+ }
464
+ }
465
+ ),
466
+ /* @__PURE__ */ jsx3(Text, { className: "txt-small text-ui-fg-subtle", children: t("fields.qty") })
467
+ ] }),
468
+ /* @__PURE__ */ jsx3("div", { className: "text-ui-fg-subtle txt-small mr-2 flex flex-shrink-0", children: /* @__PURE__ */ jsx3(
469
+ MoneyAmountCell,
470
+ {
471
+ currencyCode,
472
+ amount: previewItem?.return_requested_total ?? 0
473
+ }
474
+ ) }),
475
+ /* @__PURE__ */ jsx3(
476
+ ActionMenu,
477
+ {
478
+ groups: [
479
+ {
480
+ actions: [
481
+ !showReturnReason && {
482
+ label: t("actions.addReason"),
483
+ onClick: () => form.setValue(`inbound_items.${index}.reason_id`, ""),
484
+ icon: /* @__PURE__ */ jsx3(ChatBubble, {})
485
+ },
486
+ !showNote && {
487
+ label: t("actions.addNote"),
488
+ onClick: () => form.setValue(`inbound_items.${index}.note`, ""),
489
+ icon: /* @__PURE__ */ jsx3(DocumentText, {})
490
+ },
491
+ {
492
+ label: t("actions.remove"),
493
+ onClick: onRemove,
494
+ icon: /* @__PURE__ */ jsx3(XCircle, {})
495
+ }
496
+ ].filter(Boolean)
497
+ }
498
+ ]
499
+ }
500
+ )
501
+ ] })
502
+ ] }),
503
+ locationName && quantity > 0 && /* @__PURE__ */ jsx3(
504
+ ExchangeRestockPreview,
505
+ {
506
+ item,
507
+ quantity,
508
+ locationName
509
+ }
510
+ ),
511
+ showReturnReason && /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-1 gap-2 p-3 md:grid-cols-2", children: [
512
+ /* @__PURE__ */ jsxs("div", { children: [
513
+ /* @__PURE__ */ jsx3(Form.Label, { children: t("orders.returns.reason") }),
514
+ /* @__PURE__ */ jsx3(Form.Hint, { className: "!mt-1", children: t("orders.returns.reasonHint") })
515
+ ] }),
516
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1", children: [
517
+ /* @__PURE__ */ jsx3("div", { className: "flex-grow", children: /* @__PURE__ */ jsx3(
518
+ Form.Field,
519
+ {
520
+ control: form.control,
521
+ name: `inbound_items.${index}.reason_id`,
522
+ render: ({ field: { value, onChange, ref: _ref, ...field } }) => {
523
+ return /* @__PURE__ */ jsxs(Form.Item, { children: [
524
+ /* @__PURE__ */ jsx3(Form.Control, { children: /* @__PURE__ */ jsx3(
525
+ Combobox,
526
+ {
527
+ className: "bg-ui-bg-field-component hover:bg-ui-bg-field-component-hover",
528
+ value: value ?? void 0,
529
+ onChange: (v) => {
530
+ onUpdate({ reason_id: v ?? null });
531
+ onChange(v);
532
+ },
533
+ ...field,
534
+ options: returnReasons.map((reason) => ({
535
+ label: reason.label ?? reason.value ?? reason.id,
536
+ value: reason.id
537
+ }))
538
+ }
539
+ ) }),
540
+ /* @__PURE__ */ jsx3(Form.ErrorMessage, {})
541
+ ] });
542
+ }
543
+ }
544
+ ) }),
545
+ /* @__PURE__ */ jsx3(
546
+ IconButton,
547
+ {
548
+ type: "button",
549
+ className: "flex-shrink",
550
+ variant: "transparent",
551
+ onClick: () => {
552
+ form.setValue(`inbound_items.${index}.reason_id`, null);
553
+ onUpdate({ reason_id: null });
554
+ },
555
+ children: /* @__PURE__ */ jsx3(XMark, { className: "text-ui-fg-muted" })
556
+ }
557
+ )
558
+ ] })
559
+ ] }),
560
+ showNote && /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-1 gap-2 p-3 md:grid-cols-2", children: [
561
+ /* @__PURE__ */ jsxs("div", { children: [
562
+ /* @__PURE__ */ jsx3(Form.Label, { children: t("orders.returns.note") }),
563
+ /* @__PURE__ */ jsx3(Form.Hint, { className: "!mt-1", children: t("orders.returns.noteHint") })
564
+ ] }),
565
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1", children: [
566
+ /* @__PURE__ */ jsx3("div", { className: "flex-grow", children: /* @__PURE__ */ jsx3(
567
+ Form.Field,
568
+ {
569
+ control: form.control,
570
+ name: `inbound_items.${index}.note`,
571
+ render: ({ field: { ref: _ref, value, ...field } }) => {
572
+ return /* @__PURE__ */ jsxs(Form.Item, { children: [
573
+ /* @__PURE__ */ jsx3(Form.Control, { children: /* @__PURE__ */ jsx3(
574
+ Input,
575
+ {
576
+ ...field,
577
+ value: value ?? "",
578
+ "data-testid": `exchange-inbound-item-${item.id}-note`,
579
+ onBlur: (e) => {
580
+ const next = e.target.value;
581
+ field.onChange(next);
582
+ onUpdate({ internal_note: next || null });
583
+ },
584
+ className: "bg-ui-bg-field-component hover:bg-ui-bg-field-component-hover"
585
+ }
586
+ ) }),
587
+ /* @__PURE__ */ jsx3(Form.ErrorMessage, {})
588
+ ] });
589
+ }
590
+ }
591
+ ) }),
592
+ /* @__PURE__ */ jsx3(
593
+ IconButton,
594
+ {
595
+ type: "button",
596
+ className: "flex-shrink",
597
+ variant: "transparent",
598
+ onClick: () => {
599
+ form.setValue(`inbound_items.${index}.note`, null);
600
+ onUpdate({ internal_note: null });
601
+ },
602
+ children: /* @__PURE__ */ jsx3(XMark, { className: "text-ui-fg-muted" })
603
+ }
604
+ )
605
+ ] })
606
+ ] })
607
+ ]
608
+ }
609
+ );
610
+ }
611
+ var ExchangeRestockPreview = ({
612
+ item,
613
+ quantity,
614
+ locationName
615
+ }) => {
616
+ const { t } = useTranslation4();
617
+ const preview = getOfferRestockPreview(item, quantity);
618
+ if (!preview.length) {
619
+ return null;
620
+ }
621
+ const offerSku = item.offer?.sku ?? item.variant_sku ?? null;
622
+ return /* @__PURE__ */ jsx3("div", { className: "bg-ui-bg-subtle flex flex-col gap-y-1 rounded-md px-3 py-2", children: preview.map((row) => /* @__PURE__ */ jsx3(
623
+ Text,
624
+ {
625
+ size: "xsmall",
626
+ className: "text-ui-fg-subtle",
627
+ "data-testid": `exchange-inbound-item-${item.id}-restock-${row.inventoryItemId}`,
628
+ children: t("orders.returns.restockPreview", {
629
+ quantity,
630
+ offerSku: offerSku ?? "\u2014",
631
+ delta: row.delta,
632
+ inventoryItem: row.inventoryItemLabel,
633
+ location: locationName ?? "\u2014"
634
+ })
635
+ },
636
+ row.inventoryItemId
637
+ )) });
638
+ };
639
+
640
+ // src/pages/orders/[id]/exchanges/create/_components/exchange-create-form/exchange-inbound-section.tsx
641
+ import { jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
642
+ var itemsToAdd = [];
643
+ var itemsToRemove = [];
644
+ var ExchangeInboundSection = ({
645
+ order,
646
+ preview,
647
+ exchange,
648
+ form,
649
+ orderReturn
650
+ }) => {
651
+ const { t } = useTranslation5();
652
+ const { setIsOpen } = useStackedModal();
653
+ const { mutateAsync: addInboundShipping } = useAddExchangeInboundShipping(
654
+ exchange.id,
655
+ order.id
656
+ );
657
+ const { mutateAsync: addInboundItem } = useAddExchangeInboundItems(
658
+ exchange.id,
659
+ order.id
660
+ );
661
+ const { mutateAsync: updateInboundItem } = useUpdateExchangeInboundItem(
662
+ exchange.id,
663
+ order.id
664
+ );
665
+ const { mutateAsync: removeInboundItem } = useRemoveExchangeInboundItem(
666
+ exchange.id,
667
+ order.id
668
+ );
669
+ const previewInboundItems = useMemo3(
670
+ () => (preview?.items ?? []).filter(
671
+ (i) => !!i.actions?.find((a) => a.exchange_id === exchange.id)
672
+ ),
673
+ [preview.items, exchange.id]
674
+ );
675
+ const inboundPreviewItems = previewInboundItems.filter(
676
+ (item) => !!item.actions?.find((a) => a.action === "RETURN_ITEM")
677
+ );
678
+ const itemsMap = useMemo3(
679
+ () => new Map((order?.items ?? []).map((i) => [i.id, i])),
680
+ [order.items]
681
+ );
682
+ const locationId = form.watch("location_id");
683
+ const { stock_locations = [] } = useStockLocations({
684
+ limit: 999
685
+ });
686
+ const { shipping_options = [] } = useShippingOptions(
687
+ {
688
+ limit: 999,
689
+ stock_location_id: locationId
690
+ },
691
+ { enabled: !!locationId }
692
+ );
693
+ const inboundShippingOptions = shipping_options.filter(
694
+ (shippingOption) => !!shippingOption.rules?.find(
695
+ (r) => r.attribute === "is_return" && r.value === "true"
696
+ )
697
+ );
698
+ const {
699
+ fields: inboundItems,
700
+ append,
701
+ remove,
702
+ update
703
+ } = useFieldArray({
704
+ name: "inbound_items",
705
+ control: form.control
706
+ });
707
+ const inboundItemsMap = useMemo3(
708
+ () => new Map(previewInboundItems.map((i) => [i.id, i])),
709
+ [previewInboundItems]
710
+ );
711
+ useEffect(() => {
712
+ const existingItemsMap = {};
713
+ inboundPreviewItems.forEach((i) => {
714
+ const ind = inboundItems.findIndex((field) => field.item_id === i.id);
715
+ const requested = i.detail?.return_requested_quantity ?? 0;
716
+ existingItemsMap[i.id] = true;
717
+ if (ind > -1) {
718
+ if (inboundItems[ind].quantity !== requested) {
719
+ const returnItemAction = i.actions?.find(
720
+ (a) => a.action === "RETURN_ITEM"
721
+ );
722
+ update(ind, {
723
+ ...inboundItems[ind],
724
+ quantity: requested,
725
+ note: returnItemAction?.internal_note ?? void 0,
726
+ reason_id: returnItemAction?.details?.reason_id
727
+ });
728
+ }
729
+ } else {
730
+ append(
731
+ { item_id: i.id, quantity: requested },
732
+ { shouldFocus: false }
733
+ );
734
+ }
735
+ });
736
+ inboundItems.forEach((i, ind) => {
737
+ if (!(i.item_id in existingItemsMap)) {
738
+ remove(ind);
739
+ }
740
+ });
741
+ }, [previewInboundItems]);
742
+ useEffect(() => {
743
+ const inboundShippingMethod = (preview.shipping_methods ?? []).find(
744
+ (s) => s.actions?.find((a) => a.action === "SHIPPING_ADD" && !!a.return_id)
745
+ );
746
+ if (inboundShippingMethod?.shipping_option_id) {
747
+ form.setValue("inbound_option_id", inboundShippingMethod.shipping_option_id);
748
+ } else {
749
+ form.setValue("inbound_option_id", "");
750
+ }
751
+ }, [preview.shipping_methods]);
752
+ useEffect(() => {
753
+ if (orderReturn?.location_id) {
754
+ form.setValue("location_id", orderReturn.location_id);
755
+ }
756
+ }, [orderReturn]);
757
+ const showInboundItemsPlaceholder = !inboundItems.length;
758
+ const onItemsSelected = async () => {
759
+ if (itemsToAdd.length) {
760
+ await addInboundItem(
761
+ {
762
+ items: itemsToAdd.map((id) => ({
763
+ id,
764
+ quantity: 1
765
+ }))
766
+ },
767
+ {
768
+ onError: (error) => {
769
+ toast.error(error.message);
770
+ }
771
+ }
772
+ );
773
+ }
774
+ for (const itemToRemove of itemsToRemove) {
775
+ const actionId = previewInboundItems.find((i) => i.id === itemToRemove)?.actions?.find((a) => a.action === "RETURN_ITEM")?.id;
776
+ if (actionId) {
777
+ await removeInboundItem(actionId, {
778
+ onError: (error) => {
779
+ toast.error(error.message);
780
+ }
781
+ });
782
+ }
783
+ }
784
+ setIsOpen("inbound-items", false);
785
+ };
786
+ const onLocationChange = (_selectedLocationId) => {
787
+ };
788
+ const onShippingOptionChange = async (selectedOptionId) => {
789
+ if (selectedOptionId) {
790
+ await addInboundShipping(
791
+ { shipping_option_id: selectedOptionId },
792
+ {
793
+ onError: (error) => {
794
+ toast.error(error.message);
795
+ }
796
+ }
797
+ );
798
+ }
799
+ };
800
+ return /* @__PURE__ */ jsxs2("div", { children: [
801
+ /* @__PURE__ */ jsxs2("div", { className: "mt-8 flex items-center justify-between", children: [
802
+ /* @__PURE__ */ jsx4(Heading, { level: "h2", children: t("orders.returns.inbound") }),
803
+ /* @__PURE__ */ jsxs2(StackedFocusModal, { id: "inbound-items", children: [
804
+ /* @__PURE__ */ jsx4(StackedFocusModal.Trigger, { asChild: true, children: /* @__PURE__ */ jsx4(
805
+ "a",
806
+ {
807
+ href: "#",
808
+ onClick: (e) => e.preventDefault(),
809
+ className: "focus-visible:shadow-borders-focus transition-fg txt-compact-small-plus cursor-pointer text-blue-500 outline-none hover:text-blue-400",
810
+ children: t("actions.addItems")
811
+ }
812
+ ) }),
813
+ /* @__PURE__ */ jsxs2(StackedFocusModal.Content, { children: [
814
+ /* @__PURE__ */ jsx4(StackedFocusModal.Header, {}),
815
+ /* @__PURE__ */ jsx4(
816
+ AddExchangeInboundItemsTable,
817
+ {
818
+ items: order.items ?? [],
819
+ selectedItems: inboundItems.map((i) => i.item_id),
820
+ currencyCode: order.currency_code,
821
+ onSelectionChange: (finalSelection) => {
822
+ const alreadySelected = inboundItems.map((i) => i.item_id);
823
+ itemsToAdd = finalSelection.filter(
824
+ (selection) => !alreadySelected.includes(selection)
825
+ );
826
+ itemsToRemove = alreadySelected.filter(
827
+ (selection) => !finalSelection.includes(selection)
828
+ );
829
+ }
830
+ }
831
+ ),
832
+ /* @__PURE__ */ jsx4(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsx4("div", { className: "flex w-full items-center justify-end gap-x-4", children: /* @__PURE__ */ jsxs2("div", { className: "flex items-center justify-end gap-x-2", children: [
833
+ /* @__PURE__ */ jsx4(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx4(Button, { type: "button", variant: "secondary", size: "small", children: t("actions.cancel") }) }),
834
+ /* @__PURE__ */ jsx4(
835
+ Button,
836
+ {
837
+ type: "submit",
838
+ variant: "primary",
839
+ size: "small",
840
+ onClick: async () => await onItemsSelected(),
841
+ children: t("actions.save")
842
+ },
843
+ "submit-button"
844
+ )
845
+ ] }) }) })
846
+ ] })
847
+ ] })
848
+ ] }),
849
+ showInboundItemsPlaceholder && /* @__PURE__ */ jsx4(ItemPlaceholder, {}),
850
+ inboundItems.map((item, index) => {
851
+ const previewItem = inboundItemsMap.get(item.item_id);
852
+ const sourceItem = itemsMap.get(item.item_id);
853
+ if (!previewItem || !sourceItem) {
854
+ return null;
855
+ }
856
+ const locationName = stock_locations.find(
857
+ (l) => l.id === locationId
858
+ )?.name ?? null;
859
+ return /* @__PURE__ */ jsx4(
860
+ ExchangeInboundItem,
861
+ {
862
+ item: sourceItem,
863
+ previewItem,
864
+ currencyCode: order.currency_code,
865
+ form,
866
+ locationName,
867
+ onRemove: () => {
868
+ const actionId = previewInboundItems.find((i) => i.id === item.item_id)?.actions?.find((a) => a.action === "RETURN_ITEM")?.id;
869
+ if (actionId) {
870
+ removeInboundItem(actionId, {
871
+ onError: (error) => {
872
+ toast.error(error.message);
873
+ }
874
+ });
875
+ }
876
+ },
877
+ onUpdate: (payload) => {
878
+ const action = previewInboundItems.find((i) => i.id === item.item_id)?.actions?.find((a) => a.action === "RETURN_ITEM");
879
+ if (action?.id) {
880
+ updateInboundItem(
881
+ { $actionId: action.id, ...payload },
882
+ {
883
+ onError: (error) => {
884
+ if (action.details?.quantity && payload.quantity) {
885
+ form.setValue(
886
+ `inbound_items.${index}.quantity`,
887
+ action.details.quantity
888
+ );
889
+ }
890
+ toast.error(error.message);
891
+ }
892
+ }
893
+ );
894
+ }
895
+ },
896
+ index
897
+ },
898
+ item.id
899
+ );
900
+ }),
901
+ !showInboundItemsPlaceholder && /* @__PURE__ */ jsxs2("div", { className: "mt-8 flex flex-col gap-y-4", children: [
902
+ /* @__PURE__ */ jsxs2("div", { className: "grid grid-cols-1 gap-2 md:grid-cols-2", children: [
903
+ /* @__PURE__ */ jsxs2("div", { children: [
904
+ /* @__PURE__ */ jsx4(Form.Label, { children: t("orders.returns.location") }),
905
+ /* @__PURE__ */ jsx4(Form.Hint, { className: "!mt-1", children: t("orders.returns.locationHint") })
906
+ ] }),
907
+ /* @__PURE__ */ jsx4(
908
+ Form.Field,
909
+ {
910
+ control: form.control,
911
+ name: "location_id",
912
+ render: ({ field: { value, onChange, ...field } }) => {
913
+ return /* @__PURE__ */ jsx4(Form.Item, { children: /* @__PURE__ */ jsx4(Form.Control, { children: /* @__PURE__ */ jsx4(
914
+ Combobox,
915
+ {
916
+ ...field,
917
+ value: value ?? void 0,
918
+ onChange: (v) => {
919
+ onChange(v);
920
+ onLocationChange(v);
921
+ },
922
+ options: stock_locations.map((stockLocation) => ({
923
+ label: stockLocation.name,
924
+ value: stockLocation.id
925
+ }))
926
+ }
927
+ ) }) });
928
+ }
929
+ }
930
+ )
931
+ ] }),
932
+ /* @__PURE__ */ jsxs2("div", { className: "grid grid-cols-1 gap-2 md:grid-cols-2", children: [
933
+ /* @__PURE__ */ jsxs2("div", { children: [
934
+ /* @__PURE__ */ jsxs2(Form.Label, { children: [
935
+ t("orders.returns.inboundShipping"),
936
+ /* @__PURE__ */ jsxs2(
937
+ Text2,
938
+ {
939
+ size: "small",
940
+ leading: "compact",
941
+ className: "text-ui-fg-muted ml-1 inline",
942
+ children: [
943
+ "(",
944
+ t("fields.optional"),
945
+ ")"
946
+ ]
947
+ }
948
+ )
949
+ ] }),
950
+ /* @__PURE__ */ jsx4(Form.Hint, { className: "!mt-1", children: t("orders.returns.inboundShippingHint") })
951
+ ] }),
952
+ /* @__PURE__ */ jsx4(
953
+ Form.Field,
954
+ {
955
+ control: form.control,
956
+ name: "inbound_option_id",
957
+ render: ({ field: { value, onChange, ...field } }) => {
958
+ return /* @__PURE__ */ jsx4(Form.Item, { children: /* @__PURE__ */ jsx4(Form.Control, { children: /* @__PURE__ */ jsx4(
959
+ Combobox,
960
+ {
961
+ allowClear: true,
962
+ value: value ?? void 0,
963
+ onChange: (val) => {
964
+ onChange(val);
965
+ onShippingOptionChange(val);
966
+ },
967
+ ...field,
968
+ options: inboundShippingOptions.map((so) => ({
969
+ label: so.name,
970
+ value: so.id
971
+ })),
972
+ disabled: !locationId
973
+ }
974
+ ) }) });
975
+ }
976
+ }
977
+ )
978
+ ] })
979
+ ] })
980
+ ] });
981
+ };
982
+
983
+ // src/pages/orders/[id]/exchanges/create/_components/exchange-create-form/exchange-outbound-section.tsx
984
+ import { Button as Button2, Heading as Heading2, toast as toast2 } from "@medusajs/ui";
985
+ import { useEffect as useEffect2, useMemo as useMemo6 } from "react";
986
+ import { useFieldArray as useFieldArray2 } from "react-hook-form";
987
+ import { useTranslation as useTranslation10 } from "react-i18next";
988
+
989
+ // src/pages/orders/[id]/exchanges/create/_components/add-exchange-outbound-items-table/add-exchange-outbound-items-table.tsx
990
+ import { useMemo as useMemo5, useState as useState2 } from "react";
991
+ import { useTranslation as useTranslation8 } from "react-i18next";
992
+
993
+ // src/pages/orders/[id]/exchanges/create/_components/add-exchange-outbound-items-table/use-exchange-outbound-item-table-columns.tsx
994
+ import { Checkbox as Checkbox2, Text as Text3 } from "@medusajs/ui";
995
+ import { createColumnHelper as createColumnHelper2 } from "@tanstack/react-table";
996
+ import { useMemo as useMemo4 } from "react";
997
+ import { useTranslation as useTranslation6 } from "react-i18next";
998
+ import { jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
999
+ var columnHelper2 = createColumnHelper2();
1000
+ var useExchangeOutboundItemTableColumns = () => {
1001
+ const { t } = useTranslation6();
1002
+ return useMemo4(
1003
+ () => [
1004
+ columnHelper2.display({
1005
+ id: "select",
1006
+ header: ({ table }) => /* @__PURE__ */ jsx5(
1007
+ Checkbox2,
1008
+ {
1009
+ checked: table.getIsSomePageRowsSelected() ? "indeterminate" : table.getIsAllPageRowsSelected(),
1010
+ onCheckedChange: (value) => table.toggleAllPageRowsSelected(!!value)
1011
+ }
1012
+ ),
1013
+ cell: ({ row }) => {
1014
+ const isSelectable = row.getCanSelect();
1015
+ return /* @__PURE__ */ jsx5(
1016
+ Checkbox2,
1017
+ {
1018
+ disabled: !isSelectable,
1019
+ checked: row.getIsSelected(),
1020
+ onCheckedChange: (value) => row.toggleSelected(!!value),
1021
+ onClick: (e) => {
1022
+ e.stopPropagation();
1023
+ }
1024
+ }
1025
+ );
1026
+ }
1027
+ }),
1028
+ columnHelper2.display({
1029
+ id: "product",
1030
+ header: t("fields.product"),
1031
+ cell: ({ row }) => {
1032
+ const variant = row.original.product_variant;
1033
+ const productTitle = variant?.product?.title;
1034
+ if (!productTitle) {
1035
+ return /* @__PURE__ */ jsx5(PlaceholderCell, {});
1036
+ }
1037
+ return /* @__PURE__ */ jsxs3("div", { className: "flex h-full w-full max-w-[300px] items-center gap-x-3 overflow-hidden", children: [
1038
+ /* @__PURE__ */ jsx5(Thumbnail, { src: variant?.product?.thumbnail }),
1039
+ /* @__PURE__ */ jsx5(
1040
+ Text3,
1041
+ {
1042
+ size: "small",
1043
+ leading: "compact",
1044
+ className: "truncate",
1045
+ title: productTitle,
1046
+ children: productTitle
1047
+ }
1048
+ )
1049
+ ] });
1050
+ }
1051
+ }),
1052
+ columnHelper2.accessor("sku", {
1053
+ header: t("fields.sku"),
1054
+ cell: ({ getValue }) => {
1055
+ const sku = getValue();
1056
+ if (!sku) return /* @__PURE__ */ jsx5(PlaceholderCell, {});
1057
+ return /* @__PURE__ */ jsx5(Text3, { size: "small", leading: "compact", className: "truncate", children: sku });
1058
+ }
1059
+ }),
1060
+ columnHelper2.display({
1061
+ id: "variant_title",
1062
+ header: t("fields.title"),
1063
+ cell: ({ row }) => {
1064
+ const title = row.original.product_variant?.title;
1065
+ if (!title) return /* @__PURE__ */ jsx5(PlaceholderCell, {});
1066
+ return /* @__PURE__ */ jsx5(Text3, { size: "small", leading: "compact", className: "truncate", children: title });
1067
+ }
1068
+ })
1069
+ ],
1070
+ [t]
1071
+ );
1072
+ };
1073
+
1074
+ // src/pages/orders/[id]/exchanges/create/_components/add-exchange-outbound-items-table/use-exchange-outbound-item-table-filters.tsx
1075
+ import { useTranslation as useTranslation7 } from "react-i18next";
1076
+ var useExchangeOutboundItemTableFilters = () => {
1077
+ const { t } = useTranslation7();
1078
+ const filters = [
1079
+ {
1080
+ key: "created_at",
1081
+ label: t("fields.createdAt"),
1082
+ type: "date"
1083
+ },
1084
+ {
1085
+ key: "updated_at",
1086
+ label: t("fields.updatedAt"),
1087
+ type: "date"
1088
+ }
1089
+ ];
1090
+ return filters;
1091
+ };
1092
+
1093
+ // src/pages/orders/[id]/exchanges/create/_components/add-exchange-outbound-items-table/use-exchange-outbound-item-table-query.tsx
1094
+ var useExchangeOutboundItemTableQuery = ({
1095
+ pageSize = 50,
1096
+ prefix
1097
+ }) => {
1098
+ const raw = useQueryParams(
1099
+ ["q", "offset", "order", "created_at", "updated_at"],
1100
+ prefix
1101
+ );
1102
+ const { offset, created_at, updated_at, ...rest } = raw;
1103
+ const searchParams = {
1104
+ ...rest,
1105
+ limit: pageSize,
1106
+ offset: offset ? Number(offset) : 0,
1107
+ created_at: created_at ? JSON.parse(created_at) : void 0,
1108
+ updated_at: updated_at ? JSON.parse(updated_at) : void 0
1109
+ };
1110
+ return { searchParams, raw };
1111
+ };
1112
+
1113
+ // src/pages/orders/[id]/exchanges/create/_components/add-exchange-outbound-items-table/add-exchange-outbound-items-table.tsx
1114
+ import { jsx as jsx6 } from "react/jsx-runtime";
1115
+ var PAGE_SIZE2 = 50;
1116
+ var PREFIX2 = "rit";
1117
+ var OFFER_PICKER_FIELDS = [
1118
+ "id",
1119
+ "sku",
1120
+ "variant_id",
1121
+ "seller_id",
1122
+ "prices.amount",
1123
+ "prices.currency_code",
1124
+ "product_variant.id",
1125
+ "product_variant.title",
1126
+ "product_variant.product.id",
1127
+ "product_variant.product.title",
1128
+ "product_variant.product.thumbnail",
1129
+ "product_variant.manage_inventory",
1130
+ "product_variant.inventory_quantity",
1131
+ "product_variant.inventory_items.required_quantity",
1132
+ "product_variant.inventory_items.inventory.location_levels.available_quantity"
1133
+ ].join(",");
1134
+ var offerHasInventory = (offer) => {
1135
+ const variant = offer.product_variant;
1136
+ if (!variant) return false;
1137
+ if (variant.manage_inventory === false) return true;
1138
+ const links = variant.inventory_items ?? [];
1139
+ if (!links.length) {
1140
+ return (variant.inventory_quantity ?? 0) > 0;
1141
+ }
1142
+ return links.every((link) => {
1143
+ const available = (link.inventory?.location_levels ?? []).reduce(
1144
+ (acc, lvl) => acc + (lvl.available_quantity ?? 0),
1145
+ 0
1146
+ );
1147
+ const required = link.required_quantity ?? 1;
1148
+ return required > 0 && available >= required;
1149
+ });
1150
+ };
1151
+ var AddExchangeOutboundItemsTable = ({
1152
+ currencyCode,
1153
+ onSelectionChange,
1154
+ selectedItems = []
1155
+ }) => {
1156
+ const { t } = useTranslation8();
1157
+ const [rowSelection, setRowSelection] = useState2(
1158
+ selectedItems.reduce((acc, id) => {
1159
+ acc[id] = true;
1160
+ return acc;
1161
+ }, {})
1162
+ );
1163
+ const updater = (fn) => {
1164
+ const newState = typeof fn === "function" ? fn(rowSelection) : fn;
1165
+ setRowSelection(newState);
1166
+ onSelectionChange(Object.keys(newState));
1167
+ };
1168
+ const { searchParams, raw } = useExchangeOutboundItemTableQuery({
1169
+ pageSize: PAGE_SIZE2,
1170
+ prefix: PREFIX2
1171
+ });
1172
+ const offersResponse = useOffers({
1173
+ ...searchParams,
1174
+ fields: OFFER_PICKER_FIELDS
1175
+ });
1176
+ const rawOffers = useMemo5(
1177
+ () => offersResponse.offers ?? [],
1178
+ [offersResponse.offers]
1179
+ );
1180
+ const rawCount = offersResponse.count ?? 0;
1181
+ const offers = useMemo5(() => {
1182
+ return rawOffers.filter((offer) => {
1183
+ if (currencyCode) {
1184
+ const hasPrice = (offer.prices ?? []).some(
1185
+ (p) => p.currency_code === currencyCode
1186
+ );
1187
+ if (!hasPrice) return false;
1188
+ }
1189
+ return offerHasInventory(offer);
1190
+ });
1191
+ }, [rawOffers, currencyCode]);
1192
+ const count = offers.length;
1193
+ void rawCount;
1194
+ const columns = useExchangeOutboundItemTableColumns();
1195
+ const filters = useExchangeOutboundItemTableFilters();
1196
+ const { table } = useDataTable({
1197
+ data: offers,
1198
+ columns,
1199
+ count,
1200
+ enablePagination: true,
1201
+ // Row id = offer id so onSelectionChange yields offer_ids that the
1202
+ // modal layer sends to the backend item-add routes (which accept
1203
+ // `offer_id` and resolve to variant_id + unit_price server-side).
1204
+ getRowId: (row) => row.id,
1205
+ pageSize: PAGE_SIZE2,
1206
+ enableRowSelection: () => true,
1207
+ rowSelection: {
1208
+ state: rowSelection,
1209
+ updater
1210
+ }
1211
+ });
1212
+ return /* @__PURE__ */ jsx6(
1213
+ "div",
1214
+ {
1215
+ className: "flex size-full flex-col overflow-hidden",
1216
+ "data-testid": "add-offers-picker",
1217
+ children: /* @__PURE__ */ jsx6(
1218
+ _DataTable,
1219
+ {
1220
+ table,
1221
+ columns,
1222
+ pageSize: PAGE_SIZE2,
1223
+ count,
1224
+ filters,
1225
+ pagination: true,
1226
+ layout: "fill",
1227
+ search: true,
1228
+ orderBy: [
1229
+ { key: "sku", label: t("fields.sku") },
1230
+ { key: "created_at", label: t("fields.createdAt") },
1231
+ { key: "updated_at", label: t("fields.updatedAt") }
1232
+ ],
1233
+ prefix: PREFIX2,
1234
+ queryObject: raw
1235
+ }
1236
+ )
1237
+ }
1238
+ );
1239
+ };
1240
+
1241
+ // src/pages/orders/[id]/exchanges/create/_components/exchange-create-form/exchange-outbound-item.tsx
1242
+ import { XCircle as XCircle2 } from "@medusajs/icons";
1243
+ import { Input as Input2, Text as Text4 } from "@medusajs/ui";
1244
+ import { useTranslation as useTranslation9 } from "react-i18next";
1245
+ import { jsx as jsx7, jsxs as jsxs4 } from "react/jsx-runtime";
1246
+ function ExchangeOutboundItem({
1247
+ previewItem,
1248
+ currencyCode,
1249
+ form,
1250
+ onRemove,
1251
+ onUpdate,
1252
+ index
1253
+ }) {
1254
+ const { t } = useTranslation9();
1255
+ const appliedPromoCodes = (previewItem.adjustments ?? []).map((adjustment) => adjustment.code).filter((code) => Boolean(code));
1256
+ return /* @__PURE__ */ jsx7(
1257
+ "div",
1258
+ {
1259
+ className: "bg-ui-bg-subtle shadow-elevation-card-rest my-2 rounded-xl",
1260
+ "data-testid": `exchange-outbound-item-${previewItem.id}`,
1261
+ children: /* @__PURE__ */ jsxs4("div", { className: "flex flex-col items-center gap-x-3 gap-y-2 p-3 text-sm md:flex-row", children: [
1262
+ /* @__PURE__ */ jsxs4("div", { className: "flex flex-1 items-center gap-x-3", children: [
1263
+ /* @__PURE__ */ jsx7(Thumbnail, { src: previewItem.thumbnail ?? void 0 }),
1264
+ /* @__PURE__ */ jsxs4("div", { className: "flex flex-grow flex-col", children: [
1265
+ /* @__PURE__ */ jsxs4("div", { children: [
1266
+ /* @__PURE__ */ jsxs4(Text4, { className: "txt-small", as: "span", weight: "plus", children: [
1267
+ previewItem.title,
1268
+ " "
1269
+ ] }),
1270
+ previewItem.variant_sku && /* @__PURE__ */ jsxs4("span", { children: [
1271
+ "(",
1272
+ previewItem.variant_sku,
1273
+ ")"
1274
+ ] })
1275
+ ] }),
1276
+ /* @__PURE__ */ jsx7(Text4, { as: "div", className: "text-ui-fg-subtle txt-small", children: previewItem.subtitle ?? previewItem.variant_title ?? "" })
1277
+ ] }),
1278
+ appliedPromoCodes.length > 0 && /* @__PURE__ */ jsx7(
1279
+ "div",
1280
+ {
1281
+ className: "flex flex-shrink",
1282
+ title: appliedPromoCodes.join(", ")
1283
+ }
1284
+ )
1285
+ ] }),
1286
+ /* @__PURE__ */ jsxs4("div", { className: "flex flex-1 justify-between", children: [
1287
+ /* @__PURE__ */ jsxs4("div", { className: "flex flex-grow items-center gap-2", children: [
1288
+ /* @__PURE__ */ jsx7(
1289
+ Form.Field,
1290
+ {
1291
+ control: form.control,
1292
+ name: `outbound_items.${index}.quantity`,
1293
+ render: ({ field }) => {
1294
+ return /* @__PURE__ */ jsxs4(Form.Item, { children: [
1295
+ /* @__PURE__ */ jsx7(Form.Control, { children: /* @__PURE__ */ jsx7(
1296
+ Input2,
1297
+ {
1298
+ ...field,
1299
+ className: "bg-ui-bg-base txt-small w-[67px] rounded-lg",
1300
+ min: 1,
1301
+ type: "number",
1302
+ "data-testid": `exchange-outbound-item-${previewItem.id}-qty`,
1303
+ onBlur: (e) => {
1304
+ const val = e.target.value;
1305
+ const payload = val === "" ? null : Number(val);
1306
+ field.onChange(payload);
1307
+ if (payload) {
1308
+ onUpdate({ quantity: payload });
1309
+ }
1310
+ }
1311
+ }
1312
+ ) }),
1313
+ /* @__PURE__ */ jsx7(Form.ErrorMessage, {})
1314
+ ] });
1315
+ }
1316
+ }
1317
+ ),
1318
+ /* @__PURE__ */ jsx7(Text4, { className: "txt-small text-ui-fg-subtle", children: t("fields.qty") })
1319
+ ] }),
1320
+ /* @__PURE__ */ jsx7("div", { className: "text-ui-fg-subtle txt-small mr-2 flex flex-shrink-0", children: /* @__PURE__ */ jsx7(
1321
+ MoneyAmountCell,
1322
+ {
1323
+ currencyCode,
1324
+ amount: previewItem.total ?? 0
1325
+ }
1326
+ ) }),
1327
+ /* @__PURE__ */ jsx7(
1328
+ ActionMenu,
1329
+ {
1330
+ groups: [
1331
+ {
1332
+ actions: [
1333
+ {
1334
+ label: t("actions.remove"),
1335
+ onClick: onRemove,
1336
+ icon: /* @__PURE__ */ jsx7(XCircle2, {})
1337
+ }
1338
+ ]
1339
+ }
1340
+ ]
1341
+ }
1342
+ )
1343
+ ] })
1344
+ ] })
1345
+ }
1346
+ );
1347
+ }
1348
+
1349
+ // src/pages/orders/[id]/exchanges/create/_components/exchange-create-form/exchange-outbound-section.tsx
1350
+ import { jsx as jsx8, jsxs as jsxs5 } from "react/jsx-runtime";
1351
+ var offersToAdd = [];
1352
+ var offersToRemove = [];
1353
+ var ExchangeOutboundSection = ({
1354
+ order,
1355
+ preview,
1356
+ exchange,
1357
+ form
1358
+ }) => {
1359
+ const { t } = useTranslation10();
1360
+ const { setIsOpen } = useStackedModal();
1361
+ const { mutateAsync: addOutboundShipping } = useAddExchangeOutboundShipping(
1362
+ exchange.id,
1363
+ order.id
1364
+ );
1365
+ const { mutateAsync: addOutboundItem } = useAddExchangeOutboundItems(
1366
+ exchange.id,
1367
+ order.id
1368
+ );
1369
+ const { mutateAsync: updateOutboundItem } = useUpdateExchangeOutboundItem(
1370
+ exchange.id,
1371
+ order.id
1372
+ );
1373
+ const { mutateAsync: removeOutboundItem } = useRemoveExchangeOutboundItem(
1374
+ exchange.id,
1375
+ order.id
1376
+ );
1377
+ const previewOutboundItems = useMemo6(
1378
+ () => (preview?.items ?? []).filter(
1379
+ (i) => !!i.actions?.find(
1380
+ (a) => a.exchange_id === exchange.id && a.action === "ITEM_ADD"
1381
+ )
1382
+ ),
1383
+ [preview.items, exchange.id]
1384
+ );
1385
+ const {
1386
+ fields: outboundItems,
1387
+ append,
1388
+ remove,
1389
+ update
1390
+ } = useFieldArray2({
1391
+ name: "outbound_items",
1392
+ control: form.control
1393
+ });
1394
+ const previewItemsMap = useMemo6(
1395
+ () => new Map(previewOutboundItems.map((i) => [i.id, i])),
1396
+ [previewOutboundItems]
1397
+ );
1398
+ useEffect2(() => {
1399
+ const existingItemsMap = {};
1400
+ previewOutboundItems.forEach((i) => {
1401
+ const ind = outboundItems.findIndex((field) => field.item_id === i.id);
1402
+ const requested = i.detail?.quantity ?? 0;
1403
+ existingItemsMap[i.id] = true;
1404
+ if (ind > -1) {
1405
+ if (outboundItems[ind].quantity !== requested) {
1406
+ update(ind, {
1407
+ ...outboundItems[ind],
1408
+ quantity: requested
1409
+ });
1410
+ }
1411
+ } else {
1412
+ append(
1413
+ {
1414
+ item_id: i.id,
1415
+ quantity: requested,
1416
+ variant_id: i.variant_id ?? void 0
1417
+ },
1418
+ { shouldFocus: false }
1419
+ );
1420
+ }
1421
+ });
1422
+ outboundItems.forEach((i, ind) => {
1423
+ if (!(i.item_id in existingItemsMap)) {
1424
+ remove(ind);
1425
+ }
1426
+ });
1427
+ }, [previewOutboundItems]);
1428
+ const showOutboundItemsPlaceholder = !outboundItems.length;
1429
+ const onItemsSelected = async () => {
1430
+ if (offersToAdd.length) {
1431
+ await addOutboundItem(
1432
+ {
1433
+ // Vendor route resolves `offer_id` server-side.
1434
+ items: offersToAdd.map((offer_id) => ({
1435
+ offer_id,
1436
+ quantity: 1
1437
+ }))
1438
+ },
1439
+ {
1440
+ onError: (error) => {
1441
+ toast2.error(error.message);
1442
+ }
1443
+ }
1444
+ );
1445
+ }
1446
+ for (const offerToRemove of offersToRemove) {
1447
+ const field = outboundItems.find(
1448
+ (f) => f.offer_id === offerToRemove
1449
+ );
1450
+ const previewMatch = field ? previewOutboundItems.find((i) => i.id === field.item_id) : void 0;
1451
+ const actionId = previewMatch?.actions?.find(
1452
+ (a) => a.action === "ITEM_ADD"
1453
+ )?.id;
1454
+ if (actionId) {
1455
+ await removeOutboundItem(actionId, {
1456
+ onError: (error) => {
1457
+ toast2.error(error.message);
1458
+ }
1459
+ });
1460
+ }
1461
+ }
1462
+ setIsOpen("outbound-items", false);
1463
+ };
1464
+ useEffect2(() => {
1465
+ const outboundShipping = (preview.shipping_methods ?? []).find(
1466
+ (s) => !!s.actions?.find((a) => a.action === "SHIPPING_ADD" && !a.return_id)
1467
+ );
1468
+ if (outboundShipping?.shipping_option_id) {
1469
+ form.setValue("outbound_option_id", outboundShipping.shipping_option_id);
1470
+ } else {
1471
+ form.setValue("outbound_option_id", "");
1472
+ }
1473
+ }, [preview.shipping_methods]);
1474
+ const onShippingOptionChange = async (selectedOptionId) => {
1475
+ if (selectedOptionId) {
1476
+ await addOutboundShipping(
1477
+ { shipping_option_id: selectedOptionId },
1478
+ {
1479
+ onError: (error) => {
1480
+ toast2.error(error.message);
1481
+ }
1482
+ }
1483
+ );
1484
+ }
1485
+ };
1486
+ return /* @__PURE__ */ jsxs5("div", { children: [
1487
+ /* @__PURE__ */ jsxs5("div", { className: "mt-8 flex items-center justify-between", children: [
1488
+ /* @__PURE__ */ jsx8(Heading2, { level: "h2", children: t("orders.returns.outbound") }),
1489
+ /* @__PURE__ */ jsxs5(StackedFocusModal, { id: "outbound-items", children: [
1490
+ /* @__PURE__ */ jsx8(StackedFocusModal.Trigger, { asChild: true, children: /* @__PURE__ */ jsx8(
1491
+ "a",
1492
+ {
1493
+ href: "#",
1494
+ onClick: (e) => e.preventDefault(),
1495
+ className: "focus-visible:shadow-borders-focus transition-fg txt-compact-small-plus cursor-pointer text-blue-500 outline-none hover:text-blue-400",
1496
+ children: t("actions.addItems")
1497
+ }
1498
+ ) }),
1499
+ /* @__PURE__ */ jsxs5(StackedFocusModal.Content, { children: [
1500
+ /* @__PURE__ */ jsx8(StackedFocusModal.Header, {}),
1501
+ /* @__PURE__ */ jsx8(
1502
+ AddExchangeOutboundItemsTable,
1503
+ {
1504
+ selectedItems: outboundItems.map((i) => i.offer_id).filter(Boolean),
1505
+ currencyCode: order.currency_code,
1506
+ onSelectionChange: (finalSelection) => {
1507
+ const alreadySelected = outboundItems.map((i) => i.offer_id).filter(Boolean);
1508
+ offersToAdd = finalSelection.filter(
1509
+ (selection) => !alreadySelected.includes(selection)
1510
+ );
1511
+ offersToRemove = alreadySelected.filter(
1512
+ (selection) => !finalSelection.includes(selection)
1513
+ );
1514
+ }
1515
+ }
1516
+ ),
1517
+ /* @__PURE__ */ jsx8(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsx8("div", { className: "flex w-full items-center justify-end gap-x-4", children: /* @__PURE__ */ jsxs5("div", { className: "flex items-center justify-end gap-x-2", children: [
1518
+ /* @__PURE__ */ jsx8(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx8(Button2, { type: "button", variant: "secondary", size: "small", children: t("actions.cancel") }) }),
1519
+ /* @__PURE__ */ jsx8(
1520
+ Button2,
1521
+ {
1522
+ type: "submit",
1523
+ variant: "primary",
1524
+ size: "small",
1525
+ onClick: async () => await onItemsSelected(),
1526
+ children: t("actions.save")
1527
+ },
1528
+ "submit-button"
1529
+ )
1530
+ ] }) }) })
1531
+ ] })
1532
+ ] })
1533
+ ] }),
1534
+ showOutboundItemsPlaceholder && /* @__PURE__ */ jsx8(ItemPlaceholder, {}),
1535
+ outboundItems.map((item, index) => {
1536
+ const previewItem = previewItemsMap.get(item.item_id);
1537
+ if (!previewItem) {
1538
+ return null;
1539
+ }
1540
+ return /* @__PURE__ */ jsx8(
1541
+ ExchangeOutboundItem,
1542
+ {
1543
+ previewItem,
1544
+ currencyCode: order.currency_code,
1545
+ form,
1546
+ onRemove: () => {
1547
+ const actionId = previewOutboundItems.find((i) => i.id === item.item_id)?.actions?.find((a) => a.action === "ITEM_ADD")?.id;
1548
+ if (actionId) {
1549
+ removeOutboundItem(actionId, {
1550
+ onError: (error) => {
1551
+ toast2.error(error.message);
1552
+ }
1553
+ });
1554
+ }
1555
+ },
1556
+ onUpdate: (payload) => {
1557
+ const actionId = previewOutboundItems.find((i) => i.id === item.item_id)?.actions?.find((a) => a.action === "ITEM_ADD")?.id;
1558
+ if (actionId) {
1559
+ updateOutboundItem(
1560
+ { $actionId: actionId, ...payload },
1561
+ {
1562
+ onError: (error) => {
1563
+ toast2.error(error.message);
1564
+ }
1565
+ }
1566
+ );
1567
+ }
1568
+ },
1569
+ index
1570
+ },
1571
+ item.id
1572
+ );
1573
+ }),
1574
+ !showOutboundItemsPlaceholder && /* @__PURE__ */ jsx8("div", { className: "mt-8 flex flex-col gap-y-4", children: /* @__PURE__ */ jsxs5("div", { className: "grid grid-cols-1 gap-2 md:grid-cols-2", children: [
1575
+ /* @__PURE__ */ jsxs5("div", { children: [
1576
+ /* @__PURE__ */ jsx8(Form.Label, { children: t("orders.exchanges.outboundShipping") }),
1577
+ /* @__PURE__ */ jsx8(Form.Hint, { className: "!mt-1", children: t("orders.exchanges.outboundShippingHint") })
1578
+ ] }),
1579
+ /* @__PURE__ */ jsx8(
1580
+ Form.Field,
1581
+ {
1582
+ control: form.control,
1583
+ name: "outbound_option_id",
1584
+ render: ({ field: { value, onChange, ...field } }) => {
1585
+ return /* @__PURE__ */ jsx8(Form.Item, { children: /* @__PURE__ */ jsx8(Form.Control, { children: /* @__PURE__ */ jsx8(
1586
+ Combobox,
1587
+ {
1588
+ allowClear: true,
1589
+ value: value ?? void 0,
1590
+ onChange: (val) => {
1591
+ onChange(val);
1592
+ onShippingOptionChange(val);
1593
+ },
1594
+ ...field,
1595
+ options: [],
1596
+ disabled: true
1597
+ }
1598
+ ) }) });
1599
+ }
1600
+ }
1601
+ )
1602
+ ] }) })
1603
+ ] });
1604
+ };
1605
+
1606
+ // src/pages/orders/[id]/exchanges/create/_components/exchange-create-form/schema.ts
1607
+ import { z } from "zod";
1608
+ var ExchangeCreateSchema = z.object({
1609
+ inbound_items: z.array(
1610
+ z.object({
1611
+ item_id: z.string(),
1612
+ variant_id: z.string().nullish(),
1613
+ quantity: z.number(),
1614
+ reason_id: z.string().nullish(),
1615
+ note: z.string().nullish()
1616
+ })
1617
+ ),
1618
+ outbound_items: z.array(
1619
+ z.object({
1620
+ item_id: z.string(),
1621
+ offer_id: z.string().nullish(),
1622
+ variant_id: z.string().nullish(),
1623
+ quantity: z.number()
1624
+ })
1625
+ ),
1626
+ location_id: z.string().optional(),
1627
+ inbound_option_id: z.string().nullish(),
1628
+ outbound_option_id: z.string().nullish(),
1629
+ send_notification: z.boolean().optional()
1630
+ });
1631
+
1632
+ // src/pages/orders/[id]/exchanges/create/_components/exchange-create-form/exchange-create-form.tsx
1633
+ import { Fragment, jsx as jsx9, jsxs as jsxs6 } from "react/jsx-runtime";
1634
+ var readExchangeId = (change) => {
1635
+ if (change && typeof change === "object" && "exchange_id" in change && typeof change.exchange_id === "string") {
1636
+ return change.exchange_id;
1637
+ }
1638
+ return void 0;
1639
+ };
1640
+ var IS_REQUEST_RUNNING = false;
1641
+ var ExchangeCreateForm = () => {
1642
+ const { id } = useParams();
1643
+ const { t } = useTranslation11();
1644
+ const navigate = useNavigate();
1645
+ const { handleSuccess } = useRouteModal();
1646
+ const orderId = id ?? "";
1647
+ const { order } = useOrder(orderId, {
1648
+ fields: "currency_code,total,items.*,items.variant.*"
1649
+ });
1650
+ const { order: preview } = useOrderPreview(orderId);
1651
+ const [exchangeId, setExchangeId] = useState3("");
1652
+ const [submitting, setSubmitting] = useState3(false);
1653
+ const [canceling, setCanceling] = useState3(false);
1654
+ const form = useForm({
1655
+ defaultValues: {
1656
+ inbound_items: [],
1657
+ outbound_items: [],
1658
+ location_id: void 0,
1659
+ inbound_option_id: null,
1660
+ outbound_option_id: null,
1661
+ send_notification: false
1662
+ },
1663
+ resolver: zodResolver(ExchangeCreateSchema)
1664
+ });
1665
+ const { mutateAsync: createExchange } = useCreateExchange(orderId);
1666
+ const { mutateAsync: cancelBegin } = useCancelExchangeBegin(
1667
+ exchangeId,
1668
+ orderId
1669
+ );
1670
+ const { mutateAsync: requestExchange, isPending: isConfirming } = useRequestExchange(exchangeId, orderId);
1671
+ useEffect3(() => {
1672
+ async function run() {
1673
+ if (IS_REQUEST_RUNNING || exchangeId || !preview) {
1674
+ return;
1675
+ }
1676
+ if (preview.order_change) {
1677
+ if (preview.order_change.change_type !== "exchange") {
1678
+ navigate(`/orders/${orderId}`, { replace: true });
1679
+ toast3.error(t("orders.exchanges.activeChangeError"));
1680
+ return;
1681
+ }
1682
+ const existingExchangeId = readExchangeId(preview.order_change);
1683
+ if (existingExchangeId) {
1684
+ setExchangeId(existingExchangeId);
1685
+ }
1686
+ return;
1687
+ }
1688
+ IS_REQUEST_RUNNING = true;
1689
+ try {
1690
+ const { exchange } = await createExchange({ order_id: orderId });
1691
+ setExchangeId(exchange.id);
1692
+ } catch (e) {
1693
+ toast3.error(
1694
+ e instanceof Error ? e.message : t("errorBoundary.defaultTitle")
1695
+ );
1696
+ navigate(`/orders/${orderId}`, { replace: true });
1697
+ } finally {
1698
+ IS_REQUEST_RUNNING = false;
1699
+ }
1700
+ }
1701
+ run();
1702
+ }, [preview, orderId, exchangeId]);
1703
+ const inboundItemsWatch = form.watch("inbound_items");
1704
+ const outboundItemsWatch = form.watch("outbound_items");
1705
+ const hasSelection = useMemo7(
1706
+ () => (inboundItemsWatch?.length ?? 0) > 0 || (outboundItemsWatch?.length ?? 0) > 0,
1707
+ [inboundItemsWatch, outboundItemsWatch]
1708
+ );
1709
+ const previewItems = useMemo7(() => {
1710
+ if (!exchangeId) return [];
1711
+ return (preview?.items ?? []).filter(
1712
+ (i) => !!i.actions?.find((a) => a.exchange_id === exchangeId)
1713
+ );
1714
+ }, [preview, exchangeId]);
1715
+ const inboundPreviewItems = useMemo7(
1716
+ () => previewItems.filter(
1717
+ (item) => !!item.actions?.find((a) => a.action === "RETURN_ITEM")
1718
+ ),
1719
+ [previewItems]
1720
+ );
1721
+ const outboundPreviewItems = useMemo7(
1722
+ () => previewItems.filter(
1723
+ (item) => !!item.actions?.find((a) => a.action === "ITEM_ADD")
1724
+ ),
1725
+ [previewItems]
1726
+ );
1727
+ const currencyCode = order?.currency_code ?? "";
1728
+ const inboundTotal = useMemo7(() => {
1729
+ return inboundPreviewItems.reduce((acc, item) => {
1730
+ const action = item.actions?.find((a) => a.action === "RETURN_ITEM");
1731
+ const requested = Number(action?.details?.quantity || 0);
1732
+ const itemQty = item.quantity ?? 0;
1733
+ const itemTotal = item.total ?? 0;
1734
+ if (!itemQty) return acc;
1735
+ return acc + requested / itemQty * itemTotal;
1736
+ }, 0);
1737
+ }, [inboundPreviewItems]);
1738
+ const outboundTotal = useMemo7(() => {
1739
+ return outboundPreviewItems.reduce(
1740
+ (acc, item) => acc + (item.total ?? 0),
1741
+ 0
1742
+ );
1743
+ }, [outboundPreviewItems]);
1744
+ const inboundShippingTotal = useMemo7(() => {
1745
+ const methods = preview?.shipping_methods ?? [];
1746
+ const method = methods.find(
1747
+ (sm) => !!sm.actions?.find((a) => a.action === "SHIPPING_ADD" && !!a.return_id)
1748
+ );
1749
+ return method?.total ?? 0;
1750
+ }, [preview]);
1751
+ const outboundShippingTotal = useMemo7(() => {
1752
+ const methods = preview?.shipping_methods ?? [];
1753
+ const method = methods.find(
1754
+ (sm) => !!sm.actions?.find((a) => a.action === "SHIPPING_ADD" && !a.return_id)
1755
+ );
1756
+ return method?.total ?? 0;
1757
+ }, [preview]);
1758
+ const estimatedDifference = useMemo7(() => {
1759
+ const summary = preview?.summary;
1760
+ return (summary?.pending_difference ?? 0) - inboundTotal;
1761
+ }, [preview, inboundTotal]);
1762
+ const prompt = usePrompt();
1763
+ const handleSubmit = form.handleSubmit(async (data) => {
1764
+ if (!exchangeId) {
1765
+ return;
1766
+ }
1767
+ const res = await prompt({
1768
+ title: t("general.areYouSure"),
1769
+ description: t("orders.exchanges.confirmText"),
1770
+ confirmText: t("actions.continue"),
1771
+ cancelText: t("actions.cancel"),
1772
+ variant: "confirmation"
1773
+ });
1774
+ if (!res) {
1775
+ return;
1776
+ }
1777
+ setSubmitting(true);
1778
+ try {
1779
+ await requestExchange(
1780
+ { no_notification: !data.send_notification }
1781
+ );
1782
+ toast3.success(t("orders.exchanges.toast.confirmedSuccessfully"));
1783
+ handleSuccess(`/orders/${orderId}`);
1784
+ } catch (e) {
1785
+ toast3.error(t("general.error"), {
1786
+ description: e instanceof Error ? e.message : t("errorBoundary.defaultTitle")
1787
+ });
1788
+ } finally {
1789
+ setSubmitting(false);
1790
+ }
1791
+ });
1792
+ const handleClose = async () => {
1793
+ if (!exchangeId) {
1794
+ navigate(`/orders/${orderId}`, { replace: true });
1795
+ return;
1796
+ }
1797
+ setCanceling(true);
1798
+ try {
1799
+ await cancelBegin();
1800
+ toast3.success(t("orders.exchanges.toast.canceledSuccessfully"));
1801
+ } catch {
1802
+ } finally {
1803
+ setCanceling(false);
1804
+ navigate(`/orders/${orderId}`, { replace: true });
1805
+ }
1806
+ };
1807
+ const ready = !!order && !!preview && !!exchangeId;
1808
+ return /* @__PURE__ */ jsx9(RouteFocusModal.Form, { form, children: /* @__PURE__ */ jsxs6(KeyboundForm, { onSubmit: handleSubmit, className: "flex h-full flex-col", children: [
1809
+ /* @__PURE__ */ jsx9(RouteFocusModal.Header, {}),
1810
+ /* @__PURE__ */ jsx9(RouteFocusModal.Body, { className: "flex size-full justify-center overflow-y-auto", children: /* @__PURE__ */ jsxs6("div", { className: "mt-16 w-[720px] max-w-[100%] px-4 md:p-0", children: [
1811
+ /* @__PURE__ */ jsx9(Heading3, { level: "h1", children: t("orders.exchanges.create") }),
1812
+ /* @__PURE__ */ jsx9(Text5, { size: "small", className: "text-ui-fg-subtle mt-2", children: t("orders.exchanges.policyHint", {
1813
+ days: EXCHANGE_POLICY_DAYS
1814
+ }) }),
1815
+ ready && /* @__PURE__ */ jsxs6(Fragment, { children: [
1816
+ /* @__PURE__ */ jsx9(
1817
+ ExchangeInboundSection,
1818
+ {
1819
+ form,
1820
+ preview,
1821
+ order,
1822
+ exchange: { id: exchangeId }
1823
+ }
1824
+ ),
1825
+ /* @__PURE__ */ jsx9(
1826
+ ExchangeOutboundSection,
1827
+ {
1828
+ form,
1829
+ preview,
1830
+ order,
1831
+ exchange: { id: exchangeId }
1832
+ }
1833
+ ),
1834
+ /* @__PURE__ */ jsxs6("div", { className: "mt-8 border-y border-dotted py-4", children: [
1835
+ /* @__PURE__ */ jsxs6("div", { className: "mb-2 flex items-center justify-between", children: [
1836
+ /* @__PURE__ */ jsx9("span", { className: "txt-small text-ui-fg-subtle", children: t("orders.returns.inboundTotal") }),
1837
+ /* @__PURE__ */ jsx9("span", { className: "txt-small text-ui-fg-subtle", children: getStylizedAmount(-1 * inboundTotal, currencyCode) })
1838
+ ] }),
1839
+ /* @__PURE__ */ jsxs6("div", { className: "mb-2 flex items-center justify-between", children: [
1840
+ /* @__PURE__ */ jsx9("span", { className: "txt-small text-ui-fg-subtle", children: t("orders.exchanges.outboundTotal") }),
1841
+ /* @__PURE__ */ jsx9("span", { className: "txt-small text-ui-fg-subtle", children: getStylizedAmount(outboundTotal, currencyCode) })
1842
+ ] }),
1843
+ /* @__PURE__ */ jsxs6("div", { className: "mb-2 flex items-center justify-between", children: [
1844
+ /* @__PURE__ */ jsx9("span", { className: "txt-small text-ui-fg-subtle", children: t("orders.returns.inboundShipping") }),
1845
+ /* @__PURE__ */ jsx9("span", { className: "txt-small text-ui-fg-subtle", children: getStylizedAmount(inboundShippingTotal, currencyCode) })
1846
+ ] }),
1847
+ /* @__PURE__ */ jsxs6("div", { className: "flex items-center justify-between", children: [
1848
+ /* @__PURE__ */ jsx9("span", { className: "txt-small text-ui-fg-subtle", children: t("orders.exchanges.outboundShipping") }),
1849
+ /* @__PURE__ */ jsx9("span", { className: "txt-small text-ui-fg-subtle", children: getStylizedAmount(outboundShippingTotal, currencyCode) })
1850
+ ] }),
1851
+ /* @__PURE__ */ jsxs6("div", { className: "mt-4 flex items-center justify-between border-t border-dotted pt-4", children: [
1852
+ /* @__PURE__ */ jsx9("span", { className: "txt-small font-medium", children: t("orders.exchanges.refundAmount") }),
1853
+ /* @__PURE__ */ jsx9("span", { className: "txt-small font-medium", children: getStylizedAmount(estimatedDifference, currencyCode) })
1854
+ ] })
1855
+ ] })
1856
+ ] }),
1857
+ /* @__PURE__ */ jsx9("div", { className: "bg-ui-bg-field mt-8 rounded-lg border py-2 pl-2 pr-4", children: /* @__PURE__ */ jsx9(
1858
+ Form.Field,
1859
+ {
1860
+ control: form.control,
1861
+ name: "send_notification",
1862
+ render: ({ field: { onChange, value, ...field } }) => /* @__PURE__ */ jsxs6(Form.Item, { children: [
1863
+ /* @__PURE__ */ jsxs6("div", { className: "flex items-center", children: [
1864
+ /* @__PURE__ */ jsx9(Form.Control, { className: "mr-4 self-start", children: /* @__PURE__ */ jsx9(
1865
+ Switch,
1866
+ {
1867
+ dir: "ltr",
1868
+ className: "mt-[2px] rtl:rotate-180",
1869
+ checked: !!value,
1870
+ onCheckedChange: onChange,
1871
+ ...field,
1872
+ "data-testid": "exchange-create-notify"
1873
+ }
1874
+ ) }),
1875
+ /* @__PURE__ */ jsxs6("div", { className: "block", children: [
1876
+ /* @__PURE__ */ jsx9(Form.Label, { children: t("orders.returns.sendNotification") }),
1877
+ /* @__PURE__ */ jsx9(Form.Hint, { className: "!mt-1", children: t("orders.returns.sendNotificationHint") })
1878
+ ] })
1879
+ ] }),
1880
+ /* @__PURE__ */ jsx9(Form.ErrorMessage, {})
1881
+ ] })
1882
+ }
1883
+ ) }),
1884
+ /* @__PURE__ */ jsx9("div", { className: "p-8" })
1885
+ ] }) }),
1886
+ /* @__PURE__ */ jsx9(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsx9("div", { className: "flex w-full items-center justify-end gap-x-4", children: /* @__PURE__ */ jsxs6("div", { className: "flex items-center justify-end gap-x-2", children: [
1887
+ /* @__PURE__ */ jsx9(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx9(
1888
+ Button3,
1889
+ {
1890
+ type: "button",
1891
+ onClick: handleClose,
1892
+ variant: "secondary",
1893
+ size: "small",
1894
+ isLoading: canceling,
1895
+ disabled: submitting,
1896
+ "data-testid": "exchange-cancel",
1897
+ children: t("orders.exchanges.cancel.title")
1898
+ }
1899
+ ) }),
1900
+ /* @__PURE__ */ jsx9(
1901
+ Button3,
1902
+ {
1903
+ type: "submit",
1904
+ variant: "primary",
1905
+ size: "small",
1906
+ isLoading: submitting || isConfirming,
1907
+ disabled: !exchangeId || canceling || !hasSelection,
1908
+ "data-testid": "exchange-confirm",
1909
+ children: t("orders.exchanges.confirm")
1910
+ },
1911
+ "submit-button"
1912
+ )
1913
+ ] }) }) })
1914
+ ] }) });
1915
+ };
1916
+
1917
+ // src/pages/orders/[id]/exchanges/create/index.tsx
1918
+ import { jsx as jsx10, jsxs as jsxs7 } from "react/jsx-runtime";
1919
+ var Component = () => {
1920
+ const { t } = useTranslation12();
1921
+ return /* @__PURE__ */ jsxs7(RouteFocusModal, { children: [
1922
+ /* @__PURE__ */ jsx10(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx10("span", { className: "sr-only", children: t("orders.exchanges.title") }) }),
1923
+ /* @__PURE__ */ jsx10(RouteFocusModal.Description, { className: "sr-only", children: t("orders.exchanges.title") }),
1924
+ /* @__PURE__ */ jsx10(ExchangeCreateForm, {})
1925
+ ] });
1926
+ };
1927
+ var create_default = Component;
1928
+ export {
1929
+ Component,
1930
+ create_default as default
1931
+ };