"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.OjSelectSingle = void 0;
const OjSelectSingleBase_1 = require("./OjSelectSingleBase");
/**
 * The component WebElement for [oj-select-single](../../jsdocs/oj.ojSelectSingle.html).
 * Do not instantiate this class directly, instead, use
 * [ojSelectSingle](../functions/elements.ojSelectSingle-1.html).
 */
class OjSelectSingle extends OjSelectSingleBase_1.OjSelectSingleBase {
    /**
     * Sets the value of "value" property.
     * The value of the element.
     * @param value The value to set for "value"
     * @override
     */
    async changeValue(value) {
        // Call focus() on the root element
        await this.getDriver().executeScript('arguments[0].focus()', this);
        // Only mutate if not readonly/disabled
        const readonly = await this.getReadonly();
        const disabled = await this.getDisabled();
        if (!(readonly || disabled)) {
            await this.whenBusyContextReady();
            await this.getDriver().executeAsyncScript(`
        var element = arguments[0];
        var value = arguments[1];

        // Last argument will the done function
        var doneFunc = arguments[arguments.length - 1];
        
        require(['ojs/ojcustomelement-utils'], function (utils) {
          // Retrieve the widget instance from the element
          var bridge = utils.CustomElementUtils.getElementBridge(element);
          var widget = bridge._WIDGET_INSTANCE;
          widget._selectItemByValue(value)
            .then(doneFunc, doneFunc)
            .catch(doneFunc);
        });
      `, this, value);
        }
    }
    /**
     * Clears the value
     * @override
     */
    clear() {
        return this.changeValue(null);
    }
}
exports.OjSelectSingle = OjSelectSingle;
//# sourceMappingURL=OjSelectSingle.js.map