import Component  from '../component.js'
import CoEuiButton from './eui-button.js'
import CoEuiIcon from './eui-icon.js'

export default class CoEuiDialogContainer extends Component {
    constructor(parent) {
      let selector = 'eui-dialog-container';
      super(parent, selector);
      //https://citnet.tech.ec.europa.eu/CITnet/stash/projects/CSDR/repos/eui/browse/packages/components/eui-dialog/container/eui-dialog-container.component.html?at=support/13.x
    }
    get container() {
      return this.currentPath + '//div[contains(@class, "eui-dialog") and contains(@class, "eui-u-anim")]';
    }
    async isDraggable() {
      return await (await $(this.container+ '/self::div[contains(@class, "eui-dialog--draggable")]')).isExisting();
    }
    get content() {
      return this.container + '//div[contains(@class, "eui-dialog__content")]';
    }
    get header() {
      return this.content + '//div[contains(@class, "eui-dialog__header")]';
    }
    get headerTitle() {
      return this.header + '//h5[contains(@class, "eui-dialog__header-title")]';
    }
    async hasHeaderTilte() {
      return await (await $(this.headerTitle)).isExisting();
    }
    get euiButtonCO() {
      return new CoEuiButton(this.header);
    }
    get closeIconCO() {
      return new CoEuiIcon(this.euiButtonCO).byAttributeContains('class','eui-icon-close-m');
    }
    async isHeaderComponentPortal() {
      return await (await $(this.header + '//*[@cdkPortalOutlet="headerComponentPortal"]')).isExisting();
    }
    get body() {
      return this.content + '//div[contains(@class, "eui-dialog__body")]';
    }
    get bodyIconContainer() {
      return this.body + '//span[contains(@class, "eui-dialog__body-content-icon-container")]';
    }
    async isMessageBox() {
      return await (await $(this.bodyIconContainer)).isExisting();
    }
    async severity() {
      if (await this.isMessageBox()) {
        let at = await (await $(this.bodyIconContainer + '//span[contains(@iconClass, "eui-icon")]')).getAttribute('iconClass')
        if(at.includes('eui-icon-ecl-error')) {
          return 'danger';
        } else if(at.includes('eui-icon-check')) {
          return 'success';
        } else if(at.includes('eui-icon-info')) {
          return 'info';
        } else if(at.includes('eui-icon-question')) {
          return 'question';
        } else if(at.includes('eui-icon-exclamation-triangle')) {
          return 'warning or second';
        }
      } else {
        return 'Dialog doesn.\'t have severity';
      }
    }
    get bodyComponentNotPortal() {
      return this.body + '//div[contains(@class, "not-isBodyTemplatePortal")]';
    }
    async isNotBodyTemplatePortal() {
      return await (await $(this.bodyTemplatePortal)).isExisting();
    }
    get bodyTemplatePortal() {
      return this.body + '//div[contains(@class, "isBodyTemplatePortal")]';
    }
    async isBodyTemplatePortal() {
      return await (await $(this.bodyTemplatePortal)).isExisting();
    }
    get bodyComponentPortal() {
      return this.body + '//div[contains(@class, "isBodyComponentPortal")]';
    }
    async isBodyComponentPortal() {
      return await (await $(this.bodyComponentPortal)).isExisting();
    }
    get footer() {
      return this.content + '//div[contains(@class, "eui-dialog__footer")]';
    }
    async hasFooter() {
      return await (await $(this.footer)).isExisting();
    }
    get footerContent() {
      return this.footer + '//div[contains(@class, "eui-dialog__footer-content")]';
    }
    async isFooterTemplatePortal() {
      return !(await (await $(this.footerContent)).isExisting());
    }
    get dismissButton() {
      return new CoEuiButton(this.footerContent).byAttributeContains('class', 'eui-dialog__footer-dismiss-button');
    }
    get acceptButton() {
      return new CoEuiButton(this.footerContent).byAttributeContains('class', 'eui-dialog__footer-accept-button');
    }
    get footerComponentPortal() {
      return this.footer + '//*[@cdkPortalOutlet="footerComponentPortal"]';
    }
    async isFooterComponentPortal() {
      return await (await $(this.footerComponentPortal)).isExisting();
    }
}


