import Component  from '../component.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 CoEuiAutocompleteFieldWrapper extends Component {
  constructor(parent) {
    let selector = 'span[contains(@class, "eui-autocomplete__field-wrapper")]';
    super(parent, selector);
    //https://citnet.tech.ec.europa.eu/CITnet/stash/projects/CSDR/repos/eui/browse/packages/components/eui-autocomplete/eui-autocomplete.component.html
  }

  get euiInputTextNoChips() {
    return new CoEuiInputText(this.currentPath).currentPath + "/self::input[not(@matAutocompleteConnectedTo)]";
  }
  get euiInputTextChipList() {
    return new CoEuiInputText(this.currentPath).currentPath + "/self::input[@matAutocompleteConnectedTo]";
  }
  get matAutocompleteCO() {
    return new MatAutocomplete(this.currentPath);
  }
  get matOptGroupCO() {
    return new MatOptGroup(new CdkOverlayContainer('//body'));
  }
  async isGroupBy() {
    return await (await this.matOptGroupCO.element()).isExisting();
  }
  get customOptgroupWrapper() {
    return this.matOptGroupCO.currentPath + '//div[contains(@class,"eui-autocomplete__optgroup--custom-optgroup-wrapper")]';
  }
  async autocompleteOptGroupTemplate() {
    return await elementAttributeContains(this.matOptGroupCO.currentPath, 'class', 'eui-autocomplete__optgroup--custom');
  }
  async hasAutocompleteOptGroupTemplate() {
    return await (await $(this.customOptgroupWrapper)).isExisting();
  }
  get matOptionInOptGroupCO() {
    return new MatOption(this.matOptGroupCO);
  }
  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();
  }
}


