"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.uploadFile = void 0;
const path_1 = __importDefault(require("path"));
const fs_1 = __importDefault(require("fs"));
/**
 * Uploads a file to the file input in the provided page.
 * @param page The Playwright page object.
 * @param fileNames The names of the files to upload.
 * @throws Will throw an error if the file doesn't exist.
 */
async function uploadFile(page, fileNames) {
    const filePaths = (Array.isArray(fileNames) ? fileNames : [fileNames]).map((fileName) => path_1.default.resolve(__dirname, '../resources', fileName));
    filePaths.forEach((filePath) => {
        if (!fs_1.default.existsSync(filePath)) {
            throw new Error(`File not found: ${filePath}`);
        }
    });
    console.log('Uploading files:', filePaths);
    try {
        const fileInput = await page.locator('input[type="file"]');
        await fileInput.setInputFiles(filePaths);
    }
    catch {
        try {
            const fileInput = await page.getByLabel('Upload files');
            await fileInput.setInputFiles(filePaths);
        }
        catch {
            const fileInput = await page.getByLabel('Upload documents');
            await fileInput.setInputFiles(filePaths);
        }
    }
}
exports.uploadFile = uploadFile;
