@adyen/adyen-platform-experience-web
Version:

41 lines (40 loc) • 1.36 kB
JavaScript
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
};