var l = Object.defineProperty;
var a = (t, e) => l(t, "name", { value: e, configurable: !0 });
import { scalarZeroValue as c } from "./scalars.js";
function p(t, e, n, r) {
  let i;
  return {
    typeName: e,
    extendee: n,
    get field() {
      if (!i) {
        const o = typeof r == "function" ? r() : r;
        o.name = e.split(".").pop(), o.jsonName = `[${e}]`, i = t.util.newFieldList([o]).list()[0];
      }
      return i;
    },
    runtime: t
  };
}
a(p, "makeExtension");
function d(t) {
  const e = t.field.localName, n = /* @__PURE__ */ Object.create(null);
  return n[e] = s(t), [n, () => n[e]];
}
a(d, "createExtensionContainer");
function s(t) {
  const e = t.field;
  if (e.repeated)
    return [];
  if (e.default !== void 0)
    return e.default;
  switch (e.kind) {
    case "enum":
      return e.T.values[0].no;
    case "scalar":
      return c(e.T, e.L);
    case "message":
      const n = e.T, r = new n();
      return n.fieldWrapper ? n.fieldWrapper.unwrapField(r) : r;
    case "map":
      throw "map fields are not allowed to be extensions";
  }
}
a(s, "initExtensionField");
function m(t, e) {
  if (!e.repeated && (e.kind == "enum" || e.kind == "scalar")) {
    for (let n = t.length - 1; n >= 0; --n)
      if (t[n].no == e.no)
        return [t[n]];
    return [];
  }
  return t.filter((n) => n.no === e.no);
}
a(m, "filterUnknownFields");
export {
  d as createExtensionContainer,
  m as filterUnknownFields,
  p as makeExtension
};
