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

export default async function completeShopping(page: Page): Promise<void> {
  const cart = page.getByRole("dialog", { name: "В корзине" });

  await cart.waitFor({ state: "visible" });

  await swipeBottomSheet(cart, -200);

  const completeButton = cart.getByRole("button", {
    name: /Завершить покупки/,
  });

  page.once("dialog", (dialog) => dialog.accept());
  await completeButton.click();

  await cart.waitFor({ state: "hidden", timeout: 5000 });
}
