"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 MediaContent from "@/components/shared/MediaContent"; import { cls, shouldUseInvertedText } from "@/lib/utils"; import { useTheme } from "@/providers/themeProvider/ThemeProvider"; import { useButtonAnimation } from "@/components/hooks/useButtonAnimation"; import { getButtonProps } from "@/lib/buttonUtils"; import type { AnimationType } from "@/components/text/types"; import type { ButtonAnimationType } from "@/types/button"; import {sendContactEmail} from "@/utils/sendContactEmail"; 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 ContactSplitFormProps { title: string; description: string; inputs: InputField[]; textarea?: TextareaField; useInvertedBackground: boolean; imageSrc?: string; videoSrc?: string; imageAlt?: string; videoAriaLabel?: string; mediaPosition?: "left" | "right"; mediaAnimation: ButtonAnimationType; buttonText?: string; onSubmit?: (data: Record) => void; ariaLabel?: string; className?: string; containerClassName?: string; contentClassName?: string; formCardClassName?: string; titleClassName?: string; descriptionClassName?: string; buttonClassName?: string; buttonTextClassName?: string; mediaWrapperClassName?: string; mediaClassName?: string; } const ContactSplitForm = ({ title, description, inputs, textarea, useInvertedBackground, imageSrc, videoSrc, imageAlt = "", videoAriaLabel = "Contact section video", mediaPosition = "right", mediaAnimation, buttonText = "Submit", onSubmit, ariaLabel = "Contact section", className = "", containerClassName = "", contentClassName = "", formCardClassName = "", titleClassName = "", descriptionClassName = "", buttonClassName = "", buttonTextClassName = "", mediaWrapperClassName = "", mediaClassName = "", }: ContactSplitFormProps) => { const theme = useTheme(); const shouldUseLightText = shouldUseInvertedText(useInvertedBackground, theme.cardStyle); const { containerRef: mediaContainerRef } = useButtonAnimation({ animationType: mediaAnimation }); // Validate minimum inputs requirement if (inputs.length < 2) { throw new Error("ContactSplitForm 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 = async (e: React.FormEvent) => { e.preventDefault(); try { await sendContactEmail({ formData }); console.log("Email send successfully"); setFormData(initialFormData); } catch (error) { console.error("Failed to send email:", error); } }; const getButtonConfigProps = () => { if (theme.defaultButtonVariant === "hover-bubble") { return { bgClassName: "w-full" }; } if (theme.defaultButtonVariant === "icon-arrow") { return { className: "justify-between" }; } return {}; }; const formContent = (
{inputs.map((input) => ( setFormData({ ...formData, [input.name]: value })} required={input.required} ariaLabel={input.placeholder} className={input.className} /> ))} {textarea && (