import Component from '../../component.js'
import CoEuiChipList from './eui-chip-list.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 '../../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-next/src/lib/components/eui-autocomplete/eui-autocomplete.component.html?at=refs%2Fheads%2Fsupport%2F10.x
  }
  get container() {
    let path = '//div[contains(@class,"eui-autocomplete__container")]';
    return this.currentPath + path;
  }
  get wrapper() {
    let path = '//div[contains(@class, "eui-autocomplete__wrapper")]';
    return this.container + path;
  }
  get chipListCO() {
    return new CoEuiChipList(this.wrapper);
  }
  async hasChips() {
    return await(await $(this.chipListCO.currentPath)).isExisting();
  }
  get fieldWrapper() {
    let path = '//span[contains(@class, "eui-autocomplete__field-wrapper")]';
    return this.container + path;
  }
  get prependContent() {
    let path = '//euiAutocompletePrependContent';
    return this.fieldWrapper + path;
  }
  get inputWrapper() {
    let path = '//div[contains(@class,"eui-clearable-input-wrapper")]';
    return this.fieldWrapper + path;
  }
  get input() {
    let path = '//input';
    return this.inputWrapper + path;
  }
  async hasEuiAutocompletePrependContent() {
    return await elementAttributeContains(this.input, 'class', 'input-addon--prepend');
  }
  async hasEuiAutocompleteAppendContent() {
    return await elementAttributeContains(this.input, 'class', 'input-addon--append');
  }
  get clearLine() {
    let path = '//span[contains(@class,"eui-clearable-input-wrapper__clear")]';
    return this.inputWrapper + path;
  }
  async isClearable() {
    return await(await $(this.clearLine)).isExisting();
  }
  get loadingIndicator() {
    let path = '//span[contains(@class,"eui-autocomplete__loading-indicator")]';
    return this.inputWrapper + path;
  }
  async isLoading() {
    return await(await $(this.loadingIndicator)).isExisting();
  }
  get appendContentPlaceholder() {
    let path = '//euiAutocompleteAppendContent';
    return this.fieldWrapper + path;
  }
  get matAutocompleteCO() {
    return new MatAutocomplete(this.fieldWrapper);
  }
  get overlayContainerCO() {
    return new CdkOverlayContainer('//body');
  }
  get matOptGroupCO() {
    return new MatOptGroup(this.overlayContainerCO.currentPath);
  }
  async isGroupBy() {
    return await(await $(this.matOptGroupCO.currentPath)).isExisting();
  }
  async autocompleteOptGroupTemplate() {
    return await elementAttributeContains(this.matOptGroupCO.currentPath, 'class', 'eui-autocomplete__optgroup--custom');
  }
  get customOptgroupWrapper() {
    let path = '//div[contains(@class,"eui-autocomplete__optgroup--custom-optgroup-wrapper")]';
    return this.matOptGroupCO.currentPath + path;
  }
  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 matOptionCO() {
    return new MatOption(this.overlayContainerCO.currentPath);
  }
  async hasAutocompleteOptionTemplate() {
    return await elementAttributeContains(this.matOptionCO.currentPath, 'class', 'eui-autocomplete__option--custom');
  }
  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();
  }
}


