import { BLOCK_COMPONENTS } from "@nextsparkjs/registries/block-registry";
function getBlockComponents() {
  return BLOCK_COMPONENTS;
}
function getBlockComponent(slug) {
  return BLOCK_COMPONENTS[slug];
}
function hasBlock(slug) {
  return slug in BLOCK_COMPONENTS;
}
function normalizeBlockProps(props) {
  if (!props || typeof props !== "object" || Array.isArray(props)) {
    return {};
  }
  const result = {};
  const nestedObjects = {};
  for (const [key, value] of Object.entries(props)) {
    if (key.includes(".")) {
      const [parentKey, childKey] = key.split(".");
      if (!nestedObjects[parentKey]) {
        nestedObjects[parentKey] = {};
      }
      nestedObjects[parentKey][childKey] = value;
    } else {
      result[key] = value;
    }
  }
  for (const [parentKey, childObj] of Object.entries(nestedObjects)) {
    if (parentKey === "cta" || parentKey === "secondaryButton") {
      const text = childObj.text;
      const link = childObj.link;
      if (text && text.trim() && link && link.trim()) {
        const ctaObj = {
          text: text.trim(),
          link: link.trim(),
          target: childObj.target || "_self"
        };
        if (childObj.variant) {
          ctaObj.variant = childObj.variant;
        }
        result[parentKey] = ctaObj;
      }
    } else {
      result[parentKey] = childObj;
    }
  }
  return result;
}
export {
  getBlockComponent,
  getBlockComponents,
  hasBlock,
  normalizeBlockProps
};
