"use client" import { cx } from "class-variance-authority" import { Button } from "react-aria-components" import { useWatch } from "react-hook-form" import { useIntl } from "react-intl" import { shortDateFormat } from "@scandic-hotels/common/constants/dateFormats" import { dt } from "@scandic-hotels/common/dt" import { Divider } from "@scandic-hotels/design-system/Divider" import { MaterialIcon } from "@scandic-hotels/design-system/Icons/MaterialIcon" import SkeletonShimmer from "@scandic-hotels/design-system/SkeletonShimmer" import { Typography } from "@scandic-hotels/design-system/Typography" import useLang from "../../../hooks/useLang" import styles from "./button.module.css" import type { BookingWidgetSchema } from "../Client" type BookingWidgetToggleButtonProps = { openMobileSearch: () => void } export default function MobileToggleButton({ openMobileSearch, }: BookingWidgetToggleButtonProps) { const intl = useIntl() const lang = useLang() const date = useWatch({ name: "date" }) const rooms = useWatch({ name: "rooms" }) const searchTerm = useWatch({ name: "search" }) const selectedSearchTerm = useWatch({ name: "selectedSearch", }) const selectedFromDate = dt(date.fromDate) .locale(lang) .format(shortDateFormat[lang]) const selectedToDate = dt(date.toDate) .locale(lang) .format(shortDateFormat[lang]) const locationAndDateIsSet = searchTerm && date const totalNights = dt(date.toDate).diff(dt(date.fromDate), "days") const totalRooms = rooms.length const totalAdults = rooms.reduce((acc, room) => { if (room.adults) { acc = acc + room.adults } return acc }, 0) const totalChildren = rooms.reduce((acc, room) => { if (room.childrenInRoom) { acc = acc + room.childrenInRoom.length } return acc }, 0) const totalNightsMsg = intl.formatMessage( { id: "booking.numberOfNights", defaultMessage: "{totalNights, plural, one {# night} other {# nights}}", }, { totalNights } ) const totalAdultsMsg = intl.formatMessage( { id: "booking.numberOfAdults", defaultMessage: "{adults, plural, one {# adult} other {# adults}}", }, { adults: totalAdults } ) const totalChildrenMsg = intl.formatMessage( { id: "booking.numberOfChildren", defaultMessage: "{children, plural, one {# child} other {# children}}", }, { children: totalChildren } ) const totalRoomsMsg = intl.formatMessage( { id: "booking.numberOfRooms", defaultMessage: "{totalRooms, plural, one {# room} other {# rooms}}", }, { totalRooms } ) const totalDetails = [totalAdultsMsg] if (totalChildren > 0) { totalDetails.push(totalChildrenMsg) } totalDetails.push(totalRoomsMsg) return ( ) } export function MobileToggleButtonSkeleton() { const intl = useIntl() return (
{intl.formatMessage({ id: "bookingWidget.label.whereTo", defaultMessage: "Where to?", })} {intl.formatMessage( { id: "booking.numberOfNights", defaultMessage: "{totalNights, plural, one {# night} other {# nights}}", }, { totalNights: 0 } )}
) }