import { jsx as n, Fragment as F } from "@emotion/react/jsx-runtime";
import y from "react";
import { getPropertyByString as h } from "@m4l/core";
import { getNullGuard as C } from "../../../../utils/getNullGuard.js";
import { NestedFormatterWithImageSize as I } from "./formatter.js";
import { resolveNestedField as c } from "./helpers/resolveNestedField.js";
function k(e) {
  const {
    fieldValue: s,
    Component: l = y.Fragment,
    onLink: i
  } = e;
  return (v) => {
    const { childRows: a } = v;
    if (a.length === 0)
      return /* @__PURE__ */ n(F, { children: "-" });
    const t = a[0], r = C(
      h(t, s)
    ), f = typeof r == "object" ? JSON.stringify(r) : String(r);
    if (e.fieldImageUrl || e.fieldIcon) {
      let u, d, g;
      if (e.fieldImageUrl) {
        const o = c(t, e.fieldImageUrl);
        u = typeof o == "string" && o.length > 0 ? o : void 0;
      } else if (e.fieldIcon) {
        const o = c(t, e.fieldIcon);
        if (d = o != null && o !== "" ? o : void 0, d && e.fieldIconColor !== void 0) {
          const m = e.fieldIconColor;
          g = typeof m == "function" ? m(t) : c(t, m);
        }
      }
      return /* @__PURE__ */ n(
        I,
        {
          value: f,
          defaultValue: e.defaultValue ?? "-",
          imageUrl: u,
          icon: d,
          iconColor: g,
          onLink: i ? () => i(t) : void 0,
          Component: l
        }
      );
    }
    return i ? /* @__PURE__ */ n(
      I,
      {
        value: f,
        defaultValue: e.defaultValue ?? "-",
        onLink: () => i(t),
        Component: l
      }
    ) : /* @__PURE__ */ n(l, { children: f });
  };
}
export {
  k as ColumnNestedValueGroupFormatter
};
