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

export const CalendarRootPropsSchema = z.object({
  value: z.string().optional().describe("Controlled selected date as ISO string (YYYY-MM-DD)"),
  defaultValue: z.string().optional().describe("Initial selected date (uncontrolled)"),
  month: z.number().optional().describe("Controlled displayed month (0-11)"),
  year: z.number().optional().describe("Controlled displayed year"),
  minDate: z.string().optional().describe("Earliest selectable date as ISO string"),
  maxDate: z.string().optional().describe("Latest selectable date as ISO string"),
  disabled: z.boolean().optional().describe("Whether the calendar is disabled"),
  locale: z.string().optional().describe("BCP 47 locale string for day/month names. Defaults to 'en-US'"),
  weekStartsOn: z.number().optional().describe("Day the week starts on (0=Sunday, 1=Monday). Defaults to 0"),
});

export interface CalendarRootProps extends z.infer<typeof CalendarRootPropsSchema> {
  onValueChange?: (date: string) => void;
  onMonthChange?: (month: number, year: number) => void;
  children: JSX.Element;
}

export interface CalendarHeaderProps extends JSX.HTMLAttributes<HTMLDivElement> { children: JSX.Element; }
export interface CalendarHeadingProps extends JSX.HTMLAttributes<HTMLHeadingElement> {}
export interface CalendarNavProps extends JSX.HTMLAttributes<HTMLDivElement> { children: JSX.Element; }
export interface CalendarPrevProps extends JSX.ButtonHTMLAttributes<HTMLButtonElement> { children?: JSX.Element; }
export interface CalendarNextProps extends JSX.ButtonHTMLAttributes<HTMLButtonElement> { children?: JSX.Element; }
export interface CalendarGridProps extends JSX.HTMLAttributes<HTMLTableElement> { children: JSX.Element; }
export interface CalendarGridHeadProps extends JSX.HTMLAttributes<HTMLTableSectionElement> {}
export interface CalendarGridBodyProps extends JSX.HTMLAttributes<HTMLTableSectionElement> {}
export interface CalendarCellProps extends JSX.HTMLAttributes<HTMLTableCellElement> { date: string; children?: JSX.Element; }

export const CalendarMeta: ComponentMeta = {
  name: "Calendar",
  description: "Month grid for date selection with keyboard navigation, locale support, and min/max constraints",
  parts: ["Root", "Header", "Heading", "Nav", "PrevButton", "NextButton", "Grid", "GridHead", "GridBody", "Cell"] as const,
  requiredParts: ["Root", "Grid", "GridBody", "Cell"] as const,
} as const;
