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)

35 lines (34 loc) 1.05 kB
import { RefundMode as s } from "../../types.js"; import { useState as N, useMemo as o, useCallback as _, useEffect as p } from "../../../../../../external/preact/hooks/dist/hooks.module.js"; import { clamp as E } from "../../../../../../utils/value/number.js"; const M = ({ availableAmount: t, currency: u, interactionsDisabled: c, items: f, refundMode: e }) => { const [n, r] = N(0), m = o(() => { switch (e) { case s.NON_REFUNDABLE: return 0; case s.PARTIAL_LINE_ITEMS: case s.PARTIAL_AMOUNT: return n; // case RefundMode.PARTIAL_LINE_ITEMS: // return items.reduce((total, { amount, quantity }) => total + amount * quantity, 0); case s.FULL_AMOUNT: default: return t; } }, [t, f, e, n]), R = o(() => Object.freeze({ currency: u, value: m }), [m, u]), A = o(() => !c && e === s.PARTIAL_AMOUNT, [c, e]), T = _( (L) => void (A && r(E(0, L, t))), [t, A] ); return p(() => { r(t); }, [t]), [R, T]; }; export { M as useRefundContextAmount };