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)

99 lines (98 loc) 3.21 kB
import { jsx as e } from "../../../../../external/preact/jsx-runtime/dist/jsxRuntime.module.js"; import { memo as N } from "../../../../../external/preact/compat/dist/compat.module.js"; import { Fragment as R, createContext as O } from "../../../../../external/preact/dist/preact.module.js"; import { useMemo as o, useCallback as w, useEffect as y, useContext as j } from "../../../../../external/preact/hooks/dist/hooks.module.js"; import z from "../../../../../core/Context/useCoreContext.js"; import { ButtonVariant as A } from "../../../../internal/Button/types.js"; import { ActiveView as B } from "../types.js"; import { Icon as E } from "../../../../internal/Icon/Icon.js"; import { EMPTY_OBJECT as l, EMPTY_ARRAY as _ } from "../../../../../utils/value/constants.js"; import { noop as D } from "../../../../../utils/common.js"; const M = O({ availableItems: _, primaryAction: D, secondaryAction: D, transaction: l, extraFields: l, dataCustomization: l }), S = N( ({ children: P, lineItems: Y, refundAvailable: n, refundDisabled: f, setActiveView: u, setPrimaryAction: p, setSecondaryAction: v, transaction: i, transactionNavigator: k, extraFields: F, dataCustomization: I }) => { const { i18n: r } = z(), { currentTransaction: T, canNavigateBackward: g, canNavigateForward: C, backward: x, forward: b } = k, h = o(() => ({ title: r.get("refundAction") }), [r]), a = o(() => !n || f, [n, f]), s = w( () => void (!a && u(B.REFUND)), [a, u] ), t = o(() => { if (T === i.id) { if (g) return 2; if (C) return 1; } }, [g, C, T, i]), c = w(() => { switch (t) { case 2: return void x(); case 1: return void b(); } }, [t, x, b]), d = o(() => { switch (t) { case 2: return { title: r.get("refund.returnToRefund"), renderTitle: (m) => /* @__PURE__ */ e(R, { children: [ /* @__PURE__ */ e(E, { style: { transform: "scaleX(-1)" }, name: "angle-right" }), /* @__PURE__ */ e("span", { children: m }) ] }) }; case 1: return { title: r.get("refund.goToPayment"), renderTitle: (m) => /* @__PURE__ */ e(R, { children: [ /* @__PURE__ */ e(E, { name: "angle-right" }), /* @__PURE__ */ e("span", { children: m }) ] }) }; } }, [t, r]); return y(() => { p( n ? Object.freeze({ disabled: a, event: s, variant: A.PRIMARY, ...h }) : void 0 ); }, [s, n, a, h, p]), y(() => { v( t && d ? Object.freeze({ disabled: !1, event: c, variant: A.SECONDARY, ...d }) : void 0 ); }, [t, c, d, v]), /* @__PURE__ */ e( M.Provider, { value: { availableItems: Y, primaryAction: s, secondaryAction: c, transaction: i, extraFields: F, dataCustomization: I }, children: P } ); } ), W = () => j(M); export { S as TransactionDetailsProvider, W as default, W as useTransactionDetailsContext };