import Component  from '../component.js';
import CoEuiButton from './eui-button.js';
import CoEuiIconSvg from './eui-icon-svg.js';
import DivComponent from '../div.js';
import SpanComponent from '../span.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=master
    }
    get containerCO() {
      return new DivComponent(this.currentPath).addPredicateClassContains('eui-dialog');
    }
    async isDraggable() {
      return await (await $(this.containerCO.currentPath+ '/self::div[contains(@class, "eui-dialog--draggable")]')).isExisting();
    }
    async isMessageBox() {
      return await (await $(this.containerCO.currentPath+ '/self::div[contains(@class, "eui-dialog--message-box")]')).isExisting();
    }
    async hasNoBodyPadding() {
      return await (await $(this.containerCO.currentPath+ '/self::div[contains(@class, "eui-dialog--no-padding")]')).isExisting();
    }
    async hasMobileCustomSize() {
      return await (await $(this.containerCO.currentPath+ '/self::div[contains(@class, "eui-dialog--custom-size")]')).isExisting();
    }
    get contentCO() {
      return new DivComponent(this.containerCO).addPredicateClassContains('eui-dialog__content');
    }
    get headerCO() {
      return new DivComponent(this.contentCO).addPredicateClassContains('eui-dialog__header');
    }
    get headerTitle() {
      return this.headerCO.currentPath + '//h5[contains(@class, "eui-dialog__header-title")]';
    }
    async hasHeaderTilte() {
      return await (await $(this.headerTitle)).isExisting();
    }
    get closeButtonCO() {
      return new CoEuiButton(this.headerCO);
    }
    async hasCloseButton() {
      return await (await $(this.closeButtonCO.currentPath)).isExisting();
    }
    get closeIconCO() {
      return new CoEuiIconSvg(this.closeButtonCO).addPredicateIconContains('eui-close');
    }
    async isHeaderTemplatePortal() {
      return await (await $(this.headerCO.currentPath + '//*[@cdkPortalOutlet="dialogContainerConfig.header"]')).isExisting();
    }
    async isHeaderComponentPortal() {
      return await (await $(this.headerCO.currentPath + '//*[@cdkPortalOutlet="headerComponentPortal"]')).isExisting();
    }
    get bodyCO() {
      return new DivComponent(this.contentCO).addPredicateClassContains('eui-dialog__body');
    }
    get bodyIconContainerCO() {
      return new SpanComponent(this.bodyCO).addPredicateClassContains('eui-dialog__body-content-icon-container');
    }
    async isMessageBox() {
      return await (await this.bodyIconContainerCO.element()).isExisting();
    }
    get bodyContentIconCO() {
      return new DivComponent(this.bodyIconContainerCO).addPredicateClassContains('eui-dialog__body-content-icon');
    }
    get severitybodyIconCO() {
      return new CoEuiIconSvg(this.bodyContentIconCO);
    }
    async severity() {
      if (await this.isMessageBox()) {
        let at = await (await $(this.severitybodyIconCO.currentPath).getAttribute('icon'))
        if(at.includes('eui-ecl-error')) {
          return 'danger';
        } else if(at.includes('eui-check')) {
          return 'success';
        } else if(at.includes('eui-info')) {
          return 'info';
        } else if(at.includes('eui-question')) {
          return 'primary';
        } else if(at.includes('eui-ecl-warning')) {
          return 'warning or second';
        }
      } else {
        return 'Dialog doesn.\'t have severity';
      }
    }
    get bodyComponentNotPortalCO() {
      return new DivComponent(this.bodyCO).addPredicateAttributeContains('id','containerConfigId');
    }
    async isNotBodyTemplatePortal() {
      return await (await this.bodyComponentNotPortalCO.element()).isExisting();
    }
    get bodyTemplatePortal() {
      return new DivComponent(this.bodyCO).addPredicateAttributeContains('id','bodyTemplatePortalId');
    }
    async isBodyTemplatePortal() {
      return await (await $(this.bodyTemplatePortal)).isExisting();
    }
    get bodyComponentPortalCO() {
      return new DivComponent(this.bodyCO).addPredicateAttributeContains('id','bodyComponentPortalId');
    }
    async isBodyComponentPortal() {
      return await (await this.bodyComponentPortalCO.element()).isExisting();
    }
    get footerCO() {
      return new DivComponent(this.contentCO).addPredicateClassContains('eui-dialog__footer');
    }
    async hasFooter() {
      return await (await this.footerCO.element()).isExisting();
    }
    get footerContentCO() {
      return new DivComponent(this.footerCO).addPredicateClassContains('eui-dialog__footer-content');
    }
    async isFooterTemplatePortal() {
      return !(await (await this.footerContentCO.element()).isExisting());
    }
    get dismissButtonCO() {
      return new CoEuiButton(this.footerContentCO).addPredicateClassContains('eui-dialog__footer-dismiss-button');
    }
    async hasDismissButton() {
      return await (await this.dismissButtonCO.element()).isExisting();
    }
    get acceptButtonCO() {
      return new CoEuiButton(this.footerContentCO).addSelectorPredicate('[@euiPrimary]');
    }
    async hasAcceptButton() {
      return await (await this.acceptButtonCO.element()).isExisting();
    }
    get footerTemplatePortal() {
      return this.footerCO.currentPath + '//*[@cdkPortalOutlet="dialogContainerConfig.footer"]';
    }
    async isFooterTemplatePortal() {
      return await (await $(this.footerComponentPortal)).isExisting();
    }
    get footerComponentPortal() {
      return this.footerCO.currentPath + '//*[@cdkPortalOutlet="footerComponentPortal"]';
    }
    async isFooterComponentPortal() {
      return await (await $(this.footerComponentPortal)).isExisting();
    }
}


