import Component from '../../component.js';
import Button from '../../button.js'
import MatMenu from '../../material/mat-menu.js'
import { childByIndex }  from '../../xpath-utils.js'

export default class CoUxDropdownButtonItem extends Component {
    constructor(parent) {
      let selector = 'ux-dropdown-button-item';
      super(parent, selector);
      //https://citnet.tech.ec.europa.eu/CITnet/stash/projects/CSDR/repos/eui/browse/packages/components/src/lib/ux-components/ux-dropdown-button/ux-dropdown-button-item.component.html
    }
    get dataE2E() {
      let path = '//button[contains(@data-e2e,"ux-link-e2e")]';
      return this.currentPath + path;
    }
    get buttonCO(){
      return new Button(this.currentPath);
    }
    get buttonItemIcon() {
      let path = '//span[contains(@class,"ux-dropdown-button-item__icon")]';
      return this.dataE2E + path;
    }
    get buttonItemLabel() {
      let path = '//span[text()]';
      return this.dataE2E + path;
    }
    get matMenuCO() {
      return new MatMenu(this.currentPath);
    }
    get dropdownButtonItemMatmenuButtonCO() {
      return new Button(this.matMenuCO.currentPath);
    }
    get dropdownButtonItemMatmenuButtonItem() {
      let path = '//span[contains(@class,"ux-dropdown-button-item__icon")]';
      return this.dropdownMatmenuButtonCO.currentPath + path;
    }
    get dropdownButtonItemMatmenuButtonItemLabel(){
      return childByIndex(this.dropdownMatmenuButtonCO.currentPath, 'span', 2);
    }
    get dropdownButtonItemButtonItemCO() {
      return new CoUxDropdownButtonItem(this.matMenuCO);
    }
    async isDisabled(){
      return await (await $(this.currentPath + '//button')).getAttribute('disabled');
    }
    async hasNestedContent(){
      return await (await $(this.currentPath  + '//button')).getAttribute('mat-menu-item');
    }

}
