import { BasketsService } from './baskets.service'; import { BasketEntriesService } from './basket-entries.service'; import { ItemsService } from './items.service'; import { RecipeDetailsService } from './recipe-details.service'; import { BasketsSynchronizerService } from './baskets-synchronizing'; import { ProductPrice } from './price.service'; import { BasketEntry, Ingredient, Item, Recipe } from '../_models'; import { BehaviorSubject, Observable, Subject } from 'rxjs'; import { EventTrace } from '../_types/event-trace'; import { IgnoredIngredientsService } from './ignored-ingredients.service'; import { RecipesService } from './recipes.service'; import { AnalyticsService } from './analytics.service'; import { StoreOutOfStockService } from './store-out-of-stock.service'; import { ContextRegistryService } from './context-registry.service'; import * as i0 from "@angular/core"; export interface BasketEntryToReplace { basketEntry: BasketEntry; ignoreSelected: boolean; ingredient: Ingredient; addProductMode?: boolean; } export interface ReplaceItemWithPrice { item: Item; price: ProductPrice; isOutOfStock?: boolean; } export declare class ReplaceItemService { private basketsService; private basketEntriesService; private itemsService; private recipeDetailsService; private basketSynchroService; private ignoredBasketsService; private recipesService; private analyticsService; private storeOutOfStockService; private contextRegistryService; basketEntry: BasketEntry; recipe: Recipe; ignoreSelected: boolean; addProductMode: boolean; previousItem: Item; ingredient: Ingredient; itemsWithPricesList$: BehaviorSubject; fetchingItemLoading$: BehaviorSubject; replaceItemLoading$: BehaviorSubject; private onComplete; basketEntryToReplace$: BehaviorSubject; replaceProductFromPreviewOpen$: BehaviorSubject; additionModalOpen$: BehaviorSubject; productAdded$: Subject; scrollBackToBasketEntryId: string; constructor(basketsService: BasketsService, basketEntriesService: BasketEntriesService, itemsService: ItemsService, recipeDetailsService: RecipeDetailsService, basketSynchroService: BasketsSynchronizerService, ignoredBasketsService: IgnoredIngredientsService, recipesService: RecipesService, analyticsService: AnalyticsService, storeOutOfStockService: StoreOutOfStockService, contextRegistryService: ContextRegistryService); handleItemSelection(item: Item, searchString: string, onComplete: (itemId?: string) => void, eventTrace: EventTrace): void; /** * Handles the selection of an item to replace an ingredient in a basket entry, * either from the recipe details page or from the basket preview. * @param item The item to add to the basket. * @param searchString The search string used to find the item. * @param eventTrace The event trace from the selection. * @returns An observable that resolves to an AddIngredientAction or RemoveIngredientFromReplaceAction, * depending on whether the item was added to the basket or not. */ private onSelectItem; /** * Searches for items based on the given search string. * * This method uses the `searchForIngredient` method from the `ItemsService` to search for items * based on the given search string. It then filters the result to exclude the currently selected * item and finally retrieves the prices for the remaining items. */ searchItem(searchString: string): Observable; /** * Handles the selection of a new item to replace a basket entry. * It handles the case where the basket entry is active or not. * If the basket entry is ignored, it removes the ingredient from the store ignored list * and calls {@link replaceBasketEntryActiveItem} which adds the new item to the basket and removes the old one. * If the basket entry is not active, it calls {@link addBasketEntryItem} which adds the new item to the basket. */ private handleReplaceProductMode; /** * Adds an item to the basket without associating it with a specific recipe. * Updates the loading state with the current item and creates a new basket entry. * Handles any errors by rolling back the operation. * Adds the action to the synchronization service's action list for processing. */ private handleAddProductMode; /** * Fetches items based on the current ingredient or basket entry. * * This method retrieves a list of items associated with a specified ingredient * or basket entry and returns an observable that emits an array of objects, each containing * an item and its corresponding price. */ private fetchItems; /** * Replace the current basket entry with the given item. * Removes the previous item from the retailer cart first; the add action is only enqueued after remove succeeds. */ private selectItem; private withOutOfStockFlags; private refreshItemsOutOfStockFlags; changeReplaceModalState(state: boolean, basketEntryToReplace?: BasketEntry): void; changeAdditionModalState(state: boolean): void; setRecipe(recipe: Recipe): void; /** * Replaces the selected item in the given basket entry with the given item. * If the basket entry currently has a selected item, it will be removed. */ private replaceRelationship; private createAddIngredientFromReplaceAction; private listenToAddActionFailure; /** * After a failed replace-add, the retailer already removed the old product but Mealz was never updated * (remove-from-replace is retailer-only). reloadBasket would re-fetch Mealz and still show the old product * as active. syncMealzBasketWithRetailerCart is too broad and risky while other actions may be pending. * A targeted remove-recipe aligns Mealz with the retailer for this ingredient only. */ private confirmMealzRemoveAfterReplaceAddFailure; private handleAddTimeout; private clearReplaceLoadingState; /** * Creates a ParsedMethod for adding an ingredient to a basket. */ private getAddIngredientMethod; /** * Handles the response after attempting to add an item to the basket. * Updates loading states, creates an AddIngredientAction for the new basket entry, * and adds it to the synchronization service's action list. */ private handleAddToBasketResponse; private handleAddIngredientActionErrors; /** * Updates the loading states for ingredient and basket operations. * * Sets `ingredientToBasketLoading` to true if the basket entry status is 'initial', * indicating the ingredient is being prepared to add to the basket. * Sets `updateIngredientFromBasketLoading` to true if the basket entry status is not 'initial', * indicating an update operation for the ingredient from the basket is in progress. */ private updateLoadingStates; private replaceBasketEntryActiveItem; /** * Given an active basket entry without associated ingredient, fetches the related * recipe and ingredient, and then adds the given item to the basket. */ private processActiveBasketEntryWithoutIngredient; /** * Adds the given item to the basket for the current recipe. * Returns an observable that resolves to an AddIngredientAction, which can be used to track the status of the addition. */ private addToBasket; /** * Replaces the item in the given basket entry with the given item * and adds the new item to the basket. */ private addBasketEntryItem; private moveSelectedItemToFront; private sendReplaceEvent; static ɵfac: i0.ɵɵFactoryDef; static ɵprov: i0.ɵɵInjectableDef; } //# sourceMappingURL=replace-item.service.d.ts.map