import { isArray as c } from "lodash";
const m = (s, n, r, a) => {
  if (!c(s))
    return s;
  let l = null;
  return l = s.map((e, p) => {
    const i = {};
    return r && p === 0 && (n = f(e, n)), Object.keys(n).forEach((o) => {
      const t = n[o];
      t.alias ? i[t.alias] = e[t.mapping] : i[t.name] = e[t.mapping];
    }), a && (i.userdata = e), i;
  }), {
    mappedData: l,
    finalMapping: n
  };
}, f = (s, n) => {
  const r = [];
  return s ?? (s = []), Object.keys(s).forEach((a) => {
    const l = n.find((e) => e.name === a);
    l ? r.push({
      alias: l.alias,
      name: a,
      label: a,
      mapping: l.mapping
    }) : r.push({
      alias: a,
      name: a,
      label: a,
      mapping: a
    });
  }), r;
};
export {
  f as dynamicMappingData,
  m as mappingData
};
