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)

39 lines (38 loc) 1.26 kB
import { useState as v, useCallback as u, useMemo as s } from "../external/preact/hooks/dist/hooks.module.js"; import L from "../core/Context/useCoreContext.js"; import { capitalize as O } from "../utils/value/string.js"; import { uniqueId as _ } from "../utils/random/uniqueId.js"; const f = _(), q = (o, c = !1) => { const { i18n: r } = L(), [d, m] = v(0), p = u(() => m(0), []), e = s( () => o && [ ...o, ...c ? [ { ...o[0] ?? {}, id: f, description: void 0 } ] : [] ], [c, o] ), C = s(() => e == null ? void 0 : e[d], [e, d]), I = s( () => o && o.length > 1 ? Object.freeze( e == null ? void 0 : e.map(({ description: t, id: n }) => { const i = n === f ? r.get("balanceAccounts.all") : O(t); return { id: n, name: i }; }) ) : void 0, [e, o, r] ), S = u( ({ target: t }) => { const n = t == null ? void 0 : t.value, i = e == null ? void 0 : e.findIndex(({ id: x }) => x === n); i >= 0 && m(i); }, [e] ); return { activeBalanceAccount: C, balanceAccountSelectionOptions: I, onBalanceAccountSelection: S, resetBalanceAccountSelection: p }; }; export { f as ALL_BALANCE_ACCOUNTS_SELECTION_ID, q as default };