import { z, ZodType } from 'zod'; import { QuestionDefinition } from '../core'; const Dropdown = 'Dropdown' as const; export type DropdownComponentType = typeof Dropdown; interface DropdownOption { id: string; displayName: string; } export interface DropdownComponentDefinition extends QuestionDefinition { options: DropdownOption[]; placeholder?: string; } export const DropdownSchema = z.object({ questionId: z.string(), label: z.string(), placeholder: z.string().optional(), type: z.literal(Dropdown), options: z .array( z.object({ id: z.string(), displayName: z.string(), }), ) .min(2, { message: 'Dropdown component are required to contain at least 2 options', }) .refine( (val) => { const ids = val.map(({ id }) => id); return ids.length === new Set(ids).size; }, { message: 'Dropdown options are required to have unique ids', }, ), }) satisfies ZodType;