import { useState as s, useRef as a, useCallback as d, useEffect as P, useMemo as g } from "react";
import { useFormatter as p } from "@m4l/graphics";
import { getPropertyByString as l } from "@m4l/core";
import { deepEqual as y } from "fast-equals";
import { getFormatPrice as C } from "../../../formatters/PriceFormatter/PriceFormatter.js";
import { ColumnPriceGroupFormatter as S } from "./ColumnPriceGroupFormatter.js";
import { getColumnKey as c } from "../../helpers/shared/getColumnKey/getColumnKey.js";
import { ColumnPriceFormatter as F } from "./formatter.js";
const V = (e) => (u, t) => {
  const n = c(e.fieldValue), m = l(u, n), i = l(t, n);
  let r, o;
  return typeof m == "number" ? r = m : r = 0, typeof i == "number" ? o = i : o = 0, r > o ? 1 : r < o ? -1 : 0;
}, k = (e) => {
  const { currencyFormatter: u } = p(), [t, n] = s(e), m = a({ ...e }), i = d(
    (r, o) => {
      const f = c(t.fieldValue);
      return C(
        r,
        f,
        u.code,
        u.decimalDigits
      ).includes(o);
    },
    [t, u]
  );
  return P(() => {
    y(m.current, e) || (m.current = e, n(e));
  }, [e]), g(() => ({
    formatter: F(t),
    renderGroupCell: S(t),
    customFilter: i,
    customSort: V(t)
  }), [t, i]);
};
export {
  k as useColumnPrice
};
