import Component from './component.js'
import { elementAttributeContains } from '../core/utils.js'

export default class ButtonComponent extends Component {
    /**
    * Expects the parent element and an xpath selector (without the leading slashes)
    * @param parent WebdriverIO.Element
    */
    constructor(parent, selector) {
      if (selector) {
          super(parent, selector);
      } else {
          super(parent, 'button');
      }
  }

    async isShownButton() {
      return await elementAttributeContains(this.currentPath, 'class', 'ux-button--with-label');
    }
    async buttonDisabled(){
      return await (await $(this.currentPath)).getAttribute('disabled');
    }
    get buttonIcon() {
      let path = '//span[contains(@class,"ux-button__icon")]';
      return this.currentPath + path;
    }
    async buttonContainer() {
      let cl = await (await $(this.currentPath)).getAttribute('class');
      if (await cl.includes('eui-button')) {
        return this.currentPath + '//span[contains(@class, "eui-button__container")]';
      }
    }
    async span() {
      let cl = await (await $(this.currentPath)).getAttribute('class')
      if (await cl.includes('eui-button')) {
        return ( await this.buttonContainer() + '/span');
      } else {
        return this.currentPath + '//span[2]';
      }
    }

}
