import Component  from '../component.js'
import CoUxButton from './ux-button.js'
import CdkOverlayContainer from './cdk-overlay-container.js'
import CoUxDropdownButtonItem from './ux-dropdown-button-item.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/core/src/lib/commons/ux-components/ux-dropdown-button/ux-dropdown-button.component.html?at=support/7.x
    }

// if (isLinkToggle) show Button
// if (!isLinkToggle) show Link

// BUTTON

    get buttonCO() {
      return new CoUxButton(this.currentPath);
    }
    get buttonIcon() {
      let path = '//span[contains(@class,"ux-dropdown-button__icon")]';
      return this.buttonCO.buttonContent + path;
    }
    get buttonLabel() {
      let path = '//span[text()]';
      return this.buttonCO.buttonContent + path;
    }
    async isDisabled() {
      let at = await (await this.buttonCO.element()).getAttribute('disabled');
      if (at === 'true') {
         return true;
      } else {
         return false;
      }
    }
    async isShowDropdownToggle() {
      let cl = await (await this.buttonCO.element()).getAttribute('class');
      if (cl.includes('dropdown-toggle')) {
         return true;
      } else {
         return false;
      }
    }
// LINK this part will be modified in the component object template
    get link() {
      let path = '/a';
      return this.currentPath + path;
    }
    get linkIcon() {
       let path = '//span[contains(@class,"ux-dropdown-button__icon")]';
       return this.link + path;
    }
    get linkLabel() {
       let path = '//span[2][text()]';
       return this.link + path;
    }

    async isLinkDisplayed() {
      return await (await $(this.link)).isDisplayed();
    }

    get cdkOverlayContainer() {
      return new CdkOverlayContainer('//body');
    }

// MAT-MENU
    get dropdownMatmenu() {
      return (this.cdkOverlayContainer.overlayPane + '//mat-menu');
    }
    get dropdownMatmenuButtonContent() {
      let path = '//div[contains(@class,"ux-dropdown-button__content")]';
      return this.dropdownMatmenu + path;
    }

    get coUxDropdownButtonItem(){
      return new CoUxDropdownButtonItem(this.dropdownMatmenuButtonContent);
    }
}


