"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.EnterTextStep = void 0;
const MablStepV2_1 = require("../../MablStepV2");
const FindAction_1 = require("../../actions/FindAction");
const stepUtil_1 = require("./stepUtil");
const MablAction_1 = require("../../MablAction");
const MablSymbol_1 = require("../../MablSymbol");
const STEP_NAME = 'EnterText';
class EnterTextStep extends MablStepV2_1.MablStepV2 {
    static stepName = STEP_NAME;
    static yamlMablScriptNames = [EnterTextStep.stepName];
    static stepVersion = 2;
    constructor(descriptor) {
        super(EnterTextStep.stepName, descriptor, 'enter_text');
    }
    getInputVariables() {
        const { find, text } = this.descriptor;
        const vars = MablAction_1.MablAction.findUniqueVariableReferencesInValue(find);
        vars.push(...MablAction_1.MablAction.findUniqueVariableReferencesInValue(text));
        return vars;
    }
    stepDescription() {
        if (this.descriptor.find && (0, stepUtil_1.isPasswordField)(this.descriptor.find)) {
            return (0, stepUtil_1.getDescriptionForMobileStepDescriptor)(`Enter password in`, this.descriptor);
        }
        return (0, stepUtil_1.getDescriptionForMobileStepDescriptor)(`Enter text "${(0, MablSymbol_1.isMablSymbolObject)(this.descriptor.text)
            ? (0, MablSymbol_1.formatSymbol)(this.descriptor.text)
            : this.descriptor.text}" in`, this.descriptor);
    }
    static fromYaml(_stepName, stepDescriptor) {
        if (!stepDescriptor.find &&
            !!stepDescriptor.selector &&
            !!stepDescriptor.findType) {
            stepDescriptor.find = {
                findType: FindAction_1.formattedFindTypeToMablscript[stepDescriptor.findType],
                findTarget: {
                    selector: stepDescriptor.selector,
                },
            };
            stepDescriptor.clearExistingText = true;
            delete stepDescriptor.selector;
            delete stepDescriptor.findType;
        }
        return new EnterTextStep(stepDescriptor);
    }
    static create(descriptor) {
        descriptor.id = descriptor.id ?? MablStepV2_1.MablStepV2.generateStepId();
        return new EnterTextStep(descriptor);
    }
}
exports.EnterTextStep = EnterTextStep;
