"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.setupMasteredExam = setupMasteredExam;
exports.annotateText = annotateText;
exports.annotateImage = annotateImage;
const exam_engine_exams_1 = require("@digabi/exam-engine-exams");
const promises_1 = require("fs/promises");
const path_1 = __importDefault(require("path"));
const exam_engine_mastering_1 = require("@digabi/exam-engine-mastering");
async function setupMasteredExam(filePath = 'SC/SC.xml') {
    const examPath = (0, exam_engine_exams_1.resolveExam)(`${filePath}`);
    const resolveAttachment = (filename) => path_1.default.resolve(path_1.default.dirname(examPath), 'attachments', filename);
    const examXml = await (0, promises_1.readFile)(examPath, 'utf-8');
    const [masteredExam] = await (0, exam_engine_mastering_1.masterExam)(examXml, () => '', (0, exam_engine_mastering_1.getMediaMetadataFromLocalFile)(resolveAttachment), {
        removeCorrectAnswers: true
    });
    return masteredExam;
}
async function annotateText(locator, page, selectionWidth = 200) {
    await locator.scrollIntoViewIfNeeded(); // Scroll the element into view
    const box = await locator.boundingBox();
    if (!box)
        throw new Error('Bounding box not found');
    const startX = box.x + 1;
    const startY = box.y + 1;
    const endX = box.x + selectionWidth; // Move further to the right to select text
    const endY = startY;
    // Simulate dragging the mouse to select text
    await page.mouse.move(startX, startY);
    await page.mouse.down();
    await page.mouse.move(endX, endY);
    await page.mouse.up();
}
async function annotateImage(locator, page) {
    await locator.scrollIntoViewIfNeeded();
    const box = await locator.boundingBox();
    if (!box)
        throw new Error('Bounding box not found');
    const startX = box.x;
    const startY = box.y;
    const endX = box.x + box.width + 1;
    const endY = box.y + box.height + 1;
    // Simulate dragging the mouse to select text
    await page.mouse.move(startX, startY);
    await page.mouse.down();
    await page.mouse.move(endX, endY);
    await page.mouse.up();
}
//# sourceMappingURL=utils.js.map