import Component from '../../component.js'
import CoEuiMenuItem from './eui-menu-item.js'
import { elementAttributeContains } from '../../../core/utils.js'

export default class CoEuiMenu extends Component {
  constructor(parent) {
    let selector = 'eui-menu';
    super(parent, selector);
    //https://citnet.tech.ec.europa.eu/CITnet/stash/projects/CSDR/repos/eui/browse/packages/components-next/src/lib/components/eui-menu/eui-menu.component.html
  }
  get filter() {
    let path = '//div[contains(@class,"eui-menu-filter")]';
    return this.currentPath + path;
  }
  async hasFilter() {
    return await (await $(this.filter)).isExisting();
  }
  get wrapper() {
    let path = '//div[contains(@class,"eui-clearable-input-wrapper")]';
    return this.filter + path;
  }
  get filterInput() {
    let path = '//input[contains(@class,"eui-menu-filter__input")]';
    return this.wrapper + path;
  }
  get searchIcon() {
    let path = '//span[contains(@class,"eui-menu-filter__search-icon")]';
    return this.wrapper + path;
  }
  get clearWrapper() {
    let path = '//span[contains(@class,"eui-clearable-input-wrapper__clear")]';
    return this.wrapper + path;
  }
  async hasInputValue() {
    return await (await $(this.clearWrapper)).isExisting();
  }
  get list() {
    let path = '//ul[contains(@class,"eui-menu")]';
    return this.currentPath + path;
  }
  get noItems() {
    let path = '//span[contains(@class,"eui-menu--no-items")]';
    return this.list + path;
  }
  get euiMenuItemCO() {
    return new CoEuiMenuItem(this.list);
  }
  async isCollapsedMenuItem() {
    return await elementAttributeContains(this.euiMenuItemCO.currentPath, 'class', 'eui-menu--collapsed');
  }
  async hasIconsMenuItem() {
    return !(await elementAttributeContains(this.euiMenuItemCO.currentPath, 'class', 'eui-menu--no-icons'));
  }
  get submenu() {
    let path = '//ul[contains(@class,"eui-menu-sub")]';
    return this.euiMenuItemCO.currentPath + path;
  }
  get euiMenuItemSubCO() {
    return new CoEuiMenuItem(this.submenu);
  }
  async isCollapsedMenuItemSubmenu() {
    return await elementAttributeContains(this.euiMenuItemSubCO.currentPath, 'class', 'eui-menu--collapsed');
  }
  async hasIconsMenuItemSubmenu() {
    return !(await elementAttributeContains(this.euiMenuItemSubCO.currentPath, 'class', 'eui-menu--no-icons'));
  }
  get subSubmenu() {
    let path = '//ul[contains(@class,"eui-menu-sub")]';
    return this.euiMenuItemSubCO.currentPath + path;
  }
  get euiMenuItemSubSubCO() {
    return new CoEuiMenuItem(this.subSubmenu);
  }
  async isCollapsedMenuItemSubSubmenu() {
    return await elementAttributeContains(this.euiMenuItemSubSubCO.currentPath, 'class', 'eui-menu--collapsed');
  }
  async hasIconsMenuItemSubSubmenu() {
    return !(await elementAttributeContains(this.euiMenuItemSubSubCO.currentPath, 'class', 'eui-menu--no-icons'));
  }
  async hasItem() {
    return await (await $(this.euiMenuItemCO.currentPath)).isExisting();
  }
  async isCollapsed() {
    return await elementAttributeContains(this.currentPath, 'class', 'eui-menu--collapsed');
  }
  async hasIcons() {
    return !(await elementAttributeContains(this.currentPath, 'class', 'eui-menu--no-icons'));
  }
}


