import Component  from '../component.js'
import CoEuiChip from './eui-chip.js'
import EuiChipListChip from './eui-chip-list-chip.js'
import CoEuiButton from './eui-button.js'
import CoEuiLabel from './eui-label.js'
import CoEuiIcon from './eui-icon.js'

export default class CoEuiChipList extends Component {
    constructor(parent) {
      let selector = '*[self::eui-chip-list or self::div[@euiChipList] or self::ul[@euiChipList]]';
      super(parent, selector);
      // https://citnet.tech.ec.europa.eu/CITnet/stash/projects/CSDR/repos/eui/browse/packages/components/eui-chip-list/eui-chip-list.component.html?at=refs%2Fheads%2Fsupport%2Fdevelop-14.x
    }
    get container() {
      return this.currentPath + '//div[contains(@class,"eui-chip-list-container")]';
    }
    get wrapper() {
      return this.container + '//div[contains(@class,"eui-chip-list-wrapper")]';
    }
    get chipListList() {
      return this.wrapper + '//div[contains(@class,"eui-chip-list__list")]';
    }
    get euiChipListChipCO() {
      return new EuiChipListChip(this.chipListList);
    }
    get euiChipListAppendContent() {
      return this.chipListList +  '//euiChipListAppendContent';
    }
    get expandButtonWrapper() {
      return this.container +  '//div[contains(@class,"eui-chip-list__expand-button-wrapper")]';
    }
    async hasExpandButton() {
      return await (await $(this.expandButtonWrapper)).isExisting();
    }
    get expandButton() {
      return new CoEuiButton(this.expandButtonWrapper).byAttributeContains('class','eui-chip-list__expand-button').currentPath;
    }
    get angelLeftIcon() {
      return new CoEuiIcon(this.expandButton).byAttributeContains('iconClass',"eui-icon-angle-left");
    }
    get euiLabelCO() {
      return new CoEuiLabel(this.expandButton);
    }
    async isMaxVisibleChipsOpened() {
      return await (await $(this.angelLeftIcon.currentPath)).isExisting();
    }
    async hasLessLabel() {
      return await this.isMaxVisibleChipsOpened();
    }
    get angelRightIcon() {
      return new CoEuiIcon(this.expandButton).byAttributeContains('iconClass',"eui-icon-angle-right");
    }
    async hasMoreLabel() {
      return !( await this.isMaxVisibleChipsOpened());
    }
    get group() {
      return this.currentPath + '//div[contains(@class,"eui-chip-list__group")]';
    }
    async isGrid() {
      return await (await $(this.container)).isExisting();
    }
    get custom() {
      return this.currentPath + '//div[contains(@class,"eui-chip-list_custom")]';
    }
    get chipContainer() {
      return this.custom + '//div[contains(@class,"eui-chip-list__chip-container")]';
    }
    get euiChipCO() {
      return new CoEuiChip(this.chipContainer);
    }
    get euiChipIconCO(){
      return new CoEuiIcon(this.euiChipCO);
    }
    get chipLabel(){
      return this.euiChipCO.currentPath + '//span[@title]';
    }
    async chipsLabelTruncateCount() {
      return await this.chipLabel.isExisting();
    }
    async chipContent(){
      if(! await this.chipsLabelTruncateCount()) {
        return this.euiChipCO.currentPath + '//span';
      }
    }
    get customEuiChipListAppendContent() {
      return this.custom +  '//euiChipListAppendContent';
    }
    get customExpandButtonWrapper() {
      return this.group +  '//div[contains(@class,"eui-chip-list__expand-button-wrapper")]';
    }
    async hasCustomExpandButton() {
      return await (await $(this.customExpandButtonWrapper)).isExisting();
    }
    get customExpandButton() {
      return new CoEuiButton(this.customExpandButtonWrapper).byAttributeContains('class','eui-chip-list__expand-button').currentPath;
    }
    get customAngelLeftIcon() {
      return new CoEuiIcon(this.customExpandButton).byAttributeContains('iconClass',"eui-icon-angle-left");
    }
    get customEuiLabelCO() {
      return new CoEuiLabel(this.customExpandButton);
    }
    async isMaxVisibleCustomChipsOpened() {
      return await (await $(this.customAngelLeftIcon.currentPath)).isExisting();
    }
    async hasLessCustomLabel() {
      return await this.isMaxVisibleCustomChipsOpened();
    }
    get customAngelRightIcon() {
      return new CoEuiIcon(this.customExpandButton).byAttributeContains('iconClass',"eui-icon-angle-right");
    }
    async hasMoreCustomLabel() {
      return !( await this.isMaxVisibleCustomChipsOpened());
    }
}


