import { create } from "zustand" export interface RoomDetails { id: string hotelId: string checkInDate: Date checkOutDate: Date adults: number children: string roomName: string roomTypeCode: string rateCode: string bookingCode: string isCancelable: boolean mainRoom: boolean } interface MyStayRoomDetailsState { rooms: RoomDetails[] actions: { setRoomDetails: (room: RoomDetails) => void updateRoomDetails: (room: RoomDetails) => void } } export const useMyStayRoomDetailsStore = create( (set) => ({ rooms: [], actions: { setRoomDetails: (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, } }) }, updateRoomDetails: (room) => { set((state) => { const existingIndex = state.rooms.findIndex((r) => r.id === room.id) let newRooms = [...state.rooms] if (existingIndex >= 0) { newRooms[existingIndex] = room } return { rooms: newRooms, } }) }, }, }) )