import { __exports as u } from "../../../../../../../_virtual/builder.js";
import "./options.js";
import "./string.js";
import "./literal.js";
import { __exports as h } from "../../../../../../../_virtual/options.js";
import { __exports as w } from "../../../../../../../_virtual/string.js";
import { __exports as _ } from "../../../../../../../_virtual/literal.js";
Object.defineProperty(u, "__esModule", {
  value: !0
});
u.default = m;
var r = h, l = w, d = _;
const f = (0, r.validate)({
  placeholderPattern: !1
});
function m(n, c) {
  const o = /* @__PURE__ */ new WeakMap(), i = /* @__PURE__ */ new WeakMap(), s = c || (0, r.validate)(null);
  return Object.assign((e, ...a) => {
    if (typeof e == "string") {
      if (a.length > 1)
        throw new Error("Unexpected extra params.");
      return p((0, l.default)(n, e, (0, r.merge)(s, (0, r.validate)(a[0]))));
    } else if (Array.isArray(e)) {
      let t = o.get(e);
      return t || (t = (0, d.default)(n, e, s), o.set(e, t)), p(t(a));
    } else if (typeof e == "object" && e) {
      if (a.length > 0)
        throw new Error("Unexpected extra params.");
      return m(n, (0, r.merge)(s, (0, r.validate)(e)));
    }
    throw new Error(`Unexpected template param ${typeof e}`);
  }, {
    ast: (e, ...a) => {
      if (typeof e == "string") {
        if (a.length > 1)
          throw new Error("Unexpected extra params.");
        return (0, l.default)(n, e, (0, r.merge)((0, r.merge)(s, (0, r.validate)(a[0])), f))();
      } else if (Array.isArray(e)) {
        let t = i.get(e);
        return t || (t = (0, d.default)(n, e, (0, r.merge)(s, f)), i.set(e, t)), t(a)();
      }
      throw new Error(`Unexpected template param ${typeof e}`);
    }
  });
}
function p(n) {
  let c = "";
  try {
    throw new Error();
  } catch (o) {
    o.stack && (c = o.stack.split(`
`).slice(3).join(`
`));
  }
  return (o) => {
    try {
      return n(o);
    } catch (i) {
      throw i.stack += `
    =============
${c}`, i;
    }
  };
}
//# sourceMappingURL=builder.js.map
