"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ClickAndHoldStep = void 0;
const mablscriptFind_1 = require("../mablscriptFind");
const ActionsUtils_1 = require("./ActionsUtils");
const MablStepWithFindAction_1 = require("../MablStepWithFindAction");
class ClickAndHoldStep extends MablStepWithFindAction_1.MablStepWithFindAction {
    static stepName = 'Click and Hold';
    static actionCode = 'click_and_hold';
    static mablScriptStepNames = [ClickAndHoldStep.actionCode];
    static yamlMablScriptNames = [ClickAndHoldStep.stepName];
    clickArgs;
    constructor(descriptor, findAction) {
        super(ClickAndHoldStep.stepName, descriptor, ClickAndHoldStep.actionCode, findAction);
        this.clickArgs = { isHtml5: descriptor.isHtml5 ?? false };
    }
    static parseArgs(args) {
        if (args.length === 0) {
            return undefined;
        }
        return {
            isHtml5: args[0].isHtml5,
        };
    }
    getStepName() {
        return ClickAndHoldStep.stepName;
    }
    getInputVariables() {
        return this.findAction.getInputVariables();
    }
    stepDescription() {
        const elementDescription = this.humanizeFind();
        return `Click and hold ${elementDescription}`;
    }
    static fromYaml(_stepName, stepArgs) {
        return new ClickAndHoldStep(stepArgs);
    }
    static fromLegacyMablscript(args, actions) {
        const findAction = ActionsUtils_1.ActionsUtils.validateSingleFindAction(actions);
        const clickArgs = ClickAndHoldStep.parseArgs(args) ?? { isHtml5: false };
        const stepDescriptor = buildStepDescriptor(findAction, clickArgs);
        const step = new ClickAndHoldStep(stepDescriptor, findAction);
        step.actions = actions;
        return step;
    }
    toMablscript() {
        return `${this.findAction.toMablscript()}.click_and_hold({isHtml5:${this.clickArgs.isHtml5}})`;
    }
}
exports.ClickAndHoldStep = ClickAndHoldStep;
function buildStepDescriptor(findAction, clickArgs) {
    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: ClickAndHoldStep.actionCode,
                isHtml5: clickArgs.isHtml5,
            };
        default:
            throw new Error(`Error generating step descriptor for ${ClickAndHoldStep.stepName}: Unexpected find type ${find.findType}`);
    }
}
