import Component from '../../component.js';
import { elementAttributeContains } from '../../../core/utils.js';

export default class CoUxGrowl extends Component {
  constructor(parent) {
    let selector = 'ux-growl';
    super(parent, selector);
    //https://citnet.tech.ec.europa.eu/CITnet/stash/projects/CSDR/repos/eui/browse/packages/components/legacy/ux-growl/ux-growl.component.html
  }

  get uxGrowl() {
    return this.currentPath + '//div[@data-e2e="ux-growl"]';
  }

  get growlItemContainer() {
    const path = '//div[contains(@class, "ux-growl-item-container")]';
    return this.uxGrowl + path;
  }

  async growlSeverity() {
    const cl = await (await $(this.growlItemContainer)).getAttribute('class');
    if (await cl.includes('eui-growl-item-container--info')) {
      return 'info';
    } else if (await cl.includes('eui-growl-item-container--warning')) {
      return 'warning';
    } else if (await cl.includes('eui-growl-item-container--danger')) {
      return 'danger';
    } else if (await cl.includes('eui-growl-item-container--success')) {
      return 'success';
    } else {
      throw new Error('ux-growl component object needs to be revised, eui-growl-item-container is missing class');
    }
  }

  get growlSlideInUp() {
    const path = '//div[contains(@class, "eui-u-anim--slideInUp")]';
    return this.uxGrowl + path;
  }
  get growlSlideInDown() {
    const path = '//div[contains(@class, "eui-u-anim--slideInDown")]';
    return this.uxGrowl + path;
  }

  get growlItem() {
    const path = '//div[contains(@class, "ux-growl-item")]';
    return this.growlItemContainer + path;
  }

  get growlItemImage() {
    const path = '//span[contains(@class,"ux-growl-item-image") and contains(@class,"eui-icon")]';
    return this.growlItem + path;
  }

  IconBySeverity(severity) {
    const path = '//span[contains(@class, "eui-icon-' + severity + '")]';
    return this.growlItem + path;
  }

  get growlItemMessage() {
    const path = '//div[contains(@class,"ux-growl-item-message")]';
    return this.growlItem + path;
  }
  get growlMessagetitle() {
    const path = '//span[contains(@class,"ux-growl-item-message-title")]';
    return this.growlItemMessage + path;
  }
  get growlMessageDetail() {
    const path = '//p[contains(@class,"ux-growl-item-message-detail")]';
    return this.growlItemMessage + path;
  }
  get growlClose() {
    const path = '//div[contains(@class,"ux-growl-item-close")]';
    return this.growlItem + path;
  }
  async isSticky() {
    return await elementAttributeContains(this.growlItemContainer, 'class', 'eui-growl--sticky');
  }
}


