const importsRegex = /import(?:["'\s]*([\w*{}\n\r\t, ]+)from\s*)?["'\s].*([@\w/_-]+)["'\s].*/g;
function splitCodeImports(code) {
  const codeWithoutImports = replace(code, importsRegex);
  const hasImports = Boolean(code.match(importsRegex));
  const imports = code.match(importsRegex)?.join("\n") ?? "";
  return {
    codeWithoutImports,
    imports,
    hasImports
  };
}
function replace(string, regex, value = "") {
  return string.replace(regex, value).trim();
}

const FRONT_MATTER_DIVISOR = "---";
function splitScriptTemplate(code) {
  let script = code;
  let template = null;
  if (code.startsWith(FRONT_MATTER_DIVISOR)) {
    script = code.substring(code.indexOf(FRONT_MATTER_DIVISOR) + 3);
    script = script.substring(0, script.lastIndexOf(FRONT_MATTER_DIVISOR));
    template = code.substring(code.lastIndexOf(FRONT_MATTER_DIVISOR) + 3);
  }
  return { script, template };
}

function invertMap(map) {
  const invertedMap = /* @__PURE__ */ new Map();
  for (const [key, value] of map.entries())
    invertedMap.set(value, key);
  return invertedMap;
}

export { invertMap, splitCodeImports, splitScriptTemplate };
