import Component  from '../component.js'
import CoEuiCardMediaContent from './eui-card-media-content.js'

export default class CoEuiCardMedia extends Component {
  constructor(parent) {
    let selector = 'eui-card-media';
    super(parent, selector);
    // https://citnet.tech.ec.europa.eu/CITnet/stash/projects/CSDR/repos/eui/browse/packages/components/eui-card/components/eui-card-media/eui-card-media.component.html
  }
  get container() {
    return this.currentPath + '//div[contains(@class,"eui-card-media__container")]';
  }
  get routerlink() {
    return this.container + '//a[@routerLink]';
  }
  async hasInternalUrl() {
    return await (await $(this.routerlink)).isExisting();
  }
  get externalUrl() {
    return this.container + '//a[@href]';
  }
  async hasExternalUrl() {
    return await (await $(this.externalUrl)).isExisting();
  }
  async euiCardMediaContent() {
    if(await this.hasInternalUrl()) {
      return new CoEuiCardMediaContent(this.routerlink);
    }
    else if (await this.hasExternalUrl()) {
      return new CoEuiCardMediaContent(this.externalUrl);
    }
    else{
    return new CoEuiCardMediaContent(this.container);
    }
  }
}


