import { test as base } from "../conf";
import { RequestPage } from "../../pom/request/request.page";
import { CasePage } from "../../pom/case/case.page";

const test = base.extend<{ requestPage36: RequestPage }>({
    requestPage36: async ({ page, conf }, use) => {
        const requestPage = new RequestPage(page);
        await base.step("Setup: Check if the first medical is correct", async () => {
            await requestPage.getDetailCase(conf.data.case);
            await requestPage.dashboardLoc.buttonLinkByText("Provide").click();
            await requestPage.dashboardLoc.modal.headerModalContainText("Prepare Records").waitFor({ state: 'visible' });

            const listPostMedicalBill = (await requestPage.requestLoc.detail.snapshot.listPostMedicalbill.all()).length;
            if (listPostMedicalBill !== 2) {
                await requestPage.requestLoc.detail.snapshot.btnCloseModal.click();
                await requestPage.requestLoc.detail.caseID(conf.data.case_client).click();
                let casePage = new CasePage(requestPage.page);
                await casePage.changeStarFocus(conf.data.request_first);
                await requestPage.open();
                await requestPage.getDetailCase(conf.data.case);
                await requestPage.dashboardLoc.buttonLinkByText("Provide").click();
                await requestPage.dashboardLoc.modal.headerModalContainText("Prepare Records").waitFor({ state: 'visible' });
            }
        });

        await use(requestPage);
    }
});

export { test };
