import { Page } from "@playwright/test";
import setQuantity, { LegacyUnitName } from "../setQuantity";
import openCompletedQuantityModal from "./openCompletedQuantityModal";

export default async function specifyCompletedQuantity(
  page: Page,
  ingredientName: string,
  unit: LegacyUnitName,
  quantity?: number,
): Promise<void> {
  const dialog = await openCompletedQuantityModal(page, ingredientName);

  await setQuantity(page, unit, quantity);

  await dialog.getByRole("button", { name: "Подтвердить" }).click();
  await dialog.waitFor({ state: "hidden" });
}
