import { jsx as d } from "@emotion/react/jsx-runtime";
import { getPropertyByString as F } from "@m4l/core";
import w, { useContext as h } from "react";
import { getNullGuard as y } from "../../../../utils/getNullGuard.js";
import { DataGridContext as N } from "../../contexts/DataGridContext/DataGridContext.js";
import { IMAGE_SIZES as I } from "../ColumnImageFormatter/constants.js";
import { resolveNestedField as u } from "./helpers/resolveNestedField.js";
import { NestedFormatter as S } from "../../../formatters/NestedFormatter/NestedFormatter.js";
function C(e) {
  const n = h(N), i = (n?.viewMode ?? "table") === "cards", r = n?.currentRowHeightVariant, c = i ? I.cards : void 0, o = i ? I.cards : void 0;
  return /* @__PURE__ */ d(
    S,
    {
      ...e,
      imageWidth: c,
      imageHeight: o,
      rowHeightVariant: r
    }
  );
}
function L(e) {
  const {
    fieldValue: n,
    Component: l = w.Fragment,
    defaultValue: i = "-",
    onLink: r
  } = e;
  return (c) => {
    const { row: o } = c, m = y(
      F(o, n),
      i
    ), a = typeof m == "object" ? JSON.stringify(m) : String(m);
    if (e.fieldImageUrl || e.fieldIcon) {
      let g, f, v;
      if (e.fieldImageUrl) {
        const t = u(o, e.fieldImageUrl);
        g = typeof t == "string" && t.length > 0 ? t : void 0;
      } else if (e.fieldIcon) {
        const t = u(o, e.fieldIcon);
        if (f = t != null && t !== "" ? t : void 0, f && e.fieldIconColor !== void 0) {
          const s = e.fieldIconColor;
          v = typeof s == "function" ? s(o) : u(o, s);
        }
      }
      return /* @__PURE__ */ d(
        C,
        {
          value: a,
          defaultValue: i,
          imageUrl: g,
          icon: f,
          iconColor: v,
          onLink: r ? () => r(o) : void 0,
          Component: l
        }
      );
    }
    return r ? /* @__PURE__ */ d(
      C,
      {
        value: a,
        defaultValue: i,
        onLink: () => r(o),
        Component: l
      }
    ) : /* @__PURE__ */ d(l, { children: a });
  };
}
export {
  L as ColumnNestedValueFormatter,
  C as NestedFormatterWithImageSize
};
