Preparing search index...

    Interface UseRecipeIngredientsReturn

    Return value of the useRecipeIngredients hook.

    interface UseRecipeIngredientsReturn {
        editIngredients: (
            index: number,
            newIngredient: string,
            applyPatch: ApplyIngredientEditPatch,
        ) => void;
        addOrMergeIngredient: (ingredient: ingredientTableElement) => void;
        replaceAllMatchingFormIngredients: (
            validatedIngredient: ingredientTableElement,
            originalName?: string,
        ) => void;
        removeMatchingFormIngredients: (name: string | undefined) => void;
        resolvePlaceholderIngredient: (
            originalName: string | undefined,
            validatedIngredient: ingredientTableElement,
        ) => void;
    }
    Index
    editIngredients: (
        index: number,
        newIngredient: string,
        applyPatch: ApplyIngredientEditPatch,
    ) => void

    Updates an existing ingredient at the specified index. If the ingredient name changes, triggers validation workflow for fuzzy matching. If only quantity/unit changes, updates the ingredient in place.

    Does not touch RHF state directly. The caller supplies applyPatch, which the hook invokes with IngredientEditPatch values so the caller can apply each change via the local RHF field-array API (fieldArray.update / fieldArray.remove). Sibling rows retain object identity.

    addOrMergeIngredient: (ingredient: ingredientTableElement) => void

    Adds a validated ingredient to the recipe or merges its quantity if the same ingredient exists. If the ingredient exists with the same unit, quantities are summed. If units differ, the new ingredient replaces the existing one.

    replaceAllMatchingFormIngredients: (
        validatedIngredient: ingredientTableElement,
        originalName?: string,
    ) => void

    Replaces ALL FormIngredients named originalName (defaults to the validated ingredient's name) with the validated database ingredient, in place. Preserves each row's own quantity/note while applying database metadata. Used by scraper validation when the same ingredient appears multiple times, including when the user picks a database ingredient whose name differs from the scraped one.

    removeMatchingFormIngredients: (name: string | undefined) => void

    Removes every form ingredient whose name matches name, emitting one remove patch per match (highest index first so earlier removals don't shift the indices still pending). Used by scraper validation when the user dismisses an ingredient from the queue. No-ops on an empty / undefined name.

    resolvePlaceholderIngredient: (
        originalName: string | undefined,
        validatedIngredient: ingredientTableElement,
    ) => void

    Resolves the placeholder row named originalName with the validated ingredient, in place, so row order is preserved. Merges with another row holding the validated name like editIngredients does; falls back to addOrMergeIngredient when no placeholder exists.