import { Page } from "@playwright/test";
import openCompletedQuantityModal from "./openCompletedQuantityModal";
import swipeBottomSheet from "../swipeBottomSheet";

export default async function getQuantitySuggestions(
  page: Page,
  ingredientName: string,
): Promise<string[]> {
  const dialog = await openCompletedQuantityModal(page, ingredientName);

  const suggestionsList = dialog.getByRole("list", { name: "Подсказки" });

  let suggestions: string[] = [];

  if (await suggestionsList.isVisible()) {
    const texts = await suggestionsList.getByRole("button").allInnerTexts();
    suggestions = texts.map((t) => t.trim());
  }

  await swipeBottomSheet(dialog, 200);
  await dialog.waitFor({ state: "hidden" });

  return suggestions;
}
