/** * BookingForm Service - Manages form submission state for booking flows * * This service supports two modes: * 1. Client-side: Provide formId to load the form dynamically * 2. SSR/SSG: Provide a pre-loaded form object for server-side rendering * * When using a pre-loaded form, it must belong to the bookings namespace. */ import { type ReadOnlySignal } from '@wix/services-definitions/core-services/signals'; import { forms } from '@wix/forms'; import { FormServiceConfig } from '@wix/forms/services'; /** * The required namespace for booking forms. * All booking forms must belong to this namespace. */ export declare const BOOKING_FORM_NAMESPACE = "wix.bookings.v2.bookings"; /** * Error thrown when BookingFormService cannot be initialized due to missing configuration. * This occurs when: * - No config (formId or form) was provided * - AND the component is not wrapped with Booking.Root (no BookingService available) */ export declare class BookingFormConfigurationError extends Error { constructor(message?: string); } /** * Configuration for BookingFormService. * Supports two modes: * 1. Client-side loading: Provide formId to fetch the form dynamically * 2. SSR/SSG: Provide a pre-loaded form object (must be from bookings namespace) * * Note: The config itself is optional. If not provided, the formId will be * extracted from the selected service if available. * * @example * ```tsx * // Pattern 1: Client-side loading * const config = { formId: 'form-123' }; * * // Pattern 1b: Client-side loading with service IDs * const config = { formId: 'form-123', serviceIds: ['service-1', 'service-2'] }; * * // Pattern 2: Pre-loaded form (SSR/SSG) * const config = { form: preloadedForm }; * * // Pattern 3: No config (formId extracted from service) * // config = undefined * ``` */ export type BookingFormServiceConfig = { /** The form ID to load (client-side loading) */ formId: string; /** Optional additional metadata to pass to FormService */ additionalMetadata?: Record; /** Optional list of service IDs to pass to FormService */ serviceIds?: string[]; /** Optional namespace override. Defaults to BOOKING_FORM_NAMESPACE. */ namespace?: string; } | { /** Pre-loaded form object (SSR/SSG) - must be from bookings namespace */ form: forms.Form; /** Optional namespace override. Defaults to BOOKING_FORM_NAMESPACE. */ namespace?: string; }; /** * API interface for the BookingForm service. * Manages form submission state and validation for booking forms. * * Supports two modes: * - Client-side: formId is provided via config, form is loaded dynamically * - SSR/SSG: Pre-loaded form is provided via config */ export interface BookingFormServiceAPI { /** * Signal containing the form service config. * Contains either a pre-loaded form (SSR/SSG) or formId with metadata (client-side). */ formServiceConfig: ReadOnlySignal; } export { hasFormId, hasForm, extractFormIdFromForm, extractFormIdFromConfig, type FormIdConfig, } from './utils.js'; /** * Service definition for BookingForm. * Defines the contract that the BookingFormService must implement. */ export declare const BookingFormServiceDefinition: string & { __api: BookingFormServiceAPI; __config: {}; isServiceDefinition?: boolean; } & BookingFormServiceAPI; /** * Implementation of BookingFormService. * * This service manages form submission state for booking flows. * Supports two modes: * 1. Client-side: formId is provided, form is loaded dynamically * 2. SSR/SSG: Pre-loaded form is provided (must be from bookings namespace) * * Initialization: * - Requires either a config (formId or form) OR BookingService with selected services * - If config is not provided, formId is extracted from selected services * - For multiple services, uses DEFAULT_FORM_ID; for single service, uses service's form ID * - Service IDs are extracted from config.serviceIds or from selected services * * Validation: * - The Form.Fields core component registers a validation callback via setValidateCallback * - The validateFormSubmission() method calls this registered callback * - The callback may be null initially until the core component registers it * * @example * ```tsx * // Pattern 1: Client-side loading * const bookingFormService = useService( * BookingFormServiceDefinition.withConfig({ formId: 'form-123' }) * ); * * // Pattern 1b: Client-side loading with service IDs * const bookingFormService = useService( * BookingFormServiceDefinition.withConfig({ * formId: 'form-123', * serviceIds: ['service-1', 'service-2'] * }) * ); * * // Pattern 2: SSR with pre-loaded form * const bookingFormService = useService( * BookingFormServiceDefinition.withConfig({ form: preloadedForm }) * ); * * // Pattern 3: No config - formId extracted from BookingService * const bookingFormService = useService( * BookingFormServiceDefinition.withConfig(undefined) * ); * * // Validate form (callback must be registered by core component first) * const result = await bookingFormService.validateFormSubmission?.(); * if (result?.valid) { * // Proceed with booking * } * ``` */ export declare const BookingFormService: import("@wix/services-definitions").ServiceFactory;