"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.recordEnterTextExecutor = void 0;
const toolExecutor_types_1 = require("../toolExecutor-types");
const stepCapture_1 = require("../../background/capture/stepCapture");
const mablApi_1 = require("../../../mablApi");
const ENTER_TEXT_STEP_WAIT_TIME_MS = 2_000;
exports.recordEnterTextExecutor = {
    needsFind: () => true,
    getStepType: () => 'enter_text',
    execute: async (payload, stateProvider, eventHandler, logger) => {
        if (!payload.find ||
            !payload.contextInfo ||
            !(0, toolExecutor_types_1.isFindOneEventMessage)(payload.find)) {
            logger.error('Record Enter Text executor requires find and contextInfo');
            return {
                success: false,
            };
        }
        const findEvent = payload.find;
        const textToEnter = payload.toolCall.toolParams?.text ?? '';
        if (findEvent.selectOptions) {
            findEvent.listener = 'select';
            findEvent.action = 'select';
            findEvent.inputValue = textToEnter;
        }
        else {
            findEvent.inputValue = textToEnter;
            const serverResult = payload.toolCall.serverResult;
            findEvent.enterTextMode =
                serverResult?.enterTextMode ?? mablApi_1.EnterTextModeEnum.Fill;
        }
        return (0, toolExecutor_types_1.recordStepAndTrackResult)(() => (0, stepCapture_1.recordTrainedStep)(findEvent, payload.contextInfo, true, undefined, stateProvider, eventHandler), ENTER_TEXT_STEP_WAIT_TIME_MS, stateProvider, eventHandler, logger);
    },
};
