import Component from '../../component.js'
import ButtonComponent from '../../button.js';
import CoEuiButton from './eui-button.js';

export default class CoEuiMessageBoxContainer extends Component {
  constructor(parent) {
    let selector = 'eui-message-box-container';
    super(parent, selector);
    //https://citnet.tech.ec.europa.eu/CITnet/stash/projects/CSDR/repos/eui/browse/packages/components-next/src/lib/components/eui-message-box/container/eui-message-box-container.component.html?at=refs%2Fheads%2Fsupport%2F10.x
  }

  get messageBox() {
    let path = '//div[contains(@class,"eui-message-box")]';
    return this.currentPath + path;
  }

  get messageBoxWrapper() {
    let path = '//div[contains(@class,"eui-message-box__wrapper")]';
    return this.messageBox + path;
  }
  get messageBoxContent() {
    let path = '//div[contains(@class,"eui-message-box__content")]';
    return this.messageBoxWrapper + path;
  }
  // HEADER
  get messageBoxHeader() {
    let path = '//div[contains(@class,"eui-message-box__header")]';
    return this.messageBoxContent + path;
  }
  get messageBoxTitle() {
    let path = '//h5[contains(@class,"eui-message-box__header-title")]';
    return this.messageBoxHeader + path;
  }
  get closeButtonCo() {
    return new ButtonComponent(this.messageBoxHeader)
  }
  async hasCloseButton() {
    return await (await this.closeButtonCo.element()).isExisting();
  }
  get closeButtonIcon() {
    return this.closeButtonCo.currentPath + '//span[contains(@class,"eui-icon-close-m")]'
  }
  // BODY
  get messageBoxBody() {
    let path = '//div[contains(@class,"eui-message-box__body")]';
    return this.messageBoxContent + path;
  }
  get bodyIcon() {
    let path = '//div[contains(@class,"eui-message-box__body-icon")]';
    return this.messageBoxBody + path;
  }
  get bodyIconSeverity() {
    let path = '//span[contains(@iconClass,"eui-icon") and contains(@iconClass,"eui-message-box__body-icon-content")]';
    return this.bodyIcon + path;
  }
  async severity() {
    let cl = await (await $(this.bodyIconSeverity)).getAttribute('iconClass');
    if (await cl.includes('eui-icon-ecl-error')) {
      return 'danger';
    } else if(await cl.includes('eui-icon-check')) {
      return 'success';
    } else if(await cl.includes('eui-icon-info')) {
      return 'info';
    } else if(await cl.includes('eui-icon-question')) {
      return 'question';
    } else if(await cl.includes('eui-icon-exclamation-triangle')) {
      return 'warning';
    }
  }
  get messageBoxBodyContent() {
    let path = '//div[contains(@class,"eui-message-box__body-content")]';
    return this.messageBoxBody + path;
  }
  async isContentTemplatePortal() {
    return await (await $(this.messageBoxBodyContent + "//")).isExisting();
  }


  // FOOTER
  async isFooterTemplatePortal() {
    if(!await this.dismissButton().isExisting() && !await this.acceptButton().isExisting()) {
      return true;
    } else {
      return false;
    }
  }
  get messageBoxFooter() {
    let path = '//div[contains(@class,"eui-message-box__footer")]';
    return this.messageBoxContent + path;
  }
  get dismissButton() {
    return new CoEuiButton(this.messageBoxFooter).byAttributeContains('class', 'eui-message-box__footer-dismiss-button');
  }
  get acceptButton() {
    return new CoEuiButton(this.messageBoxFooter).byAttributeContains('class', 'eui-message-box__footer-accept-button');
  }
}


