"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.OjMenu = void 0;
const selenium_webdriver_1 = require("selenium-webdriver");
const OjMenuBase_1 = require("./OjMenuBase");
/**
 * The component WebElement for [oj-menu](../../jsdocs/oj.ojMenu.html).
 * Do not instantiate this class directly, instead, use
 * [ojMenu](../functions/elements.ojMenu-1.html).
 */
class OjMenu extends OjMenuBase_1.OjMenuBase {
    /**
     * Open the menu at the given launcher Id.  The launcher is the
     * DOM element which opens the menu when clicked.
     * @param launcher The Id of the element which launches the menu
     */
    async open(launcher) {
        await this.whenReady();
        const l = await this.getDriver().findElement(selenium_webdriver_1.By.id(launcher));
        await l.click();
        await this.whenBusyContextReady();
    }
    /**
     * @deprecated Since 12.0.0. Use doMenuAction instead
     * Select a menu item from the list.  Note that the menu must
     * first be opened with {@link #open} before an item can be
     * selected.
     * @param id The Id of the &ltl;oj-option> to select
     */
    async changeSelection(id) {
        await this.whenReady();
        const item = await this.findElement(selenium_webdriver_1.By.id(id));
        const a = await item.findElement(selenium_webdriver_1.By.tagName('a')); // get the item anchor which should be active
        const aId = await a.getAttribute('id');
        let activeAId = await this.getAttribute('aria-activedescendant');
        while (activeAId !== aId) {
            await this.sendKeys(selenium_webdriver_1.Key.DOWN);
            activeAId = await this.getAttribute('aria-activedescendant');
        }
        await item.click();
        await this.whenBusyContextReady();
    }
    /**
     * Fire the ojMenuAction event on the &lt;oj-menu>.
     * > Note that your application must be listening on the <b>oj-menu-action</b>
     * > event in the UI, not the deprecated <i>oj-action</i>.
     * @param selectedValue Value of the &ltl;oj-option> to select
     *
     */
    async doMenuAction(selectedValue) {
        await this.whenReady();
        return this.getDriver().executeScript(`
    const evt = new CustomEvent('ojMenuAction', {
      detail: {
        selectedValue: "${selectedValue}"
      }
    });
    arguments[0].dispatchEvent(evt);
    arguments[0].close();
    `, this);
    }
}
exports.OjMenu = OjMenu;
//# sourceMappingURL=OjMenu.js.map