import Component from '../component.js';
import { elementAttributeContains } from '../../core/utils.js';
import CoEuiIconSvg from './eui-icon-svg.js';
import PComponent from '../p.js';
import DivComponent from '../div.js';
import SpanComponent from '../span.js';
import CoEuiIconSvgButton from './eui-icon-svg-button.js';
import CoEuiIconState from './eui-icon-state.js';

export default class CoEuiGrowlItem extends Component {
  constructor(parent) {
    let selector = 'div[contains(@class, "eui-growl-item-container")]';
    super(parent, selector);
    //https://citnet.tech.ec.europa.eu/CITnet/stash/projects/CSDR/repos/eui/browse/packages/components/eui-growl/eui-growl.component.html
  }
  async severity() {
    let cl = await (await $(this.currentPath)).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 severity or eui-growl component needs to be revised';
    }
  }
  async isSticky() {
    return await elementAttributeContains(this.currentPath, 'class', 'eui-growl--sticky');
  }
  async growlSlideDirection() {
    let cl = await (await $(this.currentPath)).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.currentPath)).getAttribute('class');
    if (await cl.includes('bottom-left')) {
      return 'bottom-left';
    } else if (await cl.includes('bottom-center')) {
      return 'bottom-center';
    } else if (await cl.includes('bottom-right')) {
      return 'bottom-right';
    } else if (await cl.includes('top-left')) {
      return 'top-left';
    } else if (await cl.includes('top-center')) {
      return 'top-center';
    } else if (await cl.includes('top-right')) {
      return 'top-right';
    } else {
      return 'Growl\'s position is not specified or eui-growl component needs to be revised';
    }
  }
  get growlItemCO() {
    return new DivComponent(this.currentPath).addPredicateClassContains('eui-growl-item');
  }
  get growlItemImageCO() {
    return new CoEuiIconSvg(this.growlItemCO);
  }
  async iconSeverity() {
    let cl = await (await this.growlItemImageCO.element()).getAttribute('icon');
    if (cl.includes('eui-ecl-information')) {
      return 'info';
    } else if (await cl.includes('eui-ecl-warning')) {
      return 'warning';
    } else if (await cl.includes('eui-ecl-error')) {
      return 'danger';
    } else if (await cl.includes('eui-ecl-check-filled')) {
      return 'success';
    } else {
      return 'Growl doesn\'t have any severity or eui-growl component needs to be revised';
    }
  }
  get growlItemMessageCO() {
    return new DivComponent(this.growlItemCO).addPredicateClassContains('eui-growl-item-summary-wrapper');
  }
  get growlIconStateCO(){
    return new CoEuiIconState(this.growlItemMessageCO);
  }
  get growlTitleCO() {
    return new SpanComponent(this.growlItemMessageCO).addPredicateClassContains('eui-growl-item-title');
  }
  get growlDetailCO() {
    return new DivComponent(this.growlItemMessageCO).addPredicateClassContains('eui-growl-item-content');
  }
  get growlItemCloseCO() {
    return new CoEuiIconSvgButton(this.growlItemCO).addPredicateClassContains('eui-growl-item-close');
  }
}
