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