// packages/core/src/components/dialog/dialog.props.ts
import { z } from "zod/v4";
import type { Component, JSX } from "solid-js";
import type { ComponentMeta } from "../../meta";

export const DialogRootPropsSchema = z.object({
  open: z.boolean().optional().describe("Controlled open state"),
  defaultOpen: z.boolean().optional().describe("Initial open state (uncontrolled)"),
  modal: z.boolean().optional().describe("Whether to trap focus and add backdrop. Defaults to true"),
});

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

export const DialogContentPropsSchema = z.object({
  forceMount: z.boolean().optional().describe("Force mount content even when closed, useful for animations"),
});

export interface DialogContentProps
  extends z.infer<typeof DialogContentPropsSchema>,
    Omit<JSX.DialogHtmlAttributes<HTMLDialogElement>, keyof z.infer<typeof DialogContentPropsSchema>> {
  onOpenAutoFocus?: (event: Event) => void;
  onCloseAutoFocus?: (event: Event) => void;
  children?: JSX.Element;
}

export interface DialogTriggerProps extends Omit<JSX.HTMLAttributes<HTMLButtonElement>, "children"> {
  as?: string | Component;
  children?: JSX.Element | ((props: JSX.HTMLAttributes<HTMLElement>) => JSX.Element);
}

export interface DialogTitleProps extends JSX.HTMLAttributes<HTMLHeadingElement> {
  children?: JSX.Element;
}

export interface DialogDescriptionProps extends JSX.HTMLAttributes<HTMLParagraphElement> {
  children?: JSX.Element;
}

export interface DialogCloseProps extends JSX.HTMLAttributes<HTMLButtonElement> {
  as?: string | Component;
  children?: JSX.Element;
}

export interface DialogOverlayProps extends JSX.HTMLAttributes<HTMLDivElement> {
  forceMount?: boolean;
}

export interface DialogPortalProps {
  /** Override the portal target container. */
  target?: Element | null;
  children: JSX.Element;
}

export const DialogMeta: ComponentMeta = {
  name: "Dialog",
  description: "Modal overlay that interrupts the user with important content requiring acknowledgment",
  parts: ["Root", "Trigger", "Portal", "Overlay", "Content", "Title", "Description", "Close"] as const,
  requiredParts: ["Root", "Content", "Title"] as const,
} as const;
