"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.resolveVariableOrValue = resolveVariableOrValue;
exports.createAndRegisterSelector = createAndRegisterSelector;
const variable_utils_1 = require("../variable-utils");
const mablscriptFind_1 = require("@mablhq/test-model/mablscriptFind");
function resolveVariableOrValue(inputValue, variables) {
    return typeof inputValue === 'object'
        ? {
            assertionTarget: 'variable',
            value: inputValue?.value,
            variable: inputValue,
        }
        : {
            assertionTarget: 'element',
            value: (0, variable_utils_1.canonicalizeVariablePattern)(variables || {}, inputValue ?? ''),
        };
}
function createAndRegisterSelector(selectorStore, elementSelectors, selectorPrototype, selectorContext) {
    const selector = selectorStore.generateSelector({
        ...(selectorPrototype || {}),
        elementSelectors: elementSelectors,
    }, selectorContext);
    if ((0, mablscriptFind_1.isInvalidElementSelectors)(selector)) {
        const errorMessage = `Invalid selector generated. Please contact mabl Support if this persists. Additional info:\n${JSON.stringify(selector)}`;
        console.error(errorMessage);
        throw new Error(errorMessage);
    }
    return selector;
}
