import { getPropertyByString as m } from "@m4l/core";
import { ColumnNestedValueGroupFormatter as f } from "./ColumnNestedValueGroupFormatter.js";
import { useState as i, useRef as c, useEffect as a, useMemo as d } from "react";
import { deepEqual as V } from "fast-equals";
import { getNullGuard as s } from "../../../../utils/getNullGuard.js";
import { ColumnNestedValueFormatter as y } from "./formatter.js";
import { getColumnKey as g } from "../../helpers/shared/getColumnKey/getColumnKey.js";
const C = (e) => {
  const { defaultValue: t = "-" } = e;
  return (u, r) => {
    const o = s(
      m(u, e.fieldValue),
      t
    );
    return typeof o == "object" ? Object.values(o).includes(r) : o.toString().includes(r);
  };
}, p = (e) => {
  const { defaultValue: t = "-" } = e;
  return (u, r) => {
    const o = g(e.fieldValue), n = s(
      m(u, o),
      t
    ), l = s(
      m(r, o),
      t
    );
    return typeof n == "object" || typeof l == "object" || n === void 0 || l === void 0 ? 0 : n > l ? 1 : n < l ? -1 : 0;
  };
}, G = (e) => {
  const [t, u] = i(e), r = c({ ...e });
  return a(() => {
    V(r.current, e) || (r.current = e, u(e));
  }, [e]), d(
    () => ({
      formatter: y(t),
      renderGroupCell: f(t),
      customFilter: C(t),
      customSort: p(t)
    }),
    [t]
  );
};
export {
  G as useColumnNestedValue
};
