import AComponent from '../a.js';
import Component from '../component.js'
import DivComponent from '../div.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?at=master
  }
  get containerCO() {
    return new DivComponent(this.currentPath).addPredicateClassContains('eui-card-media__container');
  }
  get routerlinkCO() {
    return new AComponent(this.containerCO).addSelectorPredicate('[@routerLink]');
  }
  async hasInternalUrl() {
    return await (await this.routerlinkCO.element()).isExisting();
  }
  get externalUrlCO() {
    return new AComponent(this.containerCO).addSelectorPredicate('[@href]');
  }
  async hasExternalUrl() {
    return await (await this.externalUrlCO.element()).isExisting();
  }
  async euiCardMediaContent() {
    if (await this.hasInternalUrl()) {
      return new CoEuiCardMediaContent(this.routerlinkCO);
    }
    else if (await this.hasExternalUrl()) {
      return new CoEuiCardMediaContent(this.externalUrlCO);
    }
    else {
      return new CoEuiCardMediaContent(this.containerCO);
    }
  }
}


