"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.puppeteerMetadata = void 0;
const isNullOrUndefined = (val) => val === null || val === undefined;
const getSelector = (data) => {
    let finalSelector = null;
    for (const { selector, index } of data) {
        if (selector) {
            if (!finalSelector) {
                finalSelector = `${selector}`;
            }
            else {
                finalSelector = `${finalSelector} > ${selector}`;
            }
        }
        if (!isNullOrUndefined(index)) {
            finalSelector = `${finalSelector}[${index}]`;
        }
    }
    return finalSelector;
};
exports.puppeteerMetadata = async function puppeteerMetadata({ fnName, stepResult, methodCallData, }) {
    var _a;
    const selector = getSelector(methodCallData);
    const text = (_a = methodCallData[methodCallData.length - 1]) === null || _a === void 0 ? void 0 : _a.text;
    if (selector) {
        stepResult.selector = selector;
    }
    if (fnName) {
        stepResult.fnName = fnName;
    }
    if (text) {
        stepResult.text = text;
    }
};
