import { elementAttributeContains } from '../../core/utils.js';
import AComponent from '../a.js';
import DivComponent from '../div.js';
import LiComponent from '../li.js';
import SpanComponent from '../span.js';
import UlComponent from '../ul.js';
import CoEuiIconSvg from './eui-icon-svg.js';
import CoEuiToolbarMenuItemChild from './eui-toolbar-menu-item-child.js';

export default class CoEuiToolbarMenuItem extends LiComponent {
  constructor(parent) {
    let selector = 'li[contains(@routerLinkActive,"selected")]';
    super(parent, selector);
    //https://citnet.tech.ec.europa.eu/CITnet/stash/projects/CSDR/repos/eui/browse/packages/components/layout/eui-toolbar/toolbar-menu/toolbar-menu.component.html
  }
  
  get tabIndexLinkCO() {
    return new AComponent(this.currentPath).addSelectorPredicate('[@tabindex]');
  }
  async tabIndexLinkIsDisabled() {
    return await elementAttributeContains(this.tabIndexLinkCO.currentPath, 'class', 'disabled');
  }
  async isLinkHome() {
    return await (await $(this.tabIndexLinkCO.currentPath + '/self::a[contains(@class, "icon-home-link")]')).isExisting();
  }
  get divFlexCO() {
    return new DivComponent(this.tabIndexLinkCO).addPredicateClassContains('eui-u-flex');
  }
  get iconNameCO() {
    return new CoEuiIconSvg(this.divFlexCO).addPredicateClassContains('eui-u-mr-xs');
  }
  get tabIndexIconCO() {
    return new SpanComponent(this.divFlexCO).addPredicateClassContains('eui-icon');
  }
  get labelCO() {
    return new SpanComponent(this.divFlexCO).addPredicateClassContains('eui-toolbar-menu-label');
  }
  get iconChildrenCO() {
    return new CoEuiIconSvg(this.divFlexCO).addPredicateIconContains('chevron-down');
  }
  async noLinkUrl() {
    return await (await this.tabIndexIconCO.element()).isExisting();
  }
  get routerLinkCO() {
    return new AComponent(this.currentPath).addSelectorPredicate('[@routerLink]');
  }
  async routerLinkIsDisabled() {
    return await elementAttributeContains(this.routerLinkCO.currentPath, 'class', 'disabled');
  }
  get divFlexLinkCO() {
    return new DivComponent(this.routerLinkCO).addPredicateClassContains('eui-u-flex');
  }
  get iconNameLinkCO() {
    return new CoEuiIconSvg(this.divFlexLinkCO).addPredicateClassContains('eui-u-mr-xs');
  }
  get routerLinkIconCO() {
    return new SpanComponent(this.divFlexLinkCO).addPredicateClassContains('eui-icon');
  }
  get labelLinkCO() {
    return new SpanComponent(this.divFlexLinkCO).addPredicateClassContains('eui-toolbar-menu-label');
  }
  get iconChildrenLinkCO() {
    return new CoEuiIconSvg(this.divFlexLinkCO).addPredicateIconContains('chevron-down');
  }
  async hasLinkUrl() {
    return await (await this.routerLinkCO.element()).isExisting();
  }
  get childrenUlShowCO() {
    return new UlComponent(this.currentPath).addPredicateClassContains("show");
  }
  get children() {
    return new CoEuiToolbarMenuItemChild(this.childrenUlShowCO);
  }
  async hasChildren() {
    return await (await this.children.element()).isExisting();
  }
  async isSelected() {
    return await (await $(this.currentPath + '[contains(@routerLinkActive, "selected")]')).isExisting();
  }
}


