import Component  from '../component.js'
import CoEuiChipList from './eui-chip-list.js'
import CoEuiInputText from './eui-input-text.js'
import MatAutocomplete from '../material/mat-autocomplete.js'
import { elementAttributeContains } from '../../core/utils.js'
import MatOptGroup from '../material/mat-optgroup.js'
import MatOption from '../material/mat-option.js'
import CdkOverlayContainer from '../../components/cdk-overlay-container.js'

export default class CoEuiAutocomplete extends Component {
  constructor(parent) {
    let selector = '*[self::eui-autocomplete or input[@euiAutocomplete]]';
    super(parent, selector);
    //https://citnet.tech.ec.europa.eu/CITnet/stash/projects/CSDR/repos/eui/browse/packages/components/eui-autocomplete/eui-autocomplete.component.html?at=support/13.x
  }
  get container() {
    return this.currentPath + '//div[contains(@class,"eui-autocomplete__container")]';
  }
  get wrapper() {
    return this.container + '//div[contains(@class, "eui-autocomplete__wrapper")]';
  }
  get chipListCO() {
    return new CoEuiChipList(this.wrapper);
  }
  async hasChips() {
    return await (await $(this.chipListCO.currentPath)).isExisting();
  }
  get fieldWrapper() {
    return this.container + '//span[contains(@class, "eui-autocomplete__field-wrapper")]';
  }
  get euiInputTextNoChips() {
    return new CoEuiInputText(this.fieldWrapper).currentPath + "/self::input[not (contains(@matChipInputFor,'chipsListComponent'))]";
  }
  get euiInputTextChipList() {
    return new CoEuiInputText(this.fieldWrapper).currentPath + "/self::input[@matChipInputFor,'chipsListComponent')]";
  }
  async chipsListComponent() {
    return await (await $(this.euiInputTextChipList.currentPath)).isExisting();
  }
  get matAutocompleteCO() {
    return new MatAutocomplete(this.fieldWrapper);
  }
  get matOptGroupCO() {
    return new MatOptGroup(new CdkOverlayContainer('//body'));
  }
  async isGroupBy() {
    return await (await $(this.matOptGroupCO.currentPath)).isExisting();
  }
  async autocompleteOptGroupTemplate() {
    return await elementAttributeContains(this.matOptGroupCO.currentPath, 'class', 'eui-autocomplete__optgroup--custom');
  }
  get customOptgroupWrapper() {
    return this.matOptGroupCO.currentPath + '//div[contains(@class,"eui-autocomplete__optgroup--custom-optgroup-wrapper")]';
  }
  async hasAutocompleteOptGroupTemplate() {
    return await (await $(this.customOptgroupWrapper)).isExisting();
  }
  get matOptionInOptGroupCO() {
    return new MatOption(this.matOptGroupCO.currentPath);
  }
  async hasAutocompleteOptionTemplateOptGroup() {
    return await elementAttributeContains(this.matOptionInOptGroupCO.currentPath, 'class', 'eui-autocomplete__option--custom');
  }
  get matOptionIconGroupBy() {
    return this.matOptionInOptGroupCO.currentPath + '//span';
  }
  get matOptionNoGroupBydCO() {
    return new MatOption(new CdkOverlayContainer('//body'));
  }
  async hasAutocompleteOptionTemplateNoGroupBy() {
    return await elementAttributeContains(this.matOptionNoGroupBydCO.currentPath, 'class', 'eui-autocomplete__option--custom');
  }
  get matOptionIconNoGroupBy() {
    return this.matOptionNoGroupBydCO.currentPath + '//span';
  }
  async hasNoGroupByItemIconClass() {
    return await (await $(this.matOptionIconNoGroupBy)).isExisting();
  }
  async isChipsDragAndDrop() {
    return await (await $(this.currentPath + '/self::*[@isChipsDragAndDrop]')).isExisting();
  }
  async isItemsSorted() {
    return await (await $(this.currentPath + '/self::*[@isItemsSorted]')).isExisting();
  }
  async isChipsSorted() {
    return await (await $(this.currentPath + '/self::*[@isChipsSorted]')).isExisting();
  }
  async isChipsRemovable() {
    return await (await $(this.currentPath + '/self::*[@isChipsRemovable]')).isExisting();
  }
  async isMaxVisibleChipsOpened() {
    return await (await $(this.currentPath + '/self::*[@isMaxVisibleChipsOpened]')).isExisting();
  }
  async addOnBlur() {
    return await (await $(this.currentPath + '/self::*[@addOnBlur]')).isExisting();
  }
  async isFreeValueAllowed() {
    return await (await $(this.currentPath + '/self::*[@isFreeValueAllowed]')).isExisting();
  }
  async isDuplicateValueAllowed() {
    return await (await $(this.currentPath + '/self::*[@isDuplicateValueAllowed]')).isExisting();
  }
}


