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)

33 lines (32 loc) 1.03 kB
import { useCallback as i, useState as O, useEffect as g } from "../../../../../external/preact/hooks/dist/hooks.module.js"; import { EMPTY_ARRAY as t } from "../../../../../utils/value/constants.js"; const p = ({ items: f, multiSelect: r, selected: l }) => { const a = i( (c = t) => { const e = t.concat(c ?? t).filter(Boolean), n = f.filter((x) => e.includes(x.id)), o = r ? n : n.slice(0, 1); return o.length ? Object.freeze(o) : t; }, [f, r] ), [d, s] = O(a(l)), b = i( (c = t) => { const e = c.filter((n) => f.includes(n)); s(e.length ? Object.freeze(e) : t); }, [f, s] ), u = i( (c) => { s((e) => { const n = e.indexOf(c); if (n < 0) return Object.freeze((r ? e : t).concat(c)); if (!r) return e; const o = [...e]; return o.splice(n, 1), o.length ? Object.freeze(o) : t; }); }, [r, s] ); return g(() => s(a(l)), [a, l, s]), { resetSelection: b, select: u, selection: d }; }; export { p as default };