import Component  from '../component.js'
import { elementAttributeContains } from '../../core/utils.js'
import LiComponent from '../li.js';
import CoEuiMenuItemIconContent from './eui-menu-item-icon-content.js';
import CoEuiMenuItemLinkContent from './eui-menu-item-link-content.js';

export default class CoEuiMenuItem extends Component {
  constructor(parent) {
    let selector = 'eui-menu-item';
    super(parent, selector);
    //https://citnet.tech.ec.europa.eu/CITnet/stash/projects/CSDR/repos/eui/browse/packages/components/eui-menu/eui-menu-item.component.html
  }
  get labelItemCO() {
    return new LiComponent(this.currentPath).byAttributeContains('class', 'eui-menu-item');
  }
  async isLabelItem() {
    return await (await this.labelItemCO.element()).isExisting();
  }
  async isDisabledLabelItem() {
    return await elementAttributeContains(this.labelItemCO.currentPath, 'class', 'eui-menu-item--disabled');
  }
  get labelIconCotentCO() {
    return new CoEuiMenuItemIconContent(this.labelItemCO);
  }
  get categoryLabel() {
    let path = '//span[contains(@class,"eui-menu-item__category-label")]';
    return this.labelItemCO.currentPath + path;
  }
  get categoryItemLabel() {
    let path = '//span[contains(@class,"eui-menu-item__label")]';
    return this.categoryLabel + path;
  }
  get urlListItem() {
    let path = '//li[contains(@class,"eui-menu-item") and not(contains(@class,"eui-menu-item__category"))]';
    return this.currentPath + path;
  }
  async isUrlItem() {
    return await (await $(this.urlListItem)).isExisting();
  }
  async isUrlExpandedList() {
    return await elementAttributeContains(this.urlListItem, 'class', 'eui-menu-item--expanded');
  }
  get urlLink() {
    let path = '//a[contains(@class,"eui-menu-item__link")]';
    return this.urlListItem + path;
  }
  async isLinkDisabled() {
    return await elementAttributeContains(this.urlLink, 'class', 'eui-menu-item--disabled');
  }
  async isLinkActive() {
    return await elementAttributeContains(this.urlLink, 'class', 'eui-menu-item__link--active');
  }
  get urlLinkContentCO() {
    return new CoEuiMenuItemLinkContent(this.urlLink);
  }
  async linkListItem() {
    let path = '//li[contains(@class,"eui-menu-item") and not(contains(@class,"eui-menu-item__category"))]';
    if (! await this.isUrlItem()) {
      return this.currentPath + path;
    }
  }
  async isLinkItem() {
    return await (await $(await this.linkListItem())).isExisting();
  }
  async isLinkExpandedList() {
    return await elementAttributeContains(await this.linkListItem(), 'class', 'eui-menu-item--expanded');
  }
  async link() {
    let path = '//a[contains(@class,"eui-menu-item__link")]';
    return await this.linkListItem() + path;
  }
  async linkContentCO() {
    return new CoEuiMenuItemLinkContent(await this.link());
  }
}


