import { z } from "zod/v4";
import type { JSX } from "solid-js";
import type { ComponentMeta } from "../../meta";

export const DropdownMenuRootPropsSchema = z.object({
  open: z.boolean().optional().describe("Controlled open state"),
  defaultOpen: z.boolean().optional().describe("Initial open state (uncontrolled)"),
});

export interface DropdownMenuRootProps extends z.infer<typeof DropdownMenuRootPropsSchema> {
  onOpenChange?: (open: boolean) => void;
  children: JSX.Element;
}

export const DropdownMenuItemPropsSchema = z.object({
  disabled: z.boolean().optional().describe("Whether this item is disabled"),
  textValue: z.string().optional().describe("Accessible text used for typeahead matching"),
  closeOnSelect: z.boolean().optional().describe("Whether the menu closes when this item is selected"),
});

export interface DropdownMenuItemProps extends z.infer<typeof DropdownMenuItemPropsSchema>, JSX.HTMLAttributes<HTMLDivElement> {
  value: string;
  onSelect?: () => void;
  children?: JSX.Element;
}

export const DropdownMenuMeta: ComponentMeta = {
  name: "DropdownMenu",
  description: "Menu of actions triggered by a button, with keyboard navigation, grouping, and sub-menus",
  parts: ["Root", "Trigger", "Portal", "Content", "Item", "Group", "GroupLabel", "Separator", "Sub", "SubTrigger", "SubContent"] as const,
  requiredParts: ["Root", "Trigger", "Content"] as const,
} as const;
