/******************************************************************** * ADOBE CONFIDENTIAL * __________________ * * Copyright 2024 Adobe * All Rights Reserved. * * NOTICE: All information contained herein is, and remains * the property of Adobe and its suppliers, if any. The intellectual * and technical concepts contained herein are proprietary to Adobe * and its suppliers and are protected by all applicable intellectual * property laws, including trade secret and copyright laws. * Dissemination of this information or reproduction of this material * is strictly forbidden unless prior written permission is obtained * from Adobe. *******************************************************************/ import { CartModel } from '../data/models'; import { useText } from '../../node_modules/@dropins/tools/src/i18n'; import { PriceProps } from '../../node_modules/@dropins/tools/src/components/Price'; /** * Params for the useCartItems hook * * @param { * dictionary: ReturnType; * onQuantityUpdate?: (item: CartModel['items'][number], quantity: number) => void; * onItemRemove?: (item: CartModel['items'][number]) => void; * } * * dictionary - The dictionary * onQuantityUpdate - The function to call when the quantity is updated * onItemRemove - The function to call when the item is removed */ export interface useCartItemsProps { dictionary: ReturnType; onQuantityUpdate?: (item: CartModel['items'][number], quantity: number) => void; onItemRemove?: (item: CartModel['items'][number]) => void; } /** * Params for the getConfiguration function */ interface GetConfigurationParams { item: CartModel['items'][number]; } interface ItemUpdateState { isUpdating: boolean; updatedValue: any; } /** * Type for the API returned by useCartItems * * This interface ensures that the returned object from the hook is well-typed and clear for consumers. */ export interface UseCartItemsApi { showIncludedTaxPrice: boolean; showExcludingTaxPrice: boolean; itemsUpdating: Map; itemUpdateErrors: Map; getConfiguration: (params: GetConfigurationParams) => object | undefined; getPriceProps: (item: CartModel['items'][number]) => PriceProps; getSubtotalProps: (item: CartModel['items'][number]) => { subtotalProps: PriceProps; subtotalDiscountProps: PriceProps | null; }; processQuantityChange: (item: CartModel['items'][number], value: number) => Promise; debouncedQuantityChange: (item: CartModel['items'][number], value: number) => void; setItemsUpdating: (itemsUpdating: Map) => void; getWarningMessage: (item: CartModel['items'][number]) => string | undefined; setItemUpdateError: (uid: string, error: string) => void; handleRemoveItem: (item: CartModel['items'][number]) => Promise; setItemUpdating: (uid: string, state: boolean) => void; } /** * useCartItems hook * * Provides an API for managing and retrieving calculated cart items data, including price, subtotal, configuration, quantity updates, and error handling. * * @param {Object} params * @param {ReturnType} params.dictionary - The i18n dictionary * @param {(item: CartModel['items'][number], quantity: number) => void} [params.onQuantityUpdate] - Callback when item quantity is updated * @param {(item: CartModel['items'][number]) => void} [params.onItemRemove] - Callback when item is removed * * @returns {Object} API for cart item management: * - showIncludedTaxPrice: boolean * - showExcludingTaxPrice: boolean * - itemsUpdating: Map * - itemUpdateErrors: Map * - getConfiguration(item): object | undefined * - getPriceProps(item): PriceProps * - getSubtotalProps(item): { subtotalProps: PriceProps, subtotalDiscountProps: PriceProps | null } * - processQuantityChange(item, value): Promise * - debouncedQuantityChange(item, value): void * - setItemsUpdating(map): void * - getWarningMessage(item): string | undefined * - setItemUpdateError(uid, error): void * - handleRemoveItem(item): Promise * - setItemUpdating(uid, state): void */ export declare const useCartItems: ({ dictionary, onQuantityUpdate, onItemRemove }: useCartItemsProps) => UseCartItemsApi; export {};