import { useState } from "react"; import { useFormContext } from "react-hook-form"; import { useBoolean } from "usehooks-ts"; import FormItem from "@/components/form/form-item"; import Card from "@/components/ui/card/card"; import { Checkbox } from "@/components/ui/checkbox/checkbox"; import { RadioGroup, RadioGroupItem, } from "@/components/ui/radio-button/radio-group"; import { useLocale } from "@/hooks/useLocale"; import CompanyBillingForm from "./company-billing-form"; import PersonBillingForm from "./person-billing-form"; export interface BillingInfoFormProps { prefix: string; open?: boolean; onChangeDiffrentBillingInfoValue?: (value: boolean) => void; } export interface IBillingInfoForm { billing: BillingType; name: string; surname: string; tc: string; email: string; country: { Id: number; }; city: string; companyTitle: string; companyTaxOffice: string; taxNo: string; address: string; } type BillingType = "person" | "company" | "companyWithTaxNo"; const BillingInfoForm = (props: BillingInfoFormProps) => { const boolean = useBoolean(props?.open); const methods = useFormContext(); const [billingTypeState, setBillingTypeState] = useState( "person" as BillingType, ); const { t } = useLocale(); return (
{({ field }) => ( { props.onChangeDiffrentBillingInfoValue?.( Boolean(check.valueOf()), ); boolean.setValue(Boolean(check.valueOf())); field.onChange(check.valueOf()); }} /> )}
{boolean.value && (

{t( "When your reservation is completed, we will send you your invoice via e-mail, please make sure that you fill in the information below completely and correctly.", )}


{({ field }) => ( { setBillingTypeState(value.valueOf() as BillingType); field.onChange(value.valueOf()); }} > )}
{(methods.watch(`${props.prefix}-billing-type`) || billingTypeState) === "person" && ( )} {["company", "companyWithTaxNo"].includes( methods.watch(`${props.prefix}-billing-type`) || billingTypeState, ) && ( )}
)}
); }; export default BillingInfoForm;