import { cl as f, cm as d, cn as y, co as p, c4 as A, ci as x, cp as h, cq as L, cr as F } from "./index-KlKYOR0p.mjs";
function a(o, t) {
  switch (o.binary) {
    case "bytes":
      if ("layout" in o) {
        const { custom: r } = o;
        return r === void 0 || typeof r.from != "function" ? e(o.layout, r ? r.from : t) : t;
      }
    case "int":
    case "uint": {
      const { custom: r } = o;
      return o != null && o.omit ? void 0 : d(r) ? r : y(r) ? r.to : t;
    }
    case "array":
      return Array.isArray(t) ? t.map((r) => e(o.layout, r)) : void 0;
    case "switch": {
      const r = t[o.idTag ?? "id"], [s, n] = o.layouts.find(([c]) => (Array.isArray(c) ? c[1] : c) == r);
      return {
        [o.idTag ?? "id"]: r,
        ...e(n, t)
      };
    }
  }
}
function e(o, t) {
  if (t = t ?? {}, f(o))
    return a(o, t);
  const r = {};
  for (const s of o) {
    const n = a(s, t[s.name] ?? {});
    n !== void 0 && (r[s.name] = n);
  }
  return r;
}
function i(o, t) {
  return e(o, t);
}
function u(o) {
  return [...h, L(o)];
}
function T(o, t) {
  const [r, s] = p(o), n = i(u(o), t);
  return {
    protocolName: r,
    payloadName: s,
    payloadLiteral: o,
    ...i(F, t),
    ...n,
    hash: A(x(u(o), n))
  };
}
export {
  T as c
};
