"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ClickStep = void 0;
const mablscriptFind_1 = require("../mablscriptFind");
const ActionsUtils_1 = require("./ActionsUtils");
const MablStepWithFindAction_1 = require("../MablStepWithFindAction");
class ClickStep extends MablStepWithFindAction_1.MablStepWithFindAction {
    static stepName = 'Click';
    static actionCode = 'click';
    static mablScriptStepNames = [ClickStep.actionCode];
    static yamlMablScriptNames = [ClickStep.stepName];
    constructor(descriptor, findAction) {
        super(ClickStep.stepName, descriptor, ClickStep.actionCode, findAction);
    }
    getStepName() {
        return ClickStep.stepName;
    }
    static fromYaml(_stepName, stepArgs) {
        return new ClickStep(stepArgs);
    }
    static fromLegacyMablscript(_args, actions) {
        const findAction = ActionsUtils_1.ActionsUtils.validateSingleFindAction(actions);
        const stepDescriptor = buildStepDescriptor(findAction);
        const step = new ClickStep(stepDescriptor, findAction);
        step.actions = actions;
        return step;
    }
    toMablscript() {
        return `${this.findAction.toMablscript()}.click()`;
    }
    getInputVariables() {
        return this.findAction.getInputVariables();
    }
    stepDescription() {
        const elementDescription = this.humanizeFind();
        return `Click on ${elementDescription}`;
    }
}
exports.ClickStep = ClickStep;
function buildStepDescriptor(findAction) {
    const find = findAction.toDescriptor();
    switch (find.findType) {
        case mablscriptFind_1.FindType.FIND_FIRST:
        case mablscriptFind_1.FindType.FIND_LAST:
        case mablscriptFind_1.FindType.FIND_ANY:
        case mablscriptFind_1.FindType.FIND_ONE:
            return {
                find,
                actionCode: ClickStep.actionCode,
            };
        default:
            throw new Error(`Error generating step descriptor for ${ClickStep.stepName}: Unexpected find type ${find.findType}`);
    }
}
