import { create } from "zustand" interface RoomDetails { id: string roomName: string roomTypeCode: string rateDefinition: { breakfastIncluded: boolean cancellationRule: string | null cancellationText: string | null generalTerms: string[] isMemberRate: boolean mustBeGuaranteed: boolean rateCode: string | null title: string | null } isMainBooking?: boolean } interface MyStayRoomDetailsState { rooms: RoomDetails[] // Add a single room's details addRoomDetails: (room: RoomDetails) => void // Get room details by confirmationNumber getRoomDetails: (confirmationNumber: string) => RoomDetails | undefined } export const useMyStayRoomDetailsStore = create( (set, get) => ({ rooms: [], addRoomDetails: (room) => { set((state) => { // Check if room with this ID already exists const existingIndex = state.rooms.findIndex((r) => r.id === room.id) let newRooms = [...state.rooms] if (existingIndex >= 0) { // Update existing room newRooms[existingIndex] = room } else { // Add new room newRooms.push(room) } return { rooms: newRooms, } }) }, getRoomDetails: (confirmationNumber) => { return get().rooms.find((room) => room.id === confirmationNumber) }, }) )