import { z } from "zod";
const ctaSchema = z.object({
  text: z.string().min(1, "CTA text is required"),
  link: z.string().url("Must be a valid URL").or(z.string().startsWith("/")),
  target: z.enum(["_self", "_blank"]).default("_self")
});
const baseContentSchema = z.object({
  title: z.string().optional(),
  content: z.string().optional(),
  cta: ctaSchema.optional()
});
const backgroundColorOptions = [
  "transparent",
  "white",
  "gray-50",
  "gray-100",
  "gray-900",
  "primary",
  "primary-light",
  "primary-dark",
  "secondary",
  "accent"
];
const baseDesignSchema = z.object({
  backgroundColor: z.enum(backgroundColorOptions).default("transparent")
});
const baseAdvancedSchema = z.object({
  className: z.string().optional(),
  id: z.string().optional()
});
const baseBlockSchema = baseContentSchema.merge(baseDesignSchema).merge(baseAdvancedSchema);
function getBackgroundClasses(backgroundColor) {
  const bgMap = {
    transparent: "bg-transparent",
    white: "bg-white",
    "gray-50": "bg-gray-50",
    "gray-100": "bg-gray-100",
    "gray-900": "bg-gray-900 text-white",
    primary: "bg-primary text-primary-foreground",
    "primary-light": "bg-primary/10",
    "primary-dark": "bg-primary-dark text-white",
    secondary: "bg-secondary text-secondary-foreground",
    accent: "bg-accent text-accent-foreground"
  };
  return bgMap[backgroundColor || "transparent"];
}
function getSectionAttributes(props) {
  return {
    ...props.id && { id: props.id },
    ...props.className && { className: props.className }
  };
}
function buildSectionClasses(baseClasses, props) {
  const classes = [baseClasses];
  if (props.backgroundColor) {
    classes.push(getBackgroundClasses(props.backgroundColor));
  }
  if (props.className) {
    classes.push(props.className);
  }
  return classes.filter(Boolean).join(" ");
}
const baseContentFields = [
  {
    name: "title",
    label: "Title",
    type: "text",
    tab: "content",
    required: false,
    placeholder: "Enter section title...",
    helpText: "Main heading for this section"
  },
  {
    name: "content",
    label: "Content",
    type: "rich-text",
    tab: "content",
    required: false,
    placeholder: "Enter content...",
    helpText: "Rich text content for this section"
  },
  // CTA fields - grouped together in the UI
  {
    name: "cta.text",
    label: "Text",
    type: "text",
    tab: "content",
    required: false,
    placeholder: "Learn More",
    helpText: "Button text",
    group: "cta",
    groupLabel: "Call to Action"
  },
  {
    name: "cta.link",
    label: "Link",
    type: "url",
    tab: "content",
    required: false,
    placeholder: "/contact or https://...",
    helpText: "URL the button links to",
    group: "cta"
  },
  {
    name: "cta.target",
    label: "Open in",
    type: "select",
    tab: "content",
    required: false,
    default: "_self",
    helpText: "How the link opens",
    group: "cta",
    options: [
      { label: "Same window", value: "_self" },
      { label: "New tab", value: "_blank" }
    ]
  }
];
const baseDesignFields = [
  {
    name: "backgroundColor",
    label: "Background Color",
    type: "select",
    tab: "design",
    required: false,
    default: "transparent",
    description: "Section background color",
    options: backgroundColorOptions.map((color) => ({
      label: color.charAt(0).toUpperCase() + color.slice(1).replace("-", " "),
      value: color
    }))
  }
];
const baseAdvancedFields = [
  {
    name: "className",
    label: "CSS Class",
    type: "text",
    tab: "advanced",
    required: false,
    placeholder: "my-custom-class",
    description: "Custom CSS class(es) to add to the section",
    helpText: "Multiple classes can be separated by spaces"
  },
  {
    name: "id",
    label: "HTML ID",
    type: "text",
    tab: "advanced",
    required: false,
    placeholder: "my-section-id",
    description: "Unique identifier for this section",
    helpText: "Can be used for anchor links (#my-section-id)"
  }
];
const allBaseFields = [
  ...baseContentFields,
  ...baseDesignFields,
  ...baseAdvancedFields
];
function createBlockFieldDefinitions(blockSpecificFields) {
  const contentFields = [
    ...baseContentFields,
    ...blockSpecificFields.filter((f) => f.tab === "content")
  ];
  const designFields = [
    ...baseDesignFields,
    ...blockSpecificFields.filter((f) => f.tab === "design")
  ];
  const advancedFields = [
    ...baseAdvancedFields,
    ...blockSpecificFields.filter((f) => f.tab === "advanced")
  ];
  return [...contentFields, ...designFields, ...advancedFields];
}
function isBlockInstance(value) {
  if (typeof value !== "object" || value === null) return false;
  const block = value;
  return typeof block.id === "string" && typeof block.blockSlug === "string" && typeof block.props === "object" && block.props !== null;
}
function isBlockConfig(value) {
  if (typeof value !== "object" || value === null) return false;
  const config = value;
  return typeof config.slug === "string" && typeof config.name === "string" && typeof config.description === "string" && typeof config.category === "string" && Array.isArray(config.fieldDefinitions);
}
export {
  allBaseFields,
  backgroundColorOptions,
  baseAdvancedFields,
  baseAdvancedSchema,
  baseBlockSchema,
  baseContentFields,
  baseContentSchema,
  baseDesignFields,
  baseDesignSchema,
  buildSectionClasses,
  createBlockFieldDefinitions,
  ctaSchema,
  getBackgroundClasses,
  getSectionAttributes,
  isBlockConfig,
  isBlockInstance
};
