"use client"; import React, { useState } from "react"; import "react-phone-number-input/style.css"; import PhoneInput from "react-phone-number-input"; import { useToast } from "@/lib/toast-hook"; export default function Schedule({ onFormSubmit }) { const { showLoading, dismissToast, showSuccess, showError } = useToast(); const [formData, setFormData] = useState({ firstName: "", lastName: "", emailAddress: "", phoneNumber: "", companyName: "", websiteUrl: "", annualRevenue: "", learnFrom: "", additionalInfo: "", checkbox: false, }); const handleChange = (e) => { const { name, value, type, checked } = e.target; setFormData((prevState) => ({ ...prevState, [name]: type === "checkbox" ? checked : value, })); }; const handlePhoneChange = (value) => { setFormData((prevState) => ({ ...prevState, phoneNumber: value, })); }; const handleSubmit = async (e) => { const loadingToastId = showLoading("Submitting schedule request..."); e.preventDefault(); try { const response = await fetch("/api/schedule-send", { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify(formData), }); dismissToast(loadingToastId); if (response.ok) { showSuccess("Appointment Scheduled Successfully!"); document.cookie = `prospectClient=true; path=/; max-age=31536000`; onFormSubmit(); } else { showError("Something went wrong"); } } catch (error) { dismissToast(loadingToastId); showError( error instanceof Error ? error.message : "Something went wrong" ); } }; return (