import { getPropertyByString as l } from "@m4l/core";
import { isRecord as d } from "../../../isRecord.js";
import { resolveFieldTypeComponentProps as c } from "../../../resolveFieldContractAliases.js";
import { resolveRemoteOrAbsoluteAssetSrc as s } from "../../helpers/resolveRemoteOrAbsoluteAssetSrc.js";
import { resolveFieldInputLabel as f } from "../../../resolveFieldInputLabel/resolveFieldInputLabel.js";
import { createIsOptionEqualToValue as P } from "../../../createIsOptionEqualToValue/createIsOptionEqualToValue.js";
const r = { resource: "" };
function A(n) {
  return Array.isArray(n) ? n : [];
}
function u(n, i, a) {
  if (n && n.trim() !== "") {
    const m = n.trim();
    return (o) => {
      if (!d(o))
        return r;
      const t = l(o, m);
      if (typeof t != "string" || t.trim() === "")
        return r;
      const e = s(a, t);
      return e ? { resource: e, type: "icon" } : r;
    };
  }
  if (i && i.trim() !== "") {
    const m = i.trim();
    return (o) => {
      if (!d(o))
        return r;
      const t = l(o, m);
      if (typeof t != "string" || t.trim() === "")
        return r;
      const e = s(a, t);
      return e ? { resource: e, type: "image" } : r;
    };
  }
}
function E(n, i, a) {
  const m = A(n.options), o = c(n.fieldType), t = { resolvedOptions: m };
  d(o) && (typeof o.optionLabelPath == "string" && o.optionLabelPath.trim() !== "" && (t.optionLabelPath = o.optionLabelPath), typeof o.equalToValuePath == "string" && o.equalToValuePath.trim() !== "" && (t.equalToValuePath = o.equalToValuePath), typeof o.isMultiple == "boolean" && (t.isMultiple = o.isMultiple), typeof o.optionEndAdornmentIconPath == "string" && o.optionEndAdornmentIconPath.trim() !== "" && (t.optionEndAdornmentIconPath = o.optionEndAdornmentIconPath), typeof o.optionEndAdornmentImagePath == "string" && o.optionEndAdornmentImagePath.trim() !== "" && (t.optionEndAdornmentImagePath = o.optionEndAdornmentImagePath), typeof o.optionStartAdornmentIconPath == "string" && o.optionStartAdornmentIconPath.trim() !== "" && (t.optionStartAdornmentIconPath = o.optionStartAdornmentIconPath), typeof o.optionStartAdornmentImagePath == "string" && o.optionStartAdornmentImagePath.trim() !== "" && (t.optionStartAdornmentImagePath = o.optionStartAdornmentImagePath));
  const e = t.equalToValuePath ?? "id";
  return t.resolvedLabel = f(n, i), t.resolvedIsOptionEqualToValue = P(e), t.resolvedGetOptionLabel = t.optionLabelPath ? (p) => l(p, t.optionLabelPath ?? "") : (p) => p.label, t.resolvedOptionStartAdornment = u(
    t.optionStartAdornmentIconPath,
    t.optionStartAdornmentImagePath,
    a
  ), t.resolvedOptionEndAdornment = u(
    t.optionEndAdornmentIconPath,
    t.optionEndAdornmentImagePath,
    a
  ), t;
}
export {
  E as normalizeAutocompletePropsFromBackend
};
