import { getPropertyByString as s } from "@m4l/core";
import { deepEqual as i } from "fast-equals";
import { ColumnConcatenatedValuesGroupFormatter as c } from "./ColumnConcatenatedValuesGroupFormatter.js";
import { getFormatConcatenated as l } from "../../../formatters/ConcatenatedFormatter/ConcatenatedFormatter.js";
import { useState as f, useRef as d, useEffect as C, useMemo as V } from "react";
import { ColumnConcatenatedValuesFormatter as g } from "./formatter.js";
import { getColumnKey as y } from "../../helpers/shared/getColumnKey/getColumnKey.js";
const m = (e, t) => t.map((r) => {
  const u = y(r), a = s(e, u);
  let n;
  return typeof a == "string" || typeof a == "number" ? n = a.toString() : n = "", n;
}), S = (e) => (t, o) => {
  const r = m(t, e.fieldValue);
  return l(r, e.fieldSeparator).includes(o);
}, v = (e) => (t, o) => {
  const r = m(t, e.fieldValue), u = m(o, e.fieldValue), a = l(r, e.fieldSeparator), n = l(u, e.fieldSeparator);
  return a > n ? 1 : a < n ? -1 : 0;
}, x = (e) => {
  const [t, o] = f(e), r = d({ ...e });
  return C(() => {
    i(r.current, e) || (r.current = e, o(e));
  }, [e]), V(() => ({
    formatter: g(t),
    renderGroupCell: c(t),
    customFilter: S(t),
    customSort: v(t)
  }), [t]);
};
export {
  x as useColumnConcatenatedValues
};
