"use client" import { zodResolver } from "@hookform/resolvers/zod" import { useCallback, useEffect } from "react" import { FormProvider, useForm } from "react-hook-form" import { useIntl } from "react-intl" import { BreakfastBuffetIcon, NoBreakfastBuffetIcon, } from "@scandic-hotels/design-system/Icons" import { useEnterDetailsStore } from "@/stores/enter-details" import RadioCard from "@/components/TempDesignSystem/Form/RadioCard" import Body from "@/components/TempDesignSystem/Text/Body" import { useRoomContext } from "@/contexts/Details/Room" import { formatPrice } from "@/utils/numberFormatting" import { breakfastFormSchema } from "./schema" import styles from "./breakfast.module.css" import type { BreakfastFormSchema } from "@/types/components/hotelReservation/breakfast" import { BreakfastPackageEnum } from "@/types/enums/breakfast" export default function Breakfast() { const intl = useIntl() const packages = useEnterDetailsStore((state) => state.breakfastPackages) const { actions: { updateBreakfast }, room, } = useRoomContext() const hasChildrenInRoom = !!room.childrenInRoom?.length const totalPriceForNoBreakfast = 0 const breakfastSelection = room?.breakfast ? room.breakfast.code : room?.breakfast === false ? "false" : undefined const methods = useForm({ defaultValues: breakfastSelection ? { breakfast: breakfastSelection } : undefined, criteriaMode: "all", mode: "all", resolver: zodResolver(breakfastFormSchema), reValidateMode: "onChange", }) const onSubmit = useCallback( (values: BreakfastFormSchema) => { const pkg = packages?.find((p) => p.code === values.breakfast) if (pkg) { updateBreakfast(pkg) } else { updateBreakfast(false) } }, [packages, updateBreakfast] ) useEffect(() => { if (methods.formState.isSubmitting) { return } methods.watch(() => methods.handleSubmit(onSubmit)()) }, [methods, onSubmit]) return (
{hasChildrenInRoom ? ( {intl.formatMessage({ id: "Children's breakfast is always free as part of the adult's breakfast.", })} ) : null}
{packages?.map((pkg) => ( ))}
) }