import Component  from '../component.js'
import CoEuiMenuItem from './eui-menu-item.js'
import { elementAttributeContains } from '../../core/utils.js';
import CoEuiIcon from './eui-icon.js';
import InputComponent from '../input.js'
import UlComponent from '../ul.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/eui-menu/eui-menu.component.html?at=support/13.x
  }
  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-menu-filter__input-wrapper")]';
    return this.filter + path;
  }
  get searchIconCO() {
    return new CoEuiIcon(this.wrapper).byAttributeContains('class','eui-menu-filter__input-search')
  }
  get filterInputCO() {
    return new InputComponent(this.wrapper).byAttributeContains('class', 'eui-menu-filter__input');
  } 
  get listCO() {
    return new UlComponent(this.currentPath).byAttributeContains('class', 'eui-menu');
  }
  get noItems() {
    let path = '//span[contains(@class,"eui-menu--no-items")]';
    return this.listCO.currentPath + path;
  }
  get euiMenuItemCO() {
    return new CoEuiMenuItem(this.listCO);
  }
  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'));
  }
}


