import { type Signal, type ReadOnlySignal } from '@wix/services-definitions/core-services/signals'; import { type LineItem } from '@wix/headless-ecom/services'; import { itemVariants } from '@wix/restaurants'; import type { EnhancedItem } from '@wix/headless-restaurants-menus/services'; import { AddToCartButtonState, AvailabilityStatus, FutureAvailability, WeeklyAvailability } from './common-types.js'; type Variant = itemVariants.Variant; /** * API interface for the Item Detailsservice, providing reactive item data management. * This service handles loading and managing a single item's data, loading state, and errors. * * @interface ItemServiceAPI */ export interface ItemServiceAPI { /** Reactive signal containing the current item data */ item?: Signal; quantity: Signal; specialRequest: Signal; allowSpecialRequest: boolean; specialRequestInstructions?: string; lineItem: ReadOnlySignal; onHandleAddToCart: (onClick: (lineItem: LineItem) => void) => void; buttonState: ReadOnlySignal; addToCartButtonDisabled: Signal; price: ReadOnlySignal; selectedVariant: Signal; selectedModifiers: Signal>>; availabilityStatus: Signal; /** Reactive signal indicating if a item is currently being loaded */ isLoading: Signal; /** Reactive signal containing any error message, or null if no error */ error: Signal; /** Reactive signal containing error state for each modifier group */ modifierGroupError: Signal>; /** Function to update the quantity of the item */ updateQuantity: (quantity: number) => void; /** Function to update the special request of the item */ updateSpecialRequest: (specialRequest: string) => void; /** Function to update the selected variant of the item */ updateSelectedVariant: (variant: Variant) => void; /** Function to toggle a modifier instance in a specific group */ toggleModifier: (modifierGroupId: string, modifierId: string, singleSelect?: boolean) => void; /** Function to get the selected modifiers for a specific group */ getSelectedModifiers: (modifierGroupId: string) => Array; futureAvailability: { startDate?: Date; endDate?: Date; weeklyAvailabilitySummary?: WeeklyAvailability; }; } /** * Service definition for the Item service. * This defines the contract that the ItemService must implement. * * @constant */ export declare const ItemServiceDefinition: string & { __api: ItemServiceAPI; __config: {}; isServiceDefinition?: boolean; } & ItemServiceAPI; /** * Configuration interface required to initialize the ItemService. * Contains the initial item data that will be loaded into the service. * * @interface ItemServiceConfig */ export interface ItemServiceConfig { /** The initial item data to configure the service with */ item?: EnhancedItem; operationId?: string; availabilityStatus?: AvailabilityStatus; allowSpecialRequest?: boolean; specialRequestInstructions?: string; editItemMode?: boolean; editingItemValues?: { quantity?: number; specialRequest?: string; selectedVariantId?: string; selectedModifiers?: Record>; }; menuId?: string; sectionId?: string; futureAvailability?: FutureAvailability; } export declare const ItemService: import("@wix/services-definitions").ServiceFactory; /** * Success result interface for item service configuration loading. * Returned when a item is successfully found and loaded. * * @interface SuccessItemServiceConfigResult */ export interface SuccessItemServiceConfigResult { /** Type "success" means that the item was found and the config is valid */ type: 'success'; /** The item config containing the loaded item data */ config: ItemServiceConfig; } /** * Not found result interface for item service configuration loading. * Returned when a item with the given id cannot be found. * * @interface NotFoundItemServiceConfigResult */ export interface NotFoundItemServiceConfigResult { /** Type "notFound" means that the item was not found */ type: 'notFound'; } /** * Loads item service configuration from the Wix Items API for SSR initialization. * This function is designed to be used during Server-Side Rendering (SSR) to preload * a specific item by id that will be used to configure the ItemService. * * @param itemSlug The item id to load * @returns Promise that resolves to ItemServiceConfigResult (success with config or notFound) * * @example * ```astro * --- * // Astro page example - pages/item/[id].astro * import { loadItemServiceConfig } from '@wix/stores/services'; * import { Item } from '@wix/stores/components'; * * // Get item id from URL params * const { id } = Astro.params; * * // Load item data during SSR * const itemResult = await loadItemServiceConfig(id); * * // Handle not found case * if (itemResult.type === 'notFound') { * return Astro.redirect('/404'); * } * --- * * * * {({ name }) =>

{name}

} *
*
* ``` * * @example * ```tsx * // Next.js page example - pages/item/[id].tsx * import { GetServerSideProps } from 'next'; * import { loadItemServiceConfig } from '@wix/stores/services'; * import { Item } from '@wix/stores/components'; * * interface ItemPageProps { * itemConfig: Extract>, { type: 'success' }>['config']; * } * * export const getServerSideProps: GetServerSideProps = async ({ params }) => { * const id = params?.id as string; * * // Load item data during SSR * const itemResult = await loadItemServiceConfig(id); * * // Handle not found case * if (itemResult.type === 'notFound') { * return { * notFound: true, * }; * } * * return { * props: { * itemConfig: itemResult.config, * }, * }; * }; * * export default function ItemPage({ itemConfig }: ItemPageProps) { * return ( * * * {({ name }) =>

{name}

} *
*
* ); * } * ``` */ export declare function loadItemServiceConfig({ item, operationId, availabilityStatus, }: { item: EnhancedItem; operationId?: string; availabilityStatus?: AvailabilityStatus; }): ItemServiceConfig; export {};