import { OjPagingControlBase } from './OjPagingControlBase';

/**
 * The component WebElement for [oj-paging-control](../../jsdocs/oj.ojPagingControl.html).
 * Do not instantiate this class directly, instead, use
 * [ojPagingControl](../functions/elements.ojPagingControl-1.html).
 */
export class OjPagingControl extends OjPagingControlBase {
  /**
   * Change the page to the one provided.
   * @param {Number} page The 0-index-based page number to which to
   * switch.
   * @return A Promise that is resolved when the page
   * transition is completed.
   */
  async changeSelection(page: number) {
    await this.whenReady();
    await this.getDriver().executeAsyncScript(
      'arguments[0].page(' + page + ').then(arguments[1])',
      this
    );
    // Wait for animations to end
    await this.whenBusyContextReady();
  }
}
