/** * Types for the Book action */ import type { ServiceSelection } from '../booking.js'; import type { FormValues } from '@wix/forms/components'; import type { Location as TimeSlotLocationType } from '@wix/auto_sdk_bookings_availability-time-slots'; import type { SelectedPaymentOptionWithLiterals } from '@wix/auto_sdk_bookings_bookings'; /** * Narrowed booking-API `selectedPaymentOption` to the two values a consumer * can pick in the UI. Derived from the SDK enum (`SelectedPaymentOption`) so * the type stays in sync; MEMBERSHIP variants are intentionally excluded * because they require pricing-plan plumbing not exposed here. */ export type SelectedPaymentOption = Extract; /** * Enum for book result types */ export declare enum BookResultType { CheckoutRequired = "checkout_required", CheckoutSkipped = "checkout_skipped" } /** * Result returned from the book action */ export type BookResult = { type: BookResultType.CheckoutRequired; cartId: string; } | { type: BookResultType.CheckoutSkipped; orderId: string; }; /** * Error object for booking errors */ export interface BookingError { message: string; errorObject: unknown; } /** * Parameters for executing the book action */ export interface BookActionParams { serviceSelections: ServiceSelection[]; location: TimeSlotLocationType | null; formSubmission: FormValues | null; timezone?: string; /** Optional app ID override for the catalog reference. Defaults to the bookings app ID. */ appId?: string; /** * Optional consumer-selected payment option. When provided, overrides the * heuristic derived from `service.payment.options` in `buildBookingRequest` * and matches the line item's `paymentOption` produced by the payment * service. When omitted, the existing service-config heuristic applies. */ selectedPaymentOption?: SelectedPaymentOption; } /** * Props passed to children of Book component */ export interface BookChildProps { isLoading: boolean; error: BookingError | null; canBook: boolean; onClick: () => Promise; disabled: boolean; } /** * Props for the Book headless component */ export interface BookProps { asChild?: boolean; children?: React.ReactNode | ((props: BookChildProps) => React.ReactNode); className?: string; label?: string; loadingState?: string; disabled?: boolean; /** * Called when checkout is required for payment. * The navigateToCheckout function has the checkoutId captured - just call it. * When navigateToCheckout is called, the button will show loading state until navigation completes. */ onCheckout?: (navigateToCheckout: (options: { postFlowUrl: string; }) => Promise) => void; /** * Called when booking completes without requiring checkout (free/offline services). * Receives the orderId which can be used to display confirmation or navigate to a thank you page. */ onComplete?: (result: { orderId: string; }) => void; onError?: (error: BookingError) => void; }