"use client"
import { useFormContext } from "react-hook-form"
import { useIntl } from "react-intl"
import Caption from "@scandic-hotels/design-system/Caption"
import Stepper from "@scandic-hotels/design-system/Stepper"
import ChildInfoSelector from "./ChildInfoSelector"
import styles from "./child-selector.module.css"
import type { Child } from "@scandic-hotels/trpc/types/child"
type ChildSelectorProps = {
roomIndex: number
currentAdults: number
currentChildren: Child[]
childrenInAdultsBed: number
}
export default function ChildSelector({
roomIndex = 0,
currentAdults,
childrenInAdultsBed,
currentChildren,
}: ChildSelectorProps) {
const intl = useIntl()
const childrenLabel = intl.formatMessage({
id: "common.children",
defaultMessage: "Children",
})
const { setValue } = useFormContext()
function increaseChildrenCount(roomIndex: number) {
if (currentChildren.length < 5) {
setValue(
`rooms.${roomIndex}.childrenInRoom.${currentChildren.length}`,
{
age: undefined,
bed: undefined,
},
{ shouldDirty: true }
)
}
}
function decreaseChildrenCount(roomIndex: number) {
if (currentChildren.length > 0) {
currentChildren.pop()
setValue(`rooms.${roomIndex}.childrenInRoom`, currentChildren, {
shouldDirty: true,
})
}
}
return (
<>
{childrenLabel}
{
decreaseChildrenCount(roomIndex)
}}
handleOnIncrease={() => {
increaseChildrenCount(roomIndex)
}}
disableDecrease={currentChildren.length == 0}
disableIncrease={currentChildren.length == 5}
/>
{currentChildren.map((child, index) => (
))}
>
)
}