"use client";
'use strict';

const z = require('zod');
const button = require('../../../../../ui/src/components/button.cjs');
const badge = require('../../../../../ui/src/components/badge.cjs');
const accordion = require('../../../../../ui/src/components/accordion.cjs');
const card = require('../../../../../ui/src/components/card.cjs');
const separator = require('../../../../../ui/src/components/separator.cjs');
const flexbox = require('../../../../../ui/src/components/ui-builder/components/flexbox.cjs');
const grid = require('../../../../../ui/src/components/ui-builder/components/grid.cjs');
const codePanel = require('../../../../../ui/src/components/ui-builder/components/code-panel.cjs');
const markdown = require('../../../../../ui/src/components/ui-builder/components/markdown.cjs');
const icon = require('../../../../../ui/src/components/ui-builder/components/icon.cjs');
const formFieldOverrides = require('../../../../../ui/src/lib/ui-builder/registry/form-field-overrides.cjs');

const primitiveComponentDefinitions = {
  a: {
    schema: z.z.object({
      className: z.z.string().optional(),
      children: z.z.any().optional(),
      href: z.z.string().optional(),
      target: z.z.enum(["_blank", "_self", "_parent", "_top"]).optional().default("_self"),
      rel: z.z.enum(["noopener", "noreferrer", "nofollow"]).optional(),
      title: z.z.string().optional(),
      download: z.z.boolean().optional().default(false),
      onClick: z.z.any().optional()
    }),
    fieldOverrides: {
      ...formFieldOverrides.commonFieldOverrides(),
      onClick: () => formFieldOverrides.functionPropFieldOverrides("onClick")
    }
  },
  button: {
    schema: z.z.object({
      className: z.z.string().optional(),
      children: z.z.any().optional(),
      type: z.z.enum(["button", "submit", "reset"]).optional().default("button"),
      disabled: z.z.boolean().optional().default(false),
      onClick: z.z.any().optional()
    }),
    defaultChildren: "Button",
    fieldOverrides: {
      ...formFieldOverrides.commonFieldOverrides(),
      onClick: () => formFieldOverrides.functionPropFieldOverrides("onClick")
    }
  },
  form: {
    schema: z.z.object({
      className: z.z.string().optional(),
      children: z.z.any().optional(),
      action: z.z.string().optional(),
      method: z.z.enum(["get", "post"]).optional(),
      onSubmit: z.z.any().optional()
    }),
    fieldOverrides: {
      ...formFieldOverrides.commonFieldOverrides(),
      onSubmit: () => formFieldOverrides.functionPropFieldOverrides("onSubmit")
    }
  },
  input: {
    schema: z.z.object({
      className: z.z.string().optional(),
      type: z.z.enum([
        "text",
        "password",
        "email",
        "number",
        "tel",
        "url",
        "search",
        "date",
        "time",
        "hidden"
      ]).optional().default("text"),
      name: z.z.string().optional(),
      placeholder: z.z.string().optional(),
      defaultValue: z.z.string().optional(),
      disabled: z.z.boolean().optional().default(false),
      required: z.z.boolean().optional().default(false),
      onChange: z.z.any().optional(),
      onBlur: z.z.any().optional(),
      onFocus: z.z.any().optional()
    }),
    fieldOverrides: {
      className: (layer) => formFieldOverrides.classNameFieldOverrides(),
      onChange: () => formFieldOverrides.functionPropFieldOverrides("onChange"),
      onBlur: () => formFieldOverrides.functionPropFieldOverrides("onBlur"),
      onFocus: () => formFieldOverrides.functionPropFieldOverrides("onFocus")
    }
  },
  textarea: {
    schema: z.z.object({
      className: z.z.string().optional(),
      name: z.z.string().optional(),
      placeholder: z.z.string().optional(),
      defaultValue: z.z.string().optional(),
      rows: z.z.coerce.number().optional(),
      disabled: z.z.boolean().optional().default(false),
      required: z.z.boolean().optional().default(false),
      onChange: z.z.any().optional(),
      onBlur: z.z.any().optional(),
      onFocus: z.z.any().optional()
    }),
    fieldOverrides: {
      className: (layer) => formFieldOverrides.classNameFieldOverrides(),
      onChange: () => formFieldOverrides.functionPropFieldOverrides("onChange"),
      onBlur: () => formFieldOverrides.functionPropFieldOverrides("onBlur"),
      onFocus: () => formFieldOverrides.functionPropFieldOverrides("onFocus")
    }
  },
  select: {
    schema: z.z.object({
      className: z.z.string().optional(),
      children: z.z.any().optional(),
      name: z.z.string().optional(),
      defaultValue: z.z.string().optional(),
      disabled: z.z.boolean().optional().default(false),
      required: z.z.boolean().optional().default(false),
      onChange: z.z.any().optional()
    }),
    fieldOverrides: {
      ...formFieldOverrides.commonFieldOverrides(),
      onChange: () => formFieldOverrides.functionPropFieldOverrides("onChange")
    }
  },
  label: {
    schema: z.z.object({
      className: z.z.string().optional(),
      children: z.z.any().optional(),
      htmlFor: z.z.string().optional(),
      onClick: z.z.any().optional()
    }),
    fieldOverrides: {
      ...formFieldOverrides.commonFieldOverrides(),
      onClick: () => formFieldOverrides.functionPropFieldOverrides("onClick")
    }
  },
  img: {
    schema: z.z.object({
      className: z.z.string().optional(),
      src: z.z.string().default("https://placehold.co/200"),
      alt: z.z.string().optional(),
      width: z.z.coerce.number().optional(),
      height: z.z.coerce.number().optional(),
      onClick: z.z.any().optional()
    }),
    fieldOverrides: {
      className: (layer) => formFieldOverrides.classNameFieldOverrides(),
      onClick: () => formFieldOverrides.functionPropFieldOverrides("onClick")
    }
  },
  div: {
    schema: z.z.object({
      className: z.z.string().optional(),
      children: z.z.any().optional(),
      onClick: z.z.any().optional()
    }),
    fieldOverrides: {
      ...formFieldOverrides.commonFieldOverrides(),
      onClick: () => formFieldOverrides.functionPropFieldOverrides("onClick")
    }
  },
  iframe: {
    schema: z.z.object({
      className: z.z.string().optional(),
      src: z.z.string().default(
        "https://www.youtube.com/embed/dQw4w9WgXcQ?si=oc74qTYUBuCsOJwL"
      ),
      title: z.z.string().optional(),
      width: z.z.coerce.number().optional(),
      height: z.z.coerce.number().optional(),
      frameBorder: z.z.number().optional(),
      allowFullScreen: z.z.boolean().optional(),
      allow: z.z.string().optional(),
      referrerPolicy: z.z.enum([
        "no-referrer",
        "no-referrer-when-downgrade",
        "origin",
        "origin-when-cross-origin",
        "same-origin",
        "strict-origin",
        "strict-origin-when-cross-origin",
        "unsafe-url"
      ]).optional()
    }),
    fieldOverrides: {
      className: (layer) => formFieldOverrides.classNameFieldOverrides()
    }
  },
  span: {
    schema: z.z.object({
      className: z.z.string().optional(),
      children: z.z.string().optional(),
      onClick: z.z.any().optional()
    }),
    defaultChildren: "Text",
    fieldOverrides: {
      className: (layer) => formFieldOverrides.classNameFieldOverrides(),
      children: (layer) => formFieldOverrides.childrenAsTextareaFieldOverrides(layer),
      onClick: () => formFieldOverrides.functionPropFieldOverrides("onClick")
    }
  },
  h1: {
    schema: z.z.object({
      className: z.z.string().optional(),
      children: z.z.string().optional(),
      onClick: z.z.any().optional()
    }),
    defaultChildren: "Heading 1",
    fieldOverrides: {
      ...formFieldOverrides.commonFieldOverrides(),
      children: (layer) => formFieldOverrides.childrenAsTextareaFieldOverrides(layer),
      onClick: () => formFieldOverrides.functionPropFieldOverrides("onClick")
    }
  },
  h2: {
    schema: z.z.object({
      className: z.z.string().optional(),
      children: z.z.string().optional(),
      onClick: z.z.any().optional()
    }),
    defaultChildren: "Heading 2",
    fieldOverrides: {
      ...formFieldOverrides.commonFieldOverrides(),
      children: (layer) => formFieldOverrides.childrenAsTextareaFieldOverrides(layer),
      onClick: () => formFieldOverrides.functionPropFieldOverrides("onClick")
    }
  },
  h3: {
    schema: z.z.object({
      className: z.z.string().optional(),
      children: z.z.string().optional(),
      onClick: z.z.any().optional()
    }),
    defaultChildren: "Heading 3",
    fieldOverrides: {
      ...formFieldOverrides.commonFieldOverrides(),
      children: (layer) => formFieldOverrides.childrenAsTextareaFieldOverrides(layer),
      onClick: () => formFieldOverrides.functionPropFieldOverrides("onClick")
    }
  },
  p: {
    schema: z.z.object({
      className: z.z.string().optional(),
      children: z.z.string().optional(),
      onClick: z.z.any().optional()
    }),
    defaultChildren: "Paragraph text",
    fieldOverrides: {
      ...formFieldOverrides.commonFieldOverrides(),
      children: (layer) => formFieldOverrides.childrenAsTextareaFieldOverrides(layer),
      onClick: () => formFieldOverrides.functionPropFieldOverrides("onClick")
    }
  },
  li: {
    schema: z.z.object({
      className: z.z.string().optional(),
      children: z.z.string().optional(),
      onClick: z.z.any().optional()
    }),
    defaultChildren: "List item",
    fieldOverrides: {
      ...formFieldOverrides.commonFieldOverrides(),
      children: (layer) => formFieldOverrides.childrenAsTextareaFieldOverrides(layer),
      onClick: () => formFieldOverrides.functionPropFieldOverrides("onClick")
    }
  },
  ul: {
    schema: z.z.object({
      className: z.z.string().optional(),
      children: z.z.any().optional(),
      onClick: z.z.any().optional()
    }),
    fieldOverrides: {
      ...formFieldOverrides.commonFieldOverrides(),
      onClick: () => formFieldOverrides.functionPropFieldOverrides("onClick")
    }
  },
  ol: {
    schema: z.z.object({
      className: z.z.string().optional(),
      children: z.z.any().optional(),
      onClick: z.z.any().optional()
    }),
    fieldOverrides: {
      ...formFieldOverrides.commonFieldOverrides(),
      onClick: () => formFieldOverrides.functionPropFieldOverrides("onClick")
    }
  }
};
const complexComponentDefinitions = {
  Button: {
    component: button.Button,
    schema: z.z.object({
      className: z.z.string().optional(),
      children: z.z.any().optional(),
      asChild: z.z.boolean().optional(),
      variant: z.z.enum([
        "default",
        "destructive",
        "outline",
        "secondary",
        "ghost",
        "link"
      ]).default("default"),
      size: z.z.enum(["default", "sm", "lg", "icon"]).default("default"),
      onClick: z.z.any().optional()
    }),
    from: "@/components/ui/button",
    defaultChildren: [
      {
        id: "button-text",
        type: "span",
        name: "span",
        props: {},
        children: "Button"
      }
    ],
    fieldOverrides: {
      ...formFieldOverrides.commonFieldOverrides(),
      onClick: () => formFieldOverrides.functionPropFieldOverrides("onClick")
    }
  },
  Badge: {
    component: badge.Badge,
    schema: z.z.object({
      className: z.z.string().optional(),
      children: z.z.any().optional(),
      variant: z.z.enum(["default", "secondary", "destructive", "outline"]).default("default"),
      onClick: z.z.any().optional()
    }),
    from: "@/components/ui/badge",
    defaultChildren: [
      {
        id: "badge-text",
        type: "span",
        name: "span",
        props: {},
        children: "Badge"
      }
    ],
    fieldOverrides: {
      ...formFieldOverrides.commonFieldOverrides(),
      onClick: () => formFieldOverrides.functionPropFieldOverrides("onClick")
    }
  },
  Flexbox: {
    component: flexbox.Flexbox,
    schema: z.z.object({
      className: z.z.string().optional(),
      children: z.z.any().optional(),
      direction: z.z.enum(["row", "column", "rowReverse", "columnReverse"]).default("row"),
      justify: z.z.enum(["start", "end", "center", "between", "around", "evenly"]).default("start"),
      align: z.z.enum(["start", "end", "center", "baseline", "stretch"]).default("start"),
      wrap: z.z.enum(["wrap", "nowrap", "wrapReverse"]).default("nowrap"),
      gap: z.z.preprocess(
        (val) => typeof val === "number" ? String(val) : val,
        z.z.enum(["0", "1", "2", "4", "8"]).default("1")
      ).transform(Number)
    }),
    from: "@/components/ui/ui-builder/flexbox",
    fieldOverrides: formFieldOverrides.commonFieldOverrides()
  },
  Grid: {
    component: grid.Grid,
    schema: z.z.object({
      className: z.z.string().optional(),
      children: z.z.any().optional(),
      columns: z.z.enum(["auto", "1", "2", "3", "4", "5", "6", "7", "8"]).default("1"),
      autoRows: z.z.enum(["none", "min", "max", "fr"]).default("none"),
      justify: z.z.enum(["start", "end", "center", "between", "around", "evenly"]).default("start"),
      align: z.z.enum(["start", "end", "center", "baseline", "stretch"]).default("start"),
      templateRows: z.z.enum(["none", "1", "2", "3", "4", "5", "6"]).default("none").transform((val) => val === "none" ? val : Number(val)),
      gap: z.z.preprocess(
        (val) => typeof val === "number" ? String(val) : val,
        z.z.enum(["0", "1", "2", "4", "8"]).default("0")
      ).transform(Number)
    }),
    from: "@/components/ui/ui-builder/grid",
    fieldOverrides: formFieldOverrides.commonFieldOverrides()
  },
  CodePanel: {
    component: codePanel.CodePanel,
    schema: z.z.object({
      className: z.z.string().optional()
    }),
    from: "@/components/ui/ui-builder/code-panel",
    fieldOverrides: {
      className: (layer) => formFieldOverrides.classNameFieldOverrides()
    }
  },
  Markdown: {
    component: markdown.Markdown,
    schema: z.z.object({
      className: z.z.string().optional(),
      children: z.z.any().optional()
    }),
    from: "@/components/ui/ui-builder/markdown",
    fieldOverrides: {
      className: (layer) => formFieldOverrides.classNameFieldOverrides(),
      children: (layer) => formFieldOverrides.childrenAsTipTapFieldOverrides(layer)
    }
  },
  Icon: {
    component: icon.Icon,
    schema: z.z.object({
      className: z.z.string().optional(),
      iconName: z.z.enum([...icon.iconNames]).default("Image"),
      size: z.z.enum(["small", "medium", "large"]).default("medium"),
      color: z.z.enum([
        "accent",
        "accentForeground",
        "primary",
        "primaryForeground",
        "secondary",
        "secondaryForeground",
        "destructive",
        "destructiveForeground",
        "muted",
        "mutedForeground",
        "background",
        "foreground"
      ]).optional(),
      rotate: z.z.enum(["none", "90", "180", "270"]).default("none")
    }),
    from: "@/components/ui/ui-builder/icon",
    fieldOverrides: {
      className: (layer) => formFieldOverrides.classNameFieldOverrides(),
      iconName: (layer) => formFieldOverrides.iconNameFieldOverrides(layer)
    }
  },
  Accordion: {
    component: accordion.Accordion,
    schema: z.z.object({
      className: z.z.string().optional(),
      children: z.z.any().optional(),
      type: z.z.enum(["single", "multiple"]).default("single"),
      collapsible: z.z.boolean().optional(),
      onValueChange: z.z.any().optional()
    }),
    from: "@/components/ui/accordion",
    defaultChildren: [
      {
        id: "acc-item-1",
        type: "AccordionItem",
        name: "AccordionItem",
        props: { value: "item-1" },
        children: [
          {
            id: "acc-trigger-1",
            type: "AccordionTrigger",
            name: "AccordionTrigger",
            props: {},
            children: [
              {
                id: "acc-trigger-1-text",
                type: "span",
                name: "span",
                props: {},
                children: "Accordion Item #1"
              }
            ]
          },
          {
            id: "acc-content-1",
            type: "AccordionContent",
            name: "AccordionContent",
            props: {},
            children: [
              {
                id: "acc-content-1-text",
                type: "span",
                name: "span",
                props: {},
                children: "Accordion Content Text"
              }
            ]
          }
        ]
      },
      {
        id: "acc-item-2",
        type: "AccordionItem",
        name: "AccordionItem",
        props: { value: "item-2" },
        children: [
          {
            id: "acc-trigger-2",
            type: "AccordionTrigger",
            name: "AccordionTrigger",
            props: {},
            children: [
              {
                id: "acc-trigger-2-text",
                type: "span",
                name: "span",
                props: {},
                children: "Accordion Item #2"
              }
            ]
          },
          {
            id: "acc-content-2",
            type: "AccordionContent",
            name: "AccordionContent",
            props: {},
            children: [
              {
                id: "acc-content-2-text",
                type: "span",
                name: "span",
                props: {},
                children: "Accordion Content Text"
              }
            ]
          }
        ]
      }
    ],
    fieldOverrides: {
      ...formFieldOverrides.commonFieldOverrides(),
      onValueChange: () => formFieldOverrides.functionPropFieldOverrides("onValueChange")
    }
  },
  AccordionItem: {
    component: accordion.AccordionItem,
    schema: z.z.object({
      className: z.z.string().optional(),
      children: z.z.any().optional(),
      value: z.z.string().default("item-1")
    }),
    from: "@/components/ui/accordion",
    childOf: ["Accordion"],
    defaultChildren: [
      {
        id: "acc-trigger-default",
        type: "AccordionTrigger",
        name: "AccordionTrigger",
        props: {},
        children: [
          {
            id: "acc-trigger-default-text",
            type: "span",
            name: "span",
            props: {},
            children: "Accordion Item"
          }
        ]
      },
      {
        id: "acc-content-default",
        type: "AccordionContent",
        name: "AccordionContent",
        props: {},
        children: [
          {
            id: "acc-content-default-text",
            type: "span",
            name: "span",
            props: {},
            children: "Accordion Content"
          }
        ]
      }
    ],
    fieldOverrides: formFieldOverrides.commonFieldOverrides()
  },
  AccordionTrigger: {
    component: accordion.AccordionTrigger,
    schema: z.z.object({
      className: z.z.string().optional(),
      children: z.z.any().optional(),
      onClick: z.z.any().optional()
    }),
    from: "@/components/ui/accordion",
    childOf: ["AccordionItem"],
    fieldOverrides: {
      className: (layer) => formFieldOverrides.classNameFieldOverrides(),
      children: (layer) => formFieldOverrides.childrenFieldOverrides(layer),
      onClick: () => formFieldOverrides.functionPropFieldOverrides("onClick")
    }
  },
  AccordionContent: {
    component: accordion.AccordionContent,
    schema: z.z.object({
      className: z.z.string().optional(),
      children: z.z.any().optional()
    }),
    from: "@/components/ui/accordion",
    childOf: ["AccordionItem"],
    fieldOverrides: formFieldOverrides.commonFieldOverrides()
  },
  Card: {
    component: card.Card,
    schema: z.z.object({
      className: z.z.string().optional(),
      children: z.z.any().optional(),
      onClick: z.z.any().optional()
    }),
    from: "@/components/ui/card",
    defaultChildren: [
      {
        id: "card-header",
        type: "CardHeader",
        name: "CardHeader",
        props: {},
        children: [
          {
            id: "card-title",
            type: "CardTitle",
            name: "CardTitle",
            props: {},
            children: [
              {
                id: "card-title-text",
                type: "span",
                name: "span",
                props: {},
                children: "Card Title"
              }
            ]
          },
          {
            id: "card-description",
            type: "CardDescription",
            name: "CardDescription",
            props: {},
            children: [
              {
                id: "card-description-text",
                type: "span",
                name: "span",
                props: {},
                children: "Card Description"
              }
            ]
          }
        ]
      },
      {
        id: "card-content",
        type: "CardContent",
        name: "CardContent",
        props: {},
        children: [
          {
            id: "card-content-text",
            type: "span",
            name: "span",
            props: {},
            children: "Card Content"
          }
        ]
      },
      {
        id: "card-footer",
        type: "CardFooter",
        name: "CardFooter",
        props: {},
        children: [
          {
            id: "card-footer-text",
            type: "span",
            name: "span",
            props: {},
            children: "Card Footer"
          }
        ]
      }
    ],
    fieldOverrides: {
      ...formFieldOverrides.commonFieldOverrides(),
      onClick: () => formFieldOverrides.functionPropFieldOverrides("onClick")
    }
  },
  CardHeader: {
    component: card.CardHeader,
    schema: z.z.object({
      className: z.z.string().optional(),
      children: z.z.any().optional()
    }),
    from: "@/components/ui/card",
    childOf: ["Card"],
    fieldOverrides: formFieldOverrides.commonFieldOverrides()
  },
  CardTitle: {
    component: card.CardTitle,
    schema: z.z.object({
      className: z.z.string().optional(),
      children: z.z.any().optional()
    }),
    from: "@/components/ui/card",
    childOf: ["CardHeader"],
    fieldOverrides: formFieldOverrides.commonFieldOverrides()
  },
  CardDescription: {
    component: card.CardDescription,
    schema: z.z.object({
      className: z.z.string().optional(),
      children: z.z.any().optional()
    }),
    from: "@/components/ui/card",
    childOf: ["CardHeader"],
    fieldOverrides: formFieldOverrides.commonFieldOverrides()
  },
  CardContent: {
    component: card.CardContent,
    schema: z.z.object({
      className: z.z.string().optional(),
      children: z.z.any().optional()
    }),
    from: "@/components/ui/card",
    childOf: ["Card"],
    fieldOverrides: formFieldOverrides.commonFieldOverrides()
  },
  CardFooter: {
    component: card.CardFooter,
    schema: z.z.object({
      className: z.z.string().optional(),
      children: z.z.any().optional()
    }),
    from: "@/components/ui/card",
    childOf: ["Card"],
    fieldOverrides: formFieldOverrides.commonFieldOverrides()
  },
  Separator: {
    component: separator.Separator,
    schema: z.z.object({
      className: z.z.string().optional(),
      orientation: z.z.enum(["horizontal", "vertical"]).default("horizontal"),
      decorative: z.z.boolean().default(true)
    }),
    from: "@/components/ui/separator",
    fieldOverrides: {
      className: (layer) => formFieldOverrides.classNameFieldOverrides()
    }
  }
};
const defaultComponentRegistry = {
  ...primitiveComponentDefinitions,
  ...complexComponentDefinitions
};
function createComponentRegistry(components) {
  return components;
}

exports.complexComponentDefinitions = complexComponentDefinitions;
exports.createComponentRegistry = createComponentRegistry;
exports.defaultComponentRegistry = defaultComponentRegistry;
exports.primitiveComponentDefinitions = primitiveComponentDefinitions;
