"use client"; import { createContext, useContext, useRef, type ReactNode } from "react"; import { useStore } from "zustand"; import type { StoreApi } from "zustand"; import { createBookingActionsStore, type BookingActionsStore } from "./store"; export const BookingActionsStoreContext = createContext | null>(null); export interface BookingActionsStoreProviderProps { children: ReactNode; } export const BookingActionsStoreProvider = ({ children }: BookingActionsStoreProviderProps) => { const storeRef = useRef>(); if (!storeRef.current) { storeRef.current = createBookingActionsStore(); } return ( {children} ); }; export const useBookingActionsStoreContext = ( selector: (store: BookingActionsStore) => T, equalityFn?: (a: T, b: T) => boolean ): T => { const bookingActionsStoreContext = useContext(BookingActionsStoreContext); if (!bookingActionsStoreContext) { throw new Error("useBookingActionsStoreContext must be used within BookingActionsStoreProvider"); } return useStore(bookingActionsStoreContext, selector, equalityFn); };