import Component from '../../component.js'
import CoUxButton from './ux-button.js';
import MatMenu from '../../material/mat-menu.js'
import Button from '../../button.js';
import CoUxDropdownButtonItem from './ux-dropdown-button-item.js';
import CdkOverlayContainer from '../../cdk-overlay-container.js';
import { elementAttributeContains } from '../../../core/utils.js';
import { childByIndex }  from '../../xpath-utils.js'

export default class CoUxDropdownButton extends Component {
    constructor(parent) {
      let selector = 'ux-dropdown-button';
      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.component.html
    }
// BUTTON
    get buttonCO() {
      return new CoUxButton(this.currentPath);
    }
// MAT-MENU
    get matMenuCO() {
      let overlayContainer = new CdkOverlayContainer('//body');
      return new MatMenu(overlayContainer);
    }
    get dropdownMatmenuNoLinks() {
      let path = '//div[contains(@class,"ux-dropdown-button__content")]';
      return this.matMenuCO.currentPath + path;
    }
    get dropdownMatmenuButtonCO() {
      return new Button(this.matMenuCO.currentPath);
    }
    get dropdownMatmenuButtonItem() {
      let path = '//span[contains(@class,"ux-dropdown-button-item__icon")]';
      return this.dropdownMatmenuButtonCO.currentPath + path;
    }
    get dropdownMatmenuButtonItemLabel(){
      return childByIndex(this.dropdownMatmenuButtonCO.currentPath, 'span', 2);
    }
    get dropdownButtonItemCO() {
      return new CoUxDropdownButtonItem(this.matMenuCO.matMenuContent);
    }
    get showDropdownToggle(){
      let path = '//a[contains(@class,"ux-dropdown-toggle")]';
      return this.currentPath + path;
    }
    get dropdownToggleIconButton(){
      let path = '//span[contains(@class,"ux-button__icon")]';
      return this.showDropdownToggle + path;
    }
    get dropdownToggleButtonIconLabel(){
      return childByIndex(this.showDropdownToggle, 'span', 2);
    }
    async isShowDropdownToggle(){
      return await (await $(this.showDropdownToggle)).isExisting();
    }
    async isLinkToggle(){
      return await(await $(this.showDropdownToggle)).isExisting();
    }
}


