import Component from '../../component.js'
import CoEuiButton from './eui-button.js'
import CoEuiCardHeaderTitle from './eui-card-header-title.js'
import CoEuiCardHeaderBody from './eui-card-header-body.js'
import CoEuiCardHeaderLeftContent from './eui-card-header-left-content.js'
import CoEuiCardHeaderRightContent from './eui-card-header-right-content.js'
import CoEuiCardHeaderSubtitle from './eui-card-header-subtitle.js'


export default class CoEuiCardHeader extends Component {
  constructor(parent) {
    let selector = 'eui-card-header';
    super(parent, selector);
    // https://citnet.tech.ec.europa.eu/CITnet/stash/projects/CSDR/repos/eui/browse/packages/components/eui-card/components/eui-card-header/eui-card-header.component.html
  }
  get container() {
    return this.currentPath + '//div[contains(@class,"eui-card-header__container")]';
  }
  async isHeaderBodyOnly() {
    return !(await (await $(this.container)).isExisting());
  }
  get euiCardHeaderLeftContentCO() {
    return new CoEuiCardHeaderLeftContent(this.container);
  }
  get avatar() {
    return this.container + '//div[contains(@class,"eui-card-header__avatar")]';
  }
  async hasAvatar() {
    return await (await $(this.avatar)).isExisting();
  }
  get icon() {
    return this.container + '//div[contains(@class,"eui-card-header__icon")]';
  }
  async hasIcon() {
    return await (await $(this.icon)).isExisting();
  }
  async titleContainer() {
    let path = '//div[contains(@class,"eui-card-header__title-container")]';
    if(await this.hasFullTitle()) {
      return this.middleContainer + path;
    }
    return this.container + path;
  }
  get middleContainer() {
    return this.container + '//div[contains(@class,"eui-card-header__middle-container")]';
  }
  get middleContent() {
    return this.middleContainer + '//div[contains(@class,"eui-card-header__middle-content")]';
  }
  async hasFullTitle() {
    return await (await $(this.middleContainer)).isExisting();
  }
  async euiCardHeaderTitleCO() {
    return new CoEuiCardHeaderTitle(await this.titleContainer());
  }
  async euiCardHeaderSubtitleCO() {
    if(await this.hasFullTitle()) {
      return new CoEuiCardHeaderSubtitle(this.middleContent);
    }
    return new CoEuiCardHeaderSubtitle(await this.titleContainer());
  }
  async euiCardHeaderRightContentCO() {
    if(await this.hasFullTitle()) {
      return new CoEuiCardHeaderRightContent(this.middleContent);
    }
    return new CoEuiCardHeaderRightContent(this.container);
  }
  get expander() {
    return this.container + '//div[contains(@class,"eui-card-header__expander")]';
  }
  async isCollapsible() {
    return await (await $(this.expander)).isExisting();
  }
  get expanderButton() {
    return new CoEuiButton(this.expander).byAttributeContains('class','eui-card-header__expander-icon').currentPath;
  }
  async isCollapsed() {
    return await (await $(this.expanderButton + '/self::button[@aria-label="expand"]')).isExisting();
  }
  get iconAngleUp() {
    return this.expanderButton + '//span[contains(@class,"eui-icon-angle-up")]';
  }
  get urgentIndicator() {
    return this.currentPath + '//div[contains(@class,"eui-card-header__urgent-indicator")]';
  }
  get euiCardHeaderBodyCO() {
    return new CoEuiCardHeaderBody(this.currentPath);
  }

}


