import Component  from '../component.js'

export default class CoUxGrowl extends Component {

    constructor(parent) {
      // super();
      let selector = 'ux-growl';
      super(parent, selector);
    }
   /**
    * Sets the current component element to an xpath selector a child has a export default class of the requested severity.
	* info, warning, danger or success
    * The parent remains unchanged
    * @param severity string
    * @type CoUxGrowl
    */
    async bySeverity( severity ) {
        this.currentPath = '//' + this.selector + '//*[contains(@class,"ux-growl-item-container--' + severity + '")]' + '/ancestor::' + this.selector + '[1]';
        this.element = await this.parent.$(this.currentPath);
        return this;
    }
    /**
    * @type WebdriverIO.Element
    */
    get itemContainer() {
      let path = '//div[contains(@class,"ux-growl-item-container")]';
      return this.currentPath + path;
    }
    /**
    * @type string
    */
    async growlSeverity() {
      const cl = await (await $(this.itemContainer)).getAttribute('class');
      if (cl.includes('ux-growl-item-container--info')) {
         return 'info';
      } else if (cl.includes('ux-growl-item-container--warning')) {
         return 'warning';
      } else if (cl.includes('ux-growl-item-container--danger')) {
         return 'danger';
      } else if (cl.includes('ux-growl-item-container--success')) {
         return 'success';
      } else {
         throw new Error('ux-growl component object needs to be revised, ux-growl-item-container is missing class');
      }
    }
    /**
    * @type WebdriverIO.Element
    */
    get growlClose() {
      let path = '//div[contains(@class,"ux-growl-item-close")]';
      return this.currentPath + path;
    }
    /**
    * @type WebdriverIO.Element
    */
    get growlMessageTitle() {
      let path = '//span[contains(@class,"ux-growl-item-message-title")]';
      return this.currentPath + path;
    }
    /**
    * @type WebdriverIO.Element
    */
    get growlMessageDetail() {
      let path = '//p[contains(@class,"ux-growl-item-message-detail")]';
      return this.currentPath + path;
    }
}


