"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.OjListView = void 0;
const OjListViewBase_1 = require("./OjListViewBase");
const __1 = require("../../");
const selenium_webdriver_1 = require("selenium-webdriver");
const oj_module_proxy_1 = require("../../lib/oj-module-proxy");
/**
 * The component WebElement for [oj-list-view](../../jsdocs/oj.ojListView.html).
 * Do not instantiate this class directly, instead, use
 * [ojListView](../functions/elements.ojListView-1.html).
 */
class OjListView extends OjListViewBase_1.OjListViewBase {
    /**
     * Sets the value of "selected" property.
     * Specifies the current selected items in the listview. See the Help documentation for more information.
     * @param selected The value to set for "selected"
     * @override
     * @typeparam K Type of keys
     */
    async changeSelected(selected) {
        await this.whenReady();
        return (0, oj_module_proxy_1.executeWithModules)(this.getDriver(), ['KeySet'], [this, selected], `
      (({ KeySetImpl }, ele, selected) => {
        ele.selected = new KeySetImpl(selected);
      })
      `);
    }
    /**
     * Gets the value of "selected" property.
     * Retrieves the current selected items in the listview. See the Help documentation for more information.
     * @override
     * @typeparam K Type of keys
     * @return The value of "selected" property.
     */
    async getSelected() {
        await this.whenReady();
        const selected = await this.getDriver().executeScript(`
      const ele = arguments[0];
      const selected = Array.from(ele.selected.values())
      return selected;
    `, this);
        return selected;
    }
    /**
     * Retrieve a SlotProxy which represents a single listview item.
     * @param key The key within the Collection's dataset associated with the item.
     */
    async findItem(itemLocator) {
        // explicitly override scrollToKey to ensure changeScrollPosition regardless
        // of DataProvider or existing scrollToKey value
        await this.setProperty('scrollToKey', 'always');
        // Call changeScrollPosition to scroll the row into view and ensure it's
        // rendere in DOM
        // TODO: Base class should mark position properties as optional
        // @ts-ignore
        await this.changeScrollPosition({
            key: itemLocator.key
        });
        await this.whenBusyContextReady();
        const display = await this.getProperty('display');
        let el = await this.getDriver().executeScript(`
  return arguments[0].getNodeBySubId({ subId: 'oj-listview-item', key: arguments[1] })
  `, this, itemLocator.key);
        if (display === 'list') {
            el = el.findElement(selenium_webdriver_1.By.css('[role="gridcell"]'));
        }
        return (0, __1.slotProxy)(el, this);
    }
}
exports.OjListView = OjListView;
//# sourceMappingURL=OjListView.js.map