import Component from '../../component.js'
import Button from '../../button.js'
import CoEuiButton from './eui-button.js'
import { elementAttributeContains } from '../../../core/utils.js'

export default class CoEuiDialog extends Component {
    constructor(parent) {
      let selector = 'eui-dialog';
      super(parent, selector);
      //https://citnet.tech.ec.europa.eu/CITnet/stash/projects/CSDR/repos/eui/browse/packages/components-next/src/lib/components/eui-dialog/eui-dialog.component.html?at=support/10.x
    }
    get container() {
      return this.currentPath + '//div[contains(@class, "eui-dialog__container")]';
    }
    async hasNoBodyPadding() {
      return await elementAttributeContains(this.container, 'class', 'eui-dialog__container--no-padding');
    }
    get wrapper() {
      return this.container + '//div[contains(@class, "eui-dialog__wrapper")]';
    }
    get header() {
      return this.wrapper + '//div[contains(@class, "eui-dialog__header")]';
    }
    async isDraggable() {
      return await elementAttributeContains(this.container, 'class', 'eui-dialog__container--draggable');
    }
    get headerTitle() {
      return this.header + '//div[contains(@class, "eui-dialog__header-title")]';
    }
    get modalCloseButtonCO() {
      return new CoEuiButton(this.header).byAttributeContains('class','eui-dialog__header-close');
    }
    get body() {
      return this.wrapper + '//div[contains(@class, "eui-dialog__body")]';
    }
    get bodyContentWrapper() {
      return this.body + '//div[contains(@class, "eui-dialog__body-content-wrapper")]';
    }
    get bodyIconContainer() {
      return this.bodyContentWrapper + '//span[contains(@class, "eui-dialog__body-content-icon-container")]';
    }
    async bodyText() {
      let status = await (await $(this.bodyIconContainer)).isExisting();
      if (!status) {
        return this.bodyContentWrapper + '/span';
      } else {
        return this.bodyContentWrapper + '/span[2]';
      }
    }
    async hasSeverity() {
      return await (await $(this.bodyIconContainer)).isExisting();
    }
    async severity() {
      if (await this.hasSeverity()) {
        let at = await (await $(this.bodyIconContainer + '//span[contains(@class, "eui-dialog__body-content-icon")]')).getAttribute('class')
        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';
        }
      } else {
        return 'Dialog doesn.\'t have severity';
      }
    }
    get footer() {
      return this.wrapper + '//div[contains(@class, "eui-dialog__footer")]';
    }
    get footerActionsContainer() {
      return this.footer + '//div[contains(@class, "eui-dialog__footer-actions-container")]';
    }
    get dismissButton() {
      return new Button(this.footerActionsContainer).byAttributeContains('class', 'eui-dialog__footer-actions--dismiss');
    }
    get acceptButton() {
      return new Button(this.footerActionsContainer).byAttributeContains('class', 'eui-dialog__footer-actions--accept');
    }
}


