"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.OjSwitch = void 0;
const OjSwitchBase_1 = require("./OjSwitchBase");
const selenium_webdriver_1 = require("selenium-webdriver");
/**
 * The component WebElement for [oj-switch](../../jsdocs/oj.ojSwitch.html).
 * Do not instantiate this class directly, instead, use
 * [ojSwitch](../functions/elements.ojSwitch-1.html).
 */
class OjSwitch extends OjSwitchBase_1.OjSwitchBase {
    /**
     * Sets the value of "value" property.
     * The boolean state of the switch component.
     * @param value The value to set for "value"
     */
    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('OjSwitch: Value cannot be changed when the control is disabled or readonly'));
        }
        // Call focus() on the root element
        await this.getDriver().executeScript('arguments[0].focus()', this);
        const isChecked = (await this.getAttribute('class')).split(' ').includes('oj-selected');
        if (value !== isChecked) {
            await this.findElement(selenium_webdriver_1.By.css('.oj-switch-thumb')).sendKeys(selenium_webdriver_1.Key.SPACE);
        }
    }
    /**
     * Checks if the Switch is in interactable state
     */
    async isInteractable() {
        const isReadonly = await this.getReadonly();
        const isDisabled = await this.getDisabled();
        return !(isReadonly || isDisabled);
    }
}
exports.OjSwitch = OjSwitch;
//# sourceMappingURL=OjSwitch.js.map