"use client"; import { type ReactNode } from "react"; import * as z from "zod"; import { zodResolver } from "@hookform/resolvers/zod"; import { FieldErrors, useForm, FieldValues, DefaultValues, Path, } from "react-hook-form"; import { cn } from "@/lib/utils"; import Template from "./Template"; import { Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage, } from "@/components/ui/form"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select"; import { Textarea } from "@/components/ui/textarea"; import { Input } from "@/components/ui/input"; import { Button } from "@/components/ui/button"; import { Switch } from "@/components/ui/switch"; type FieldOptions = | "toggle" | "horizontal-tabs" | "input" | "text-area" | "custom"; type DefaultFieldType = { label: string; slug: keyof z.infer> & string; placeholder?: string; description?: string; lines?: number; styles?: string; value?: string | number | boolean; custom?: ReactNode; options?: { label: string; value: string; icon?: ReactNode }[]; }; type FieldType = DefaultFieldType & ( | { type: "select"; options: { label: string; value: string; icon?: ReactNode }[]; } | { type: FieldOptions; } ); type FormModalProps = { title: string; fields: FieldType[]; errors?: FieldErrors; isSubmitting?: boolean; cta: { text: string; }; defaultValues?: Partial>>; onSubmit: (props: z.infer>) => any; formSchema: z.Schema; }; export default function FormModal({ title, fields, cta, errors, isSubmitting, formSchema, defaultValues, onSubmit, }: FormModalProps) { type FormDataType = z.infer; const form = useForm({ resolver: zodResolver(formSchema), defaultValues: defaultValues as DefaultValues, mode: "onChange", }); return (