"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.VisibilityChecker = void 0;
const test_1 = require("@playwright/test");
const logger_1 = require("../../../utils/logger");
const timeouts_1 = require("../../../timeouts");
/**
 * Проверка visible/hidden (и опционально enabled) по спискам ключей из конфигурации.
 */
class VisibilityChecker {
    async checkElementsVisibility(params) {
        const { locators, visibleKeys, hiddenKeys = [], logContext, stepTitle, elementLabel = 'элементов', expectTimeout = (0, timeouts_1.getTimeouts)().EXPECT, checkEnabled = false, } = params;
        const hiddenSet = new Set(hiddenKeys);
        const allKeys = [...visibleKeys, ...hiddenKeys];
        await test_1.test.step(stepTitle, async () => {
            logger_1.logger.debug(`${stepTitle} для ${logContext}`, `${logContext}.checkElementsVisibility`);
            const checks = [];
            for (const key of allKeys) {
                const locator = locators[key];
                if (!locator) {
                    logger_1.logger.warn(`Локатор "${key}" не найден при проверке ${elementLabel}`, `${logContext}.checkElementsVisibility`);
                    continue;
                }
                const isHidden = hiddenSet.has(key);
                checks.push(test_1.test.step(`Проверка ${elementLabel}: ${key}`, async () => {
                    if (isHidden) {
                        await test_1.expect.soft(locator).toBeHidden({ timeout: expectTimeout });
                    }
                    else {
                        await test_1.expect.soft(locator).toBeVisible({ timeout: expectTimeout });
                        if (checkEnabled) {
                            await test_1.expect.soft(locator).toBeEnabled();
                        }
                    }
                }));
            }
            await Promise.all(checks);
            logger_1.logger.info(`Проверка ${elementLabel} завершена. Проверено: ${checks.length}`, `${logContext}.checkElementsVisibility`);
        });
    }
}
exports.VisibilityChecker = VisibilityChecker;
