import { WebElement } from 'selenium-webdriver';
import { OjSwipeActionsBase } from './OjSwipeActionsBase';

/**
 * The component WebElement for [oj-swipe-actions](../../jsdocs/oj.ojSwipeActions.html).
 * Do not instantiate this class directly, instead, use
 * [ojSwipeActions](../functions/elements.ojSwipeActions-1.html).
 */
export class OjSwipeActions extends OjSwipeActionsBase {
  // Put overrides here

  /**
   * Performs the specified action.
   *
   * @param {string} value The value of the oj-option associated with the action to perform.
   */
  async doAction(value: string) {
    await this.getDriver().executeAsyncScript<WebElement>(
      [
        'var elem = arguments[0];',
        'var action = arguments[1];',
        'var done = arguments[2];',
        "require(['ojs/ojcustomelement-utils'], function (utils) {",
        '  var bridge = utils.CustomElementUtils.getElementBridge(elem);',
        '  bridge._WIDGET_INSTANCE._doAction(action).then(done);',
        '});'
      ].join('\n'),
      this,
      value
    );
  }
}
