"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.humanizeAwaitTabStep = humanizeAwaitTabStep;
exports.awaitTabStepToAIString = awaitTabStepToAIString;
const mablscriptFind_1 = require("@mablhq/test-model/mablscriptFind");
const mablscript_step_types_1 = require("../../mablscript-step-types");
const BaseStep_1 = __importDefault(require("./BaseStep"));
const AwaitTabStep_1 = require("@mablhq/test-model/steps/AwaitTabStep");
const yaml_utils_1 = require("../yaml-utils");
class AwaitTabStep extends BaseStep_1.default {
    static getStepType() {
        return mablscript_step_types_1.StepType.AWAIT_TAB;
    }
    constructor(tabSelector) {
        super(AwaitTabStep.getStepType());
        this.tabSelector = tabSelector;
        this.options = {
            duplicateStepEnabled: false,
            editable: false,
            executionContext: 'background',
        };
    }
    generateMablscript() {
        return `await_tab(${AwaitTabStep_1.AwaitTabStep.getMablscriptSelectorFromTabFindAction(this.tabSelector)})`;
    }
    inputVariables() {
        return [];
    }
    static generateStepFromMablStep(mablAwaitTabStep) {
        const selector = mablAwaitTabStep.tab;
        delete selector.selector_type;
        return new AwaitTabStep(selector);
    }
    static create(descriptor) {
        const step = new AwaitTabStep(descriptor.tab);
        step.generateStepId();
        return step;
    }
}
exports.default = AwaitTabStep;
function humanizeAwaitTabStep(step) {
    return `Wait for ${(0, mablscriptFind_1.humanizeTabSelector)(step.tabSelector)}`;
}
function awaitTabStepToAIString(step) {
    const target = { type: 'tab' };
    if (step.tabSelector.title) {
        target.title = step.tabSelector.title;
    }
    if (step.tabSelector.url) {
        target.url = step.tabSelector.url;
    }
    return (0, yaml_utils_1.toYaml)({
        stepType: step.stepType,
        target,
    });
}
