"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.NavigateHomeExecutor = void 0;
const mablApi_1 = require("@mablhq-internal/runtime/mablApi");
const execution_1 = require("@mablhq-internal/runtime/execution");
const execution_2 = require("@mablhq-internal/runtime/execution");
class NavigateHomeExecutor {
    run(step, executionContext) {
        return (0, execution_1.runActionWithElementReadyRetriesForMobile)(() => this.navigateHome(step, executionContext), executionContext);
    }
    async navigateHome(_step, executionContext) {
        const { mobileTestEnvironment } = executionContext;
        const currentTargetOS = mobileTestEnvironment.getConfig().app.platformName;
        const driver = mobileTestEnvironment.getDriver();
        await executionContext.observeDeferredFunction();
        try {
            switch (currentTargetOS) {
                case mablApi_1.MobilePlatformEnum.Ios:
                    await driver.execute('mobile: pressButton', { name: 'home' });
                    break;
                case mablApi_1.MobilePlatformEnum.Android:
                    await driver.execute('mobile: pressKey', { keycode: 3 });
                    break;
                default:
                    executionContext.log.error(`Unsupported platform: ${currentTargetOS}`);
                    return {
                        status: execution_2.StepStatus.Failed,
                        logInfo: `Unable to navigate home (unsupported platform: ${currentTargetOS})`,
                    };
            }
        }
        catch (error) {
            executionContext.log.error(error);
            return {
                status: execution_2.StepStatus.Failed,
                logInfo: 'Unable to navigate home',
            };
        }
        return { status: execution_2.StepStatus.Passed };
    }
}
exports.NavigateHomeExecutor = NavigateHomeExecutor;
