/** * Booking Service - Global booking store * Manages booking flow state (selected services, time slot, location, form submission) * Persists across page navigation in SPA until page refresh */ import { type Signal } from '@wix/services-definitions/core-services/signals'; import type { Service, V2Location as ServiceLocationType } from '@wix/auto_sdk_bookings_services'; import type { Resource, EventInfo, Location as TimeSlotLocationType } from '@wix/auto_sdk_bookings_availability-time-slots'; import type { FormValues } from '@wix/forms/components'; import type { BookResult, SelectedPaymentOption } from './book-action/types.js'; export type { SelectedPaymentOption } from './book-action/types.js'; /** * Extended Resource type with a type field for categorization */ export interface ExtendedResource extends Resource { /** Resource type identifier (e.g., 'staff', 'room', 'equipment') */ type: string; } /** * Minimal time slot data for service selections */ export interface ServiceSelectionTimeSlot { startDate: string; endDate: string; totalCapacity?: number; remainingCapacity?: number; scheduleId?: string; eventInfo?: EventInfo; /** Resources available in this time slot (populated when slot is selected) */ resources?: Resource[]; /** Location of this time slot (populated when slot is selected) */ location?: TimeSlotLocationType; } /** * ServiceSelection contains the service AND its related selections */ export interface ServiceSelection { /** Unique identifier for this booking instance (allows same service multiple times) */ instanceId: string; /** The selected service */ service: Service; /** Selected resources (staff members, rooms, etc.) with type information */ resources: ExtendedResource[]; /** Per-item time slot data (single-slot path; existing behavior). */ timeSlot?: ServiceSelectionTimeSlot; /** * Per-day slots for DAY-range services. Populated by the availability * picker after the customer picks a start + end date: one entry per day * in the picked range. When set, supersedes `timeSlot` for the DAY-range * builder, which produces one Booking per entry and routes via length: * - 1 -> bulkCreateBooking * - 2-8 -> createMultiServiceBooking * Optional & additive: existing single-slot callers stay on `timeSlot`. */ rangeTimeSlots?: ServiceSelectionTimeSlot[]; /** Number of participants for this service selection */ totalParticipants?: number; } /** * BookingService actions - setters only, no API calls */ export interface BookingServiceActions { /** Clears all service selections and sets a single item (instanceId is auto-generated) */ setItem(item: Omit): string; /** Adds an item and returns the generated instanceId */ addItem(item: Omit): string; /** Updates a service selection. If no instanceId provided, updates the first item. */ updateItem(updates: Partial>, instanceId?: string): void; /** Removes a service selection. If no instanceId provided, removes the first item. */ removeItem(instanceId?: string): void; /** Clears all service selections */ clearItems(): void; /** Sets a resource by type within a service selection. If no instanceId provided, uses the first item. Only one resource per type is allowed. The resourceType parameter specifies which type to set. */ setResource(resource: ExtendedResource, instanceId?: string): void; /** Gets a resource by type from a service selection. If no instanceId provided, uses the first item. */ getResourceByType(resourceType: string, instanceId?: string): Resource | undefined; /** Clears a resource by type from a service selection. If no instanceId provided, uses the first item. */ clearResourceByType(resourceType: string, instanceId?: string): void; setLocation(location: ServiceLocationType | null): void; clearLocation(): void; setTimezone(timezone: string): void; setFormSubmission(values: FormValues | null): void; clearFormSubmission(): void; /** * Set (or clear with `null`) the consumer-selected payment option. When set * to `'ONLINE'` or `'OFFLINE'`, this overrides the service-config heuristic * used by `book()` and the payment preview. When set to `null`, the override * is cleared and the heuristic applies again. */ setSelectedPaymentOption(value: SelectedPaymentOption | null): void; clearAll(): void; book(): Promise; } /** * Booking Service interface * Pure state management - no API calls */ export interface BookingService { /** Signal containing the service selections (services with their related data) */ serviceSelections: Signal; /** Signal containing the selected location */ location: Signal; /** Signal containing the selected timezone */ timezone: Signal; /** Signal containing the form submission */ formSubmission: Signal; /** * Signal containing the consumer-selected payment option. `undefined` means * "not chosen" — `book()` and the payment preview fall back to the * service-config heuristic. Set to `'ONLINE'` or `'OFFLINE'` to override. */ selectedPaymentOption: Signal; /** Actions for modifying booking state */ actions: BookingServiceActions; } /** * Service definition for Booking */ export declare const BookingServiceDefinition: string & { __api: BookingService; __config: {}; isServiceDefinition?: boolean; } & BookingService; /** * Configuration interface for BookingService * Mirrors BookingService structure (without actions and Signal wrappers) */ export interface BookingServiceConfig { /** Optional initial service selections to pre-populate */ serviceSelections?: ServiceSelection[]; /** Optional initial location */ location?: ServiceLocationType | null; /** Optional initial timezone */ timezone?: string; /** Optional initial form submission */ formSubmission?: FormValues | null; /** * Optional initial consumer-selected payment option. Omit to use the * service-config heuristic; set to `'ONLINE'` or `'OFFLINE'` to override. */ selectedPaymentOption?: SelectedPaymentOption; /** Optional app ID override for the catalog reference. Defaults to the bookings app ID. */ appId?: string; } /** * Implementation of BookingService * * This service stores booking state in memory during the session. * State persists across page navigation (SPA behavior) until page refresh. * * @example * ```tsx * // In BaseLayout.astro * const bookingConfig = await loadBookingServiceConfig(); * * // Wrap app with provider * * {children} * * * // In any page - access booking data * * {({ serviceSelections, location, formSubmission, actions }) => ( *
{serviceSelections.map(item => item.service.name).join(', ')}
* )} *
* ``` */ export declare const BookingService: import("@wix/services-definitions").ServiceFactory;