import Component  from '../component.js'
import CoEuiButton from './eui-button.js'
import CoEuiIconSvg from './eui-icon-svg.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=develop
    }
    get container() {
      return this.currentPath + '//div[contains(@class, "eui-dialog")]';
    }
    async isDraggable() {
      return await (await $(this.container+ '/self::div[contains(@class, "eui-dialog--draggable")]')).isExisting();
    }
    async isMessageBox() {
      return await (await $(this.container+ '/self::div[contains(@class, "eui-dialog--message-box")]')).isExisting();
    }
    async hasNoBodyPadding() {
      return await (await $(this.container+ '/self::div[contains(@class, "eui-dialog--no-padding")]')).isExisting();
    }
    async hasMobileCustomSize() {
      return await (await $(this.container+ '/self::div[contains(@class, "eui-dialog--custom-size")]')).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 closeButtonCO() {
      return new CoEuiButton(this.header);
    }
    async hasCloseButton() {
      return await (await $(this.closeButtonCO.currentPath)).isExisting();
    }
    get closeIconCO() {
      return new CoEuiIconSvg(this.closeButtonCO).byAttributeContains('icon','eui-close');
    }
    async isHeaderTemplatePortal() {
      return await (await $(this.header + '//*[@cdkPortalOutlet="dialogContainerConfig.header"]')).isExisting();
    }
    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();
    }
    get bodyContentIcon() {
      return this.bodyIconContainer + '//div[contains(@class, "eui-dialog__body-content-icon")]';
    }
    get severitybodyIconCO() {
      return new CoEuiIconSvg(this.bodyContentIcon);
    }
    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 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');
    }
    async hasDismissButton() {
      return await (await $(this.dismissButton.currentPath)).isExisting();
    }
    get acceptButton() {
      return new CoEuiButton(this.footerContent).byAttributeContains('class', 'eui-dialog__footer-accept-button');
    }
    async hasAcceptButton() {
      return await (await $(this.acceptButton.currentPath)).isExisting();
    }
    get footerComponentPortal() {
      return this.footer + '//*[@cdkPortalOutlet="footerComponentPortal"]';
    }
    async isFooterComponentPortal() {
      return await (await $(this.footerComponentPortal)).isExisting();
    }
}


