UNPKG

@adyen/adyen-platform-experience-web

Version:

![Platform Experience header](https://github.com/Adyen/adyen-platform-experience-web/assets/7926613/18094965-9e01-450e-8dc9-ea84e6b22c2b)

41 lines (40 loc) 1.36 kB
import { updateRefundItems as p } from "../helpers.js"; import { useState as v, useMemo as f, useCallback as b } from "../../../../../../external/preact/hooks/dist/hooks.module.js"; import { EMPTY_ARRAY as o } from "../../../../../../utils/value/constants.js"; const T = ({ currency: c, lineItems: n }) => { const [s, m] = v(o), u = f(() => { const a = n == null ? void 0 : n.filter((t) => { if (t.amountIncludingTax.currency !== c) return; const e = t.availableQuantity; return e > 0 && Number.isFinite(e) && Math.trunc(e) === e; }).map( ({ id: t, ...e }) => [ t, Object.freeze({ amount: e.amountIncludingTax.value, quantity: e.availableQuantity, id: t }) ] ); return new Map(a ?? o); }, [c, n]), M = f( () => (n == null ? void 0 : n.filter(({ id: a }) => u.has(a))) ?? o, [s, n, u] ), i = b( function(a) { m((t) => { const d = [...arguments.length === 0 ? new Map(t.map(({ id: r }) => [r, 0])) : new Map((a == null ? void 0 : a.map((r) => [r, 0])) ?? o)].map(([r, g]) => ({ id: r, quantity: g })); return p(u, t, d); }); }, [u] ), l = b( (a) => m((t) => p(u, t, a)), [u] ); return { availableItems: M, clearItems: i, items: s, updateItems: l }; }; export { T as useRefundContextLineItems };