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

50 lines (49 loc) • 1.85 kB
JavaScript
import { useMemo as v } from "../external/preact/hooks/dist/hooks.module.js";
import { getLabel as E } from "../components/utils/getLabel.js";
import U from "../core/Context/useCoreContext.js";
import { useResponsiveContainer as w, containerQueries as A } from "./useResponsiveContainer.js";
import { EMPTY_OBJECT as O } from "../utils/value/constants.js";
import { isUndefined as P } from "../utils/value/is.js";
function B(t) {
let i = {};
for (const r of Object.keys(t))
P(t[r]) || (i = { ...i, [r]: t[r] });
return i;
}
const _ = ({
fields: t,
customColumns: i,
columnConfig: r,
fieldsKeys: k
}) => {
const { i18n: o } = U(), b = v(() => t.map((y) => ({ key: y })), [t]), s = w(A.up.sm);
return v(() => {
const y = (i == null ? void 0 : i.filter((e) => !(t != null && t.some((n) => n === e.key))).map((e) => e.key)) || [], M = [...b, ...(i == null ? void 0 : i.filter((e) => e == null ? void 0 : e.key)) || []], f = (i == null ? void 0 : i.reduce((e, n) => (e[n.key] = n, e), {})) || {}, a = /* @__PURE__ */ new Map();
return M.forEach((e) => {
const n = f[e.key];
if ((n == null ? void 0 : n.visibility) !== "hidden")
if (a.has(e.key)) {
const p = a.get(e.key);
a.set(e.key, {
...p,
...e,
visible: e.visibility !== "hidden",
position: e.align || p.position
});
} else {
const { key: p, flex: x, align: T } = e, g = o.get(E((k == null ? void 0 : k[p]) || p)), h = B((r == null ? void 0 : r[p]) || O);
a.set(e.key, {
key: p,
label: g,
visible: y.includes(e.key) ? s : !0,
flex: x,
position: T,
...h
});
}
}), Array.from(a.values());
}, [r, i, t, o, s, b]);
};
export {
_ as useTableColumns
};