import Component  from '../component.js'

export default class CoEuiAutocomplete extends Component {
    constructor(parent) {
      let selector = 'eui-autocomplete[contains(@class, "eui-autocomplete")]';
      super(parent, selector);
    }
    get autocompleteContainer() {
      let path = '//div[@class = "eui-autocomplete__container"]';
      return this.currentPath + path;
    }
    get autocompleteWrapper() {
      let path = '//div[contains(@class, "eui-autocomplete__wrapper")]';
      return this.autocompleteContainer + path;
    }
    get autocompleteFieldWrapper() {
      let path = '//span[contains(@class, "eui-autocomplete__field-wrapper")]';
      return this.autocompleteContainer + path;
    }
    get inputWrapper() {
      let path = '//div[@class = "eui-clearable-input-wrapper"]';
      return this.autocompleteFieldWrapper + path;
    }
    // eui autocomplete prepend content
    get euiButtonCO() {
      return new CoEuiButton(this.autocompleteFieldWrapper);
    }
    // input field
    get prependInputField() {
      let path = '//input[contains(@class, "input-addon--prepend")]';
      return this.currentPath + path;
    }
    get apendInputField() {
      let path = '//input[contains(@class, "input-addon--append")]';
      return this.currentPath + path;
    }
    get inputField() {
      let path = '//input[contains(@class, "mat-autocomplete-trigger")]';
      return this.currentPath + path;
    }
    async isLoading() {
      let cl = await (await $(this.inputWrapper + '//span[contains(@class, "eui-autocomplete__loading-indicator")]')).isExisting();
      if (cl) {
         return true;
      } else if (!cl) {
         return false;
      } else {
         throw new Error('eui-autocomplete component object needs to be revised, ' +
            'Loading indicaotr export default class is missing');
      }
    }
    get matAutocompleteList() {
      let path = '//div[contains(@class, "mat-autocomplete-panel")]';
      return new CdkOverlayContainer(new ChainedXpathElement('//body')).overlayPane + path;
    }
    // Input field clear button
    get inputFieldClearButton() {
      let path = '//span[contains(@class, "eui-clearable-input-wrapper__clear")]';
      return this.inputWrapper + path;
    }
    // Chips list
    get autocompleteChipList() {
      return new CoEuiChipsList(this.autocompleteWrapper);
    }
    // Mat section
    get matAutocomplete() {
      let path = '//mat-autocomplete';
      return this.autocompleteFieldWrapper + path;
    }
}


