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

export default class CoEuiGrowl extends Component {
    constructor(parent) {
      let selector = 'eui-growl';
      super(parent, selector);
      //https://citnet.tech.ec.europa.eu/CITnet/stash/projects/CSDR/repos/eui/browse/packages/components-next/src/lib/components/eui-growl/eui-growl.component.html
    }
    get dataE2E() {
      return this.currentPath + '//div[@data-e2e = "eui-growl"]'
    }
    get growlItemContainer() {
      return this.dataE2E + '//div[contains(@class, "eui-growl-item-container")]';
    }
    async severity() {
      let 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 {
        return 'Growl doesn\'t have any sevevrity or eui-growl component needs to be revised';
      }
    }
    async isSticky() {
      return await elementAttributeContains(this.growlItemContainer, 'class', 'eui-growl--sticky');
    }
    async growlSlideDirection() {
      let cl = await (await $(this.growlItemContainer)).getAttribute('class');
      if(await cl.includes('eui-u-anim--slideInDown')) {
        return 'SlideInDown';
      } else if(await cl.includes('eui-u-anim--slideInUp')) {
        return 'SlideInUp';
      } else {
        return 'Growl\'s Slide Position is not specified or eui-growl component needs to be revised';
      }
    }
    async growlPosition() {
      let cl = await (await $(this.dataE2E)).getAttribute('class');
      if(await cl.includes('eui-growl--bottom-left')) {
        return 'bottom-left';
      } else if(await cl.includes('eui-growl--bottom-center')) {
        return 'bottom-center';
      } else if(await cl.includes('eui-growl--bottom-right')) {
        return 'bottom-right';
      } else if(await cl.includes('eui-growl--top-left')) {
        return 'top-left';
      } else if(await cl.includes('eui-growl--top-center')) {
        return 'top-center';
      } else if(await cl.includes('eui-growl--top-right')) {
        return 'top-right';
      } else {
        return 'Growl\'s position is not specified or eui-growl component needs to be revised';
      }
    }
    get growlItem() {
      return this.growlItemContainer + '//div[contains(@class, "eui-growl-item")]';
    }
    get growlItemImage() {
      let path = '//span[contains(@class, "eui-growl-item-image") and contains(@class, "eui-icon-3x")]'
      return this.growlItem + path;
    }
    async iconSeverity() {
      let cl = await (await $(this.growlItemImage)).getAttribute('class');
      if(cl.includes('eui-icon-info-circle')) {
        return 'info';
      } else if(await cl.includes('eui-icon-exclamation-circle')) {
        return 'warning';
      } else if(await cl.includes('eui-icon-ecl-error')) {
        return 'danger';
      } else if(await cl.includes('eui-icon-check-circle')) {
        return 'success';
      } else {
        return 'Growl doesn\'t have any sevevrity or eui-growl component needs to be revised';
      }
    }
    get growlItemMessage() {
      return this.growlItem + '//div[contains(@class, "eui-growl-item-message")]';
    }
    get growlTitle() {
      return this.growlItemMessage + '//span[contains(@class, "eui-growl-item-message-title")]';
    }
    get growlDetail() {
      return this.growlItemMessage + '//p[contains(@class, "eui-growl-item-message-detail")]';
    }
    get growlItemClose() {
      let path = '//div[contains(@class, "eui-growl-item-close") and contains(@class, "eui-icon-close-m")]'
      return this.growlItem + path;
    }
}


