"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const cucumber_1 = require("@cucumber/cucumber");
const form_data_1 = require("../runtime/form-data");
const locator_1 = require("../runtime/locator");
const resources_1 = require("../runtime/resources");
(0, cucumber_1.When)('I fill the form from {string}', async function (filePath) {
    const data = await (0, form_data_1.loadFormDataJson)((0, resources_1.resolveInputResourcePath)(this.config, this.featureName, filePath));
    await this.attach(JSON.stringify(data, null, 2), 'application/json');
    await (0, form_data_1.fillFormFromData)(requirePage(this), data, undefined, {
        fieldVerification: this.config.fieldVerification
    });
});
(0, cucumber_1.When)('I fill the form {string} from {string}', async function (formSelector, filePath) {
    const data = await (0, form_data_1.loadFormDataJson)((0, resources_1.resolveInputResourcePath)(this.config, this.featureName, filePath));
    await this.attach(JSON.stringify(data, null, 2), 'application/json');
    await (0, form_data_1.fillFormFromData)(requirePage(this), data, (0, locator_1.resolveSelectorAlias)(formSelector, this.config.selectors) ?? formSelector, {
        fieldVerification: this.config.fieldVerification
    });
});
function requirePage(world) {
    if (!world.page) {
        throw new Error('Cannot fill a form before the Playwright page has been created.');
    }
    return world.page;
}
