import { __exports as p } from "../../../../../../../_virtual/literal.js";
import "./options.js";
import "./parse.js";
import "./populate.js";
import { __exports as m } from "../../../../../../../_virtual/options.js";
import { __exports as u } from "../../../../../../../_virtual/parse.js";
import { __exports as d } from "../../../../../../../_virtual/populate.js";
Object.defineProperty(p, "__esModule", {
  value: !0
});
p.default = v;
var h = m, f = u, _ = d;
function v(r, c, e) {
  const {
    metadata: o,
    names: a
  } = w(r, c, e);
  return (l) => {
    const n = {};
    return l.forEach((t, s) => {
      n[a[s]] = t;
    }), (t) => {
      const s = (0, h.normalizeReplacements)(t);
      return s && Object.keys(s).forEach((i) => {
        if (Object.prototype.hasOwnProperty.call(n, i))
          throw new Error("Unexpected replacement overlap.");
      }), r.unwrap((0, _.default)(o, s ? Object.assign(s, n) : n));
    };
  };
}
function w(r, c, e) {
  let o, a, l, n = "";
  do {
    n += "$";
    const t = y(c, n);
    o = t.names, a = new Set(o), l = (0, f.default)(r, r.code(t.code), {
      parser: e.parser,
      placeholderWhitelist: new Set(t.names.concat(e.placeholderWhitelist ? Array.from(e.placeholderWhitelist) : [])),
      placeholderPattern: e.placeholderPattern,
      preserveComments: e.preserveComments,
      syntacticPlaceholders: e.syntacticPlaceholders
    });
  } while (l.placeholders.some((t) => t.isDuplicate && a.has(t.name)));
  return {
    metadata: l,
    names: o
  };
}
function y(r, c) {
  const e = [];
  let o = r[0];
  for (let a = 1; a < r.length; a++) {
    const l = `${c}${a - 1}`;
    e.push(l), o += l + r[a];
  }
  return {
    names: e,
    code: o
  };
}
//# sourceMappingURL=literal.js.map
