import Component from '../../component.js'
import ButtonComponent from '../../button.js';
import CoEuiButton from './eui-button.js'
import CoEuiDropdownContent from './eui-dropdown-content.js'
import CdkOverlayContainer from '../../cdk-overlay-container.js'
import { elementAttributeContains } from '../../../core/utils.js'

export default class CoEuiDropdown extends Component {
    overlayContainer;
    constructor(parent) {
      let selector = 'eui-dropdown';
      super(parent, selector);
      this.overlayContainer = new CdkOverlayContainer('//body');
      //https://citnet.tech.ec.europa.eu/CITnet/stash/projects/CSDR/repos/eui/browse/packages/components-next/src/lib/components/eui-dropdown/eui-dropdown.component.html
    }
    get matMenuTrigger() {
      return this.currentPath + '//div[contains(@class, "mat-menu-trigger")]';
    }
    // eui button
    get euiButtonCO() {
      return new CoEuiButton(this.matMenuTrigger);
    }
    // Mat section
    get matmenu() {
      let path = '//mat-menu';
      return this.currentPath + path;
    }
    get euiDropdownContentCO() {
      return new CoEuiDropdownContent(this.matContentWrapper);
    }
    get matContentWrapper() {
      let path = '//div[contains(@class, "eui-dropdown-content-wrapper")]';
      return this.overlayContainer.overlayPane + path;
    }
    get euiDropdownContent() {
      return new CoEuiDropdownContent(this.matContentWrapper);
    }

    matDropdownItemByLabel(label) {
      let btnItem = new ButtonComponent(this.euiDropdownContent).byAttributeContains('class', 'eui-list-item');
      return btnItem.byTextContains(label);
    }
    async isDisabled() {
      return await elementAttributeContains(this.currentPath, 'aria-disabled', 'true');
    }
    async isExpanded() {
      return await elementAttributeContains(this.matMenuTrigger, 'aria-expanded', 'true');
    }
    async hasPopup() {
      return await elementAttributeContains(this.matMenuTrigger, 'aria-haspopup', 'true');
    }

}


