"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.scenarioNeedsUi = scenarioNeedsUi;
exports.ensureUiStarted = ensureUiStarted;
function stepsFromBlock(block) {
    if ("given" in block)
        return [block.given];
    if ("when" in block)
        return [block.when];
    if ("and" in block)
        return [block.and];
    if ("then" in block)
        return Array.isArray(block.then) ? block.then : [block.then];
    return [block];
}
function scenarioNeedsUi(scenario) {
    if (scenario.type === "ui" || scenario.type === "mixed")
        return true;
    for (const block of scenario.steps) {
        for (const step of stepsFromBlock(block)) {
            if (step.op.startsWith("ui."))
                return true;
        }
    }
    return false;
}
async function ensureUiStarted(ctxBase, startedFlag) {
    if (!ctxBase.ui || startedFlag.value)
        return;
    await ctxBase.ui.start();
    startedFlag.value = true;
}
//# sourceMappingURL=lifecycle.js.map