"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const cucumber_1 = require("@cucumber/cucumber");
const credentials_1 = require("../runtime/credentials");
const locator_1 = require("../runtime/locator");
const ui_controls_1 = require("../runtime/ui-controls");
(0, cucumber_1.When)('I fill {string} with {string}', async function (field, value) {
    const locator = (0, locator_1.fieldByName)(this.page, field, this.config.selectors).first();
    await locator.fill(value);
    await (0, ui_controls_1.assertLocatorValue)(locator, value, `Field "${field}"`, (0, ui_controls_1.resolveFieldVerificationRule)(field, this.config.fieldVerification));
});
(0, cucumber_1.When)('I fill {string} at index {int} with {string}', async function (field, index, value) {
    const locator = (0, locator_1.atIndex)((0, locator_1.fieldByName)(this.page, field, this.config.selectors), index);
    await locator.fill(value);
    await (0, ui_controls_1.assertLocatorValue)(locator, value, `Field "${field}" at index ${index}`, (0, ui_controls_1.resolveFieldVerificationRule)(field, this.config.fieldVerification));
});
(0, cucumber_1.When)('I fill {string} with credential {string}', async function (field, credential) {
    const value = (0, credentials_1.resolveCredential)(this, credential);
    const locator = (0, locator_1.fieldByName)(this.page, field, this.config.selectors).first();
    await locator.fill(value);
    await (0, ui_controls_1.assertLocatorValue)(locator, value, `Field "${field}"`, (0, ui_controls_1.resolveFieldVerificationRule)(field, this.config.fieldVerification));
});
(0, cucumber_1.When)('I fill {string} at index {int} with credential {string}', async function (field, index, credential) {
    const value = (0, credentials_1.resolveCredential)(this, credential);
    const locator = (0, locator_1.atIndex)((0, locator_1.fieldByName)(this.page, field, this.config.selectors), index);
    await locator.fill(value);
    await (0, ui_controls_1.assertLocatorValue)(locator, value, `Field "${field}" at index ${index}`, (0, ui_controls_1.resolveFieldVerificationRule)(field, this.config.fieldVerification));
});
(0, cucumber_1.When)('I clear {string}', async function (field) {
    await (0, locator_1.fieldByName)(this.page, field, this.config.selectors).first().clear();
});
(0, cucumber_1.When)('I clear {string} at index {int}', async function (field, index) {
    await (0, locator_1.atIndex)((0, locator_1.fieldByName)(this.page, field, this.config.selectors), index).clear();
});
(0, cucumber_1.When)('I select {string} from {string}', async function (option, field) {
    await (0, locator_1.fieldByName)(this.page, field, this.config.selectors).first().selectOption({ label: option });
});
(0, cucumber_1.When)('I select {string} from {string} at index {int}', async function (option, field, index) {
    await (0, locator_1.atIndex)((0, locator_1.fieldByName)(this.page, field, this.config.selectors), index).selectOption({ label: option });
});
