import "../../chunks/chunk.QU3DSPNU.js";
import { html as litHtml } from "lit";
const VER_SUFFIX = "-e5c037";
class ScopedElementRegistry {
  static get instance() {
    if (!globalThis.__gdsElementLookupTable?.[VER_SUFFIX])
      globalThis.__gdsElementLookupTable = {
        ...globalThis.__gdsElementLookupTable,
        [VER_SUFFIX]: /* @__PURE__ */ new Map()
      };
    return globalThis.__gdsElementLookupTable[VER_SUFFIX];
  }
}
const gdsCustomElement = (tagName, options) => {
  return function(constructor) {
    var _a;
    return _a = class extends constructor {
      constructor() {
        super(...arguments);
        this.gdsElementName = tagName;
      }
      static define() {
        if (_a.isDefined) return;
        const isVersioningDisabled = globalThis.GDS_DISABLE_VERSIONED_ELEMENTS;
        const nameToRegister = isVersioningDisabled ? tagName : tagName + VER_SUFFIX;
        if (customElements.get(nameToRegister)) return;
        _a.isDefined = true;
        ScopedElementRegistry.instance.set(tagName, nameToRegister);
        customElements.define(nameToRegister, _a);
        if (options?.dependsOn) {
          options.dependsOn.forEach((dep) => dep.define());
        }
      }
    }, _a.isDefined = false, _a;
  };
};
const templateCache = /* @__PURE__ */ new WeakMap();
function applyElementScoping(strings, ...values) {
  let modstrings = templateCache.get(strings);
  if (!modstrings) {
    modstrings = replaceTags(strings);
    modstrings.raw = replaceTags(strings.raw);
    templateCache.set(strings, modstrings);
  }
  return [modstrings, ...values];
}
const replaceTags = (inStr) => inStr.map((s) => {
  for (const [key, value] of ScopedElementRegistry.instance.entries()) {
    s = s.replace(new RegExp(`${key}(?![-a-z])`, "mg"), value);
  }
  return s;
});
function htmlTemplateTagFactory(extendedTag) {
  return (strings, ...values) => {
    if (globalThis.GDS_DISABLE_VERSIONED_ELEMENTS) {
      return extendedTag(strings, ...values);
    }
    const [modstrings, ...modvalues] = applyElementScoping(strings, ...values);
    return extendedTag(modstrings, ...modvalues);
  };
}
const html = htmlTemplateTagFactory(litHtml);
function getScopedTagName(tagName, alwaysAddSuffix = false) {
  return ScopedElementRegistry.instance.get(tagName) ?? tagName + (alwaysAddSuffix ? VER_SUFFIX : "");
}
function getUnscopedTagName(tagName) {
  return [...ScopedElementRegistry.instance.entries()].find(
    ([, value]) => value === tagName
  )?.[0];
}
var custom_element_scoping_default = {};
export {
  ScopedElementRegistry,
  VER_SUFFIX,
  custom_element_scoping_default as default,
  gdsCustomElement,
  getScopedTagName,
  getUnscopedTagName,
  html,
  htmlTemplateTagFactory
};
