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

37 lines (36 loc) • 1.23 kB
JavaScript
import I from "../../../../hooks/useAnalytics/useFilterAnalyticsEvent.js";
import { useMemo as a, useCallback as i, useState as v, useRef as u, useEffect as p } from "../../../../external/.pnpm/preact@10.28.2/node_modules/preact/hooks/dist/hooks.module.js";
const k = ({
availableCurrencies: c,
eventCategory: g,
eventSubCategory: h,
eventLabel: R,
onUpdateSelection: f,
selectedCurrency: n
}) => {
const { logEvent: d } = I({ category: g, subCategory: h, label: R }), S = a(
() => Object.freeze(c?.map((t) => ({ id: t, name: t })) ?? []),
[c]
), o = i(
(t) => {
const s = t ? c?.findIndex((E) => E === t) ?? -1 : -1;
return c?.[s];
},
[c]
), [e, y] = v(() => o(n)), r = u(), m = u(c), A = u(n), x = i(
({ target: t }) => {
const s = o(t?.value);
s && (r.current = e, y(s));
},
[o, e]
);
return p(() => {
(m.current !== c || A.current !== n) && (m.current = c, A.current = n, r.current = void 0, y(o(n)));
}, [o, n, c]), p(() => {
const t = r.current;
t !== e && (r.current = e, t && e && d?.("update", e), f?.(e));
}, [e, d, f]), { activeCurrency: e, currencySelectionOptions: S, onCurrencySelection: x };
};
export {
k as default
};