import { usePageQueries as j, useLoopedQuery as Q, useData as w } from "../../../../../use-page-data.js";
import { useBrickManifest as O } from "./use-brick-manifest.js";
import y from "../../../../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/get.js";
import k from "../../../../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/isPlainObject.js";
function S({
  brick: f,
  editable: d,
  iterationIndex: m = 0
}) {
  const { props: a } = f, g = j(), u = a.loop, i = Q(u?.over), v = O(f.type), s = w(d);
  if (!g.length)
    return a;
  function l(r, n) {
    if (typeof r == "string")
      return r.replace(/{{(.*?)}}/g, (o, e) => y(n, e.trim(), ""));
    if (typeof r == "object" && r !== null) {
      const o = {};
      for (const [e, t] of Object.entries(r))
        o[e] = typeof t == "string" || k(t) ? l(t, n) : t;
      return o;
    }
    return r;
  }
  function p(r) {
    if (typeof r == "string")
      return r.replace(/{{(.*?)}}/g, (n, o) => {
        const [e, t] = o.trim().split(".");
        if (!e || !t)
          return console.warn("Invalid placeholder:", o), "";
        if (!s[e])
          return console.warn("No data for dataset:", e), console.log("Available datasets:", s), "";
        const c = s[e][m] ?? {};
        return y(c, t, "");
      });
    if (typeof r == "object" && r !== null) {
      const n = {};
      for (const [o, e] of Object.entries(r))
        n[o] = typeof e == "string" ? p(e) : e;
      return n;
    }
    return r;
  }
  function P(r) {
    const n = {};
    for (const [o, e] of Object.entries(r))
      if (v.props.properties[o]?.metadata?.consumeQuery && i) {
        const c = s[i.alias] ?? [], b = (Array.isArray(e) ? e : [e])[0];
        n[o] = c.map((h) => l(b, { [i.alias]: h })).slice(0, u?.overrideLimit ?? void 0);
      } else
        n[o] = typeof e == "string" ? p(e) : e;
    return n;
  }
  return P(a);
}
export {
  S as useBrickProps
};
//# sourceMappingURL=use-brick-props.js.map
