"use client"; import { useState } from "react"; import TextAnimation from "@/components/text/TextAnimation"; import Button from "@/components/button/Button"; import Input from "@/components/form/Input"; import Textarea from "@/components/form/Textarea"; import { cls, shouldUseInvertedText } from "@/lib/utils"; import { useTheme } from "@/providers/themeProvider/ThemeProvider"; import { getButtonProps } from "@/lib/buttonUtils"; import type { AnimationType } from "@/components/text/types"; export interface InputField { name: string; type: string; placeholder: string; required?: boolean; className?: string; } export interface TextareaField { name: string; placeholder: string; rows?: number; required?: boolean; className?: string; } interface ContactCenterFormProps { title: string; description: string; inputs: InputField[]; textarea?: TextareaField; useInvertedBackground: "noInvert" | "invertDefault"; buttonText?: string; onSubmit?: (data: Record) => void; ariaLabel?: string; className?: string; containerClassName?: string; contentClassName?: string; titleClassName?: string; descriptionClassName?: string; buttonClassName?: string; buttonTextClassName?: string; } const ContactCenterForm = ({ title, description, inputs, textarea, useInvertedBackground, buttonText = "Submit", onSubmit, ariaLabel = "Contact section", className = "", containerClassName = "", contentClassName = "", titleClassName = "", descriptionClassName = "", buttonClassName = "", buttonTextClassName = "", }: ContactCenterFormProps) => { const theme = useTheme(); const shouldUseLightText = shouldUseInvertedText(useInvertedBackground, theme.cardStyle); // Validate minimum inputs requirement if (inputs.length < 2) { throw new Error("ContactCenterForm requires at least 2 inputs"); } // Initialize form data dynamically const initialFormData: Record = {}; inputs.forEach(input => { initialFormData[input.name] = ""; }); if (textarea) { initialFormData[textarea.name] = ""; } const [formData, setFormData] = useState(initialFormData); const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); if (onSubmit) { onSubmit(formData); } }; return (
{inputs.map((input) => ( setFormData({ ...formData, [input.name]: value })} required={input.required} ariaLabel={input.placeholder} className={input.className} /> ))} {textarea && (