import  Component from '../component.js';
import  SpanComponent from '../span.js';
import  CoEuiBadge from './eui-badge.js';

export default class CoEuiIconSvg extends Component {
  constructor(parent) {
    let selector = '*[self::span[@euiIconSvg] or self::i[@euiIconSvg] or self::eui-icon-svg]';
    super(parent, selector);
    // https://citnet.tech.ec.europa.eu/CITnet/stash/projects/CSDR/repos/eui/browse/packages/components/eui-icon/eui-icon-svg.component.html?at=master
  }
  async isDefault() {
    return await (await $(this.currentPath + '/self::*[@icon]')).isExisting();
  }
  async isCustom() {
    return await (await $(this.currentPath + '/self::*[@iconUrl]')).isExisting();
  }
  async isLoading() {
    return await (await $(this.loading)).isExisting();
  }

  //following elements are present in the template but SVG element doesn’t support the standard format of XPath, hence these elements cannot be used in the tests
  get defaultSvg() {
    return this.currentPath + '//*[local-name()="svg"]';
  }
  get defaultSvgUse() {
    return this.defaultSvg + '//*[local-name()="use"]';
  }
  get defaultSvgSpanCO() {
    return new SpanComponent(this.currentPath).addPredicateClassContains('eui-icon-svg__badge');
  }
  get euiBadgeCO() {
    return new CoEuiBadge(this.defaultSvgSpanCO);
  }
  get customSvg() {
    return this.currentPath + '//svg//image/ancestor::svg';
  }
  get customSvgImage() {
    return this.customSvg + '//image';
  }
  get loading() {
    return this.currentPath + '//eui-icon-svg[contains(@class,"eui-icon-svg--loading")]';
  }
}