"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.OjRadioset = void 0;
const OjRadiosetBase_1 = require("./OjRadiosetBase");
const selenium_webdriver_1 = require("selenium-webdriver");
/**
 * The component WebElement for [oj-radioset](../../jsdocs/oj.ojRadioset.html).
 * Do not instantiate this class directly, instead, use
 * [ojRadioset](../functions/elements.ojRadioset-1.html).
 */
class OjRadioset extends OjRadiosetBase_1.OjRadiosetBase {
    /**
     * Sets the value of "value" property.
     * The value of the component. See the Help documentation for more information.
     * @param value The value to set for "value"
     * @throws {ElementNotInteractableError} if the API is called when the control is readonly or disabled
     * @throws {InvalidArgumentError} if the value is non-exisitent
     */
    async changeValue(value) {
        // Check if the control is interactable
        if (!(await this.isInteractable())) {
            // Cannot interact when the control is disabled or readonly
            return Promise.reject(new selenium_webdriver_1.error.ElementNotInteractableError('ojRadioset: Value cannot be changed when the control is disabled or readonly'));
        }
        // Get the input element using the value property
        const input = await this.getRadio(value);
        if (input == null) {
            // If the input is not found, then the provided value does not exist in the
            // oj-radioset element
            return Promise.reject(new selenium_webdriver_1.error.InvalidArgumentError(`ojRadioset: ${value} is not a valid value.`));
        }
        // If all is good, then do the selection by sending the space key
        return input.sendKeys(selenium_webdriver_1.Key.SPACE);
    }
    /**
     * Checks if the Radioset is in interactable state
     */
    async isInteractable() {
        const isReadonly = await this.getReadonly();
        const isDisabled = await this.getDisabled();
        return !(isReadonly || isDisabled);
    }
    /**
     * Finds the input element for the provided value if it exists
     *
     * @param value The value for which the radio element has to be fetched
     * @returns The corresponding input element if it exists, null otherwise
     */
    async getRadio(value) {
        const subId = { subId: 'oj-radioset-radio', value: value };
        return await this.getDriver().executeScript(`
      var element = arguments[0];
      var subId = arguments[1];
      return element.getNodeBySubId(subId);
    `, this, subId);
    }
}
exports.OjRadioset = OjRadioset;
//# sourceMappingURL=OjRadioset.js.map